freedreno: Make the slice pitch be bytes, not pixels.
[mesa.git] / src / freedreno / fdl / freedreno_layout.h
index 4704a5fc88d5f65cf57fee02db16ee3988098568..011cf131dea18dfb2200f4fad5b79ea0ebd25fe5 100644 (file)
 #ifndef FREEDRENO_LAYOUT_H_
 #define FREEDRENO_LAYOUT_H_
 
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "util/u_debug.h"
+#include "util/u_math.h"
+#include "util/format/u_format.h"
+
 /* Shared freedreno mipmap layout helper
  *
  * It does *not* attempt to track surface transitions, in particular
  * texture.
  */
 
+#define FDL_MAX_MIP_LEVELS 14
+
 struct fdl_slice {
        uint32_t offset;         /* offset of first layer in slice */
-       uint32_t pitch;
+       uint32_t pitch;          /* pitch in bytes between rows. */
        uint32_t size0;          /* size of first layer in slice */
 };
 
@@ -80,9 +89,11 @@ struct fdl_slice {
  * to derive this.
  */
 struct fdl_layout {
-       struct fdl_slice slices[MAX_MIP_LEVELS];
-       struct fdl_slice ubwc_slices[MAX_MIP_LEVELS];
+       struct fdl_slice slices[FDL_MAX_MIP_LEVELS];
+       struct fdl_slice ubwc_slices[FDL_MAX_MIP_LEVELS];
        uint32_t layer_size;
+       uint32_t ubwc_layer_size; /* in bytes */
+       bool ubwc : 1;
        bool layer_first : 1;    /* see above description */
 
        /* Note that for tiled textures, beyond a certain mipmap level (ie.
@@ -98,11 +109,27 @@ struct fdl_layout {
         */
        uint8_t cpp;
 
+       /**
+        * Left shift necessary to multiply by cpp.  Invalid for NPOT cpp, please
+        * use fdl_cpp_shift() to sanity check you aren't hitting that case.
+        */
+       uint8_t cpp_shift;
+
        uint32_t width0, height0, depth0;
+       uint32_t nr_samples;
+       enum pipe_format format;
 
-       uint32_t ubwc_size;
+       uint32_t size; /* Size of the whole image, in bytes. */
+       uint32_t base_align; /* Alignment of the base address, in bytes. */
 };
 
+static inline uint32_t
+fdl_cpp_shift(const struct fdl_layout *layout)
+{
+       assert(util_is_power_of_two_or_zero(layout->cpp));
+       return layout->cpp_shift;
+}
+
 static inline uint32_t
 fdl_layer_stride(const struct fdl_layout *layout, unsigned level)
 {
@@ -122,22 +149,20 @@ fdl_surface_offset(const struct fdl_layout *layout, unsigned level, unsigned lay
 static inline uint32_t
 fdl_ubwc_offset(const struct fdl_layout *layout, unsigned level, unsigned layer)
 {
-       /* for now this doesn't do anything clever, but when UBWC is enabled
-        * for multi layer/level images, it will.
-        */
-       if (layout->ubwc_size) {
-               debug_assert(level == 0);
-               debug_assert(layer == 0);
-       }
-       return layout->ubwc_slices[0].offset;
+       const struct fdl_slice *slice = &layout->ubwc_slices[level];
+       return slice->offset + layer * layout->ubwc_layer_size;
 }
 
 static inline bool
 fdl_level_linear(const struct fdl_layout *layout, int level)
 {
+       if (layout->ubwc)
+               return false;
+
        unsigned w = u_minify(layout->width0, level);
        if (w < 16)
                return true;
+
        return false;
 }
 
@@ -153,7 +178,23 @@ fdl_tile_mode(const struct fdl_layout *layout, int level)
 static inline bool
 fdl_ubwc_enabled(const struct fdl_layout *layout, int level)
 {
-       return layout->ubwc_size && fdl_tile_mode(layout, level);
+       return layout->ubwc;
 }
 
+void
+fdl_layout_buffer(struct fdl_layout *layout, uint32_t size);
+
+void
+fdl6_layout(struct fdl_layout *layout,
+               enum pipe_format format, uint32_t nr_samples,
+               uint32_t width0, uint32_t height0, uint32_t depth0,
+               uint32_t mip_levels, uint32_t array_size, bool is_3d);
+
+void
+fdl_dump_layout(struct fdl_layout *layout);
+
+void
+fdl6_get_ubwc_blockwidth(struct fdl_layout *layout,
+               uint32_t *blockwidth, uint32_t *blockheight);
+
 #endif /* FREEDRENO_LAYOUT_H_ */