This allows us to drop the "ptr" argument to various functions.
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com --- libs/vkd3d-shader/dxbc.c | 21 ++++++++++++++------- libs/vkd3d-shader/glsl.c | 4 ++-- libs/vkd3d-shader/trace.c | 7 +++---- libs/vkd3d-shader/vkd3d_shader_main.c | 13 ++++++++----- libs/vkd3d-shader/vkd3d_shader_private.h | 9 ++++----- 5 files changed, 31 insertions(+), 23 deletions(-)
diff --git a/libs/vkd3d-shader/dxbc.c b/libs/vkd3d-shader/dxbc.c index 99a085f1..86cd0ec0 100644 --- a/libs/vkd3d-shader/dxbc.c +++ b/libs/vkd3d-shader/dxbc.c @@ -1110,12 +1110,11 @@ static struct vkd3d_shader_src_param *get_src_param(struct vkd3d_sm4_data *priv) return &e->param; }
-void shader_sm4_read_header(struct vkd3d_shader_parser *parser, - const uint32_t **ptr, struct vkd3d_shader_version *shader_version) +void shader_sm4_read_header(struct vkd3d_shader_parser *parser, struct vkd3d_shader_version *shader_version) { struct vkd3d_sm4_data *sm4 = parser->data;
- *ptr = sm4->start; + parser->ptr = sm4->start; *shader_version = sm4->shader_version; }
@@ -1527,12 +1526,12 @@ static void shader_sm4_read_instruction_modifier(DWORD modifier, struct vkd3d_sh } }
-void shader_sm4_read_instruction(struct vkd3d_shader_parser *parser, - const uint32_t **ptr, struct vkd3d_shader_instruction *ins) +void shader_sm4_read_instruction(struct vkd3d_shader_parser *parser, struct vkd3d_shader_instruction *ins) { const struct vkd3d_sm4_opcode_info *opcode_info; uint32_t opcode_token, opcode, previous_token; struct vkd3d_sm4_data *sm4 = parser->data; + const uint32_t **ptr = &parser->ptr; unsigned int i, len; size_t remaining; const DWORD *p; @@ -1647,10 +1646,18 @@ fail: return; }
-bool shader_sm4_is_end(struct vkd3d_shader_parser *parser, const uint32_t **ptr) +bool shader_sm4_is_end(struct vkd3d_shader_parser *parser) { struct vkd3d_sm4_data *sm4 = parser->data; - return *ptr == sm4->end; + + return parser->ptr == sm4->end; +} + +void shader_sm4_reset(struct vkd3d_shader_parser *parser) +{ + struct vkd3d_sm4_data *sm4 = parser->data; + + parser->ptr = sm4->start; }
static bool require_space(size_t offset, size_t count, size_t size, size_t data_size) diff --git a/libs/vkd3d-shader/glsl.c b/libs/vkd3d-shader/glsl.c index 9824840f..b304addc 100644 --- a/libs/vkd3d-shader/glsl.c +++ b/libs/vkd3d-shader/glsl.c @@ -104,9 +104,9 @@ int vkd3d_glsl_generator_generate(struct vkd3d_glsl_generator *generator, 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, &parser->ptr)) + while (!shader_sm4_is_end(parser)) { - shader_sm4_read_instruction(parser, &parser->ptr, &ins); + shader_sm4_read_instruction(parser, &ins);
if (ins.handler_idx == VKD3DSIH_INVALID) { diff --git a/libs/vkd3d-shader/trace.c b/libs/vkd3d-shader/trace.c index 409ed550..1dca1ae2 100644 --- a/libs/vkd3d-shader/trace.c +++ b/libs/vkd3d-shader/trace.c @@ -1781,7 +1781,6 @@ enum vkd3d_result vkd3d_dxbc_binary_to_text(struct vkd3d_shader_parser *parser, struct vkd3d_string_buffer *buffer; unsigned int indent, i; const char *indent_str; - const DWORD *ptr; void *code;
static const struct vkd3d_d3d_asm_colours no_colours = @@ -1831,17 +1830,17 @@ enum vkd3d_result vkd3d_dxbc_binary_to_text(struct vkd3d_shader_parser *parser, vkd3d_string_buffer_init(buffer);
shader_version = &compiler.shader_version; - shader_sm4_read_header(parser, &ptr, shader_version); + shader_sm4_read_header(parser, shader_version); vkd3d_string_buffer_printf(buffer, "%s%s_%u_%u%s\n", compiler.colours.version, shader_get_type_prefix(shader_version->type), shader_version->major, shader_version->minor, compiler.colours.reset);
indent = 0; - while (!shader_sm4_is_end(parser, &ptr)) + while (!shader_sm4_is_end(parser)) { struct vkd3d_shader_instruction ins;
- shader_sm4_read_instruction(parser, &ptr, &ins); + shader_sm4_read_instruction(parser, &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 b108fa65..5d7cdf01 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -388,7 +388,7 @@ static int vkd3d_shader_parser_init(struct vkd3d_shader_parser *parser, return VKD3D_ERROR_INVALID_ARGUMENT; }
- shader_sm4_read_header(parser, &parser->ptr, &parser->shader_version); + shader_sm4_read_header(parser, &parser->shader_version); return VKD3D_OK; }
@@ -952,11 +952,14 @@ static int scan_dxbc(const struct vkd3d_shader_compile_info *compile_info, }
if (TRACE_ON()) + { vkd3d_shader_trace(&parser); + shader_sm4_reset(&parser); + }
- while (!shader_sm4_is_end(&parser, &parser.ptr)) + while (!shader_sm4_is_end(&parser)) { - shader_sm4_read_instruction(&parser, &parser.ptr, &instruction); + shader_sm4_read_instruction(&parser, &instruction);
if (instruction.handler_idx == VKD3DSIH_INVALID) { @@ -1085,9 +1088,9 @@ static int compile_dxbc_tpf(const struct vkd3d_shader_compile_info *compile_info return VKD3D_ERROR; }
- while (!shader_sm4_is_end(&parser, &parser.ptr)) + while (!shader_sm4_is_end(&parser)) { - shader_sm4_read_instruction(&parser, &parser.ptr, &instruction); + shader_sm4_read_instruction(&parser, &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 6d044c51..b9c2ccea 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -891,11 +891,10 @@ struct vkd3d_shader_message_context; void *shader_sm4_init(const DWORD *byte_code, size_t byte_code_size, const struct vkd3d_shader_signature *output_signature, struct vkd3d_shader_message_context *message_context); 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(struct vkd3d_shader_parser *parser, - const uint32_t **ptr, struct vkd3d_shader_instruction *ins); -bool shader_sm4_is_end(struct vkd3d_shader_parser *parser, const uint32_t **ptr); +void shader_sm4_read_header(struct vkd3d_shader_parser *parser, struct vkd3d_shader_version *shader_version); +void shader_sm4_read_instruction(struct vkd3d_shader_parser *parser, struct vkd3d_shader_instruction *ins); +bool shader_sm4_is_end(struct vkd3d_shader_parser *parser); +void shader_sm4_reset(struct vkd3d_shader_parser *parser);
struct vkd3d_string_buffer {