nir/validate: add some (light) validation for sampler type matching

this adds minimal validation for tex ops with derefs to check that the
dest type integer-ness matches the sampled type's integer-ness

the aim is to provide the most basic validation that nir is being modified
and created consistently, not to perform exact verification that
the types are identical

fix #6985

Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17874>
This commit is contained in:
Mike Blumenkrantz
2022-08-03 10:58:03 -04:00
committed by Marge Bot
parent b7eda568a4
commit c37c6ac613

View File

@@ -899,6 +899,31 @@ validate_tex_instr(nir_tex_instr *instr, validate_state *state)
validate_assert(state, glsl_type_is_image(deref->type) ||
glsl_type_is_texture(deref->type) ||
glsl_type_is_sampler(deref->type));
switch (instr->op) {
case nir_texop_descriptor_amd:
break;
case nir_texop_lod:
validate_assert(state, nir_alu_type_get_base_type(instr->dest_type) == nir_type_float);
break;
case nir_texop_samples_identical:
validate_assert(state, nir_alu_type_get_base_type(instr->dest_type) == nir_type_bool);
break;
case nir_texop_txs:
case nir_texop_texture_samples:
case nir_texop_query_levels:
case nir_texop_fragment_mask_fetch_amd:
case nir_texop_txf_ms_mcs_intel:
validate_assert(state, nir_alu_type_get_base_type(instr->dest_type) == nir_type_int ||
nir_alu_type_get_base_type(instr->dest_type) == nir_type_uint);
break;
default:
validate_assert(state,
glsl_get_sampler_result_type(deref->type) == GLSL_TYPE_VOID ||
glsl_base_type_is_integer(glsl_get_sampler_result_type(deref->type)) ==
(nir_alu_type_get_base_type(instr->dest_type) == nir_type_int ||
nir_alu_type_get_base_type(instr->dest_type) == nir_type_uint));
}
break;
}