vkd3d-shader/hlsl: Validate cbuffer register allocations.

This commit is contained in:
Victor Chiletto
2024-07-03 14:05:58 -03:00
parent 27414ef928
commit da36a447b8
Notes: Henri Verbeet 2024-07-08 18:04:49 +02:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/792
2 changed files with 470 additions and 2 deletions

View File

@@ -4925,6 +4925,14 @@ void hlsl_calculate_buffer_offsets(struct hlsl_ctx *ctx)
}
}
static unsigned int get_max_cbuffer_reg_index(struct hlsl_ctx *ctx)
{
if (hlsl_version_ge(ctx, 5, 1))
return UINT_MAX;
return 13;
}
static void allocate_buffers(struct hlsl_ctx *ctx)
{
struct hlsl_buffer *buffer;
@@ -4956,6 +4964,12 @@ static void allocate_buffers(struct hlsl_ctx *ctx)
{
const struct hlsl_buffer *reserved_buffer = get_reserved_buffer(ctx,
reservation->reg_space, reservation->reg_index);
unsigned int max_index = get_max_cbuffer_reg_index(ctx);
if (buffer->reservation.reg_index > max_index)
hlsl_error(ctx, &buffer->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_RESERVATION,
"Buffer reservation cb%u exceeds target's maximum (cb%u).",
buffer->reservation.reg_index, max_index);
if (reserved_buffer && reserved_buffer != buffer)
{
@@ -4980,9 +4994,14 @@ static void allocate_buffers(struct hlsl_ctx *ctx)
}
else if (!reservation->reg_type)
{
unsigned int max_index = get_max_cbuffer_reg_index(ctx);
while (get_reserved_buffer(ctx, 0, index))
++index;
if (index > max_index)
hlsl_error(ctx, &buffer->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_RESERVATION,
"Too many buffers allocated, target's maximum is %u.", max_index);
buffer->reg.space = 0;
buffer->reg.index = index;
if (hlsl_version_ge(ctx, 5, 1))