mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-03 15:50:17 +01:00
agx: Lower offsets in NIR
Rather than the backend. This way we can handle non-constant offsets as well as constants with a single code path (with the constant offset code subsumed as a special case via NIR's constant folding). This nets us dynamic offset support. Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21264>
This commit is contained in:
parent
a5dfee1c22
commit
8dc861dbb5
2 changed files with 24 additions and 19 deletions
|
|
@ -1166,6 +1166,10 @@ agx_emit_tex(agx_builder *b, nir_tex_instr *instr)
|
|||
coords = index;
|
||||
break;
|
||||
|
||||
case nir_tex_src_backend2:
|
||||
packed_offset = index;
|
||||
break;
|
||||
|
||||
case nir_tex_src_lod:
|
||||
case nir_tex_src_bias:
|
||||
lod = index;
|
||||
|
|
@ -1176,25 +1180,6 @@ agx_emit_tex(agx_builder *b, nir_tex_instr *instr)
|
|||
compare = index;
|
||||
break;
|
||||
|
||||
case nir_tex_src_offset: {
|
||||
assert(instr->src[i].src.is_ssa);
|
||||
nir_ssa_def *def = instr->src[i].src.ssa;
|
||||
uint32_t packed = 0;
|
||||
|
||||
for (unsigned c = 0; c < def->num_components; ++c) {
|
||||
nir_ssa_scalar s = nir_ssa_scalar_resolved(def, c);
|
||||
assert(nir_ssa_scalar_is_const(s) && "no nonconstant offsets");
|
||||
|
||||
int32_t val = nir_ssa_scalar_as_uint(s);
|
||||
assert((val >= -8 && val <= 7) && "out of bounds offset");
|
||||
|
||||
packed |= (val & 0xF) << (4 * c);
|
||||
}
|
||||
|
||||
packed_offset = agx_mov_imm(b, 32, packed);
|
||||
break;
|
||||
}
|
||||
|
||||
case nir_tex_src_ddx: {
|
||||
int y_idx = nir_tex_instr_src_index(instr, nir_tex_src_ddy);
|
||||
assert(y_idx >= 0 && "we only handle gradients");
|
||||
|
|
|
|||
|
|
@ -210,6 +210,26 @@ lower_regular_texture(nir_builder *b, nir_instr *instr, UNUSED void *data)
|
|||
}
|
||||
|
||||
nir_tex_instr_add_src(tex, nir_tex_src_backend1, nir_src_for_ssa(coord));
|
||||
|
||||
/* Furthermore, if there is an offset vector, it must be packed */
|
||||
nir_ssa_def *offset = steal_tex_src(tex, nir_tex_src_offset);
|
||||
|
||||
if (offset != NULL) {
|
||||
nir_ssa_def *packed = NULL;
|
||||
|
||||
for (unsigned c = 0; c < offset->num_components; ++c) {
|
||||
nir_ssa_def *nibble = nir_iand_imm(b, nir_channel(b, offset, c), 0xF);
|
||||
nir_ssa_def *shifted = nir_ishl_imm(b, nibble, 4 * c);
|
||||
|
||||
if (packed != NULL)
|
||||
packed = nir_ior(b, packed, shifted);
|
||||
else
|
||||
packed = shifted;
|
||||
}
|
||||
|
||||
nir_tex_instr_add_src(tex, nir_tex_src_backend2, nir_src_for_ssa(packed));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue