diff --git a/src/compiler/nir/nir_lower_system_values.c b/src/compiler/nir/nir_lower_system_values.c index 5e58cd52688..815dcd438fe 100644 --- a/src/compiler/nir/nir_lower_system_values.c +++ b/src/compiler/nir/nir_lower_system_values.c @@ -200,8 +200,12 @@ lower_system_value_instr(nir_builder *b, nir_instr *instr, void *_state) switch (var->data.location) { case SYSTEM_VALUE_INSTANCE_INDEX: - return nir_iadd(b, nir_load_instance_id(b), - nir_load_base_instance(b)); + if (b->shader->options->instance_id_includes_base_index) { + return nir_load_instance_id(b); + } else { + return nir_iadd(b, nir_load_instance_id(b), + nir_load_base_instance(b)); + } case SYSTEM_VALUE_GLOBAL_INVOCATION_ID: { return nir_iadd(b, nir_load_global_invocation_id(b, bit_size), diff --git a/src/compiler/nir/nir_shader_compiler_options.h b/src/compiler/nir/nir_shader_compiler_options.h index 65e4cc111fa..7f728d72cac 100644 --- a/src/compiler/nir/nir_shader_compiler_options.h +++ b/src/compiler/nir/nir_shader_compiler_options.h @@ -356,6 +356,11 @@ typedef struct nir_shader_compiler_options { */ bool lower_base_vertex; + /* Indicates that gl_InstanceIndex already includes base index + * and doesn't require further lowering. + */ + bool instance_id_includes_base_index; + /** * If enabled, gl_HelperInvocation will be lowered as: *