From: Nikolay Sivov nsivov@codeweavers.com
--- dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 184 +++++++++++++++++--------- 1 file changed, 122 insertions(+), 62 deletions(-)
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c index f99aba87753..9fe79b1ac44 100644 --- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c +++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c @@ -99,13 +99,14 @@ static void delete_directory(const WCHAR *dir) RemoveDirectoryW(path); }
-#define compile_shader(a, b) compile_shader_(__LINE__, a, b) -static ID3D10Blob *compile_shader_(unsigned int line, const char *source, const char *target) +#define compile_shader(a, b, c) compile_shader_(__LINE__, a, b, c) +static ID3D10Blob *compile_shader_(unsigned int line, const char *source, const char *target, + unsigned int flags) { ID3D10Blob *blob = NULL, *errors = NULL; HRESULT hr;
- hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", target, 0, 0, &blob, &errors); + hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", target, flags, 0, &blob, &errors); ok_(__FILE__, line)(hr == D3D_OK, "Failed to compile shader, hr %#lx.\n", hr); if (errors) { @@ -243,7 +244,7 @@ static void draw_quad_(unsigned int line, IDirect3DDevice9 *device, ID3D10Blob * hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration); ok_(__FILE__, line)(hr == D3D_OK, "Failed to set vertex declaration, hr %#lx.\n", hr);
- vs_code = compile_shader(vs_source, "vs_2_0"); + vs_code = compile_shader(vs_source, "vs_2_0", 0);
hr = IDirect3DDevice9_CreateVertexShader(device, ID3D10Blob_GetBufferPointer(vs_code), &vs); ok_(__FILE__, line)(hr == D3D_OK, "Failed to create vertex shader, hr %#lx.\n", hr); @@ -454,7 +455,7 @@ static void test_swizzle(void)
for (i = 0; i < ARRAY_SIZE(tests); ++i) { - ps_code = compile_shader(tests[i].source, "ps_2_0"); + ps_code = compile_shader(tests[i].source, "ps_2_0", 0); if (i == 0) { hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants); @@ -498,7 +499,7 @@ static void test_math(void) return; device = test_context.device;
- ps_code = compile_shader(ps_source, "ps_2_0"); + ps_code = compile_shader(ps_source, "ps_2_0", 0); hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants); ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); hr = ID3DXConstantTable_SetFloat(constants, device, "$u", 2.5f); @@ -553,7 +554,7 @@ static void test_conditionals(void) return; device = test_context.device;
- ps_code = compile_shader(ps_if_source, "ps_2_0"); + ps_code = compile_shader(ps_if_source, "ps_2_0", 0); draw_quad(device, ps_code); init_readback(device, &rb);
@@ -574,7 +575,7 @@ static void test_conditionals(void) release_readback(&rb); ID3D10Blob_Release(ps_code);
- todo_wine ps_code = compile_shader(ps_ternary_source, "ps_2_0"); + todo_wine ps_code = compile_shader(ps_ternary_source, "ps_2_0", 0); if (ps_code) { draw_quad(device, ps_code); @@ -636,7 +637,7 @@ static void test_float_vectors(void) return; device = test_context.device;
- ps_code = compile_shader(ps_indexing_source, "ps_2_0"); + ps_code = compile_shader(ps_indexing_source, "ps_2_0", 0); if (ps_code) { draw_quad(device, ps_code); @@ -648,7 +649,7 @@ static void test_float_vectors(void) ID3D10Blob_Release(ps_code); }
- ps_code = compile_shader(ps_uniform_indexing_source, "ps_2_0"); + ps_code = compile_shader(ps_uniform_indexing_source, "ps_2_0", 0); if (ps_code) { hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants); @@ -691,7 +692,7 @@ static void test_trig(void) return; device = test_context.device;
- ps_code = compile_shader(ps_source, "ps_2_0"); + ps_code = compile_shader(ps_source, "ps_2_0", 0); if (ps_code) { draw_quad(device, ps_code); @@ -730,7 +731,7 @@ static void test_comma(void) if (!init_test_context(&test_context)) return;
- ps_code = compile_shader(ps_source, "ps_2_0"); + ps_code = compile_shader(ps_source, "ps_2_0", 0); draw_quad(test_context.device, ps_code);
v = get_color_vec4(test_context.device, 0, 0); @@ -764,7 +765,7 @@ static void test_return(void) if (!init_test_context(&test_context)) return;
- ps_code = compile_shader(void_source, "ps_2_0"); + ps_code = compile_shader(void_source, "ps_2_0", 0); draw_quad(test_context.device, ps_code);
v = get_color_vec4(test_context.device, 0, 0); @@ -773,7 +774,7 @@ static void test_return(void)
ID3D10Blob_Release(ps_code);
- ps_code = compile_shader(implicit_conversion_source, "ps_2_0"); + ps_code = compile_shader(implicit_conversion_source, "ps_2_0", 0); if (ps_code) { draw_quad(test_context.device, ps_code); @@ -809,7 +810,7 @@ static void test_array_dimensions(void) if (!init_test_context(&test_context)) return;
- todo_wine ps_code = compile_shader(shader, "ps_2_0"); + todo_wine ps_code = compile_shader(shader, "ps_2_0", 0); if (ps_code) { draw_quad(test_context.device, ps_code); @@ -826,11 +827,9 @@ static void test_array_dimensions(void)
static void test_majority(void) { - static const D3DXMATRIX matrix = {{{0.1, 0.2, 0.0, 0.0, 0.3, 0.4}}}; + static const float data[] = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f }; struct test_context test_context; - ID3DXConstantTable *constants; ID3D10Blob *ps_code = NULL; - IDirect3DDevice9 *device; struct vec4 v; HRESULT hr;
@@ -838,71 +837,132 @@ static void test_majority(void) "typedef float2x2 matrix_t;\n" "typedef row_major matrix_t row_matrix_t;\n" "typedef column_major matrix_t col_matrix_t;\n" - "uniform row_matrix_t r;\n" - "uniform col_matrix_t c;\n" + "uniform row_matrix_t m1;\n" + "uniform col_matrix_t m2;\n" "float4 main() : COLOR\n" "{\n" " float4 ret;\n" - " ret.xy = mul(r, float2(0.5, 0.6));\n" - " ret.zw = mul(c, float2(0.5, 0.6));\n" + " ret.xy = m1[0];\n" + " ret.zw = m2[0];\n" " return ret;\n" "}";
- static const char ps_default_source[] = + static const char ps_pragmas_source[] = "#pragma pack_matrix(row_major)\n" - "uniform float2x2 r;\n" + "uniform float2x2 m1;\n" "#pragma pack_matrix(column_major)\n" - "uniform float2x2 c;\n" + "uniform float2x2 m2;\n" + "float4 main() : COLOR\n" + "{\n" + " float4 ret;\n" + " ret.xy = m1[0];\n" + " ret.zw = m2[0];\n" + " return ret;\n" + "}"; + + static const char ps_row_source[] = + "uniform row_major float2x2 m1;\n" + "uniform row_major float2x2 m2;\n" + "float4 main() : COLOR\n" + "{\n" + " float4 ret;\n" + " ret.xy = m1[0];\n" + " ret.zw = m2[0];\n" + " return ret;\n" + "}"; + + static const char ps_column_source[] = + "uniform column_major float2x2 m1;\n" + "uniform column_major float2x2 m2;\n" + "float4 main() : COLOR\n" + "{\n" + " float4 ret;\n" + " ret.xy = m1[0];\n" + " ret.zw = m2[0];\n" + " return ret;\n" + "}"; + + static const char ps_no_modifiers_source[] = + "uniform float2x2 m1;\n" + "uniform float2x2 m2;\n" "float4 main() : COLOR\n" "{\n" " float4 ret;\n" - " ret.xy = mul(r, float2(0.5, 0.6));\n" - " ret.zw = mul(c, float2(0.5, 0.6));\n" + " ret.xy = m1[0];\n" + " ret.zw = m2[0];\n" " return ret;\n" "}";
+ static const struct test + { + const char *code; + struct vec4 color; + unsigned int flags; + } + tests[] = + { + { ps_typedef_source, { 0.1f, 0.2f, 0.1f, 0.5f } }, + { ps_pragmas_source, { 0.1f, 0.2f, 0.1f, 0.5f } }, + { ps_row_source, { 0.1f, 0.2f, 0.1f, 0.2f } }, + { ps_column_source, { 0.1f, 0.5f, 0.1f, 0.5f } }, + { ps_no_modifiers_source, { 0.1f, 0.2f, 0.1f, 0.2f }, D3DCOMPILE_PACK_MATRIX_ROW_MAJOR }, + { ps_no_modifiers_source, { 0.1f, 0.5f, 0.1f, 0.5f }, D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR }, + { ps_pragmas_source, { 0.1f, 0.2f, 0.1f, 0.5f }, D3DCOMPILE_PACK_MATRIX_ROW_MAJOR }, + { ps_pragmas_source, { 0.1f, 0.2f, 0.1f, 0.5f }, D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR }, + }; + unsigned int i; + if (!init_test_context(&test_context)) return; - device = test_context.device;
- ps_code = compile_shader(ps_typedef_source, "ps_2_0"); - if (ps_code) + for (i = 0; i < ARRAY_SIZE(tests); ++i) { - hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants); - ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); - hr = ID3DXConstantTable_SetMatrix(constants, device, "r", &matrix); - ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); - hr = ID3DXConstantTable_SetMatrix(constants, device, "c", &matrix); - ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); - ID3DXConstantTable_Release(constants); + const struct vec4 *c = &tests[i].color;
- draw_quad(test_context.device, ps_code); + winetest_push_context("Test %u", i);
- v = get_color_vec4(test_context.device, 0, 0); - ok(compare_vec4(&v, 0.17f, 0.39f, 0.17f, 0.39f, 1), - "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w); + ps_code = compile_shader(tests[i].code, "ps_2_0", tests[i].flags); + if (ps_code) + { + ID3DXConstantTable *constants; + D3DXCONSTANT_DESC desc; + D3DXHANDLE h; + UINT count;
- ID3D10Blob_Release(ps_code); - } + hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
- ps_code = compile_shader(ps_default_source, "ps_2_0"); - if (ps_code) - { - hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants); - ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); - hr = ID3DXConstantTable_SetMatrix(constants, device, "r", &matrix); - ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); - hr = ID3DXConstantTable_SetMatrix(constants, device, "c", &matrix); - ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); - ID3DXConstantTable_Release(constants); + h = ID3DXConstantTable_GetConstantByName(constants, NULL, "m1"); + ok(!!h, "Failed to find a constant.\n"); + count = 1; + hr = ID3DXConstantTable_GetConstantDesc(constants, h, &desc, &count); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice9_SetPixelShaderConstantF(test_context.device, desc.RegisterIndex, + data, desc.RegisterCount); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
- draw_quad(test_context.device, ps_code); + h = ID3DXConstantTable_GetConstantByName(constants, NULL, "m2"); + ok(!!h, "Failed to find a constant.\n"); + count = 1; + hr = ID3DXConstantTable_GetConstantDesc(constants, h, &desc, &count); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice9_SetPixelShaderConstantF(test_context.device, desc.RegisterIndex, + data, desc.RegisterCount); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
- v = get_color_vec4(test_context.device, 0, 0); - ok(compare_vec4(&v, 0.17f, 0.39f, 0.17f, 0.39f, 1), + ID3DXConstantTable_Release(constants); + + draw_quad(test_context.device, ps_code); + + v = get_color_vec4(test_context.device, 0, 0); + todo_wine_if(i == 4) + ok(compare_vec4(&v, c->x, c->y, c->z, c->w, 1), "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
- ID3D10Blob_Release(ps_code); + ID3D10Blob_Release(ps_code); + } + + winetest_pop_context(); }
release_test_context(&test_context); @@ -935,7 +995,7 @@ static void test_struct_assignment(void) if (!init_test_context(&test_context)) return;
- ps_code = compile_shader(ps_source, "ps_2_0"); + ps_code = compile_shader(ps_source, "ps_2_0", 0); draw_quad(test_context.device, ps_code);
v = get_color_vec4(test_context.device, 0, 0); @@ -977,7 +1037,7 @@ static void test_struct_semantics(void) if (!init_test_context(&test_context)) return;
- ps_code = compile_shader(ps_source, "ps_2_0"); + ps_code = compile_shader(ps_source, "ps_2_0", 0); draw_quad(test_context.device, ps_code);
v = get_color_vec4(test_context.device, 64, 48); @@ -1016,7 +1076,7 @@ static void test_global_initializer(void) if (!init_test_context(&test_context)) return;
- todo_wine ps_code = compile_shader(ps_source, "ps_2_0"); + todo_wine ps_code = compile_shader(ps_source, "ps_2_0", 0); if (ps_code) { hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants); @@ -1103,7 +1163,7 @@ static void test_samplers(void) { hr = IDirect3DDevice9_Clear(test_context.device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 0, 0), 1.0f, 0); ok(hr == D3D_OK, "Test %u: Got unexpected hr %#lx.\n", i, hr); - ps_code = compile_shader(tests[i], "ps_2_0"); + ps_code = compile_shader(tests[i], "ps_2_0", 0); if (ps_code) { draw_quad(test_context.device, ps_code); @@ -1229,7 +1289,7 @@ static void test_constant_table(void) static const D3DXCONSTANT_DESC expect_fields_j = {"a", D3DXRS_FLOAT4, 0, 3, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 3, 3, 1, 0, 36};
- todo_wine ps_code = compile_shader(source, "ps_2_0"); + todo_wine ps_code = compile_shader(source, "ps_2_0", 0); if (!ps_code) return;