Skip to content
Snippets Groups Projects

vkd3d-shader/hlsl: Improvements to static expression evaluation.

Merged Nikolay Sivov requested to merge nsivov/vkd3d:validate_static_expressions into master
1 unresolved thread
4 files
+ 56
8
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 38
6
@@ -1139,20 +1139,50 @@ 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),
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);
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);
@@ -1161,9 +1191,11 @@ 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);
return ret;
}
@@ -5675,7 +5707,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);
Loading