vkd3d-shader/ir: Represent the normalisation level with an enumeration.

This commit is contained in:
Giovanni Mascellani 2024-10-17 21:56:39 +02:00 committed by Henri Verbeet
parent 9f3b21cc78
commit ed4d45355a
Notes: Henri Verbeet 2024-10-21 18:42:33 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1199
9 changed files with 30 additions and 32 deletions

View File

@ -1320,7 +1320,7 @@ static enum vkd3d_result shader_sm1_init(struct vkd3d_shader_sm1_parser *sm1, st
/* Estimate instruction count to avoid reallocation in most shaders. */
if (!vsir_program_init(program, compile_info, &version,
code_size != ~(size_t)0 ? token_count / 4u + 4 : 16, VSIR_CF_STRUCTURED, false))
code_size != ~(size_t)0 ? token_count / 4u + 4 : 16, VSIR_CF_STRUCTURED, VSIR_NOT_NORMALISED))
return VKD3D_ERROR_OUT_OF_MEMORY;
vkd3d_shader_parser_init(&sm1->p, program, message_context, compile_info->source_name);

View File

@ -10312,7 +10312,7 @@ static enum vkd3d_result sm6_parser_init(struct sm6_parser *sm6, struct vsir_pro
/* Estimate instruction count to avoid reallocation in most shaders. */
count = max(token_count, 400) - 400;
if (!vsir_program_init(program, compile_info, &version,
(count + (count >> 2)) / 2u + 10, VSIR_CF_BLOCKS, true))
(count + (count >> 2)) / 2u + 10, VSIR_CF_BLOCKS, VSIR_FULLY_NORMALISED_IO))
return VKD3D_ERROR_OUT_OF_MEMORY;
vkd3d_shader_parser_init(&sm6->p, program, message_context, compile_info->source_name);
sm6->ptr = &sm6->start[1];

View File

