LGTM

Reviewed-by: Tapani Pälli <tapani.pa...@intel.com>

On 11/29/2017 03:24 AM, Timothy Arceri wrote:
From: Jordan Justen <jordan.l.jus...@intel.com>

This resolves an apparent game bug described in 85564. The game
doesn't properly handle ARB_get_program_binary with 0 supported
formats.

V2 (Timothy Arceri):
  - less driver code as more has been moved into the common helpers.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=85564
Signed-off-by: Timothy Arceri <tarc...@itsqueeze.com>
Signed-off-by: Jordan Justen <jordan.l.jus...@intel.com> (v1)
---
  src/mesa/drivers/dri/i965/Makefile.sources     |  1 +
  src/mesa/drivers/dri/i965/brw_context.c        | 10 ++++
  src/mesa/drivers/dri/i965/brw_context.h        | 16 ++++++
  src/mesa/drivers/dri/i965/brw_program.h        |  7 ---
  src/mesa/drivers/dri/i965/brw_program_binary.c | 72 ++++++++++++++++++++++++++
  src/mesa/drivers/dri/i965/meson.build          |  1 +
  6 files changed, 100 insertions(+), 7 deletions(-)
  create mode 100644 src/mesa/drivers/dri/i965/brw_program_binary.c

diff --git a/src/mesa/drivers/dri/i965/Makefile.sources 
b/src/mesa/drivers/dri/i965/Makefile.sources
index 2980cdb3c54..3fba8dc17ef 100644
--- a/src/mesa/drivers/dri/i965/Makefile.sources
+++ b/src/mesa/drivers/dri/i965/Makefile.sources
@@ -30,20 +30,21 @@ i965_FILES = \
        brw_meta_util.h \
        brw_misc_state.c \
        brw_multisample_state.h \
        brw_nir_uniforms.cpp \
        brw_object_purgeable.c \
        brw_pipe_control.c \
        brw_performance_query.h \
        brw_performance_query.c \
        brw_program.c \
        brw_program.h \
+       brw_program_binary.c \
        brw_program_cache.c \
        brw_primitive_restart.c \
        brw_queryobj.c \
        brw_reset.c \
        brw_sf.c \
        brw_state.h \
        brw_state_upload.c \
        brw_structs.h \
        brw_surface_formats.c \
        brw_sync.c \
diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
b/src/mesa/drivers/dri/i965/brw_context.c
index dd55b436698..5cd759f7356 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -322,20 +322,27 @@ brw_init_driver_functions(struct brw_context *brw,
        functions->BeginTransformFeedback = brw_begin_transform_feedback;
        functions->EndTransformFeedback = brw_end_transform_feedback;
        functions->PauseTransformFeedback = brw_pause_transform_feedback;
        functions->ResumeTransformFeedback = brw_resume_transform_feedback;
        functions->GetTransformFeedbackVertexCount =
           brw_get_transform_feedback_vertex_count;
     }
if (devinfo->gen >= 6)
        functions->GetSamplePosition = gen6_get_sample_position;
+
+   /* GL_ARB_get_program_binary */
+   brw_program_binary_init(brw->screen->deviceID);
+   functions->GetProgramBinaryDriverSHA1 = brw_get_program_binary_driver_sha1;
+   functions->ProgramBinarySerializeDriverBlob = brw_program_serialize_nir;
+   functions->ProgramBinaryDeserializeDriverBlob =
+      brw_deserialize_program_binary;
  }
