mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader/ir: Pass an initialised vsir_program structure to vkd3d_shader_parser_init().
This commit is contained in:
parent
9e4a790de1
commit
19b552ce1b
Notes:
Alexandre Julliard
2024-05-16 23:13:19 +02:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/869
@ -1242,6 +1242,7 @@ static enum vkd3d_result shader_sm1_init(struct vkd3d_shader_sm1_parser *sm1,
|
||||
const uint32_t *code = compile_info->source.code;
|
||||
size_t code_size = compile_info->source.size;
|
||||
struct vkd3d_shader_version version;
|
||||
struct vsir_program *program;
|
||||
uint16_t shader_type;
|
||||
size_t token_count;
|
||||
|
||||
@ -1289,10 +1290,16 @@ static enum vkd3d_result shader_sm1_init(struct vkd3d_shader_sm1_parser *sm1,
|
||||
sm1->start = &code[1];
|
||||
sm1->end = &code[token_count];
|
||||
|
||||
/* Estimate instruction count to avoid reallocation in most shaders. */
|
||||
if (!vkd3d_shader_parser_init(&sm1->p, message_context, compile_info->source_name, &version, &shader_sm1_parser_ops,
|
||||
code_size != ~(size_t)0 ? token_count / 4u + 4 : 16))
|
||||
if (!(program = vkd3d_malloc(sizeof(*program))))
|
||||
return VKD3D_ERROR_OUT_OF_MEMORY;
|
||||
/* Estimate instruction count to avoid reallocation in most shaders. */
|
||||
if (!vsir_program_init(program, &version, code_size != ~(size_t)0 ? token_count / 4u + 4 : 16))
|
||||
{
|
||||
vkd3d_free(program);
|
||||
return VKD3D_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
vkd3d_shader_parser_init(&sm1->p, program, message_context, compile_info->source_name, &shader_sm1_parser_ops);
|
||||
sm1->ptr = sm1->start;
|
||||
|
||||
return VKD3D_OK;
|
||||
|
@ -10250,14 +10250,19 @@ static enum vkd3d_result sm6_parser_init(struct sm6_parser *sm6, const char *sou
|
||||
return VKD3D_ERROR_INVALID_SHADER;
|
||||
}
|
||||
|
||||
if (!(program = vkd3d_malloc(sizeof(*program))))
|
||||
return VKD3D_ERROR_OUT_OF_MEMORY;
|
||||
/* Estimate instruction count to avoid reallocation in most shaders. */
|
||||
count = max(token_count, 400) - 400;
|
||||
vkd3d_shader_parser_init(&sm6->p, message_context, source_name, &version, &sm6_parser_ops,
|
||||
(count + (count >> 2)) / 2u + 10);
|
||||
if (!vsir_program_init(program, &version, (count + (count >> 2)) / 2u + 10))
|
||||
{
|
||||
vkd3d_free(program);
|
||||
return VKD3D_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
vkd3d_shader_parser_init(&sm6->p, program, message_context, source_name, &sm6_parser_ops);
|
||||
sm6->ptr = &sm6->start[1];
|
||||
sm6->bitpos = 2;
|
||||
|
||||
program = sm6->p.program;
|
||||
input_signature = &program->input_signature;
|
||||
output_signature = &program->output_signature;
|
||||
patch_constant_signature = &program->patch_constant_signature;
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
bool vsir_program_init(struct vsir_program *program, const struct vkd3d_shader_version *version, unsigned int reserve)
|
||||
{
|
||||
memset(program, 0, sizeof(*program));
|
||||
program->shader_version = *version;
|
||||
return shader_instruction_array_init(&program->instructions, reserve);
|
||||
}
|
||||
|
@ -2517,6 +2517,7 @@ static bool shader_sm4_init(struct vkd3d_shader_sm4_parser *sm4, const uint32_t
|
||||
{
|
||||
struct vkd3d_shader_version version;
|
||||
uint32_t version_token, token_count;
|
||||
struct vsir_program *program;
|
||||
|
||||
if (byte_code_size / sizeof(*byte_code) < 2)
|
||||
{
|
||||
@ -2570,10 +2571,15 @@ static bool shader_sm4_init(struct vkd3d_shader_sm4_parser *sm4, const uint32_t
|
||||
version.major = VKD3D_SM4_VERSION_MAJOR(version_token);
|
||||
version.minor = VKD3D_SM4_VERSION_MINOR(version_token);
|
||||
|
||||
/* Estimate instruction count to avoid reallocation in most shaders. */
|
||||
if (!vkd3d_shader_parser_init(&sm4->p, message_context, source_name, &version, &shader_sm4_parser_ops,
|
||||
token_count / 7u + 20))
|
||||
if (!(program = vkd3d_malloc(sizeof(*program))))
|
||||
return false;
|
||||
/* Estimate instruction count to avoid reallocation in most shaders. */
|
||||
if (!vsir_program_init(program, &version, token_count / 7u + 20))
|
||||
{
|
||||
vkd3d_free(program);
|
||||
return false;
|
||||
}
|
||||
vkd3d_shader_parser_init(&sm4->p, program, message_context, source_name, &shader_sm4_parser_ops);
|
||||
sm4->ptr = sm4->start;
|
||||
|
||||
init_sm4_lookup_tables(&sm4->lookup);
|
||||
|
@ -554,24 +554,17 @@ static uint64_t vkd3d_shader_init_config_flags(void)
|
||||
return config_flags;
|
||||
}
|
||||
|
||||
bool vkd3d_shader_parser_init(struct vkd3d_shader_parser *parser,
|
||||
void vkd3d_shader_parser_init(struct vkd3d_shader_parser *parser, struct vsir_program *program,
|
||||
struct vkd3d_shader_message_context *message_context, const char *source_name,
|
||||
const struct vkd3d_shader_version *version, const struct vkd3d_shader_parser_ops *ops,
|
||||
unsigned int instruction_reserve)
|
||||
const struct vkd3d_shader_parser_ops *ops)
|
||||
{
|
||||
bool ret;
|
||||
|
||||
parser->message_context = message_context;
|
||||
parser->location.source_name = source_name;
|
||||
parser->location.line = 1;
|
||||
parser->location.column = 0;
|
||||
parser->ops = ops;
|
||||
parser->config_flags = vkd3d_shader_init_config_flags();
|
||||
if (!(parser->program = vkd3d_calloc(1, sizeof(*parser->program))))
|
||||
return false;
|
||||
if (!(ret = vsir_program_init(parser->program, version, instruction_reserve)))
|
||||
vkd3d_free(parser->program);
|
||||
return ret;
|
||||
parser->program = program;
|
||||
}
|
||||
|
||||
void VKD3D_PRINTF_FUNC(3, 4) vkd3d_shader_parser_error(struct vkd3d_shader_parser *parser,
|
||||
|
@ -1407,10 +1407,9 @@ struct vkd3d_shader_parser_ops
|
||||
|
||||
void vkd3d_shader_parser_error(struct vkd3d_shader_parser *parser,
|
||||
enum vkd3d_shader_error error, const char *format, ...) VKD3D_PRINTF_FUNC(3, 4);
|
||||
bool vkd3d_shader_parser_init(struct vkd3d_shader_parser *parser,
|
||||
void vkd3d_shader_parser_init(struct vkd3d_shader_parser *parser, struct vsir_program *program,
|
||||
struct vkd3d_shader_message_context *message_context, const char *source_name,
|
||||
const struct vkd3d_shader_version *version, const struct vkd3d_shader_parser_ops *ops,
|
||||
unsigned int instruction_reserve);
|
||||
const struct vkd3d_shader_parser_ops *ops);
|
||||
void vkd3d_shader_parser_warning(struct vkd3d_shader_parser *parser,
|
||||
enum vkd3d_shader_error error, const char *format, ...) VKD3D_PRINTF_FUNC(3, 4);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user