vkd3d-shader: Factor out a vsir_program_get_parameter() helper.

This commit is contained in:
Elizabeth Figura 2024-07-18 21:38:37 -05:00 committed by Henri Verbeet
parent 6b58b6f261
commit f6dd6d52b3
Notes: Henri Verbeet 2024-07-23 21:18:54 +02:00
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/956
3 changed files with 24 additions and 34 deletions

View File

@ -105,6 +105,18 @@ void vsir_program_cleanup(struct vsir_program *program)
shader_signature_cleanup(&program->patch_constant_signature); shader_signature_cleanup(&program->patch_constant_signature);
} }
const struct vkd3d_shader_parameter1 *vsir_program_get_parameter(
const struct vsir_program *program, enum vkd3d_shader_parameter_name name)
{
for (unsigned int i = 0; i < program->parameter_count; ++i)
{
if (program->parameters[i].name == name)
return &program->parameters[i];
}
return NULL;
}
static inline bool shader_register_is_phase_instance_id(const struct vkd3d_shader_register *reg) static inline bool shader_register_is_phase_instance_id(const struct vkd3d_shader_register *reg)
{ {
return reg->type == VKD3DSPR_FORKINSTID || reg->type == VKD3DSPR_JOININSTID; return reg->type == VKD3DSPR_FORKINSTID || reg->type == VKD3DSPR_JOININSTID;
@ -5541,17 +5553,8 @@ static enum vkd3d_result vsir_program_insert_alpha_test(struct vsir_program *pro
|| !(program->output_signature.elements[colour_signature_idx].mask & VKD3DSP_WRITEMASK_3)) || !(program->output_signature.elements[colour_signature_idx].mask & VKD3DSP_WRITEMASK_3))
return VKD3D_OK; return VKD3D_OK;
for (unsigned int i = 0; i < program->parameter_count; ++i) if (!(func = vsir_program_get_parameter(program, VKD3D_SHADER_PARAMETER_NAME_ALPHA_TEST_FUNC))
{ || !(ref = vsir_program_get_parameter(program, VKD3D_SHADER_PARAMETER_NAME_ALPHA_TEST_REF)))
const struct vkd3d_shader_parameter1 *parameter = &program->parameters[i];
if (parameter->name == VKD3D_SHADER_PARAMETER_NAME_ALPHA_TEST_FUNC)
func = parameter;
else if (parameter->name == VKD3D_SHADER_PARAMETER_NAME_ALPHA_TEST_REF)
ref = parameter;
}
if (!func || !ref)
return VKD3D_OK; return VKD3D_OK;
if (func->type != VKD3D_SHADER_PARAMETER_TYPE_IMMEDIATE_CONSTANT) if (func->type != VKD3D_SHADER_PARAMETER_TYPE_IMMEDIATE_CONSTANT)

View File

@ -2393,6 +2393,7 @@ struct ssa_register_info
struct spirv_compiler struct spirv_compiler
{ {
struct vkd3d_spirv_builder spirv_builder; struct vkd3d_spirv_builder spirv_builder;
const struct vsir_program *program;
struct vkd3d_shader_message_context *message_context; struct vkd3d_shader_message_context *message_context;
struct vkd3d_shader_location location; struct vkd3d_shader_location location;
@ -2418,8 +2419,6 @@ struct spirv_compiler
uint32_t *descriptor_offset_ids; uint32_t *descriptor_offset_ids;
struct vkd3d_push_constant_buffer_binding *push_constants; struct vkd3d_push_constant_buffer_binding *push_constants;
const struct vkd3d_shader_spirv_target_info *spirv_target_info; const struct vkd3d_shader_spirv_target_info *spirv_target_info;
const struct vkd3d_shader_parameter1 *parameters;
unsigned int parameter_count;
struct struct
{ {
@ -3287,20 +3286,6 @@ static uint32_t spirv_compiler_emit_array_variable(struct spirv_compiler *compil
return vkd3d_spirv_build_op_variable(builder, stream, ptr_type_id, storage_class, 0); return vkd3d_spirv_build_op_variable(builder, stream, ptr_type_id, storage_class, 0);
} }
static const struct vkd3d_shader_parameter1 *spirv_compiler_get_shader_parameter(
struct spirv_compiler *compiler, enum vkd3d_shader_parameter_name name)
{
unsigned int i;
for (i = 0; i < compiler->parameter_count; ++i)
{
if (compiler->parameters[i].name == name)
return &compiler->parameters[i];
}
return NULL;
}
static const struct vkd3d_spec_constant_info static const struct vkd3d_spec_constant_info
{ {
enum vkd3d_shader_parameter_name name; enum vkd3d_shader_parameter_name name;
@ -3394,7 +3379,7 @@ static uint32_t spirv_compiler_get_buffer_parameter(struct spirv_compiler *compi
const struct vkd3d_shader_parameter1 *parameter, enum vkd3d_data_type type) const struct vkd3d_shader_parameter1 *parameter, enum vkd3d_data_type type)
{ {
struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; struct vkd3d_spirv_builder *builder = &compiler->spirv_builder;
unsigned int index = parameter - compiler->parameters; unsigned int index = parameter - compiler->program->parameters;
uint32_t type_id, ptr_id, ptr_type_id; uint32_t type_id, ptr_id, ptr_type_id;
type_id = vkd3d_spirv_get_type_id(builder, vkd3d_component_type_from_data_type(type), 1); type_id = vkd3d_spirv_get_type_id(builder, vkd3d_component_type_from_data_type(type), 1);
@ -3411,7 +3396,7 @@ static uint32_t spirv_compiler_emit_shader_parameter(struct spirv_compiler *comp
const struct vkd3d_shader_parameter1 *parameter; const struct vkd3d_shader_parameter1 *parameter;
enum vkd3d_data_type type = VKD3D_DATA_UINT; enum vkd3d_data_type type = VKD3D_DATA_UINT;
if (!(parameter = spirv_compiler_get_shader_parameter(compiler, name))) if (!(parameter = vsir_program_get_parameter(compiler->program, name)))
{ {
WARN("Unresolved shader parameter %#x.\n", name); WARN("Unresolved shader parameter %#x.\n", name);
goto default_parameter; goto default_parameter;
@ -10604,12 +10589,10 @@ static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler, struct
spirv_compiler_emit_descriptor_declarations(compiler); spirv_compiler_emit_descriptor_declarations(compiler);
compiler->parameter_count = program->parameter_count; compiler->spirv_parameter_info = vkd3d_calloc(program->parameter_count, sizeof(*compiler->spirv_parameter_info));
compiler->parameters = program->parameters; for (i = 0; i < program->parameter_count; ++i)
compiler->spirv_parameter_info = vkd3d_calloc(compiler->parameter_count, sizeof(*compiler->spirv_parameter_info));
for (i = 0; i < compiler->parameter_count; ++i)
{ {
const struct vkd3d_shader_parameter1 *parameter = &compiler->parameters[i]; const struct vkd3d_shader_parameter1 *parameter = &program->parameters[i];
if (parameter->type == VKD3D_SHADER_PARAMETER_TYPE_BUFFER) if (parameter->type == VKD3D_SHADER_PARAMETER_TYPE_BUFFER)
{ {
@ -10636,6 +10619,8 @@ static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler, struct
if (program->block_count && !spirv_compiler_init_blocks(compiler, program->block_count)) if (program->block_count && !spirv_compiler_init_blocks(compiler, program->block_count))
return VKD3D_ERROR_OUT_OF_MEMORY; return VKD3D_ERROR_OUT_OF_MEMORY;
compiler->program = program;
instructions = program->instructions; instructions = program->instructions;
memset(&program->instructions, 0, sizeof(program->instructions)); memset(&program->instructions, 0, sizeof(program->instructions));

View File

@ -1382,6 +1382,8 @@ void vsir_program_cleanup(struct vsir_program *program);
int vsir_program_compile(struct vsir_program *program, uint64_t config_flags, int vsir_program_compile(struct vsir_program *program, uint64_t config_flags,
const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out, const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out,
struct vkd3d_shader_message_context *message_context); struct vkd3d_shader_message_context *message_context);
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, 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); const struct vkd3d_shader_version *version, unsigned int reserve);
enum vkd3d_result vsir_program_normalise(struct vsir_program *program, uint64_t config_flags, enum vkd3d_result vsir_program_normalise(struct vsir_program *program, uint64_t config_flags,