From 5910c938a293c03337911ca3c067b4ecf4b406ee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tapani=20P=C3=A4lli?= Date: Wed, 19 Feb 2020 08:33:04 +0200 Subject: [PATCH] nir/glsl: gather bitmask of images used by program In a similar fashion as commit f5c7df4dc95 does for textures. Reviewed-by: Lionel Landwerlin Part-of: --- .../glsl/gl_nir_lower_samplers_as_deref.c | 18 ++++++++++++++++++ src/compiler/shader_info.h | 3 +++ src/mesa/state_tracker/st_glsl_to_nir.cpp | 1 + 3 files changed, 22 insertions(+) diff --git a/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c b/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c index dde858f9cfc..a0a5f018ad7 100644 --- a/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c +++ b/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c @@ -118,6 +118,21 @@ remove_struct_derefs_prep(nir_deref_instr **p, char **name, } } +static void +record_images_used(struct shader_info *info, + nir_deref_instr *deref) +{ + nir_variable *var = nir_deref_instr_get_variable(deref); + + /* Structs have been lowered already, so get_aoa_size is sufficient. */ + const unsigned size = + glsl_type_is_array(var->type) ? glsl_get_aoa_size(var->type) : 1; + unsigned mask = ((1ull << MAX2(size, 1)) - 1) << var->data.binding; + + info->images_used |= mask; +} + + static nir_deref_instr * lower_deref(nir_builder *b, struct lower_samplers_as_deref_state *state, nir_deref_instr *deref) @@ -286,6 +301,9 @@ lower_intrinsic(nir_intrinsic_instr *instr, b->cursor = nir_before_instr(&instr->instr); nir_deref_instr *deref = lower_deref(b, state, nir_src_as_deref(instr->src[0])); + + record_images_used(&state->shader->info, deref); + /* don't lower bindless: */ if (!deref) return false; diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h index 4510ce33fb6..19a963d62f3 100644 --- a/src/compiler/shader_info.h +++ b/src/compiler/shader_info.h @@ -140,6 +140,9 @@ typedef struct shader_info { /** Bitfield of which textures are used by texelFetch() */ uint32_t textures_used_by_txf; + /** Bitfield of which images are used */ + uint32_t images_used; + /* SPV_KHR_float_controls: execution mode for floating point ops */ uint16_t float_controls_execution_mode; diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp index d23719d49e8..40560082873 100644 --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp @@ -889,6 +889,7 @@ st_nir_lower_samplers(struct pipe_screen *screen, nir_shader *nir, if (prog) { prog->info.textures_used = nir->info.textures_used; prog->info.textures_used_by_txf = nir->info.textures_used_by_txf; + prog->info.images_used = nir->info.images_used; } } -- 2.30.2