glsl: lower mediump temporaries to 16 bits except structures (v2)
[mesa.git] / src / mesa / main / externalobjects.c
index 8b5ecb2cd8a871a0ca39908497d022abe9e76336..777a5dd5acd0c799a570106a1be590d476347bd1 100644 (file)
 
 #include "macros.h"
 #include "mtypes.h"
+#include "bufferobj.h"
+#include "context.h"
 #include "externalobjects.h"
 #include "teximage.h"
 #include "texobj.h"
 #include "glformats.h"
 #include "texstorage.h"
+#include "util/u_memory.h"
 
 /**
  * Allocate and initialize a new memory object.  But don't put it into the
@@ -667,12 +670,32 @@ _mesa_IsSemaphoreEXT(GLuint semaphore)
    return obj ? GL_TRUE : GL_FALSE;
 }
 
+/**
+ * Helper that outputs the correct error status for parameter
+ * calls where no pnames are defined
+ */
+static void
+semaphore_parameter_stub(const char* func, GLenum pname)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (!ctx->Extensions.EXT_semaphore) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
+      return;
+   }
+
+   /* EXT_semaphore and EXT_semaphore_fd define no parameters */
+   _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", func, pname);
+}
+
 void GLAPIENTRY
 _mesa_SemaphoreParameterui64vEXT(GLuint semaphore,
                                  GLenum pname,
                                  const GLuint64 *params)
 {
+   const char *func = "glSemaphoreParameterui64vEXT";
 
+   semaphore_parameter_stub(func, pname);
 }
 
 void GLAPIENTRY
@@ -680,7 +703,9 @@ _mesa_GetSemaphoreParameterui64vEXT(GLuint semaphore,
                                     GLenum pname,
                                     GLuint64 *params)
 {
+   const char *func = "glGetSemaphoreParameterui64vEXT";
 
+   semaphore_parameter_stub(func, pname);
 }
 
 void GLAPIENTRY
@@ -691,7 +716,56 @@ _mesa_WaitSemaphoreEXT(GLuint semaphore,
                        const GLuint *textures,
                        const GLenum *srcLayouts)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_semaphore_object *semObj = NULL;
+   struct gl_buffer_object **bufObjs = NULL;
+   struct gl_texture_object **texObjs = NULL;
+
+   const char *func = "glWaitSemaphoreEXT";
+
+   if (!ctx->Extensions.EXT_semaphore) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
+      return;
+   }
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   semObj = _mesa_lookup_semaphore_object(ctx, semaphore);
+   if (!semObj)
+      return;
+
+   FLUSH_VERTICES(ctx, 0);
+
+   bufObjs = malloc(sizeof(struct gl_buffer_object *) * numBufferBarriers);
+   if (!bufObjs) {
+      _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(numBufferBarriers=%u)",
+                  func, numBufferBarriers);
+      goto end;
+   }
 
+   for (unsigned i = 0; i < numBufferBarriers; i++) {
+      bufObjs[i] = _mesa_lookup_bufferobj(ctx, buffers[i]);
+   }
+
+   texObjs = malloc(sizeof(struct gl_texture_object *) * numTextureBarriers);
+   if (!texObjs) {
+      _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(numTextureBarriers=%u)",
+                  func, numTextureBarriers);
+      goto end;
+   }
+
+   for (unsigned i = 0; i < numTextureBarriers; i++) {
+      texObjs[i] = _mesa_lookup_texture(ctx, textures[i]);
+   }
+
+   ctx->Driver.ServerWaitSemaphoreObject(ctx, semObj,
+                                         numBufferBarriers, bufObjs,
+                                         numTextureBarriers, texObjs,
+                                         srcLayouts);
+
+end:
+   free(bufObjs);
+   free(texObjs);
 }
 
 void GLAPIENTRY
@@ -702,7 +776,56 @@ _mesa_SignalSemaphoreEXT(GLuint semaphore,
                          const GLuint *textures,
                          const GLenum *dstLayouts)
 {
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_semaphore_object *semObj = NULL;
+   struct gl_buffer_object **bufObjs = NULL;
+   struct gl_texture_object **texObjs = NULL;
+
+   const char *func = "glSignalSemaphoreEXT";
+
+   if (!ctx->Extensions.EXT_semaphore) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
+      return;
+   }
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   semObj = _mesa_lookup_semaphore_object(ctx, semaphore);
+   if (!semObj)
+      return;
+
+   FLUSH_VERTICES(ctx, 0);
+
+   bufObjs = malloc(sizeof(struct gl_buffer_object *) * numBufferBarriers);
+   if (!bufObjs) {
+      _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(numBufferBarriers=%u)",
+                  func, numBufferBarriers);
+      goto end;
+   }
+
+   for (unsigned i = 0; i < numBufferBarriers; i++) {
+      bufObjs[i] = _mesa_lookup_bufferobj(ctx, buffers[i]);
+   }
+
+   texObjs = malloc(sizeof(struct gl_texture_object *) * numTextureBarriers);
+   if (!texObjs) {
+      _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(numTextureBarriers=%u)",
+                  func, numTextureBarriers);
+      goto end;
+   }
+
+   for (unsigned i = 0; i < numTextureBarriers; i++) {
+      texObjs[i] = _mesa_lookup_texture(ctx, textures[i]);
+   }
+
+   ctx->Driver.ServerSignalSemaphoreObject(ctx, semObj,
+                                           numBufferBarriers, bufObjs,
+                                           numTextureBarriers, texObjs,
+                                           dstLayouts);
 
+end:
+   free(bufObjs);
+   free(texObjs);
 }
 
 void GLAPIENTRY
@@ -721,7 +844,7 @@ _mesa_ImportMemoryFdEXT(GLuint memory,
    }
 
    if (handleType != GL_HANDLE_TYPE_OPAQUE_FD_EXT) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "%s(handleType=%u)", func, handleType);
+      _mesa_error(ctx, GL_INVALID_ENUM, "%s(handleType=%u)", func, handleType);
       return;
    }
 
@@ -748,7 +871,7 @@ _mesa_ImportSemaphoreFdEXT(GLuint semaphore,
    }
 
    if (handleType != GL_HANDLE_TYPE_OPAQUE_FD_EXT) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "%s(handleType=%u)", func, handleType);
+      _mesa_error(ctx, GL_INVALID_ENUM, "%s(handleType=%u)", func, handleType);
       return;
    }