mesa: add EXT_shader_image_load_store glBindImageTextureEXT function
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Fri, 12 Jul 2019 13:47:26 +0000 (15:47 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 6 Aug 2019 21:40:53 +0000 (17:40 -0400)
The implementation is almost identical to glBindImageTexture except for error
checking.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mapi/glapi/gen/EXT_shader_image_load_store.xml
src/mapi/glapi/gen/static_data.py
src/mesa/main/shaderimage.c
src/mesa/main/shaderimage.h
src/mesa/main/tests/dispatch_sanity.cpp

index 2a69357efa59bcb94bee5fff5b4886de7e03a061..e893afb45b32a7562eea76ceb4dd9347a5f53c0e 100644 (file)
@@ -61,7 +61,6 @@
 <enum name="MAX_IMAGE_SAMPLES_EXT" value="0x906D"/>
 <enum name="IMAGE_BINDING_FORMAT_EXT" value="0x906E"/>
 
-<!--
 <function name="BindImageTextureEXT">
   <param name="index" type="GLuint"/>
   <param name="texture" type="GLuint"/>
@@ -71,7 +70,6 @@
   <param name="access" type="GLenum"/>
   <param name="format" type="GLint"/>
 </function>
--->
 
 <function name="MemoryBarrierEXT" alias="MemoryBarrier" >
   <param name="barriers" type="GLbitfield"/>
index b184fd8123da3d1d2d06cb7068e229c7f24f8c6d..231563fd622d5aa8e17fc4e47b088974d9bd09ae 100644 (file)
@@ -1551,6 +1551,7 @@ offsets = {
     "GetMultiTexGenfvEXT": 1515,
     "GetMultiTexGenivEXT": 1516,
     "MultiTexCoordPointerEXT": 1517,
+    "BindImageTextureEXT": 1518,
 }
 
 functions = [
index 242a8c29909406f4d9f900e5e3ca67f622bc3f79..1712483c41515cd7ecaa7115b81c3b081f9db100 100644 (file)
@@ -541,7 +541,7 @@ _mesa_is_image_unit_valid(struct gl_context *ctx, struct gl_image_unit *u)
 static GLboolean
 validate_bind_image_texture(struct gl_context *ctx, GLuint unit,
                             GLuint texture, GLint level, GLint layer,
-                            GLenum access, GLenum format)
+                            GLenum access, GLenum format, bool check_level_layer)
 {
    assert(ctx->Const.MaxImageUnits <= MAX_IMAGE_UNITS);
 
@@ -550,14 +550,19 @@ validate_bind_image_texture(struct gl_context *ctx, GLuint unit,
       return GL_FALSE;
    }
 
-   if (level < 0) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glBindImageTexture(level)");
-      return GL_FALSE;
-   }
+   if (check_level_layer) {
+      /* EXT_shader_image_load_store doesn't throw an error if level or
+       * layer is negative.
+       */
+      if (level < 0) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "glBindImageTexture(level)");
+         return GL_FALSE;
+      }
 
-   if (layer < 0) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glBindImageTexture(layer)");
-      return GL_FALSE;
+         if (layer < 0) {
+            _mesa_error(ctx, GL_INVALID_VALUE, "glBindImageTexture(layer)");
+            return GL_FALSE;
+      }
    }
 
    if (access != GL_READ_ONLY &&
@@ -637,7 +642,7 @@ _mesa_BindImageTexture(GLuint unit, GLuint texture, GLint level,
    GET_CURRENT_CONTEXT(ctx);
 
    if (!validate_bind_image_texture(ctx, unit, texture, level, layer, access,
-                                    format))
+                                    format, true))
       return;
 
    if (texture) {
@@ -669,6 +674,31 @@ _mesa_BindImageTexture(GLuint unit, GLuint texture, GLint level,
    bind_image_texture(ctx, texObj, unit, level, layered, layer, access, format);
 }
 
+void GLAPIENTRY
+_mesa_BindImageTextureEXT(GLuint index, GLuint texture, GLint level,
+                          GLboolean layered, GLint layer, GLenum access,
+                          GLint format)
+{
+   struct gl_texture_object *texObj = NULL;
+
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (!validate_bind_image_texture(ctx, index, texture, level, layer, access,
+                                    format, false))
+      return;
+
+   if (texture) {
+      texObj = _mesa_lookup_texture(ctx, texture);
+
+      if (!texObj) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "glBindImageTextureEXT(texture)");
+         return;
+      }
+   }
+
+   bind_image_texture(ctx, texObj, index, level, layered, layer, access, format);
+}
+
 static ALWAYS_INLINE void
 bind_image_textures(struct gl_context *ctx, GLuint first, GLuint count,
                     const GLuint *textures, bool no_error)
index daed27508a7b4a0815857d649f8e2da781318bb0..d43578b192b6aea226d1e8a7c256a91c05dc2cd0 100644 (file)
@@ -92,6 +92,11 @@ _mesa_BindImageTexture(GLuint unit, GLuint texture, GLint level,
                        GLboolean layered, GLint layer, GLenum access,
                        GLenum format);
 
+void GLAPIENTRY
+_mesa_BindImageTextureEXT(GLuint unit, GLuint texture, GLint level,
+                          GLboolean layered, GLint layer, GLenum access,
+                          GLint format);
+
 void GLAPIENTRY
 _mesa_BindImageTextures_no_error(GLuint first, GLsizei count,
                                  const GLuint *textures);
index 4f8a40ba99e23a4b1fe281159e6f3fb98e04d8d0..2542f15b056fe06912f5aac27a80f60308afb711 100644 (file)
@@ -1409,6 +1409,9 @@ const struct function common_desktop_functions_possible[] = {
 
    { "glMaxShaderCompilerThreadsKHR", 11, -1 },
 
+   /* GL_EXT_shader_image_load_store */
+   { "glBindImageTextureEXT", 30, -1 },
+
    { NULL, 0, -1 }
 };