diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 3dd8dd3a..82dd19eb 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1143,6 +1143,28 @@ static unsigned int evaluate_static_expression_as_uint(struct hlsl_ctx *ctx, str unsigned int ret = 0; bool progress; + LIST_FOR_EACH_ENTRY(node, &block->instrs, struct hlsl_ir_node, entry) + { + switch (node->type) + { + case HLSL_IR_CONSTANT: + case HLSL_IR_EXPR: + case HLSL_IR_SWIZZLE: + case HLSL_IR_LOAD: + case HLSL_IR_INDEX: + continue; + case HLSL_IR_CALL: + case HLSL_IR_IF: + case HLSL_IR_LOOP: + case HLSL_IR_JUMP: + case HLSL_IR_RESOURCE_LOAD: + case HLSL_IR_RESOURCE_STORE: + case HLSL_IR_STORE: + hlsl_error(ctx, &node->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, + "Expected literal expression."); + } + } + if (!hlsl_clone_block(ctx, &expr, &ctx->static_initializers)) return 0; hlsl_block_add_block(&expr, block); @@ -1169,7 +1191,7 @@ static unsigned int evaluate_static_expression_as_uint(struct hlsl_ctx *ctx, str else { hlsl_error(ctx, &node->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, - "Failed to evaluate constant expression %d.", node->type); + "Failed to evaluate constant expression."); } hlsl_block_cleanup(&expr); diff --git a/tests/hlsl/array-size-expr.shader_test b/tests/hlsl/array-size-expr.shader_test index ac774be1..1fd4e262 100644 --- a/tests/hlsl/array-size-expr.shader_test +++ b/tests/hlsl/array-size-expr.shader_test @@ -51,3 +51,18 @@ float4 main() : sv_target [test] draw quad probe all rgba (2, 3, 6, 1) + +% Additional level of indirection +[pixel shader todo] +static const float array[8] = {1, 2, 3, 4, 5, 6, 7, 8}; +static const int idx = 2; +static const float array2[array[idx]] = {1, 2, 3}; + +float4 main() : sv_target +{ + return float4(array[1], array2[2], array[5], array[0]); +} + +[test] +todo draw quad +probe all rgba (2, 3, 6, 1) diff --git a/tests/hlsl/invalid.shader_test b/tests/hlsl/invalid.shader_test index 61033811..ad062652 100644 --- a/tests/hlsl/invalid.shader_test +++ b/tests/hlsl/invalid.shader_test @@ -72,7 +72,7 @@ float4 main() : sv_target return 0; } -[pixel shader fail todo] +[pixel shader fail] float4 main() : sv_target { int x;