Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/hlsl.y | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index 67393f6ca97..5381fa211a2 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -814,6 +814,10 @@ static BOOL add_typedef(DWORD modifiers, struct hlsl_type *orig_type, struct lis if (type->type != HLSL_CLASS_MATRIX) check_invalid_matrix_modifiers(type->modifiers, v->loc);
+ if ((type->modifiers & HLSL_MODIFIER_COLUMN_MAJOR) + && (type->modifiers & HLSL_MODIFIER_ROW_MAJOR)) + hlsl_report_message(v->loc, HLSL_LEVEL_ERROR, "more than one matrix majority keyword"); + ret = add_type_to_scope(hlsl_ctx.cur_scope, type); if (!ret) {
Signed-off-by: Zebediah Figura zfigura@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..233f2747bed 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 float 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", (const D3DXMATRIX *)matrix); + ok(hr == D3D_OK, "Failed to get constant table, hr %#x.\n", hr); + hr = ID3DXConstantTable_SetMatrix(constants, device, "c", (const D3DXMATRIX *)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", (const D3DXMATRIX *)matrix); + ok(hr == D3D_OK, "Failed to get constant table, hr %#x.\n", hr); + hr = ID3DXConstantTable_SetMatrix(constants, device, "c", (const D3DXMATRIX *)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(); }
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- Ultimately, the difficulty is that the default majority is syntactically a property of the declaration, but semantically a property of the type. I had to play around with various solutions before settling on this one, which seems to make things easiest for RA and reflection without breaking typedefs.
dlls/d3dcompiler_43/d3dcompiler_private.h | 2 +- dlls/d3dcompiler_43/hlsl.y | 39 +++++++++++++++++++---- dlls/d3dcompiler_43/utils.c | 8 +++-- 3 files changed, 39 insertions(+), 10 deletions(-)
diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index df45a7082fe..40c4fcffee5 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -1081,7 +1081,7 @@ void free_declaration(struct hlsl_ir_var *decl) DECLSPEC_HIDDEN; struct hlsl_type *new_hlsl_type(const char *name, enum hlsl_type_class type_class, enum hlsl_base_type base_type, unsigned dimx, unsigned dimy) DECLSPEC_HIDDEN; struct hlsl_type *new_array_type(struct hlsl_type *basic_type, unsigned int array_size) DECLSPEC_HIDDEN; -struct hlsl_type *clone_hlsl_type(struct hlsl_type *old) DECLSPEC_HIDDEN; +struct hlsl_type *clone_hlsl_type(struct hlsl_type *old, unsigned int default_majority) DECLSPEC_HIDDEN; struct hlsl_type *get_type(struct hlsl_scope *scope, const char *name, BOOL recursive) DECLSPEC_HIDDEN; BOOL find_function(const char *name) DECLSPEC_HIDDEN; unsigned int components_count_type(struct hlsl_type *type) DECLSPEC_HIDDEN; diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index 5381fa211a2..833472a351b 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -576,6 +576,9 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers, BOOL ret, local = TRUE; struct list *statements_list = d3dcompiler_alloc(sizeof(*statements_list));
+ if (basic_type->type == HLSL_CLASS_MATRIX) + assert(basic_type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK); + if (!statements_list) { ERR("Out of memory.\n"); @@ -717,14 +720,32 @@ static BOOL add_struct_field(struct list *fields, struct hlsl_struct_field *fiel return TRUE; }
-static struct hlsl_type *apply_type_modifiers(struct hlsl_type *type, DWORD *modifiers, struct source_location loc) +static struct hlsl_type *apply_type_modifiers(struct hlsl_type *type, + unsigned int *modifiers, struct source_location loc) { + unsigned int default_majority = 0; struct hlsl_type *new_type;
- if (!(*modifiers & HLSL_TYPE_MODIFIERS_MASK)) + /* This function is only used for declarations (i.e. variables and struct + * fields), which should inherit the matrix majority. We only explicitly set + * the default majority for declarations—typedefs depend on this—but we + * want to always set it, so that an hlsl_type object is never used to + * represent two different majorities (and thus can be used to store its + * register size, etc.) */ + if (!(*modifiers & HLSL_MODIFIERS_MAJORITY_MASK) + && !(type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK) + && type->type == HLSL_CLASS_MATRIX) + { + if (hlsl_ctx.matrix_majority == HLSL_COLUMN_MAJOR) + default_majority = HLSL_MODIFIER_COLUMN_MAJOR; + else + default_majority = HLSL_MODIFIER_ROW_MAJOR; + } + + if (!default_majority && !(*modifiers & HLSL_TYPE_MODIFIERS_MASK)) return type;
- if (!(new_type = clone_hlsl_type(type))) + if (!(new_type = clone_hlsl_type(type, default_majority))) return NULL;
new_type->modifiers = add_modifiers(new_type->modifiers, *modifiers, loc); @@ -738,6 +759,9 @@ static struct list *gen_struct_fields(struct hlsl_type *type, DWORD modifiers, s struct hlsl_struct_field *field; struct list *list;
+ if (type->type == HLSL_CLASS_MATRIX) + assert(type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK); + list = d3dcompiler_alloc(sizeof(*list)); if (!list) { @@ -801,7 +825,7 @@ static BOOL add_typedef(DWORD modifiers, struct hlsl_type *orig_type, struct lis if (v->array_size) type = new_array_type(orig_type, v->array_size); else - type = clone_hlsl_type(orig_type); + type = clone_hlsl_type(orig_type, 0); if (!type) { ERR("Out of memory\n"); @@ -834,6 +858,9 @@ static BOOL add_func_parameter(struct list *list, struct parse_parameter *param, { struct hlsl_ir_var *decl = d3dcompiler_alloc(sizeof(*decl));
+ if (param->type->type == HLSL_CLASS_MATRIX) + assert(param->type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK); + if (!decl) { ERR("Out of memory.\n"); @@ -2066,7 +2093,7 @@ postfix_expr: primary_expr } inc = new_unary_expr(HLSL_IR_UNOP_POSTINC, node_from_list($1), loc); /* Post increment/decrement expressions are considered const */ - inc->data_type = clone_hlsl_type(inc->data_type); + inc->data_type = clone_hlsl_type(inc->data_type, 0); inc->data_type->modifiers |= HLSL_MODIFIER_CONST; $$ = append_unop($1, inc); } @@ -2083,7 +2110,7 @@ postfix_expr: primary_expr } inc = new_unary_expr(HLSL_IR_UNOP_POSTDEC, node_from_list($1), loc); /* Post increment/decrement expressions are considered const */ - inc->data_type = clone_hlsl_type(inc->data_type); + inc->data_type = clone_hlsl_type(inc->data_type, 0); inc->data_type->modifiers |= HLSL_MODIFIER_CONST; $$ = append_unop($1, inc); } diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index 84323c334f8..ff779891fd8 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -927,7 +927,7 @@ BOOL compare_hlsl_types(const struct hlsl_type *t1, const struct hlsl_type *t2) return TRUE; }
-struct hlsl_type *clone_hlsl_type(struct hlsl_type *old) +struct hlsl_type *clone_hlsl_type(struct hlsl_type *old, unsigned int default_majority) { struct hlsl_type *type; struct hlsl_struct_field *old_field, *field; @@ -952,11 +952,13 @@ struct hlsl_type *clone_hlsl_type(struct hlsl_type *old) type->dimx = old->dimx; type->dimy = old->dimy; type->modifiers = old->modifiers; + if (!(type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK)) + type->modifiers |= default_majority; type->sampler_dim = old->sampler_dim; switch (old->type) { case HLSL_CLASS_ARRAY: - type->e.array.type = old->e.array.type; + type->e.array.type = clone_hlsl_type(old->e.array.type, default_majority); type->e.array.elements_count = old->e.array.elements_count; break; case HLSL_CLASS_STRUCT: @@ -984,7 +986,7 @@ struct hlsl_type *clone_hlsl_type(struct hlsl_type *old) d3dcompiler_free(type); return NULL; } - field->type = clone_hlsl_type(old_field->type); + field->type = clone_hlsl_type(old_field->type, default_majority); field->name = d3dcompiler_strdup(old_field->name); if (old_field->semantic) field->semantic = d3dcompiler_strdup(old_field->semantic);
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- For better or worse, this is pretty much exactly how I envisoned it.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/d3dcompiler_private.h | 3 +++ dlls/d3dcompiler_43/hlsl.y | 21 +++++++++++++++++++++ dlls/d3dcompiler_43/utils.c | 20 ++++++++++++++++++++ 3 files changed, 44 insertions(+)
diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index 40c4fcffee5..1f1d8e26637 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -614,6 +614,7 @@ struct hlsl_type unsigned int modifiers; unsigned int dimx; unsigned int dimy; + unsigned int reg_size; union { struct list *elements; @@ -632,6 +633,7 @@ struct hlsl_struct_field const char *name; const char *semantic; DWORD modifiers; + unsigned int reg_offset; };
struct source_location @@ -1083,6 +1085,7 @@ struct hlsl_type *new_hlsl_type(const char *name, enum hlsl_type_class type_clas struct hlsl_type *new_array_type(struct hlsl_type *basic_type, unsigned int array_size) DECLSPEC_HIDDEN; struct hlsl_type *clone_hlsl_type(struct hlsl_type *old, unsigned int default_majority) DECLSPEC_HIDDEN; struct hlsl_type *get_type(struct hlsl_scope *scope, const char *name, BOOL recursive) DECLSPEC_HIDDEN; +BOOL is_row_major(const struct hlsl_type *type) DECLSPEC_HIDDEN; BOOL find_function(const char *name) DECLSPEC_HIDDEN; unsigned int components_count_type(struct hlsl_type *type) DECLSPEC_HIDDEN; BOOL compare_hlsl_types(const struct hlsl_type *t1, const struct hlsl_type *t2) DECLSPEC_HIDDEN; diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index 833472a351b..d3ef18bb6e9 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -720,6 +720,13 @@ static BOOL add_struct_field(struct list *fields, struct hlsl_struct_field *fiel return TRUE; }
+BOOL is_row_major(const struct hlsl_type *type) +{ + /* Default to column-major if the majority isn't explicitly set, which can + * happen for anonymous nodes. */ + return !!(type->modifiers & HLSL_MODIFIER_ROW_MAJOR); +} + static struct hlsl_type *apply_type_modifiers(struct hlsl_type *type, unsigned int *modifiers, struct source_location loc) { @@ -750,6 +757,9 @@ static struct hlsl_type *apply_type_modifiers(struct hlsl_type *type,
new_type->modifiers = add_modifiers(new_type->modifiers, *modifiers, loc); *modifiers &= ~HLSL_TYPE_MODIFIERS_MASK; + + if (new_type->type == HLSL_CLASS_MATRIX) + new_type->reg_size = is_row_major(new_type) ? new_type->dimy : new_type->dimx; return new_type; }
@@ -798,6 +808,8 @@ static struct list *gen_struct_fields(struct hlsl_type *type, DWORD modifiers, s static struct hlsl_type *new_struct_type(const char *name, struct list *fields) { struct hlsl_type *type = d3dcompiler_alloc(sizeof(*type)); + struct hlsl_struct_field *field; + unsigned int reg_size = 0;
if (!type) { @@ -809,6 +821,13 @@ static struct hlsl_type *new_struct_type(const char *name, struct list *fields) type->dimx = type->dimy = 1; type->e.elements = fields;
+ LIST_FOR_EACH_ENTRY(field, fields, struct hlsl_struct_field, entry) + { + field->reg_offset = reg_size; + reg_size += field->type->reg_size; + } + type->reg_size = reg_size; + list_add_tail(&hlsl_ctx.types, &type->entry);
return type; @@ -837,6 +856,8 @@ static BOOL add_typedef(DWORD modifiers, struct hlsl_type *orig_type, struct lis
if (type->type != HLSL_CLASS_MATRIX) check_invalid_matrix_modifiers(type->modifiers, v->loc); + else + type->reg_size = is_row_major(type) ? type->dimy : type->dimx;
if ((type->modifiers & HLSL_MODIFIER_COLUMN_MAJOR) && (type->modifiers & HLSL_MODIFIER_ROW_MAJOR)) diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index ff779891fd8..0c8b918d139 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -820,6 +820,10 @@ struct hlsl_type *new_hlsl_type(const char *name, enum hlsl_type_class type_clas type->base_type = base_type; type->dimx = dimx; type->dimy = dimy; + if (type_class == HLSL_CLASS_MATRIX) + type->reg_size = is_row_major(type) ? dimy : dimx; + else + type->reg_size = 1;
list_add_tail(&hlsl_ctx.types, &type->entry);
@@ -836,6 +840,7 @@ struct hlsl_type *new_array_type(struct hlsl_type *basic_type, unsigned int arra type->modifiers = basic_type->modifiers; type->e.array.elements_count = array_size; type->e.array.type = basic_type; + type->reg_size = basic_type->reg_size * array_size; return type; }
@@ -960,8 +965,13 @@ struct hlsl_type *clone_hlsl_type(struct hlsl_type *old, unsigned int default_ma case HLSL_CLASS_ARRAY: type->e.array.type = clone_hlsl_type(old->e.array.type, default_majority); type->e.array.elements_count = old->e.array.elements_count; + type->reg_size = type->e.array.elements_count * type->e.array.type->reg_size; break; + case HLSL_CLASS_STRUCT: + { + unsigned int reg_size = 0; + type->e.elements = d3dcompiler_alloc(sizeof(*type->e.elements)); if (!type->e.elements) { @@ -991,10 +1001,20 @@ struct hlsl_type *clone_hlsl_type(struct hlsl_type *old, unsigned int default_ma if (old_field->semantic) field->semantic = d3dcompiler_strdup(old_field->semantic); field->modifiers = old_field->modifiers; + field->reg_offset = reg_size; + reg_size += field->type->reg_size; list_add_tail(type->e.elements, &field->entry); } + type->reg_size = reg_size; break; + } + + case HLSL_CLASS_MATRIX: + type->reg_size = is_row_major(type) ? type->dimy : type->dimx; + break; + default: + type->reg_size = 1; break; }
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
From: Alistair Leslie-Hughes leslie_alistair@hotmail.com
Test image is of my own creation.
Wine-bug: https://bugs.winehq.org/show_bug.cgi?id=48731 Signed-off-by: Alistair Leslie-Hughes leslie_alistair@hotmail.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/d3dx9_36/surface.c | 12 +++++ dlls/d3dx9_36/tests/surface.c | 92 +++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index 42e7bf16f1f..a5143cbee4a 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -108,6 +108,7 @@ static const GUID *d3dformat_to_wic_guid(D3DFORMAT format) #define DDS_PF_ALPHA 0x1 #define DDS_PF_ALPHA_ONLY 0x2 #define DDS_PF_FOURCC 0x4 +#define DDS_PF_INDEXED 0x20 #define DDS_PF_RGB 0x40 #define DDS_PF_YUV 0x200 #define DDS_PF_LUMINANCE 0x20000 @@ -349,6 +350,15 @@ static D3DFORMAT dds_alpha_to_d3dformat(const struct dds_pixel_format *pixel_for return D3DFMT_UNKNOWN; }
+static D3DFORMAT dds_indexed_to_d3dformat(const struct dds_pixel_format *pixel_format) +{ + if (pixel_format->bpp == 8) + return D3DFMT_P8; + + WARN("Unknown indexed pixel format (%u).\n", pixel_format->bpp); + return D3DFMT_UNKNOWN; +} + static D3DFORMAT dds_bump_to_d3dformat(const struct dds_pixel_format *pixel_format) { if (pixel_format->bpp == 16 && pixel_format->rmask == 0x00ff && pixel_format->gmask == 0xff00) @@ -381,6 +391,8 @@ static D3DFORMAT dds_pixel_format_to_d3dformat(const struct dds_pixel_format *pi
if (pixel_format->flags & DDS_PF_FOURCC) return dds_fourcc_to_d3dformat(pixel_format->fourcc); + if (pixel_format->flags & DDS_PF_INDEXED) + return dds_indexed_to_d3dformat(pixel_format); if (pixel_format->flags & DDS_PF_RGB) return dds_rgb_to_d3dformat(pixel_format); if (pixel_format->flags & DDS_PF_LUMINANCE) diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index d5d3d6d2112..e9b9e041785 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -107,6 +107,87 @@ static const unsigned char noimage[4] = { 0x11,0x22,0x33,0x44 };
+/* 16x4 8-bit dds */ +static const unsigned char dds_8bit[] = +{ + 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x0f,0x10,0x00,0x00,0x04,0x00,0x00,0x00, + 0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, + 0x47,0x49,0x4d,0x50,0x2d,0x44,0x44,0x53,0x5a,0x09,0x03,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00, + 0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff, + 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0x8c,0xcd,0x12,0xff, + 0x78,0x01,0x14,0xff,0x50,0xcd,0x12,0xff,0x00,0x3d,0x8c,0xff,0x02,0x00,0x00,0xff, + 0x47,0x00,0x00,0xff,0xda,0x07,0x02,0xff,0x50,0xce,0x12,0xff,0xea,0x11,0x01,0xff, + 0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x08,0x3d,0x8c,0xff,0x08,0x01,0x00,0xff, + 0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x60,0xcc,0x12,0xff, + 0xa1,0xb2,0xd4,0xff,0xda,0x07,0x02,0xff,0x47,0x00,0x00,0xff,0x00,0x00,0x00,0xff, + 0x50,0xce,0x12,0xff,0x00,0x00,0x14,0xff,0xa8,0xcc,0x12,0xff,0x3c,0xb2,0xd4,0xff, + 0xda,0x07,0x02,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x01,0xff, + 0x21,0x00,0x00,0xff,0xd8,0xcb,0x12,0xff,0x54,0xcd,0x12,0xff,0x8b,0x4f,0xd5,0xff, + 0x00,0x04,0xda,0xff,0x00,0x00,0x00,0xff,0x3d,0x04,0x91,0xff,0x70,0xce,0x18,0xff, + 0xb4,0xcc,0x12,0xff,0x6b,0x4e,0xd5,0xff,0xb0,0xcc,0x12,0xff,0x00,0x00,0x00,0xff, + 0xc8,0x05,0x91,0xff,0x98,0xc7,0xcc,0xff,0x7c,0xcd,0x12,0xff,0x51,0x05,0x91,0xff, + 0x48,0x07,0x14,0xff,0x6d,0x05,0x91,0xff,0x00,0x07,0xda,0xff,0xa0,0xc7,0xcc,0xff, + 0x00,0x07,0xda,0xff,0x3a,0x77,0xd5,0xff,0xda,0x07,0x02,0xff,0x7c,0x94,0xd4,0xff, + 0xe0,0xce,0xd6,0xff,0x0a,0x80,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff, + 0x78,0x9a,0xab,0xff,0xde,0x08,0x18,0xff,0xda,0x07,0x02,0xff,0x30,0x00,0x00,0xff, + 0x00,0x00,0x00,0xff,0x50,0xce,0x12,0xff,0x8c,0xcd,0x12,0xff,0xd0,0xb7,0xd8,0xff, + 0x00,0x00,0x00,0xff,0x60,0x32,0xd9,0xff,0x30,0xc1,0x1a,0xff,0xa8,0xcd,0x12,0xff, + 0xa4,0xcd,0x12,0xff,0xc0,0x1d,0x4b,0xff,0x46,0x71,0x0e,0xff,0xc0,0x1d,0x4b,0xff, + 0x09,0x87,0xd4,0xff,0x00,0x00,0x00,0xff,0xf6,0x22,0x00,0xff,0x64,0xcd,0x12,0xff, + 0x00,0x00,0x00,0xff,0xca,0x1d,0x4b,0xff,0x09,0x87,0xd4,0xff,0xaa,0x02,0x05,0xff, + 0x82,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0xc0,0x1d,0x4b,0xff, + 0xcd,0xab,0xba,0xff,0x00,0x00,0x00,0xff,0xa4,0xcd,0x12,0xff,0xc0,0x1d,0x4b,0xff, + 0xd4,0xcd,0x12,0xff,0xa6,0x4c,0xd5,0xff,0x00,0xf0,0xfd,0xff,0xd4,0xcd,0x12,0xff, + 0xf4,0x4c,0xd5,0xff,0x90,0xcd,0x12,0xff,0xc2,0x4c,0xd5,0xff,0x82,0x00,0x00,0xff, + 0xaa,0x02,0x05,0xff,0x88,0xd4,0xba,0xff,0x14,0x00,0x00,0xff,0x01,0x00,0x00,0xff, + 0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x10,0x00,0x00,0xff,0x00,0x00,0x00,0xff, + 0x0c,0x08,0x13,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff, + 0xd0,0xcd,0x12,0xff,0xc6,0x84,0xf1,0xff,0x7c,0x84,0xf1,0xff,0x20,0x20,0xf5,0xff, + 0x00,0x00,0x0a,0xff,0xf0,0xb0,0x94,0xff,0x64,0x6c,0xf1,0xff,0x85,0x6c,0xf1,0xff, + 0x8b,0x4f,0xd5,0xff,0x00,0x04,0xda,0xff,0x88,0xd4,0xba,0xff,0x82,0x00,0x00,0xff, + 0x39,0xde,0xd4,0xff,0x10,0x50,0xd5,0xff,0xaa,0x02,0x05,0xff,0x00,0x00,0x00,0xff, + 0x4f,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x5c,0xce,0x12,0xff,0x00,0x00,0x00,0xff, + 0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x5c,0xce,0x12,0xff, + 0xaa,0x02,0x05,0xff,0x4c,0xce,0x12,0xff,0x39,0xe6,0xd4,0xff,0x00,0x00,0x00,0xff, + 0x82,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x5b,0xe6,0xd4,0xff,0x00,0x00,0x00,0xff, + 0x00,0x00,0x00,0xff,0x68,0x50,0xcd,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff, + 0x00,0x00,0x00,0xff,0x10,0x00,0x00,0xff,0xe3,0xea,0x90,0xff,0x5c,0xce,0x12,0xff, + 0x18,0x00,0x00,0xff,0x88,0xd4,0xba,0xff,0x82,0x00,0x00,0xff,0x00,0x00,0x00,0xff, + 0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, + 0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, + 0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, + 0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01 +}; + /* 2x2 24-bit dds, 2 mipmaps */ static const unsigned char dds_24bit[] = { 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x0a,0x00,0x02,0x00,0x00,0x00, @@ -650,6 +731,17 @@ static void test_D3DXGetImageInfo(void) ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS); } else skip("Couldn't get image info from 16-bit DDS file in memory\n");
+ memset(&info, 0, sizeof(info)); + hr = D3DXGetImageInfoFromFileInMemory(dds_8bit, sizeof(dds_8bit), &info); + ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x\n", hr); + ok(info.Width == 16, "Got width %u.\n", info.Width); + ok(info.Height == 4, "Got height %u.\n", info.Height); + ok(info.Depth == 1, "Got depth %u.\n", info.Depth); + ok(info.MipLevels == 1, "Got miplevels %u.\n", info.MipLevels); + ok(info.Format == D3DFMT_P8, "Got format %#x.\n", info.Format); + ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x.\n", info.ResourceType); + ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x.\n", info.ImageFileFormat); + hr = D3DXGetImageInfoFromFileInMemory(dds_cube_map, sizeof(dds_cube_map), &info); ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK); if (hr == D3D_OK) {
From: Zebediah Figura z.figura12@gmail.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@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(); }
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=69512
Your paranoid android.
=== debiant (32 bit report) ===
d3dcompiler_43: hlsl_d3d9.c:1108: Test failed: Test 14, target ps_2_0, expected non-NULL error blob. Unhandled exception: page fault on read access to 0x00000000 in 32-bit code (0x0040e0d7).
Report validation errors: d3dcompiler_43:hlsl_d3d9 crashed (c0000005)
=== debiant (32 bit French report) ===
d3dcompiler_43: hlsl_d3d9.c:1108: Test failed: Test 14, target ps_2_0, expected non-NULL error blob. Unhandled exception: page fault on read access to 0x00000000 in 32-bit code (0x0040e0d7).
Report validation errors: d3dcompiler_43:hlsl_d3d9 crashed (c0000005)
=== debiant (32 bit Japanese:Japan report) ===
d3dcompiler_43: hlsl_d3d9.c:1108: Test failed: Test 14, target ps_2_0, expected non-NULL error blob. Unhandled exception: page fault on read access to 0x00000000 in 32-bit code (0x0040e0d7).
Report validation errors: d3dcompiler_43:hlsl_d3d9 crashed (c0000005)
=== debiant (32 bit Chinese:China report) ===
d3dcompiler_43: hlsl_d3d9.c:1108: Test failed: Test 14, target ps_2_0, expected non-NULL error blob. Unhandled exception: page fault on read access to 0x00000000 in 32-bit code (0x0040e0d7).
Report validation errors: d3dcompiler_43:hlsl_d3d9 crashed (c0000005)
=== debiant (32 bit WoW report) ===
d3dcompiler_43: hlsl_d3d9.c:1108: Test failed: Test 14, target ps_2_0, expected non-NULL error blob. Unhandled exception: page fault on read access to 0x00000000 in 32-bit code (0x0040e0d7).
Report validation errors: d3dcompiler_43:hlsl_d3d9 crashed (c0000005)
=== debiant (64 bit WoW report) ===
d3dcompiler_43: hlsl_d3d9.c:1108: Test failed: Test 14, target ps_2_0, expected non-NULL error blob. Unhandled exception: page fault on read access to 0x00000000 in 32-bit code (0x0040e0d7).
Report validation errors: d3dcompiler_43:hlsl_d3d9 crashed (c0000005)