mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-09-12 18:50:22 -07:00
vkd3d-shader/ir: Do not make a local copy of the instructions array in vsir_program_flatten_hull_shader_phases().
This commit is contained in:
committed by
Henri Verbeet
parent
44ca7b7b1b
commit
15561c1e56
Notes:
Henri Verbeet
2025-07-14 18:54:01 +02:00
Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1612
@@ -2056,7 +2056,6 @@ static enum vkd3d_result vsir_program_remap_output_signature(struct vsir_program
|
|||||||
|
|
||||||
struct hull_flattener
|
struct hull_flattener
|
||||||
{
|
{
|
||||||
struct vkd3d_shader_instruction_array instructions;
|
|
||||||
struct vsir_program *program;
|
struct vsir_program *program;
|
||||||
|
|
||||||
unsigned int instance_count;
|
unsigned int instance_count;
|
||||||
@@ -2089,7 +2088,7 @@ struct shader_phase_location_array
|
|||||||
static void flattener_eliminate_phase_related_dcls(struct hull_flattener *normaliser,
|
static void flattener_eliminate_phase_related_dcls(struct hull_flattener *normaliser,
|
||||||
unsigned int index, struct shader_phase_location_array *locations)
|
unsigned int index, struct shader_phase_location_array *locations)
|
||||||
{
|
{
|
||||||
struct vkd3d_shader_instruction *ins = &normaliser->instructions.elements[index];
|
struct vkd3d_shader_instruction *ins = &normaliser->program->instructions.elements[index];
|
||||||
struct shader_phase_location *loc;
|
struct shader_phase_location *loc;
|
||||||
bool b;
|
bool b;
|
||||||
|
|
||||||
@@ -2200,23 +2199,24 @@ static void flattener_fixup_registers(struct hull_flattener *normaliser,
|
|||||||
static enum vkd3d_result flattener_flatten_phases(struct hull_flattener *normaliser,
|
static enum vkd3d_result flattener_flatten_phases(struct hull_flattener *normaliser,
|
||||||
struct shader_phase_location_array *locations)
|
struct shader_phase_location_array *locations)
|
||||||
{
|
{
|
||||||
|
struct vkd3d_shader_instruction_array *instructions = &normaliser->program->instructions;
|
||||||
struct shader_phase_location *loc;
|
struct shader_phase_location *loc;
|
||||||
unsigned int i, j, k, end, count;
|
unsigned int i, j, k, end, count;
|
||||||
|
|
||||||
for (i = 0, count = 0; i < locations->count; ++i)
|
for (i = 0, count = 0; i < locations->count; ++i)
|
||||||
count += (locations->locations[i].instance_count - 1) * locations->locations[i].instruction_count;
|
count += (locations->locations[i].instance_count - 1) * locations->locations[i].instruction_count;
|
||||||
|
|
||||||
if (!shader_instruction_array_reserve(&normaliser->instructions, normaliser->instructions.count + count))
|
if (!shader_instruction_array_reserve(instructions, instructions->count + count))
|
||||||
return VKD3D_ERROR_OUT_OF_MEMORY;
|
return VKD3D_ERROR_OUT_OF_MEMORY;
|
||||||
end = normaliser->instructions.count;
|
end = instructions->count;
|
||||||
normaliser->instructions.count += count;
|
instructions->count += count;
|
||||||
|
|
||||||
for (i = locations->count; i > 0; --i)
|
for (i = locations->count; i > 0; --i)
|
||||||
{
|
{
|
||||||
loc = &locations->locations[i - 1];
|
loc = &locations->locations[i - 1];
|
||||||
j = loc->index + loc->instruction_count;
|
j = loc->index + loc->instruction_count;
|
||||||
memmove(&normaliser->instructions.elements[j + count], &normaliser->instructions.elements[j],
|
memmove(&instructions->elements[j + count], &instructions->elements[j],
|
||||||
(end - j) * sizeof(*normaliser->instructions.elements));
|
(end - j) * sizeof(*instructions->elements));
|
||||||
end = j;
|
end = j;
|
||||||
count -= (loc->instance_count - 1) * loc->instruction_count;
|
count -= (loc->instance_count - 1) * loc->instruction_count;
|
||||||
loc->index += count;
|
loc->index += count;
|
||||||
@@ -2230,7 +2230,7 @@ static enum vkd3d_result flattener_flatten_phases(struct hull_flattener *normali
|
|||||||
{
|
{
|
||||||
for (k = 0; k < loc->instruction_count; ++k)
|
for (k = 0; k < loc->instruction_count; ++k)
|
||||||
{
|
{
|
||||||
if (!shader_instruction_array_clone_instruction(&normaliser->instructions,
|
if (!shader_instruction_array_clone_instruction(instructions,
|
||||||
loc->index + loc->instruction_count * j + k, loc->index + k))
|
loc->index + loc->instruction_count * j + k, loc->index + k))
|
||||||
return VKD3D_ERROR_OUT_OF_MEMORY;
|
return VKD3D_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
@@ -2243,7 +2243,7 @@ static enum vkd3d_result flattener_flatten_phases(struct hull_flattener *normali
|
|||||||
|
|
||||||
for (k = 0; k < loc->instruction_count; ++k)
|
for (k = 0; k < loc->instruction_count; ++k)
|
||||||
flattener_fixup_registers(normaliser,
|
flattener_fixup_registers(normaliser,
|
||||||
&normaliser->instructions.elements[loc->index + loc->instruction_count * j + k], j);
|
&instructions->elements[loc->index + loc->instruction_count * j + k], j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2253,14 +2253,12 @@ static enum vkd3d_result flattener_flatten_phases(struct hull_flattener *normali
|
|||||||
static enum vkd3d_result vsir_program_flatten_hull_shader_phases(struct vsir_program *program,
|
static enum vkd3d_result vsir_program_flatten_hull_shader_phases(struct vsir_program *program,
|
||||||
struct vsir_transformation_context *ctx)
|
struct vsir_transformation_context *ctx)
|
||||||
{
|
{
|
||||||
struct hull_flattener flattener = {program->instructions, program};
|
struct vkd3d_shader_instruction_array *instructions = &program->instructions;
|
||||||
struct vkd3d_shader_instruction_array *instructions;
|
|
||||||
struct shader_phase_location_array locations;
|
struct shader_phase_location_array locations;
|
||||||
|
struct hull_flattener flattener = {program};
|
||||||
enum vkd3d_result result = VKD3D_OK;
|
enum vkd3d_result result = VKD3D_OK;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
instructions = &flattener.instructions;
|
|
||||||
|
|
||||||
flattener.phase = VSIR_OP_INVALID;
|
flattener.phase = VSIR_OP_INVALID;
|
||||||
for (i = 0, locations.count = 0; i < instructions->count; ++i)
|
for (i = 0, locations.count = 0; i < instructions->count; ++i)
|
||||||
flattener_eliminate_phase_related_dcls(&flattener, i, &locations);
|
flattener_eliminate_phase_related_dcls(&flattener, i, &locations);
|
||||||
@@ -2281,13 +2279,12 @@ static enum vkd3d_result vsir_program_flatten_hull_shader_phases(struct vsir_pro
|
|||||||
|
|
||||||
if (flattener.phase != VSIR_OP_INVALID)
|
if (flattener.phase != VSIR_OP_INVALID)
|
||||||
{
|
{
|
||||||
if (!shader_instruction_array_reserve(&flattener.instructions, flattener.instructions.count + 1))
|
if (!shader_instruction_array_reserve(instructions, instructions->count + 1))
|
||||||
return VKD3D_ERROR_OUT_OF_MEMORY;
|
return VKD3D_ERROR_OUT_OF_MEMORY;
|
||||||
vsir_instruction_init(&instructions->elements[instructions->count++],
|
vsir_instruction_init(&instructions->elements[instructions->count++],
|
||||||
&flattener.last_ret_location, VSIR_OP_RET);
|
&flattener.last_ret_location, VSIR_OP_RET);
|
||||||
}
|
}
|
||||||
|
|
||||||
program->instructions = flattener.instructions;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user