[Mesa-dev] [PATCH 05/23] i965: Add brw_program_deserialize_nir

Timothy Arceri tarceri at itsqueeze.com
Wed Nov 29 01:24:41 UTC 2017


From: Jordan Justen <jordan.l.justen at intel.com>

Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
---
 src/mesa/drivers/dri/i965/brw_disk_cache.c | 31 ++++++++----------------------
 src/mesa/drivers/dri/i965/brw_program.c    | 16 +++++++++++++++
 src/mesa/drivers/dri/i965/brw_program.h    |  4 ++++
 3 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_disk_cache.c b/src/mesa/drivers/dri/i965/brw_disk_cache.c
index 853ea98af03..65bb52726eb 100644
--- a/src/mesa/drivers/dri/i965/brw_disk_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_disk_cache.c
@@ -17,21 +17,20 @@
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  * IN THE SOFTWARE.
  */
 
 #include "compiler/blob.h"
 #include "compiler/glsl/ir_uniform.h"
 #include "compiler/glsl/shader_cache.h"
-#include "compiler/nir/nir_serialize.h"
 #include "main/mtypes.h"
 #include "util/build_id.h"
 #include "util/debug.h"
 #include "util/disk_cache.h"
 #include "util/macros.h"
 #include "util/mesa-sha1.h"
 
 #include "brw_context.h"
 #include "brw_program.h"
 #include "brw_cs.h"
@@ -54,41 +53,20 @@ gen_shader_sha1(struct brw_context *brw, struct gl_program *prog,
 
    _mesa_sha1_compute(key, brw_prog_key_size(stage), sha1);
    _mesa_sha1_format(sha1_buf, sha1);
    offset += snprintf(manifest + offset, sizeof(manifest) - offset,
                       "%s_key: %s\n", _mesa_shader_stage_to_abbrev(stage),
                       sha1_buf);
 
    _mesa_sha1_compute(manifest, strlen(manifest), out_sha1);
 }
 
-static void
-restore_serialized_nir_shader(struct brw_context *brw, struct gl_program *prog,
-                              gl_shader_stage stage)
-{
-   prog->program_written_to_cache = false;
-   if (brw->ctx._Shader->Flags & GLSL_CACHE_INFO) {
-      fprintf(stderr, "falling back to nir %s.\n",
-              _mesa_shader_stage_to_abbrev(prog->info.stage));
-   }
-
-   if (!prog->nir) {
-      assert(prog->driver_cache_blob && prog->driver_cache_blob_size > 0);
-      const struct nir_shader_compiler_options *options =
-         brw->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);
-   }
-}
-
 static void
 write_blob_program_data(struct blob *binary, gl_shader_stage stage,
                         const void *program,
                         struct brw_stage_prog_data *prog_data)
 {
    /* Write prog_data to blob. */
    blob_write_bytes(binary, prog_data, brw_prog_data_size(stage));
 
    /* Write program to blob. */
    blob_write_bytes(binary, program, prog_data->program_size);
@@ -291,21 +269,28 @@ brw_disk_cache_upload_program(struct brw_context *brw, gl_shader_stage stage)
    if (!read_and_upload(brw, cache, prog, stage))
       goto fail;
 
    if (brw->ctx._Shader->Flags & GLSL_CACHE_INFO) {
       fprintf(stderr, "read gen program from cache\n");
    }
 
    return true;
 
 fail:
-   restore_serialized_nir_shader(brw, prog, stage);
+   prog->program_written_to_cache = false;
+   if (brw->ctx._Shader->Flags & GLSL_CACHE_INFO) {
+      fprintf(stderr, "falling back to nir %s.\n",
+              _mesa_shader_stage_to_abbrev(prog->info.stage));
+   }
+
+   brw_program_deserialize_nir(&brw->ctx, prog, stage);
+
    return false;
 }
 
 static void
 write_program_data(struct brw_context *brw, struct gl_program *prog,
                    void *key, struct brw_stage_prog_data *prog_data,
                    uint32_t prog_offset, struct disk_cache *cache,
                    gl_shader_stage stage)
 {
    struct blob binary;
diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c
index 755d4973cc0..2a647cdd734 100644
--- a/src/mesa/drivers/dri/i965/brw_program.c
+++ b/src/mesa/drivers/dri/i965/brw_program.c
@@ -33,20 +33,21 @@
 #include "main/imports.h"
 #include "program/prog_parameter.h"
 #include "program/prog_print.h"
 #include "program/prog_to_nir.h"
 #include "program/program.h"
 #include "program/programopt.h"
 #include "tnl/tnl.h"
 #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"
 #include "compiler/brw_nir.h"
 #include "brw_defines.h"
 #include "intel_batchbuffer.h"
 
 static bool
 brw_nir_lower_uniforms(nir_shader *nir, bool is_scalar)
 {
@@ -778,10 +779,25 @@ brw_assign_common_binding_table_offsets(const struct gen_device_info *devinfo,
    next_binding_table_offset += num_textures;
 
    stage_prog_data->binding_table.plane_start[2] = next_binding_table_offset;
    next_binding_table_offset += num_textures;
 
    /* prog_data->base.binding_table.size will be set by brw_mark_surface_used. */
 
    assert(next_binding_table_offset <= BRW_MAX_SURFACES);
    return next_binding_table_offset;
 }
+
+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);
+   }
+}
diff --git a/src/mesa/drivers/dri/i965/brw_program.h b/src/mesa/drivers/dri/i965/brw_program.h
index 701b8da482e..bd9b4ad168a 100644
--- a/src/mesa/drivers/dri/i965/brw_program.h
+++ b/src/mesa/drivers/dri/i965/brw_program.h
@@ -74,20 +74,24 @@ void brw_populate_sampler_prog_key_data(struct gl_context *ctx,
 bool brw_debug_recompile_sampler_key(struct brw_context *brw,
                                      const struct brw_sampler_prog_key_data *old_key,
                                      const struct brw_sampler_prog_key_data *key);
 
 uint32_t
 brw_assign_common_binding_table_offsets(const struct gen_device_info *devinfo,
                                         const struct gl_program *prog,
                                         struct brw_stage_prog_data *stage_prog_data,
                                         uint32_t next_binding_table_offset);
 
+void
+brw_program_deserialize_nir(struct gl_context *ctx, struct gl_program *prog,
+                            gl_shader_stage stage);
+
 void
 brw_stage_prog_data_free(const void *prog_data);
 
 void
 brw_dump_arb_asm(const char *stage, struct gl_program *prog);
 
 bool brw_vs_precompile(struct gl_context *ctx, struct gl_program *prog);
 bool brw_tcs_precompile(struct gl_context *ctx,
                         struct gl_shader_program *shader_prog,
                         struct gl_program *prog);
-- 
2.14.3



More information about the mesa-dev mailing list