From 2a5ae0a8c646c48aed0b8bbe447dc0db2bd41c7d Mon Sep 17 00:00:00 2001 From: Conor McCarthy Date: Fri, 20 Jan 2023 12:44:18 +1000 Subject: [PATCH] vkd3d-shader/sm4: Use the instruction array interface in compile_dxbc_tpf(). --- libs/vkd3d-shader/d3dbc.c | 2 -- libs/vkd3d-shader/dxbc.c | 2 -- libs/vkd3d-shader/vkd3d_shader_main.c | 29 +++--------------------- libs/vkd3d-shader/vkd3d_shader_private.h | 15 ------------ 4 files changed, 3 insertions(+), 45 deletions(-) diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c index 5f11667b..ed81137d 100644 --- a/libs/vkd3d-shader/d3dbc.c +++ b/libs/vkd3d-shader/d3dbc.c @@ -874,8 +874,6 @@ static bool shader_sm1_is_end(struct vkd3d_shader_parser *parser) const struct vkd3d_shader_parser_ops shader_sm1_parser_ops = { .parser_destroy = shader_sm1_destroy, - .parser_read_instruction = shader_parser_read_instruction, - .parser_is_end = shader_parser_is_end, }; static enum vkd3d_result shader_sm1_init(struct vkd3d_shader_sm1_parser *sm1, diff --git a/libs/vkd3d-shader/dxbc.c b/libs/vkd3d-shader/dxbc.c index 39fbdcc6..4041e0f5 100644 --- a/libs/vkd3d-shader/dxbc.c +++ b/libs/vkd3d-shader/dxbc.c @@ -1588,8 +1588,6 @@ static bool shader_sm4_is_end(struct vkd3d_shader_parser *parser) static const struct vkd3d_shader_parser_ops shader_sm4_parser_ops = { .parser_destroy = shader_sm4_destroy, - .parser_read_instruction = shader_parser_read_instruction, - .parser_is_end = shader_parser_is_end, }; static bool shader_sm4_init(struct vkd3d_shader_sm4_parser *sm4, const uint32_t *byte_code, diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index 8c50e193..012b3eb6 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -463,16 +463,6 @@ void VKD3D_PRINTF_FUNC(3, 4) vkd3d_shader_parser_warning(struct vkd3d_shader_par va_end(args); } -void shader_parser_read_instruction(struct vkd3d_shader_parser *parser, struct vkd3d_shader_instruction *ins) -{ - *ins = parser->instructions.elements[parser->instruction_idx++]; -} - -bool shader_parser_is_end(struct vkd3d_shader_parser *parser) -{ - return parser->instruction_idx >= parser->instructions.count; -} - static int vkd3d_shader_validate_compile_info(const struct vkd3d_shader_compile_info *compile_info, bool validate_target_type) { @@ -1183,10 +1173,10 @@ static int compile_dxbc_tpf(const struct vkd3d_shader_compile_info *compile_info struct vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context) { struct vkd3d_shader_scan_descriptor_info scan_descriptor_info; - struct vkd3d_shader_instruction instruction; struct vkd3d_shader_compile_info scan_info; struct spirv_compiler *spirv_compiler; struct vkd3d_shader_parser *parser; + unsigned int i; int ret; scan_info = *compile_info; @@ -1244,24 +1234,11 @@ static int compile_dxbc_tpf(const struct vkd3d_shader_compile_info *compile_info return VKD3D_ERROR; } - while (!vkd3d_shader_parser_is_end(parser)) + for (i = 0; i < parser->instructions.count && ret >= 0; ++i) { - vkd3d_shader_parser_read_instruction(parser, &instruction); - - if (instruction.handler_idx == VKD3DSIH_INVALID) - { - WARN("Encountered unrecognized or invalid instruction.\n"); - ret = VKD3D_ERROR_INVALID_SHADER; - break; - } - - if ((ret = spirv_compiler_handle_instruction(spirv_compiler, &instruction)) < 0) - break; + ret = spirv_compiler_handle_instruction(spirv_compiler, &parser->instructions.elements[i]); } - if (parser->failed) - ret = VKD3D_ERROR_INVALID_SHADER; - if (ret >= 0) ret = spirv_compiler_generate_spirv(spirv_compiler, compile_info, out); diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index 1baa7f7f..b5f45834 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -997,8 +997,6 @@ struct vkd3d_shader_parser struct vkd3d_shader_parser_ops { void (*parser_destroy)(struct vkd3d_shader_parser *parser); - void (*parser_read_instruction)(struct vkd3d_shader_parser *parser, struct vkd3d_shader_instruction *instruction); - bool (*parser_is_end)(struct vkd3d_shader_parser *parser); }; void vkd3d_shader_parser_error(struct vkd3d_shader_parser *parser, @@ -1009,8 +1007,6 @@ bool vkd3d_shader_parser_init(struct vkd3d_shader_parser *parser, unsigned int instruction_reserve); void vkd3d_shader_parser_warning(struct vkd3d_shader_parser *parser, enum vkd3d_shader_error error, const char *format, ...) VKD3D_PRINTF_FUNC(3, 4); -void shader_parser_read_instruction(struct vkd3d_shader_parser *parser, struct vkd3d_shader_instruction *ins); -bool shader_parser_is_end(struct vkd3d_shader_parser *parser); static inline struct vkd3d_shader_dst_param *shader_parser_get_dst_params( struct vkd3d_shader_parser *parser, unsigned int count) @@ -1029,17 +1025,6 @@ static inline void vkd3d_shader_parser_destroy(struct vkd3d_shader_parser *parse parser->ops->parser_destroy(parser); } -static inline bool vkd3d_shader_parser_is_end(struct vkd3d_shader_parser *parser) -{ - return parser->ops->parser_is_end(parser); -} - -static inline void vkd3d_shader_parser_read_instruction(struct vkd3d_shader_parser *parser, - struct vkd3d_shader_instruction *instruction) -{ - parser->ops->parser_read_instruction(parser, instruction); -} - void vkd3d_shader_trace(struct vkd3d_shader_parser *parser); const char *shader_get_type_prefix(enum vkd3d_shader_type type);