vtn: use vtn_has_decoration more

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37175>
This commit is contained in:
Rhys Perry 2025-09-04 11:47:18 +01:00 committed by Marge Bot
parent 721af20a58
commit efe536dbe9
6 changed files with 21 additions and 113 deletions

View file

@ -3265,22 +3265,6 @@ image_operand_arg(struct vtn_builder *b, const uint32_t *w, uint32_t count,
return idx;
}
static void
non_uniform_decoration_cb(struct vtn_builder *b,
struct vtn_value *val, int member,
const struct vtn_decoration *dec, void *void_ctx)
{
enum gl_access_qualifier *access = void_ctx;
switch (dec->decoration) {
case SpvDecorationNonUniformEXT:
*access |= ACCESS_NON_UNIFORM;
break;
default:
break;
}
}
/* Apply SignExtend/ZeroExtend operands to get the actual result type for
* image read/sample operations and source type for write operations.
*/
@ -3318,10 +3302,9 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
"Type of Image operand of OpSampledImage");
enum gl_access_qualifier access = 0;
vtn_foreach_decoration(b, vtn_untyped_value(b, w[3]),
non_uniform_decoration_cb, &access);
vtn_foreach_decoration(b, vtn_untyped_value(b, w[4]),
non_uniform_decoration_cb, &access);
if (vtn_has_decoration(b, vtn_untyped_value(b, w[3]), SpvDecorationNonUniformEXT) ||
vtn_has_decoration(b, vtn_untyped_value(b, w[4]), SpvDecorationNonUniformEXT))
access |= ACCESS_NON_UNIFORM;
vtn_push_sampled_image(b, w[2], si, access & ACCESS_NON_UNIFORM);
return;
@ -3329,8 +3312,8 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
struct vtn_sampled_image si = vtn_get_sampled_image(b, w[3]);
enum gl_access_qualifier access = 0;
vtn_foreach_decoration(b, vtn_untyped_value(b, w[3]),
non_uniform_decoration_cb, &access);
if (vtn_has_decoration(b, vtn_untyped_value(b, w[3]), SpvDecorationNonUniformEXT))
access |= ACCESS_NON_UNIFORM;
vtn_push_image(b, w[2], si.image, access & ACCESS_NON_UNIFORM);
return;
@ -3809,7 +3792,8 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
* can assume it doesn't exist.
*/
enum gl_access_qualifier access = 0;
vtn_foreach_decoration(b, sampled_val, non_uniform_decoration_cb, &access);
if (vtn_has_decoration(b, sampled_val, SpvDecorationNonUniformEXT))
access |= ACCESS_NON_UNIFORM;
if (operands & SpvImageOperandsNontemporalMask)
access |= ACCESS_NON_TEMPORAL;
@ -4236,7 +4220,8 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
* chains to find the NonUniform decoration. It's either right there or we
* can assume it doesn't exist.
*/
vtn_foreach_decoration(b, res_val, non_uniform_decoration_cb, &access);
if (vtn_has_decoration(b, res_val, SpvDecorationNonUniformEXT))
access |= ACCESS_NON_UNIFORM;
nir_intrinsic_set_access(intrin, access);
switch (opcode) {

View file

@ -455,24 +455,6 @@ vtn_handle_fp_fast_math(struct vtn_builder *b, struct vtn_value *val)
#undef FLOAT_CONTROLS2_BITS
}
static void
handle_no_contraction(struct vtn_builder *b, UNUSED struct vtn_value *val,
UNUSED int member, const struct vtn_decoration *dec,
UNUSED void *_void)
{
vtn_assert(dec->scope == VTN_DEC_DECORATION);
if (dec->decoration != SpvDecorationNoContraction)
return;
b->nb.exact = true;
}
void
vtn_handle_no_contraction(struct vtn_builder *b, struct vtn_value *val)
{
vtn_foreach_decoration(b, val, handle_no_contraction, NULL);
}
nir_rounding_mode
vtn_rounding_mode_to_nir(struct vtn_builder *b, SpvFPRoundingMode mode)
{
@ -524,54 +506,11 @@ handle_conversion_opts(struct vtn_builder *b, UNUSED struct vtn_value *val,
}
}
static void
handle_no_wrap(UNUSED struct vtn_builder *b, UNUSED struct vtn_value *val,
UNUSED int member,
const struct vtn_decoration *dec, void *_alu)
{
nir_alu_instr *alu = _alu;
switch (dec->decoration) {
case SpvDecorationNoSignedWrap:
alu->no_signed_wrap = true;
break;
case SpvDecorationNoUnsignedWrap:
alu->no_unsigned_wrap = true;
break;
default:
/* Do nothing. */
break;
}
}
static void
vtn_value_is_relaxed_precision_cb(struct vtn_builder *b,
struct vtn_value *val, int member,
const struct vtn_decoration *dec, void *void_ctx)
{
bool *relaxed_precision = void_ctx;
switch (dec->decoration) {
case SpvDecorationRelaxedPrecision:
*relaxed_precision = true;
break;
default:
break;
}
}
bool
vtn_value_is_relaxed_precision(struct vtn_builder *b, struct vtn_value *val)
{
bool result = false;
vtn_foreach_decoration(b, val,
vtn_value_is_relaxed_precision_cb, &result);
return result;
}
static bool
vtn_alu_op_mediump_16bit(struct vtn_builder *b, SpvOp opcode, struct vtn_value *dest_val)
{
if (!b->options->mediump_16bit_alu || !vtn_value_is_relaxed_precision(b, dest_val))
if (!b->options->mediump_16bit_alu ||
!vtn_has_decoration(b, dest_val, SpvDecorationRelaxedPrecision))
return false;
switch (opcode) {
@ -790,7 +729,7 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
return;
}
vtn_handle_no_contraction(b, dest_val);
b->nb.exact |= vtn_has_decoration(b, dest_val, SpvDecorationNoContraction);
vtn_handle_fp_fast_math(b, dest_val);
bool mediump_16bit = vtn_alu_op_mediump_16bit(b, opcode, dest_val);
@ -1148,7 +1087,8 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
case SpvOpShiftLeftLogical:
case SpvOpSNegate: {
nir_alu_instr *alu = nir_def_as_alu(dest->def);
vtn_foreach_decoration(b, dest_val, handle_no_wrap, alu);
alu->no_signed_wrap |= vtn_has_decoration(b, dest_val, SpvDecorationNoSignedWrap);
alu->no_unsigned_wrap |= vtn_has_decoration(b, dest_val, SpvDecorationNoUnsignedWrap);
break;
}
default:
@ -1171,7 +1111,7 @@ vtn_handle_integer_dot(struct vtn_builder *b, SpvOp opcode,
const struct glsl_type *dest_type = vtn_get_type(b, w[1])->type;
const unsigned dest_size = glsl_get_bit_size(dest_type);
vtn_handle_no_contraction(b, dest_val);
b->nb.exact |= vtn_has_decoration(b, dest_val, SpvDecorationNoContraction);
/* Collect the various SSA sources.
*

View file

@ -570,7 +570,7 @@ vtn_handle_phis_first_pass(struct vtn_builder *b, SpvOp opcode,
nir_local_variable_create(b->nb.impl, type->type, "phi");
struct vtn_value *phi_val = vtn_untyped_value(b, w[2]);
if (vtn_value_is_relaxed_precision(b, phi_val))
if (vtn_has_decoration(b, phi_val, SpvDecorationRelaxedPrecision))
phi_var->data.precision = GLSL_PRECISION_MEDIUM;
_mesa_hash_table_insert(b->phi_table, w, phi_var);

View file

@ -322,7 +322,8 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,
break;
default:
mediump_16bit = b->options->mediump_16bit_alu && vtn_value_is_relaxed_precision(b, dest_val);
mediump_16bit = b->options->mediump_16bit_alu &&
vtn_has_decoration(b, dest_val, SpvDecorationRelaxedPrecision);
break;
}
@ -343,7 +344,7 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,
struct vtn_ssa_value *dest = vtn_create_ssa_value(b, dest_type);
vtn_handle_no_contraction(b, vtn_untyped_value(b, w[2]));
b->nb.exact |= vtn_has_decoration(b, vtn_untyped_value(b, w[2]), SpvDecorationNoContraction);
switch (entrypoint) {
case GLSLstd450Radians:
dest->def = nir_radians(nb, src[0]);

View file

@ -987,8 +987,6 @@ void vtn_handle_integer_dot(struct vtn_builder *b, SpvOp opcode,
void vtn_handle_bitcast(struct vtn_builder *b, const uint32_t *w,
unsigned count);
void vtn_handle_no_contraction(struct vtn_builder *b, struct vtn_value *val);
void vtn_handle_fp_fast_math(struct vtn_builder *b, struct vtn_value *val);
void vtn_handle_subgroup(struct vtn_builder *b, SpvOp opcode,
@ -1058,7 +1056,6 @@ SpvMemorySemanticsMask vtn_mode_to_memory_semantics(enum vtn_variable_mode mode)
void vtn_emit_memory_barrier(struct vtn_builder *b, SpvScope scope,
SpvMemorySemanticsMask semantics);
bool vtn_value_is_relaxed_precision(struct vtn_builder *b, struct vtn_value *val);
nir_def *
vtn_mediump_downconvert(struct vtn_builder *b, enum glsl_base_type base_type, nir_def *def);
struct vtn_ssa_value *

View file

@ -2649,22 +2649,6 @@ vtn_emit_make_available_barrier(struct vtn_builder *b, SpvMemoryAccessMask acces
vtn_mode_to_memory_semantics(mode));
}
static void
ptr_nonuniform_workaround_cb(struct vtn_builder *b, struct vtn_value *val,
int member, const struct vtn_decoration *dec, void *void_ptr)
{
enum gl_access_qualifier *access = void_ptr;
switch (dec->decoration) {
case SpvDecorationNonUniformEXT:
*access |= ACCESS_NON_UNIFORM;
break;
default:
break;
}
}
struct vtn_pointer *
vtn_cast_pointer(struct vtn_builder *b, struct vtn_pointer *p,
struct vtn_type *pointed)
@ -2836,7 +2820,8 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
}
/* Workaround for https://gitlab.freedesktop.org/mesa/mesa/-/issues/3406 */
vtn_foreach_decoration(b, link_val, ptr_nonuniform_workaround_cb, &access);
if (vtn_has_decoration(b, link_val, SpvDecorationNonUniformEXT))
access |= ACCESS_NON_UNIFORM;
idx++;
}