Mesa (main): main: allow all external textures for BindImageTexture

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Aug 31 22:28:20 UTC 2021


Module: Mesa
Branch: main
Commit: e52aa1edffb8552d6215732b00efc85e6188d597
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=e52aa1edffb8552d6215732b00efc85e6188d597

Author: Quantum <me at quantum2.xyz>
Date:   Sun Aug 15 17:44:04 2021 -0400

main: allow all external textures for BindImageTexture

According to OES_EGL_image_external_essl3:

  On p. 196 in the errors section for BindImageTexture, replace the
  last error with the following:

    "An INVALID_OPERATION error is generated if <texture> is neither the
     name of an immutable texture object, nor the name of an external
     texture object."

According to OES_EGL_image_external:

  The command

    void EGLImageTargetTexture2DOES(enum target, eglImageOES image);

  with <target> set to TEXTURE_EXTERNAL_OES defines the currently bound
  external texture object to be a target sibling of <image>.

  ...

  If <target> is not TEXTURE_EXTERNAL_OES, the error INVALID_ENUM is
  generated.  (Note: if GL_OES_EGL_image is supported then <target> may
  also be TEXTURE_2D).

Currently, mesa only allows GL_TEXTURE_EXTERNAL_OES textures to be bound
by glBindImageTexture. However, the language of the specification does not
appear to use "external" to refer to GL_TEXTURE_EXTERNAL_OES specifically,
since OES_EGL_image_external allows external eglImageOES to be attached
to GL_TEXTURE_2D in the presence of GL_OES_EGL_image. Thus, it should be
interpreted to refer to all types of external textures, including 2D
textures attached via glEGLImageTargetTexture2DOES.

Fixes: ed43dd62acc ("main: allow external textures for BindImageTexture")
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12383>

---

 src/mesa/main/genmipmap.c   | 2 ++
 src/mesa/main/mtypes.h      | 1 +
 src/mesa/main/shaderimage.c | 7 +++----
 src/mesa/main/teximage.c    | 6 ++++++
 src/mesa/main/textureview.c | 2 ++
 5 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/mesa/main/genmipmap.c b/src/mesa/main/genmipmap.c
index 36727bb7060..2593dbb10bd 100644
--- a/src/mesa/main/genmipmap.c
+++ b/src/mesa/main/genmipmap.c
@@ -131,6 +131,8 @@ generate_texture_mipmap(struct gl_context *ctx,
 
    _mesa_lock_texture(ctx, texObj);
 
+   texObj->External = GL_FALSE;
+
    srcImage = _mesa_select_tex_image(texObj, target, texObj->Attrib.BaseLevel);
    if (caller) {
       if (!srcImage) {
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index acda78eb74c..280aa1b4c25 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -996,6 +996,7 @@ struct gl_texture_object
    bool StencilSampling;       /**< Should we sample stencil instead of depth? */
 
    /** GL_OES_EGL_image_external */
+   GLboolean External;
    GLubyte RequiredTextureImageUnits;
 
    /** GL_EXT_memory_object */
diff --git a/src/mesa/main/shaderimage.c b/src/mesa/main/shaderimage.c
index cfa229acdb5..b3b020e0423 100644
--- a/src/mesa/main/shaderimage.c
+++ b/src/mesa/main/shaderimage.c
@@ -641,11 +641,10 @@ _mesa_BindImageTexture(GLuint unit, GLuint texture, GLint level,
        * so those are excluded from this requirement.
        *
        * Additionally, issue 10 of the OES_EGL_image_external_essl3 spec
-       * states that glBindImageTexture must accept external textures.
+       * states that glBindImageTexture must accept external texture objects.
        */
-      if (_mesa_is_gles(ctx) && !texObj->Immutable &&
-          texObj->Target != GL_TEXTURE_BUFFER &&
-          texObj->Target != GL_TEXTURE_EXTERNAL_OES) {
+      if (_mesa_is_gles(ctx) && !texObj->Immutable && !texObj->External &&
+          texObj->Target != GL_TEXTURE_BUFFER) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "glBindImageTexture(!immutable)");
          return;
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 3b17a462c45..71c5f2b299f 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -3132,6 +3132,8 @@ teximage(struct gl_context *ctx, GLboolean compressed, GLuint dims,
 
       _mesa_lock_texture(ctx, texObj);
       {
+         texObj->External = GL_FALSE;
+
          texImage = _mesa_get_tex_image(ctx, texObj, target, level);
 
          if (!texImage) {
@@ -3438,6 +3440,8 @@ egl_image_target_texture(struct gl_context *ctx,
    } else {
       ctx->Driver.FreeTextureImageBuffer(ctx, texImage);
 
+      texObj->External = GL_TRUE;
+
       if (tex_storage) {
          ctx->Driver.EGLImageTargetTexStorage(ctx, target, texObj, texImage,
                                               image);
@@ -4410,6 +4414,7 @@ copyteximage(struct gl_context *ctx, GLuint dims, struct gl_texture_object *texO
 
    _mesa_lock_texture(ctx, texObj);
    {
+      texObj->External = GL_FALSE;
       texImage = _mesa_get_tex_image(ctx, texObj, target, level);
 
       if (!texImage) {
@@ -6907,6 +6912,7 @@ texture_image_multisample(struct gl_context *ctx, GLuint dims,
          }
       }
 
+      texObj->External = GL_FALSE;
       texObj->Immutable |= immutable;
 
       if (immutable) {
diff --git a/src/mesa/main/textureview.c b/src/mesa/main/textureview.c
index 48596487d22..c532fd1b834 100644
--- a/src/mesa/main/textureview.c
+++ b/src/mesa/main/textureview.c
@@ -486,6 +486,7 @@ _mesa_set_texture_view_state(struct gl_context *ctx,
     */
 
    texObj->Immutable = GL_TRUE;
+   texObj->External = GL_FALSE;
    texObj->Attrib.ImmutableLevels = levels;
    texObj->Attrib.MinLevel = 0;
    texObj->Attrib.NumLevels = levels;
@@ -692,6 +693,7 @@ texture_view(struct gl_context *ctx, struct gl_texture_object *origTexObj,
    texObj->Attrib.NumLevels = newViewNumLevels;
    texObj->Attrib.NumLayers = newViewNumLayers;
    texObj->Immutable = GL_TRUE;
+   texObj->External = GL_FALSE;
    texObj->Attrib.ImmutableLevels = origTexObj->Attrib.ImmutableLevels;
    texObj->Target = target;
    texObj->TargetIndex = _mesa_tex_target_to_index(ctx, target);



More information about the mesa-commit mailing list