freedreno/a6xx: FETCHSIZE is PITCHALIGN
authorJonathan Marek <jonathan@marek.ca>
Tue, 12 May 2020 16:34:37 +0000 (12:34 -0400)
committerMarge Bot <eric+marge@anholt.net>
Thu, 18 Jun 2020 02:26:43 +0000 (02:26 +0000)
"FETCHSIZE" is actually a "minimum pitch" or "pitchalign" value that's
relevant for mipmaps. The 0 value means 64-bytes. Understanding this allows
some simplifications and will make it possible to use less alignment on
linear formats.

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

12 files changed:
src/freedreno/fdl/fd6_layout.c
src/freedreno/fdl/freedreno_layout.h
src/freedreno/registers/a6xx.xml
src/freedreno/vulkan/tu_clear_blit.c
src/freedreno/vulkan/tu_cmd_buffer.c
src/freedreno/vulkan/tu_image.c
src/freedreno/vulkan/tu_private.h
src/gallium/drivers/freedreno/a6xx/fd6_emit.c
src/gallium/drivers/freedreno/a6xx/fd6_format.c
src/gallium/drivers/freedreno/a6xx/fd6_format.h
src/gallium/drivers/freedreno/a6xx/fd6_image.c
src/gallium/drivers/freedreno/a6xx/fd6_texture.c

index 20aec1fdb9a777531ccd8400b4896d7b6db5d301..146e86900aa8360facfc6cb9678845984549e310 100644 (file)
@@ -165,6 +165,9 @@ fdl6_layout(struct fdl_layout *layout,
                                        ta->ubwc_blockheight),
                        ubwc_tile_height_alignment);
 
