glsl/linker: add DisableTransformFeedbackPacking workaround
[mesa.git] / src / mesa / main / transformfeedback.c
index b79b41d35ef7f71b2d7d0fd3d877015748745fe2..06719b1ce827dda23a6c777607c809abf3008534 100644 (file)
@@ -39,8 +39,8 @@
 #include "transformfeedback.h"
 #include "shaderapi.h"
 #include "shaderobj.h"
-#include "main/dispatch.h"
 
+#include "program/program.h"
 #include "program/prog_parameter.h"
 
 struct using_program_tuple
@@ -198,6 +198,27 @@ _mesa_init_transform_feedback_object(struct gl_transform_feedback_object *obj,
    obj->EverBound = GL_FALSE;
 }
 
+/**
+ * Delete a transform feedback object.  Called via
+ * ctx->Driver->DeleteTransformFeedback, if not overwritten by driver.  In
+ * the latter case, called from the driver after all driver-specific clean-up
+ * has been done.
+ *
+ * \param ctx GL context to wich transform feedback object belongs.
+ * \param obj Transform feedback object due to be deleted.
+ */
+void
+_mesa_delete_transform_feedback_object(struct gl_context *ctx,
+                                       struct gl_transform_feedback_object
+                                              *obj)
+{
+   for (unsigned i = 0; i < ARRAY_SIZE(obj->Buffers); i++) {
+      _mesa_reference_buffer_object(ctx, &obj->Buffers[i], NULL);
+   }
+
+   free(obj->Label);
+   free(obj);
+}
 
 /** Default fallback for ctx->Driver.NewTransformFeedback() */
 static struct gl_transform_feedback_object *
@@ -213,22 +234,6 @@ new_transform_feedback_fallback(struct gl_context *ctx, GLuint name)
    return obj;
 }
 
