From 429c33641275e02b17351ab24a693f2469cc36f3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alejandro=20Pi=C3=B1eiro?= Date: Tue, 10 Nov 2020 22:05:10 +0100 Subject: [PATCH] broadcom/compiler: separate texture/sampler info from v3d_key So far the v3d compiler has them combined, as for OpenGL both are the same. This change is intended to fit the v3d compiler better with Vulkan, where they are separate concepts. Note that NIR has them separate for a long time, both on nir_variable and on some NIR lowerings. v2: (from Iago feedback) * Use key->num_tex/sampler_used to iterate through the array * Fill up num_samplers_used on v3d, assert that is the same that num_tex_used if possible. v3: (Iago) * Assert num_tex/samplers_used is smaller that tex/sampler array size. v4: Update assert mentioned on v3 to use <= instead of < (detected by CI) Reviewed-by: Iago Toral Quiroga squash! broadcom/compiler: separate texture/sampler info from v3d_key Part-of: --- src/broadcom/compiler/v3d40_tex.c | 18 ++++++++++-------- src/broadcom/compiler/v3d_compiler.h | 8 ++++++-- src/broadcom/compiler/vir.c | 9 +++++++-- src/broadcom/vulkan/v3dv_pipeline.c | 4 ++-- src/gallium/drivers/v3d/v3d_program.c | 23 +++++++++++++++-------- 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/broadcom/compiler/v3d40_tex.c b/src/broadcom/compiler/v3d40_tex.c index 7e39f8b..e9737d6 100644 --- a/src/broadcom/compiler/v3d40_tex.c +++ b/src/broadcom/compiler/v3d40_tex.c @@ -61,7 +61,9 @@ static const struct V3D41_TMU_CONFIG_PARAMETER_2 p2_unpacked_default = { void v3d40_vir_emit_tex(struct v3d_compile *c, nir_tex_instr *instr) { - unsigned unit = instr->texture_index; + unsigned texture_idx = instr->texture_index; + unsigned sampler_idx = instr->sampler_index; + int tmu_writes = 0; struct V3D41_TMU_CONFIG_PARAMETER_0 p0_unpacked = { @@ -199,11 +201,11 @@ v3d40_vir_emit_tex(struct v3d_compile *c, nir_tex_instr *instr) if (instr->op == nir_texop_lod) p2_packed |= 1UL << 24; - /* Load unit number into the high bits of the texture address field, + /* Load texture_idx number into the high bits of the texture address field, * which will be be used by the driver to decide which texture to put * in the actual address field. */ - p0_packed |= unit << 24; + p0_packed |= texture_idx << 24; vir_WRTMUC(c, QUNIFORM_TMU_CONFIG_P0, p0_packed); @@ -211,7 +213,7 @@ v3d40_vir_emit_tex(struct v3d_compile *c, nir_tex_instr *instr) * itself, we still need to add the sampler configuration * parameter if the output is 32 bit */ - bool output_type_32_bit = (c->key->tex[unit].return_size == 32 && + bool output_type_32_bit = (c->key->sampler[sampler_idx].return_size == 32 && !instr->is_shadow); /* @@ -248,12 +250,12 @@ v3d40_vir_emit_tex(struct v3d_compile *c, nir_tex_instr *instr) &p1_unpacked); if (nir_tex_instr_need_sampler(instr)) { - /* Load unit number into the high bits of the sampler - * address field, which will be be used by the driver - * to decide which sampler to put in the actual + /* Load sampler_idx number into the high bits of the + * sampler address field, which will be be used by the + * driver to decide which sampler to put in the actual * address field. */ - p1_packed |= unit << 24; + p1_packed |= sampler_idx << 24; vir_WRTMUC(c, QUNIFORM_TMU_CONFIG_P1, p1_packed); } else { diff --git a/src/broadcom/compiler/v3d_compiler.h b/src/broadcom/compiler/v3d_compiler.h index 6e17649..d0bfa1f 100644 --- a/src/broadcom/compiler/v3d_compiler.h +++ b/src/broadcom/compiler/v3d_compiler.h @@ -344,13 +344,17 @@ struct v3d_key { void *shader_state; struct { uint8_t swizzle[4]; - uint8_t return_size; - uint8_t return_channels; bool clamp_s:1; bool clamp_t:1; bool clamp_r:1; } tex[V3D_MAX_TEXTURE_SAMPLERS]; + struct { + uint8_t return_size; + uint8_t return_channels; + } sampler[V3D_MAX_TEXTURE_SAMPLERS]; + uint8_t num_tex_used; + uint8_t num_samplers_used; uint8_t ucp_enables; bool is_last_geometry_stage; bool robust_buffer_access; diff --git a/src/broadcom/compiler/vir.c b/src/broadcom/compiler/vir.c index 3ce8fe4..42ce76f 100644 --- a/src/broadcom/compiler/vir.c +++ b/src/broadcom/compiler/vir.c @@ -564,7 +564,8 @@ v3d_lower_nir(struct v3d_compile *c) /* Lower the format swizzle and (for 32-bit returns) * ARB_texture_swizzle-style swizzle. */ - for (int i = 0; i < ARRAY_SIZE(c->key->tex); i++) { + assert(c->key->num_tex_used <= ARRAY_SIZE(c->key->tex)); + for (int i = 0; i < c->key->num_tex_used; i++) { for (int j = 0; j < 4; j++) tex_options.swizzles[i][j] = c->key->tex[i].swizzle[j]; @@ -574,7 +575,11 @@ v3d_lower_nir(struct v3d_compile *c) tex_options.saturate_t |= 1 << i; if (c->key->tex[i].clamp_r) tex_options.saturate_r |= 1 << i; - if (c->key->tex[i].return_size == 16) { + } + + assert(c->key->num_samplers_used <= ARRAY_SIZE(c->key->sampler)); + for (int i = 0; i < c->key->num_samplers_used; i++) { + if (c->key->sampler[i].return_size == 16) { tex_options.lower_tex_packing[i] = nir_lower_tex_packing_16; } diff --git a/src/broadcom/vulkan/v3dv_pipeline.c b/src/broadcom/vulkan/v3dv_pipeline.c index c5ab1cc..fc8c188 100644 --- a/src/broadcom/vulkan/v3dv_pipeline.c +++ b/src/broadcom/vulkan/v3dv_pipeline.c @@ -1029,8 +1029,8 @@ pipeline_populate_v3d_key(struct v3d_key *key, key->tex[tex_idx].swizzle[2] = PIPE_SWIZZLE_Z; key->tex[tex_idx].swizzle[3] = PIPE_SWIZZLE_W; - key->tex[tex_idx].return_size = 16; - key->tex[tex_idx].return_channels = 2; + key->sampler[tex_idx].return_size = 16; + key->sampler[tex_idx].return_channels = 2; tex_idx++; } diff --git a/src/gallium/drivers/v3d/v3d_program.c b/src/gallium/drivers/v3d/v3d_program.c index 3132eb5..64229d2 100644 --- a/src/gallium/drivers/v3d/v3d_program.c +++ b/src/gallium/drivers/v3d/v3d_program.c @@ -446,6 +446,8 @@ v3d_setup_shared_key(struct v3d_context *v3d, struct v3d_key *key, const struct v3d_device_info *devinfo = &v3d->screen->devinfo; key->num_tex_used = texstate->num_textures; + key->num_samplers_used = texstate->num_textures; + assert(key->num_tex_used == key->num_samplers_used); for (int i = 0; i < texstate->num_textures; i++) { struct pipe_sampler_view *sampler = texstate->textures[i]; struct v3d_sampler_view *v3d_sampler = v3d_sampler_view(sampler); @@ -455,7 +457,7 @@ v3d_setup_shared_key(struct v3d_context *v3d, struct v3d_key *key, if (!sampler) continue; - key->tex[i].return_size = + key->sampler[i].return_size = v3d_get_tex_return_size(devinfo, sampler->format, sampler_state->compare_mode); @@ -464,17 +466,17 @@ v3d_setup_shared_key(struct v3d_context *v3d, struct v3d_key *key, * channels (meaning no recompiles for most statechanges), * while for 32 we actually scale the returns with channels. */ - if (key->tex[i].return_size == 16) { - key->tex[i].return_channels = 2; + if (key->sampler[i].return_size == 16) { + key->sampler[i].return_channels = 2; } else if (devinfo->ver > 40) { - key->tex[i].return_channels = 4; + key->sampler[i].return_channels = 4; } else { - key->tex[i].return_channels = + key->sampler[i].return_channels = v3d_get_tex_return_channels(devinfo, sampler->format); } - if (key->tex[i].return_size == 32 && devinfo->ver < 40) { + if (key->sampler[i].return_size == 32 && devinfo->ver < 40) { memcpy(key->tex[i].swizzle, v3d_sampler->swizzle, sizeof(v3d_sampler->swizzle)); @@ -505,10 +507,15 @@ v3d_setup_shared_precompile_key(struct v3d_uncompiled_shader *uncompiled, { nir_shader *s = uncompiled->base.ir.nir; + /* Note that below we access they key's texture and sampler fields + * using the same index. On OpenGL they are the same (they are + * combined) + */ key->num_tex_used = s->info.num_textures; + key->num_samplers_used = s->info.num_textures; for (int i = 0; i < s->info.num_textures; i++) { - key->tex[i].return_size = 16; - key->tex[i].return_channels = 2; + key->sampler[i].return_size = 16; + key->sampler[i].return_channels = 2; key->tex[i].swizzle[0] = PIPE_SWIZZLE_X; key->tex[i].swizzle[1] = PIPE_SWIZZLE_Y; -- 2.7.4