From: Giovanni Mascellani gmascellani@codeweavers.com
The profile cannot be reliably devised by analyzing the HLSL code, so it's useful to have it included in the file name. --- libs/vkd3d-shader/hlsl.c | 2 +- libs/vkd3d-shader/vkd3d_shader_main.c | 17 +++++++++++------ libs/vkd3d-shader/vkd3d_shader_private.h | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 2d383bc2f..ab92745cc 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -3491,7 +3491,7 @@ int hlsl_compile_shader(const struct vkd3d_shader_code *hlsl, const struct vkd3d return VKD3D_ERROR_NOT_IMPLEMENTED; }
- vkd3d_shader_dump_shader(compile_info->source_type, profile->type, &compile_info->source); + vkd3d_shader_dump_shader(compile_info->source_type, profile->name, &compile_info->source);
if (compile_info->target_type == VKD3D_SHADER_TARGET_D3D_BYTECODE && profile->major_version > 3) { diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index 7aaec49f8..946c5cf6a 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -391,7 +391,10 @@ static void vkd3d_shader_dump_blob(const char *path, const char *prefix,
id = InterlockedIncrement(&shader_id) - 1;
- snprintf(filename, ARRAY_SIZE(filename), "%s/vkd3d-shader-%s-%u.%s", path, prefix, id, suffix); + if (prefix) + snprintf(filename, ARRAY_SIZE(filename), "%s/vkd3d-shader-%s-%u.%s", path, prefix, id, suffix); + else + snprintf(filename, ARRAY_SIZE(filename), "%s/vkd3d-shader-%u.%s", path, id, suffix); if ((f = fopen(filename, "wb"))) { if (fwrite(data, 1, size, f) != size) @@ -424,7 +427,7 @@ static const char *shader_get_source_type_suffix(enum vkd3d_shader_source_type t }
void vkd3d_shader_dump_shader(enum vkd3d_shader_source_type source_type, - enum vkd3d_shader_type shader_type, const struct vkd3d_shader_code *shader) + const char *prefix, const struct vkd3d_shader_code *shader) { static bool enabled = true; const char *path; @@ -438,8 +441,8 @@ void vkd3d_shader_dump_shader(enum vkd3d_shader_source_type source_type, return; }
- vkd3d_shader_dump_blob(path, shader_get_type_prefix(shader_type), - shader_get_source_type_suffix(source_type), shader->code, shader->size); + vkd3d_shader_dump_blob(path, prefix, shader_get_source_type_suffix(source_type), + shader->code, shader->size); }
static void init_scan_signature_info(const struct vkd3d_shader_compile_info *info) @@ -1354,7 +1357,8 @@ static int vkd3d_shader_parser_compile(struct vkd3d_shader_parser *parser, struct vkd3d_shader_compile_info scan_info; int ret;
- vkd3d_shader_dump_shader(compile_info->source_type, parser->shader_version.type, &compile_info->source); + vkd3d_shader_dump_shader(compile_info->source_type, shader_get_type_prefix(parser->shader_version.type), + &compile_info->source);
scan_info = *compile_info;
@@ -1439,7 +1443,8 @@ static int compile_d3d_bytecode(const struct vkd3d_shader_compile_info *compile_ return ret; }
- vkd3d_shader_dump_shader(compile_info->source_type, parser->shader_version.type, &compile_info->source); + vkd3d_shader_dump_shader(compile_info->source_type, shader_get_type_prefix(parser->shader_version.type), + &compile_info->source);
if (compile_info->target_type == VKD3D_SHADER_TARGET_D3D_ASM) { diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index c9d2dec8b..c334bc2a7 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -1315,7 +1315,7 @@ 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(enum vkd3d_shader_source_type source_type, - enum vkd3d_shader_type shader_type, const struct vkd3d_shader_code *shader); + const char *prefix, const struct vkd3d_shader_code *shader); 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__)
From: Giovanni Mascellani gmascellani@codeweavers.com
So that they are dumped even if parsing fails, which is a circumstance in which one likely wants to see the problematic shader.
The downside of that is that for shader types other than HLSL the profile is not written any more in the filename. This should not be a big problem, because in those cases the shader describes its own type.
When dumping an HLSL shader, the id is brought in front of the profile in the file name, in order to make it more tab-friendly: when dealing with a directory full of shaders it's likely that the id determines the profile, but the other way around. --- libs/vkd3d-shader/hlsl.c | 6 ++-- libs/vkd3d-shader/hlsl.h | 1 + libs/vkd3d-shader/vkd3d_shader_main.c | 37 ++++++++++++++++-------- libs/vkd3d-shader/vkd3d_shader_private.h | 3 +- 4 files changed, 29 insertions(+), 18 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index ab92745cc..92ec47304 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -3118,7 +3118,7 @@ unsigned int hlsl_combine_swizzles(unsigned int first, unsigned int second, unsi return ret; }
-static const struct hlsl_profile_info *get_target_info(const char *target) +const struct hlsl_profile_info *hlsl_get_target_info(const char *target) { unsigned int i;
@@ -3485,14 +3485,12 @@ int hlsl_compile_shader(const struct vkd3d_shader_code *hlsl, const struct vkd3d } entry_point = hlsl_source_info->entry_point ? hlsl_source_info->entry_point : "main";
- if (!(profile = get_target_info(hlsl_source_info->profile))) + if (!(profile = hlsl_get_target_info(hlsl_source_info->profile))) { FIXME("Unknown compilation target %s.\n", debugstr_a(hlsl_source_info->profile)); return VKD3D_ERROR_NOT_IMPLEMENTED; }
- vkd3d_shader_dump_shader(compile_info->source_type, profile->name, &compile_info->source); - if (compile_info->target_type == VKD3D_SHADER_TARGET_D3D_BYTECODE && profile->major_version > 3) { vkd3d_shader_error(message_context, NULL, VKD3D_SHADER_ERROR_HLSL_INCOMPATIBLE_PROFILE, diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 9e83b8b76..04739a9d0 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -1130,6 +1130,7 @@ void hlsl_free_var(struct hlsl_ir_var *decl);
struct hlsl_ir_function *hlsl_get_function(struct hlsl_ctx *ctx, const char *name); struct hlsl_ir_function_decl *hlsl_get_func_decl(struct hlsl_ctx *ctx, const char *name); +const struct hlsl_profile_info *hlsl_get_target_info(const char *target); struct hlsl_type *hlsl_get_type(struct hlsl_scope *scope, const char *name, bool recursive, bool case_insensitive); struct hlsl_ir_var *hlsl_get_var(struct hlsl_scope *scope, const char *name);
diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index 946c5cf6a..aebd2b782 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -18,6 +18,7 @@
#include "vkd3d_shader_private.h" #include "vkd3d_version.h" +#include "hlsl.h"
#include <stdio.h> #include <math.h> @@ -381,7 +382,7 @@ void set_u32(struct vkd3d_bytecode_buffer *buffer, size_t offset, uint32_t value memcpy(buffer->data + offset, &value, sizeof(value)); }
-static void vkd3d_shader_dump_blob(const char *path, const char *prefix, +static void vkd3d_shader_dump_blob(const char *path, const char *profile, const char *suffix, const void *data, size_t size) { static LONG shader_id = 0; @@ -391,8 +392,8 @@ static void vkd3d_shader_dump_blob(const char *path, const char *prefix,
id = InterlockedIncrement(&shader_id) - 1;
- if (prefix) - snprintf(filename, ARRAY_SIZE(filename), "%s/vkd3d-shader-%s-%u.%s", path, prefix, id, suffix); + if (profile) + snprintf(filename, ARRAY_SIZE(filename), "%s/vkd3d-shader-%u-%s.%s", path, id, profile, suffix); else snprintf(filename, ARRAY_SIZE(filename), "%s/vkd3d-shader-%u.%s", path, id, suffix); if ((f = fopen(filename, "wb"))) @@ -426,9 +427,12 @@ static const char *shader_get_source_type_suffix(enum vkd3d_shader_source_type t } }
-void vkd3d_shader_dump_shader(enum vkd3d_shader_source_type source_type, - const char *prefix, const struct vkd3d_shader_code *shader) +void vkd3d_shader_dump_shader(const struct vkd3d_shader_compile_info *compile_info) { + const struct vkd3d_shader_code *shader = &compile_info->source; + const struct vkd3d_shader_hlsl_source_info *hlsl_source_info; + const struct hlsl_profile_info *profile; + const char *profile_name = NULL; static bool enabled = true; const char *path;
@@ -441,7 +445,18 @@ void vkd3d_shader_dump_shader(enum vkd3d_shader_source_type source_type, return; }
- vkd3d_shader_dump_blob(path, prefix, shader_get_source_type_suffix(source_type), + if (compile_info->source_type == VKD3D_SHADER_SOURCE_HLSL) + { + if (!(hlsl_source_info = vkd3d_find_struct(compile_info->next, HLSL_SOURCE_INFO))) + return; + + if (!(profile = hlsl_get_target_info(hlsl_source_info->profile))) + return; + + profile_name = profile->name; + } + + vkd3d_shader_dump_blob(path, profile_name, shader_get_source_type_suffix(compile_info->source_type), shader->code, shader->size); }
@@ -1316,6 +1331,8 @@ int vkd3d_shader_scan(const struct vkd3d_shader_compile_info *compile_info, char
vkd3d_shader_message_context_init(&message_context, compile_info->log_level);
+ vkd3d_shader_dump_shader(compile_info); + switch (compile_info->source_type) { case VKD3D_SHADER_SOURCE_DXBC_TPF: @@ -1357,9 +1374,6 @@ static int vkd3d_shader_parser_compile(struct vkd3d_shader_parser *parser, struct vkd3d_shader_compile_info scan_info; int ret;
- vkd3d_shader_dump_shader(compile_info->source_type, shader_get_type_prefix(parser->shader_version.type), - &compile_info->source); - scan_info = *compile_info;
if ((ret = scan_with_parser(&scan_info, message_context, &scan_descriptor_info, parser)) < 0) @@ -1443,9 +1457,6 @@ static int compile_d3d_bytecode(const struct vkd3d_shader_compile_info *compile_ return ret; }
- vkd3d_shader_dump_shader(compile_info->source_type, shader_get_type_prefix(parser->shader_version.type), - &compile_info->source); - if (compile_info->target_type == VKD3D_SHADER_TARGET_D3D_ASM) { ret = vkd3d_dxbc_binary_to_text(&parser->instructions, &parser->shader_version, compile_info, out); @@ -1492,6 +1503,8 @@ int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info,
vkd3d_shader_message_context_init(&message_context, compile_info->log_level);
+ vkd3d_shader_dump_shader(compile_info); + switch (compile_info->source_type) { case VKD3D_SHADER_SOURCE_DXBC_TPF: diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index c334bc2a7..6e89563a3 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -1314,8 +1314,7 @@ void vkd3d_shader_vnote(struct vkd3d_shader_message_context *context, const stru void vkd3d_shader_vwarning(struct vkd3d_shader_message_context *context, const struct vkd3d_shader_location *location, enum vkd3d_shader_error error, const char *format, va_list args);
-void vkd3d_shader_dump_shader(enum vkd3d_shader_source_type source_type, - const char *prefix, const struct vkd3d_shader_code *shader); +void vkd3d_shader_dump_shader(const struct vkd3d_shader_compile_info *compile_info); 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__)
I think on Linux systems process creation overhead generally isn't much of a concern. It may be a bit more of a consideration on Windows and/or Wine, but if this is something we're concerned about, I'm inclined to suggest extending vkd3d-compiler with a "batch mode" instead.
What do you mean by "batch mode"?
In the meantime, I'm leaving just the first two patches in the series.
This merge request was approved by Henri Verbeet.