[Mesa-dev] [PATCH 07/23] mesa: hook up memory object multisamples tex(ture)storage api

Timothy Arceri tarceri at itsqueeze.com
Fri Aug 4 01:54:10 UTC 2017


From: Andres Rodriguez <andresx7 at gmail.com>

V2 (Timothy):
 - error check memory == 0 before lookup

Signed-off-by: Andres Rodriguez <andresx7 at gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com> (v1)
---
 src/mesa/main/externalobjects.c | 46 +++++++++++++++++++++----
 src/mesa/main/teximage.c        | 75 +++++++++++++++++++++++++++++------------
 src/mesa/main/teximage.h        | 10 ++++++
 3 files changed, 103 insertions(+), 28 deletions(-)

diff --git a/src/mesa/main/externalobjects.c b/src/mesa/main/externalobjects.c
index d10d414f02..3dd325ca0d 100644
--- a/src/mesa/main/externalobjects.c
+++ b/src/mesa/main/externalobjects.c
@@ -278,23 +278,38 @@ texstorage_memory(GLuint dims, GLenum target, GLsizei levels,
 
    _mesa_texture_storage_memory(ctx, dims, texObj, memObj, target,
                                 levels, internalFormat,
                                 width, height, depth, offset, false);
 }
 
 static void
 texstorage_memory_ms(GLuint dims, GLenum target, GLsizei samples,
                      GLenum internalFormat, GLsizei width, GLsizei height,
                      GLsizei depth, GLboolean fixedSampleLocations,
-                     GLuint memory, GLuint64 offset)
+                     GLuint memory, GLuint64 offset, const char* func)
 {
+   struct gl_texture_object *texObj;
+   struct gl_memory_object *memObj;
+
+   GET_CURRENT_CONTEXT(ctx);
+
+   texObj = _mesa_get_current_tex_object(ctx, target);
+   if (!texObj)
+      return;
+
+   memObj = lookup_memory_object_err(ctx, memory, func);
+   if (!memObj)
+      return;
 
+   _mesa_texture_storage_ms_memory(ctx, dims, texObj, memObj, target, samples,
+                                   internalFormat, width, height, depth,
+                                   fixedSampleLocations, offset, func);
 }
 
 /**
  * Helper used by _mesa_TextureStorageMem1/2/3DEXT().
  */
 static void
 texturestorage_memory(GLuint dims, GLuint texture, GLsizei levels,
                       GLenum internalFormat, GLsizei width, GLsizei height,
                       GLsizei depth, GLuint memory, GLuint64 offset,
                       const char *func)
@@ -314,23 +329,38 @@ texturestorage_memory(GLuint dims, GLuint texture, GLsizei levels,
 
    _mesa_texture_storage_memory(ctx, dims, texObj, memObj, texObj->Target,
                                 levels, internalFormat,
                                 width, height, depth, offset, true);
 }
 
 static void
 texturestorage_memory_ms(GLuint dims, GLuint texture, GLsizei samples,
                          GLenum internalFormat, GLsizei width, GLsizei height,
                          GLsizei depth, GLboolean fixedSampleLocations,
-                         GLuint memory, GLuint64 offset)
+                         GLuint memory, GLuint64 offset, const char* func)
 {
+   struct gl_texture_object *texObj;
+   struct gl_memory_object *memObj;
+
+   GET_CURRENT_CONTEXT(ctx);
+
+   texObj = _mesa_lookup_texture(ctx, texture);
+   if (!texObj)
+      return;
+
+   memObj = lookup_memory_object_err(ctx, memory, func);
+   if (!memObj)
+      return;
 
+   _mesa_texture_storage_ms_memory(ctx, dims, texObj, memObj, texObj->Target,
+                                   samples, internalFormat, width, height,
+                                   depth, fixedSampleLocations, offset, func);
 }
 
 void GLAPIENTRY
 _mesa_TexStorageMem2DEXT(GLenum target,
                          GLsizei levels,
                          GLenum internalFormat,
                          GLsizei width,
                          GLsizei height,
                          GLuint memory,
                          GLuint64 offset)
