From 0c1c916ad7a64ecb97bab7645c841f4729f7feef Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Thu, 18 Mar 2021 00:22:23 -0500 Subject: [PATCH] vkd3d-shader: Allow static const variables to lack an initializer. Signed-off-by: Zebediah Figura Signed-off-by: Matteo Bruni Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- libs/vkd3d-shader/hlsl.y | 3 ++- tests/hlsl-invalid.shader_test | 7 +++++++ tests/hlsl-static-initializer.shader_test | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index c12b4e9a..45767de9 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1472,7 +1472,8 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t local = false; } - if (type->modifiers & HLSL_MODIFIER_CONST && !(var->modifiers & HLSL_STORAGE_UNIFORM) && !v->initializer.args_count) + if ((type->modifiers & HLSL_MODIFIER_CONST) && !v->initializer.args_count + && !(var->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); diff --git a/tests/hlsl-invalid.shader_test b/tests/hlsl-invalid.shader_test index 16e75d0a..370d84d4 100644 --- a/tests/hlsl-invalid.shader_test +++ b/tests/hlsl-invalid.shader_test @@ -115,3 +115,10 @@ float4 main() : sv_target { return 0; } + +[pixel shader fail] +float4 main() : sv_target +{ + const float4 x; + return x; +} diff --git a/tests/hlsl-static-initializer.shader_test b/tests/hlsl-static-initializer.shader_test index 9b9d000f..9c486512 100644 --- a/tests/hlsl-static-initializer.shader_test +++ b/tests/hlsl-static-initializer.shader_test @@ -5,9 +5,10 @@ float myfunc() } static float a = myfunc() + 0.2; static float b; +static const float c; float4 main() : sv_target { - return float4(a, b, 0, 0); + return float4(a, b, c, 0); } [test]