diff --git a/src/compiler/spirv/nir_spirv.h b/src/compiler/spirv/nir_spirv.h index 348a6b82c9e..2d85194efae 100644 --- a/src/compiler/spirv/nir_spirv.h +++ b/src/compiler/spirv/nir_spirv.h @@ -90,6 +90,9 @@ struct spirv_to_nir_options { /* Whether or not printf is supported */ bool printf; + /* Whether or not the driver wants consume debug information (Debugging purposes). */ + bool debug_info; + const struct spirv_capabilities *capabilities; /* Address format for various kinds of pointers. */ diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index 4e0f461c827..1af86e9c69d 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -745,10 +745,6 @@ const uint32_t * vtn_foreach_instruction(struct vtn_builder *b, const uint32_t *start, const uint32_t *end, vtn_instruction_handler handler) { - b->file = NULL; - b->line = -1; - b->col = -1; - const uint32_t *w = start; while (w < end) { SpvOp opcode = w[0] & SpvOpCodeMask; @@ -782,11 +778,6 @@ vtn_foreach_instruction(struct vtn_builder *b, const uint32_t *start, w += count; } - b->spirv_offset = 0; - b->file = NULL; - b->line = -1; - b->col = -1; - assert(w == end); return w; } @@ -6096,6 +6087,34 @@ static bool vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode, const uint32_t *w, unsigned count) { + if (b->options->debug_info) { + nir_debug_info_instr *instr = + nir_debug_info_instr_create(b->shader, nir_debug_info_src_loc, 0); + instr->src_loc.spirv_offset = b->spirv_offset; + instr->src_loc.source = nir_debug_info_spirv; + + if (b->file) { + nir_def *filename; + struct hash_entry *he = _mesa_hash_table_search(b->strings, b->file); + if (he) { + filename = he->data; + } else { + nir_builder _b = nir_builder_at(nir_before_cf_list(&b->nb.impl->body)); + filename = nir_build_string(&_b, b->file); + _mesa_hash_table_insert(b->strings, b->file, filename); + } + + instr->src_loc.filename = nir_src_for_ssa(filename); + /* Make sure line is at least 1 since 0 is reserved for spirv_offset-only + * source locations. + */ + instr->src_loc.line = MAX2(b->line, 1); + instr->src_loc.column = b->col; + } + + nir_builder_instr_insert(&b->nb, &instr->instr); + } + switch (opcode) { case SpvOpLabel: break; @@ -6717,6 +6736,9 @@ vtn_create_builder(const uint32_t *words, size_t word_count, if (b->options->environment == NIR_SPIRV_VULKAN && b->version < 0x10400) b->vars_used_indirectly = _mesa_pointer_set_create(b); + if (b->options->debug_info) + b->strings = _mesa_pointer_hash_table_create(b); + return b; fail: ralloc_free(b); @@ -6933,6 +6955,7 @@ spirv_to_nir(const uint32_t *words, size_t word_count, progress = false; vtn_foreach_function(func, &b->functions) { if ((options->create_library || func->referenced) && !func->emitted) { + _mesa_hash_table_clear(b->strings, NULL); vtn_function_emit(b, func, vtn_handle_body_instruction); progress = true; } diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h index d9c22b5140d..098f946cba5 100644 --- a/src/compiler/spirv/vtn_private.h +++ b/src/compiler/spirv/vtn_private.h @@ -699,6 +699,8 @@ struct vtn_builder { struct vtn_function *func; struct list_head functions; + struct hash_table *strings; + /* Current function parameter index */ unsigned func_param_idx;