glsl/shader_cache: Save and restore serialized nir in gl_program
authorJordan Justen <jordan.l.justen@intel.com>
Fri, 13 Oct 2017 20:02:29 +0000 (13:02 -0700)
committerJordan Justen <jordan.l.justen@intel.com>
Wed, 1 Nov 2017 06:36:54 +0000 (23:36 -0700)
v3:
 * Rename serialized_nir* to driver_cache_blob*. (Tim)

Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/glsl/shader_cache.cpp

index ca90cfde350e37d039e40b5b313c622579d0a85b..1d208fb091176b4a4cf7a3528c3f06dc96d3e893 100644 (file)
@@ -1062,6 +1062,14 @@ write_shader_metadata(struct blob *metadata, gl_linked_shader *shader)
    }
 
    write_shader_parameters(metadata, glprog->Parameters);
+
+   assert((glprog->driver_cache_blob == NULL) ==
+          (glprog->driver_cache_blob_size == 0));
+   blob_write_uint32(metadata, (uint32_t)glprog->driver_cache_blob_size);
+   if (glprog->driver_cache_blob_size > 0) {
+      blob_write_bytes(metadata, glprog->driver_cache_blob,
+                       glprog->driver_cache_blob_size);
+   }
 }
 
 static void
@@ -1116,6 +1124,14 @@ read_shader_metadata(struct blob_reader *metadata,
 
    glprog->Parameters = _mesa_new_parameter_list();
    read_shader_parameters(metadata, glprog->Parameters);
+
+   glprog->driver_cache_blob_size = (size_t)blob_read_uint32(metadata);
+   if (glprog->driver_cache_blob_size > 0) {
+      glprog->driver_cache_blob =
+         (uint8_t*)ralloc_size(glprog, glprog->driver_cache_blob_size);
+      blob_copy_bytes(metadata, glprog->driver_cache_blob,
+                      glprog->driver_cache_blob_size);
+   }
 }
 
 static void