mesa: create new gl_shader_program_data struct
authorTimothy Arceri <timothy.arceri@collabora.com>
Mon, 7 Nov 2016 03:43:48 +0000 (14:43 +1100)
committerTimothy Arceri <timothy.arceri@collabora.com>
Sat, 19 Nov 2016 04:45:46 +0000 (15:45 +1100)
This will be used to share data between gl_program and gl_shader_program
allowing for greater code simplification as we can remove a number of
awkward uses of gl_shader_program.

Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
src/mesa/main/mtypes.h
src/mesa/main/shaderobj.c
src/mesa/main/shaderobj.h

index 440bbb4b7627e039c31db4f10948a38a52a79600..aa4d1d5e8f02d2663a4393f9e908b97cc3fb0d66 100644 (file)
@@ -2624,6 +2624,31 @@ struct gl_program_resource
    uint8_t StageReferences; /** Bitmask of shader stage references. */
 };
 
+/**
+ * A data structure to be shared by gl_shader_program and gl_program.
+ */
+struct gl_shader_program_data
+{
+   GLint RefCount;  /**< Reference count */
+
+   unsigned NumUniformStorage;
+   unsigned NumHiddenUniforms;
+   struct gl_uniform_storage *UniformStorage;
+
+   unsigned NumUniformBlocks;
+   struct gl_uniform_block *UniformBlocks;
+
+   unsigned NumShaderStorageBlocks;
+   struct gl_uniform_block *ShaderStorageBlocks;
+
+   struct gl_active_atomic_buffer *AtomicBuffers;
+   unsigned NumAtomicBuffers;
+
+   GLboolean LinkStatus;   /**< GL_LINK_STATUS */
+   GLboolean Validated;
+   GLchar *InfoLog;
+};
+
 /**
  * A GLSL program object.
  * Basically a linked collection of vertex and fragment shaders.
index 8fd574e5121d01569fa2f2fa575f15b9f7944122..fe0b45f57e8d5e35ef34e510e177e7343664b68a 100644 (file)
@@ -41,6 +41,7 @@
 #include "program/prog_parameter.h"
 #include "util/ralloc.h"
 #include "util/string_to_uint_map.h"
+#include "util/u_atomic.h"
 
 /**********************************************************************/
 /*** Shader object functions                                        ***/
@@ -208,6 +209,33 @@ _mesa_lookup_shader_err(struct gl_context *ctx, GLuint name, const char *caller)
 /**********************************************************************/
 
 
+void
+_mesa_reference_shader_program_data(struct gl_context *ctx,
+                                    struct gl_shader_program_data **ptr,
+                                    struct gl_shader_program_data *data)
+{
+   if (*ptr == data)
+      return;
+
+   if (*ptr) {
+      struct gl_shader_program_data *oldData = *ptr;
+
+      assert(oldData->RefCount > 0);
+
+      if (p_atomic_dec_zero(&oldData->RefCount)) {
+         assert(ctx);
+         ralloc_free(oldData);
+      }
+
+      *ptr = NULL;
+   }
+
+   if (data)
+      p_atomic_inc(&data->RefCount);
+
+   *ptr = data;
+}
+
 /**
  * Set ptr to point to shProg.
  * If ptr is pointing to another object, decrement its refcount (and delete
@@ -249,6 +277,17 @@ _mesa_reference_shader_program_(struct gl_context *ctx,
    }
 }
 
+static struct gl_shader_program_data *
+create_shader_program_data()
+{
+   struct gl_shader_program_data *data;
+   data = rzalloc(NULL, struct gl_shader_program_data);
+   if (data)
+      data->RefCount = 1;
+
+   return data;
+}
+
 static void
 init_shader_program(struct gl_shader_program *prog)
 {
index 12497328f986328b28c84b9f0f85361f85003760..c5153d09ba40349ce4760df23dfc1ad6a0a0b348 100644 (file)
@@ -66,6 +66,11 @@ _mesa_reference_shader_program_(struct gl_context *ctx,
                                struct gl_shader_program **ptr,
                                struct gl_shader_program *shProg);
 
+void
+_mesa_reference_shader_program_data(struct gl_context *ctx,
+                                    struct gl_shader_program_data **ptr,
+                                    struct gl_shader_program_data *data);
+
 static inline void
 _mesa_reference_shader_program(struct gl_context *ctx,
                                struct gl_shader_program **ptr,