turnip: respect color attachment formats
authorChia-I Wu <olvaffe@gmail.com>
Thu, 14 Feb 2019 18:53:20 +0000 (10:53 -0800)
committerChia-I Wu <olvaffe@gmail.com>
Mon, 11 Mar 2019 17:02:13 +0000 (10:02 -0700)
Make tu6_get_native_format available to tu_cmd_buffer and start
using of it.

src/freedreno/vulkan/tu_cmd_buffer.c
src/freedreno/vulkan/tu_formats.c
src/freedreno/vulkan/tu_private.h

index 51f97971335328346ab242549cc0dd94e0d756c7..f307c145e166dd5ef40cc4d6b22d65085121087f 100644 (file)
@@ -427,8 +427,6 @@ tu6_emit_mrt(struct tu_cmd_buffer *cmd, struct tu_cs *cs)
       const struct tu_image_level *slice =
          &iview->image->levels[iview->base_mip];
       const enum a6xx_tile_mode tile_mode = TILE6_LINEAR;
-      const enum a6xx_color_fmt format = RB6_R8G8B8A8_UNORM;
-      const enum a3xx_color_swap swap = WZYX;
       uint32_t stride = 0;
       uint32_t offset = 0;
 
@@ -437,13 +435,17 @@ tu6_emit_mrt(struct tu_cmd_buffer *cmd, struct tu_cs *cs)
       if (vk_format_is_srgb(iview->vk_format))
          srgb_cntl |= (1 << i);
 
+      const struct tu_native_format *format =
+         tu6_get_native_format(iview->vk_format);
+      assert(format && format->rb >= 0);
+
       offset = slice->offset + slice->size * iview->base_layer;
       stride = slice->pitch * vk_format_get_blocksize(iview->vk_format);
 
       tu_cs_emit_pkt4(cs, REG_A6XX_RB_MRT_BUF_INFO(i), 6);
-      tu_cs_emit(cs, A6XX_RB_MRT_BUF_INFO_COLOR_FORMAT(format) |
+      tu_cs_emit(cs, A6XX_RB_MRT_BUF_INFO_COLOR_FORMAT(format->rb) |
                         A6XX_RB_MRT_BUF_INFO_COLOR_TILE_MODE(tile_mode) |
-                        A6XX_RB_MRT_BUF_INFO_COLOR_SWAP(swap));
+                        A6XX_RB_MRT_BUF_INFO_COLOR_SWAP(format->swap));
       tu_cs_emit(cs, A6XX_RB_MRT_PITCH(stride));
       tu_cs_emit(cs, A6XX_RB_MRT_ARRAY_PITCH(slice->size));
       tu_cs_emit_qw(cs, iview->image->bo->iova + iview->image->bo_offset +
@@ -452,7 +454,7 @@ tu6_emit_mrt(struct tu_cmd_buffer *cmd, struct tu_cs *cs)
          cs, tiling->gmem_offsets[gmem_index++]); /* RB_MRT[i].BASE_GMEM */
 
       tu_cs_emit_pkt4(cs, REG_A6XX_SP_FS_MRT_REG(i), 1);
-      tu_cs_emit(cs, A6XX_SP_FS_MRT_REG_COLOR_FORMAT(RB6_R8G8B8A8_UNORM));
+      tu_cs_emit(cs, A6XX_SP_FS_MRT_REG_COLOR_FORMAT(format->rb));
 
 #if 0
       /* when we support UBWC, these would be the system memory
@@ -592,19 +594,20 @@ tu6_emit_blit_info(struct tu_cmd_buffer *cmd,
       slice->pitch * vk_format_get_blocksize(iview->vk_format);
    const enum a6xx_tile_mode tile_mode = TILE6_LINEAR;
    const enum a3xx_msaa_samples samples = tu6_msaa_samples(1);
-   const enum a6xx_color_fmt format = RB6_R8G8B8A8_UNORM;
-   const enum a3xx_color_swap swap = WZYX;
 
    tu_cs_emit_pkt4(cs, REG_A6XX_RB_BLIT_INFO, 1);
    tu_cs_emit(cs, blit_info);
 
    /* tile mode? */
