vkd3d-shader: Write SM5.1 register indices.

Separate ID and index. Allocate IDs for all external resources (but ignore them
for shader models other than 5).
This commit is contained in:
Elizabeth Figura
2023-08-29 12:13:35 -05:00
committed by Henri Verbeet
parent 19a13740de
commit 28a5e23814
Notes: Henri Verbeet 2024-06-11 17:09:29 +02:00
Approved-by: Francisco Casas (@fcasas)
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/865
4 changed files with 156 additions and 45 deletions

View File

@@ -3847,10 +3847,7 @@ static void allocate_register_reservations(struct hlsl_ctx *ctx)
else
{
var->regs[r].allocated = true;
var->regs[r].id = var->reg_reservation.reg_index;
TRACE("Allocated reserved %s to %c%u-%c%u.\n", var->name, var->reg_reservation.reg_type,
var->reg_reservation.reg_index, var->reg_reservation.reg_type,
var->reg_reservation.reg_index + var->regs[r].allocation_size);
var->regs[r].index = var->reg_reservation.reg_index;
}
}
}
@@ -4924,8 +4921,8 @@ void hlsl_calculate_buffer_offsets(struct hlsl_ctx *ctx)
static void allocate_buffers(struct hlsl_ctx *ctx)
{
struct hlsl_buffer *buffer;
uint32_t index = 0, id = 0;
struct hlsl_ir_var *var;
uint32_t index = 0;
LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, struct hlsl_ir_var, extern_entry)
{
@@ -4953,25 +4950,34 @@ static void allocate_buffers(struct hlsl_ctx *ctx)
if (reserved_buffer && reserved_buffer != buffer)
{
hlsl_error(ctx, &buffer->loc, VKD3D_SHADER_ERROR_HLSL_OVERLAPPING_RESERVATIONS,
"Multiple buffers bound to cb%u.", buffer->reservation.reg_index);
"Multiple buffers bound to index %u.", buffer->reservation.reg_index);
hlsl_note(ctx, &reserved_buffer->loc, VKD3D_SHADER_LOG_ERROR,
"Buffer %s is already bound to cb%u.", reserved_buffer->name, buffer->reservation.reg_index);
"Buffer %s is already bound to index %u.",
reserved_buffer->name, buffer->reservation.reg_index);
}
buffer->reg.id = buffer->reservation.reg_index;
buffer->reg.index = buffer->reservation.reg_index;
if (hlsl_version_ge(ctx, 5, 1))
buffer->reg.id = id++;
else
buffer->reg.id = buffer->reg.index;
buffer->reg.allocation_size = 1;
buffer->reg.allocated = true;
TRACE("Allocated reserved %s to cb%u.\n", buffer->name, index);
TRACE("Allocated reserved %s to index %u, id %u.\n", buffer->name, buffer->reg.index, buffer->reg.id);
}
else if (!buffer->reservation.reg_type)
{
while (get_reserved_buffer(ctx, index))
++index;
buffer->reg.id = index;
buffer->reg.index = index;
if (hlsl_version_ge(ctx, 5, 1))
buffer->reg.id = id++;
else
buffer->reg.id = buffer->reg.index;
buffer->reg.allocation_size = 1;
buffer->reg.allocated = true;
TRACE("Allocated %s to cb%u.\n", buffer->name, index);
TRACE("Allocated %s to index %u, id %u.\n", buffer->name, buffer->reg.index, buffer->reg.id);
++index;
}
else
@@ -5008,7 +5014,7 @@ static const struct hlsl_ir_var *get_allocated_object(struct hlsl_ctx *ctx, enum
}
else if (var->regs[regset].allocated)
{
start = var->regs[regset].id;
start = var->regs[regset].index;
count = var->regs[regset].allocation_size;
}
else
@@ -5025,8 +5031,8 @@ static const struct hlsl_ir_var *get_allocated_object(struct hlsl_ctx *ctx, enum
static void allocate_objects(struct hlsl_ctx *ctx, enum hlsl_regset regset)
{
char regset_name = get_regset_name(regset);
uint32_t min_index = 0, id = 0;
struct hlsl_ir_var *var;
uint32_t min_index = 0;
if (regset == HLSL_REGSET_UAVS)
{
@@ -5051,18 +5057,18 @@ static void allocate_objects(struct hlsl_ctx *ctx, enum hlsl_regset regset)
const struct hlsl_ir_var *reserved_object, *last_reported = NULL;
unsigned int index, i;
if (var->regs[regset].id < min_index)
if (var->regs[regset].index < min_index)
{
assert(regset == HLSL_REGSET_UAVS);
hlsl_error(ctx, &var->loc, VKD3D_SHADER_ERROR_HLSL_OVERLAPPING_RESERVATIONS,
"UAV index (%u) must be higher than the maximum render target index (%u).",
var->regs[regset].id, min_index - 1);
var->regs[regset].index, min_index - 1);
continue;
}
for (i = 0; i < count; ++i)
{
index = var->regs[regset].id + i;
index = var->regs[regset].index + i;
/* get_allocated_object() may return "var" itself, but we
* actually want that, otherwise we'll end up reporting the
@@ -5078,6 +5084,14 @@ static void allocate_objects(struct hlsl_ctx *ctx, enum hlsl_regset regset)
last_reported = reserved_object;
}
}
if (hlsl_version_ge(ctx, 5, 1))
var->regs[regset].id = id++;
else
var->regs[regset].id = var->regs[regset].index;
TRACE("Allocated reserved variable %s to indices %c%u-%c%u, id %u.\n",
var->name, regset_name, var->regs[regset].index,
regset_name, var->regs[regset].index + count, var->regs[regset].id);
}
else
{
@@ -5094,10 +5108,14 @@ static void allocate_objects(struct hlsl_ctx *ctx, enum hlsl_regset regset)
}
index -= count;
var->regs[regset].id = index;
var->regs[regset].index = index;
if (hlsl_version_ge(ctx, 5, 1))
var->regs[regset].id = id++;
else
var->regs[regset].id = var->regs[regset].index;
var->regs[regset].allocated = true;
TRACE("Allocated variable %s to %c%u-%c%u.\n", var->name, regset_name, index, regset_name,
index + count);
TRACE("Allocated variable %s to indices %c%u-%c%u, id %u.\n", var->name,
regset_name, index, regset_name, index + count, var->regs[regset].id);
++index;
}
}
@@ -5303,6 +5321,7 @@ struct hlsl_reg hlsl_reg_from_deref(struct hlsl_ctx *ctx, const struct hlsl_dere
assert(deref->data_type);
assert(hlsl_is_numeric_type(deref->data_type));
ret.index += offset / 4;
ret.id += offset / 4;
ret.writemask = 0xf & (0xf << (offset % 4));