From 1b113876f86f62c58e306f36570cfc61ed084091 Mon Sep 17 00:00:00 2001 From: Mariusz Sikora Date: Wed, 29 Nov 2023 09:04:53 +0100 Subject: [PATCH] Add tests for Deduplicate constant data tables --- .../general/TestDeduplicateConstTables.frag | 98 ++++++++++ .../general/TestDeduplicateConstTables.spvasm | 174 ++++++++++++++++++ 2 files changed, 272 insertions(+) create mode 100644 llpc/test/shaderdb/general/TestDeduplicateConstTables.frag create mode 100644 llpc/test/shaderdb/general/TestDeduplicateConstTables.spvasm diff --git a/llpc/test/shaderdb/general/TestDeduplicateConstTables.frag b/llpc/test/shaderdb/general/TestDeduplicateConstTables.frag new file mode 100644 index 0000000000..58d1f2c6ab --- /dev/null +++ b/llpc/test/shaderdb/general/TestDeduplicateConstTables.frag @@ -0,0 +1,98 @@ +// BEGIN_SHADERTEST +// RUN: amdllpc -v %gfxip %s | FileCheck -check-prefix=SHADERTEST %s +// SHADERTEST-LABEL: {{^// LLPC}} SPIRV-to-LLVM translation results +// SHADERTEST: @indexable = addrspace(5) constant [28 x <4 x i32>] [<4 x i32> ] [<4 x i32> ] [<4 x i32> ], ptr addrspace(5) @indexable, i32 +// SHADERTEST: getelementptr [28 x <4 x i32>], ptr addrspace(5) @indexable.1, i32 +// SHADERTEST: getelementptr [28 x <4 x i32>], ptr addrspace(5) @indexable.2, i32 +// +// SHADERTEST-LABEL: {{^// LLPC}} SPIR-V lowering results +// SHADERTEST: @__llpc_global_proxy_indexable.2 = internal unnamed_addr addrspace(4) constant [28 x <4 x i32>] [<4 x i32> ], ptr addrspace(4) @__llpc_global_proxy_indexable.2, i64 +// SHADERTEST: getelementptr [28 x <4 x i32>], ptr addrspace(4) @__llpc_global_proxy_indexable.2, i64 +// SHADERTEST: getelementptr [28 x <4 x i32>], ptr addrspace(4) @__llpc_global_proxy_indexable.2, i64 +// SHADERTEST: AMDLLPC SUCCESS +// END_SHADERTEST + + +#version 460 + +const uvec4 _211[28] = uvec4[](uvec4(1059055552u, 1057692236u, 1062465857u, 0u), uvec4(3188284415u, 3211912104u, 1064587336u, 0u), uvec4(1053197116u, 3202258829u, 1058349232u, 0u), uvec4(1039685418u, 3192222363u, 1047084841u, 0u), uvec4(3192964587u, 1038352636u, 1047388173u, 0u), uvec4(1062520215u, 3197474974u, 1063356727u, 0u), uvec4(1037850661u, 3205763422u, 1058446204u, 0u), uvec4(1049678263u, 1061836040u, 1062659634u, 0u), uvec4(3199959344u, 1053446761u, 1057614893u, 0u), uvec4(1061258065u, 1046506363u, 1061780340u, 0u), uvec4(3204886141u, 1019442700u, 1057411553u, 0u), uvec4(3210859837u, 3195704642u, 1063935038u, 0u), uvec4(3204075131u, 3197512555u, 1058140859u, 0u), uvec4(1054956040u, 3182380177u, 1055232528u, 0u), uvec4(1046011770u, 1057194959u, 1057898596u, 0u), uvec4(1029739884u, 1064631963u, 1064658304u, 0u), uvec4(3205958373u, 3207889095u, 1064000637u, 0u), uvec4(3209492326u, 1048328368u, 1062629938u, 0u), uvec4(3192317658u, 3191631805u, 1049165551u, 0u), uvec4(3202323254u, 1061452681u, 1063390953u, 0u), uvec4(1046338590u, 1038982117u, 1048292130u, 0u), uvec4(1042332191u, 3210420945u, 1063176708u, 0u), uvec4(3208780301u, 1058367687u, 1064628776u, 0u), uvec4(1065233091u, 3169707339u, 1065240305u, 0u), uvec4(3194203417u, 3205774830u, 1058982739u, 0u), uvec4(1057812193u, 3207297698u, 1063122517u, 0u), uvec4(1055767050u, 1049621221u, 1057682673u, 0u), uvec4(3180576291u, 1058735275u, 1058807082u, 0u)); + +layout(set = 1, binding = 0, std140) uniform _14_16 +{ + vec4 _m0; + vec4 _m1; + vec4 _m2; +} _16; + +layout(set = 0, binding = 0) uniform sampler2D _33; + +layout(location = 0) in vec2 vs_TEXCOORD1; +layout(location = 0) out vec4 _354; +vec4 _9; +vec4 _39; +float _54; +vec3 _69; +vec3 _75; +vec3 _79; +float _81; +vec4 _94; +vec4 _245; +vec2 _255; +bool _264; +vec2 _281; +int _374; + +void main() +{ + vec2 _27 = (vs_TEXCOORD1 * _16._m1.xy) + _16._m1.zw; + _9 = vec4(_27.x, _27.y, _9.z, _9.w); + _9 = texture(_33, _9.xy).xwyz; + _39 = _9.yyyy * _16._m0.xyxy; + _39 *= _16._m2.wwww; + _54 = _9.y * 0.25; + _54 = max(_54, _16._m2.z); + _69 = _9.xzw * vec3(_54); + _75.x = 1.2000000476837158203125; + _79 = _69; + _81 = _54; + for (int _84 = 0; _84 < 28; _84++) + { + _94 = _39 * uintBitsToFloat(_211[_84].xyxy); + _75.z = uintBitsToFloat(_211[_84].z); + _94 /= _75.xxzz; + _94 += vs_TEXCOORD1.xyxy; + _94 = (_94 * _16._m1.xyxy) + _16._m1.zwzw; + _245 = texture(_33, _94.xy); + _94 = texture(_33, _94.zw); + _255.x = _94.w + _245.w; + _264 = 0.0 < _255.x; + if (_264) + { + _9.x = _9.y * uintBitsToFloat(_211[_84].z); + _281.x = _245.w; + _281.y = _94.w; + _255 = ((-_9.xy) * vec2(0.833333313465118408203125, 1.0)) + _281; + _255 += vec2(0.26499998569488525390625); + _255 *= vec2(3.7735850811004638671875); + _255 = clamp(_255, vec2(0.0), vec2(1.0)); + _281 = (_255 * vec2(-2.0)) + vec2(3.0); + _255 *= _255; + _255 *= _281; + vec3 _326 = _255.yyy * _94.xyz; + _94 = vec4(_326.x, _326.y, _326.z, _94.w); + vec3 _336 = (_245.xyz * _255.xxx) + _94.xyz; + _94 = vec4(_336.x, _336.y, _336.z, _94.w); + _79 += _94.xyz; + _9.x = dot(_255, vec2(1.0)); + _81 = _9.x + _81; + } + } + vec3 _358 = _79 / vec3(_81); + _354 = vec4(_358.x, _358.y, _358.z, _354.w); + _354.w = 1.0; +} + diff --git a/llpc/test/shaderdb/general/TestDeduplicateConstTables.spvasm b/llpc/test/shaderdb/general/TestDeduplicateConstTables.spvasm new file mode 100644 index 0000000000..a57404d529 --- /dev/null +++ b/llpc/test/shaderdb/general/TestDeduplicateConstTables.spvasm @@ -0,0 +1,174 @@ +; BEGIN_SHADERTEST +; RUN: amdllpc -v %gfxip %s | FileCheck -check-prefix=SHADERTEST %s +; SHADERTEST-LABEL: {{^// LLPC}} SPIRV-to-LLVM translation results +; SHADERTEST: store [5 x <4 x i32>] [<4 x i32> ] [<4 x i32> ] [<4 x i32> ] [<4 x i32> ], ptr addrspace(4) @0 +; SHADERTEST: getelementptr [5 x <4 x i32>], ptr addrspace(4) @0 +; SHADERTEST: getelementptr [5 x <4 x i32>], ptr addrspace(4) @0 +; SHADERTEST: AMDLLPC SUCCESS +; END_SHADERTEST + + +; SPIR-V +; Version: 1.6 +; Generator: Khronos Glslang Reference Front End; 11 +; Bound: 112 +; Schema: 0 + OpCapability Shader + %1 = OpExtInstImport "GLSL.std.450" + OpMemoryModel Logical GLSL450 + OpEntryPoint Fragment %main "main" %vs_TEXCOORD1 %_16 %_354 + OpExecutionMode %main OriginUpperLeft + OpSource GLSL 460 + OpName %main "main" + OpName %_84 "_84" + OpName %t1 "t1" + OpName %vs_TEXCOORD1 "vs_TEXCOORD1" + OpName %_14_16 "_14_16" + OpMemberName %_14_16 0 "_m0" + OpMemberName %_14_16 1 "_m1" + OpMemberName %_14_16 2 "_m2" + OpName %_16 "_16" + OpName %t2 "t2" + OpName %t3 "t3" + OpName %_354 "_354" + OpDecorate %vs_TEXCOORD1 Location 0 + OpMemberDecorate %_14_16 0 Offset 0 + OpMemberDecorate %_14_16 1 Offset 16 + OpMemberDecorate %_14_16 2 Offset 32 + OpDecorate %_14_16 Block + OpDecorate %_16 DescriptorSet 1 + OpDecorate %_16 Binding 0 + OpDecorate %_354 Location 0 + %void = OpTypeVoid + %3 = OpTypeFunction %void + %int = OpTypeInt 32 1 +%_ptr_Function_int = OpTypePointer Function %int + %int_0 = OpConstant %int 0 + %int_5 = OpConstant %int 5 + %bool = OpTypeBool + %float = OpTypeFloat 32 + %v4float = OpTypeVector %float 4 +%_ptr_Function_v4float = OpTypePointer Function %v4float + %v2float = OpTypeVector %float 2 +%_ptr_Input_v2float = OpTypePointer Input %v2float +%vs_TEXCOORD1 = OpVariable %_ptr_Input_v2float Input + %_14_16 = OpTypeStruct %v4float %v4float %v4float +%_ptr_Uniform__14_16 = OpTypePointer Uniform %_14_16 + %_16 = OpVariable %_ptr_Uniform__14_16 Uniform + %int_2 = OpConstant %int 2 +%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float + %uint = OpTypeInt 32 0 + %v4uint = OpTypeVector %uint 4 + %uint_5 = OpConstant %uint 5 +%_arr_v4uint_uint_5 = OpTypeArray %v4uint %uint_5 +%uint_1059055552 = OpConstant %uint 1059055552 +%uint_1057692236 = OpConstant %uint 1057692236 +%uint_1062465857 = OpConstant %uint 1062465857 + %uint_0 = OpConstant %uint 0 + %48 = OpConstantComposite %v4uint %uint_1059055552 %uint_1057692236 %uint_1062465857 %uint_0 +%uint_3188284415 = OpConstant %uint 3188284415 +%uint_3211912104 = OpConstant %uint 3211912104 +%uint_1064587336 = OpConstant %uint 1064587336 + %52 = OpConstantComposite %v4uint %uint_3188284415 %uint_3211912104 %uint_1064587336 %uint_0 +%uint_1053197116 = OpConstant %uint 1053197116 +%uint_3202258829 = OpConstant %uint 3202258829 +%uint_1058349232 = OpConstant %uint 1058349232 + %56 = OpConstantComposite %v4uint %uint_1053197116 %uint_3202258829 %uint_1058349232 %uint_0 +%uint_1039685418 = OpConstant %uint 1039685418 +%uint_3192222363 = OpConstant %uint 3192222363 +%uint_1047084841 = OpConstant %uint 1047084841 + %60 = OpConstantComposite %v4uint %uint_1039685418 %uint_3192222363 %uint_1047084841 %uint_0 +%uint_3192964587 = OpConstant %uint 3192964587 +%uint_1038352636 = OpConstant %uint 1038352636 +%uint_1047388173 = OpConstant %uint 1047388173 + %64 = OpConstantComposite %v4uint %uint_3192964587 %uint_1038352636 %uint_1047388173 %uint_0 + %65 = OpConstantComposite %_arr_v4uint_uint_5 %48 %52 %56 %60 %64 +%_ptr_Function__arr_v4uint_uint_5 = OpTypePointer Function %_arr_v4uint_uint_5 +%_ptr_Function_v4uint = OpTypePointer Function %v4uint +%_ptr_Function_float = OpTypePointer Function %float + %int_1 = OpConstant %int 1 +%_ptr_Uniform_float = OpTypePointer Uniform %float + %uint_2 = OpConstant %uint 2 +%_ptr_Function_uint = OpTypePointer Function %uint +%_ptr_Input_float = OpTypePointer Input %float +%_ptr_Output_v4float = OpTypePointer Output %v4float + %_354 = OpVariable %_ptr_Output_v4float Output + %main = OpFunction %void None %3 + %5 = OpLabel + %_84 = OpVariable %_ptr_Function_int Function + %t1 = OpVariable %_ptr_Function_v4float Function + %indexable = OpVariable %_ptr_Function__arr_v4uint_uint_5 Function + %t2 = OpVariable %_ptr_Function_float Function +%indexable_0 = OpVariable %_ptr_Function__arr_v4uint_uint_5 Function + %t3 = OpVariable %_ptr_Function_float Function +%indexable_1 = OpVariable %_ptr_Function__arr_v4uint_uint_5 Function + OpStore %indexable %65 + OpStore %indexable_0 %65 + OpStore %indexable_1 %65 + OpStore %_84 %int_0 + OpBranch %10 + %10 = OpLabel + OpLoopMerge %12 %13 None + OpBranch %14 + %14 = OpLabel + %15 = OpLoad %int %_84 + %18 = OpSLessThan %bool %15 %int_5 + OpBranchConditional %18 %11 %12 + %11 = OpLabel + %26 = OpLoad %v2float %vs_TEXCOORD1 + %32 = OpAccessChain %_ptr_Uniform_v4float %_16 %int_2 + %33 = OpLoad %v4float %32 + %34 = OpVectorShuffle %v2float %33 %33 0 3 + %35 = OpCompositeExtract %float %26 0 + %36 = OpCompositeExtract %float %26 1 + %37 = OpCompositeExtract %float %34 0 + %38 = OpCompositeExtract %float %34 1 + %39 = OpCompositeConstruct %v4float %35 %36 %37 %38 + %66 = OpLoad %int %_84 + %70 = OpAccessChain %_ptr_Function_v4uint %indexable %66 + %71 = OpLoad %v4uint %70 + %72 = OpVectorShuffle %v4uint %71 %71 0 1 0 1 + %73 = OpBitcast %v4float %72 + %74 = OpFMul %v4float %39 %73 + OpStore %t1 %74 + %79 = OpAccessChain %_ptr_Uniform_float %_16 %int_1 %uint_0 + %80 = OpLoad %float %79 + %81 = OpLoad %int %_84 + %85 = OpAccessChain %_ptr_Function_uint %indexable_0 %81 %uint_2 + %86 = OpLoad %uint %85 + %87 = OpBitcast %float %86 + %88 = OpFMul %float %80 %87 + OpStore %t2 %88 + %91 = OpAccessChain %_ptr_Input_float %vs_TEXCOORD1 %uint_0 + %92 = OpLoad %float %91 + %93 = OpLoad %int %_84 + %95 = OpAccessChain %_ptr_Function_uint %indexable_1 %93 %uint_2 + %96 = OpLoad %uint %95 + %97 = OpBitcast %float %96 + %98 = OpFMul %float %92 %97 + OpStore %t3 %98 + %101 = OpLoad %v4float %t1 + %102 = OpVectorShuffle %v2float %101 %101 0 3 + %103 = OpLoad %float %t2 + %104 = OpLoad %float %t3 + %105 = OpCompositeExtract %float %102 0 + %106 = OpCompositeExtract %float %102 1 + %107 = OpCompositeConstruct %v4float %105 %106 %103 %104 + %108 = OpLoad %v4float %_354 + %109 = OpFAdd %v4float %108 %107 + OpStore %_354 %109 + OpBranch %13 + %13 = OpLabel + %110 = OpLoad %int %_84 + %111 = OpIAdd %int %110 %int_1 + OpStore %_84 %111 + OpBranch %10 + %12 = OpLabel + OpReturn + OpFunctionEnd