From ef47a6800bae1316136ffc41a8de850984719bd4 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Fri, 14 Jan 2022 01:44:04 -0800 Subject: [PATCH] microsoft/spirv_to_dxil: Make sure the SampleMask is a uint DXIL doesn't like when SV_Coverage (AKA SampleMask in DXIL) is a signed integer. Fix the type while we're in the NIR domain. Signed-off-by: Boris Brezillon Reviewed-by: Jesse Natalie Part-of: --- src/microsoft/ci/spirv2dxil_reference.txt | 27 ++------------ src/microsoft/spirv_to_dxil/spirv_to_dxil.c | 40 +++++++++++++++++++++ 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/microsoft/ci/spirv2dxil_reference.txt b/src/microsoft/ci/spirv2dxil_reference.txt index c2835065de8..5db53535e9f 100644 --- a/src/microsoft/ci/spirv2dxil_reference.txt +++ b/src/microsoft/ci/spirv2dxil_reference.txt @@ -420,30 +420,9 @@ Test:SpvModuleScopeVarParserTest_SampleMask_In_U32_AccessChain.spvasm:main|Fragm Test:SpvModuleScopeVarParserTest_SampleMask_In_U32_CopyObject.spvasm:main|Fragment: Pass Test:SpvModuleScopeVarParserTest_SampleMask_In_U32_Direct.spvasm:main|Fragment: Pass Test:SpvModuleScopeVarParserTest_SampleMask_In_WithStride.spvasm:main|Fragment: Pass -Test:SpvModuleScopeVarParserTest_SampleMask_Out_I32_AccessChain.spvasm:main|Fragment: Fail -DXIL: SV_Coverage must be uint - -Validation failed. - -Failed to validate DXIL - - -Test:SpvModuleScopeVarParserTest_SampleMask_Out_I32_CopyObject.spvasm:main|Fragment: Fail -DXIL: SV_Coverage must be uint - -Validation failed. - -Failed to validate DXIL - - -Test:SpvModuleScopeVarParserTest_SampleMask_Out_I32_Direct.spvasm:main|Fragment: Fail -DXIL: SV_Coverage must be uint - -Validation failed. - -Failed to validate DXIL - - +Test:SpvModuleScopeVarParserTest_SampleMask_Out_I32_AccessChain.spvasm:main|Fragment: Pass +Test:SpvModuleScopeVarParserTest_SampleMask_Out_I32_CopyObject.spvasm:main|Fragment: Pass +Test:SpvModuleScopeVarParserTest_SampleMask_Out_I32_Direct.spvasm:main|Fragment: Pass Test:SpvModuleScopeVarParserTest_SampleMask_Out_U32_AccessChain.spvasm:main|Fragment: Pass Test:SpvModuleScopeVarParserTest_SampleMask_Out_U32_CopyObject.spvasm:main|Fragment: Pass Test:SpvModuleScopeVarParserTest_SampleMask_Out_U32_Direct.spvasm:main|Fragment: Pass diff --git a/src/microsoft/spirv_to_dxil/spirv_to_dxil.c b/src/microsoft/spirv_to_dxil/spirv_to_dxil.c index 8250bf93c64..5df6dea1929 100644 --- a/src/microsoft/spirv_to_dxil/spirv_to_dxil.c +++ b/src/microsoft/spirv_to_dxil/spirv_to_dxil.c @@ -475,6 +475,45 @@ dxil_spirv_nir_discard_point_size_var(nir_shader *shader) return true; } +static bool +fix_sample_mask_type(struct nir_builder *builder, nir_instr *instr, + void *cb_data) +{ + struct dxil_spirv_runtime_conf *conf = + (struct dxil_spirv_runtime_conf *)cb_data; + + if (instr->type != nir_instr_type_deref) + return false; + + nir_deref_instr *deref = nir_instr_as_deref(instr); + nir_variable *var = + deref->deref_type == nir_deref_type_var ? deref->var : NULL; + + if (!var || var->data.mode != nir_var_shader_out || + var->data.location != FRAG_RESULT_SAMPLE_MASK || + deref->type == glsl_uint_type()) + return false; + + assert(glsl_without_array(deref->type) == glsl_int_type()); + deref->type = glsl_uint_type(); + return true; +} + +static bool +dxil_spirv_nir_fix_sample_mask_type(nir_shader *shader) +{ + nir_foreach_variable_with_modes(var, shader, nir_var_shader_out) { + if (var->data.location == FRAG_RESULT_SAMPLE_MASK && + var->type != glsl_uint_type()) { + var->type = glsl_uint_type(); + } + } + + return nir_shader_instructions_pass(shader, fix_sample_mask_type, + nir_metadata_all, NULL); +} + + bool spirv_to_dxil(const uint32_t *words, size_t word_count, struct dxil_spirv_specialization *specializations, @@ -669,6 +708,7 @@ spirv_to_dxil(const uint32_t *words, size_t word_count, nir_lower_tex_options lower_tex_options = {0}; NIR_PASS_V(nir, nir_lower_tex, &lower_tex_options); + NIR_PASS_V(nir, dxil_spirv_nir_fix_sample_mask_type); NIR_PASS_V(nir, dxil_nir_lower_atomics_to_dxil); NIR_PASS_V(nir, dxil_nir_split_clip_cull_distance); NIR_PASS_V(nir, dxil_nir_lower_loads_stores_to_dxil);