diff --git a/src/compiler/nir/nir_lower_system_values.c b/src/compiler/nir/nir_lower_system_values.c index b73135aff46..5e23019a81a 100644 --- a/src/compiler/nir/nir_lower_system_values.c +++ b/src/compiler/nir/nir_lower_system_values.c @@ -347,11 +347,14 @@ lower_system_value_instr(nir_builder *b, nir_instr *instr, void *_state) nir_def * nir_build_lowered_load_helper_invocation(nir_builder *b) { - nir_def *tmp; - tmp = nir_ishl(b, nir_imm_int(b, 1), - nir_load_sample_id_no_per_sample(b)); - tmp = nir_iand(b, nir_load_sample_mask_in(b), tmp); - return nir_inot(b, nir_i2b(b, tmp)); + nir_def *mask = nir_load_sample_mask_in(b); + + if (b->shader->info.fs.uses_sample_shading) { + nir_def *id = nir_load_sample_id(b); + mask = nir_iand(b, mask, nir_ishl(b, nir_imm_int(b, 1), id)); + } + + return nir_ieq_imm(b, mask, 0); } bool diff --git a/src/compiler/nir/nir_shader_compiler_options.h b/src/compiler/nir/nir_shader_compiler_options.h index 525fcd02a45..f7d6ef07184 100644 --- a/src/compiler/nir/nir_shader_compiler_options.h +++ b/src/compiler/nir/nir_shader_compiler_options.h @@ -370,7 +370,14 @@ typedef struct nir_shader_compiler_options { /** * If enabled, gl_HelperInvocation will be lowered as: * - * !((1 << sample_id) & sample_mask_in)) + * - non-sample-shading: sample_mask_in == 0. + * - sample shading: !((1 << sample_id) & sample_mask_in)) + * + * For this to be correct, it requires that fs.uses_sample_shading is set to + * true when sample shading is enabled. This means that you need shader + * variants to set the flag when Vulkan's + * VkPipelineMultisampleStateCreateInfo->sampleShadingEnable or GL's + * glMinSampleshading() are enabled. * * This depends on some possibly hw implementation details, which may * not be true for all hw. In particular that the FS is only executed