iris: Add support for serialized NIR
authorJason Ekstrand <jason@jlekstrand.net>
Tue, 11 Aug 2020 00:05:56 +0000 (19:05 -0500)
committerMarge Bot <eric+marge@anholt.net>
Wed, 12 Aug 2020 10:11:06 +0000 (10:11 +0000)
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6280>

src/gallium/drivers/iris/iris_program.c
src/gallium/drivers/iris/iris_screen.c

index a9e464bcb465005879e9e46f7b421ab4016deb49..f38afc5726d9b7d0a886ff8d0765d50efb201cfc 100644 (file)
@@ -2376,12 +2376,31 @@ static void *
 iris_create_compute_state(struct pipe_context *ctx,
                           const struct pipe_compute_state *state)
 {
-   assert(state->ir_type == PIPE_SHADER_IR_NIR);
-
    struct iris_context *ice = (void *) ctx;
    struct iris_screen *screen = (void *) ctx->screen;
+   const nir_shader_compiler_options *options =
+      screen->compiler->glsl_compiler_options[MESA_SHADER_COMPUTE].NirOptions;
+
+   nir_shader *nir;
+   switch (state->ir_type) {
+   case PIPE_SHADER_IR_NIR:
+      nir = (void *)state->prog;
+      break;
+
+   case PIPE_SHADER_IR_NIR_SERIALIZED: {
+      struct blob_reader reader;
+      const struct pipe_binary_program_header *hdr = state->prog;
+      blob_reader_init(&reader, hdr->blob, hdr->num_bytes);
+      nir = nir_deserialize(NULL, options, &reader);
+      break;
+   }
+
+   default:
+      unreachable("Unsupported IR");
+   }
+
    struct iris_uncompiled_shader *ish =
-      iris_create_uncompiled_shader(ctx, (void *) state->prog, NULL);
+      iris_create_uncompiled_shader(ctx, nir, NULL);
 
    // XXX: disallow more than 64KB of shared variables
 
index ca75a1308ddf0f13826e118575bc8f7c17fd1044..c30626c132cf3e739355d4e15545d92fffabad7e 100644 (file)
@@ -422,7 +422,8 @@ iris_get_shader_param(struct pipe_screen *pscreen,
    case PIPE_SHADER_CAP_PREFERRED_IR:
       return PIPE_SHADER_IR_NIR;
    case PIPE_SHADER_CAP_SUPPORTED_IRS:
-      return 1 << PIPE_SHADER_IR_NIR;
+      return (1 << PIPE_SHADER_IR_NIR) |
+             (1 << PIPE_SHADER_IR_NIR_SERIALIZED);
    case PIPE_SHADER_CAP_TGSI_DROUND_SUPPORTED:
    case PIPE_SHADER_CAP_TGSI_LDEXP_SUPPORTED:
       return 1;