squash! v3dv,broadcom/compiler: don't abuse sampler index

For tex instructions that don't have sampler state use backend_flags
instead of sampler index to bind default sampler state.

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24537>
This commit is contained in:
Iago Toral Quiroga 2023-08-07 09:19:11 +02:00 committed by Marge Bot
parent b2de3f71dc
commit da625903c7
4 changed files with 27 additions and 14 deletions

View file

@ -229,12 +229,18 @@ v3d40_vir_emit_tex(struct v3d_compile *c, nir_tex_instr *instr)
assert(instr->op != nir_texop_lod || c->devinfo->ver >= 42);
unsigned texture_idx = instr->texture_index;
unsigned sampler_idx = instr->sampler_index;
/* For instructions that don't have a sampler (i.e. txf) we bind
* default sampler state via the backend_flags to handle precision.
*/
unsigned sampler_idx = nir_tex_instr_need_sampler(instr) ?
instr->sampler_index : instr->backend_flags;
/* Even if the texture operation doesn't need a sampler by
* itself, we still need to add the sampler configuration
* parameter if the output is 32 bit
*/
assert(sampler_idx < c->key->num_samplers_used);
bool output_type_32_bit =
c->key->sampler[sampler_idx].return_size == 32;

View file

@ -614,6 +614,19 @@ type_size_vec4(const struct glsl_type *type, bool bindless)
return glsl_count_attribute_slots(type, false);
}
static enum nir_lower_tex_packing
lower_tex_packing_cb(const nir_tex_instr *tex, const void *data)
{
struct v3d_compile *c = (struct v3d_compile *) data;
int sampler_index = nir_tex_instr_need_sampler(tex) ?
tex->sampler_index : tex->backend_flags;
assert(sampler_index < c->key->num_samplers_used);
return c->key->sampler[sampler_index].return_size == 16 ?
nir_lower_tex_packing_16 : nir_lower_tex_packing_none;
}
static void
v3d_lower_nir(struct v3d_compile *c)
{
@ -638,13 +651,8 @@ v3d_lower_nir(struct v3d_compile *c)
tex_options.swizzles[i][j] = c->key->tex[i].swizzle[j];
}
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;
}
}
tex_options.lower_tex_packing_cb = lower_tex_packing_cb;
tex_options.lower_tex_packing_data = c;
NIR_PASS(_, c->s, nir_lower_tex, &tex_options);
NIR_PASS(_, c->s, nir_lower_system_values);

View file

@ -3621,13 +3621,12 @@ build_nir_tex_op_ms_fetch_sample(struct nir_builder *b,
nir_ssa_def *tex_pos,
nir_ssa_def *sample_idx)
{
nir_tex_instr *tex = nir_tex_instr_create(b->shader, 4);
nir_tex_instr *tex = nir_tex_instr_create(b->shader, 3);
tex->sampler_dim = GLSL_SAMPLER_DIM_MS;
tex->op = nir_texop_txf_ms;
tex->src[0] = nir_tex_src_for_ssa(nir_tex_src_coord, tex_pos);
tex->src[1] = nir_tex_src_for_ssa(nir_tex_src_texture_deref, tex_deref);
tex->src[2] = nir_tex_src_for_ssa(nir_tex_src_sampler_deref, tex_deref);
tex->src[3] = nir_tex_src_for_ssa(nir_tex_src_ms_index, sample_idx);
tex->src[2] = nir_tex_src_for_ssa(nir_tex_src_ms_index, sample_idx);
tex->dest_type = nir_get_nir_type_for_glsl_base_type(tex_type);
tex->is_array = false;
tex->coord_components = tex_pos->num_components;

View file

@ -718,12 +718,12 @@ lower_sampler(nir_builder *b,
if (texture_idx < 0 && sampler_idx < 0)
return false;
/* If we don't have a sampler, we assign it the idx we reserve for this
* case, and we ensure that it is using the correct return size.
/* If the instruction doesn't have a sampler (i.e. txf) we use backend_flags
* to bind a default sampler state to configure precission.
*/
if (sampler_idx < 0) {
state->needs_default_sampler_state = true;
instr->sampler_index = return_size == 16 ?
instr->backend_flags = return_size == 16 ?
V3DV_NO_SAMPLER_16BIT_IDX : V3DV_NO_SAMPLER_32BIT_IDX;
}