From 73c563ffb7f07d43f8fd768768558c3b280ce3dc Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Thu, 16 Nov 2023 17:57:58 +0100 Subject: [PATCH] vkd3d-shader/d3dbc: Adjust the token count for DEF and DEFI instructions in shader_sm1_skip_opcode(). This was broken by commit e390bc35e2c9b0a2110370f916033eea2366317e; that commit fixed the source count for these instructions, but didn't adjust shader_sm1_skip_opcode(). Note that this only affects shader model 1; later versions have a token count embedded in the initial opcode token. --- libs/vkd3d-shader/d3dbc.c | 8 ++++++++ tests/vkd3d_shader_api.c | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c index 7e0eac6c..3d139416 100644 --- a/libs/vkd3d-shader/d3dbc.c +++ b/libs/vkd3d-shader/d3dbc.c @@ -855,6 +855,14 @@ static void shader_sm1_skip_opcode(const struct vkd3d_shader_sm1_parser *sm1, co { *ptr += 2; } + /* Somewhat similarly, DEF and DEFI have a single source, but need to read + * four tokens for that source. See shader_sm1_read_immconst(). + * Technically shader model 1 doesn't have integer registers or DEFI; we + * handle it here anyway because it's easy. */ + else if (opcode_info->vkd3d_opcode == VKD3DSIH_DEF || opcode_info->vkd3d_opcode == VKD3DSIH_DEFI) + { + *ptr += 3; + } *ptr += (opcode_info->dst_count + opcode_info->src_count); } diff --git a/tests/vkd3d_shader_api.c b/tests/vkd3d_shader_api.c index 9fe5eec8..61c412c5 100644 --- a/tests/vkd3d_shader_api.c +++ b/tests/vkd3d_shader_api.c @@ -238,6 +238,13 @@ static void test_d3dbc(void) 0xfffe0100, /* vs_1_0 */ 0x0000ffff, /* end */ }; + static const uint32_t vs_dcl_def[] = + { + 0xfffe0101, /* vs_1_1 */ + 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */ + 0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, /* def c0, 1.0, 0.0, 0.0, 1.0 */ + 0x0000ffff, /* end */ + }; static const uint32_t invalid_type[] = { 0x00010100, /* _1_0 */ @@ -255,6 +262,10 @@ static void test_d3dbc(void) 0x0000ffff, /* end */ }; static const char expected[] = "vs_1_0\n"; + static const char expected_dcl_def[] = + "vs_1_1\n" + "dcl_position0 v0\n" + "def c0 = 1.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.00000000e+00\n"; info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO; info.next = NULL; @@ -291,6 +302,15 @@ static void test_d3dbc(void) rc = vkd3d_shader_compile(&info, &d3d_asm, NULL); ok(rc == VKD3D_ERROR_INVALID_SHADER, "Got unexpected error code %d.\n", rc); + info.source.code = vs_dcl_def; + info.source.size = sizeof(vs_dcl_def); + rc = vkd3d_shader_compile(&info, &d3d_asm, NULL); + ok(rc == VKD3D_OK, "Got unexpected error code %d.\n", rc); + ok(d3d_asm.size == strlen(expected_dcl_def), "Got unexpected size %zu.\n", d3d_asm.size); + ok(!memcmp(d3d_asm.code, expected_dcl_def, d3d_asm.size), "Got unexpected code \"%.*s\"\n", + (int)d3d_asm.size, (char *)d3d_asm.code); + vkd3d_shader_free_shader_code(&d3d_asm); + info.source.code = invalid_type; info.source.size = sizeof(invalid_type); rc = vkd3d_shader_compile(&info, &d3d_asm, NULL);