From c7e5d24d8f5281a85d9f6646e4d7601f947d6f7d Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 9 Oct 2019 13:21:21 -0500 Subject: [PATCH] anv/pipeline: Capture serialized NIR This allows the serialized NIR to be displayed in RenderDoc and similar tools. Reviewed-by: Lionel Landwerlin --- src/intel/vulkan/anv_pipeline.c | 32 ++++++++++++++++++++++++++++++++ src/intel/vulkan/anv_private.h | 1 + 2 files changed, 33 insertions(+) diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c index 14343260882..5460bcca01a 100644 --- a/src/intel/vulkan/anv_pipeline.c +++ b/src/intel/vulkan/anv_pipeline.c @@ -1073,6 +1073,26 @@ anv_pipeline_add_executable(struct anv_pipeline *pipeline, struct brw_compile_stats *stats, uint32_t code_offset) { + char *nir = NULL; + if (stage->nir && + (pipeline->flags & + VK_PIPELINE_CREATE_CAPTURE_INTERNAL_REPRESENTATIONS_BIT_KHR)) { + char *stream_data = NULL; + size_t stream_size = 0; + FILE *stream = open_memstream(&stream_data, &stream_size); + + nir_print_shader(stage->nir, stream); + + fclose(stream); + + /* Copy it to a ralloc'd thing */ + nir = ralloc_size(pipeline->mem_ctx, stream_size + 1); + memcpy(nir, stream_data, stream_size); + nir[stream_size] = 0; + + free(stream_data); + } + char *disasm = NULL; if (stage->code && (pipeline->flags & @@ -1102,6 +1122,7 @@ anv_pipeline_add_executable(struct anv_pipeline *pipeline, (struct anv_pipeline_executable) { .stage = stage->stage, .stats = *stats, + .nir = nir, .disasm = disasm, }; } @@ -2166,6 +2187,17 @@ VkResult anv_GetPipelineExecutableInternalRepresentationsKHR( const struct anv_pipeline_executable *exe = &pipeline->executables[pExecutableInfo->executableIndex]; + if (exe->nir) { + vk_outarray_append(&out, ir) { + WRITE_STR(ir->name, "Final NIR"); + WRITE_STR(ir->description, + "Final NIR before going into the back-end compiler"); + + if (!write_ir_text(ir, exe->nir)) + incomplete_text = true; + } + } + if (exe->disasm) { vk_outarray_append(&out, ir) { WRITE_STR(ir->name, "GEN Assembly"); diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index ab35f127970..3aa6d1922f9 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -2820,6 +2820,7 @@ struct anv_pipeline_executable { struct brw_compile_stats stats; + char *nir; char *disasm; }; -- 2.30.2