vkd3d-shader/hlsl: Simplify allocate_const_registers_recurse() to stop accounting for constants larger than a vector.

That cannot happen with the current code.
This commit is contained in:
Zebediah Figura 2023-02-24 16:24:47 -06:00 committed by Alexandre Julliard
parent 8a2b357855
commit e5afbda34a
Notes: Alexandre Julliard 2023-07-04 23:26:22 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Francisco Casas (@fcasas)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/254

View File

@ -3268,16 +3268,15 @@ static void allocate_const_registers_recurse(struct hlsl_ctx *ctx,
{
struct hlsl_ir_constant *constant = hlsl_ir_constant(instr);
const struct hlsl_type *type = instr->data_type;
unsigned int x, y, i, writemask, end_reg;
unsigned int reg_size = type->reg_size[HLSL_REGSET_NUMERIC];
unsigned int x, i, end_reg;
constant->reg = allocate_numeric_registers_for_type(ctx, allocator, 1, UINT_MAX, type);
TRACE("Allocated constant @%u to %s.\n", instr->index, debug_register('c', constant->reg, type));
if (!hlsl_array_reserve(ctx, (void **)&defs->values, &defs->size,
constant->reg.id + reg_size / 4, sizeof(*defs->values)))
constant->reg.id + 1, sizeof(*defs->values)))
return;
end_reg = constant->reg.id + reg_size / 4;
end_reg = constant->reg.id + 1;
if (end_reg > defs->count)
{
memset(&defs->values[defs->count], 0, sizeof(*defs->values) * (end_reg - defs->count));
@ -3285,49 +3284,45 @@ static void allocate_const_registers_recurse(struct hlsl_ctx *ctx,
}
assert(type->class <= HLSL_CLASS_LAST_NUMERIC);
assert(type->dimy == 1);
assert(constant->reg.writemask);
if (!(writemask = constant->reg.writemask))
writemask = (1u << type->dimx) - 1;
for (y = 0; y < type->dimy; ++y)
for (x = 0, i = 0; x < 4; ++x)
{
for (x = 0, i = 0; x < 4; ++x)
const union hlsl_constant_value_component *value;
float f;
if (!(constant->reg.writemask & (1u << x)))
continue;
value = &constant->value.u[i++];
switch (type->base_type)
{
const union hlsl_constant_value_component *value;
float f;
case HLSL_TYPE_BOOL:
f = !!value->u;
break;
if (!(writemask & (1u << x)))
continue;
value = &constant->value.u[i++];
case HLSL_TYPE_FLOAT:
case HLSL_TYPE_HALF:
f = value->f;
break;
switch (type->base_type)
{
case HLSL_TYPE_BOOL:
f = !!value->u;
break;
case HLSL_TYPE_INT:
f = value->i;
break;
case HLSL_TYPE_FLOAT:
case HLSL_TYPE_HALF:
f = value->f;
break;
case HLSL_TYPE_UINT:
f = value->u;
break;
case HLSL_TYPE_INT:
f = value->i;
break;
case HLSL_TYPE_DOUBLE:
FIXME("Double constant.\n");
return;
case HLSL_TYPE_UINT:
f = value->u;
break;
case HLSL_TYPE_DOUBLE:
FIXME("Double constant.\n");
return;
default:
vkd3d_unreachable();
}
defs->values[constant->reg.id + y].f[x] = f;
default:
vkd3d_unreachable();
}
defs->values[constant->reg.id].f[x] = f;
}
break;