@@ -343,21 +373,22 @@ void GLAPIENTRY
 _mesa_TexStorageMem2DMultisampleEXT(GLenum target,
                                     GLsizei samples,
                                     GLenum internalFormat,
                                     GLsizei width,
                                     GLsizei height,
                                     GLboolean fixedSampleLocations,
                                     GLuint memory,
                                     GLuint64 offset)
 {
    texstorage_memory_ms(2, target, samples, internalFormat, width, height, 1,
-                        fixedSampleLocations, memory, offset);
+                        fixedSampleLocations, memory, offset,
+                        "glTexStorageMem2DMultisampleEXT");
 }
 
 void GLAPIENTRY
 _mesa_TexStorageMem3DEXT(GLenum target,
                          GLsizei levels,
                          GLenum internalFormat,
                          GLsizei width,
                          GLsizei height,
                          GLsizei depth,
                          GLuint memory,
@@ -372,21 +403,22 @@ _mesa_TexStorageMem3DMultisampleEXT(GLenum target,
                                     GLsizei samples,
                                     GLenum internalFormat,
                                     GLsizei width,
                                     GLsizei height,
                                     GLsizei depth,
                                     GLboolean fixedSampleLocations,
                                     GLuint memory,
                                     GLuint64 offset)
 {
    texstorage_memory_ms(3, target, samples, internalFormat, width, height,
-                        depth, fixedSampleLocations, memory, offset);
+                        depth, fixedSampleLocations, memory, offset,
+                        "glTexStorageMem3DMultisampleEXT");
 }
 
 void GLAPIENTRY
 _mesa_TextureStorageMem2DEXT(GLuint texture,
                              GLsizei levels,
                              GLenum internalFormat,
                              GLsizei width,
                              GLsizei height,
                              GLuint memory,
                              GLuint64 offset)
