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

Submitted by Andres Rodriguez on July 7, 2017, 4:24 a.m.

Details

Message ID 20170707042457.18219-8-andresx7@gmail.com
State New
Headers show
Series "Series without cover letter" ( rev: 3 2 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Andres Rodriguez July 7, 2017, 4:24 a.m.
Signed-off-by: Andres Rodriguez <andresx7@gmail.com>
---
 src/mesa/main/externalobjects.c | 53 ++++++++++++++++++++++++----
 src/mesa/main/teximage.c        | 76 +++++++++++++++++++++++++++++------------
 src/mesa/main/teximage.h        | 10 ++++++
 3 files changed, 110 insertions(+), 29 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/mesa/main/externalobjects.c b/src/mesa/main/externalobjects.c
index d083ad9..0b4f5f5 100644
--- a/src/mesa/main/externalobjects.c
+++ b/src/mesa/main/externalobjects.c
@@ -261,10 +261,26 @@  texstorage_memory(GLuint dims, GLenum target, GLsizei levels, GLenum internalFor
 
 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)
+                     GLsizei width, GLsizei height, GLsizei depth,
+                     GLboolean fixedSampleLocations, 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 = _mesa_lookup_memory_object(ctx, memory);
+   if (!memObj)
+      return;
 
+   _mesa_texture_storage_ms_memory(ctx, dims, texObj, memObj, target, samples,
+                                   internalFormat, width, height, depth,
+                                   fixedSampleLocations, offset, func);
 }
 
 /**
@@ -297,9 +313,24 @@  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 = _mesa_lookup_memory_object(ctx, memory);
+   if (!memObj)
+      return;
 
+   _mesa_texture_storage_ms_memory(ctx, dims, texObj, memObj, texObj->Target,
+                                   samples, internalFormat, width, height,
+                                   depth, fixedSampleLocations, offset, func);
 }
 
 void GLAPIENTRY
@@ -324,7 +355,9 @@  _mesa_TexStorageMem2DMultisampleEXT(GLenum target,
                                     GLuint memory,
                                     GLuint64 offset)
 {
-   texstorage_memory_ms(2, target, samples, internalFormat, width, height, 1, fixedSampleLocations, memory, offset);
+   texstorage_memory_ms(2, target, samples, internalFormat, width, height, 1,
+                        fixedSampleLocations, memory, offset,
+                        "glTexStorageMem2DMultisampleEXT");
 }
 
 void GLAPIENTRY
@@ -351,7 +384,9 @@  _mesa_TexStorageMem3DMultisampleEXT(GLenum target,
                                     GLuint memory,
                                     GLuint64 offset)
 {
-   texstorage_memory_ms(3, target, samples, internalFormat, width, height, depth, fixedSampleLocations, memory, offset);
+   texstorage_memory_ms(3, target, samples, internalFormat, width, height, depth,
+                        fixedSampleLocations, memory, offset,
+                        "glTexStorageMem3DMultisampleEXT");
 }
 
 void GLAPIENTRY
@@ -385,7 +420,9 @@  _mesa_TextureStorageMem2DMultisampleEXT(GLuint texture,
                                         GLuint memory,
                                         GLuint64 offset)
 {
-   texturestorage_memory_ms(2, texture, samples, internalFormat, width, height, 1, fixedSampleLocations, memory, offset);
+   texturestorage_memory_ms(2, texture, samples, internalFormat, width, height, 1,
+                            fixedSampleLocations, memory, offset,
+                            "glTextureStorageMem2DMultisampleEXT");
 }
 
 void GLAPIENTRY
@@ -412,7 +449,9 @@  _mesa_TextureStorageMem3DMultisampleEXT(GLuint texture,
                                         GLuint memory,
                                         GLuint64 offset)
 {
-   texturestorage_memory_ms(3, texture, samples, internalFormat, width, height, depth, fixedSampleLocations, memory, offset);
+   texturestorage_memory_ms(3, texture, samples, internalFormat, width, height, depth,
+                            fixedSampleLocations, memory, offset,
+                            "glTextureStorageMem3DMultisampleEXT");
 }
 
 void GLAPIENTRY
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 36747a7..e6aeaae 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -5617,11 +5617,13 @@  check_multisample_target(GLuint dims, GLenum target, bool dsa)
 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;
@@ -5758,14 +5760,26 @@  texture_image_multisample(struct gl_context *ctx, GLuint dims,
                               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, GL_NONE, MESA_FORMAT_NONE);
+         if (memObj) {
+            if (!ctx->Driver.SetTextureStorageForMemoryObject(ctx, texObj, memObj,
+                                                              1,
+                                                              width, height, depth,
+                                                              offset)) {
+
+               _mesa_init_teximage_fields(ctx, texImage,
+                                          0, 0, 0, 0, GL_NONE, MESA_FORMAT_NONE);
+            }
+         }
+         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, GL_NONE, MESA_FORMAT_NONE);
+            }
          }
       }
 
@@ -5792,9 +5806,9 @@  _mesa_TexImage2DMultisample(GLenum target, GLsizei samples,
    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");
 }
 
@@ -5812,9 +5826,9 @@  _mesa_TexImage3DMultisample(GLenum target, GLsizei samples,
    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");
 }
 
@@ -5848,9 +5862,9 @@  _mesa_TexStorage2DMultisample(GLenum target, GLsizei samples,
    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");
 }
 
@@ -5870,9 +5884,9 @@  _mesa_TexStorage3DMultisample(GLenum target, GLsizei samples,
    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");
 }
 
@@ -5893,9 +5907,9 @@  _mesa_TextureStorage2DMultisample(GLuint texture, GLsizei samples,
    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");
 }
 
@@ -5917,8 +5931,26 @@  _mesa_TextureStorage3DMultisample(GLuint texture, GLsizei samples,
    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 04ddbb9..8db476d 100644
--- a/src/mesa/main/teximage.h
+++ b/src/mesa/main/teximage.h
@@ -226,6 +226,16 @@  _mesa_texture_sub_image(struct gl_context *ctx, GLuint dims,
                         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);