From: Giovanni Mascellani gmascellani@codeweavers.com
--- tests/vkd3d_shader_api.c | 171 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+)
diff --git a/tests/vkd3d_shader_api.c b/tests/vkd3d_shader_api.c index 00dcd2248..a85cc1480 100644 --- a/tests/vkd3d_shader_api.c +++ b/tests/vkd3d_shader_api.c @@ -1038,6 +1038,176 @@ static void test_scan_combined_resource_samplers(void) pfn_free_combined_sampler_info(&combined_sampler_info); }
+static void test_emit_signature(void) +{ + static const struct emit_signature_test + { + const char *source; + const char *signature; + bool hlsl_todo; + bool signature_todo; + } tests[] = + { + { + "float4 main() : SV_Target\n" + "{\n" + " return float4(1.0, 2.0, 3.0, 4.0);\n" + "}\n", + ".output\n" + ".param SV_Target.xyzw, v0.xyzw, float, TARGET\n", + false, false + }, + { + "void main(float4 pos : SV_POSITION, float3 color : COLOR2, uint2 color2 : COLOR5,\n" + " out int3 target : sv_target1, out float target2 : SV_TaRgEt5)\n" + "{\n" + " float tmp = length(pos) + length(color) + length(color2);\n" + " target.xyz = tmp;\n" + " target2 = tmp;\n" + "}\n", + ".input\n" + ".param SV_POSITION.xyzw, v0.xyzw, float, POS\n" + ".param COLOR2.xyz, v1.xyz, float\n" + ".param COLOR5.xy, v2.xy, uint\n" + ".output\n" + ".param sv_target1.xyz, v1.xyz, int, TARGET\n" + ".param SV_TaRgEt5.x, v5.x, float, TARGET\n", + false, false + }, + { + "void main(float4 pos : SV_Position, float3 color : COLOR2, uint2 color2 : COLOR5,\n" + " out int3 target : SV_Target1, out float target2 : SV_Target5)\n" + "{\n" + " float tmp = pos.x + pos.w + color.y + color.z + color2.x;\n" + " target.xz = tmp;\n" + " target2 = tmp;\n" + "}\n", + ".input\n" + ".param SV_Position.xyzw, v0.xw, float, POS\n" + ".param COLOR2.xyz, v1.yz, float\n" + ".param COLOR5.xy, v2.x, uint\n" + ".output\n" + ".param SV_Target1.xyz, v1.xz, int, TARGET\n" + ".param SV_Target5.x, v5.x, float, TARGET\n", + false, true + }, + { + "void main(float4 pos : SV_Position, float3 color : COLOR2, uint2 color2 : COLOR5,\n" + " float2 clip : SV_ClipDistance0, float3 clip2 : SV_ClipDistance1,\n" + " float1 cull : SV_CullDistance0, float cull2 : SV_CullDistance1,\n" + " uint prim : SV_PrimitiveID, uint inst : SV_InstanceID,\n" + " bool front : SV_IsFrontFace0, uint sample : SV_SampleIndex,\n" + " out int3 target : SV_Target1, out float target2 : SV_Target5,\n" + " out float depth : SV_Depth)\n" + "{\n" + " float tmp = color.y + color.z + color2 + pos.x + pos.w + clip.x + clip2.x + clip2.z\n" + " + cull.x + cull2 + prim + front + sample;\n" + " target.xz = tmp;\n" + " target2 = tmp;\n" + " depth = tmp;\n" + "}\n", + ".input\n" + ".param SV_Position.xyzw, v0.xw, float, POS\n" + ".param COLOR2.xyz, v1.yz, float\n" + ".param COLOR5.xy, v2.x, uint\n" + ".param SV_PrimitiveID.z, v2.z, uint, PRIMID\n" + ".param SV_InstanceID.w, v2.w, uint\n" + ".param SV_ClipDistance.xy, v3.x, float, CLIPDST\n" + ".param SV_CullDistance.z, v3.z, float, CULLDST\n" + ".param SV_CullDistance1.w, v3.w, float, CULLDST\n" + ".param SV_ClipDistance1.xyz, v4.xz, float, CLIPDST\n" + ".param SV_IsFrontFace.x, v5.x, uint, FFACE\n" + ".param SV_SampleIndex.y, v5.y, uint, SAMPLE\n" + ".output\n" + ".param SV_Target1.xyz, v1.xz, int, TARGET\n" + ".param SV_Target5.x, v5.x, float, TARGET\n" + ".param SV_Depth, oDepth, float, DEPTH\n", + true, true + }, + { + "float4 main(out float depth : SV_DEPTHGreaterEqual) : SV_Target\n" + "{\n" + " depth = 0.5;\n" + " return float4(1.0, 2.0, 3.0, 4.0);\n" + "}\n", + ".output\n" + ".param SV_Target.xyzw, v0.xyzw, float, TARGET\n" + ".param SV_DEPTHGreaterEqual, oDepthGE, float, DEPTHGE\n", + true, true + }, + { + "float4 main(out float depth : SV_DEPTHlessEQUAL) : SV_Target\n" + "{\n" + " depth = 0.5;\n" + " return float4(1.0, 2.0, 3.0, 4.0);\n" + "}\n", + ".output\n" + ".param SV_Target.xyzw, v0.xyzw, float, TARGET\n" + ".param SV_DEPTHlessEQUAL, oDepthLE, float, DEPTHLE\n", + true, true + }, + }; + + struct vkd3d_shader_hlsl_source_info hlsl_info = + { + .type = VKD3D_SHADER_STRUCTURE_TYPE_HLSL_SOURCE_INFO, + .entry_point = "main", + .profile = "ps_5_0", + }; + struct vkd3d_shader_compile_info compile_info = + { + .type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO, + .next = &hlsl_info, + .source_type = VKD3D_SHADER_SOURCE_HLSL, + .target_type = VKD3D_SHADER_TARGET_DXBC_TPF, + .log_level = VKD3D_SHADER_LOG_NONE, + }; + struct vkd3d_shader_compile_option disassemble_options[] = + { + { .name = VKD3D_SHADER_COMPILE_OPTION_EMIT_SIGNATURE, .value = 1 }, + }; + struct vkd3d_shader_compile_info disassemble_info = + { + .type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO, + .source_type = VKD3D_SHADER_SOURCE_DXBC_TPF, + .target_type = VKD3D_SHADER_TARGET_D3D_ASM, + .options = disassemble_options, + .option_count = ARRAY_SIZE(disassemble_options), + .log_level = VKD3D_SHADER_LOG_NONE, + }; + struct vkd3d_shader_code dxbc, disasm; + unsigned int i; + char *ptr; + int rc; + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + const struct emit_signature_test *test = &tests[i]; + + compile_info.source.code = test->source; + compile_info.source.size = strlen(test->source); + rc = vkd3d_shader_compile(&compile_info, &dxbc, NULL); + todo_if(test->hlsl_todo) + ok(rc == VKD3D_OK, "Cannot compile HLSL shader, rc %d.\n", rc); + + if (rc != VKD3D_OK) + continue; + + disassemble_info.source = dxbc; + rc = vkd3d_shader_compile(&disassemble_info, &disasm, NULL); + ok(rc == VKD3D_OK, "Cannot disassemble shader, rc %d.\n", rc); + + ptr = strstr(disasm.code, ".text\n"); + ok(ptr, "Cannot find text marker in disassembled code.\n"); + *ptr = '\0'; + todo_if(test->signature_todo) + ok(strcmp(disasm.code, test->signature) == 0, "Unexpected signature description.\n"); + + vkd3d_shader_free_shader_code(&dxbc); + vkd3d_shader_free_shader_code(&disasm); + } +} + START_TEST(vkd3d_shader_api) { setlocale(LC_ALL, ""); @@ -1051,4 +1221,5 @@ START_TEST(vkd3d_shader_api) run_test(test_scan_descriptors); run_test(test_build_varying_map); run_test(test_scan_combined_resource_samplers); + run_test(test_emit_signature); }