@ -2213,8 +2213,7 @@ int glsl_compile(struct vsir_program *program, uint64_t config_flags,
if ((ret = vsir_program_transform(program, config_flags, compile_info, message_context)) < 0)
return ret;
VKD3D_ASSERT(program->normalised_io);
VKD3D_ASSERT(program->normalised_hull_cp_io);
VKD3D_ASSERT(program->normalisation_level == VSIR_FULLY_NORMALISED_IO);
vkd3d_glsl_generator_init(&generator, program, compile_info,
descriptor_info, combined_sampler_info, message_context);

View File

@ -7371,7 +7371,7 @@ static void sm1_generate_vsir(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl
version.major = ctx->profile->major_version;
version.minor = ctx->profile->minor_version;
version.type = ctx->profile->type;
if (!vsir_program_init(program, NULL, &version, 0, VSIR_CF_STRUCTURED, false))
if (!vsir_program_init(program, NULL, &version, 0, VSIR_CF_STRUCTURED, VSIR_NOT_NORMALISED))
{
ctx->result = VKD3D_ERROR_OUT_OF_MEMORY;
return;
@ -7409,7 +7409,7 @@ static void sm4_generate_vsir(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl
version.minor = ctx->profile->minor_version;
version.type = ctx->profile->type;
if (!vsir_program_init(program, NULL, &version, 0, VSIR_CF_STRUCTURED, false))
if (!vsir_program_init(program, NULL, &version, 0, VSIR_CF_STRUCTURED, VSIR_NOT_NORMALISED))
{
ctx->result = VKD3D_ERROR_OUT_OF_MEMORY;
return;

View File

@ -75,7 +75,7 @@ static int convert_parameter_info(const struct vkd3d_shader_compile_info *compil
bool vsir_program_init(struct vsir_program *program, const struct vkd3d_shader_compile_info *compile_info,
const struct vkd3d_shader_version *version, unsigned int reserve, enum vsir_control_flow_type cf_type,
bool normalised_io)
enum vsir_normalisation_level normalisation_level)
{
memset(program, 0, sizeof(*program));
@ -98,8 +98,7 @@ bool vsir_program_init(struct vsir_program *program, const struct vkd3d_shader_c
program->shader_version = *version;
program->cf_type = cf_type;
program->normalised_io = normalised_io;
program->normalised_hull_cp_io = normalised_io;
program->normalisation_level = normalisation_level;
return shader_instruction_array_init(&program->instructions, reserve);
}
@ -1135,11 +1134,11 @@ static enum vkd3d_result instruction_array_normalise_hull_shader_control_point_i
enum vkd3d_result ret;
unsigned int i, j;
VKD3D_ASSERT(!program->normalised_hull_cp_io);
VKD3D_ASSERT(program->normalisation_level == VSIR_NOT_NORMALISED);
if (program->shader_version.type != VKD3D_SHADER_TYPE_HULL)
{
program->normalised_hull_cp_io = true;
program->normalisation_level = VSIR_NORMALISED_HULL_CONTROL_POINT_IO;
return VKD3D_OK;
}
@ -1186,7 +1185,7 @@ static enum vkd3d_result instruction_array_normalise_hull_shader_control_point_i
break;
case VKD3DSIH_HS_CONTROL_POINT_PHASE:
program->instructions = normaliser.instructions;
program->normalised_hull_cp_io = true;
program->normalisation_level = VSIR_NORMALISED_HULL_CONTROL_POINT_IO;
return VKD3D_OK;
case VKD3DSIH_HS_FORK_PHASE:
case VKD3DSIH_HS_JOIN_PHASE:
@ -1195,7 +1194,7 @@ static enum vkd3d_result instruction_array_normalise_hull_shader_control_point_i
ret = control_point_normaliser_emit_hs_input(&normaliser, &program->input_signature,
input_control_point_count, i, &location);
program->instructions = normaliser.instructions;
program->normalised_hull_cp_io = true;
program->normalisation_level = VSIR_NORMALISED_HULL_CONTROL_POINT_IO;
return ret;
default:
break;
@ -1203,7 +1202,7 @@ static enum vkd3d_result instruction_array_normalise_hull_shader_control_point_i
}
program->instructions = normaliser.instructions;
program->normalised_hull_cp_io = true;
program->normalisation_level = VSIR_NORMALISED_HULL_CONTROL_POINT_IO;
return VKD3D_OK;
}
@ -1917,7 +1916,7 @@ static enum vkd3d_result vsir_program_normalise_io_registers(struct vsir_program
struct vkd3d_shader_instruction *ins;
unsigned int i;
VKD3D_ASSERT(!program->normalised_io);
VKD3D_ASSERT(program->normalisation_level == VSIR_NORMALISED_HULL_CONTROL_POINT_IO);
normaliser.phase = VKD3DSIH_INVALID;
normaliser.shader_type = program->shader_version.type;
@ -1975,7 +1974,7 @@ static enum vkd3d_result vsir_program_normalise_io_registers(struct vsir_program
program->instructions = normaliser.instructions;
program->use_vocp = normaliser.use_vocp;
program->normalised_io = true;
program->normalisation_level = VSIR_FULLY_NORMALISED_IO;
return VKD3D_OK;
}
@ -6234,15 +6233,11 @@ static void vsir_validate_io_register(struct validation_context *ctx,
switch (ctx->program->shader_version.type)
{
case VKD3D_SHADER_TYPE_HULL:
if (ctx->phase == VKD3DSIH_HS_CONTROL_POINT_PHASE)
if (ctx->phase == VKD3DSIH_HS_CONTROL_POINT_PHASE
|| ctx->program->normalisation_level >= VSIR_FULLY_NORMALISED_IO)
{
signature = &ctx->program->output_signature;
has_control_point = ctx->program->normalised_hull_cp_io;
}
else if (ctx->program->normalised_io)
{
signature = &ctx->program->output_signature;
has_control_point = true;
has_control_point = ctx->program->normalisation_level >= VSIR_NORMALISED_HULL_CONTROL_POINT_IO;
}
else
{
@ -6274,7 +6269,7 @@ static void vsir_validate_io_register(struct validation_context *ctx,
vkd3d_unreachable();
}
if (!ctx->program->normalised_io)
if (ctx->program->normalisation_level < VSIR_FULLY_NORMALISED_IO)
{
/* Indices are [register] or [control point, register]. Both are
* allowed to have a relative address. */

View File

@ -869,8 +869,7 @@ int msl_compile(struct vsir_program *program, uint64_t config_flags,
if ((ret = vsir_program_transform(program, config_flags, compile_info, message_context)) < 0)
return ret;
VKD3D_ASSERT(program->normalised_io);
VKD3D_ASSERT(program->normalised_hull_cp_io);
VKD3D_ASSERT(program->normalisation_level == VSIR_FULLY_NORMALISED_IO);
if ((ret = msl_generator_init(&generator, program, compile_info, descriptor_info, message_context)) < 0)
return ret;

View File

@ -10650,8 +10650,7 @@ static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler, struct
compile_info, compiler->message_context)) < 0)
return result;
VKD3D_ASSERT(program->normalised_io);
VKD3D_ASSERT(program->normalised_hull_cp_io);
VKD3D_ASSERT(program->normalisation_level == VSIR_FULLY_NORMALISED_IO);
max_element_count = max(program->output_signature.element_count, program->patch_constant_signature.element_count);
if (!(compiler->output_info = vkd3d_calloc(max_element_count, sizeof(*compiler->output_info))))

View File

@ -2793,7 +2793,7 @@ static bool shader_sm4_init(struct vkd3d_shader_sm4_parser *sm4, struct vsir_pro
/* Estimate instruction count to avoid reallocation in most shaders. */
if (!vsir_program_init(program, compile_info,
&version, token_count / 7u + 20, VSIR_CF_STRUCTURED, false))
&version, token_count / 7u + 20, VSIR_CF_STRUCTURED, VSIR_NOT_NORMALISED))
return false;
vkd3d_shader_parser_init(&sm4->p, program, message_context, compile_info->source_name);
sm4->ptr = sm4->start;

View File

@ -1393,6 +1393,13 @@ enum vsir_control_flow_type
VSIR_CF_BLOCKS,
};
enum vsir_normalisation_level
{
VSIR_NOT_NORMALISED,
VSIR_NORMALISED_HULL_CONTROL_POINT_IO,
VSIR_FULLY_NORMALISED_IO,
};
struct vsir_program
{
struct vkd3d_shader_version shader_version;
@ -1415,8 +1422,7 @@ struct vsir_program
bool use_vocp;
bool has_point_size;
enum vsir_control_flow_type cf_type;
bool normalised_io;
bool normalised_hull_cp_io;
enum vsir_normalisation_level normalisation_level;
const char **block_names;
size_t block_name_count;
@ -1430,7 +1436,7 @@ const struct vkd3d_shader_parameter1 *vsir_program_get_parameter(
const struct vsir_program *program, enum vkd3d_shader_parameter_name name);
bool vsir_program_init(struct vsir_program *program, const struct vkd3d_shader_compile_info *compile_info,
const struct vkd3d_shader_version *version, unsigned int reserve, enum vsir_control_flow_type cf_type,
bool normalised_io);
enum vsir_normalisation_level normalisation_level);
enum vkd3d_result vsir_program_transform(struct vsir_program *program, uint64_t config_flags,
const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_message_context *message_context);
enum vkd3d_result vsir_program_validate(struct vsir_program *program, uint64_t config_flags,