Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
---
include/vkd3d_shader.h | 24 ++++-
libs/vkd3d-shader/dxbc.c | 29 ++++--
libs/vkd3d-shader/trace.c | 85 ++-------------
libs/vkd3d-shader/vkd3d_shader.map | 1 +
libs/vkd3d-shader/vkd3d_shader_main.c | 171 +++++++++++++++++++++++++++++--
libs/vkd3d-shader/vkd3d_shader_private.h | 32 +++++-
libs/vkd3d/state.c | 8 +-
programs/vkd3d-compiler/main.c | 8 +-
tests/vkd3d_shader_api.c | 10 +-
9 files changed, 260 insertions(+), 108 deletions(-)
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h
index f4a2be5..69a98e0 100644
--- a/include/vkd3d_shader.h
+++ b/include/vkd3d_shader.h
@@ -248,6 +248,16 @@ enum vkd3d_shader_target_type
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_TARGET_TYPE),
};
+enum vkd3d_shader_log_level
+{
+ VKD3D_SHADER_LOG_NONE,
+ VKD3D_SHADER_LOG_ERROR,
+ VKD3D_SHADER_LOG_WARNING,
+ VKD3D_SHADER_LOG_INFO,
+
+ VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_LOG_LEVEL),
+};
+
struct vkd3d_shader_compile_info
{
enum vkd3d_shader_structure_type type;
@@ -260,6 +270,9 @@ struct vkd3d_shader_compile_info
const struct vkd3d_shader_compile_option *options;
unsigned int option_count;
+
+ enum vkd3d_shader_log_level log_level;
+ const char *source_name;
};
enum vkd3d_shader_spirv_environment
@@ -733,7 +746,9 @@ struct vkd3d_shader_signature
#ifndef VKD3D_SHADER_NO_PROTOTYPES
-int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out);
+int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info,
+ struct vkd3d_shader_code *out, char **messages);
+void vkd3d_shader_free_messages(char *messages);
void vkd3d_shader_free_shader_code(struct vkd3d_shader_code *code);
int vkd3d_shader_parse_root_signature(const struct vkd3d_shader_code *dxbc,
@@ -748,7 +763,7 @@ int vkd3d_shader_convert_root_signature(struct vkd3d_shader_versioned_root_signa
enum vkd3d_shader_root_signature_version version, const struct vkd3d_shader_versioned_root_signature_desc *src);
int vkd3d_shader_scan_dxbc(const struct vkd3d_shader_code *dxbc,
- struct vkd3d_shader_scan_info *scan_info);
+ struct vkd3d_shader_scan_info *scan_info, char **messages);
void vkd3d_shader_free_scan_info(struct vkd3d_shader_scan_info *scan_info);
int vkd3d_shader_parse_input_signature(const struct vkd3d_shader_code *dxbc,
@@ -764,7 +779,8 @@ void vkd3d_shader_free_shader_signature(struct vkd3d_shader_signature *signature
* Function pointer typedefs for vkd3d-shader functions.
*/
typedef int (*PFN_vkd3d_shader_compile)(const struct vkd3d_shader_compile_info *compile_info,
- struct vkd3d_shader_code *out);
+ struct vkd3d_shader_code *out, char **messages);
+typedef void (*PFN_vkd3d_shader_free_messages)(char *messages);
typedef void (*PFN_vkd3d_shader_free_shader_code)(struct vkd3d_shader_code *code);
typedef int (*PFN_vkd3d_shader_parse_root_signature)(const struct vkd3d_shader_code *dxbc,
@@ -778,7 +794,7 @@ typedef int (*PFN_vkd3d_shader_convert_root_signature)(struct vkd3d_shader_versi
enum vkd3d_shader_root_signature_version version, const struct vkd3d_shader_versioned_root_signature_desc *src);
typedef int (*PFN_vkd3d_shader_scan_dxbc)(const struct vkd3d_shader_code *dxbc,
- struct vkd3d_shader_scan_info *scan_info);
+ struct vkd3d_shader_scan_info *scan_info, char **messages);
typedef void (*PFN_vkd3d_shader_free_scan_info)(struct vkd3d_shader_scan_info *scan_info);
typedef int (*PFN_vkd3d_shader_parse_input_signature)(const struct vkd3d_shader_code *dxbc,
diff --git a/libs/vkd3d-shader/dxbc.c b/libs/vkd3d-shader/dxbc.c
index 21efffd..2901998 100644
--- a/libs/vkd3d-shader/dxbc.c
+++ b/libs/vkd3d-shader/dxbc.c
@@ -1941,7 +1941,7 @@ static const char *shader_get_string(const char *data, size_t data_size, DWORD o
return data + offset;
}
-static int parse_dxbc(const char *data, size_t data_size,
+static int parse_dxbc(const char *data, size_t data_size, struct vkd3d_shader_message_context *message_context,
int (*chunk_handler)(const char *data, DWORD data_size, DWORD tag, void *ctx), void *ctx)
{
const char *ptr = data;
@@ -1955,6 +1955,8 @@ static int parse_dxbc(const char *data, size_t data_size,
if (data_size < VKD3D_DXBC_HEADER_SIZE)
{
WARN("Invalid data size %zu.\n", data_size);
+ vkd3d_shader_error(message_context, VKD3D_SHADER_ERROR_DXBC_INVALID_SIZE,
+ "DXBC size %zu is smaller than the DXBC header size.", data_size);
return VKD3D_ERROR_INVALID_ARGUMENT;
}
@@ -2110,11 +2112,16 @@ static int isgn_handler(const char *data, DWORD data_size, DWORD tag, void *ctx)
int shader_parse_input_signature(const void *dxbc, size_t dxbc_length,
struct vkd3d_shader_signature *signature)
{
+ struct vkd3d_shader_message_context message_context;
int ret;
memset(signature, 0, sizeof(*signature));
- if ((ret = parse_dxbc(dxbc, dxbc_length, isgn_handler, signature)) < 0)
+ if (!vkd3d_shader_message_context_init(&message_context, VKD3D_SHADER_LOG_NONE, NULL))
+ return VKD3D_ERROR;
+ if ((ret = parse_dxbc(dxbc, dxbc_length, &message_context, isgn_handler, signature)) < 0)
ERR("Failed to parse input signature.\n");
+ vkd3d_shader_message_context_cleanup(&message_context);
+
return ret;
}
@@ -2187,7 +2194,7 @@ void free_shader_desc(struct vkd3d_shader_desc *desc)
}
int shader_extract_from_dxbc(const void *dxbc, size_t dxbc_length,
- struct vkd3d_shader_desc *desc)
+ struct vkd3d_shader_message_context *message_context, struct vkd3d_shader_desc *desc)
{
int ret;
@@ -2197,13 +2204,13 @@ int shader_extract_from_dxbc(const void *dxbc, size_t dxbc_length,
memset(&desc->output_signature, 0, sizeof(desc->output_signature));
memset(&desc->patch_constant_signature, 0, sizeof(desc->patch_constant_signature));
- ret = parse_dxbc(dxbc, dxbc_length, shdr_handler, desc);
+ ret = parse_dxbc(dxbc, dxbc_length, message_context, shdr_handler, desc);
if (!desc->byte_code)
ret = VKD3D_ERROR_INVALID_ARGUMENT;
if (ret < 0)
{
- FIXME("Failed to parse shader, vkd3d result %d.\n", ret);
+ WARN("Failed to parse shader, vkd3d result %d.\n", ret);
free_shader_desc(desc);
}
@@ -2656,18 +2663,20 @@ static int rts0_handler(const char *data, DWORD data_size, DWORD tag, void *cont
int vkd3d_shader_parse_root_signature(const struct vkd3d_shader_code *dxbc,
struct vkd3d_shader_versioned_root_signature_desc *root_signature)
{
+ struct vkd3d_shader_message_context message_context;
int ret;
TRACE("dxbc {%p, %zu}, root_signature %p.\n", dxbc->code, dxbc->size, root_signature);
memset(root_signature, 0, sizeof(*root_signature));
- if ((ret = parse_dxbc(dxbc->code, dxbc->size, rts0_handler, root_signature)) < 0)
- {
+ if (!vkd3d_shader_message_context_init(&message_context, VKD3D_SHADER_LOG_NONE, NULL))
+ return VKD3D_ERROR;
+ ret = parse_dxbc(dxbc->code, dxbc->size, &message_context, rts0_handler, root_signature);
+ vkd3d_shader_message_context_cleanup(&message_context);
+ if (ret < 0)
vkd3d_shader_free_root_signature(root_signature);
- return ret;
- }
- return VKD3D_OK;
+ return ret;
}
static unsigned int versioned_root_signature_get_parameter_count(
diff --git a/libs/vkd3d-shader/trace.c b/libs/vkd3d-shader/trace.c
index 7ba9695..b0ad387 100644
--- a/libs/vkd3d-shader/trace.c
+++ b/libs/vkd3d-shader/trace.c
@@ -26,14 +26,6 @@
#include <stdio.h>
-struct vkd3d_string_buffer
-{
- struct list entry;
- char *buffer;
- unsigned int buffer_size;
- unsigned int content_size;
-};
-
static const char * const shader_opcode_names[] =
{
/* VKD3DSIH_ABS */ "abs",
@@ -308,77 +300,16 @@ shader_input_sysval_semantic_names[] =
{VKD3D_SIV_LINE_DENSITY_TESS_FACTOR, "finalLineDensityTessFactor"},
};
-static void string_buffer_clear(struct vkd3d_string_buffer *buffer)
-{
- buffer->buffer[0] = '\0';
- buffer->content_size = 0;
-}
-
-static bool string_buffer_init(struct vkd3d_string_buffer *buffer)
-{
- buffer->buffer_size = 32;
- if (!(buffer->buffer = vkd3d_malloc(buffer->buffer_size)))
- {
- ERR("Failed to allocate shader buffer memory.\n");
- return false;
- }
-
- string_buffer_clear(buffer);
- return true;
-}
-
-static void string_buffer_free(struct vkd3d_string_buffer *buffer)
-{
- vkd3d_free(buffer->buffer);
-}
-
-static bool string_buffer_resize(struct vkd3d_string_buffer *buffer, int rc)
-{
- unsigned int new_buffer_size = buffer->buffer_size * 2;
- char *new_buffer;
-
- while (rc > 0 && (unsigned int)rc >= new_buffer_size - buffer->content_size)
- new_buffer_size *= 2;
- if (!(new_buffer = vkd3d_realloc(buffer->buffer, new_buffer_size)))
- {
- ERR("Failed to grow buffer.\n");
- buffer->buffer[buffer->content_size] = '\0';
- return false;
- }
- buffer->buffer = new_buffer;
- buffer->buffer_size = new_buffer_size;
- return true;
-}
-
-static int shader_vaddline(struct vkd3d_string_buffer *buffer, const char *format, va_list args)
-{
- unsigned int rem;
- int rc;
-
- rem = buffer->buffer_size - buffer->content_size;
- rc = vsnprintf(&buffer->buffer[buffer->content_size], rem, format, args);
- if (rc < 0 || (unsigned int)rc >= rem)
- return rc;
-
- buffer->content_size += rc;
- return 0;
-}
-
-static int shader_addline(struct vkd3d_string_buffer *buffer, const char *format, ...)
+static int VKD3D_PRINTF_FUNC(2, 3) shader_addline(struct vkd3d_string_buffer *buffer, const char *format, ...)
{
va_list args;
int ret;
- for (;;)
- {
- va_start(args, format);
- ret = shader_vaddline(buffer, format, args);
- va_end(args);
- if (!ret)
- return ret;
- if (!string_buffer_resize(buffer, ret))
- return -1;
- }
+ va_start(args, format);
+ ret = vkd3d_string_buffer_vprintf(buffer, format, args);
+ va_end(args);
+
+ return ret;
}
/* Convert floating point offset relative to a register file to an absolute
@@ -1617,7 +1548,7 @@ void vkd3d_shader_trace(void *data)
const char *p, *q;
const DWORD *ptr;
- if (!string_buffer_init(&buffer))
+ if (!vkd3d_string_buffer_init(&buffer))
{
ERR("Failed to initialize string buffer.\n");
return;
@@ -1651,5 +1582,5 @@ void vkd3d_shader_trace(void *data)
TRACE(" %.*s", (int)(q - p), p);
}
- string_buffer_free(&buffer);
+ vkd3d_string_buffer_cleanup(&buffer);
}
diff --git a/libs/vkd3d-shader/vkd3d_shader.map b/libs/vkd3d-shader/vkd3d_shader.map
index 13bebde..55b50ad 100644
--- a/libs/vkd3d-shader/vkd3d_shader.map
+++ b/libs/vkd3d-shader/vkd3d_shader.map
@@ -4,6 +4,7 @@ global:
vkd3d_shader_compile;
vkd3d_shader_convert_root_signature;
vkd3d_shader_find_signature_element;
+ vkd3d_shader_free_messages;
vkd3d_shader_free_root_signature;
vkd3d_shader_free_scan_info;
vkd3d_shader_free_shader_code;
diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c
index 30b4405..c7161e4 100644
--- a/libs/vkd3d-shader/vkd3d_shader_main.c
+++ b/libs/vkd3d-shader/vkd3d_shader_main.c
@@ -22,6 +22,129 @@
VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG");
+static void vkd3d_string_buffer_clear(struct vkd3d_string_buffer *buffer)
+{
+ buffer->buffer[0] = '\0';
+ buffer->content_size = 0;
+}
+
+bool vkd3d_string_buffer_init(struct vkd3d_string_buffer *buffer)
+{
+ buffer->buffer_size = 32;
+ if (!(buffer->buffer = vkd3d_malloc(buffer->buffer_size)))
+ {
+ ERR("Failed to allocate shader buffer memory.\n");
+ return false;
+ }
+
+ vkd3d_string_buffer_clear(buffer);
+ return true;
+}
+
+void vkd3d_string_buffer_cleanup(struct vkd3d_string_buffer *buffer)
+{
+ vkd3d_free(buffer->buffer);
+}
+
+static bool vkd3d_string_buffer_resize(struct vkd3d_string_buffer *buffer, int rc)
+{
+ unsigned int new_buffer_size = buffer->buffer_size * 2;
+ char *new_buffer;
+
+ while (rc > 0 && (unsigned int)rc >= new_buffer_size - buffer->content_size)
+ new_buffer_size *= 2;
+ if (!(new_buffer = vkd3d_realloc(buffer->buffer, new_buffer_size)))
+ {
+ ERR("Failed to grow buffer.\n");
+ buffer->buffer[buffer->content_size] = '\0';
+ return false;
+ }
+ buffer->buffer = new_buffer;
+ buffer->buffer_size = new_buffer_size;
+ return true;
+}
+
+int vkd3d_string_buffer_vprintf(struct vkd3d_string_buffer *buffer, const char *format, va_list args)
+{
+ unsigned int rem;
+ va_list a;
+ int rc;
+
+ for (;;)
+ {
+ rem = buffer->buffer_size - buffer->content_size;
+ va_copy(a, args);
+ rc = vsnprintf(&buffer->buffer[buffer->content_size], rem, format, a);
+ va_end(a);
+ if (rc >= 0 && (unsigned int)rc < rem)
+ {
+ buffer->content_size += rc;
+ return 0;
+ }
+
+ if (!vkd3d_string_buffer_resize(buffer, rc))
+ return -1;
+ }
+}
+
+static int VKD3D_PRINTF_FUNC(2, 3) vkd3d_string_buffer_printf(struct vkd3d_string_buffer *buffer,
+ const char *format, ...)
+{
+ va_list args;
+ int ret;
+
+ va_start(args, format);
+ ret = vkd3d_string_buffer_vprintf(buffer, format, args);
+ va_end(args);
+
+ return ret;
+}
+
+bool vkd3d_shader_message_context_init(struct vkd3d_shader_message_context *context,
+ enum vkd3d_shader_log_level log_level, const char *source_name)
+{
+ context->log_level = log_level;
+ context->source_name = source_name ? source_name : "<anonymous>";
+ context->line = 0;
+ context->column = 0;
+
+ return vkd3d_string_buffer_init(&context->messages);
+}
+
+void vkd3d_shader_message_context_cleanup(struct vkd3d_shader_message_context *context)
+{
+ vkd3d_string_buffer_cleanup(&context->messages);
+}
+
+static char *vkd3d_shader_message_context_copy_messages(struct vkd3d_shader_message_context *context)
+{
+ char *messages;
+
+ if ((messages = vkd3d_malloc(context->messages.content_size)))
+ memcpy(messages, context->messages.buffer, context->messages.content_size);
+
+ return messages;
+}
+
+void vkd3d_shader_error(struct vkd3d_shader_message_context *context,
+ enum vkd3d_shader_error error, const char *format, ...)
+{
+ va_list args;
+
+ if (context->log_level < VKD3D_SHADER_LOG_ERROR)
+ return;
+
+ if (context->line)
+ vkd3d_string_buffer_printf(&context->messages, "%s:%u:%u: E%04u: ",
+ context->source_name, context->line, context->column, error);
+ else
+ vkd3d_string_buffer_printf(&context->messages, "%s: E%04u: ", context->source_name, error);
+ va_start(args, format);
+ vkd3d_string_buffer_vprintf(&context->messages, format, args);
+ va_end(args);
+ vkd3d_string_buffer_printf(&context->messages, "\n");
+}
+
static void vkd3d_shader_dump_blob(const char *path, const char *prefix, const void *data, size_t size)
{
static int shader_id = 0;
@@ -71,12 +194,12 @@ struct vkd3d_shader_parser
};
static int vkd3d_shader_parser_init(struct vkd3d_shader_parser *parser,
- const struct vkd3d_shader_code *dxbc)
+ const struct vkd3d_shader_code *dxbc, struct vkd3d_shader_message_context *message_context)
{
struct vkd3d_shader_desc *shader_desc = &parser->shader_desc;
int ret;
- if ((ret = shader_extract_from_dxbc(dxbc->code, dxbc->size, shader_desc)) < 0)
+ if ((ret = shader_extract_from_dxbc(dxbc->code, dxbc->size, message_context, shader_desc)) < 0)
{
WARN("Failed to extract shader, vkd3d result %d.\n", ret);
return ret;
@@ -129,25 +252,45 @@ static int vkd3d_shader_validate_compile_info(const struct vkd3d_shader_compile_
return VKD3D_OK;
}
-int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out)
+void vkd3d_shader_free_messages(char *messages)
+{
+ vkd3d_free(messages);
+}
+
+int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info,
+ struct vkd3d_shader_code *out, char **messages)
{
+ struct vkd3d_shader_message_context message_context;
struct vkd3d_shader_instruction instruction;
struct vkd3d_dxbc_compiler *spirv_compiler;
struct vkd3d_shader_scan_info scan_info;
struct vkd3d_shader_parser parser;
int ret;
- TRACE("compile_info %p, out %p.\n", compile_info, out);
+ TRACE("compile_info %p, out %p, messages %p.\n", compile_info, out, messages);
+
+ if (messages)
+ *messages = NULL;
if ((ret = vkd3d_shader_validate_compile_info(compile_info)) < 0)
return ret;
scan_info.type = VKD3D_SHADER_STRUCTURE_TYPE_SCAN_INFO;
scan_info.next = NULL;
- if ((ret = vkd3d_shader_scan_dxbc(&compile_info->source, &scan_info)) < 0)
+ if ((ret = vkd3d_shader_scan_dxbc(&compile_info->source, &scan_info, messages)) < 0)
return ret;
- if ((ret = vkd3d_shader_parser_init(&parser, &compile_info->source)) < 0)
+ if (!vkd3d_shader_message_context_init(&message_context, compile_info->log_level, compile_info->source_name))
+ return VKD3D_ERROR;
+ ret = vkd3d_shader_parser_init(&parser, &compile_info->source, &message_context);
+ if (messages)
+ {
+ vkd3d_shader_free_messages(*messages);
+ if (!(*messages = vkd3d_shader_message_context_copy_messages(&message_context)))
+ ret = VKD3D_ERROR_OUT_OF_MEMORY;
+ }
+ vkd3d_shader_message_context_cleanup(&message_context);
+ if (ret < 0)
return ret;
vkd3d_shader_dump_shader(parser.shader_version.type, &compile_info->source);
@@ -418,14 +561,18 @@ static void vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *cont
}
int vkd3d_shader_scan_dxbc(const struct vkd3d_shader_code *dxbc,
- struct vkd3d_shader_scan_info *scan_info)
+ struct vkd3d_shader_scan_info *scan_info, char **messages)
{
+ struct vkd3d_shader_message_context message_context;
struct vkd3d_shader_instruction instruction;
struct vkd3d_shader_scan_context context;
struct vkd3d_shader_parser parser;
int ret;
- TRACE("dxbc {%p, %zu}, scan_info %p.\n", dxbc->code, dxbc->size, scan_info);
+ TRACE("dxbc {%p, %zu}, scan_info %p, messages %p.\n", dxbc->code, dxbc->size, scan_info, messages);
+
+ if (messages)
+ *messages = NULL;
if (scan_info->type != VKD3D_SHADER_STRUCTURE_TYPE_SCAN_INFO)
{
@@ -433,7 +580,13 @@ int vkd3d_shader_scan_dxbc(const struct vkd3d_shader_code *dxbc,
return VKD3D_ERROR_INVALID_ARGUMENT;
}
- if ((ret = vkd3d_shader_parser_init(&parser, dxbc)) < 0)
+ if (!vkd3d_shader_message_context_init(&message_context, VKD3D_SHADER_LOG_INFO, NULL))
+ return VKD3D_ERROR;
+ ret = vkd3d_shader_parser_init(&parser, dxbc, &message_context);
+ if (messages && !(*messages = vkd3d_shader_message_context_copy_messages(&message_context)))
+ ret = VKD3D_ERROR_OUT_OF_MEMORY;
+ vkd3d_shader_message_context_cleanup(&message_context);
+ if (ret < 0)
return ret;
memset(scan_info, 0, sizeof(*scan_info));
diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h
index 49de8f0..b820012 100644
--- a/libs/vkd3d-shader/vkd3d_shader_private.h
+++ b/libs/vkd3d-shader/vkd3d_shader_private.h
@@ -59,6 +59,11 @@
#define VKD3D_VEC4_SIZE 4
+enum vkd3d_shader_error
+{
+ VKD3D_SHADER_ERROR_DXBC_INVALID_SIZE = 1,
+};
+
enum VKD3D_SHADER_INSTRUCTION_HANDLER
{
VKD3DSIH_ABS,
@@ -799,8 +804,33 @@ void shader_sm4_read_instruction(void *data, const DWORD **ptr,
struct vkd3d_shader_instruction *ins) DECLSPEC_HIDDEN;
bool shader_sm4_is_end(void *data, const DWORD **ptr) DECLSPEC_HIDDEN;
+struct vkd3d_string_buffer
+{
+ char *buffer;
+ unsigned int buffer_size;
+ unsigned int content_size;
+};
+
+void vkd3d_string_buffer_cleanup(struct vkd3d_string_buffer *buffer) DECLSPEC_HIDDEN;
+bool vkd3d_string_buffer_init(struct vkd3d_string_buffer *buffer) DECLSPEC_HIDDEN;
+int vkd3d_string_buffer_vprintf(struct vkd3d_string_buffer *buffer, const char *format, va_list args) DECLSPEC_HIDDEN;
+
+struct vkd3d_shader_message_context
+{
+ enum vkd3d_shader_log_level log_level;
+ const char *source_name;
+ unsigned int line, column;
+ struct vkd3d_string_buffer messages;
+};
+
+void vkd3d_shader_message_context_cleanup(struct vkd3d_shader_message_context *context) DECLSPEC_HIDDEN;
+bool vkd3d_shader_message_context_init(struct vkd3d_shader_message_context *context,
+ enum vkd3d_shader_log_level log_level, const char *source_name) DECLSPEC_HIDDEN;
+void vkd3d_shader_error(struct vkd3d_shader_message_context *context, enum vkd3d_shader_error error,
+ const char *format, ...) VKD3D_PRINTF_FUNC(3, 4) DECLSPEC_HIDDEN;
+
int shader_extract_from_dxbc(const void *dxbc, size_t dxbc_length,
- struct vkd3d_shader_desc *desc) DECLSPEC_HIDDEN;
+ struct vkd3d_shader_message_context *message_context, struct vkd3d_shader_desc *desc) DECLSPEC_HIDDEN;
void free_shader_desc(struct vkd3d_shader_desc *desc) DECLSPEC_HIDDEN;
int shader_parse_input_signature(const void *dxbc, size_t dxbc_length,
diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c
index f6a38c6..55cb389 100644
--- a/libs/vkd3d/state.c
+++ b/libs/vkd3d/state.c
@@ -1354,8 +1354,10 @@ static HRESULT create_shader_stage(struct d3d12_device *device,
compile_info.target_type = VKD3D_SHADER_TARGET_SPIRV_BINARY;
compile_info.options = NULL;
compile_info.option_count = 0;
+ compile_info.log_level = VKD3D_SHADER_LOG_NONE;
+ compile_info.source_name = NULL;
- if ((ret = vkd3d_shader_compile(&compile_info, &spirv)) < 0)
+ if ((ret = vkd3d_shader_compile(&compile_info, &spirv, NULL)) < 0)
{
WARN("Failed to compile shader, vkd3d result %d.\n", ret);
return hresult_from_vkd3d_result(ret);
@@ -1527,7 +1529,7 @@ static HRESULT d3d12_pipeline_state_init_compute(struct d3d12_pipeline_state *st
dxbc.size = desc->CS.BytecodeLength;
shader_info.type = VKD3D_SHADER_STRUCTURE_TYPE_SCAN_INFO;
shader_info.next = NULL;
- if ((ret = vkd3d_shader_scan_dxbc(&dxbc, &shader_info)) < 0)
+ if ((ret = vkd3d_shader_scan_dxbc(&dxbc, &shader_info, NULL)) < 0)
{
WARN("Failed to scan shader bytecode, vkd3d result %d.\n", ret);
return hresult_from_vkd3d_result(ret);
@@ -2271,7 +2273,7 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s
if (!b->pShaderBytecode)
continue;
- if ((ret = vkd3d_shader_scan_dxbc(&dxbc, &shader_info)) < 0)
+ if ((ret = vkd3d_shader_scan_dxbc(&dxbc, &shader_info, NULL)) < 0)
{
WARN("Failed to scan shader bytecode, stage %#x, vkd3d result %d.\n",
shader_stages[i].stage, ret);
diff --git a/programs/vkd3d-compiler/main.c b/programs/vkd3d-compiler/main.c
index 4da3a99..be8a99d 100644
--- a/programs/vkd3d-compiler/main.c
+++ b/programs/vkd3d-compiler/main.c
@@ -222,6 +222,7 @@ int main(int argc, char **argv)
struct vkd3d_shader_compile_info info;
struct vkd3d_shader_code spirv;
struct options options;
+ char *messages;
int ret;
if (!parse_command_line(argc, argv, &options))
@@ -242,6 +243,8 @@ int main(int argc, char **argv)
info.target_type = VKD3D_SHADER_TARGET_SPIRV_BINARY;
info.options = options.compile_options;
info.option_count = options.compile_option_count;
+ info.log_level = VKD3D_SHADER_LOG_INFO;
+ info.source_name = options.filename;
if (!read_shader(&info.source, options.filename))
{
@@ -249,7 +252,10 @@ int main(int argc, char **argv)
return 1;
}
- ret = vkd3d_shader_compile(&info, &spirv);
+ ret = vkd3d_shader_compile(&info, &spirv, &messages);
+ if (messages)
+ fputs(messages, stderr);
+ vkd3d_shader_free_messages(messages);
vkd3d_shader_free_shader_code(&info.source);
if (ret < 0)
{
diff --git a/tests/vkd3d_shader_api.c b/tests/vkd3d_shader_api.c
index 161feb8..079559a 100644
--- a/tests/vkd3d_shader_api.c
+++ b/tests/vkd3d_shader_api.c
@@ -63,8 +63,10 @@ static void test_invalid_shaders(void)
info.target_type = VKD3D_SHADER_TARGET_SPIRV_BINARY;
info.options = &option;
info.option_count = 1;
+ info.log_level = VKD3D_SHADER_LOG_NONE;
+ info.source_name = NULL;
- rc = vkd3d_shader_compile(&info, &spirv);
+ rc = vkd3d_shader_compile(&info, &spirv, NULL);
ok(rc == VKD3D_ERROR_INVALID_SHADER, "Got unexpected error code %d.\n", rc);
}
@@ -140,14 +142,16 @@ static void test_vkd3d_shader_pfns(void)
compile_info.target_type = VKD3D_SHADER_TARGET_SPIRV_BINARY;
compile_info.options = NULL;
compile_info.option_count = 0;
+ compile_info.log_level = VKD3D_SHADER_LOG_NONE;
+ compile_info.source_name = NULL;
- rc = pfn_vkd3d_shader_compile(&compile_info, &spirv);
+ rc = pfn_vkd3d_shader_compile(&compile_info, &spirv, NULL);
ok(rc == VKD3D_OK, "Got unexpected error code %d.\n", rc);
pfn_vkd3d_shader_free_shader_code(&spirv);
memset(&scan_info, 0, sizeof(scan_info));
scan_info.type = VKD3D_SHADER_STRUCTURE_TYPE_SCAN_INFO;
- rc = pfn_vkd3d_shader_scan_dxbc(&vs, &scan_info);
+ rc = pfn_vkd3d_shader_scan_dxbc(&vs, &scan_info, NULL);
ok(rc == VKD3D_OK, "Got unexpected error code %d.\n", rc);
}
--
2.11.0