From efe9dfd73aac352fbe81e4baef3c3e54592ee484 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Thu, 16 May 2024 11:42:16 +0200 Subject: [PATCH] vkd3d-shader/ir: Do not store the vkd3d-shader configuration flags in struct vkd3d_shader_parser. --- libs/vkd3d-shader/d3dbc.c | 4 ++-- libs/vkd3d-shader/dxil.c | 4 ++-- libs/vkd3d-shader/hlsl.c | 7 ++++--- libs/vkd3d-shader/tpf.c | 4 ++-- libs/vkd3d-shader/vkd3d_shader_main.c | 19 ++++++++++--------- libs/vkd3d-shader/vkd3d_shader_private.h | 13 ++++++------- 6 files changed, 26 insertions(+), 25 deletions(-) diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c index 43d4374a..4e0a2905 100644 --- a/libs/vkd3d-shader/d3dbc.c +++ b/libs/vkd3d-shader/d3dbc.c @@ -1322,7 +1322,7 @@ static uint32_t get_external_constant_count(struct vkd3d_shader_sm1_parser *sm1, return 0; } -int vkd3d_shader_sm1_parser_create(const struct vkd3d_shader_compile_info *compile_info, +int vkd3d_shader_sm1_parser_create(const struct vkd3d_shader_compile_info *compile_info, uint64_t config_flags, struct vkd3d_shader_message_context *message_context, struct vkd3d_shader_parser **parser) { struct vkd3d_shader_instruction_array *instructions; @@ -1372,7 +1372,7 @@ int vkd3d_shader_sm1_parser_create(const struct vkd3d_shader_compile_info *compi program->flat_constant_count[i] = get_external_constant_count(sm1, i); if (!sm1->p.failed) - ret = vkd3d_shader_parser_validate(&sm1->p); + ret = vkd3d_shader_parser_validate(&sm1->p, config_flags); if (sm1->p.failed && ret >= 0) ret = VKD3D_ERROR_INVALID_SHADER; diff --git a/libs/vkd3d-shader/dxil.c b/libs/vkd3d-shader/dxil.c index 7275489f..29b36c35 100644 --- a/libs/vkd3d-shader/dxil.c +++ b/libs/vkd3d-shader/dxil.c @@ -10474,7 +10474,7 @@ static enum vkd3d_result sm6_parser_init(struct sm6_parser *sm6, const char *sou return VKD3D_OK; } -int vkd3d_shader_sm6_parser_create(const struct vkd3d_shader_compile_info *compile_info, +int vkd3d_shader_sm6_parser_create(const struct vkd3d_shader_compile_info *compile_info, uint64_t config_flags, struct vkd3d_shader_message_context *message_context, struct vkd3d_shader_parser **parser) { struct dxbc_shader_desc dxbc_desc = {0}; @@ -10520,7 +10520,7 @@ int vkd3d_shader_sm6_parser_create(const struct vkd3d_shader_compile_info *compi vkd3d_free(byte_code); if (!sm6->p.failed && ret >= 0) - ret = vkd3d_shader_parser_validate(&sm6->p); + ret = vkd3d_shader_parser_validate(&sm6->p, config_flags); if (sm6->p.failed && ret >= 0) ret = VKD3D_ERROR_INVALID_SHADER; diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index a0ae457e..40548d4a 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -3991,6 +3991,7 @@ int hlsl_compile_shader(const struct vkd3d_shader_code *hlsl, const struct vkd3d || target_type == VKD3D_SHADER_TARGET_SPIRV_TEXT || target_type == VKD3D_SHADER_TARGET_D3D_ASM) { + uint64_t config_flags = vkd3d_shader_init_config_flags(); struct vkd3d_shader_compile_info info = *compile_info; struct vkd3d_shader_parser *parser; @@ -3999,18 +4000,18 @@ int hlsl_compile_shader(const struct vkd3d_shader_code *hlsl, const struct vkd3d if ((ret = hlsl_emit_bytecode(&ctx, entry_func, VKD3D_SHADER_TARGET_D3D_BYTECODE, &info.source)) < 0) goto done; info.source_type = VKD3D_SHADER_SOURCE_D3D_BYTECODE; - ret = vkd3d_shader_sm1_parser_create(&info, message_context, &parser); + ret = vkd3d_shader_sm1_parser_create(&info, config_flags, message_context, &parser); } else { if ((ret = hlsl_emit_bytecode(&ctx, entry_func, VKD3D_SHADER_TARGET_DXBC_TPF, &info.source)) < 0) goto done; info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF; - ret = vkd3d_shader_sm4_parser_create(&info, message_context, &parser); + ret = vkd3d_shader_sm4_parser_create(&info, config_flags, message_context, &parser); } if (ret >= 0) { - ret = vsir_program_compile(parser->program, parser->config_flags, &info, out, message_context); + ret = vsir_program_compile(parser->program, config_flags, &info, out, message_context); vkd3d_shader_parser_destroy(parser); } vkd3d_shader_free_shader_code(&info.source); diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index e7301d72..633e9f89 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -2658,7 +2658,7 @@ static void shader_sm4_validate_default_phase_index_ranges(struct vkd3d_shader_s return; } -int vkd3d_shader_sm4_parser_create(const struct vkd3d_shader_compile_info *compile_info, +int vkd3d_shader_sm4_parser_create(const struct vkd3d_shader_compile_info *compile_info, uint64_t config_flags, struct vkd3d_shader_message_context *message_context, struct vkd3d_shader_parser **parser) { struct vkd3d_shader_instruction_array *instructions; @@ -2741,7 +2741,7 @@ int vkd3d_shader_sm4_parser_create(const struct vkd3d_shader_compile_info *compi shader_sm4_validate_default_phase_index_ranges(sm4); if (!sm4->p.failed) - vkd3d_shader_parser_validate(&sm4->p); + vkd3d_shader_parser_validate(&sm4->p, config_flags); if (sm4->p.failed) { diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index a25b5f4a..f0297666 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -540,7 +540,7 @@ static const struct vkd3d_debug_option vkd3d_shader_config_options[] = {"force_validation", VKD3D_SHADER_CONFIG_FLAG_FORCE_VALIDATION}, /* force validation of internal shader representations */ }; -static uint64_t vkd3d_shader_init_config_flags(void) +uint64_t vkd3d_shader_init_config_flags(void) { uint64_t config_flags; const char *config; @@ -563,7 +563,6 @@ void vkd3d_shader_parser_init(struct vkd3d_shader_parser *parser, struct vsir_pr parser->location.line = 1; parser->location.column = 0; parser->ops = ops; - parser->config_flags = vkd3d_shader_init_config_flags(); parser->program = program; } @@ -1515,20 +1514,21 @@ int vkd3d_shader_scan(const struct vkd3d_shader_compile_info *compile_info, char } else { + uint64_t config_flags = vkd3d_shader_init_config_flags(); struct vkd3d_shader_parser *parser; switch (compile_info->source_type) { case VKD3D_SHADER_SOURCE_D3D_BYTECODE: - ret = vkd3d_shader_sm1_parser_create(compile_info, &message_context, &parser); + ret = vkd3d_shader_sm1_parser_create(compile_info, config_flags, &message_context, &parser); break; case VKD3D_SHADER_SOURCE_DXBC_TPF: - ret = vkd3d_shader_sm4_parser_create(compile_info, &message_context, &parser); + ret = vkd3d_shader_sm4_parser_create(compile_info, config_flags, &message_context, &parser); break; case VKD3D_SHADER_SOURCE_DXBC_DXIL: - ret = vkd3d_shader_sm6_parser_create(compile_info, &message_context, &parser); + ret = vkd3d_shader_sm6_parser_create(compile_info, config_flags, &message_context, &parser); break; default: @@ -1636,20 +1636,21 @@ int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info, } else { + uint64_t config_flags = vkd3d_shader_init_config_flags(); struct vkd3d_shader_parser *parser; switch (compile_info->source_type) { case VKD3D_SHADER_SOURCE_D3D_BYTECODE: - ret = vkd3d_shader_sm1_parser_create(compile_info, &message_context, &parser); + ret = vkd3d_shader_sm1_parser_create(compile_info, config_flags, &message_context, &parser); break; case VKD3D_SHADER_SOURCE_DXBC_TPF: - ret = vkd3d_shader_sm4_parser_create(compile_info, &message_context, &parser); + ret = vkd3d_shader_sm4_parser_create(compile_info, config_flags, &message_context, &parser); break; case VKD3D_SHADER_SOURCE_DXBC_DXIL: - ret = vkd3d_shader_sm6_parser_create(compile_info, &message_context, &parser); + ret = vkd3d_shader_sm6_parser_create(compile_info, config_flags, &message_context, &parser); break; default: @@ -1664,7 +1665,7 @@ int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info, } else { - ret = vsir_program_compile(parser->program, parser->config_flags, compile_info, out, &message_context); + ret = vsir_program_compile(parser->program, config_flags, compile_info, out, &message_context); vkd3d_shader_parser_destroy(parser); } } diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index 196d92ef..cd4916a3 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -1396,8 +1396,6 @@ struct vkd3d_shader_parser bool failed; const struct vkd3d_shader_parser_ops *ops; - - uint64_t config_flags; }; struct vkd3d_shader_parser_ops @@ -1418,9 +1416,9 @@ static inline void vkd3d_shader_parser_destroy(struct vkd3d_shader_parser *parse parser->ops->parser_destroy(parser); } -static inline enum vkd3d_result vkd3d_shader_parser_validate(struct vkd3d_shader_parser *parser) +static inline enum vkd3d_result vkd3d_shader_parser_validate(struct vkd3d_shader_parser *parser, uint64_t config_flags) { - return vsir_program_validate(parser->program, parser->config_flags, + return vsir_program_validate(parser->program, config_flags, parser->location.source_name, parser->message_context); } @@ -1551,15 +1549,16 @@ void vkd3d_shader_vwarning(struct vkd3d_shader_message_context *context, const s enum vkd3d_shader_error error, const char *format, va_list args); void vkd3d_shader_dump_shader(const struct vkd3d_shader_compile_info *compile_info); +uint64_t vkd3d_shader_init_config_flags(void); void vkd3d_shader_trace_text_(const char *text, size_t size, const char *function); #define vkd3d_shader_trace_text(text, size) \ vkd3d_shader_trace_text_(text, size, __FUNCTION__) -int vkd3d_shader_sm1_parser_create(const struct vkd3d_shader_compile_info *compile_info, +int vkd3d_shader_sm1_parser_create(const struct vkd3d_shader_compile_info *compile_info, uint64_t config_flags, struct vkd3d_shader_message_context *message_context, struct vkd3d_shader_parser **parser); -int vkd3d_shader_sm4_parser_create(const struct vkd3d_shader_compile_info *compile_info, +int vkd3d_shader_sm4_parser_create(const struct vkd3d_shader_compile_info *compile_info, uint64_t config_flags, struct vkd3d_shader_message_context *message_context, struct vkd3d_shader_parser **parser); -int vkd3d_shader_sm6_parser_create(const struct vkd3d_shader_compile_info *compile_info, +int vkd3d_shader_sm6_parser_create(const struct vkd3d_shader_compile_info *compile_info, uint64_t config_flags, struct vkd3d_shader_message_context *message_context, struct vkd3d_shader_parser **parser); void free_dxbc_shader_desc(struct dxbc_shader_desc *desc);