Mesa (master): mesa/glspirv: Add struct gl_shader_spirv_data

Eduardo Lima Mitev elima at kemper.freedesktop.org
Tue Dec 12 13:05:44 UTC 2017


Module: Mesa
Branch: master
Commit: a8889f5cc7129c1f8942248d620f64b4496e8f35
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a8889f5cc7129c1f8942248d620f64b4496e8f35

Author: Eduardo Lima Mitev <elima at igalia.com>
Date:   Mon Nov 13 13:57:46 2017 +0100

mesa/glspirv: Add struct gl_shader_spirv_data

This is a per-shader structure holding the SPIR-V data associated with the
shader (binary module, specialization constants and entry-point).

This is needed because both gl_shader and gl_linked_shader need to share this
data. Instead of copying the data, we pass a reference to it upon program
linking. That's why it is reference-counted.

This struct is created and associated with the shader upon calling
glShaderBinary(), then subsequently filled up by the call to
glSpecializeShaderARB().

v2: Readability improvements (Ian Romanick)

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

---

 src/mesa/main/glspirv.c | 17 +++++++++++++++++
 src/mesa/main/glspirv.h | 25 +++++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/src/mesa/main/glspirv.c b/src/mesa/main/glspirv.c
index d4832db549..8d1e652e08 100644
--- a/src/mesa/main/glspirv.c
+++ b/src/mesa/main/glspirv.c
@@ -42,6 +42,23 @@ _mesa_spirv_module_reference(struct gl_spirv_module **dest,
       p_atomic_inc(&src->RefCount);
 }
 
+void
+_mesa_shader_spirv_data_reference(struct gl_shader_spirv_data **dest,
+                                  struct gl_shader_spirv_data *src)
+{
+   struct gl_shader_spirv_data *old = *dest;
+
+   if (old && p_atomic_dec_zero(&old->RefCount)) {
+      _mesa_spirv_module_reference(&(*dest)->SpirVModule, NULL);
+      ralloc_free(old);
+   }
+
+   *dest = src;
+
+   if (src)
+      p_atomic_inc(&src->RefCount);
+}
+
 void GLAPIENTRY
 _mesa_SpecializeShaderARB(GLuint shader,
                           const GLchar *pEntryPoint,
diff --git a/src/mesa/main/glspirv.h b/src/mesa/main/glspirv.h
index 4e033735cf..b8a0125ea9 100644
--- a/src/mesa/main/glspirv.h
+++ b/src/mesa/main/glspirv.h
@@ -42,10 +42,35 @@ struct gl_spirv_module {
    char Binary[0];
 };
 
+/**
+ * SPIR-V data needed to compile and link a SPIR-V shader.
+ *
+ * It includes a SPIR-V binary that is potentially shared among different
+ * shaders; and shader-specific specialization constants and entry point.
+ *
+ * It is reference-counted because it is shared between gl_shader and its
+ * corresponding gl_linked_shader.
+ */
+struct gl_shader_spirv_data {
+   GLint RefCount;
+
+   struct gl_spirv_module *SpirVModule;
+
+   GLchar *SpirVEntryPoint;
+
+   GLuint NumSpecializationConstants;
+   GLuint *SpecializationConstantsIndex;
+   GLuint *SpecializationConstantsValue;
+};
+
 void
 _mesa_spirv_module_reference(struct gl_spirv_module **dest,
                              struct gl_spirv_module *src);
 
+void
+_mesa_shader_spirv_data_reference(struct gl_shader_spirv_data **dest,
+                                  struct gl_shader_spirv_data *src);
+
 /**
  * \name API functions
  */




More information about the mesa-commit mailing list