-/** Default fallback for ctx->Driver.DeleteTransformFeedback() */
-static void
-delete_transform_feedback_fallback(struct gl_context *ctx,
-                                   struct gl_transform_feedback_object *obj)
-{
-   GLuint i;
-
-   for (i = 0; i < ARRAY_SIZE(obj->Buffers); i++) {
-      _mesa_reference_buffer_object(ctx, &obj->Buffers[i], NULL);
-   }
-
-   free(obj->Label);
-   free(obj);
-}
-
-
 /** Default fallback for ctx->Driver.BeginTransformFeedback() */
 static void
 begin_transform_feedback_fallback(struct gl_context *ctx, GLenum mode,
@@ -270,7 +275,7 @@ void
 _mesa_init_transform_feedback_functions(struct dd_function_table *driver)
 {
    driver->NewTransformFeedback = new_transform_feedback_fallback;
-   driver->DeleteTransformFeedback = delete_transform_feedback_fallback;
+   driver->DeleteTransformFeedback = _mesa_delete_transform_feedback_object;
    driver->BeginTransformFeedback = begin_transform_feedback_fallback;
    driver->EndTransformFeedback = end_transform_feedback_fallback;
    driver->PauseTransformFeedback = pause_transform_feedback_fallback;
@@ -346,7 +351,7 @@ _mesa_compute_max_transform_feedback_vertices(struct gl_context *ctx,
 
          /* Skip any inactive buffers, which have a stride of 0. */
          if (stride == 0)
-           continue;
+            continue;
 
          max_for_this_buffer = obj->Size[i] / (4 * stride);
          max_index = MIN2(max_index, max_for_this_buffer);
@@ -471,6 +476,7 @@ begin_transform_feedback(struct gl_context *ctx, GLenum mode, bool no_error)
 
    if (obj->program != source) {
       ctx->NewDriverState |= ctx->DriverFlags.NewTransformFeedbackProg;
+      _mesa_reference_program_(ctx, &obj->program, source);
       obj->program = source;
    }
 
@@ -505,6 +511,7 @@ end_transform_feedback(struct gl_context *ctx,
    assert(ctx->Driver.EndTransformFeedback);
    ctx->Driver.EndTransformFeedback(ctx, obj);
 
+   _mesa_reference_program_(ctx, &obj->program, NULL);
    ctx->TransformFeedback.CurrentObject->Active = GL_FALSE;
    ctx->TransformFeedback.CurrentObject->Paused = GL_FALSE;
    ctx->TransformFeedback.CurrentObject->EndedAnytime = GL_TRUE;
@@ -605,7 +612,7 @@ _mesa_validate_buffer_range_xfb(struct gl_context *ctx,
       _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d must be a multiple of "
                   "four)", gl_methd_name, (int) size);
       return false;
-   }  
+   }
 
    if (offset & 0x3) {
       /* OpenGL 4.5 core profile, 6.7, pdf page 103: multiple of 4 */
@@ -732,13 +739,13 @@ _mesa_TransformFeedbackBufferBase(GLuint xfb, GLuint index, GLuint buffer)
 
    obj = lookup_transform_feedback_object_err(ctx, xfb,
                                               "glTransformFeedbackBufferBase");
-   if(!obj) {
+   if (!obj) {
       return;
    }
 
    bufObj = lookup_transform_feedback_bufferobj_err(ctx, buffer,
                                               "glTransformFeedbackBufferBase");
-   if(!bufObj) {
+   if (!bufObj) {
       return;
    }
 
@@ -755,13 +762,13 @@ _mesa_TransformFeedbackBufferRange(GLuint xfb, GLuint index, GLuint buffer,
 
    obj = lookup_transform_feedback_object_err(ctx, xfb,
                                               "glTransformFeedbackBufferRange");
-   if(!obj) {
+   if (!obj) {
       return;
    }
 
    bufObj = lookup_transform_feedback_bufferobj_err(ctx, buffer,
                                               "glTransformFeedbackBufferRange");
-   if(!bufObj) {
+   if (!bufObj) {
       return;
    }
 
@@ -779,12 +786,43 @@ _mesa_TransformFeedbackBufferRange(GLuint xfb, GLuint index, GLuint buffer,
  * offset in the buffer to start placing results.
  * This function is part of GL_EXT_transform_feedback, but not GL3.
  */
+static ALWAYS_INLINE void
+bind_buffer_offset(struct gl_context *ctx,
+                   struct gl_transform_feedback_object *obj, GLuint index,
+                   GLuint buffer, GLintptr offset, bool no_error)
+{
+   struct gl_buffer_object *bufObj;
+
+   if (buffer == 0) {
+      bufObj = ctx->Shared->NullBufferObj;
+   } else {
+      bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+      if (!no_error && !bufObj) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glBindBufferOffsetEXT(invalid buffer=%u)", buffer);
+         return;
+      }
+   }
+
+   _mesa_bind_buffer_range_xfb(ctx, obj, index, bufObj, offset, 0);
+}
+
+
+void GLAPIENTRY
+_mesa_BindBufferOffsetEXT_no_error(GLenum target, GLuint index, GLuint buffer,
+                                   GLintptr offset)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   bind_buffer_offset(ctx, ctx->TransformFeedback.CurrentObject, index, buffer,
+                      offset, true);
+}
+
+
 void GLAPIENTRY
 _mesa_BindBufferOffsetEXT(GLenum target, GLuint index, GLuint buffer,
                           GLintptr offset)
 {
    struct gl_transform_feedback_object *obj;
-   struct gl_buffer_object *bufObj;
    GET_CURRENT_CONTEXT(ctx);
 
    if (target != GL_TRANSFORM_FEEDBACK_BUFFER) {
@@ -813,18 +851,7 @@ _mesa_BindBufferOffsetEXT(GLenum target, GLuint index, GLuint buffer,
       return;
    }
 
-   if (buffer == 0) {
-      bufObj = ctx->Shared->NullBufferObj;
-   } else {
-      bufObj = _mesa_lookup_bufferobj(ctx, buffer);
-      if (!bufObj) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glBindBufferOffsetEXT(invalid buffer=%u)", buffer);
-         return;
-      }
-   }
-
-   _mesa_bind_buffer_range_xfb(ctx, obj, index, bufObj, offset, 0);
+   bind_buffer_offset(ctx, obj, index, buffer, offset, false);
 }
 
 
@@ -1317,7 +1344,7 @@ _mesa_GetTransformFeedbackiv(GLuint xfb, GLenum pname, GLint *param)
 
     obj = lookup_transform_feedback_object_err(ctx, xfb,
                                                "glGetTransformFeedbackiv");
-    if(!obj) {
+    if (!obj) {
        return;
     }
 
@@ -1343,7 +1370,7 @@ _mesa_GetTransformFeedbacki_v(GLuint xfb, GLenum pname, GLuint index,
 
    obj = lookup_transform_feedback_object_err(ctx, xfb,
                                               "glGetTransformFeedbacki_v");
-   if(!obj) {
+   if (!obj) {
       return;
    }
 
@@ -1372,7 +1399,7 @@ _mesa_GetTransformFeedbacki64_v(GLuint xfb, GLenum pname, GLuint index,
 
    obj = lookup_transform_feedback_object_err(ctx, xfb,
                                               "glGetTransformFeedbacki64_v");
-   if(!obj) {
+   if (!obj) {
       return;
    }
 
@@ -1382,12 +1409,34 @@ _mesa_GetTransformFeedbacki64_v(GLuint xfb, GLenum pname, GLuint index,
       return;
    }
 
+   /**
+    * This follows the same general rules used for BindBufferBase:
+    *
+    *   "To query the starting offset or size of the range of a buffer
+    *    object binding in an indexed array, call GetInteger64i_v with
+    *    target set to respectively the starting offset or binding size
+    *    name from table 6.5 for that array. Index must be in the range
+    *    zero to the number of bind points supported minus one. If the
+    *    starting offset or size was not specified when the buffer object
+    *    was bound (e.g. if it was bound with BindBufferBase), or if no
+    *    buffer object is bound to the target array at index, zero is
+    *    returned."
+    */
+   if (obj->RequestedSize[index] == 0 &&
+       (pname == GL_TRANSFORM_FEEDBACK_BUFFER_START ||
+        pname == GL_TRANSFORM_FEEDBACK_BUFFER_SIZE)) {
+      *param = 0;
+      return;
+   }
+
    compute_transform_feedback_buffer_sizes(obj);
    switch(pname) {
    case GL_TRANSFORM_FEEDBACK_BUFFER_START:
+      assert(obj->RequestedSize[index] > 0);
       *param = obj->Offset[index];
       break;
    case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
+      assert(obj->RequestedSize[index] > 0);
       *param = obj->Size[index];
       break;
    default: