-- v2: vkd3d-shader/hlsl: Get rid of the check_invalid_matrix_modifiers() helper. vkd3d-shader/hlsl: Apply latent majority modifiers to typedefs as well. vkd3d-shader/hlsl: Do not set an initial latent matrix majority. vkd3d-shader/hlsl: Store the matrix majority as a type modifiers bitmask. vkd3d-shader/hlsl: Apply latent type modifiers to matrix array typedefs. tests: Add more tests for pack_matrix pragmas.
From: Zebediah Figura zfigura@codeweavers.com
--- tests/hlsl-majority-pragma.shader_test | 131 +++++++++++++++++++++++++ 1 file changed, 131 insertions(+)
diff --git a/tests/hlsl-majority-pragma.shader_test b/tests/hlsl-majority-pragma.shader_test index d269e859..da1b1ff3 100644 --- a/tests/hlsl-majority-pragma.shader_test +++ b/tests/hlsl-majority-pragma.shader_test @@ -20,6 +20,51 @@ uniform 12 float4 0.2 0.4 0.0 0.0 draw quad probe all rgba (0.17, 0.39, 0.17, 0.39) 1
+ +%% Test with a struct. + +[pixel shader] +#pragma pack_matrix(row_major) +struct apple +{ + float2x2 m; +}; +#pragma pack_matrix(column_major) +uniform struct apple a; + +float4 main() : sv_target +{ + return float4(a.m[0], a.m[1]); +} + +[test] +uniform 0 float4 0.1 0.2 0.0 0.0 +uniform 4 float4 0.3 0.4 0.0 0.0 +draw quad +probe all rgba (0.1, 0.2, 0.3, 0.4) + + +%% Test with an array. + +[pixel shader] +#pragma pack_matrix(row_major) +uniform float2x2 m[2]; +#pragma pack_matrix(column_major) + +float4 main() : sv_target +{ + return float4(m[1][0], m[1][1]); +} + +[test] +uniform 0 float4 0.0 0.0 0.0 0.0 +uniform 4 float4 0.0 0.0 0.0 0.0 +uniform 8 float4 0.5 0.6 0.0 0.0 +uniform 12 float4 0.7 0.8 0.0 0.0 +draw quad +probe all rgba (0.5, 0.6, 0.7, 0.8) + + % The documentation claims these strings are subject to macro expansion. % They are not.
@@ -47,3 +92,89 @@ uniform 0 float4 0.1 0.2 0.0 0.0 uniform 4 float4 0.3 0.4 0.0 0.0 draw quad probe all rgba (0.23, 0.34, 0.5, 0.5) 1 + + +% The majority that applies to a typedef is the latent majority at the time +% that typedef was declared. + +[pixel shader] +#pragma pack_matrix(row_major) +typedef float2x2 mat_t; +#pragma pack_matrix(column_major) +uniform mat_t m; + +float4 main() : sv_target +{ + return float4(m[0], m[1]); +} + +[test] +uniform 0 float4 0.1 0.2 0.0 0.0 +uniform 4 float4 0.3 0.4 0.0 0.0 +draw quad +todo probe all rgba (0.1, 0.2, 0.3, 0.4) + + +% In fact, it's illegal to specify a contradictory majority. + +[pixel shader fail todo] +#pragma pack_matrix(row_major) +typedef float2x2 mat_t; +uniform column_major mat_t m; + +float4 main() : sv_target +{ + return 0; +} + + +% However, if no pack_matrix directive has been used yet, a typedef has no +% defined majority, and the majority can be overwritten, including by a +% subsequent pragma. + +[pixel shader] +typedef float2x2 mat_t; +#pragma pack_matrix(row_major) +uniform mat_t m; + +uniform row_major mat_t r; +uniform column_major mat_t c; + +float4 main() : sv_target +{ + return float4(m[0], m[1]); +} + +[test] +uniform 0 float4 0.1 0.2 0.0 0.0 +uniform 4 float4 0.3 0.4 0.0 0.0 +draw quad +probe all rgba (0.1, 0.2, 0.3, 0.4) + + +% This does not apply recursively to struct or array members, however. Members +% defined while there is no latent majority are always column-major, even if +% the type is later used after a pack_matrix(row_major) directive. + +% Note that the majority of the struct or array type cannot itself be +% overwritten with modifiers; those are only valid on matrix types. + +[pixel shader] +struct apple +{ + float2x2 m; +}; +#pragma pack_matrix(row_major) +typedef struct apple apple_t; +uniform apple_t a; + +float4 main() : sv_target +{ + return float4(a.m[0], a.m[1]); +} + +[test] +uniform 0 float4 0.2 0.4 0.0 0.0 +uniform 4 float4 0.3 0.5 0.0 0.0 +draw quad +probe all rgba (0.2, 0.3, 0.4, 0.5)
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/hlsl.y | 25 +++++++------- tests/hlsl-majority-pragma.shader_test | 45 ++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 11 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 697b895d..b1c2dab1 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -882,12 +882,6 @@ static struct hlsl_type *apply_type_modifiers(struct hlsl_ctx *ctx, struct hlsl_ unsigned int default_majority = 0; struct hlsl_type *new_type;
- /* 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) @@ -1003,7 +997,8 @@ static bool gen_struct_fields(struct hlsl_ctx *ctx, struct parse_fields *fields, return true; }
-static bool add_typedef(struct hlsl_ctx *ctx, DWORD modifiers, struct hlsl_type *orig_type, struct list *list) +static bool add_typedef(struct hlsl_ctx *ctx, const unsigned int modifiers, + struct hlsl_type *const orig_type, struct list *list) { struct parse_variable_def *v, *v_next; struct hlsl_type *type; @@ -1014,15 +1009,26 @@ static bool add_typedef(struct hlsl_ctx *ctx, DWORD modifiers, struct hlsl_type { if (!v->arrays.count) { + /* Do not use apply_type_modifiers() here. We should not apply the + * latent matrix majority to plain matrix types. */ if (!(type = hlsl_type_clone(ctx, orig_type, 0, modifiers))) { free_parse_variable_def(v); continue; } + + if (type->type != HLSL_CLASS_MATRIX) + check_invalid_matrix_modifiers(ctx, modifiers, v->loc); } else { - type = orig_type; + unsigned int var_modifiers = modifiers; + + if (!(type = apply_type_modifiers(ctx, orig_type, &var_modifiers, v->loc))) + { + free_parse_variable_def(v); + continue; + } }
ret = true; @@ -1048,9 +1054,6 @@ static bool add_typedef(struct hlsl_ctx *ctx, DWORD modifiers, struct hlsl_type vkd3d_free((void *)type->name); type->name = v->name;
- if (type->type != HLSL_CLASS_MATRIX) - check_invalid_matrix_modifiers(ctx, type->modifiers, v->loc); - if ((type->modifiers & HLSL_MODIFIER_COLUMN_MAJOR) && (type->modifiers & HLSL_MODIFIER_ROW_MAJOR)) hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER, diff --git a/tests/hlsl-majority-pragma.shader_test b/tests/hlsl-majority-pragma.shader_test index da1b1ff3..48915aa7 100644 --- a/tests/hlsl-majority-pragma.shader_test +++ b/tests/hlsl-majority-pragma.shader_test @@ -128,6 +128,31 @@ float4 main() : sv_target }
+% This applies to arrays as well. Note that struct fields already have latent +% majority applied (even if there have been no pragmas, as shown below), so the +% question of typedefs is moot there. + + +[pixel shader] +#pragma pack_matrix(row_major) +typedef float2x2 myarray_t[2]; +#pragma pack_matrix(column_major) +uniform myarray_t a; + +float4 main() : sv_target +{ + return float4(a[0][0], a[1][1]); +} + +[test] +uniform 0 float4 0.3 0.4 0.0 0.0 +uniform 4 float4 0.0 0.0 0.0 0.0 +uniform 8 float4 0.0 0.0 0.0 0.0 +uniform 12 float4 0.5 0.6 0.0 0.0 +draw quad +probe all rgba (0.3, 0.4, 0.5, 0.6) + + % However, if no pack_matrix directive has been used yet, a typedef has no % defined majority, and the majority can be overwritten, including by a % subsequent pragma. @@ -178,3 +203,23 @@ uniform 0 float4 0.2 0.4 0.0 0.0 uniform 4 float4 0.3 0.5 0.0 0.0 draw quad probe all rgba (0.2, 0.3, 0.4, 0.5) + + +[pixel shader] +typedef float2x2 myarray_t[2]; +#pragma pack_matrix(row_major) +typedef myarray_t myarray2_t; +uniform myarray2_t a; + +float4 main() : sv_target +{ + return float4(a[0][0], a[1][1]); +} + +[test] +uniform 0 float4 0.3 0.0 0.0 0.0 +uniform 4 float4 0.4 0.0 0.0 0.0 +uniform 8 float4 0.0 0.5 0.0 0.0 +uniform 12 float4 0.0 0.6 0.0 0.0 +draw quad +probe all rgba (0.3, 0.4, 0.5, 0.6)
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/hlsl.c | 2 +- libs/vkd3d-shader/hlsl.h | 8 +------- libs/vkd3d-shader/hlsl.l | 4 ++-- libs/vkd3d-shader/hlsl.y | 5 +---- 4 files changed, 5 insertions(+), 14 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index d6a87b3f..63c5a9d4 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -2881,7 +2881,7 @@ static bool hlsl_ctx_init(struct hlsl_ctx *ctx, const char *source_name, ctx->location.line = ctx->location.column = 1; vkd3d_string_buffer_cache_init(&ctx->string_buffers);
- ctx->matrix_majority = HLSL_COLUMN_MAJOR; + ctx->matrix_majority = HLSL_MODIFIER_COLUMN_MAJOR;
list_init(&ctx->scopes);
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 81b1a61d..8f36fc4c 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -116,12 +116,6 @@ enum hlsl_sampler_dim HLSL_SAMPLER_DIM_MAX = HLSL_SAMPLER_DIM_CUBEARRAY, };
-enum hlsl_matrix_majority -{ - HLSL_COLUMN_MAJOR, - HLSL_ROW_MAJOR -}; - /* An HLSL source-level data type, including anonymous structs and typedefs. */ struct hlsl_type { @@ -729,7 +723,7 @@ struct hlsl_ctx const struct hlsl_ir_function_decl *cur_function;
/* Default matrix majority for matrix types. Can be set by a pragma within the HLSL source. */ - enum hlsl_matrix_majority matrix_majority; + unsigned int matrix_majority;
/* Basic data types stored for convenience. */ struct diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l index 69ed9d9d..9e827048 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -233,14 +233,14 @@ row_major {return KW_ROW_MAJOR; } struct hlsl_ctx *ctx = yyget_extra(yyscanner);
TRACE("#pragma setting row_major mode.\n"); - ctx->matrix_majority = HLSL_ROW_MAJOR; + ctx->matrix_majority = HLSL_MODIFIER_ROW_MAJOR; BEGIN(pp_ignore); } <pp_pragma>pack_matrix{WS}*({WS}*column_major{WS}*) { struct hlsl_ctx *ctx = yyget_extra(yyscanner);
TRACE("#pragma setting column_major mode.\n"); - ctx->matrix_majority = HLSL_COLUMN_MAJOR; + ctx->matrix_majority = HLSL_MODIFIER_COLUMN_MAJOR; BEGIN(pp_ignore); } <pp_pragma>{NEWLINE} { diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index b1c2dab1..87d4b6cc 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -886,10 +886,7 @@ static struct hlsl_type *apply_type_modifiers(struct hlsl_ctx *ctx, struct hlsl_ && !(type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK) && type->type == HLSL_CLASS_MATRIX) { - if (ctx->matrix_majority == HLSL_COLUMN_MAJOR) - default_majority = HLSL_MODIFIER_COLUMN_MAJOR; - else - default_majority = HLSL_MODIFIER_ROW_MAJOR; + default_majority = ctx->matrix_majority; } else if (type->type != HLSL_CLASS_MATRIX) {
From: Zebediah Figura zfigura@codeweavers.com
This change does nothing by itself. --- libs/vkd3d-shader/hlsl.c | 2 -- libs/vkd3d-shader/hlsl.y | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 63c5a9d4..0c4f6686 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -2881,8 +2881,6 @@ static bool hlsl_ctx_init(struct hlsl_ctx *ctx, const char *source_name, ctx->location.line = ctx->location.column = 1; vkd3d_string_buffer_cache_init(&ctx->string_buffers);
- ctx->matrix_majority = HLSL_MODIFIER_COLUMN_MAJOR; - list_init(&ctx->scopes);
if (!(ctx->dummy_scope = hlsl_new_scope(ctx, NULL))) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 87d4b6cc..c5d6bc94 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -886,7 +886,8 @@ static struct hlsl_type *apply_type_modifiers(struct hlsl_ctx *ctx, struct hlsl_ && !(type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK) && type->type == HLSL_CLASS_MATRIX) { - default_majority = ctx->matrix_majority; + if (!(default_majority = ctx->matrix_majority)) + default_majority = HLSL_MODIFIER_COLUMN_MAJOR; } else if (type->type != HLSL_CLASS_MATRIX) {
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/hlsl.y | 54 +++++++++++++------------- tests/hlsl-majority-pragma.shader_test | 4 +- 2 files changed, 29 insertions(+), 29 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index c5d6bc94..1d48d53a 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -877,7 +877,7 @@ static const struct hlsl_struct_field *get_struct_field(const struct hlsl_struct }
static struct hlsl_type *apply_type_modifiers(struct hlsl_ctx *ctx, struct hlsl_type *type, - unsigned int *modifiers, struct vkd3d_shader_location loc) + unsigned int *modifiers, bool force_majority, const struct vkd3d_shader_location *loc) { unsigned int default_majority = 0; struct hlsl_type *new_type; @@ -886,12 +886,12 @@ static struct hlsl_type *apply_type_modifiers(struct hlsl_ctx *ctx, struct hlsl_ && !(type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK) && type->type == HLSL_CLASS_MATRIX) { - if (!(default_majority = ctx->matrix_majority)) + if (!(default_majority = ctx->matrix_majority) && force_majority) default_majority = HLSL_MODIFIER_COLUMN_MAJOR; } else if (type->type != HLSL_CLASS_MATRIX) { - check_invalid_matrix_modifiers(ctx, *modifiers, loc); + check_invalid_matrix_modifiers(ctx, *modifiers, *loc); }
if (!default_majority && !(*modifiers & HLSL_TYPE_MODIFIERS_MASK)) @@ -903,7 +903,7 @@ static struct hlsl_type *apply_type_modifiers(struct hlsl_ctx *ctx, struct hlsl_ *modifiers &= ~HLSL_TYPE_MODIFIERS_MASK;
if ((new_type->modifiers & HLSL_MODIFIER_ROW_MAJOR) && (new_type->modifiers & HLSL_MODIFIER_COLUMN_MAJOR)) - hlsl_error(ctx, &loc, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER, + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER, "'row_major' and 'column_major' modifiers are mutually exclusive.");
return new_type; @@ -995,8 +995,7 @@ static bool gen_struct_fields(struct hlsl_ctx *ctx, struct parse_fields *fields, return true; }
-static bool add_typedef(struct hlsl_ctx *ctx, const unsigned int modifiers, - struct hlsl_type *const orig_type, struct list *list) +static bool add_typedef(struct hlsl_ctx *ctx, struct hlsl_type *const orig_type, struct list *list) { struct parse_variable_def *v, *v_next; struct hlsl_type *type; @@ -1007,22 +1006,17 @@ static bool add_typedef(struct hlsl_ctx *ctx, const unsigned int modifiers, { if (!v->arrays.count) { - /* Do not use apply_type_modifiers() here. We should not apply the - * latent matrix majority to plain matrix types. */ - if (!(type = hlsl_type_clone(ctx, orig_type, 0, modifiers))) + if (!(type = hlsl_type_clone(ctx, orig_type, 0, 0))) { free_parse_variable_def(v); continue; } - - if (type->type != HLSL_CLASS_MATRIX) - check_invalid_matrix_modifiers(ctx, modifiers, v->loc); } else { - unsigned int var_modifiers = modifiers; + unsigned int var_modifiers = 0;
- if (!(type = apply_type_modifiers(ctx, orig_type, &var_modifiers, v->loc))) + if (!(type = apply_type_modifiers(ctx, orig_type, &var_modifiers, true, &v->loc))) { free_parse_variable_def(v); continue; @@ -1052,11 +1046,6 @@ static bool add_typedef(struct hlsl_ctx *ctx, const unsigned int modifiers, vkd3d_free((void *)type->name); type->name = v->name;
- if ((type->modifiers & HLSL_MODIFIER_COLUMN_MAJOR) - && (type->modifiers & HLSL_MODIFIER_ROW_MAJOR)) - hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER, - "'row_major' and 'column_major' modifiers are mutually exclusive."); - ret = hlsl_scope_add_type(ctx->cur_scope, type); if (!ret) hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_REDEFINED, @@ -3902,7 +3891,7 @@ struct_declaration: "Modifiers are not allowed on struct type declarations."); }
- if (!(type = apply_type_modifiers(ctx, $2, &modifiers, @1))) + if (!(type = apply_type_modifiers(ctx, $2, &modifiers, true, &@1))) YYABORT; $$ = declare_vars(ctx, type, modifiers, &@1, $3); } @@ -3987,7 +3976,7 @@ field: struct hlsl_type *type; unsigned int modifiers = $1;
- if (!(type = apply_type_modifiers(ctx, $2, &modifiers, @1))) + if (!(type = apply_type_modifiers(ctx, $2, &modifiers, true, &@1))) YYABORT; if (modifiers & ~HLSL_STORAGE_NOINTERPOLATION) { @@ -4137,7 +4126,7 @@ func_prototype_no_attrs: if (modifiers & ~HLSL_MODIFIERS_MAJORITY_MASK) hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER, "Only majority modifiers are allowed on functions."); - if (!(type = apply_type_modifiers(ctx, $2, &modifiers, @1))) + if (!(type = apply_type_modifiers(ctx, $2, &modifiers, true, &@1))) YYABORT; if ((var = hlsl_get_var(ctx->globals, $3))) { @@ -4363,7 +4352,7 @@ parameter: struct hlsl_type *type; unsigned int i;
- if (!(type = apply_type_modifiers(ctx, $2, &modifiers, @1))) + if (!(type = apply_type_modifiers(ctx, $2, &modifiers, true, &@1))) YYABORT;
$$.modifiers = modifiers; @@ -4595,9 +4584,20 @@ typedef_type: typedef: KW_TYPEDEF var_modifiers typedef_type type_specs ';' { - if ($2 & ~HLSL_TYPE_MODIFIERS_MASK) + struct parse_variable_def *v, *v_next; + unsigned int modifiers = $2; + struct hlsl_type *type; + + if (!(type = apply_type_modifiers(ctx, $3, &modifiers, false, &@2))) + { + LIST_FOR_EACH_ENTRY_SAFE(v, v_next, $4, struct parse_variable_def, entry) + free_parse_variable_def(v); + vkd3d_free($4); + YYABORT; + } + + if (modifiers) { - struct parse_variable_def *v, *v_next; hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER, "Storage modifiers are not allowed on typedefs."); LIST_FOR_EACH_ENTRY_SAFE(v, v_next, $4, struct parse_variable_def, entry) @@ -4605,7 +4605,7 @@ typedef: vkd3d_free($4); YYABORT; } - if (!add_typedef(ctx, $2, $3, $4)) + if (!add_typedef(ctx, type, $4)) YYABORT; }
@@ -4637,7 +4637,7 @@ declaration: struct hlsl_type *type; unsigned int modifiers = $1;
- if (!(type = apply_type_modifiers(ctx, $2, &modifiers, @1))) + if (!(type = apply_type_modifiers(ctx, $2, &modifiers, true, &@1))) YYABORT; $$ = declare_vars(ctx, type, modifiers, &@1, $3); } diff --git a/tests/hlsl-majority-pragma.shader_test b/tests/hlsl-majority-pragma.shader_test index 48915aa7..10778fd0 100644 --- a/tests/hlsl-majority-pragma.shader_test +++ b/tests/hlsl-majority-pragma.shader_test @@ -112,12 +112,12 @@ float4 main() : sv_target uniform 0 float4 0.1 0.2 0.0 0.0 uniform 4 float4 0.3 0.4 0.0 0.0 draw quad -todo probe all rgba (0.1, 0.2, 0.3, 0.4) +probe all rgba (0.1, 0.2, 0.3, 0.4)
% In fact, it's illegal to specify a contradictory majority.
-[pixel shader fail todo] +[pixel shader fail] #pragma pack_matrix(row_major) typedef float2x2 mat_t; uniform column_major mat_t m;
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/hlsl.y | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 1d48d53a..47d58e9f 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -149,13 +149,6 @@ static void destroy_instr_list(struct list *list) vkd3d_free(list); }
-static void check_invalid_matrix_modifiers(struct hlsl_ctx *ctx, DWORD modifiers, struct vkd3d_shader_location loc) -{ - if (modifiers & HLSL_MODIFIERS_MAJORITY_MASK) - hlsl_error(ctx, &loc, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER, - "'row_major' and 'column_major' modifiers are only allowed for matrices."); -} - static bool hlsl_types_are_componentwise_compatible(struct hlsl_ctx *ctx, struct hlsl_type *src, struct hlsl_type *dst) { @@ -889,9 +882,10 @@ static struct hlsl_type *apply_type_modifiers(struct hlsl_ctx *ctx, struct hlsl_ if (!(default_majority = ctx->matrix_majority) && force_majority) default_majority = HLSL_MODIFIER_COLUMN_MAJOR; } - else if (type->type != HLSL_CLASS_MATRIX) + else if (type->type != HLSL_CLASS_MATRIX && (*modifiers & HLSL_MODIFIERS_MAJORITY_MASK)) { - check_invalid_matrix_modifiers(ctx, *modifiers, *loc); + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER, + "'row_major' and 'column_major' modifiers are only allowed for matrices."); }
if (!default_majority && !(*modifiers & HLSL_TYPE_MODIFIERS_MASK))
v2: Just drop the struct-typedef test, it wasn't testing anything that wasn't already tested elsewhere and there's nothing else interesting to test in that area either.
Francisco Casas (@fcasas) commented about libs/vkd3d-shader/hlsl.y:
struct hlsl_type *type; unsigned int modifiers = $1;
if (!(type = apply_type_modifiers(ctx, $2, &modifiers, @1)))
if (!(type = apply_type_modifiers(ctx, $2, &modifiers, true, &@1)))
In the context of the commit is clear, but I think that it would be nice to have a comment to indicate that the sole purpose of this call now is forcing the matrix members of a typedef array to be column-major when no latent majority has been specified.
This merge request was approved by Francisco Casas.
This doesn't apply cleanly.