vkd3d-shader/ir: Check that semantic indices for tessellation system values are not duplicated.

This commit is contained in:
Giovanni Mascellani 2024-11-15 14:26:43 +01:00 committed by Henri Verbeet
parent 8d8de1db10
commit 49ec9add38
Notes: Henri Verbeet 2024-11-21 19:36:02 +01:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1266

View File

@ -6665,6 +6665,9 @@ struct validation_context
enum vkd3d_shader_opcode *blocks; enum vkd3d_shader_opcode *blocks;
size_t depth; size_t depth;
size_t blocks_capacity; size_t blocks_capacity;
unsigned int outer_tess_idxs[4];
unsigned int inner_tess_idxs[2];
}; };
static void VKD3D_PRINTF_FUNC(3, 4) validator_error(struct validation_context *ctx, static void VKD3D_PRINTF_FUNC(3, 4) validator_error(struct validation_context *ctx,
@ -7471,8 +7474,8 @@ static void vsir_validate_signature_element(struct validation_context *ctx,
{ {
const char *signature_type_name = signature_type_names[signature_type]; const char *signature_type_name = signature_type_names[signature_type];
const struct signature_element *element = &signature->elements[idx]; const struct signature_element *element = &signature->elements[idx];
bool integer_type = false, is_outer = false;
unsigned int semantic_index_max = 0; unsigned int semantic_index_max = 0;
bool integer_type = false;
if (element->register_count == 0) if (element->register_count == 0)
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_SIGNATURE, validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_SIGNATURE,
@ -7534,23 +7537,28 @@ static void vsir_validate_signature_element(struct validation_context *ctx,
case VKD3D_SHADER_SV_TESS_FACTOR_QUADEDGE: case VKD3D_SHADER_SV_TESS_FACTOR_QUADEDGE:
semantic_index_max = 4; semantic_index_max = 4;
is_outer = true;
break; break;
case VKD3D_SHADER_SV_TESS_FACTOR_QUADINT: case VKD3D_SHADER_SV_TESS_FACTOR_QUADINT:
semantic_index_max = 2; semantic_index_max = 2;
is_outer = false;
break; break;
case VKD3D_SHADER_SV_TESS_FACTOR_TRIEDGE: case VKD3D_SHADER_SV_TESS_FACTOR_TRIEDGE:
semantic_index_max = 3; semantic_index_max = 3;
is_outer = true;
break; break;
case VKD3D_SHADER_SV_TESS_FACTOR_TRIINT: case VKD3D_SHADER_SV_TESS_FACTOR_TRIINT:
semantic_index_max = 1; semantic_index_max = 1;
is_outer = false;
break; break;
case VKD3D_SHADER_SV_TESS_FACTOR_LINEDET: case VKD3D_SHADER_SV_TESS_FACTOR_LINEDET:
case VKD3D_SHADER_SV_TESS_FACTOR_LINEDEN: case VKD3D_SHADER_SV_TESS_FACTOR_LINEDEN:
semantic_index_max = 2; semantic_index_max = 2;
is_outer = true;
break; break;
default: default:
@ -7560,10 +7568,26 @@ static void vsir_validate_signature_element(struct validation_context *ctx,
break; break;
} }
if (semantic_index_max != 0 && element->semantic_index >= semantic_index_max) if (semantic_index_max != 0)
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_SIGNATURE, {
"element %u of %s signature: Invalid semantic index %u for system value semantic %#x.", if (element->semantic_index >= semantic_index_max)
idx, signature_type_name, element->semantic_index, element->sysval_semantic); {
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_SIGNATURE,
"element %u of %s signature: Invalid semantic index %u for system value semantic %#x.",
idx, signature_type_name, element->semantic_index, element->sysval_semantic);
}
else
{
unsigned int *idx_pos = &(is_outer ? ctx->outer_tess_idxs : ctx->inner_tess_idxs)[element->semantic_index];
if (*idx_pos != ~0u)
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_SIGNATURE,
"element %u of %s signature: Duplicate semantic index %u for system value semantic %#x.",
idx, signature_type_name, element->semantic_index, element->sysval_semantic);
else
*idx_pos = idx;
}
}
if (element->sysval_semantic < ARRAY_SIZE(sysval_validation_data)) if (element->sysval_semantic < ARRAY_SIZE(sysval_validation_data))
{ {
@ -8198,6 +8222,12 @@ enum vkd3d_result vsir_program_validate(struct vsir_program *program, uint64_t c
.status = VKD3D_OK, .status = VKD3D_OK,
.phase = VKD3DSIH_INVALID, .phase = VKD3DSIH_INVALID,
.invalid_instruction_idx = true, .invalid_instruction_idx = true,
.outer_tess_idxs[0] = ~0u,
.outer_tess_idxs[1] = ~0u,
.outer_tess_idxs[2] = ~0u,
.outer_tess_idxs[3] = ~0u,
.inner_tess_idxs[0] = ~0u,
.inner_tess_idxs[1] = ~0u,
}; };
unsigned int i; unsigned int i;