From 5db28b0cf748cdcd50408cb8391cdf5df03cfd92 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Fri, 12 Jul 2019 15:47:26 +0200 Subject: [PATCH] mesa: add EXT_shader_image_load_store glBindImageTextureEXT function MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The implementation is almost identical to glBindImageTexture except for error checking. Reviewed-by: Marek Olšák --- .../glapi/gen/EXT_shader_image_load_store.xml | 2 - src/mapi/glapi/gen/static_data.py | 1 + src/mesa/main/shaderimage.c | 48 +++++++++++++++---- src/mesa/main/shaderimage.h | 5 ++ src/mesa/main/tests/dispatch_sanity.cpp | 3 ++ 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/mapi/glapi/gen/EXT_shader_image_load_store.xml b/src/mapi/glapi/gen/EXT_shader_image_load_store.xml index 2a69357efa5..e893afb45b3 100644 --- a/src/mapi/glapi/gen/EXT_shader_image_load_store.xml +++ b/src/mapi/glapi/gen/EXT_shader_image_load_store.xml @@ -61,7 +61,6 @@ - diff --git a/src/mapi/glapi/gen/static_data.py b/src/mapi/glapi/gen/static_data.py index b184fd8123d..231563fd622 100644 --- a/src/mapi/glapi/gen/static_data.py +++ b/src/mapi/glapi/gen/static_data.py @@ -1551,6 +1551,7 @@ offsets = { "GetMultiTexGenfvEXT": 1515, "GetMultiTexGenivEXT": 1516, "MultiTexCoordPointerEXT": 1517, + "BindImageTextureEXT": 1518, } functions = [ diff --git a/src/mesa/main/shaderimage.c b/src/mesa/main/shaderimage.c index 242a8c29909..1712483c415 100644 --- a/src/mesa/main/shaderimage.c +++ b/src/mesa/main/shaderimage.c @@ -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) diff --git a/src/mesa/main/shaderimage.h b/src/mesa/main/shaderimage.h index daed27508a7..d43578b192b 100644 --- a/src/mesa/main/shaderimage.h +++ b/src/mesa/main/shaderimage.h @@ -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); diff --git a/src/mesa/main/tests/dispatch_sanity.cpp b/src/mesa/main/tests/dispatch_sanity.cpp index 4f8a40ba99e..2542f15b056 100644 --- a/src/mesa/main/tests/dispatch_sanity.cpp +++ b/src/mesa/main/tests/dispatch_sanity.cpp @@ -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 } }; -- 2.30.2