mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
vkd3d-shader/ir: Introduce a helper for validating PHI.
This commit is contained in:
parent
9696a0cd4a
commit
e27cf68173
Notes:
Henri Verbeet
2024-09-14 16:54:24 +02:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1073
@ -6287,6 +6287,63 @@ static void vsir_validate_loop(struct validation_context *ctx, const struct vkd3
|
||||
vsir_validator_push_block(ctx, VKD3DSIH_LOOP);
|
||||
}
|
||||
|
||||
static void vsir_validate_phi(struct validation_context *ctx, const struct vkd3d_shader_instruction *instruction)
|
||||
{
|
||||
unsigned int i, incoming_count;
|
||||
|
||||
vsir_validate_cf_type(ctx, instruction, VSIR_CF_BLOCKS);
|
||||
|
||||
vsir_validate_src_min_count(ctx, instruction, 2);
|
||||
|
||||
if (instruction->src_count % 2 != 0)
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_SOURCE_COUNT,
|
||||
"Invalid source count %u for a PHI instruction, it must be an even number.",
|
||||
instruction->src_count);
|
||||
incoming_count = instruction->src_count / 2;
|
||||
|
||||
if (!register_is_ssa(&instruction->dst[0].reg))
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_REGISTER_TYPE,
|
||||
"Invalid destination of type %#x in PHI instruction, expected SSA.",
|
||||
instruction->dst[0].reg.type);
|
||||
|
||||
if (instruction->dst[0].reg.dimension != VSIR_DIMENSION_SCALAR)
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_DIMENSION,
|
||||
"Invalid destination dimension %#x in PHI instruction, expected scalar.",
|
||||
instruction->dst[0].reg.dimension);
|
||||
|
||||
if (instruction->dst[0].modifiers != VKD3DSPDM_NONE)
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_MODIFIERS,
|
||||
"Invalid modifiers %#x for the destination of a PHI instruction, expected none.",
|
||||
instruction->dst[0].modifiers);
|
||||
|
||||
if (instruction->dst[0].shift != 0)
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_SHIFT,
|
||||
"Invalid shift %#x for the destination of a PHI instruction, expected none.",
|
||||
instruction->dst[0].shift);
|
||||
|
||||
for (i = 0; i < incoming_count; ++i)
|
||||
{
|
||||
unsigned int value_idx = 2 * i;
|
||||
unsigned int label_idx = 2 * i + 1;
|
||||
|
||||
if (!register_is_constant_or_undef(&instruction->src[value_idx].reg)
|
||||
&& !register_is_ssa(&instruction->src[value_idx].reg))
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_REGISTER_TYPE,
|
||||
"Invalid value register for incoming %u of type %#x in PHI instruction, "
|
||||
"expected SSA, IMMCONST or IMMCONST64.", i, instruction->src[value_idx].reg.type);
|
||||
|
||||
if (instruction->src[value_idx].reg.dimension != VSIR_DIMENSION_SCALAR)
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_DIMENSION,
|
||||
"Invalid value dimension %#x for incoming %u in PHI instruction, expected scalar.",
|
||||
instruction->src[value_idx].reg.dimension, i);
|
||||
|
||||
if (!vsir_register_is_label(&instruction->src[label_idx].reg))
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_REGISTER_TYPE,
|
||||
"Invalid label register for case %u of type %#x in PHI instruction, "
|
||||
"expected LABEL.", i, instruction->src[value_idx].reg.type);
|
||||
}
|
||||
}
|
||||
|
||||
static void vsir_validate_rep(struct validation_context *ctx, const struct vkd3d_shader_instruction *instruction)
|
||||
{
|
||||
vsir_validate_cf_type(ctx, instruction, VSIR_CF_STRUCTURED);
|
||||
@ -6370,6 +6427,7 @@ static const struct vsir_validator_instruction_desc vsir_validator_instructions[
|
||||
[VKD3DSIH_IFC] = {0, 2, vsir_validate_ifc},
|
||||
[VKD3DSIH_LABEL] = {0, 1, vsir_validate_label},
|
||||
[VKD3DSIH_LOOP] = {0, ~0u, vsir_validate_loop},
|
||||
[VKD3DSIH_PHI] = {1, ~0u, vsir_validate_phi},
|
||||
[VKD3DSIH_REP] = {0, 1, vsir_validate_rep},
|
||||
[VKD3DSIH_RET] = {0, 0, vsir_validate_ret},
|
||||
[VKD3DSIH_SWITCH] = {0, 1, vsir_validate_switch},
|
||||
@ -6533,69 +6591,6 @@ static void vsir_validate_instruction(struct validation_context *ctx)
|
||||
desc->validate(ctx, instruction);
|
||||
}
|
||||
}
|
||||
|
||||
switch (instruction->opcode)
|
||||
{
|
||||
case VKD3DSIH_PHI:
|
||||
{
|
||||
unsigned int incoming_count;
|
||||
|
||||
vsir_validate_cf_type(ctx, instruction, VSIR_CF_BLOCKS);
|
||||
vsir_validate_dst_count(ctx, instruction, 1);
|
||||
vsir_validate_src_min_count(ctx, instruction, 2);
|
||||
if (instruction->src_count % 2 != 0)
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_SOURCE_COUNT,
|
||||
"Invalid source count %u for a PHI instruction, it must be an even number.",
|
||||
instruction->src_count);
|
||||
incoming_count = instruction->src_count / 2;
|
||||
|
||||
if (!register_is_ssa(&instruction->dst[0].reg))
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_REGISTER_TYPE,
|
||||
"Invalid destination of type %#x in PHI instruction, expected SSA.",
|
||||
instruction->dst[0].reg.type);
|
||||
|
||||
if (instruction->dst[0].reg.dimension != VSIR_DIMENSION_SCALAR)
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_DIMENSION,
|
||||
"Invalid destination dimension %#x in PHI instruction, expected scalar.",
|
||||
instruction->dst[0].reg.dimension);
|
||||
|
||||
if (instruction->dst[0].modifiers != VKD3DSPDM_NONE)
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_MODIFIERS,
|
||||
"Invalid modifiers %#x for the destination of a PHI instruction, expected none.",
|
||||
instruction->dst[0].modifiers);
|
||||
|
||||
if (instruction->dst[0].shift != 0)
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_SHIFT,
|
||||
"Invalid shift %#x for the destination of a PHI instruction, expected none.",
|
||||
instruction->dst[0].shift);
|
||||
|
||||
for (i = 0; i < incoming_count; ++i)
|
||||
{
|
||||
unsigned int value_idx = 2 * i;
|
||||
unsigned int label_idx = 2 * i + 1;
|
||||
|
||||
if (!register_is_constant_or_undef(&instruction->src[value_idx].reg)
|
||||
&& !register_is_ssa(&instruction->src[value_idx].reg))
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_REGISTER_TYPE,
|
||||
"Invalid value register for incoming %zu of type %#x in PHI instruction, "
|
||||
"expected SSA, IMMCONST or IMMCONST64.", i, instruction->src[value_idx].reg.type);
|
||||
|
||||
if (instruction->src[value_idx].reg.dimension != VSIR_DIMENSION_SCALAR)
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_DIMENSION,
|
||||
"Invalid value dimension %#x for incoming %zu in PHI instruction, expected scalar.",
|
||||
instruction->src[value_idx].reg.dimension, i);
|
||||
|
||||
if (!vsir_register_is_label(&instruction->src[label_idx].reg))
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_REGISTER_TYPE,
|
||||
"Invalid label register for case %zu of type %#x in PHI instruction, "
|
||||
"expected LABEL.", i, instruction->src[value_idx].reg.type);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
enum vkd3d_result vsir_program_validate(struct vsir_program *program, uint64_t config_flags,
|
||||
|
Loading…
x
Reference in New Issue
Block a user