@@ -399,21 +431,22 @@ void GLAPIENTRY
 _mesa_TextureStorageMem2DMultisampleEXT(GLuint texture,
                                         GLsizei samples,
                                         GLenum internalFormat,
                                         GLsizei width,
                                         GLsizei height,
                                         GLboolean fixedSampleLocations,
                                         GLuint memory,
                                         GLuint64 offset)
 {
    texturestorage_memory_ms(2, texture, samples, internalFormat, width, height,
-                            1, fixedSampleLocations, memory, offset);
+                            1, fixedSampleLocations, memory, offset,
+                            "glTextureStorageMem2DMultisampleEXT");
 }
 
 void GLAPIENTRY
 _mesa_TextureStorageMem3DEXT(GLuint texture,
                              GLsizei levels,
                              GLenum internalFormat,
                              GLsizei width,
                              GLsizei height,
                              GLsizei depth,
                              GLuint memory,
@@ -428,21 +461,22 @@ _mesa_TextureStorageMem3DMultisampleEXT(GLuint texture,
                                         GLsizei samples,
                                         GLenum internalFormat,
                                         GLsizei width,
                                         GLsizei height,
                                         GLsizei depth,
                                         GLboolean fixedSampleLocations,
                                         GLuint memory,
                                         GLuint64 offset)
 {
    texturestorage_memory_ms(3, texture, samples, internalFormat, width, height,
-                            depth, fixedSampleLocations, memory, offset);
+                            depth, fixedSampleLocations, memory, offset,
+                            "glTextureStorageMem3DMultisampleEXT");
 }
 
 void GLAPIENTRY
 _mesa_TexStorageMem1DEXT(GLenum target,
                          GLsizei levels,
                          GLenum internalFormat,
                          GLsizei width,
                          GLuint memory,
                          GLuint64 offset)
 {
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 04d0d6f911..7bcd734204 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -5711,25 +5711,27 @@ check_multisample_target(GLuint dims, GLenum target, bool dsa)
       return dims == 3 && !dsa;
    default:
       return GL_FALSE;
    }
 }
 
 
 static void
 texture_image_multisample(struct gl_context *ctx, GLuint dims,
                           struct gl_texture_object *texObj,
+                          struct gl_memory_object *memObj,
                           GLenum target, GLsizei samples,
                           GLint internalformat, GLsizei width,
                           GLsizei height, GLsizei depth,
                           GLboolean fixedsamplelocations,
-                          GLboolean immutable, const char *func)
+                          GLboolean immutable, GLuint64 offset,
+                          const char *func)
 {
    struct gl_texture_image *texImage;
    GLboolean sizeOK, dimensionsOK, samplesOK;
    mesa_format texFormat;
    GLenum sample_count_error;
    bool dsa = strstr(func, "ture") ? true : false;
 
    if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) {
       _mesa_debug(ctx, "%s(target=%s, samples=%d)\n", func,
                   _mesa_enum_to_string(target), samples);
@@ -5852,28 +5854,39 @@ texture_image_multisample(struct gl_context *ctx, GLuint dims,
          return;
       }
 
       ctx->Driver.FreeTextureImageBuffer(ctx, texImage);
 
       init_teximage_fields_ms(ctx, texImage, width, height, depth, 0,
                               internalformat, texFormat,
                               samples, fixedsamplelocations);
 
       if (width > 0 && height > 0 && depth > 0) {
-         if (!ctx->Driver.AllocTextureStorage(ctx, texObj, 1,
-                                              width, height, depth)) {
-            /* tidy up the texture image state. strictly speaking,
-             * we're allowed to just leave this in whatever state we
-             * like, but being tidy is good.
-             */
-            _mesa_init_teximage_fields(ctx, texImage,
-                  0, 0, 0, 0, internalformat, texFormat);
+         if (memObj) {
+            if (!ctx->Driver.SetTextureStorageForMemoryObject(ctx, texObj,
+                                                              memObj, 1, width,
+                                                              height, depth,
+                                                              offset)) {
+
+               _mesa_init_teximage_fields(ctx, texImage, 0, 0, 0, 0,
+                                          internalformat, texFormat);
+            }
+         } else {
+            if (!ctx->Driver.AllocTextureStorage(ctx, texObj, 1,
+                                                 width, height, depth)) {
+               /* tidy up the texture image state. strictly speaking,
+                * we're allowed to just leave this in whatever state we
+                * like, but being tidy is good.
+                */
+               _mesa_init_teximage_fields(ctx, texImage, 0, 0, 0, 0,
+                                          internalformat, texFormat);
+            }
          }
       }
 
       texObj->Immutable |= immutable;
 
       if (immutable) {
          _mesa_set_texture_view_state(ctx, texObj, target, 1);
       }
 
       _mesa_update_fbo_texture(ctx, texObj, 0, 0);
@@ -5886,43 +5899,43 @@ _mesa_TexImage2DMultisample(GLenum target, GLsizei samples,
                             GLenum internalformat, GLsizei width,
                             GLsizei height, GLboolean fixedsamplelocations)
 {
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
    texObj = _mesa_get_current_tex_object(ctx, target);
    if (!texObj)
       return;
 
-   texture_image_multisample(ctx, 2, texObj, target, samples,
+   texture_image_multisample(ctx, 2, texObj, NULL, target, samples,
                              internalformat, width, height, 1,
-                             fixedsamplelocations, GL_FALSE,
+                             fixedsamplelocations, GL_FALSE, 0,
                              "glTexImage2DMultisample");
 }
 
 
 void GLAPIENTRY
 _mesa_TexImage3DMultisample(GLenum target, GLsizei samples,
                             GLenum internalformat, GLsizei width,
                             GLsizei height, GLsizei depth,
                             GLboolean fixedsamplelocations)
 {
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
    texObj = _mesa_get_current_tex_object(ctx, target);
    if (!texObj)
       return;
 
-   texture_image_multisample(ctx, 3, texObj, target, samples,
+   texture_image_multisample(ctx, 3, texObj, NULL, target, samples,
                              internalformat, width, height, depth,
-                             fixedsamplelocations, GL_FALSE,
+                             fixedsamplelocations, GL_FALSE, 0,
                              "glTexImage3DMultisample");
 }
 
 static bool
 valid_texstorage_ms_parameters(GLsizei width, GLsizei height, GLsizei depth,
                                GLsizei samples, unsigned dims)
 {
    GET_CURRENT_CONTEXT(ctx);
 
    if (!_mesa_valid_tex_storage_dim(width, height, depth)) {
@@ -5942,68 +5955,68 @@ _mesa_TexStorage2DMultisample(GLenum target, GLsizei samples,
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
    texObj = _mesa_get_current_tex_object(ctx, target);
    if (!texObj)
       return;
 
    if (!valid_texstorage_ms_parameters(width, height, 1, samples, 2))
       return;
 
-   texture_image_multisample(ctx, 2, texObj, target, samples,
+   texture_image_multisample(ctx, 2, texObj, NULL, target, samples,
                              internalformat, width, height, 1,
-                             fixedsamplelocations, GL_TRUE,
+                             fixedsamplelocations, GL_TRUE, 0,
                              "glTexStorage2DMultisample");
 }
 
 void GLAPIENTRY
 _mesa_TexStorage3DMultisample(GLenum target, GLsizei samples,
                               GLenum internalformat, GLsizei width,
                               GLsizei height, GLsizei depth,
                               GLboolean fixedsamplelocations)
 {
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
    texObj = _mesa_get_current_tex_object(ctx, target);
    if (!texObj)
       return;
 
    if (!valid_texstorage_ms_parameters(width, height, depth, samples, 3))
       return;
 
-   texture_image_multisample(ctx, 3, texObj, target, samples,
+   texture_image_multisample(ctx, 3, texObj, NULL, target, samples,
                              internalformat, width, height, depth,
-                             fixedsamplelocations, GL_TRUE,
+                             fixedsamplelocations, GL_TRUE, 0,
                              "glTexStorage3DMultisample");
 }
 
 void GLAPIENTRY
 _mesa_TextureStorage2DMultisample(GLuint texture, GLsizei samples,
                                   GLenum internalformat, GLsizei width,
                                   GLsizei height,
                                   GLboolean fixedsamplelocations)
 {
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
    texObj = _mesa_lookup_texture_err(ctx, texture,
                                      "glTextureStorage2DMultisample");
    if (!texObj)
       return;
 
    if (!valid_texstorage_ms_parameters(width, height, 1, samples, 2))
       return;
 
-   texture_image_multisample(ctx, 2, texObj, texObj->Target, samples,
-                             internalformat, width, height, 1,
-                             fixedsamplelocations, GL_TRUE,
+   texture_image_multisample(ctx, 2, texObj, NULL, texObj->Target,
+                             samples, internalformat, width, height, 1,
+                             fixedsamplelocations, GL_TRUE, 0,
                              "glTextureStorage2DMultisample");
 }
 
 void GLAPIENTRY
 _mesa_TextureStorage3DMultisample(GLuint texture, GLsizei samples,
                                   GLenum internalformat, GLsizei width,
                                   GLsizei height, GLsizei depth,
                                   GLboolean fixedsamplelocations)
 {
    struct gl_texture_object *texObj;
@@ -6011,15 +6024,33 @@ _mesa_TextureStorage3DMultisample(GLuint texture, GLsizei samples,
 
    /* Get the texture object by Name. */
    texObj = _mesa_lookup_texture_err(ctx, texture,
                                      "glTextureStorage3DMultisample");
    if (!texObj)
       return;
 
    if (!valid_texstorage_ms_parameters(width, height, depth, samples, 3))
       return;
 
-   texture_image_multisample(ctx, 3, texObj, texObj->Target, samples,
+   texture_image_multisample(ctx, 3, texObj, NULL, texObj->Target, samples,
                              internalformat, width, height, depth,
-                             fixedsamplelocations, GL_TRUE,
+                             fixedsamplelocations, GL_TRUE, 0,
                              "glTextureStorage3DMultisample");
 }
+
+void
+_mesa_texture_storage_ms_memory(struct gl_context *ctx, GLuint dims,
+                                struct gl_texture_object *texObj,
+                                struct gl_memory_object *memObj,
+                                GLenum target, GLsizei samples,
+                                GLenum internalFormat, GLsizei width,
+                                GLsizei height, GLsizei depth,
+                                GLboolean fixedSampleLocations,
+                                GLuint64 offset, const char* func)
+{
+   assert(memObj);
+
+   texture_image_multisample(ctx, dims, texObj, memObj, target, samples,
+                             internalFormat, width, height, depth,
+                             fixedSampleLocations, GL_TRUE, offset,
+                             func);
+}
diff --git a/src/mesa/main/teximage.h b/src/mesa/main/teximage.h
index e988e263a9..18452db24d 100644
--- a/src/mesa/main/teximage.h
+++ b/src/mesa/main/teximage.h
@@ -221,20 +221,30 @@ _mesa_is_renderable_texture_format(struct gl_context *ctx, GLenum internalformat
 extern void
 _mesa_texture_sub_image(struct gl_context *ctx, GLuint dims,
                         struct gl_texture_object *texObj,
                         struct gl_texture_image *texImage,
                         GLenum target, GLint level,
                         GLint xoffset, GLint yoffset, GLint zoffset,
                         GLsizei width, GLsizei height, GLsizei depth,
                         GLenum format, GLenum type, const GLvoid *pixels,
                         bool dsa);
 
+extern void
+_mesa_texture_storage_ms_memory(struct gl_context *ctx, GLuint dims,
+                                struct gl_texture_object *texObj,
+                                struct gl_memory_object *memObj,
+                                GLenum target, GLsizei samples,
+                                GLenum internalFormat, GLsizei width,
+                                GLsizei height, GLsizei depth,
+                                GLboolean fixedSampleLocations,
+                                GLuint64 offset, const char* func);
+
 bool
 _mesa_is_cube_map_texture(GLenum target);
 
 /*@}*/
 
 
 /** \name API entry point functions */
 /*@{*/
 
 extern void GLAPIENTRY
-- 
2.13.3



More information about the mesa-dev mailing list