From 4f2e07a45d0cdb82b1cbba0cfe95c87a69799865 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Wed, 9 Aug 2023 13:13:39 +0200 Subject: [PATCH] vkd3d-shader/hlsl: Allow 'const' modifier without initializer in the global scope. Signed-off-by: Nikolay Sivov --- 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