+   const struct tu_native_format *format =
+      tu6_get_native_format(iview->vk_format);
+   assert(format && format->rb >= 0);
 
    tu_cs_emit_pkt4(cs, REG_A6XX_RB_BLIT_DST_INFO, 5);
    tu_cs_emit(cs, A6XX_RB_BLIT_DST_INFO_TILE_MODE(tile_mode) |
                      A6XX_RB_BLIT_DST_INFO_SAMPLES(samples) |
-                     A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(format) |
-                     A6XX_RB_BLIT_DST_INFO_COLOR_SWAP(swap));
+                     A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(format->rb) |
+                     A6XX_RB_BLIT_DST_INFO_COLOR_SWAP(format->swap));
    tu_cs_emit_qw(cs,
                  iview->image->bo->iova + iview->image->bo_offset + offset);
    tu_cs_emit(cs, A6XX_RB_BLIT_DST_PITCH(stride));
@@ -623,14 +626,17 @@ tu6_emit_blit_clear(struct tu_cmd_buffer *cmd,
 {
    const enum a6xx_tile_mode tile_mode = TILE6_LINEAR;
    const enum a3xx_msaa_samples samples = tu6_msaa_samples(1);
-   const enum a6xx_color_fmt format = RB6_R8G8B8A8_UNORM;
+
+   const struct tu_native_format *format =
+      tu6_get_native_format(iview->vk_format);
+   assert(format && format->rb >= 0);
    /* must be WZYX; other values are ignored */
    const enum a3xx_color_swap swap = WZYX;
 
    tu_cs_emit_pkt4(cs, REG_A6XX_RB_BLIT_DST_INFO, 1);
    tu_cs_emit(cs, A6XX_RB_BLIT_DST_INFO_TILE_MODE(tile_mode) |
                      A6XX_RB_BLIT_DST_INFO_SAMPLES(samples) |
-                     A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(format) |
+                     A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(format->rb) |
                      A6XX_RB_BLIT_DST_INFO_COLOR_SWAP(swap));
 
    tu_cs_emit_pkt4(cs, REG_A6XX_RB_BLIT_INFO, 1);
index 00a45aaac0102907ac45173cd27b3599d6793fa0..1dbb6de33809d6f115aec313f8d3330d15140aa3 100644 (file)
 #include "vk_format.h"
 #include "vk_util.h"
 
-struct tu_native_format
-{
-   int vtx; /* VFMTn_xxx or -1 */
-   int tex; /* TFMTn_xxx or -1 */
-   int rb;  /* RBn_xxx or -1 */
-   enum a3xx_color_swap swap;
-   bool present;
-};
-
 /**
  * Declare a format table.  A format table is an array of tu_native_format.
  * It can map a consecutive range of VkFormat to the corresponding
@@ -325,7 +316,7 @@ TU_FORMAT_TABLE(tu6_format_table0) = {
 #undef TU_FORMAT_TABLE_FIRST
 #undef TU_FORMAT_TABLE_LAST
 
-static const struct tu_native_format *
+const struct tu_native_format *
 tu6_get_native_format(VkFormat format)
 {
    const struct tu_native_format *fmt = NULL;
index 6643168af5f01e4a591bc1a66cee489207348564..9b179f666cfa78eb509de1c17164bcef9e9aa038 100644 (file)
@@ -1002,8 +1002,22 @@ tu_graphics_pipeline_create(
    const VkAllocationCallbacks *alloc,
    VkPipeline *pPipeline);
 
+struct tu_native_format
+{
+   int vtx;      /* VFMTn_xxx or -1 */
+   int tex;      /* TFMTn_xxx or -1 */
+   int rb;       /* RBn_xxx or -1 */
+   int swap;     /* enum a3xx_color_swap */
+   bool present; /* internal only; always true to external users */
+};
+
+const struct tu_native_format *
+tu6_get_native_format(VkFormat format);
+
 int
-tu_pack_clear_value(const VkClearValue *val, VkFormat format, uint32_t buf[4]);
+tu_pack_clear_value(const VkClearValue *val,
+                    VkFormat format,
+                    uint32_t buf[4]);
 
 struct tu_image_level
 {