i965: Move brw_program_*serialize_nir to brw_program_binary.c

This will allow get_program_binary to add the gen program into its
serialization in addition to just the nir program.

Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
This commit is contained in:
Jordan Justen 2018-02-28 01:39:27 -08:00
parent cce3994dee
commit f4c154afc1
No known key found for this signature in database
GPG key ID: 37F99F68CAF992EB
2 changed files with 37 additions and 37 deletions

View file

@ -41,7 +41,6 @@
#include "util/ralloc.h"
#include "compiler/glsl/ir.h"
#include "compiler/glsl/glsl_to_nir.h"
#include "compiler/nir/nir_serialize.h"
#include "brw_program.h"
#include "brw_context.h"
@ -839,39 +838,3 @@ brw_assign_common_binding_table_offsets(const struct gen_device_info *devinfo,
assert(next_binding_table_offset <= BRW_MAX_SURFACES);
return next_binding_table_offset;
}
void
brw_program_serialize_nir(struct gl_context *ctx, struct gl_program *prog)
{
if (prog->driver_cache_blob)
return;
struct blob writer;
blob_init(&writer);
nir_serialize(&writer, prog->nir);
prog->driver_cache_blob = ralloc_size(NULL, writer.size);
memcpy(prog->driver_cache_blob, writer.data, writer.size);
prog->driver_cache_blob_size = writer.size;
blob_finish(&writer);
}
void
brw_program_deserialize_nir(struct gl_context *ctx, struct gl_program *prog,
gl_shader_stage stage)
{
if (!prog->nir) {
assert(prog->driver_cache_blob && prog->driver_cache_blob_size > 0);
const struct nir_shader_compiler_options *options =
ctx->Const.ShaderCompilerOptions[stage].NirOptions;
struct blob_reader reader;
blob_reader_init(&reader, prog->driver_cache_blob,
prog->driver_cache_blob_size);
prog->nir = nir_deserialize(NULL, options, &reader);
}
if (prog->driver_cache_blob) {
ralloc_free(prog->driver_cache_blob);
prog->driver_cache_blob = NULL;
prog->driver_cache_blob_size = 0;
}
}

View file

@ -23,6 +23,7 @@
#include <stdint.h>
#include "compiler/nir/nir_serialize.h"
#include "util/build_id.h"
#include "util/mesa-sha1.h"
@ -60,6 +61,42 @@ brw_get_program_binary_driver_sha1(struct gl_context *ctx, uint8_t *sha1)
memcpy(sha1, driver_sha1, sizeof(uint8_t) * 20);
}
void
brw_program_serialize_nir(struct gl_context *ctx, struct gl_program *prog)
{
if (prog->driver_cache_blob)
return;
struct blob writer;
blob_init(&writer);
nir_serialize(&writer, prog->nir);
prog->driver_cache_blob = ralloc_size(NULL, writer.size);
memcpy(prog->driver_cache_blob, writer.data, writer.size);
prog->driver_cache_blob_size = writer.size;
blob_finish(&writer);
}
void
brw_program_deserialize_nir(struct gl_context *ctx, struct gl_program *prog,
gl_shader_stage stage)
{
if (!prog->nir) {
assert(prog->driver_cache_blob && prog->driver_cache_blob_size > 0);
const struct nir_shader_compiler_options *options =
ctx->Const.ShaderCompilerOptions[stage].NirOptions;
struct blob_reader reader;
blob_reader_init(&reader, prog->driver_cache_blob,
prog->driver_cache_blob_size);
prog->nir = nir_deserialize(NULL, options, &reader);
}
if (prog->driver_cache_blob) {
ralloc_free(prog->driver_cache_blob);
prog->driver_cache_blob = NULL;
prog->driver_cache_blob_size = 0;
}
}
/* This is just a wrapper around brw_program_deserialize_nir() as i965
* doesn't need gl_shader_program like other drivers do.
*/