spirv: Emit nir_debug_info_instr for OpLine

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18903>
This commit is contained in:
Konstantin Seurer 2024-05-19 17:31:49 +02:00 committed by Marge Bot
parent ce24486ee4
commit 4423c50c1b
3 changed files with 37 additions and 9 deletions

View file

@ -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. */

View file

@ -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;
}

View file

@ -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;