nir: add nir_shader_as_str function
It would be later used by Turnip in implementation of VK_KHR_pipeline_executable_properties. Signed-off-by: Danylo Piliaiev <dpiliaiev@igalia.com> Reviewed-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com> Reviewed-by: Connor Abbott <cwabbott0@gmail.com> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8877>
This commit is contained in:

committed by
Marge Bot

parent
616394cf31
commit
2bff8fd53b
@@ -4062,6 +4062,8 @@ void nir_print_shader_annotated(nir_shader *shader, FILE *fp, struct hash_table
|
||||
void nir_print_instr(const nir_instr *instr, FILE *fp);
|
||||
void nir_print_deref(const nir_deref_instr *deref, FILE *fp);
|
||||
|
||||
char *nir_shader_as_str(nir_shader *nir, void *mem_ctx);
|
||||
|
||||
/** Shallow clone of a single instruction. */
|
||||
nir_instr *nir_instr_clone(nir_shader *s, const nir_instr *orig);
|
||||
|
||||
|
@@ -28,6 +28,7 @@
|
||||
#include "nir.h"
|
||||
#include "compiler/shader_enums.h"
|
||||
#include "util/half_float.h"
|
||||
#include "util/memstream.h"
|
||||
#include "vulkan/vulkan_core.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -1669,6 +1670,27 @@ nir_print_shader(nir_shader *shader, FILE *fp)
|
||||
fflush(fp);
|
||||
}
|
||||
|
||||
char *
|
||||
nir_shader_as_str(nir_shader *nir, void *mem_ctx)
|
||||
{
|
||||
char *stream_data = NULL;
|
||||
size_t stream_size = 0;
|
||||
struct u_memstream mem;
|
||||
if (u_memstream_open(&mem, &stream_data, &stream_size)) {
|
||||
FILE *const stream = u_memstream_get(&mem);
|
||||
nir_print_shader(nir, stream);
|
||||
u_memstream_close(&mem);
|
||||
}
|
||||
|
||||
char *str = ralloc_size(mem_ctx, stream_size + 1);
|
||||
memcpy(str, stream_data, stream_size);
|
||||
str[stream_size] = '\0';
|
||||
|
||||
free(stream_data);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
void
|
||||
nir_print_instr(const nir_instr *instr, FILE *fp)
|
||||
{
|
||||
|
@@ -1092,20 +1092,7 @@ anv_pipeline_add_executable(struct anv_pipeline *pipeline,
|
||||
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);
|
||||
nir = nir_shader_as_str(stage->nir, pipeline->mem_ctx);
|
||||
}
|
||||
|
||||
char *disasm = NULL;
|
||||
|
Reference in New Issue
Block a user