anv/pipeline: Capture serialized NIR
authorJason Ekstrand <jason@jlekstrand.net>
Wed, 9 Oct 2019 18:21:21 +0000 (13:21 -0500)
committerJason Ekstrand <jason@jlekstrand.net>
Wed, 9 Oct 2019 22:28:01 +0000 (22:28 +0000)
This allows the serialized NIR to be displayed in RenderDoc and similar
tools.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
src/intel/vulkan/anv_pipeline.c
src/intel/vulkan/anv_private.h

index 14343260882d0e60137bf0f7023c220746d7c93a..5460bcca01a85820a15346e1c367373056357c3b 100644 (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");
index ab35f12797022c9deeed65c893ac3e4142a88898..3aa6d1922f955c88682900c47467aa95c8ffb20a 100644 (file)
@@ -2820,6 +2820,7 @@ struct anv_pipeline_executable {
 
    struct brw_compile_stats stats;
 
+   char *nir;
    char *disasm;
 };