[PATCH 0/2] MR256: vkd3d-shader/hlsl: Support evaluated expressions for sample count in...
vkd3d-shader/hlsl: Support evaluated expressions for sample count in multisampled textures declarations. Signed-off-by: Nikolay Sivov <nsivov(a)codeweavers.com> -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/256
From: Nikolay Sivov <nsivov(a)codeweavers.com> Signed-off-by: Nikolay Sivov <nsivov(a)codeweavers.com> --- libs/vkd3d-shader/hlsl.y | 20 +++++++++++++++----- tests/texture-load.shader_test | 3 ++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index b487c5c13..2d0343a56 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1104,20 +1104,28 @@ static unsigned int evaluate_static_expression_as_uint(struct hlsl_ctx *ctx, str { struct hlsl_ir_constant *constant; struct hlsl_ir_node *node; + struct hlsl_block expr; unsigned int ret = 0; bool progress; - if (!add_implicit_conversion(ctx, &block->instrs, node_from_list(&block->instrs), + if (!hlsl_clone_block(ctx, &expr, &ctx->static_initializers)) + return 0; + hlsl_block_add_block(&expr, block); + + if (!add_implicit_conversion(ctx, &expr.instrs, node_from_list(&expr.instrs), hlsl_get_scalar_type(ctx, HLSL_TYPE_UINT), loc)) + { + hlsl_block_cleanup(&expr); return 0; + } do { - progress = hlsl_transform_ir(ctx, hlsl_fold_constant_exprs, block, NULL); - progress |= hlsl_copy_propagation_execute(ctx, block); + progress = hlsl_transform_ir(ctx, hlsl_fold_constant_exprs, &expr, NULL); + progress |= hlsl_copy_propagation_execute(ctx, &expr); } while (progress); - node = node_from_list(&block->instrs); + node = node_from_list(&expr.instrs); if (node->type == HLSL_IR_CONSTANT) { constant = hlsl_ir_constant(node); @@ -1129,6 +1137,8 @@ static unsigned int evaluate_static_expression_as_uint(struct hlsl_ctx *ctx, str "Failed to evaluate constant expression %d.", node->type); } + hlsl_block_cleanup(&expr); + return ret; } @@ -5538,7 +5548,7 @@ arrays: uint32_t *new_array; unsigned int size; - hlsl_clone_block(ctx, &block, &ctx->static_initializers); + hlsl_block_init(&block); list_move_tail(&block.instrs, $2); size = evaluate_static_expression_as_uint(ctx, &block, &@2); diff --git a/tests/texture-load.shader_test b/tests/texture-load.shader_test index 4893e4d84..362e1d2e3 100644 --- a/tests/texture-load.shader_test +++ b/tests/texture-load.shader_test @@ -37,7 +37,8 @@ probe (0, 1) rgba (0.5, 0.7, 0.6, 0.8) probe (1, 1) rgba (0.8, 0.0, 0.7, 1.0) [pixel shader] -Texture2DMS<float4, 1> t; +static const int size = 2; +Texture2DMS<float4, size - 1> t; float4 main(float4 pos : sv_position) : sv_target { -- GitLab https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/256
From: Nikolay Sivov <nsivov(a)codeweavers.com> Signed-off-by: Nikolay Sivov <nsivov(a)codeweavers.com> --- libs/vkd3d-shader/hlsl.y | 17 ++++++++++++++++- tests/hlsl-invalid.shader_test | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 2d0343a56..4daeda442 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1108,6 +1108,21 @@ 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: + continue; + default: + 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); @@ -1134,7 +1149,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-invalid.shader_test b/tests/hlsl-invalid.shader_test index 61033811d..ad0626520 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; -- GitLab https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/256
Zebediah Figura (@zfigura) commented about libs/vkd3d-shader/hlsl.y:
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: + continue; + default: + hlsl_error(ctx, &node->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, + "Expected literal expression.");
Can you please spell out the other cases instead of using DEFAULT? Not least because some brief tests suggest INDEX should also be allowed. (Interestingly, though, ternary expressions are not.) -- https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/256#note_37237
participants (3)
-
Nikolay Sivov -
Nikolay Sivov (@nsivov) -
Zebediah Figura (@zfigura)