vkd3d-shader: Dump shaders as soon as possible.

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.
This commit is contained in:
Giovanni Mascellani 2023-10-21 21:35:08 +02:00 committed by Alexandre Julliard
parent ab09c0b45b
commit dd96fe50e2
Notes: Alexandre Julliard 2023-11-02 22:49:26 +01:00
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/424
4 changed files with 29 additions and 18 deletions

View File

@ -3260,7 +3260,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;
@ -3627,14 +3627,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,

View File

@ -1169,6 +1169,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);

View File

@ -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);
}
@ -1310,6 +1325,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:
@ -1351,9 +1368,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)
@ -1437,9 +1451,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);
@ -1486,6 +1497,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:

View File

@ -1324,8 +1324,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__)