mesa: Implement glMemoryBarrierByRegion
authorMarta Lofstedt <marta.lofstedt@intel.com>
Fri, 14 Aug 2015 11:30:45 +0000 (13:30 +0200)
committerTapani Pälli <tapani.palli@intel.com>
Mon, 17 Aug 2015 05:25:04 +0000 (08:25 +0300)
The function glMemoryBarrierByRegion is part of OpenGL ES 3.1
and OpenGL 4.5 core and compatibility profiles.

Signed-off-by: Marta Lofstedt <marta.lofstedt@intel.com>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
src/mapi/glapi/gen/GL4x.xml
src/mesa/main/shaderimage.c
src/mesa/main/shaderimage.h
src/mesa/main/tests/dispatch_sanity.cpp

index 94ddfb7296078d8d9b8e5d7d762f50a7f9ab38e9..dee50275a578ce77edc71b89f2ec7c354b706533 100644 (file)
   <enum name="DEPTH_STENCIL_TEXTURE_MODE"              value="0x90EA"/>
 </category>
 
+<category name="4.5">
+  <function name="MemoryBarrierByRegion" es2="3.1">
+    <param name="barriers" type="GLbitfield"/>
+  </function>
+</category>
+
 </OpenGLAPI>
index a348cdb04058840698dff09c1394ae1f0aa5f829..7337f2255c43705a07060481d89f3a13ef88abe0 100644 (file)
@@ -653,3 +653,43 @@ _mesa_MemoryBarrier(GLbitfield barriers)
    if (ctx->Driver.MemoryBarrier)
       ctx->Driver.MemoryBarrier(ctx, barriers);
 }
+
+void GLAPIENTRY
+_mesa_MemoryBarrierByRegion(GLbitfield barriers)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   GLbitfield all_allowed_bits = GL_ATOMIC_COUNTER_BARRIER_BIT |
+                                 GL_FRAMEBUFFER_BARRIER_BIT |
+                                 GL_SHADER_IMAGE_ACCESS_BARRIER_BIT |
+                                 GL_SHADER_STORAGE_BARRIER_BIT |
+                                 GL_TEXTURE_FETCH_BARRIER_BIT |
+                                 GL_UNIFORM_BARRIER_BIT;
+
+   if (ctx->Driver.MemoryBarrier) {
+      /* From section 7.11.2 of the OpenGL ES 3.1 specification:
+       *
+       *    "When barriers is ALL_BARRIER_BITS, shader memory accesses will be
+       *     synchronized relative to all these barrier bits, but not to other
+       *     barrier bits specific to MemoryBarrier."
+       *
+       * That is, if barriers is the special value GL_ALL_BARRIER_BITS, then all
+       * barriers allowed by glMemoryBarrierByRegion should be activated."
+       */
+      if (barriers == GL_ALL_BARRIER_BITS)
+         return ctx->Driver.MemoryBarrier(ctx, all_allowed_bits);
+
+      /* From section 7.11.2 of the OpenGL ES 3.1 specification:
+       *
+       *    "An INVALID_VALUE error is generated if barriers is not the special
+       *     value ALL_BARRIER_BITS, and has any bits set other than those
+       *     described above."
+       */
+      if ((barriers & ~all_allowed_bits) != 0) {
+         _mesa_error(ctx, GL_INVALID_VALUE,
+                     "glMemoryBarrierByRegion(unsupported barrier bit");
+      }
+
+      ctx->Driver.MemoryBarrier(ctx, barriers);
+   }
+}
index 33d8a1eff5516c71cad4d34edc83937b9a1961aa..d08ece81f11d735f4d65cf2669e1117589daa470 100644 (file)
@@ -68,6 +68,9 @@ _mesa_BindImageTextures(GLuint first, GLsizei count, const GLuint *textures);
 void GLAPIENTRY
 _mesa_MemoryBarrier(GLbitfield barriers);
 
+void GLAPIENTRY
+_mesa_MemoryBarrierByRegion(GLbitfield barriers);
+
 #ifdef __cplusplus
 }
 #endif
index af89d2c1cfbe5d93b833a12a9f70cc786932b8bf..59107eb67b1b9a3de1385480b3ef1f1f1aeb15c9 100644 (file)
@@ -851,6 +851,9 @@ const struct function common_desktop_functions_possible[] = {
 // { "glTextureStorage2DMultisampleEXT", 43, -1 },      // XXX: Add to xml
 // { "glTextureStorage3DMultisampleEXT", 43, -1 },      // XXX: Add to xml
 
+/* GL 4.5 */
+   { "glMemoryBarrierByRegion", 45, -1 },
+
    /* GL_ARB_internalformat_query */
    { "glGetInternalformativ", 30, -1 },
 
@@ -1739,6 +1742,9 @@ const struct function gl_core_functions_possible[] = {
 // { "glTextureStorage2DMultisampleEXT", 43, -1 },      // XXX: Add to xml
 // { "glTextureStorage3DMultisampleEXT", 43, -1 },      // XXX: Add to xml
 
+/* GL 4.5 */
+   { "glMemoryBarrierByRegion", 45, -1 },
+
    /* GL_ARB_direct_state_access */
    { "glCreateTransformFeedbacks", 45, -1 },
    { "glTransformFeedbackBufferBase", 45, -1 },
@@ -2461,8 +2467,7 @@ const struct function gles31_functions_possible[] = {
    { "glGetBooleani_v", 31, -1 },
    { "glMemoryBarrier", 31, -1 },
 
-   // FINISHME: This function has not been implemented yet.
-   // { "glMemoryBarrierByRegion", 31, -1 },
+   { "glMemoryBarrierByRegion", 31, -1 },
 
    { "glTexStorage2DMultisample", 31, -1 },
    { "glGetMultisamplefv", 31, -1 },