d3d12: Support RGBX formats mapped to RGBA
authorJesse Natalie <jenatali@microsoft.com>
Wed, 11 Aug 2021 21:43:52 +0000 (14:43 -0700)
committerMarge Bot <emma+marge@anholt.net>
Fri, 19 Nov 2021 22:54:46 +0000 (22:54 +0000)
Reviewed-by: Bill Kristiansen <billkris@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13054>

src/gallium/drivers/d3d12/d3d12_blit.cpp
src/gallium/drivers/d3d12/d3d12_context.cpp
src/gallium/drivers/d3d12/d3d12_format.c

index 55a741a..e87ef87 100644 (file)
@@ -69,7 +69,8 @@ resolve_supported(const struct pipe_blit_info *info)
       return false;
    } else {
       if (util_format_get_mask(info->dst.format) != info->mask ||
-          util_format_get_mask(info->src.format) != info->mask)
+          util_format_get_mask(info->src.format) != info->mask ||
+          util_format_has_alpha1(info->src.format))
          return false;
    }
 
index d09315a..7cac481 100644 (file)
@@ -1697,6 +1697,10 @@ d3d12_clear_render_target(struct pipe_context *pctx,
          clear_color[c] = color->f[c];
    }
 
+   if (!(util_format_colormask(util_format_description(psurf->texture->format)) &
+       PIPE_MASK_A))
+      clear_color[3] = 1.0f;
+
    D3D12_RECT rect = { (int)dstx, (int)dsty,
                        (int)dstx + (int)width,
                        (int)dsty + (int)height };
index 1a87102..d49c3b0 100644 (file)
@@ -63,6 +63,16 @@ static const DXGI_FORMAT formats[PIPE_FORMAT_COUNT] = {
    MAP_FORMAT_INT(R8G8B8A8)
    MAP_FORMAT_SRGB(R8G8B8A8)
 
+   /* Since we report PIPE_CAP_RGB_OVERRIDE_DST_ALPHA_BLEND and other caps,
+    * we can rely on st/mesa to force the alpha to 1 for these, so we can
+    * just use RGBA. This is needed to support RGB configs, since some apps
+    * will only choose RGB (not RGBA) configs.
+    */
+   [PIPE_FORMAT_R8G8B8X8_UNORM] = DXGI_FORMAT_R8G8B8A8_UNORM,
+   [PIPE_FORMAT_R8G8B8X8_SNORM] = DXGI_FORMAT_R8G8B8A8_SNORM,
+   [PIPE_FORMAT_R8G8B8X8_UINT] = DXGI_FORMAT_R8G8B8A8_UINT,
+   [PIPE_FORMAT_R8G8B8X8_SINT] = DXGI_FORMAT_R8G8B8A8_SINT,
+
    [PIPE_FORMAT_B8G8R8X8_UNORM] = DXGI_FORMAT_B8G8R8X8_UNORM,
    [PIPE_FORMAT_B8G8R8A8_UNORM] = DXGI_FORMAT_B8G8R8A8_UNORM,
 
@@ -238,6 +248,8 @@ d3d12_get_format_info(enum pipe_format pformat, enum pipe_texture_target target)
           * but the shader will read the x component so we need to adjust the swizzle. */
          plane_slice = 1;
          swizzle = STENCIL_SWIZZLE;
+      } else if (util_format_has_alpha1(pformat)) {
+         swizzle = RGB1_SWIZZLE;
       }
    }