#include "util/u_format.h"
#include "fd6_format.h"
+#include "freedreno_resource.h"
/* Specifies the table of all the formats and their features. Also supplies
_T(R9G9B9E5_FLOAT, 9_9_9_E5_FLOAT, NONE, WZYX),
_T(Z24X8_UNORM, X8Z24_UNORM, X8Z24_UNORM, WZYX),
- _T(X24S8_UINT, 8_8_8_8_UINT, X8Z24_UNORM, XYZW), // XXX
+ _T(X24S8_UINT, 8_8_8_8_UINT, X8Z24_UNORM, WZYX),
_T(Z24_UNORM_S8_UINT, X8Z24_UNORM, X8Z24_UNORM, WZYX),
_T(Z32_FLOAT, 32_FLOAT, R32_FLOAT, WZYX),
_T(Z32_FLOAT_S8X24_UINT, 32_FLOAT, R32_FLOAT, WZYX),
_T(X32_S8X24_UINT, 8_UINT, R8_UINT, WZYX),
+ /* special format for blits: */
+ _T(Z24_UNORM_S8_UINT_AS_R8G8B8A8, Z24_UNORM_S8_UINT, Z24_UNORM_S8_UINT, WZYX),
+
/* 48-bit */
V_(R16G16B16_UNORM, 16_16_16_UNORM, NONE, WZYX),
V_(R16G16B16_SNORM, 16_16_16_SNORM, NONE, WZYX),
}
}
-static inline enum a6xx_tex_swiz
-tex_swiz(unsigned swiz)
+enum a6xx_tex_swiz
+fd6_pipe2swiz(unsigned swiz)
{
switch (swiz) {
default:
}
}
-uint32_t
-fd6_tex_swiz(enum pipe_format format, unsigned swizzle_r, unsigned swizzle_g,
- unsigned swizzle_b, unsigned swizzle_a)
+void
+fd6_tex_swiz(enum pipe_format format, unsigned char *swiz,
+ unsigned swizzle_r, unsigned swizzle_g,
+ unsigned swizzle_b, unsigned swizzle_a)
{
const struct util_format_description *desc =
util_format_description(format);
- unsigned char swiz[4] = {
- swizzle_r, swizzle_g, swizzle_b, swizzle_a,
- }, rswiz[4];
+ const unsigned char uswiz[4] = {
+ swizzle_r, swizzle_g, swizzle_b, swizzle_a
+ };
+
+ /* Gallium expects stencil sampler to return (s,s,s,s), so massage
+ * the swizzle to do so.
+ */
+ if (format == PIPE_FORMAT_X24S8_UINT) {
+ const unsigned char stencil_swiz[4] = {
+ PIPE_SWIZZLE_W, PIPE_SWIZZLE_W, PIPE_SWIZZLE_W, PIPE_SWIZZLE_W
+ };
+ util_format_compose_swizzles(stencil_swiz, uswiz, swiz);
+ } else if (fd6_pipe2swap(format) != WZYX) {
+ /* Formats with a non-pass-through swap are permutations of RGBA
+ * formats. We program the permutation using the swap and don't
+ * need to compose the format swizzle with the user swizzle.
+ */
+ memcpy(swiz, uswiz, sizeof(uswiz));
+ } else {
+ /* Otherwise, it's an unswapped RGBA format or a format like L8 where
+ * we need the XXX1 swizzle from the gallium format description.
+ */
+ util_format_compose_swizzles(desc->swizzle, uswiz, swiz);
+ }
+}
+
+/* Compute the TEX_CONST_0 value for texture state, including SWIZ/SWAP/etc: */
+uint32_t
+fd6_tex_const_0(struct pipe_resource *prsc,
+ unsigned level, enum pipe_format format,
+ unsigned swizzle_r, unsigned swizzle_g,
+ unsigned swizzle_b, unsigned swizzle_a)
+{
+ struct fd_resource *rsc = fd_resource(prsc);
+ uint32_t swap, texconst0 = 0;
+ unsigned char swiz[4];
+
+ if (util_format_is_srgb(format)) {
+ texconst0 |= A6XX_TEX_CONST_0_SRGB;
+ }
+
+ if (rsc->tile_mode && !fd_resource_level_linear(prsc, level)) {
+ texconst0 |= A6XX_TEX_CONST_0_TILE_MODE(rsc->tile_mode);
+ swap = WZYX;
+ } else {
+ swap = fd6_pipe2swap(format);
+ }
+
+ fd6_tex_swiz(format, swiz,
+ swizzle_r, swizzle_g,
+ swizzle_b, swizzle_a);
- util_format_compose_swizzles(desc->swizzle, swiz, rswiz);
+ texconst0 |=
+ A6XX_TEX_CONST_0_FMT(fd6_pipe2tex(format)) |
+ A6XX_TEX_CONST_0_SAMPLES(fd_msaa_samples(prsc->nr_samples)) |
+ A6XX_TEX_CONST_0_SWAP(swap) |
+ A6XX_TEX_CONST_0_SWIZ_X(fd6_pipe2swiz(swiz[0])) |
+ A6XX_TEX_CONST_0_SWIZ_Y(fd6_pipe2swiz(swiz[1])) |
+ A6XX_TEX_CONST_0_SWIZ_Z(fd6_pipe2swiz(swiz[2])) |
+ A6XX_TEX_CONST_0_SWIZ_W(fd6_pipe2swiz(swiz[3]));
- return A6XX_TEX_CONST_0_SWIZ_X(tex_swiz(rswiz[0])) |
- A6XX_TEX_CONST_0_SWIZ_Y(tex_swiz(rswiz[1])) |
- A6XX_TEX_CONST_0_SWIZ_Z(tex_swiz(rswiz[2])) |
- A6XX_TEX_CONST_0_SWIZ_W(tex_swiz(rswiz[3]));
+ return texconst0;
}