turnip: rework format helpers
authorJonathan Marek <jonathan@marek.ca>
Wed, 8 Apr 2020 14:56:16 +0000 (10:56 -0400)
committerMarge Bot <eric+marge@anholt.net>
Thu, 9 Apr 2020 14:43:02 +0000 (14:43 +0000)
* Take tile_mode as input directly
* tu6_format_gmem to tu6_base_format, use may not be limited to GMEM
* Add new helpers that will return the correct tile_mode as for image level
  as part of the format.

Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3783>

src/freedreno/vulkan/tu_blit.c
src/freedreno/vulkan/tu_blit.h
src/freedreno/vulkan/tu_formats.c
src/freedreno/vulkan/tu_image.c
src/freedreno/vulkan/tu_meta_clear.c
src/freedreno/vulkan/tu_private.h

index 116528d5a4f5a41f3c1dcb638c19c7a10fc40ed4..469fb517dd6d29f6756f8d77cb239d2e27f5c93e 100644 (file)
@@ -79,8 +79,8 @@ emit_blit_step(struct tu_cmd_buffer *cmdbuf, struct tu_cs *cs,
 {
    struct tu_physical_device *phys_dev = cmdbuf->device->physical_device;
 
-   struct tu_native_format dfmt = tu6_format_color(blt->dst.fmt, blt->dst.tiled);
-   struct tu_native_format sfmt = tu6_format_texture(blt->src.fmt, blt->src.tiled);
+   struct tu_native_format dfmt = tu6_format_color(blt->dst.fmt, blt->dst.image_tile_mode);
+   struct tu_native_format sfmt = tu6_format_texture(blt->src.fmt, blt->src.image_tile_mode);
 
    if (dfmt.fmt == FMT6_Z24_UNORM_S8_UINT)
       dfmt.fmt = FMT6_Z24_UNORM_S8_UINT_AS_R8G8B8A8;
@@ -318,7 +318,7 @@ void tu_blit(struct tu_cmd_buffer *cmdbuf, struct tu_cs *cs,
          }
       } else if ((blt->src.va & 63) || (blt->src.pitch & 63)) {
          /* per line copy path (buffer_to_image) */
-         assert(blt->type == TU_BLIT_COPY && !blt->src.tiled);
+         assert(blt->type == TU_BLIT_COPY && !blt->src.image_tile_mode);
          struct tu_blit line_blt = *blt;
          uint64_t src_va = line_blt.src.va + blt->src.pitch * blt->src.y;
 
@@ -338,7 +338,7 @@ void tu_blit(struct tu_cmd_buffer *cmdbuf, struct tu_cs *cs,
          }
       } else if ((blt->dst.va & 63) || (blt->dst.pitch & 63)) {
          /* per line copy path (image_to_buffer) */
-         assert(blt->type == TU_BLIT_COPY && !blt->dst.tiled);
+         assert(blt->type == TU_BLIT_COPY && !blt->dst.image_tile_mode);
          struct tu_blit line_blt = *blt;
          uint64_t dst_va = line_blt.dst.va + blt->dst.pitch * blt->dst.y;
 
index 6400fa9d2bca9fc589f56de2b39be5f28530ade2..62851d747780e5ad4e5ca1d9d24ae7f4a2ba1617 100644 (file)
@@ -35,7 +35,7 @@
 struct tu_blit_surf {
    VkFormat fmt;
    enum a6xx_tile_mode tile_mode;
-   bool tiled;
+   enum a6xx_tile_mode image_tile_mode;
    uint64_t va;
    uint32_t pitch, layer_size;
    uint32_t x, y;
@@ -60,7 +60,7 @@ tu_blit_surf(struct tu_image *image,
    return (struct tu_blit_surf) {
       .fmt = image->vk_format,
       .tile_mode = tu6_get_image_tile_mode(image, subres.mipLevel),
-      .tiled = image->layout.tile_mode != TILE6_LINEAR,
+      .image_tile_mode = image->layout.tile_mode,
       .va = tu_image_base(image, subres.mipLevel, layer),
       .pitch = tu_image_stride(image, subres.mipLevel),
       .layer_size = tu_layer_size(image, subres.mipLevel),
index 0d2351d0066dc52252c9462127e62ca55bc4584c..6a8f3d022a2c3f5573409d3011656ce27fe2972c 100644 (file)
@@ -287,7 +287,7 @@ static const struct tu_native_format tu6_format_table[] = {
    TU6_xTx(ASTC_12x12_SRGB_BLOCK,      ASTC_12x12,        WZYX), /* 184 */
 };
 
-struct tu_native_format
+static struct tu_native_format
 tu6_get_native_format(VkFormat format)
 {
    struct tu_native_format fmt = {};
@@ -314,20 +314,8 @@ tu6_format_vtx(VkFormat format)
    return fmt;
 }
 
-enum a6xx_format
-tu6_format_gmem(VkFormat format)
-{
-   struct tu_native_format fmt = tu6_get_native_format(format);
-   assert(fmt.supported & FMT_COLOR);
-
-   if (fmt.fmt == FMT6_10_10_10_2_UNORM)
-      return FMT6_10_10_10_2_UNORM_DEST;
-
-   return fmt.fmt;
-}
-
 struct tu_native_format
-tu6_format_color(VkFormat format, bool tiled)
+tu6_format_color(VkFormat format, enum a6xx_tile_mode tile_mode)
 {
    struct tu_native_format fmt = tu6_get_native_format(format);
    assert(fmt.supported & FMT_COLOR);
@@ -335,19 +323,19 @@ tu6_format_color(VkFormat format, bool tiled)
    if (fmt.fmt == FMT6_10_10_10_2_UNORM)
       fmt.fmt = FMT6_10_10_10_2_UNORM_DEST;
 
-   if (tiled)
+   if (tile_mode)
       fmt.swap = WZYX;
 
    return fmt;
 }
 
 struct tu_native_format
-tu6_format_texture(VkFormat format, bool tiled)
+tu6_format_texture(VkFormat format, enum a6xx_tile_mode tile_mode)
 {
    struct tu_native_format fmt = tu6_get_native_format(format);
    assert(fmt.supported & FMT_TEXTURE);
 
-   if (!tiled) {
+   if (!tile_mode) {
       /* different from format table when used as linear src */
       if (format == VK_FORMAT_R5G5B5A1_UNORM_PACK16)
          fmt.fmt = FMT6_1_5_5_5_UNORM, fmt.swap = WXYZ;
index d77f3c8df43354e8818f5ba15ed508d2d42ba3ca..ddb8dbebf7b6e7066bcac8eeedfe956cfce809a3 100644 (file)
@@ -520,7 +520,7 @@ tu_buffer_view_init(struct tu_buffer_view *view,
 
    enum VkFormat vfmt = pCreateInfo->format;
    enum pipe_format pfmt = vk_format_to_pipe_format(vfmt);
-   const struct tu_native_format fmt = tu6_format_texture(vfmt, false);
+   const struct tu_native_format fmt = tu6_format_texture(vfmt, TILE6_LINEAR);
 
    uint32_t range;
    if (pCreateInfo->range == VK_WHOLE_SIZE)
index b3a7354c286c429689d55b7a1725809ab0a448f0..500f6ae3529bad40ed776d92b677da3cf0099a8d 100644 (file)
@@ -135,7 +135,7 @@ tu_clear_gmem_attachment(struct tu_cmd_buffer *cmd,
    VkFormat fmt = cmd->state.pass->attachments[attachment].format;
 
    tu_cs_emit_pkt4(cs, REG_A6XX_RB_BLIT_DST_INFO, 1);
-   tu_cs_emit(cs, A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(tu6_format_gmem(fmt)));
+   tu_cs_emit(cs, A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(tu6_base_format(fmt)));
 
    tu_cs_emit_pkt4(cs, REG_A6XX_RB_BLIT_INFO, 1);
    tu_cs_emit(cs, A6XX_RB_BLIT_INFO_GMEM | A6XX_RB_BLIT_INFO_CLEAR_MASK(component_mask));
index 3de415304d8404b7629e6e61a8a551cac4819e6d..50365371dad39c463314624500ab10100fce5530 100644 (file)
@@ -1315,14 +1315,20 @@ struct tu_native_format
 {
    enum a6xx_format fmt : 8;
    enum a3xx_color_swap swap : 8;
+   enum a6xx_tile_mode tile_mode : 8;
    enum tu_supported_formats supported : 8;
 };
 
-struct tu_native_format tu6_get_native_format(VkFormat format);
 struct tu_native_format tu6_format_vtx(VkFormat format);
-enum a6xx_format tu6_format_gmem(VkFormat format);
-struct tu_native_format tu6_format_color(VkFormat format, bool tiled);
-struct tu_native_format tu6_format_texture(VkFormat format, bool tiled);
+struct tu_native_format tu6_format_color(VkFormat format, enum a6xx_tile_mode tile_mode);
+struct tu_native_format tu6_format_texture(VkFormat format, enum a6xx_tile_mode tile_mode);
+
+static inline enum a6xx_format
+tu6_base_format(VkFormat format)
+{
+   /* note: tu6_format_color doesn't care about tiling for .fmt field */
+   return tu6_format_color(format, TILE6_LINEAR).fmt;
+}
 
 void
 tu_pack_clear_value(const VkClearValue *val,
@@ -1457,6 +1463,24 @@ tu6_get_image_tile_mode(struct tu_image *image, int level);
 enum a3xx_msaa_samples
 tu_msaa_samples(uint32_t samples);
 
+static inline struct tu_native_format
+tu6_format_image(struct tu_image *image, VkFormat format, uint32_t level)
+{
+   struct tu_native_format fmt =
+      tu6_format_color(format, image->layout.tile_mode);
+   fmt.tile_mode = tu6_get_image_tile_mode(image, level);
+   return fmt;
+}
+
+static inline struct tu_native_format
+tu6_format_image_src(struct tu_image *image, VkFormat format, uint32_t level)
+{
+   struct tu_native_format fmt =
+      tu6_format_texture(format, image->layout.tile_mode);
+   fmt.tile_mode = tu6_get_image_tile_mode(image, level);
+   return fmt;
+}
+
 struct tu_image_view
 {
    struct tu_image *image; /**< VkImageViewCreateInfo::image */