mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader/ir: Check that SSA registers have consistent dimensions.
This commit is contained in:
parent
7503429555
commit
26bebe8f91
Notes:
Alexandre Julliard
2024-01-15 23:01:43 +01:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/550
@ -1533,6 +1533,12 @@ struct validation_context
|
|||||||
size_t first_seen;
|
size_t first_seen;
|
||||||
} *temps;
|
} *temps;
|
||||||
|
|
||||||
|
struct validation_context_ssa_data
|
||||||
|
{
|
||||||
|
enum vsir_dimension dimension;
|
||||||
|
size_t first_seen;
|
||||||
|
} *ssas;
|
||||||
|
|
||||||
enum vkd3d_shader_opcode *blocks;
|
enum vkd3d_shader_opcode *blocks;
|
||||||
size_t depth;
|
size_t depth;
|
||||||
size_t blocks_capacity;
|
size_t blocks_capacity;
|
||||||
@ -1649,6 +1655,9 @@ static void vsir_validate_register(struct validation_context *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case VKD3DSPR_SSA:
|
case VKD3DSPR_SSA:
|
||||||
|
{
|
||||||
|
struct validation_context_ssa_data *data;
|
||||||
|
|
||||||
if (reg->idx_count != 1)
|
if (reg->idx_count != 1)
|
||||||
{
|
{
|
||||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_INDEX_COUNT, "Invalid index count %u for a SSA register.",
|
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_INDEX_COUNT, "Invalid index count %u for a SSA register.",
|
||||||
@ -1660,9 +1669,36 @@ static void vsir_validate_register(struct validation_context *ctx,
|
|||||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_INDEX, "Non-NULL relative address for a SSA register.");
|
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_INDEX, "Non-NULL relative address for a SSA register.");
|
||||||
|
|
||||||
if (reg->idx[0].offset >= ctx->parser->shader_desc.ssa_count)
|
if (reg->idx[0].offset >= ctx->parser->shader_desc.ssa_count)
|
||||||
|
{
|
||||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_INDEX, "SSA register index %u exceeds the maximum count %u.",
|
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_INDEX, "SSA register index %u exceeds the maximum count %u.",
|
||||||
reg->idx[0].offset, ctx->parser->shader_desc.ssa_count);
|
reg->idx[0].offset, ctx->parser->shader_desc.ssa_count);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
data = &ctx->ssas[reg->idx[0].offset];
|
||||||
|
|
||||||
|
if (reg->dimension == VSIR_DIMENSION_NONE)
|
||||||
|
{
|
||||||
|
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_DIMENSION, "Invalid dimension NONE for a SSA register.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SSA registers can be scalar or vec4, provided that each
|
||||||
|
* individual register always appears with the same
|
||||||
|
* dimension. */
|
||||||
|
if (data->dimension == VSIR_DIMENSION_NONE)
|
||||||
|
{
|
||||||
|
data->dimension = reg->dimension;
|
||||||
|
data->first_seen = ctx->instruction_idx;
|
||||||
|
}
|
||||||
|
else if (data->dimension != reg->dimension)
|
||||||
|
{
|
||||||
|
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_DIMENSION, "Invalid dimension %#x for a SSA register: "
|
||||||
|
"it has already been seen with dimension %#x at instruction %zu.",
|
||||||
|
reg->dimension, data->dimension, data->first_seen);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case VKD3DSPR_NULL:
|
case VKD3DSPR_NULL:
|
||||||
if (reg->idx_count != 0)
|
if (reg->idx_count != 0)
|
||||||
@ -1938,6 +1974,9 @@ enum vkd3d_result vsir_validate(struct vkd3d_shader_parser *parser)
|
|||||||
if (!(ctx.temps = vkd3d_calloc(parser->shader_desc.temp_count, sizeof(*ctx.temps))))
|
if (!(ctx.temps = vkd3d_calloc(parser->shader_desc.temp_count, sizeof(*ctx.temps))))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
if (!(ctx.ssas = vkd3d_calloc(parser->shader_desc.ssa_count, sizeof(*ctx.ssas))))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
for (ctx.instruction_idx = 0; ctx.instruction_idx < parser->instructions.count; ++ctx.instruction_idx)
|
for (ctx.instruction_idx = 0; ctx.instruction_idx < parser->instructions.count; ++ctx.instruction_idx)
|
||||||
vsir_validate_instruction(&ctx);
|
vsir_validate_instruction(&ctx);
|
||||||
|
|
||||||
@ -1946,12 +1985,14 @@ enum vkd3d_result vsir_validate(struct vkd3d_shader_parser *parser)
|
|||||||
|
|
||||||
vkd3d_free(ctx.blocks);
|
vkd3d_free(ctx.blocks);
|
||||||
vkd3d_free(ctx.temps);
|
vkd3d_free(ctx.temps);
|
||||||
|
vkd3d_free(ctx.ssas);
|
||||||
|
|
||||||
return VKD3D_OK;
|
return VKD3D_OK;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
vkd3d_free(ctx.blocks);
|
vkd3d_free(ctx.blocks);
|
||||||
vkd3d_free(ctx.temps);
|
vkd3d_free(ctx.temps);
|
||||||
|
vkd3d_free(ctx.ssas);
|
||||||
|
|
||||||
return VKD3D_ERROR_OUT_OF_MEMORY;
|
return VKD3D_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user