[PATCH] d3dcompiler/tests: Add some tests for matrix majority.
Matteo Bruni
mbruni at codeweavers.com
Tue Apr 14 02:21:27 CDT 2020
From: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
---
dlls/d3dcompiler_43/tests/hlsl_d3d11.c | 9 +-
dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 129 +++++++++++++++++++++++--
2 files changed, 129 insertions(+), 9 deletions(-)
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d11.c b/dlls/d3dcompiler_43/tests/hlsl_d3d11.c
index 8e37976d5ac..0dbbcc8d029 100644
--- a/dlls/d3dcompiler_43/tests/hlsl_d3d11.c
+++ b/dlls/d3dcompiler_43/tests/hlsl_d3d11.c
@@ -570,13 +570,15 @@ static void test_reflection(void)
" uint_t j;\n"
" float3x1 k;\n"
" row_major float3x1 l;\n"
+ "#pragma pack_matrix(row_major)\n"
+ " float3x1 o;\n"
"};\n"
"\n"
"float m;\n"
"\n"
"float4 main(uniform float4 n) : SV_POSITION\n"
"{\n"
- " return l._31 + m + n;\n"
+ " return o._31 + m + n;\n"
"}";
struct shader_variable
@@ -608,7 +610,8 @@ static void test_reflection(void)
{{"i", 100, 4}, {D3D_SVC_SCALAR, D3D_SVT_INT, 1, 1, 0, 0, 0, "int"}},
{{"j", 104, 4}, {D3D_SVC_SCALAR, D3D_SVT_UINT, 1, 1, 0, 0, 0, "uint_t"}},
{{"k", 112, 12}, {D3D_SVC_MATRIX_COLUMNS, D3D_SVT_FLOAT, 3, 1, 0, 0, 0, "float3x1"}},
- {{"l", 128, 36, D3D_SVF_USED}, {D3D_SVC_MATRIX_ROWS, D3D_SVT_FLOAT, 3, 1, 0, 0, 0, "float3x1"}},
+ {{"l", 128, 36}, {D3D_SVC_MATRIX_ROWS, D3D_SVT_FLOAT, 3, 1, 0, 0, 0, "float3x1"}},
+ {{"o", 176, 36, D3D_SVF_USED}, {D3D_SVC_MATRIX_ROWS, D3D_SVT_FLOAT, 3, 1, 0, 0, 0, "float3x1"}},
};
static const struct
@@ -620,7 +623,7 @@ static void test_reflection(void)
{
{{"$Globals", D3D_CT_CBUFFER, 1, 16}, &globals_vars},
{{"$Params", D3D_CT_CBUFFER, 1, 16}, ¶ms_vars},
- {{"b1", D3D_CT_CBUFFER, ARRAY_SIZE(buffer_vars), 176}, buffer_vars},
+ {{"b1", D3D_CT_CBUFFER, ARRAY_SIZE(buffer_vars), 224}, buffer_vars},
};
todo_wine vs_code = compile_shader(vs_source, "vs_5_0");
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
index b96ab166796..9ebc42147e3 100644
--- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
+++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
@@ -775,6 +775,90 @@ static void test_array_dimensions(void)
release_test_context(&test_context);
}
+static void test_majority(void)
+{
+ static const D3DXMATRIX matrix = {{{0.1, 0.2, 0.0, 0.0, 0.3, 0.4}}};
+ struct test_context test_context;
+ ID3DXConstantTable *constants;
+ ID3D10Blob *ps_code = NULL;
+ IDirect3DDevice9 *device;
+ struct vec4 v;
+ HRESULT hr;
+
+ static const char ps_typedef_source[] =
+ "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"
+ "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"
+ " return ret;\n"
+ "}";
+
+ static const char ps_default_source[] =
+ "#pragma pack_matrix(row_major)\n"
+ "uniform float2x2 r;\n"
+ "#pragma pack_matrix(column_major)\n"
+ "uniform float2x2 c;\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"
+ " return ret;\n"
+ "}";
+
+ if (!init_test_context(&test_context))
+ return;
+ device = test_context.device;
+
+ todo_wine ps_code = compile_shader(ps_typedef_source, "ps_2_0");
+ if (ps_code)
+ {
+ hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants);
+ ok(hr == D3D_OK, "Failed to get constant table, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetMatrix(constants, device, "r", &matrix);
+ ok(hr == D3D_OK, "Failed to get constant table, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetMatrix(constants, device, "c", &matrix);
+ ok(hr == D3D_OK, "Failed to get constant table, hr %#x.\n", hr);
+ ID3DXConstantTable_Release(constants);
+
+ draw_quad(test_context.device, ps_code);
+
+ 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);
+
+ ID3D10Blob_Release(ps_code);
+ }
+
+ todo_wine ps_code = compile_shader(ps_default_source, "ps_2_0");
+ if (ps_code)
+ {
+ hr = pD3DXGetShaderConstantTable(ID3D10Blob_GetBufferPointer(ps_code), &constants);
+ ok(hr == D3D_OK, "Failed to get constant table, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetMatrix(constants, device, "r", &matrix);
+ ok(hr == D3D_OK, "Failed to get constant table, hr %#x.\n", hr);
+ hr = ID3DXConstantTable_SetMatrix(constants, device, "c", &matrix);
+ ok(hr == D3D_OK, "Failed to get constant table, hr %#x.\n", hr);
+ ID3DXConstantTable_Release(constants);
+
+ draw_quad(test_context.device, ps_code);
+
+ 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);
+
+ ID3D10Blob_Release(ps_code);
+ }
+
+ release_test_context(&test_context);
+}
+
static void check_constant_desc(const char *prefix, const D3DXCONSTANT_DESC *desc,
const D3DXCONSTANT_DESC *expect, BOOL nonzero_defaultvalue)
{
@@ -794,6 +878,8 @@ static void check_constant_desc(const char *prefix, const D3DXCONSTANT_DESC *des
static void test_constant_table(void)
{
static const char *source =
+ "typedef float3x3 matrix_t;\n"
+ "struct matrix_record { float3x3 a; };\n"
"uniform float4 a;\n"
"uniform float b;\n"
"uniform float unused;\n"
@@ -805,11 +891,15 @@ static void test_constant_table(void)
" float2x2 a;\n"
" float b;\n"
" float c;\n"
+ "#pragma pack_matrix(row_major)\n"
+ " float2x2 d;\n"
"} f;\n"
"uniform float g[5];\n"
+ "uniform matrix_t i;\n"
+ "uniform struct matrix_record j;\n"
"float4 main(uniform float4 h) : COLOR\n"
"{\n"
- " return a + b + c._31 + d._31 + f.c + g[e] + h;\n"
+ " return a + b + c._31 + d._31 + f.d._22 + g[e] + h + i._33 + j.a._33;\n"
"}";
D3DXCONSTANTTABLE_DESC table_desc;
@@ -829,17 +919,23 @@ static void test_constant_table(void)
{"c", D3DXRS_FLOAT4, 0, 1, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 3, 1, 1, 0, 12},
{"d", D3DXRS_FLOAT4, 0, 3, D3DXPC_MATRIX_ROWS, D3DXPT_FLOAT, 3, 1, 1, 0, 12},
{"e", D3DXRS_FLOAT4, 0, 1, D3DXPC_SCALAR, D3DXPT_INT, 1, 1, 1, 0, 4},
- {"f", D3DXRS_FLOAT4, 0, 4, D3DXPC_STRUCT, D3DXPT_VOID, 1, 6, 1, 3, 24},
+ {"f", D3DXRS_FLOAT4, 0, 6, D3DXPC_STRUCT, D3DXPT_VOID, 1, 10, 1, 4, 40},
{"g", D3DXRS_FLOAT4, 0, 5, D3DXPC_SCALAR, D3DXPT_FLOAT, 1, 1, 5, 0, 20},
+ {"i", D3DXRS_FLOAT4, 0, 3, D3DXPC_MATRIX_ROWS, D3DXPT_FLOAT, 3, 3, 1, 0, 36},
+ {"j", D3DXRS_FLOAT4, 0, 3, D3DXPC_STRUCT, D3DXPT_VOID, 1, 9, 1, 1, 36},
};
- static const D3DXCONSTANT_DESC expect_fields[] =
+ static const D3DXCONSTANT_DESC expect_fields_f[] =
{
{"a", D3DXRS_FLOAT4, 0, 2, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 2, 2, 1, 0, 16},
{"b", D3DXRS_FLOAT4, 0, 1, D3DXPC_SCALAR, D3DXPT_FLOAT, 1, 1, 1, 0, 4},
{"c", D3DXRS_FLOAT4, 0, 1, D3DXPC_SCALAR, D3DXPT_FLOAT, 1, 1, 1, 0, 4},
+ {"d", D3DXRS_FLOAT4, 0, 2, D3DXPC_MATRIX_ROWS, D3DXPT_FLOAT, 2, 2, 1, 0, 16},
};
+ 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");
if (!ps_code)
return;
@@ -850,7 +946,7 @@ static void test_constant_table(void)
hr = ID3DXConstantTable_GetDesc(constants, &table_desc);
ok(hr == D3D_OK, "Got hr %#x.\n", hr);
ok(table_desc.Version == D3DPS_VERSION(2, 0), "Got Version %#x.\n", table_desc.Version);
- ok(table_desc.Constants == 8, "Got %u constants.\n", table_desc.Constants);
+ ok(table_desc.Constants == ARRAY_SIZE(expect_constants), "Got %u constants.\n", table_desc.Constants);
for (i = 0; i < table_desc.Constants; ++i)
{
@@ -868,7 +964,7 @@ static void test_constant_table(void)
if (!strcmp(desc.Name, "f"))
{
- for (j = 0; j < ARRAY_SIZE(expect_fields); ++j)
+ for (j = 0; j < ARRAY_SIZE(expect_fields_f); ++j)
{
field = ID3DXConstantTable_GetConstant(constants, handle, j);
ok(!!field, "Failed to get constant.\n");
@@ -878,9 +974,21 @@ static void test_constant_table(void)
ok(hr == D3D_OK, "Got hr %#x.\n", hr);
ok(count == 1, "Got count %u.\n", count);
sprintf(prefix, "Test %u, %u", i, j);
- check_constant_desc(prefix, &desc, &expect_fields[j], !!j);
+ check_constant_desc(prefix, &desc, &expect_fields_f[j], !!j);
}
}
+ else if (!strcmp(desc.Name, "j"))
+ {
+ field = ID3DXConstantTable_GetConstant(constants, handle, 0);
+ ok(!!field, "Failed to get constant.\n");
+ memset(&desc, 0xcc, sizeof(desc));
+ count = 1;
+ hr = ID3DXConstantTable_GetConstantDesc(constants, field, &desc, &count);
+ ok(hr == D3D_OK, "Got hr %#x.\n", hr);
+ ok(count == 1, "Got count %u.\n", count);
+ sprintf(prefix, "Test %u", i);
+ check_constant_desc(prefix, &desc, &expect_fields_j, FALSE);
+ }
}
ID3DXConstantTable_Release(constants);
@@ -975,6 +1083,13 @@ static void test_fail(void)
"{\n"
" return float4(0, 0, 0, 0);\n"
"}",
+
+ "typedef row_major float4x4 matrix_t;\n"
+ "typedef column_major matrix_t matrix2_t;\n"
+ "float4 test() : SV_TARGET\n"
+ "{\n"
+ " return float4(0, 0, 0, 0);\n"
+ "}",
};
static const char *targets[] = {"ps_2_0", "ps_3_0", "ps_4_0"};
@@ -1036,6 +1151,8 @@ START_TEST(hlsl_d3d9)
test_comma();
test_return();
test_array_dimensions();
+ test_majority();
+
test_constant_table();
test_fail();
}
--
2.24.1
More information about the wine-devel
mailing list