[PATCH 0/2] MR302: vkd3d-shader/hlsl: Allow 'const' modifier without initializer in the global scope.
Signed-off-by: Nikolay Sivov <nsivov(a)codeweavers.com> -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/302
From: Nikolay Sivov <nsivov(a)codeweavers.com> Signed-off-by: Nikolay Sivov <nsivov(a)codeweavers.com> --- Makefile.am | 1 + tests/hlsl/const.shader_test | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/hlsl/const.shader_test diff --git a/Makefile.am b/Makefile.am index 27738f3b..ad007d8f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -74,6 +74,7 @@ vkd3d_shader_tests = \ tests/hlsl/comma.shader_test \ tests/hlsl/compute.shader_test \ tests/hlsl/conditional.shader_test \ + tests/hlsl/const.shader_test \ tests/hlsl/cross.shader_test \ tests/hlsl/d3dcolor-to-ubyte4.shader_test \ tests/hlsl/ddxddy.shader_test \ diff --git a/tests/hlsl/const.shader_test b/tests/hlsl/const.shader_test new file mode 100644 index 00000000..ff89791e --- /dev/null +++ b/tests/hlsl/const.shader_test @@ -0,0 +1,21 @@ +[pixel shader todo] +const float4 f1; +const uniform float4 f2; + +float4 main() : sv_target +{ + return f1 + f2; +} + +[test] +uniform 0 float4 1.0 2.0 3.0 4.0 +uniform 4 float4 0.1 0.2 0.3 0.4 +todo draw quad +todo probe all rgba (1.1, 2.2, 3.3, 4.4) + +[pixel shader fail] +float4 main() : sv_target +{ + const float f; + return 0; +} -- GitLab https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/302
From: Nikolay Sivov <nsivov(a)codeweavers.com> Signed-off-by: Nikolay Sivov <nsivov(a)codeweavers.com> --- libs/vkd3d-shader/hlsl.y | 15 ++++++--------- tests/hlsl/const.shader_test | 6 +++--- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 0d994673..29e0ff0c 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2131,6 +2131,12 @@ static void declare_var(struct hlsl_ctx *ctx, struct parse_variable_def *v) if (var->semantic.name) hlsl_error(ctx, &var->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_SEMANTIC, "Semantics are not allowed on local variables."); + + if ((type->modifiers & HLSL_MODIFIER_CONST) && !v->initializer.args_count && !(modifiers & HLSL_STORAGE_STATIC)) + { + hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_INITIALIZER, + "Const variable \"%s\" is missing an initializer.", var->name); + } } if ((var->storage_modifiers & HLSL_STORAGE_STATIC) && type_has_numeric_components(var->data_type) @@ -2140,15 +2146,6 @@ static void declare_var(struct hlsl_ctx *ctx, struct parse_variable_def *v) "Static variables cannot have both numeric and resource components."); } - if ((type->modifiers & HLSL_MODIFIER_CONST) && !v->initializer.args_count - && !(modifiers & (HLSL_STORAGE_STATIC | HLSL_STORAGE_UNIFORM))) - { - hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_INITIALIZER, - "Const variable \"%s\" is missing an initializer.", var->name); - hlsl_free_var(var); - return; - } - if (!hlsl_add_var(ctx, var, local)) { struct hlsl_ir_var *old = hlsl_get_var(ctx->cur_scope, var->name); diff --git a/tests/hlsl/const.shader_test b/tests/hlsl/const.shader_test index ff89791e..ed5899f6 100644 --- a/tests/hlsl/const.shader_test +++ b/tests/hlsl/const.shader_test @@ -1,4 +1,4 @@ -[pixel shader todo] +[pixel shader] const float4 f1; const uniform float4 f2; @@ -10,8 +10,8 @@ float4 main() : sv_target [test] uniform 0 float4 1.0 2.0 3.0 4.0 uniform 4 float4 0.1 0.2 0.3 0.4 -todo draw quad -todo probe all rgba (1.1, 2.2, 3.3, 4.4) +draw quad +probe all rgba (1.1, 2.2, 3.3, 4.4) [pixel shader fail] float4 main() : sv_target -- GitLab https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/302
I find no problem with the series. Maybe I would add a test for const arguments, but that doesn't stop working because of the changes: ```hlsl float4 main(const float a : SEM) : sv_target { return a + 1; } ``` By the way, this a little silly, but it seems that while native compiler doesn't allow to assign to a const lhs with `=`, it surprisingly does allow assignments with operators such as `+=`. The value is not updated in this case though: ```hlsl float4 main() : sv_target { const float4 f = {1, 2, 3, 4}; f += 3; return f; } ``` ``` ps_4_0 dcl_output o0.xyzw mov o0.xyzw, l(1.000000,2.000000,3.000000,4.000000) ret ``` -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/302#note_41828
This merge request was approved by Francisco Casas. -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/302
This merge request was approved by Zebediah Figura. -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/302
This merge request was approved by Giovanni Mascellani. -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/302
This merge request was approved by Henri Verbeet. -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/302
participants (6)
-
Francisco Casas (@fcasas) -
Giovanni Mascellani (@giomasce) -
Henri Verbeet (@hverbeet) -
Nikolay Sivov -
Nikolay Sivov (@nsivov) -
Zebediah Figura (@zfigura)