svga: Fix imported surface view creation
authorThomas Hellstrom <thellstrom@vmware.com>
Tue, 30 May 2017 13:51:06 +0000 (15:51 +0200)
committerThomas Hellstrom <thellstrom@vmware.com>
Wed, 7 Jun 2017 17:43:54 +0000 (19:43 +0200)
When deciding to create a view with or without an alpha channel we need to
look at the SVGA3D format and not the PIPE format.

This fixes the glx-tfp piglit test for dri3/xa.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Charmaine Lee <charmainel@vmware.com>
src/gallium/drivers/svga/svga_resource_texture.c
src/gallium/drivers/svga/svga_resource_texture.h
src/gallium/drivers/svga/svga_shader.c
src/gallium/drivers/svga/svga_state_sampler.c

index 356e7c54d9d921c8503731258561f7b5eb5ed761..39e11d3a6165a1540d656a66b3f1950d9a22f7c5 100644 (file)
@@ -1488,3 +1488,25 @@ svga_texture_transfer_unmap_upload(struct svga_context *svga,
 
    pipe_resource_reference(&st->upload.buf, NULL);
 }
+
+/**
+ * Does the device format backing this surface have an
+ * alpha channel?
+ *
+ * \param texture[in]  The texture whose format we're querying
+ * \return TRUE if the format has an alpha channel, FALSE otherwise
+ *
+ * For locally created textures, the device (svga) format is typically
+ * identical to svga_format(texture->format), and we can use the gallium
+ * format tests to determine whether the device format has an alpha channel
+ * or not. However, for textures backed by imported svga surfaces that is
+ * not always true, and we have to look at the SVGA3D utilities.
+ */
+boolean
+svga_texture_device_format_has_alpha(struct pipe_resource *texture)
+{
+   enum svga3d_block_desc block_desc =
+      svga3dsurface_get_desc(svga_texture(texture)->key.format)->block_desc;
+
+   return !!(block_desc & SVGA3DBLOCKDESC_ALPHA);
+}
index 4cb98970a5bc4bbee747736bed92c973f6ec405c..fe52738b4f18b45b46e84ad11be0d26f07b3c87c 100644 (file)
@@ -313,4 +313,7 @@ void
 svga_texture_transfer_unmap_upload(struct svga_context *svga,
                                    struct svga_transfer *st);
 
+boolean
+svga_texture_device_format_has_alpha(struct pipe_resource *texture);
+
 #endif /* SVGA_TEXTURE_H */
index 669672de6430cca817a75eda25c96957d362cbb5..795531773bfab950d10db7f954782ac9cf9de4af 100644 (file)
@@ -215,7 +215,6 @@ svga_init_shader_key_common(const struct svga_context *svga,
          key->tex[i].swizzle_r = view->swizzle_r;
          key->tex[i].swizzle_g = view->swizzle_g;
          key->tex[i].swizzle_b = view->swizzle_b;
-         key->tex[i].swizzle_a = view->swizzle_a;
 
          /* If we have a non-alpha view into an svga3d surface with an
           * alpha channel, then explicitly set the alpha channel to 1
@@ -223,13 +222,11 @@ svga_init_shader_key_common(const struct svga_context *svga,
           * in the svga texture key, since the imported format is
           * stored here and it may differ from the gallium format.
           */
-         if (!util_format_has_alpha(view->format)) {
-            enum svga3d_block_desc block_desc =
-               svga3dsurface_get_desc(svga_texture(view->texture)->key.format)->
-               block_desc;
-
-            if (block_desc & SVGA3DBLOCKDESC_ALPHA)
-               key->tex[i].swizzle_a = PIPE_SWIZZLE_1;
+         if (!util_format_has_alpha(view->format) &&
+             svga_texture_device_format_has_alpha(view->texture)) {
+            key->tex[i].swizzle_a = PIPE_SWIZZLE_1;
+         } else {
+            key->tex[i].swizzle_a = view->swizzle_a;
          }
       }
    }
index 482449ecc663ce0195a4a10e22eebbecd25eb11b..c361dba676a4e83ccae27d736584307942280f19 100644 (file)
@@ -44,7 +44,7 @@
 #include "svga_shader.h"
 #include "svga_state.h"
 #include "svga_surface.h"
-
+#include "svga3d_surfacedefs.h"
 
 /** Get resource handle for a texture or buffer */
 static inline struct svga_winsys_surface *
@@ -141,11 +141,11 @@ svga_validate_pipe_sampler_view(struct svga_context *svga,
        * create a BGRA view (and vice versa).
        */
       if (viewFormat == PIPE_FORMAT_B8G8R8X8_UNORM &&
-          texture->format == PIPE_FORMAT_B8G8R8A8_UNORM) {
+          svga_texture_device_format_has_alpha(texture)) {
          viewFormat = PIPE_FORMAT_B8G8R8A8_UNORM;
       }
       else if (viewFormat == PIPE_FORMAT_B8G8R8A8_UNORM &&
-          texture->format == PIPE_FORMAT_B8G8R8X8_UNORM) {
+               !svga_texture_device_format_has_alpha(texture)) {
          viewFormat = PIPE_FORMAT_B8G8R8X8_UNORM;
       }