anv/pipeline: Capture serialized NIR

This allows the serialized NIR to be displayed in RenderDoc and similar
tools.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
This commit is contained in:
Jason Ekstrand 2019-10-09 13:21:21 -05:00
parent b2f6fda542
commit c7e5d24d8f
2 changed files with 33 additions and 0 deletions

View file

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

View file

@ -2820,6 +2820,7 @@ struct anv_pipeline_executable {
struct brw_compile_stats stats;
char *nir;
char *disasm;
};