From 55083705cf59ac451a9c1483db2c2e8c0f4b82f5 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Thu, 25 May 2017 11:19:52 +0200 Subject: [PATCH] mesa: add KHR_no_error support for glBindImageTextures() Signed-off-by: Samuel Pitoiset Reviewed-by: Timothy Arceri --- src/mapi/glapi/gen/ARB_multi_bind.xml | 2 +- src/mesa/main/shaderimage.c | 78 ++++++++++++++++----------- src/mesa/main/shaderimage.h | 4 ++ 3 files changed, 52 insertions(+), 32 deletions(-) diff --git a/src/mapi/glapi/gen/ARB_multi_bind.xml b/src/mapi/glapi/gen/ARB_multi_bind.xml index f42eaa28e96..d58c2708cb2 100644 --- a/src/mapi/glapi/gen/ARB_multi_bind.xml +++ b/src/mapi/glapi/gen/ARB_multi_bind.xml @@ -35,7 +35,7 @@ - + diff --git a/src/mesa/main/shaderimage.c b/src/mesa/main/shaderimage.c index 494125346b4..5e31d4e8220 100644 --- a/src/mesa/main/shaderimage.c +++ b/src/mesa/main/shaderimage.c @@ -658,31 +658,12 @@ _mesa_BindImageTexture(GLuint unit, GLuint texture, GLint level, bind_image_texture(ctx, texObj, unit, level, layered, layer, access, format); } -void GLAPIENTRY -_mesa_BindImageTextures(GLuint first, GLsizei count, const GLuint *textures) +static ALWAYS_INLINE void +bind_image_textures(struct gl_context *ctx, GLuint first, GLuint count, + const GLuint *textures, bool no_error) { - GET_CURRENT_CONTEXT(ctx); int i; - if (!ctx->Extensions.ARB_shader_image_load_store) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glBindImageTextures()"); - return; - } - - if (first + count > ctx->Const.MaxImageUnits) { - /* The ARB_multi_bind spec says: - * - * "An INVALID_OPERATION error is generated if + - * is greater than the number of image units supported by - * the implementation." - */ - _mesa_error(ctx, GL_INVALID_OPERATION, - "glBindImageTextures(first=%u + count=%d > the value of " - "GL_MAX_IMAGE_UNITS=%u)", - first, count, ctx->Const.MaxImageUnits); - return; - } - /* Assume that at least one binding will be changed */ FLUSH_VERTICES(ctx, 0); ctx->NewDriverState |= ctx->DriverFlags.NewImageUnits; @@ -712,13 +693,13 @@ _mesa_BindImageTextures(GLuint first, GLsizei count, const GLuint *textures) struct gl_image_unit *u = &ctx->ImageUnits[first + i]; const GLuint texture = textures ? textures[i] : 0; - if (texture != 0) { - struct gl_texture_object *texObj; + if (texture) { + struct gl_texture_object *texObj = u->TexObj; GLenum tex_format; - if (!u->TexObj || u->TexObj->Name != texture) { + if (!texObj || texObj->Name != texture) { texObj = _mesa_lookup_texture_locked(ctx, texture); - if (!texObj) { + if (!no_error && !texObj) { /* The ARB_multi_bind spec says: * * "An INVALID_OPERATION error is generated if any value @@ -731,8 +712,6 @@ _mesa_BindImageTextures(GLuint first, GLsizei count, const GLuint *textures) "object)", i, texture); continue; } - } else { - texObj = u->TexObj; } if (texObj->Target == GL_TEXTURE_BUFFER) { @@ -740,8 +719,8 @@ _mesa_BindImageTextures(GLuint first, GLsizei count, const GLuint *textures) } else { struct gl_texture_image *image = texObj->Image[0][0]; - if (!image || image->Width == 0 || image->Height == 0 || - image->Depth == 0) { + if (!no_error && (!image || image->Width == 0 || + image->Height == 0 || image->Depth == 0)) { /* The ARB_multi_bind spec says: * * "An INVALID_OPERATION error is generated if the width, @@ -758,7 +737,8 @@ _mesa_BindImageTextures(GLuint first, GLsizei count, const GLuint *textures) tex_format = image->InternalFormat; } - if (!_mesa_is_shader_image_format_supported(ctx, tex_format)) { + if (!no_error && + !_mesa_is_shader_image_format_supported(ctx, tex_format)) { /* The ARB_multi_bind spec says: * * "An INVALID_OPERATION error is generated if the internal @@ -786,3 +766,39 @@ _mesa_BindImageTextures(GLuint first, GLsizei count, const GLuint *textures) _mesa_HashUnlockMutex(ctx->Shared->TexObjects); } + +void GLAPIENTRY +_mesa_BindImageTextures_no_error(GLuint first, GLsizei count, + const GLuint *textures) +{ + GET_CURRENT_CONTEXT(ctx); + + bind_image_textures(ctx, first, count, textures, true); +} + +void GLAPIENTRY +_mesa_BindImageTextures(GLuint first, GLsizei count, const GLuint *textures) +{ + GET_CURRENT_CONTEXT(ctx); + + if (!ctx->Extensions.ARB_shader_image_load_store) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glBindImageTextures()"); + return; + } + + if (first + count > ctx->Const.MaxImageUnits) { + /* The ARB_multi_bind spec says: + * + * "An INVALID_OPERATION error is generated if + + * is greater than the number of image units supported by + * the implementation." + */ + _mesa_error(ctx, GL_INVALID_OPERATION, + "glBindImageTextures(first=%u + count=%d > the value of " + "GL_MAX_IMAGE_UNITS=%u)", + first, count, ctx->Const.MaxImageUnits); + return; + } + + bind_image_textures(ctx, first, count, textures, false); +} diff --git a/src/mesa/main/shaderimage.h b/src/mesa/main/shaderimage.h index b2b22bbf863..6a9e3d67e92 100644 --- a/src/mesa/main/shaderimage.h +++ b/src/mesa/main/shaderimage.h @@ -89,6 +89,10 @@ _mesa_BindImageTexture(GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format); +void GLAPIENTRY +_mesa_BindImageTextures_no_error(GLuint first, GLsizei count, + const GLuint *textures); + void GLAPIENTRY _mesa_BindImageTextures(GLuint first, GLsizei count, const GLuint *textures); -- 2.30.2