mesa/glspirv: Add struct gl_spirv_module
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Sat, 10 Jun 2017 18:14:44 +0000 (20:14 +0200)
committerEduardo Lima Mitev <elima@igalia.com>
Tue, 12 Dec 2017 07:18:32 +0000 (08:18 +0100)
v2: * Make the SPIR-V module struct part of a larger gl_shader_spirv_data
    struct that will be introduced later, and don't reference it directly
    in gl_shader. (Eduardo Lima)
    * Readability improvements (Ian Romanick)

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/main/glspirv.c
src/mesa/main/glspirv.h

index 3989f42..d4832db 100644 (file)
 
 #include "errors.h"
 
+#include "util/u_atomic.h"
+
+void
+_mesa_spirv_module_reference(struct gl_spirv_module **dest,
+                             struct gl_spirv_module *src)
+{
+   struct gl_spirv_module *old = *dest;
+
+   if (old && p_atomic_dec_zero(&old->RefCount))
+      free(old);
+
+   *dest = src;
+
+   if (src)
+      p_atomic_inc(&src->RefCount);
+}
+
 void GLAPIENTRY
 _mesa_SpecializeShaderARB(GLuint shader,
                           const GLchar *pEntryPoint,
index 1de8871..4e03373 100644 (file)
@@ -31,6 +31,22 @@ extern "C" {
 #endif
 
 /**
+ * A SPIR-V module contains the raw SPIR-V binary as set by ShaderBinary.
+ *
+ * It is reference-counted, because the same module can be attached to multiple
+ * shader objects simultaneously.
+ */
+struct gl_spirv_module {
+   unsigned RefCount;
+   GLint Length;
+   char Binary[0];
+};
+
+void
+_mesa_spirv_module_reference(struct gl_spirv_module **dest,
+                             struct gl_spirv_module *src);
+
+/**
  * \name API functions
  */
 /*@{*/