vkd3d-shader: Move shader signatures to vsir_program.

This commit is contained in:
Giovanni Mascellani 2024-03-01 13:36:11 +01:00 committed by Alexandre Julliard
parent 56dc0c9842
commit 470d83a9da
Notes: Alexandre Julliard 2024-03-11 23:06:10 +01:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Francisco Casas (@fcasas)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/680
9 changed files with 88 additions and 87 deletions

View File

@ -2196,22 +2196,22 @@ static enum vkd3d_result dump_signature(struct vkd3d_d3d_asm_compiler *compiler,
}
static enum vkd3d_result dump_signatures(struct vkd3d_d3d_asm_compiler *compiler,
const struct vkd3d_shader_desc *shader_desc, enum vkd3d_shader_type shader_type)
const struct vsir_program *program)
{
enum vkd3d_result ret;
if ((ret = dump_signature(compiler, ".input",
shader_type == VKD3D_SHADER_TYPE_DOMAIN ? "vicp" : "v",
&shader_desc->input_signature)) < 0)
program->shader_version.type == VKD3D_SHADER_TYPE_DOMAIN ? "vicp" : "v",
&program->input_signature)) < 0)
return ret;
if ((ret = dump_signature(compiler, ".output", "o",
&shader_desc->output_signature)) < 0)
&program->output_signature)) < 0)
return ret;
if ((ret = dump_signature(compiler, ".patch_constant",
shader_type == VKD3D_SHADER_TYPE_DOMAIN ? "vpc" : "o",
&shader_desc->patch_constant_signature)) < 0)
program->shader_version.type == VKD3D_SHADER_TYPE_DOMAIN ? "vpc" : "o",
&program->patch_constant_signature)) < 0)
return ret;
vkd3d_string_buffer_printf(&compiler->buffer, "%s.text%s\n",
@ -2297,7 +2297,7 @@ enum vkd3d_result vkd3d_dxbc_binary_to_text(const struct vsir_program *program,
* doesn't even have an explicit concept of signature. */
if (formatting & VKD3D_SHADER_COMPILE_OPTION_FORMATTING_IO_SIGNATURES && shader_version->major >= 4)
{
if ((result = dump_signatures(&compiler, shader_desc, shader_version->type)) < 0)
if ((result = dump_signatures(&compiler, program)) < 0)
{
vkd3d_string_buffer_cleanup(buffer);
return result;

View File

@ -541,9 +541,9 @@ static bool add_signature_element(struct vkd3d_shader_sm1_parser *sm1, bool outp
struct signature_element *element;
if (output)
signature = &sm1->p.shader_desc.output_signature;
signature = &sm1->p.program.output_signature;
else
signature = &sm1->p.shader_desc.input_signature;
signature = &sm1->p.program.input_signature;
if ((element = find_signature_element(signature, name, index)))
{
@ -581,9 +581,9 @@ static void add_signature_mask(struct vkd3d_shader_sm1_parser *sm1, bool output,
struct signature_element *element;
if (output)
signature = &sm1->p.shader_desc.output_signature;
signature = &sm1->p.program.output_signature;
else
signature = &sm1->p.shader_desc.input_signature;
signature = &sm1->p.program.input_signature;
if (!(element = find_signature_element_by_register_index(signature, register_index)))
{
@ -886,7 +886,6 @@ static void shader_sm1_destroy(struct vkd3d_shader_parser *parser)
struct vkd3d_shader_sm1_parser *sm1 = vkd3d_shader_sm1_parser(parser);
vsir_program_cleanup(&parser->program);
free_shader_desc(&sm1->p.shader_desc);
vkd3d_free(sm1);
}

View File

@ -560,13 +560,6 @@ void free_dxbc_shader_desc(struct dxbc_shader_desc *desc)
shader_signature_cleanup(&desc->patch_constant_signature);
}
void free_shader_desc(struct vkd3d_shader_desc *desc)
{
shader_signature_cleanup(&desc->input_signature);
shader_signature_cleanup(&desc->output_signature);
shader_signature_cleanup(&desc->patch_constant_signature);
}
int shader_extract_from_dxbc(const struct vkd3d_shader_code *dxbc,
struct vkd3d_shader_message_context *message_context, const char *source_name, struct dxbc_shader_desc *desc)
{

View File

@ -4193,7 +4193,7 @@ static void sm6_parser_emit_dx_load_input(struct sm6_parser *sm6, enum dx_intrin
vsir_instruction_init(ins, &sm6->p.location, VKD3DSIH_MOV);
signature = &sm6->p.shader_desc.input_signature;
signature = &sm6->p.program.input_signature;
if (row_index >= signature->element_count)
{
WARN("Invalid row index %u.\n", row_index);
@ -4583,7 +4583,7 @@ static void sm6_parser_emit_dx_store_output(struct sm6_parser *sm6, enum dx_intr
row_index = sm6_value_get_constant_uint(operands[0]);
column_index = sm6_value_get_constant_uint(operands[2]);
signature = &sm6->p.shader_desc.output_signature;
signature = &sm6->p.program.output_signature;
if (row_index >= signature->element_count)
{
WARN("Invalid row index %u.\n", row_index);
@ -7827,19 +7827,19 @@ static enum vkd3d_result sm6_parser_signatures_init(struct sm6_parser *sm6, cons
}
if (m->u.node->operand_count && (ret = sm6_parser_read_signature(sm6, m->u.node->operands[0],
&sm6->p.shader_desc.input_signature)) < 0)
&sm6->p.program.input_signature)) < 0)
{
return ret;
}
if (m->u.node->operand_count > 1 && (ret = sm6_parser_read_signature(sm6, m->u.node->operands[1],
&sm6->p.shader_desc.output_signature)) < 0)
&sm6->p.program.output_signature)) < 0)
{
return ret;
}
/* TODO: patch constant signature in operand 2. */
sm6_parser_init_input_signature(sm6, &sm6->p.shader_desc.input_signature);
sm6_parser_init_output_signature(sm6, &sm6->p.shader_desc.output_signature);
sm6_parser_init_input_signature(sm6, &sm6->p.program.input_signature);
sm6_parser_init_output_signature(sm6, &sm6->p.program.output_signature);
return VKD3D_OK;
}
@ -8137,7 +8137,6 @@ static void sm6_parser_destroy(struct vkd3d_shader_parser *parser)
sm6_parser_metadata_cleanup(sm6);
vkd3d_free(sm6->descriptors);
vkd3d_free(sm6->values);
free_shader_desc(&parser->shader_desc);
vkd3d_free(sm6);
}
@ -8155,15 +8154,16 @@ static struct sm6_function *sm6_parser_get_function(const struct sm6_parser *sm6
return NULL;
}
static enum vkd3d_result sm6_parser_init(struct sm6_parser *sm6, const uint32_t *byte_code, size_t byte_code_size,
const char *source_name, struct vkd3d_shader_message_context *message_context)
static enum vkd3d_result sm6_parser_init(struct sm6_parser *sm6, const char *source_name,
struct vkd3d_shader_message_context *message_context, struct dxbc_shader_desc *dxbc_desc)
{
const struct shader_signature *output_signature = &sm6->p.shader_desc.output_signature;
const struct shader_signature *input_signature = &sm6->p.shader_desc.input_signature;
const struct shader_signature *output_signature = &sm6->p.program.output_signature;
const struct shader_signature *input_signature = &sm6->p.program.input_signature;
size_t count, length, function_count, byte_code_size = dxbc_desc->byte_code_size;
const struct vkd3d_shader_location location = {.source_name = source_name};
uint32_t version_token, dxil_version, token_count, magic;
const uint32_t *byte_code = dxbc_desc->byte_code;
unsigned int chunk_offset, chunk_size;
size_t count, length, function_count;
enum bitcode_block_abbreviation abbr;
struct vkd3d_shader_version version;
struct dxil_block *block;
@ -8256,6 +8256,11 @@ static enum vkd3d_result sm6_parser_init(struct sm6_parser *sm6, const uint32_t
sm6->ptr = &sm6->start[1];
sm6->bitpos = 2;
sm6->p.program.input_signature = dxbc_desc->input_signature;
sm6->p.program.output_signature = dxbc_desc->output_signature;
sm6->p.program.patch_constant_signature = dxbc_desc->patch_constant_signature;
memset(dxbc_desc, 0, sizeof(*dxbc_desc));
block = &sm6->root_block;
if ((ret = dxil_block_init(block, NULL, sm6)) < 0)
{
@ -8453,23 +8458,25 @@ int vkd3d_shader_sm6_parser_create(const struct vkd3d_shader_compile_info *compi
shader_desc->is_dxil = true;
shader_desc->byte_code = dxbc_desc.byte_code;
shader_desc->byte_code_size = dxbc_desc.byte_code_size;
shader_desc->input_signature = dxbc_desc.input_signature;
shader_desc->output_signature = dxbc_desc.output_signature;
shader_desc->patch_constant_signature = dxbc_desc.patch_constant_signature;
memset(&dxbc_desc, 0, sizeof(dxbc_desc));
if (((uintptr_t)shader_desc->byte_code & (VKD3D_DXBC_CHUNK_ALIGNMENT - 1)))
{
/* LLVM bitcode should be 32-bit aligned, but before dxc v1.7.2207 this was not always the case in the DXBC
* container due to missing padding after signature names. Get an aligned copy to prevent unaligned access. */
if (!(byte_code = vkd3d_malloc(align(shader_desc->byte_code_size, VKD3D_DXBC_CHUNK_ALIGNMENT))))
ERR("Failed to allocate aligned chunk. Unaligned access will occur.\n");
else
memcpy(byte_code, shader_desc->byte_code, shader_desc->byte_code_size);
{
ERR("Failed to allocate aligned chunk.\n");
free_dxbc_shader_desc(&dxbc_desc);
vkd3d_free(sm6);
return VKD3D_ERROR_OUT_OF_MEMORY;
}
memcpy(byte_code, shader_desc->byte_code, shader_desc->byte_code_size);
dxbc_desc.byte_code = byte_code;
}
ret = sm6_parser_init(sm6, byte_code ? byte_code : shader_desc->byte_code, shader_desc->byte_code_size,
compile_info->source_name, message_context);
ret = sm6_parser_init(sm6, compile_info->source_name, message_context, &dxbc_desc);
free_dxbc_shader_desc(&dxbc_desc);
vkd3d_free(byte_code);
if (!sm6->p.failed && ret >= 0)

View File

@ -32,6 +32,9 @@ void vsir_program_cleanup(struct vsir_program *program)
vkd3d_free((void *)program->block_names[i]);
vkd3d_free(program->block_names);
shader_instruction_array_destroy(&program->instructions);
shader_signature_cleanup(&program->input_signature);
shader_signature_cleanup(&program->output_signature);
shader_signature_cleanup(&program->patch_constant_signature);
}
static inline bool shader_register_is_phase_instance_id(const struct vkd3d_shader_register *reg)
@ -230,7 +233,7 @@ static const struct vkd3d_shader_varying_map *find_varying_map(
static enum vkd3d_result remap_output_signature(struct vkd3d_shader_parser *parser,
const struct vkd3d_shader_compile_info *compile_info)
{
struct shader_signature *signature = &parser->shader_desc.output_signature;
struct shader_signature *signature = &parser->program.output_signature;
const struct vkd3d_shader_varying_map_info *varying_map;
unsigned int i;
@ -1394,9 +1397,9 @@ static enum vkd3d_result shader_normalise_io_registers(struct vkd3d_shader_parse
normaliser.phase = VKD3DSIH_INVALID;
normaliser.shader_type = program->shader_version.type;
normaliser.major = program->shader_version.major;
normaliser.input_signature = &parser->shader_desc.input_signature;
normaliser.output_signature = &parser->shader_desc.output_signature;
normaliser.patch_constant_signature = &parser->shader_desc.patch_constant_signature;
normaliser.input_signature = &program->input_signature;
normaliser.output_signature = &program->output_signature;
normaliser.patch_constant_signature = &program->patch_constant_signature;
for (i = 0, has_control_point_phase = false; i < program->instructions.count; ++i)
{
@ -1439,9 +1442,9 @@ static enum vkd3d_result shader_normalise_io_registers(struct vkd3d_shader_parse
}
}
if (!shader_signature_merge(&parser->shader_desc.input_signature, normaliser.input_range_map, false)
|| !shader_signature_merge(&parser->shader_desc.output_signature, normaliser.output_range_map, false)
|| !shader_signature_merge(&parser->shader_desc.patch_constant_signature, normaliser.pc_range_map, true))
if (!shader_signature_merge(&program->input_signature, normaliser.input_range_map, false)
|| !shader_signature_merge(&program->output_signature, normaliser.output_range_map, false)
|| !shader_signature_merge(&program->patch_constant_signature, normaliser.pc_range_map, true))
{
program->instructions = normaliser.instructions;
return VKD3D_ERROR_OUT_OF_MEMORY;
@ -3766,7 +3769,7 @@ enum vkd3d_result vkd3d_shader_normalise(struct vkd3d_shader_parser *parser,
return result;
if ((result = instruction_array_normalise_hull_shader_control_point_io(instructions,
&parser->shader_desc.input_signature)) < 0)
&parser->program.input_signature)) < 0)
return result;
}

View File

@ -2444,14 +2444,14 @@ static void spirv_compiler_destroy(struct spirv_compiler *compiler)
vkd3d_free(compiler);
}
static struct spirv_compiler *spirv_compiler_create(const struct vkd3d_shader_version *shader_version,
struct vkd3d_shader_desc *shader_desc, const struct vkd3d_shader_compile_info *compile_info,
static struct spirv_compiler *spirv_compiler_create(const struct vsir_program *program,
const struct vkd3d_shader_compile_info *compile_info,
const struct vkd3d_shader_scan_descriptor_info1 *scan_descriptor_info,
struct vkd3d_shader_message_context *message_context, const struct vkd3d_shader_location *location,
uint64_t config_flags)
{
const struct shader_signature *patch_constant_signature = &shader_desc->patch_constant_signature;
const struct shader_signature *output_signature = &shader_desc->output_signature;
const struct shader_signature *patch_constant_signature = &program->patch_constant_signature;
const struct shader_signature *output_signature = &program->output_signature;
const struct vkd3d_shader_interface_info *shader_interface;
const struct vkd3d_shader_descriptor_offset_info *offset_info;
const struct vkd3d_shader_spirv_target_info *target_info;
@ -2562,7 +2562,7 @@ static struct spirv_compiler *spirv_compiler_create(const struct vkd3d_shader_ve
rb_init(&compiler->symbol_table, vkd3d_symbol_compare);
compiler->shader_type = shader_version->type;
compiler->shader_type = program->shader_version.type;
if ((shader_interface = vkd3d_find_struct(compile_info->next, INTERFACE_INFO)))
{
@ -9982,7 +9982,6 @@ static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler,
const struct vkd3d_shader_spirv_target_info *info = compiler->spirv_target_info;
const struct vkd3d_shader_spirv_domain_shader_target_info *ds_info;
struct vkd3d_spirv_builder *builder = &compiler->spirv_builder;
struct vkd3d_shader_desc *shader_desc = &parser->shader_desc;
struct vkd3d_shader_instruction_array instructions;
struct vsir_program *program = &parser->program;
enum vkd3d_result result = VKD3D_OK;
@ -10007,12 +10006,12 @@ static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler,
instructions = program->instructions;
memset(&program->instructions, 0, sizeof(program->instructions));
compiler->input_signature = shader_desc->input_signature;
compiler->output_signature = shader_desc->output_signature;
compiler->patch_constant_signature = shader_desc->patch_constant_signature;
memset(&shader_desc->input_signature, 0, sizeof(shader_desc->input_signature));
memset(&shader_desc->output_signature, 0, sizeof(shader_desc->output_signature));
memset(&shader_desc->patch_constant_signature, 0, sizeof(shader_desc->patch_constant_signature));
compiler->input_signature = program->input_signature;
compiler->output_signature = program->output_signature;
compiler->patch_constant_signature = program->patch_constant_signature;
memset(&program->input_signature, 0, sizeof(program->input_signature));
memset(&program->output_signature, 0, sizeof(program->output_signature));
memset(&program->patch_constant_signature, 0, sizeof(program->patch_constant_signature));
compiler->use_vocp = program->use_vocp;
compiler->block_names = program->block_names;
compiler->block_name_count = program->block_name_count;
@ -10119,8 +10118,8 @@ int spirv_compile(struct vkd3d_shader_parser *parser,
struct spirv_compiler *spirv_compiler;
int ret;
if (!(spirv_compiler = spirv_compiler_create(&parser->program.shader_version, &parser->shader_desc,
compile_info, scan_descriptor_info, message_context, &parser->location, parser->config_flags)))
if (!(spirv_compiler = spirv_compiler_create(&parser->program, compile_info,
scan_descriptor_info, message_context, &parser->location, parser->config_flags)))
{
ERR("Failed to create SPIR-V compiler.\n");
return VKD3D_ERROR;

View File

@ -954,32 +954,32 @@ static void shader_sm4_read_dcl_index_range(struct vkd3d_shader_instruction *ins
case VKD3DSPR_INCONTROLPOINT:
io_masks = priv->input_register_masks;
ranges = &priv->input_index_ranges;
signature = &priv->p.shader_desc.input_signature;
signature = &priv->p.program.input_signature;
break;
case VKD3DSPR_OUTPUT:
if (sm4_parser_is_in_fork_or_join_phase(priv))
{
io_masks = priv->patch_constant_register_masks;
ranges = &priv->patch_constant_index_ranges;
signature = &priv->p.shader_desc.patch_constant_signature;
signature = &priv->p.program.patch_constant_signature;
}
else
{
io_masks = priv->output_register_masks;
ranges = &priv->output_index_ranges;
signature = &priv->p.shader_desc.output_signature;
signature = &priv->p.program.output_signature;
}
break;
case VKD3DSPR_COLOROUT:
case VKD3DSPR_OUTCONTROLPOINT:
io_masks = priv->output_register_masks;
ranges = &priv->output_index_ranges;
signature = &priv->p.shader_desc.output_signature;
signature = &priv->p.program.output_signature;
break;
case VKD3DSPR_PATCHCONST:
io_masks = priv->patch_constant_register_masks;
ranges = &priv->patch_constant_index_ranges;
signature = &priv->p.shader_desc.patch_constant_signature;
signature = &priv->p.program.patch_constant_signature;
break;
default:
@ -1113,7 +1113,7 @@ static void shader_sm4_read_dcl_input_ps(struct vkd3d_shader_instruction *ins, u
if (shader_sm4_read_dst_param(priv, &tokens, &tokens[token_count], VKD3D_DATA_FLOAT, dst))
{
struct signature_element *e = vsir_signature_find_element_for_reg(
&priv->p.shader_desc.input_signature, dst->reg.idx[dst->reg.idx_count - 1].offset, dst->write_mask);
&priv->p.program.input_signature, dst->reg.idx[dst->reg.idx_count - 1].offset, dst->write_mask);
e->interpolation_mode = ins->flags;
}
@ -1128,7 +1128,7 @@ static void shader_sm4_read_dcl_input_ps_siv(struct vkd3d_shader_instruction *in
if (shader_sm4_read_dst_param(priv, &tokens, &tokens[token_count], VKD3D_DATA_FLOAT, dst))
{
struct signature_element *e = vsir_signature_find_element_for_reg(
&priv->p.shader_desc.input_signature, dst->reg.idx[dst->reg.idx_count - 1].offset, dst->write_mask);
&priv->p.program.input_signature, dst->reg.idx[dst->reg.idx_count - 1].offset, dst->write_mask);
e->interpolation_mode = ins->flags;
}
@ -1748,7 +1748,6 @@ static void shader_sm4_destroy(struct vkd3d_shader_parser *parser)
struct vkd3d_shader_sm4_parser *sm4 = vkd3d_shader_sm4_parser(parser);
vsir_program_cleanup(&parser->program);
free_shader_desc(&parser->shader_desc);
vkd3d_free(sm4);
}
@ -2673,31 +2672,32 @@ int vkd3d_shader_sm4_parser_create(const struct vkd3d_shader_compile_info *compi
shader_desc->is_dxil = false;
shader_desc->byte_code = dxbc_desc.byte_code;
shader_desc->byte_code_size = dxbc_desc.byte_code_size;
shader_desc->input_signature = dxbc_desc.input_signature;
shader_desc->output_signature = dxbc_desc.output_signature;
shader_desc->patch_constant_signature = dxbc_desc.patch_constant_signature;
memset(&dxbc_desc, 0, sizeof(dxbc_desc));
if (!shader_sm4_init(sm4, shader_desc->byte_code, shader_desc->byte_code_size,
compile_info->source_name, message_context))
{
WARN("Failed to initialise shader parser.\n");
free_shader_desc(shader_desc);
free_dxbc_shader_desc(&dxbc_desc);
vkd3d_free(sm4);
return VKD3D_ERROR_INVALID_ARGUMENT;
}
sm4->p.program.input_signature = dxbc_desc.input_signature;
sm4->p.program.output_signature = dxbc_desc.output_signature;
sm4->p.program.patch_constant_signature = dxbc_desc.patch_constant_signature;
memset(&dxbc_desc, 0, sizeof(dxbc_desc));
/* DXBC stores used masks inverted for output signatures, for some reason.
* We return them un-inverted. */
uninvert_used_masks(&shader_desc->output_signature);
uninvert_used_masks(&sm4->p.program.output_signature);
if (sm4->p.program.shader_version.type == VKD3D_SHADER_TYPE_HULL)
uninvert_used_masks(&shader_desc->patch_constant_signature);
uninvert_used_masks(&sm4->p.program.patch_constant_signature);
if (!shader_sm4_parser_validate_signature(sm4, &shader_desc->input_signature,
if (!shader_sm4_parser_validate_signature(sm4, &sm4->p.program.input_signature,
sm4->input_register_masks, "Input")
|| !shader_sm4_parser_validate_signature(sm4, &shader_desc->output_signature,
|| !shader_sm4_parser_validate_signature(sm4, &sm4->p.program.output_signature,
sm4->output_register_masks, "Output")
|| !shader_sm4_parser_validate_signature(sm4, &shader_desc->patch_constant_signature,
|| !shader_sm4_parser_validate_signature(sm4, &sm4->p.program.patch_constant_signature,
sm4->patch_constant_register_masks, "Patch constant"))
{
shader_sm4_destroy(&sm4->p);

View File

@ -1450,11 +1450,11 @@ static int scan_with_parser(const struct vkd3d_shader_compile_info *compile_info
if (!ret && signature_info)
{
if (!vkd3d_shader_signature_from_shader_signature(&signature_info->input, &parser->shader_desc.input_signature)
if (!vkd3d_shader_signature_from_shader_signature(&signature_info->input, &parser->program.input_signature)
|| !vkd3d_shader_signature_from_shader_signature(&signature_info->output,
&parser->shader_desc.output_signature)
&parser->program.output_signature)
|| !vkd3d_shader_signature_from_shader_signature(&signature_info->patch_constant,
&parser->shader_desc.patch_constant_signature))
&parser->program.patch_constant_signature))
{
ret = VKD3D_ERROR_OUT_OF_MEMORY;
}

View File

@ -1043,9 +1043,6 @@ struct vkd3d_shader_desc
const uint32_t *byte_code;
size_t byte_code_size;
bool is_dxil;
struct shader_signature input_signature;
struct shader_signature output_signature;
struct shader_signature patch_constant_signature;
struct
{
@ -1303,6 +1300,10 @@ struct vsir_program
struct vkd3d_shader_version shader_version;
struct vkd3d_shader_instruction_array instructions;
struct shader_signature input_signature;
struct shader_signature output_signature;
struct shader_signature patch_constant_signature;
unsigned int input_control_point_count, output_control_point_count;
unsigned int block_count;
unsigned int temp_count;
@ -1498,7 +1499,6 @@ int vkd3d_shader_sm6_parser_create(const struct vkd3d_shader_compile_info *compi
struct vkd3d_shader_message_context *message_context, struct vkd3d_shader_parser **parser);
void free_dxbc_shader_desc(struct dxbc_shader_desc *desc);
void free_shader_desc(struct vkd3d_shader_desc *desc);
int shader_extract_from_dxbc(const struct vkd3d_shader_code *dxbc,
struct vkd3d_shader_message_context *message_context, const char *source_name, struct dxbc_shader_desc *desc);