vkd3d-shader: Keep track of whether programs have normalised I/O.

This commit is contained in:
Giovanni Mascellani 2024-10-02 14:44:38 +02:00 committed by Henri Verbeet
parent 7ae1284c16
commit eba8fd4720
Notes: Henri Verbeet 2024-10-17 17:40:38 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1196
9 changed files with 22 additions and 7 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. */ /* Estimate instruction count to avoid reallocation in most shaders. */
if (!vsir_program_init(program, compile_info, &version, if (!vsir_program_init(program, compile_info, &version,
code_size != ~(size_t)0 ? token_count / 4u + 4 : 16, VSIR_CF_STRUCTURED)) code_size != ~(size_t)0 ? token_count / 4u + 4 : 16, VSIR_CF_STRUCTURED, false))
return VKD3D_ERROR_OUT_OF_MEMORY; return VKD3D_ERROR_OUT_OF_MEMORY;
vkd3d_shader_parser_init(&sm1->p, program, message_context, compile_info->source_name); vkd3d_shader_parser_init(&sm1->p, program, message_context, compile_info->source_name);

View File

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

View File

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

View File

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

View File

@ -74,7 +74,8 @@ 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, 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) const struct vkd3d_shader_version *version, unsigned int reserve, enum vsir_control_flow_type cf_type,
bool normalised_io)
{ {
memset(program, 0, sizeof(*program)); memset(program, 0, sizeof(*program));
@ -97,6 +98,7 @@ bool vsir_program_init(struct vsir_program *program, const struct vkd3d_shader_c
program->shader_version = *version; program->shader_version = *version;
program->cf_type = cf_type; program->cf_type = cf_type;
program->normalised_io = normalised_io;
return shader_instruction_array_init(&program->instructions, reserve); return shader_instruction_array_init(&program->instructions, reserve);
} }
@ -1903,6 +1905,8 @@ static enum vkd3d_result vsir_program_normalise_io_registers(struct vsir_program
struct vkd3d_shader_instruction *ins; struct vkd3d_shader_instruction *ins;
unsigned int i; unsigned int i;
VKD3D_ASSERT(!program->normalised_io);
normaliser.phase = VKD3DSIH_INVALID; normaliser.phase = VKD3DSIH_INVALID;
normaliser.shader_type = program->shader_version.type; normaliser.shader_type = program->shader_version.type;
normaliser.major = program->shader_version.major; normaliser.major = program->shader_version.major;
@ -1959,6 +1963,7 @@ static enum vkd3d_result vsir_program_normalise_io_registers(struct vsir_program
program->instructions = normaliser.instructions; program->instructions = normaliser.instructions;
program->use_vocp = normaliser.use_vocp; program->use_vocp = normaliser.use_vocp;
program->normalised_io = true;
return VKD3D_OK; return VKD3D_OK;
} }

View File

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

View File

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

View File

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

View File

@ -1415,6 +1415,7 @@ struct vsir_program
bool use_vocp; bool use_vocp;
bool has_point_size; bool has_point_size;
enum vsir_control_flow_type cf_type; enum vsir_control_flow_type cf_type;
bool normalised_io;
const char **block_names; const char **block_names;
size_t block_name_count; size_t block_name_count;
@ -1427,7 +1428,8 @@ int vsir_program_compile(struct vsir_program *program, uint64_t config_flags,
const struct vkd3d_shader_parameter1 *vsir_program_get_parameter( const struct vkd3d_shader_parameter1 *vsir_program_get_parameter(
const struct vsir_program *program, enum vkd3d_shader_parameter_name name); 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, 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); const struct vkd3d_shader_version *version, unsigned int reserve, enum vsir_control_flow_type cf_type,
bool normalised_io);
enum vkd3d_result vsir_program_transform(struct vsir_program *program, uint64_t config_flags, 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); 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, enum vkd3d_result vsir_program_validate(struct vsir_program *program, uint64_t config_flags,