vkd3d-shader/hlsl: Disallow certain instruction types from constant expressions.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
Nikolay Sivov 2023-06-28 11:57:54 +02:00 committed by Alexandre Julliard
parent a65c0b0e22
commit 06040d2a30
Notes: Alexandre Julliard 2023-07-04 23:25:55 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Zebediah Figura (@zfigura)
Approved-by: Francisco Casas (@fcasas)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/256
3 changed files with 39 additions and 2 deletions

View File

@ -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);

View File

@ -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)

View File

@ -72,7 +72,7 @@ float4 main() : sv_target
return 0;
}
[pixel shader fail todo]
[pixel shader fail]
float4 main() : sv_target
{
int x;