Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/vkd3d_shader_main.c | 32 ++++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-)
diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index eed0316c..2ea233bb 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -600,6 +600,16 @@ static void vkd3d_shader_scan_typed_resource_declaration(struct vkd3d_shader_sca semantic->resource_type, resource_data_type); }
+static void vkd3d_shader_scan_error(struct vkd3d_shader_scan_context *context, + enum vkd3d_shader_error error, const char *format, ...) +{ + va_list args; + + va_start(args, format); + vkd3d_shader_verror(context->message_context, error, format, args); + va_end(args); +} + static int vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *context, const struct vkd3d_shader_instruction *instruction) { @@ -636,7 +646,7 @@ static int vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *conte case VKD3DSIH_ELSE: if (!(cf_info = vkd3d_shader_scan_get_current_cf_info(context)) || cf_info->type != VKD3D_SHADER_BLOCK_IF) { - vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, + vkd3d_shader_scan_error(context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, "Encountered ‘else’ instruction without corresponding ‘if’ block."); return VKD3D_ERROR_INVALID_SHADER; } @@ -645,7 +655,7 @@ static int vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *conte case VKD3DSIH_ENDIF: if (!(cf_info = vkd3d_shader_scan_get_current_cf_info(context)) || cf_info->type != VKD3D_SHADER_BLOCK_IF) { - vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, + vkd3d_shader_scan_error(context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, "Encountered ‘endif’ instruction without corresponding ‘if’ block."); return VKD3D_ERROR_INVALID_SHADER; } @@ -658,7 +668,7 @@ static int vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *conte case VKD3DSIH_ENDLOOP: if (!(cf_info = vkd3d_shader_scan_get_current_cf_info(context)) || cf_info->type != VKD3D_SHADER_BLOCK_LOOP) { - vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, + vkd3d_shader_scan_error(context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, "Encountered ‘endloop’ instruction without corresponding ‘loop’ block."); return VKD3D_ERROR_INVALID_SHADER; } @@ -672,7 +682,7 @@ static int vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *conte if (!(cf_info = vkd3d_shader_scan_get_current_cf_info(context)) || cf_info->type != VKD3D_SHADER_BLOCK_SWITCH || cf_info->inside_block) { - vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, + vkd3d_shader_scan_error(context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, "Encountered ‘endswitch’ instruction without corresponding ‘switch’ block."); return VKD3D_ERROR_INVALID_SHADER; } @@ -682,7 +692,7 @@ static int vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *conte if (!(cf_info = vkd3d_shader_scan_get_current_cf_info(context)) || cf_info->type != VKD3D_SHADER_BLOCK_SWITCH) { - vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, + vkd3d_shader_scan_error(context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, "Encountered ‘case’ instruction outside switch block."); return VKD3D_ERROR_INVALID_SHADER; } @@ -692,13 +702,13 @@ static int vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *conte if (!(cf_info = vkd3d_shader_scan_get_current_cf_info(context)) || cf_info->type != VKD3D_SHADER_BLOCK_SWITCH) { - vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, + vkd3d_shader_scan_error(context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, "Encountered ‘default’ instruction outside switch block."); return VKD3D_ERROR_INVALID_SHADER; } if (cf_info->has_default) { - vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, + vkd3d_shader_scan_error(context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, "Encountered duplicate ‘default’ instruction inside the current switch block."); return VKD3D_ERROR_INVALID_SHADER; } @@ -708,7 +718,7 @@ static int vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *conte case VKD3DSIH_BREAK: if (!(cf_info = vkd3d_shader_scan_find_innermost_breakable_cf_info(context))) { - vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, + vkd3d_shader_scan_error(context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, "Encountered ‘break’ instruction outside breakable block."); return VKD3D_ERROR_INVALID_SHADER; } @@ -717,7 +727,7 @@ static int vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *conte case VKD3DSIH_BREAKP: if (!(cf_info = vkd3d_shader_scan_find_innermost_loop_cf_info(context))) { - vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, + vkd3d_shader_scan_error(context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, "Encountered ‘breakp’ instruction outside loop."); return VKD3D_ERROR_INVALID_SHADER; } @@ -725,7 +735,7 @@ static int vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *conte case VKD3DSIH_CONTINUE: if (!(cf_info = vkd3d_shader_scan_find_innermost_loop_cf_info(context))) { - vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, + vkd3d_shader_scan_error(context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, "Encountered ‘continue’ instruction outside loop."); return VKD3D_ERROR_INVALID_SHADER; } @@ -734,7 +744,7 @@ static int vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *conte case VKD3DSIH_CONTINUEP: if (!(cf_info = vkd3d_shader_scan_find_innermost_loop_cf_info(context))) { - vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, + vkd3d_shader_scan_error(context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF, "Encountered ‘continue’ instruction outside loop."); return VKD3D_ERROR_INVALID_SHADER; }
Includes a slight change in behaviour: parse_dxbc() and vkd3d_shader_serialize_root_signature() now print nothing instead of "<anonymous>".
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/dxbc.c | 50 ++++++++++++------------ libs/vkd3d-shader/spirv.c | 6 ++- libs/vkd3d-shader/vkd3d_shader_main.c | 41 +++++++++---------- libs/vkd3d-shader/vkd3d_shader_private.h | 16 +++++--- 4 files changed, 58 insertions(+), 55 deletions(-)
diff --git a/libs/vkd3d-shader/dxbc.c b/libs/vkd3d-shader/dxbc.c index 9977d1a3..df9245de 100644 --- a/libs/vkd3d-shader/dxbc.c +++ b/libs/vkd3d-shader/dxbc.c @@ -2036,7 +2036,7 @@ static int parse_dxbc(const char *data, size_t data_size, struct vkd3d_shader_me 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, + vkd3d_shader_error(message_context, NULL, VKD3D_SHADER_ERROR_DXBC_INVALID_SIZE, "DXBC size %zu is smaller than the DXBC header size.", data_size); return VKD3D_ERROR_INVALID_ARGUMENT; } @@ -2047,7 +2047,7 @@ static int parse_dxbc(const char *data, size_t data_size, struct vkd3d_shader_me if (tag != TAG_DXBC) { WARN("Wrong tag.\n"); - vkd3d_shader_error(message_context, VKD3D_SHADER_ERROR_DXBC_INVALID_MAGIC, "Invalid DXBC magic."); + vkd3d_shader_error(message_context, NULL, VKD3D_SHADER_ERROR_DXBC_INVALID_MAGIC, "Invalid DXBC magic."); return VKD3D_ERROR_INVALID_ARGUMENT; }
@@ -2063,7 +2063,7 @@ static int parse_dxbc(const char *data, size_t data_size, struct vkd3d_shader_me checksum[0], checksum[1], checksum[2], checksum[3], calculated_checksum[0], calculated_checksum[1], calculated_checksum[2], calculated_checksum[3]); - vkd3d_shader_error(message_context, VKD3D_SHADER_ERROR_DXBC_INVALID_CHECKSUM, "Invalid DXBC checksum."); + vkd3d_shader_error(message_context, NULL, VKD3D_SHADER_ERROR_DXBC_INVALID_CHECKSUM, "Invalid DXBC checksum."); return VKD3D_ERROR_INVALID_ARGUMENT; }
@@ -2072,7 +2072,7 @@ static int parse_dxbc(const char *data, size_t data_size, struct vkd3d_shader_me if (version != 0x00000001) { WARN("Got unexpected DXBC version %#x.\n", version); - vkd3d_shader_error(message_context, VKD3D_SHADER_ERROR_DXBC_INVALID_VERSION, + vkd3d_shader_error(message_context, NULL, VKD3D_SHADER_ERROR_DXBC_INVALID_VERSION, "DXBC version %#x is not supported.", version); return VKD3D_ERROR_INVALID_ARGUMENT; } @@ -2095,7 +2095,7 @@ static int parse_dxbc(const char *data, size_t data_size, struct vkd3d_shader_me if (chunk_offset >= data_size || !require_space(chunk_offset, 2, sizeof(DWORD), data_size)) { WARN("Invalid chunk offset %#x (data size %zu).\n", chunk_offset, data_size); - vkd3d_shader_error(message_context, VKD3D_SHADER_ERROR_DXBC_INVALID_CHUNK_OFFSET, + vkd3d_shader_error(message_context, NULL, VKD3D_SHADER_ERROR_DXBC_INVALID_CHUNK_OFFSET, "DXBC chunk %u has invalid offset %#x (data size %#zx).", i, chunk_offset, data_size); return VKD3D_ERROR_INVALID_ARGUMENT; } @@ -2109,7 +2109,7 @@ static int parse_dxbc(const char *data, size_t data_size, struct vkd3d_shader_me { WARN("Invalid chunk size %#x (data size %zu, chunk offset %#x).\n", chunk_size, data_size, chunk_offset); - vkd3d_shader_error(message_context, VKD3D_SHADER_ERROR_DXBC_INVALID_CHUNK_SIZE, + vkd3d_shader_error(message_context, NULL, VKD3D_SHADER_ERROR_DXBC_INVALID_CHUNK_SIZE, "DXBC chunk %u has invalid size %#x (data size %#zx, chunk offset %#x).", i, chunk_offset, data_size, chunk_offset); return VKD3D_ERROR_INVALID_ARGUMENT; @@ -2781,7 +2781,7 @@ int vkd3d_shader_parse_root_signature(const struct vkd3d_shader_code *dxbc, memset(root_signature, 0, sizeof(*root_signature)); if (messages) *messages = NULL; - vkd3d_shader_message_context_init(&message_context, VKD3D_SHADER_LOG_INFO, NULL); + vkd3d_shader_message_context_init(&message_context, VKD3D_SHADER_LOG_INFO);
ret = parse_dxbc(dxbc->code, dxbc->size, &message_context, rts0_handler, root_signature); vkd3d_shader_message_context_trace_messages(&message_context); @@ -2935,7 +2935,7 @@ static int shader_write_root_signature_header(struct root_signature_writer_conte return VKD3D_OK;
fail: - vkd3d_shader_error(&context->message_context, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, + vkd3d_shader_error(&context->message_context, NULL, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, "Out of memory while writing root signature header."); return VKD3D_ERROR_OUT_OF_MEMORY; } @@ -2963,7 +2963,7 @@ static int shader_write_descriptor_ranges(struct root_signature_writer_context * return VKD3D_OK;
fail: - vkd3d_shader_error(&context->message_context, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, + vkd3d_shader_error(&context->message_context, NULL, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, "Out of memory while writing root signature descriptor ranges."); return VKD3D_ERROR_OUT_OF_MEMORY; } @@ -2993,7 +2993,7 @@ static int shader_write_descriptor_ranges1(struct root_signature_writer_context return VKD3D_OK;
fail: - vkd3d_shader_error(&context->message_context, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, + vkd3d_shader_error(&context->message_context, NULL, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, "Out of memory while writing root signature descriptor ranges."); return VKD3D_ERROR_OUT_OF_MEMORY; } @@ -3009,7 +3009,7 @@ static int shader_write_descriptor_table(struct root_signature_writer_context *c return shader_write_descriptor_ranges(context, table);
fail: - vkd3d_shader_error(&context->message_context, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, + vkd3d_shader_error(&context->message_context, NULL, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, "Out of memory while writing root signature root descriptor table."); return VKD3D_ERROR_OUT_OF_MEMORY; } @@ -3025,7 +3025,7 @@ static int shader_write_descriptor_table1(struct root_signature_writer_context * return shader_write_descriptor_ranges1(context, table);
fail: - vkd3d_shader_error(&context->message_context, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, + vkd3d_shader_error(&context->message_context, NULL, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, "Out of memory while writing root signature root descriptor table."); return VKD3D_ERROR_OUT_OF_MEMORY; } @@ -3043,7 +3043,7 @@ static int shader_write_root_constants(struct root_signature_writer_context *con return VKD3D_OK;
fail: - vkd3d_shader_error(&context->message_context, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, + vkd3d_shader_error(&context->message_context, NULL, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, "Out of memory while writing root signature root constants."); return VKD3D_ERROR_OUT_OF_MEMORY; } @@ -3059,7 +3059,7 @@ static int shader_write_root_descriptor(struct root_signature_writer_context *co return VKD3D_OK;
fail: - vkd3d_shader_error(&context->message_context, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, + vkd3d_shader_error(&context->message_context, NULL, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, "Out of memory while writing root signature root descriptor."); return VKD3D_ERROR_OUT_OF_MEMORY; } @@ -3077,7 +3077,7 @@ static int shader_write_root_descriptor1(struct root_signature_writer_context *c return VKD3D_OK;
fail: - vkd3d_shader_error(&context->message_context, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, + vkd3d_shader_error(&context->message_context, NULL, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, "Out of memory while writing root signature root descriptor."); return VKD3D_ERROR_OUT_OF_MEMORY; } @@ -3126,7 +3126,7 @@ static int shader_write_root_parameters(struct root_signature_writer_context *co break; default: FIXME("Unrecognized type %#x.\n", versioned_root_signature_get_parameter_type(desc, i)); - vkd3d_shader_error(&context->message_context, VKD3D_SHADER_ERROR_RS_INVALID_ROOT_PARAMETER_TYPE, + vkd3d_shader_error(&context->message_context, NULL, VKD3D_SHADER_ERROR_RS_INVALID_ROOT_PARAMETER_TYPE, "Invalid/unrecognised root signature root parameter type %#x.", versioned_root_signature_get_parameter_type(desc, i)); return VKD3D_ERROR_INVALID_ARGUMENT; @@ -3139,7 +3139,7 @@ static int shader_write_root_parameters(struct root_signature_writer_context *co return VKD3D_OK;
fail: - vkd3d_shader_error(&context->message_context, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, + vkd3d_shader_error(&context->message_context, NULL, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, "Out of memory while writing root signature root parameters."); return VKD3D_ERROR_OUT_OF_MEMORY; } @@ -3183,7 +3183,7 @@ static int shader_write_static_samplers(struct root_signature_writer_context *co return VKD3D_OK;
fail: - vkd3d_shader_error(&context->message_context, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, + vkd3d_shader_error(&context->message_context, NULL, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, "Out of memory while writing root signature static samplers."); return VKD3D_ERROR_OUT_OF_MEMORY; } @@ -3218,7 +3218,7 @@ static int shader_write_root_signature(struct root_signature_writer_context *con return shader_write_static_samplers(context, desc);
fail: - vkd3d_shader_error(&context->message_context, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, + vkd3d_shader_error(&context->message_context, NULL, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY, "Out of memory while writing root signature."); return VKD3D_ERROR_OUT_OF_MEMORY; } @@ -3247,7 +3247,7 @@ static int validate_descriptor_table_v_1_0(const struct vkd3d_shader_root_descri else { WARN("Invalid descriptor range type %#x.\n", r->range_type); - vkd3d_shader_error(message_context, VKD3D_SHADER_ERROR_RS_INVALID_DESCRIPTOR_RANGE_TYPE, + vkd3d_shader_error(message_context, NULL, VKD3D_SHADER_ERROR_RS_INVALID_DESCRIPTOR_RANGE_TYPE, "Invalid root signature descriptor range type %#x.", r->range_type); return VKD3D_ERROR_INVALID_ARGUMENT; } @@ -3256,7 +3256,7 @@ static int validate_descriptor_table_v_1_0(const struct vkd3d_shader_root_descri if (have_srv_uav_cbv && have_sampler) { WARN("Samplers cannot be mixed with CBVs/SRVs/UAVs in descriptor tables.\n"); - vkd3d_shader_error(message_context, VKD3D_SHADER_ERROR_RS_MIXED_DESCRIPTOR_RANGE_TYPES, + vkd3d_shader_error(message_context, NULL, VKD3D_SHADER_ERROR_RS_MIXED_DESCRIPTOR_RANGE_TYPES, "Encountered both CBV/SRV/UAV and sampler descriptor ranges in the same root descriptor table."); return VKD3D_ERROR_INVALID_ARGUMENT; } @@ -3288,7 +3288,7 @@ static int validate_descriptor_table_v_1_1(const struct vkd3d_shader_root_descri else { WARN("Invalid descriptor range type %#x.\n", r->range_type); - vkd3d_shader_error(message_context, VKD3D_SHADER_ERROR_RS_INVALID_DESCRIPTOR_RANGE_TYPE, + vkd3d_shader_error(message_context, NULL, VKD3D_SHADER_ERROR_RS_INVALID_DESCRIPTOR_RANGE_TYPE, "Invalid root signature descriptor range type %#x.", r->range_type); return VKD3D_ERROR_INVALID_ARGUMENT; } @@ -3297,7 +3297,7 @@ static int validate_descriptor_table_v_1_1(const struct vkd3d_shader_root_descri if (have_srv_uav_cbv && have_sampler) { WARN("Samplers cannot be mixed with CBVs/SRVs/UAVs in descriptor tables.\n"); - vkd3d_shader_error(message_context, VKD3D_SHADER_ERROR_RS_MIXED_DESCRIPTOR_RANGE_TYPES, + vkd3d_shader_error(message_context, NULL, VKD3D_SHADER_ERROR_RS_MIXED_DESCRIPTOR_RANGE_TYPES, "Encountered both CBV/SRV/UAV and sampler descriptor ranges in the same root descriptor table."); return VKD3D_ERROR_INVALID_ARGUMENT; } @@ -3345,14 +3345,14 @@ int vkd3d_shader_serialize_root_signature(const struct vkd3d_shader_versioned_ro *messages = NULL;
memset(&context, 0, sizeof(context)); - vkd3d_shader_message_context_init(&context.message_context, VKD3D_SHADER_LOG_INFO, NULL); + vkd3d_shader_message_context_init(&context.message_context, VKD3D_SHADER_LOG_INFO);
if (root_signature->version != VKD3D_SHADER_ROOT_SIGNATURE_VERSION_1_0 && root_signature->version != VKD3D_SHADER_ROOT_SIGNATURE_VERSION_1_1) { ret = VKD3D_ERROR_INVALID_ARGUMENT; WARN("Root signature version %#x not supported.\n", root_signature->version); - vkd3d_shader_error(&context.message_context, VKD3D_SHADER_ERROR_RS_INVALID_VERSION, + vkd3d_shader_error(&context.message_context, NULL, VKD3D_SHADER_ERROR_RS_INVALID_VERSION, "Root signature version %#x is not supported.", root_signature->version); goto done; } diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index cb9c7a12..61d0d472 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -2155,6 +2155,7 @@ struct vkd3d_dxbc_compiler struct vkd3d_spirv_builder spirv_builder;
struct vkd3d_shader_message_context *message_context; + struct vkd3d_shader_location location; bool failed;
bool strip_debug; @@ -2245,6 +2246,8 @@ struct vkd3d_dxbc_compiler *vkd3d_dxbc_compiler_create(const struct vkd3d_shader
memset(compiler, 0, sizeof(*compiler)); compiler->message_context = message_context; + compiler->location.source_name = compile_info->source_name; + compiler->location.line = 2; /* Line 1 is the version token. */
if ((target_info = vkd3d_find_struct(compile_info->next, SPIRV_TARGET_INFO))) { @@ -2452,7 +2455,7 @@ static void VKD3D_PRINTF_FUNC(3, 4) vkd3d_dxbc_compiler_error(struct vkd3d_dxbc_ va_list args;
va_start(args, format); - vkd3d_shader_verror(compiler->message_context, error, format, args); + vkd3d_shader_verror(compiler->message_context, &compiler->location, error, format, args); va_end(args); compiler->failed = true; } @@ -9194,6 +9197,7 @@ int vkd3d_dxbc_compiler_handle_instruction(struct vkd3d_dxbc_compiler *compiler, FIXME("Unhandled instruction %#x.\n", instruction->handler_idx); }
+ ++compiler->location.line; return ret; }
diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index 2ea233bb..53e22789 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -108,13 +108,9 @@ void vkd3d_string_buffer_trace_(const struct vkd3d_string_buffer *buffer, const }
void vkd3d_shader_message_context_init(struct vkd3d_shader_message_context *context, - enum vkd3d_shader_log_level log_level, const char *source_name) + enum vkd3d_shader_log_level log_level) { context->log_level = log_level; - context->source_name = source_name ? source_name : "<anonymous>"; - context->line = 0; - context->column = 0; - vkd3d_string_buffer_init(&context->messages); }
@@ -148,28 +144,28 @@ bool vkd3d_shader_message_context_copy_messages(struct vkd3d_shader_message_cont return true; }
-void vkd3d_shader_verror(struct vkd3d_shader_message_context *context, +void vkd3d_shader_verror(struct vkd3d_shader_message_context *context, const struct vkd3d_shader_location *location, enum vkd3d_shader_error error, const char *format, va_list args) { if (context->log_level < VKD3D_SHADER_LOG_ERROR) return;
- if (context->line) + if (location) vkd3d_string_buffer_printf(&context->messages, "%s:%u:%u: E%04u: ", - context->source_name, context->line, context->column, error); + location->source_name ? location->source_name : "<anonymous>", location->line, location->column, error); else - vkd3d_string_buffer_printf(&context->messages, "%s: E%04u: ", context->source_name, error); + vkd3d_string_buffer_printf(&context->messages, "E%04u: ", error); vkd3d_string_buffer_vprintf(&context->messages, format, args); vkd3d_string_buffer_printf(&context->messages, "\n"); }
-void vkd3d_shader_error(struct vkd3d_shader_message_context *context, +void vkd3d_shader_error(struct vkd3d_shader_message_context *context, const struct vkd3d_shader_location *location, enum vkd3d_shader_error error, const char *format, ...) { va_list args;
va_start(args, format); - vkd3d_shader_verror(context, error, format, args); + vkd3d_shader_verror(context, location, error, format, args); va_end(args); }
@@ -307,6 +303,7 @@ struct vkd3d_shader_scan_context size_t descriptors_size;
struct vkd3d_shader_message_context *message_context; + struct vkd3d_shader_location location;
struct vkd3d_shader_cf_info { @@ -332,12 +329,15 @@ struct vkd3d_shader_scan_context };
static void vkd3d_shader_scan_context_init(struct vkd3d_shader_scan_context *context, + const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_scan_descriptor_info *scan_descriptor_info, struct vkd3d_shader_message_context *message_context) { memset(context, 0, sizeof(*context)); context->scan_descriptor_info = scan_descriptor_info; context->message_context = message_context; + context->location.source_name = compile_info->source_name; + context->location.line = 2; /* Line 1 is the version token. */ }
static void vkd3d_shader_scan_context_cleanup(struct vkd3d_shader_scan_context *context) @@ -606,7 +606,7 @@ static void vkd3d_shader_scan_error(struct vkd3d_shader_scan_context *context, va_list args;
va_start(args, format); - vkd3d_shader_verror(context->message_context, error, format, args); + vkd3d_shader_verror(context->message_context, &context->location, error, format, args); va_end(args); }
@@ -774,6 +774,7 @@ static int vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *conte if (vkd3d_shader_instruction_is_uav_counter(instruction)) vkd3d_shader_scan_record_uav_counter(context, &instruction->src[0].reg);
+ ++context->location.line; return VKD3D_OK; }
@@ -792,7 +793,7 @@ static int scan_dxbc(const struct vkd3d_shader_compile_info *compile_info, scan_descriptor_info->descriptor_count = 0; }
- vkd3d_shader_scan_context_init(&context, scan_descriptor_info, message_context); + vkd3d_shader_scan_context_init(&context, compile_info, scan_descriptor_info, message_context);
if ((ret = vkd3d_shader_parser_init(&parser, &compile_info->source, message_context)) < 0) { @@ -803,8 +804,6 @@ static int scan_dxbc(const struct vkd3d_shader_compile_info *compile_info, if (TRACE_ON()) vkd3d_shader_trace(parser.data);
- message_context->line = 2; /* Line 1 is the version token. */ - message_context->column = 1; while (!shader_sm4_is_end(parser.data, &parser.ptr)) { shader_sm4_read_instruction(parser.data, &parser.ptr, &instruction); @@ -824,7 +823,6 @@ static int scan_dxbc(const struct vkd3d_shader_compile_info *compile_info, vkd3d_shader_free_scan_descriptor_info(scan_descriptor_info); goto done; } - ++message_context->line; }
ret = VKD3D_OK; @@ -848,7 +846,7 @@ int vkd3d_shader_scan(const struct vkd3d_shader_compile_info *compile_info, char if ((ret = vkd3d_shader_validate_compile_info(compile_info, true)) < 0) return ret;
- vkd3d_shader_message_context_init(&message_context, compile_info->log_level, compile_info->source_name); + vkd3d_shader_message_context_init(&message_context, compile_info->log_level);
ret = scan_dxbc(compile_info, &message_context);
@@ -902,8 +900,6 @@ static int compile_dxbc_tpf(const struct vkd3d_shader_compile_info *compile_info return VKD3D_ERROR; }
- message_context->line = 2; /* Line 1 is the version token. */ - message_context->column = 1; while (!shader_sm4_is_end(parser.data, &parser.ptr)) { shader_sm4_read_instruction(parser.data, &parser.ptr, &instruction); @@ -917,7 +913,6 @@ static int compile_dxbc_tpf(const struct vkd3d_shader_compile_info *compile_info
if ((ret = vkd3d_dxbc_compiler_handle_instruction(spirv_compiler, &instruction)) < 0) break; - ++message_context->line; }
if (ret >= 0) @@ -949,7 +944,7 @@ int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info, if ((ret = vkd3d_shader_validate_compile_info(compile_info, true)) < 0) return ret;
- vkd3d_shader_message_context_init(&message_context, compile_info->log_level, compile_info->source_name); + vkd3d_shader_message_context_init(&message_context, compile_info->log_level);
switch (compile_info->source_type) { @@ -1051,7 +1046,7 @@ int vkd3d_shader_parse_input_signature(const struct vkd3d_shader_code *dxbc,
if (messages) *messages = NULL; - vkd3d_shader_message_context_init(&message_context, VKD3D_SHADER_LOG_INFO, NULL); + vkd3d_shader_message_context_init(&message_context, VKD3D_SHADER_LOG_INFO);
ret = shader_parse_input_signature(dxbc->code, dxbc->size, &message_context, signature); vkd3d_shader_message_context_trace_messages(&message_context); @@ -1174,7 +1169,7 @@ int vkd3d_shader_preprocess(const struct vkd3d_shader_compile_info *compile_info if ((ret = vkd3d_shader_validate_compile_info(compile_info, false)) < 0) return ret;
- vkd3d_shader_message_context_init(&message_context, compile_info->log_level, compile_info->source_name); + vkd3d_shader_message_context_init(&message_context, compile_info->log_level);
ret = preproc_lexer_parse(compile_info, out, &message_context);
diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index 83038384..7b0e0fc0 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -844,11 +844,15 @@ int vkd3d_string_buffer_printf(struct vkd3d_string_buffer *buffer, void vkd3d_string_buffer_trace_(const struct vkd3d_string_buffer *buffer, const char *function) 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 +struct vkd3d_shader_location { - enum vkd3d_shader_log_level log_level; const char *source_name; unsigned int line, column; +}; + +struct vkd3d_shader_message_context +{ + enum vkd3d_shader_log_level log_level; struct vkd3d_string_buffer messages; };
@@ -856,14 +860,14 @@ void vkd3d_shader_message_context_cleanup(struct vkd3d_shader_message_context *c bool vkd3d_shader_message_context_copy_messages(struct vkd3d_shader_message_context *context, char **out) DECLSPEC_HIDDEN; void vkd3d_shader_message_context_init(struct vkd3d_shader_message_context *context, - enum vkd3d_shader_log_level log_level, const char *source_name) DECLSPEC_HIDDEN; + enum vkd3d_shader_log_level log_level) DECLSPEC_HIDDEN; void vkd3d_shader_message_context_trace_messages_(const struct vkd3d_shader_message_context *context, const char *function) DECLSPEC_HIDDEN; #define vkd3d_shader_message_context_trace_messages(context) \ vkd3d_shader_message_context_trace_messages_(context, __FUNCTION__) -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; -void vkd3d_shader_verror(struct vkd3d_shader_message_context *context, +void vkd3d_shader_error(struct vkd3d_shader_message_context *context, const struct vkd3d_shader_location *location, + enum vkd3d_shader_error error, const char *format, ...) VKD3D_PRINTF_FUNC(4, 5) DECLSPEC_HIDDEN; +void vkd3d_shader_verror(struct vkd3d_shader_message_context *context, const struct vkd3d_shader_location *location, enum vkd3d_shader_error error, const char *format, va_list args) DECLSPEC_HIDDEN;
int shader_extract_from_dxbc(const void *dxbc, size_t dxbc_length,
On Tue, 15 Dec 2020 at 08:19, Zebediah Figura zfigura@codeweavers.com wrote:
Includes a slight change in behaviour: parse_dxbc() and vkd3d_shader_serialize_root_signature() now print nothing instead of "<anonymous>".
It does a bit more than that. E.g., before this patch:
$ vkd3d-compiler -b d3d-asm invalid.dxbc invalid.dxbc: E0003: Invalid DXBC checksum. Failed to compile shader, ret -3.
After this patch, parse_dxbc() doesn't print source names at all.