+       layout->pitchalign =
+               util_logbase2_ceil(fdl6_pitchalign(layout, mip_levels - 1) * layout->cpp >> 6);
+
        for (uint32_t level = 0; level < mip_levels; level++) {
                uint32_t depth = u_minify(depth0, level);
                struct fdl_slice *slice = &layout->slices[level];
index ec4090066ca8afd66ead4c21841dc7905da5fa35..3b2cb67c49394e5eb6fc45859d0bc6cd17f9d1e5 100644 (file)
@@ -121,6 +121,7 @@ struct fdl_layout {
 
        uint32_t size; /* Size of the whole image, in bytes. */
        uint32_t base_align; /* Alignment of the base address, in bytes. */
+       uint8_t pitchalign; /* log2(pitchalign / 64) */
 };
 
 static inline uint32_t
index 515b1043aae506e111a64c1a5ad92f83307382d9..382dc7e1fb1b52515a2eb840a46145f1de5e4bc2 100644 (file)
@@ -158,14 +158,6 @@ xsi:schemaLocation="http://nouveau.freedesktop.org/ rules-ng.xsd">
 
 </enum>
 
-<enum name="a6xx_tex_fetchsize">
-       <value name="TFETCH6_1_BYTE"  value="0"/>
-       <value name="TFETCH6_2_BYTE"  value="1"/>
-       <value name="TFETCH6_4_BYTE"  value="2"/>
-       <value name="TFETCH6_8_BYTE"  value="3"/>
-       <value name="TFETCH6_16_BYTE" value="4"/>
-</enum>
-
 <!-- probably same as a5xx -->
 <enum name="a6xx_depth_format">
        <value name="DEPTH6_NONE" value="0"/>
@@ -3489,7 +3481,8 @@ to upconvert to 32b float internally?
                behavior of texture in dEQP-GLES31.functional.texture.texture_buffer.render.as_fragment_texture.buffer_size_131071
                 -->
                <bitfield name="UNK4" pos="4" type="boolean"/>
-               <bitfield name="FETCHSIZE" low="0" high="3" type="a6xx_tex_fetchsize"/>
+                <!-- minimum pitch (for mipmap levels): log2(pitchalign / 64) -->
+               <bitfield name="PITCHALIGN" low="0" high="3" type="uint"/>
                <doc>Pitch in bytes (so actually stride)</doc>
                <bitfield name="PITCH" low="7" high="28" type="uint"/>
                <bitfield name="TYPE" low="29" high="30" type="a6xx_tex_type"/>
index c9cf1a0a589c8569ebce6aad51faf49bafa4e408..0ebe3ba2c90ed01ef5430e455e162d1f65189f03 100644 (file)
@@ -709,7 +709,6 @@ r3d_src_buffer(struct tu_cmd_buffer *cmd,
       A6XX_TEX_CONST_0_SWIZ_W(vk_format == VK_FORMAT_R8_UNORM ? A6XX_TEX_X : A6XX_TEX_W);
    desc[1] = A6XX_TEX_CONST_1_WIDTH(width) | A6XX_TEX_CONST_1_HEIGHT(height);
    desc[2] =
-      A6XX_TEX_CONST_2_FETCHSIZE(tu6_fetchsize(vk_format)) |
       A6XX_TEX_CONST_2_PITCH(pitch) |
       A6XX_TEX_CONST_2_TYPE(A6XX_TEX_2D);
    desc[3] = 0;
index b2712af5b84a68066998f942c3f01a8135d625f2..13e782a80a2289bc4096428d1dcbb633121ec35b 100644 (file)
@@ -1318,8 +1318,7 @@ tu_emit_input_attachments(struct tu_cmd_buffer *cmd,
       /* patched for gmem */
       dst[0] &= ~(A6XX_TEX_CONST_0_SWAP__MASK | A6XX_TEX_CONST_0_TILE_MODE__MASK);
       dst[0] |= A6XX_TEX_CONST_0_TILE_MODE(TILE6_2);
-      dst[2] &= ~(A6XX_TEX_CONST_2_TYPE__MASK | A6XX_TEX_CONST_2_PITCH__MASK);
-      dst[2] |=
+      dst[2] =
          A6XX_TEX_CONST_2_TYPE(A6XX_TEX_2D) |
          A6XX_TEX_CONST_2_PITCH(cmd->state.tiling_config.tile0.extent.width * att->cpp);
       dst[3] = 0;
index 420842f45441335944f17af5e1aee329853c7185..4d3980e66efce3f428712d3c9204d1cf610b72b4 100644 (file)
@@ -187,20 +187,6 @@ invalid_layout:
    return vk_error(device->instance, VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT);
 }
 
-enum a6xx_tex_fetchsize
-tu6_fetchsize(VkFormat format)
-{
-   switch (vk_format_get_blocksize(format)) {
-   case 1: return TFETCH6_1_BYTE;
-   case 2: return TFETCH6_2_BYTE;
-   case 4: return TFETCH6_4_BYTE;
-   case 8: return TFETCH6_8_BYTE;
-   case 16: return TFETCH6_16_BYTE;
-   default:
-      unreachable("bad block size");
-   }
-}
-
 static void
 compose_swizzle(unsigned char *swiz, const VkComponentMapping *mapping)
 {
@@ -398,7 +384,7 @@ tu_image_view_init(struct tu_image_view *iview,
       A6XX_TEX_CONST_0_MIPLVLS(tu_get_levelCount(image, range) - 1);
    iview->descriptor[1] = A6XX_TEX_CONST_1_WIDTH(width) | A6XX_TEX_CONST_1_HEIGHT(height);
    iview->descriptor[2] =
-      A6XX_TEX_CONST_2_FETCHSIZE(tu6_fetchsize(format)) |
+      A6XX_TEX_CONST_2_PITCHALIGN(layout->pitchalign) |
       A6XX_TEX_CONST_2_PITCH(pitch) |
       A6XX_TEX_CONST_2_TYPE(tu6_tex_type(pCreateInfo->viewType, false));
    iview->descriptor[3] = A6XX_TEX_CONST_3_ARRAY_PITCH(layer_size);
index 5e50b983302ea69c1d07f618f87c7ca1930ac28a..f7fe939ce1446a57b091c5fe7074dff8227e81b6 100644 (file)
@@ -1299,8 +1299,6 @@ tu_get_levelCount(const struct tu_image *image,
 
 enum a3xx_msaa_samples
 tu_msaa_samples(uint32_t samples);
-enum a6xx_tex_fetchsize
-tu6_fetchsize(VkFormat format);
 
 struct tu_image_view
 {
index 0853a9529b04f916b55b04af2cc5f010455324dd..70c464b4afe17076239c1cc25996bf15ce3f3ba5 100644 (file)
@@ -258,8 +258,7 @@ fd6_emit_fb_tex(struct fd_ringbuffer *state, struct fd_context *ctx)
        OUT_RING(state, texconst0);
        OUT_RING(state, A6XX_TEX_CONST_1_WIDTH(pfb->width) |
                        A6XX_TEX_CONST_1_HEIGHT(pfb->height));
-       OUT_RINGP(state, A6XX_TEX_CONST_2_TYPE(A6XX_TEX_2D) |
-                       A6XX_TEX_CONST_2_FETCHSIZE(TFETCH6_2_BYTE),
+       OUT_RINGP(state, A6XX_TEX_CONST_2_TYPE(A6XX_TEX_2D),
                        &ctx->batch->fb_read_patches);
        OUT_RING(state, A6XX_TEX_CONST_3_ARRAY_PITCH(rsc->layout.layer_size));
 
index 0cd7b397a34416c5d8bc4121b01ebba022ecfe2c..bbc71cf0a08b40b38aa2c42c38c86c23951fd944 100644 (file)
@@ -369,28 +369,6 @@ fd6_pipe2swap(enum pipe_format format)
        return formats[format].swap;
 }
 
-// XXX possibly same as a4xx..
-enum a6xx_tex_fetchsize
-fd6_pipe2fetchsize(enum pipe_format format)
-{
-       if (format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT)
-               format = PIPE_FORMAT_Z32_FLOAT;
-
-       switch (util_format_get_blocksizebits(format)) {
-       case 8:   return TFETCH6_1_BYTE;
-       case 16:  return TFETCH6_2_BYTE;
-       case 32:  return TFETCH6_4_BYTE;
-       case 64:  return TFETCH6_8_BYTE;
-       case 96:  return TFETCH6_1_BYTE; /* Does this matter? */
-       case 128: return TFETCH6_16_BYTE;
-       default:
-               debug_printf("Unknown block size for format %s: %d\n",
-                               util_format_name(format),
-                               util_format_get_blocksizebits(format));
-               return TFETCH6_1_BYTE;
-       }
-}
-
 enum a6xx_depth_format
 fd6_pipe2depth(enum pipe_format format)
 {
index ef8818f233f165f61557d722ac295b47a4343a16..a7fe81084e760e548701730c3b78b49f267e053e 100644 (file)
@@ -37,7 +37,6 @@ enum a6xx_format fd6_pipe2vtx(enum pipe_format format);
 enum a6xx_format fd6_pipe2tex(enum pipe_format format);
 enum a6xx_format fd6_pipe2color(enum pipe_format format);
 enum a3xx_color_swap fd6_pipe2swap(enum pipe_format format);
-enum a6xx_tex_fetchsize fd6_pipe2fetchsize(enum pipe_format format);
 enum a6xx_depth_format fd6_pipe2depth(enum pipe_format format);
 enum a6xx_tex_swiz fd6_pipe2swiz(unsigned swiz);
 
index 6098799e22dc7ab3e654a83c340c2217c9c8b700..b7999aacf9a51b90d8dae5851c7c1935fc6c7a69 100644 (file)
@@ -39,7 +39,6 @@ struct fd6_image {
        struct pipe_resource *prsc;
        enum pipe_format pfmt;
        enum a6xx_format fmt;
-       enum a6xx_tex_fetchsize fetchsize;
        enum a6xx_tex_type type;
        bool srgb;
        uint32_t cpp;
@@ -69,7 +68,6 @@ static void translate_image(struct fd6_image *img, const struct pipe_image_view
        img->prsc      = prsc;
        img->pfmt      = format;
        img->fmt       = fd6_pipe2tex(format);
-       img->fetchsize = fd6_pipe2fetchsize(format);
        img->type      = fd6_tex_type(prsc->target);
        img->srgb      = util_format_is_srgb(format);
        img->cpp       = rsc->layout.cpp;
@@ -148,7 +146,6 @@ static void translate_buf(struct fd6_image *img, const struct pipe_shader_buffer
        img->prsc      = prsc;
        img->pfmt      = format;
        img->fmt       = fd6_pipe2tex(format);
-       img->fetchsize = fd6_pipe2fetchsize(format);
        img->type      = fd6_tex_type(prsc->target);
        img->srgb      = util_format_is_srgb(format);
        img->cpp       = rsc->layout.cpp;
@@ -179,7 +176,7 @@ static void emit_image_tex(struct fd_ringbuffer *ring, struct fd6_image *img)
                        PIPE_SWIZZLE_Z, PIPE_SWIZZLE_W));
        OUT_RING(ring, A6XX_TEX_CONST_1_WIDTH(img->width) |
                A6XX_TEX_CONST_1_HEIGHT(img->height));
-       OUT_RING(ring, A6XX_TEX_CONST_2_FETCHSIZE(img->fetchsize) |
+       OUT_RING(ring,
                COND(img->buffer, A6XX_TEX_CONST_2_UNK4 | A6XX_TEX_CONST_2_UNK31) |
                A6XX_TEX_CONST_2_TYPE(img->type) |
                A6XX_TEX_CONST_2_PITCH(img->pitch));
index 4338f1f1f6c763b4f82cce00ae018d1b18b482c0..19402290565d720bf492a48e78c52c4013ea03a9 100644 (file)
@@ -265,7 +265,7 @@ fd6_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                        A6XX_TEX_CONST_1_WIDTH(u_minify(prsc->width0, lvl)) |
                        A6XX_TEX_CONST_1_HEIGHT(u_minify(prsc->height0, lvl));
                so->texconst2 =
-                       A6XX_TEX_CONST_2_FETCHSIZE(fd6_pipe2fetchsize(format)) |
+                       A6XX_TEX_CONST_2_PITCHALIGN(rsc->layout.pitchalign) |
                        A6XX_TEX_CONST_2_PITCH(slice->pitch);
                so->offset = fd_resource_offset(rsc, lvl, cso->u.tex.first_layer);
                so->ubwc_offset = fd_resource_ubwc_offset(rsc, lvl, cso->u.tex.first_layer);