static void
  brw_initialize_context_constants(struct brw_context *brw)
  {
     const struct gen_device_info *devinfo = &brw->screen->devinfo;
     struct gl_context *ctx = &brw->ctx;
     const struct brw_compiler *compiler = brw->screen->compiler;
const bool stage_exists[MESA_SHADER_STAGES] = {
@@ -689,20 +696,23 @@ brw_initialize_context_constants(struct brw_context *brw)
      * pull an entire cache line at a time for constant offset loads both of
      * which support almost any alignment.
      *
      * [1] glsl-1.40/uniform_buffer/vs-float-array-variable-index.shader_test
      */
     if (devinfo->gen >= 7)
        ctx->Const.UseSTD430AsDefaultPacking = true;
if (!(ctx->Const.ContextFlags & GL_CONTEXT_FLAG_DEBUG_BIT))
        ctx->Const.AllowMappedBuffersDuringExecution = true;
+
+   /* GL_ARB_get_program_binary */
+   ctx->Const.NumProgramBinaryFormats = 1;
  }
static void
  brw_initialize_cs_context_constants(struct brw_context *brw)
  {
     struct gl_context *ctx = &brw->ctx;
     const struct intel_screen *screen = brw->screen;
     struct gen_device_info *devinfo = &brw->screen->devinfo;
/* FINISHME: Do this for all platforms that the kernel supports */
diff --git a/src/mesa/drivers/dri/i965/brw_context.h 
b/src/mesa/drivers/dri/i965/brw_context.h
index b3d7c6baf8a..da88bea739e 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1539,20 +1539,36 @@ gen7_upload_urb(struct brw_context *brw, unsigned 
vs_size,
  /* brw_reset.c */
  extern GLenum
  brw_get_graphics_reset_status(struct gl_context *ctx);
  void
  brw_check_for_reset(struct brw_context *brw);
/* brw_compute.c */
  extern void
  brw_init_compute_functions(struct dd_function_table *functions);
+/* brw_program_binary.c */
+extern void
+brw_program_binary_init(unsigned device_id);
+extern void
+brw_get_program_binary_driver_sha1(struct gl_context *ctx, uint8_t *sha1);
+extern void
+brw_deserialize_program_binary(struct gl_context *ctx,
+                               struct gl_shader_program *shProg,
+                               struct gl_program *prog);
+void
+brw_program_serialize_nir(struct gl_context *ctx, struct gl_program *prog,
+                          gl_shader_stage stage);
+void
+brw_program_deserialize_nir(struct gl_context *ctx, struct gl_program *prog,
+                            gl_shader_stage stage);
+
  /*======================================================================
   * Inline conversion functions.  These are better-typed than the
   * macros used previously:
   */
  static inline struct brw_context *
  brw_context( struct gl_context *ctx )
  {
     return (struct brw_context *)ctx;
  }
diff --git a/src/mesa/drivers/dri/i965/brw_program.h b/src/mesa/drivers/dri/i965/brw_program.h
index a5e41522841..701b8da482e 100644
--- a/src/mesa/drivers/dri/i965/brw_program.h
+++ b/src/mesa/drivers/dri/i965/brw_program.h
@@ -74,27 +74,20 @@ 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_serialize_nir(struct gl_context *ctx, struct gl_program *prog,
-                          gl_shader_stage stage);
-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);
diff --git a/src/mesa/drivers/dri/i965/brw_program_binary.c 
b/src/mesa/drivers/dri/i965/brw_program_binary.c
new file mode 100644
index 00000000000..f1b327de4b3
--- /dev/null
+++ b/src/mesa/drivers/dri/i965/brw_program_binary.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * 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 <stdint.h>
+
+#include "util/build_id.h"
+#include "util/mesa-sha1.h"
+
+#include "brw_context.h"
+#include "brw_program.h"
+
+static uint8_t driver_sha1[20];
+
+void
+brw_program_binary_init(unsigned device_id)
+{
+   const struct build_id_note *note =
+      build_id_find_nhdr_for_addr(brw_program_binary_init);
+   assert(note);
+
+   /**
+    * With Mesa's megadrivers, taking the sha1 of i965_dri.so may not be
+    * unique. Therefore, we make a sha1 of the "i965" string and the sha1
+    * build id from i965_dri.so.
+    */
+   struct mesa_sha1 ctx;
+   _mesa_sha1_init(&ctx);
+   char renderer[10];
+   assert(device_id < 0x10000);
+   int len = snprintf(renderer, sizeof(renderer), "i965_%04x", device_id);
+   assert(len == sizeof(renderer) - 1);
+   _mesa_sha1_update(&ctx, renderer, len);
+   _mesa_sha1_update(&ctx, build_id_data(note), build_id_length(note));
+   _mesa_sha1_final(&ctx, driver_sha1);
+}
+
+void
+brw_get_program_binary_driver_sha1(struct gl_context *ctx, uint8_t *sha1)
+{
+   memcpy(sha1, driver_sha1, sizeof(uint8_t) * 20);
+}
+
+/* This is just a wrapper around brw_program_deserialize_nir() as i965
+ * doesn't need gl_shader_program like other drivers do.
+ */
+void
+brw_deserialize_program_binary(struct gl_context *ctx,
+                               struct gl_shader_program *shProg,
+                               struct gl_program *prog)
+{
+   brw_program_deserialize_nir(ctx, prog, prog->info.stage);
+}
diff --git a/src/mesa/drivers/dri/i965/meson.build 
b/src/mesa/drivers/dri/i965/meson.build
index 09e1179adc4..5d8b983a154 100644
--- a/src/mesa/drivers/dri/i965/meson.build
+++ b/src/mesa/drivers/dri/i965/meson.build
@@ -50,20 +50,21 @@ files_i965 = files(
    'brw_meta_util.h',
    'brw_misc_state.c',
    'brw_multisample_state.h',
    'brw_nir_uniforms.cpp',
    'brw_object_purgeable.c',
    'brw_pipe_control.c',
    'brw_performance_query.h',
    'brw_performance_query.c',
    'brw_program.c',
    'brw_program.h',
+  'brw_program_binary.c',
    'brw_program_cache.c',
    'brw_primitive_restart.c',
    'brw_queryobj.c',
    'brw_reset.c',
    'brw_sf.c',
    'brw_state.h',
    'brw_state_upload.c',
    'brw_structs.h',
    'brw_surface_formats.c',
    'brw_sync.c',

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to