spirv/tests: add a test for force_tex_non_uniform

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33866>
This commit is contained in:
Samuel Pitoiset 2025-03-04 09:38:04 +01:00 committed by Marge Bot
parent 74e1cebd02
commit 40ea8c2edc
2 changed files with 94 additions and 0 deletions

View file

@ -84,6 +84,24 @@ protected:
return NULL;
}
nir_tex_instr *find_tex_instr(nir_texop op, unsigned index=0)
{
nir_function_impl *impl = nir_shader_get_entrypoint(shader);
nir_foreach_block(block, impl) {
nir_foreach_instr(instr, block) {
if (instr->type != nir_instr_type_tex ||
nir_instr_as_tex(instr)->op != op)
continue;
if (index == 0)
return nir_instr_as_tex(instr);
else
index--;
}
}
return NULL;
}
spirv_capabilities spirv_caps;
spirv_to_nir_options spirv_options;
nir_shader_compiler_options nir_options;

View file

@ -78,3 +78,79 @@ TEST_F(Workarounds, force_ssbo_non_uniform)
ASSERT_EQ(nir_intrinsic_access(intrinsic), ACCESS_NON_UNIFORM);
}
TEST_F(Workarounds, force_tex_non_uniform)
{
/*
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %color %coord
OpExecutionMode %main OriginUpperLeft
OpSource GLSL 460
OpName %main "main"
OpName %color "color"
OpName %samplerColor "samplerColor"
OpName %coord "coord"
OpDecorate %color Location 0
OpDecorate %samplerColor Binding 0
OpDecorate %samplerColor DescriptorSet 0
OpDecorate %coord Location 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
%color = OpVariable %_ptr_Output_v4float Output
%10 = OpTypeImage %float 2D 0 0 0 1 Unknown
%11 = OpTypeSampledImage %10
%_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
%samplerColor = OpVariable %_ptr_UniformConstant_11 UniformConstant
%v2float = OpTypeVector %float 2
%_ptr_Input_v2float = OpTypePointer Input %v2float
%coord = OpVariable %_ptr_Input_v2float Input
%main = OpFunction %void None %3
%5 = OpLabel
%14 = OpLoad %11 %samplerColor
%18 = OpLoad %v2float %coord
%19 = OpImageSampleImplicitLod %v4float %14 %18
OpStore %color %19
OpReturn
OpFunctionEnd
*/
static const uint32_t words[] = {
0x07230203, 0x00010000, 0x0008000b, 0x00000014, 0x00000000, 0x00020011,
0x00000001, 0x0006000b, 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e,
0x00000000, 0x0003000e, 0x00000000, 0x00000001, 0x0007000f, 0x00000004,
0x00000004, 0x6e69616d, 0x00000000, 0x00000009, 0x00000011, 0x00030010,
0x00000004, 0x00000007, 0x00030003, 0x00000002, 0x000001cc, 0x00040005,
0x00000004, 0x6e69616d, 0x00000000, 0x00040005, 0x00000009, 0x6f6c6f63,
0x00000072, 0x00060005, 0x0000000d, 0x706d6173, 0x4372656c, 0x726f6c6f,
0x00000000, 0x00040005, 0x00000011, 0x726f6f63, 0x00000064, 0x00040047,
0x00000009, 0x0000001e, 0x00000000, 0x00040047, 0x0000000d, 0x00000021,
0x00000000, 0x00040047, 0x0000000d, 0x00000022, 0x00000000, 0x00040047,
0x00000011, 0x0000001e, 0x00000000, 0x00020013, 0x00000002, 0x00030021,
0x00000003, 0x00000002, 0x00030016, 0x00000006, 0x00000020, 0x00040017,
0x00000007, 0x00000006, 0x00000004, 0x00040020, 0x00000008, 0x00000003,
0x00000007, 0x0004003b, 0x00000008, 0x00000009, 0x00000003, 0x00090019,
0x0000000a, 0x00000006, 0x00000001, 0x00000000, 0x00000000, 0x00000000,
0x00000001, 0x00000000, 0x0003001b, 0x0000000b, 0x0000000a, 0x00040020,
0x0000000c, 0x00000000, 0x0000000b, 0x0004003b, 0x0000000c, 0x0000000d,
0x00000000, 0x00040017, 0x0000000f, 0x00000006, 0x00000002, 0x00040020,
0x00000010, 0x00000001, 0x0000000f, 0x0004003b, 0x00000010, 0x00000011,
0x00000001, 0x00050036, 0x00000002, 0x00000004, 0x00000000, 0x00000003,
0x000200f8, 0x00000005, 0x0004003d, 0x0000000b, 0x0000000e, 0x0000000d,
0x0004003d, 0x0000000f, 0x00000012, 0x00000011, 0x00050057, 0x00000007,
0x00000013, 0x0000000e, 0x00000012, 0x0003003e, 0x00000009, 0x00000013,
0x000100fd, 0x00010038,
};
spirv_options.workarounds.force_tex_non_uniform = true;
get_nir(sizeof(words) / sizeof(words[0]), words, MESA_SHADER_FRAGMENT);
nir_tex_instr *tex_instr = find_tex_instr(nir_texop_tex, 0);
ASSERT_NE(tex_instr, nullptr);
ASSERT_TRUE(tex_instr->texture_non_uniform);
}