Signed-off-by: Henri Verbeet hverbeet@codeweavers.com --- Note that this does also change the way vkd3d_glsl_generator_generate() interacts with parser->ptr; it's inconsequential because the parser is destroyed immediately after the only call to vkd3d_glsl_generator_generate().
libs/vkd3d-shader/dxbc.c | 31 ++++++++++++------------ libs/vkd3d-shader/glsl.c | 9 +++---- libs/vkd3d-shader/trace.c | 2 +- libs/vkd3d-shader/vkd3d_shader_main.c | 6 ++--- libs/vkd3d-shader/vkd3d_shader_private.h | 9 +++---- 5 files changed, 28 insertions(+), 29 deletions(-)
diff --git a/libs/vkd3d-shader/dxbc.c b/libs/vkd3d-shader/dxbc.c index 18ccc952..99c32ae2 100644 --- a/libs/vkd3d-shader/dxbc.c +++ b/libs/vkd3d-shader/dxbc.c @@ -1527,24 +1527,25 @@ static void shader_sm4_read_instruction_modifier(DWORD modifier, struct vkd3d_sh } }
-void shader_sm4_read_instruction(void *data, const DWORD **ptr, struct vkd3d_shader_instruction *ins) +void shader_sm4_read_instruction(struct vkd3d_shader_parser *parser, + const uint32_t **ptr, struct vkd3d_shader_instruction *ins) { const struct vkd3d_sm4_opcode_info *opcode_info; - DWORD opcode_token, opcode, previous_token; - struct vkd3d_sm4_data *priv = data; + uint32_t opcode_token, opcode, previous_token; + struct vkd3d_sm4_data *sm4 = parser->data; unsigned int i, len; size_t remaining; const DWORD *p; DWORD precise;
- list_move_head(&priv->src_free, &priv->src); + list_move_head(&sm4->src_free, &sm4->src);
- if (*ptr >= priv->end) + if (*ptr >= sm4->end) { WARN("End of byte-code, failed to read opcode.\n"); goto fail; } - remaining = priv->end - *ptr; + remaining = sm4->end - *ptr;
opcode_token = *(*ptr)++; opcode = opcode_token & VKD3D_SM4_OPCODE_MASK; @@ -1581,9 +1582,9 @@ void shader_sm4_read_instruction(void *data, const DWORD **ptr, struct vkd3d_sha ins->structured = false; ins->predicate = NULL; ins->dst_count = strlen(opcode_info->dst_info); - ins->dst = priv->dst_param; + ins->dst = sm4->dst_param; ins->src_count = strlen(opcode_info->src_info); - ins->src = priv->src_param; + ins->src = sm4->src_param; ins->resource_type = VKD3D_SHADER_RESOURCE_NONE; ins->resource_stride = 0; ins->resource_data_type[0] = VKD3D_DATA_FLOAT; @@ -1597,7 +1598,7 @@ void shader_sm4_read_instruction(void *data, const DWORD **ptr, struct vkd3d_sha
if (opcode_info->read_opcode_func) { - opcode_info->read_opcode_func(ins, opcode, opcode_token, p, len, priv); + opcode_info->read_opcode_func(ins, opcode, opcode_token, p, len, sm4); } else { @@ -1618,19 +1619,19 @@ void shader_sm4_read_instruction(void *data, const DWORD **ptr, struct vkd3d_sha
for (i = 0; i < ins->dst_count; ++i) { - if (!(shader_sm4_read_dst_param(priv, &p, *ptr, map_data_type(opcode_info->dst_info[i]), - &priv->dst_param[i]))) + if (!(shader_sm4_read_dst_param(sm4, &p, *ptr, map_data_type(opcode_info->dst_info[i]), + &sm4->dst_param[i]))) { ins->handler_idx = VKD3DSIH_INVALID; return; } - priv->dst_param[i].modifiers |= instruction_dst_modifier; + sm4->dst_param[i].modifiers |= instruction_dst_modifier; }
for (i = 0; i < ins->src_count; ++i) { - if (!(shader_sm4_read_src_param(priv, &p, *ptr, map_data_type(opcode_info->src_info[i]), - &priv->src_param[i]))) + if (!(shader_sm4_read_src_param(sm4, &p, *ptr, map_data_type(opcode_info->src_info[i]), + &sm4->src_param[i]))) { ins->handler_idx = VKD3DSIH_INVALID; return; @@ -1641,7 +1642,7 @@ void shader_sm4_read_instruction(void *data, const DWORD **ptr, struct vkd3d_sha return;
fail: - *ptr = priv->end; + *ptr = sm4->end; ins->handler_idx = VKD3DSIH_INVALID; return; } diff --git a/libs/vkd3d-shader/glsl.c b/libs/vkd3d-shader/glsl.c index 38d18cce..04d948c2 100644 --- a/libs/vkd3d-shader/glsl.c +++ b/libs/vkd3d-shader/glsl.c @@ -95,9 +95,8 @@ static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *generator return; }
-int vkd3d_glsl_generator_generate(void *parser_data, const uint32_t *parser_ptr, - struct vkd3d_glsl_generator *generator, - struct vkd3d_shader_code *out) +int vkd3d_glsl_generator_generate(struct vkd3d_glsl_generator *generator, + struct vkd3d_shader_parser *parser, struct vkd3d_shader_code *out) { void *code; struct vkd3d_shader_instruction ins; @@ -105,9 +104,9 @@ int vkd3d_glsl_generator_generate(void *parser_data, const uint32_t *parser_ptr, vkd3d_string_buffer_printf(&generator->buffer, "#version 440\n\n"); vkd3d_string_buffer_printf(&generator->buffer, "void main()\n{\n");
- while (!shader_sm4_is_end(parser_data, &parser_ptr)) + while (!shader_sm4_is_end(parser->data, &parser->ptr)) { - shader_sm4_read_instruction(parser_data, &parser_ptr, &ins); + shader_sm4_read_instruction(parser, &parser->ptr, &ins);
if (ins.handler_idx == VKD3DSIH_INVALID) { diff --git a/libs/vkd3d-shader/trace.c b/libs/vkd3d-shader/trace.c index 107554f6..3e2b1523 100644 --- a/libs/vkd3d-shader/trace.c +++ b/libs/vkd3d-shader/trace.c @@ -1841,7 +1841,7 @@ enum vkd3d_result vkd3d_dxbc_binary_to_text(struct vkd3d_shader_parser *parser, { struct vkd3d_shader_instruction ins;
- shader_sm4_read_instruction(parser->data, &ptr, &ins); + shader_sm4_read_instruction(parser, &ptr, &ins); if (ins.handler_idx == VKD3DSIH_INVALID) { WARN("Skipping unrecognized instruction.\n"); diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index 08a1cee1..56611772 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -956,7 +956,7 @@ static int scan_dxbc(const struct vkd3d_shader_compile_info *compile_info,
while (!shader_sm4_is_end(parser.data, &parser.ptr)) { - shader_sm4_read_instruction(parser.data, &parser.ptr, &instruction); + shader_sm4_read_instruction(&parser, &parser.ptr, &instruction);
if (instruction.handler_idx == VKD3DSIH_INVALID) { @@ -1068,7 +1068,7 @@ static int compile_dxbc_tpf(const struct vkd3d_shader_compile_info *compile_info return VKD3D_ERROR; }
- ret = vkd3d_glsl_generator_generate(parser.data, parser.ptr, glsl_generator, out); + ret = vkd3d_glsl_generator_generate(glsl_generator, &parser, out);
vkd3d_glsl_generator_destroy(glsl_generator); vkd3d_shader_parser_destroy(&parser); @@ -1087,7 +1087,7 @@ static int compile_dxbc_tpf(const struct vkd3d_shader_compile_info *compile_info
while (!shader_sm4_is_end(parser.data, &parser.ptr)) { - shader_sm4_read_instruction(parser.data, &parser.ptr, &instruction); + shader_sm4_read_instruction(&parser, &parser.ptr, &instruction);
if (instruction.handler_idx == VKD3DSIH_INVALID) { diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index 3b1169a1..5e828b6f 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -893,8 +893,8 @@ void *shader_sm4_init(const DWORD *byte_code, size_t byte_code_size, void shader_sm4_free(struct vkd3d_shader_parser *parser); void shader_sm4_read_header(struct vkd3d_shader_parser *parser, const uint32_t **ptr, struct vkd3d_shader_version *shader_version); -void shader_sm4_read_instruction(void *data, const DWORD **ptr, - struct vkd3d_shader_instruction *ins); +void shader_sm4_read_instruction(struct vkd3d_shader_parser *parser, + const uint32_t **ptr, struct vkd3d_shader_instruction *ins); bool shader_sm4_is_end(void *data, const DWORD **ptr);
struct vkd3d_string_buffer @@ -998,9 +998,8 @@ struct vkd3d_glsl_generator; struct vkd3d_glsl_generator *vkd3d_glsl_generator_create(const struct vkd3d_shader_version *version, const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_message_context *message_context); -int vkd3d_glsl_generator_generate(void *parser_data, const uint32_t *parser_ptr, - struct vkd3d_glsl_generator *generator, - struct vkd3d_shader_code *out); +int vkd3d_glsl_generator_generate(struct vkd3d_glsl_generator *generator, + struct vkd3d_shader_parser *parser, struct vkd3d_shader_code *out); void vkd3d_glsl_generator_destroy(struct vkd3d_glsl_generator *generator);
struct vkd3d_dxbc_compiler;