aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Gmeiner <[email protected]>2017-06-16 17:02:29 +0200
committerChristian Gmeiner <[email protected]>2017-06-26 19:56:39 +0200
commit751ae6afbefd6e0b3cbf9323995465d5a078c9fb (patch)
treec5a279ce23c6bc4bc5aa57038068ef4d14e3d826
parent0ddcccac4f73f33e8d22368fa663e0991a704cc8 (diff)
etnaviv: add support for swizzled texture formats
Passes all ext_texture_swizzle piglits. Signed-off-by: Christian Gmeiner <[email protected]> Reviewed-By: Wladimir J. van der Laan <[email protected]>
-rw-r--r--src/gallium/drivers/etnaviv/etnaviv_format.c103
-rw-r--r--src/gallium/drivers/etnaviv/etnaviv_format.h7
-rw-r--r--src/gallium/drivers/etnaviv/etnaviv_screen.c19
-rw-r--r--src/gallium/drivers/etnaviv/etnaviv_texture.c9
4 files changed, 99 insertions, 39 deletions
diff --git a/src/gallium/drivers/etnaviv/etnaviv_format.c b/src/gallium/drivers/etnaviv/etnaviv_format.c
index e9cd1040b5a..ee50b529622 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_format.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_format.c
@@ -40,6 +40,7 @@ struct etna_format {
unsigned tex;
unsigned rs;
boolean present;
+ const unsigned char tex_swiz[4];
};
#define RS_FORMAT_NONE ~0
@@ -51,22 +52,31 @@ struct etna_format {
#define RS_FORMAT_X8B8G8R8 (RS_FORMAT_X8R8G8B8 | RS_FORMAT_RB_SWAP)
#define RS_FORMAT_A8B8G8R8 (RS_FORMAT_A8R8G8B8 | RS_FORMAT_RB_SWAP)
+#define SWIZ(x,y,z,w) { \
+ PIPE_SWIZZLE_##x, \
+ PIPE_SWIZZLE_##y, \
+ PIPE_SWIZZLE_##z, \
+ PIPE_SWIZZLE_##w \
+}
+
/* vertex + texture */
-#define VT(pipe, vtxfmt, texfmt, rsfmt) \
+#define VT(pipe, vtxfmt, texfmt, texswiz, rsfmt) \
[PIPE_FORMAT_##pipe] = { \
.vtx = VIVS_FE_VERTEX_ELEMENT_CONFIG_TYPE_##vtxfmt, \
.tex = TEXTURE_FORMAT_##texfmt, \
.rs = RS_FORMAT_##rsfmt, \
.present = 1, \
+ .tex_swiz = texswiz, \
}
/* texture-only */
-#define _T(pipe, fmt, rsfmt) \
+#define _T(pipe, fmt, swiz, rsfmt) \
[PIPE_FORMAT_##pipe] = { \
.vtx = ETNA_NO_MATCH, \
.tex = TEXTURE_FORMAT_##fmt, \
.rs = RS_FORMAT_##rsfmt, \
.present = 1, \
+ .tex_swiz = swiz, \
}
/* vertex-only */
@@ -87,9 +97,9 @@ static struct etna_format formats[PIPE_FORMAT_COUNT] = {
V_(R8_USCALED, UNSIGNED_BYTE, NONE),
V_(R8_SSCALED, BYTE, NONE),
- _T(A8_UNORM, A8, NONE),
- _T(L8_UNORM, L8, NONE),
- _T(I8_UNORM, I8, NONE),
+ _T(A8_UNORM, A8, SWIZ(X, Y, Z, W), NONE),
+ _T(L8_UNORM, L8, SWIZ(X, Y, Z, W), NONE),
+ _T(I8_UNORM, I8, SWIZ(X, Y, Z, W), NONE),
/* 16-bit */
V_(R16_UNORM, UNSIGNED_SHORT, NONE),
@@ -100,15 +110,15 @@ static struct etna_format formats[PIPE_FORMAT_COUNT] = {
V_(R16_SSCALED, SHORT, NONE),
V_(R16_FLOAT, HALF_FLOAT, NONE),
- _T(B4G4R4A4_UNORM, A4R4G4B4, A4R4G4B4),
- _T(B4G4R4X4_UNORM, X4R4G4B4, X4R4G4B4),
+ _T(B4G4R4A4_UNORM, A4R4G4B4, SWIZ(X, Y, Z, W), A4R4G4B4),
+ _T(B4G4R4X4_UNORM, X4R4G4B4, SWIZ(X, Y, Z, W), X4R4G4B4),
- _T(L8A8_UNORM, A8L8, NONE),
+ _T(L8A8_UNORM, A8L8, SWIZ(X, Y, Z, W), NONE),
- _T(Z16_UNORM, D16, A4R4G4B4),
- _T(B5G6R5_UNORM, R5G6B5, R5G6B5),
- _T(B5G5R5A1_UNORM, A1R5G5B5, A1R5G5B5),
- _T(B5G5R5X1_UNORM, X1R5G5B5, X1R5G5B5),
+ _T(Z16_UNORM, D16, SWIZ(X, Y, Z, W), A4R4G4B4),
+ _T(B5G6R5_UNORM, R5G6B5, SWIZ(X, Y, Z, W), R5G6B5),
+ _T(B5G5R5A1_UNORM, A1R5G5B5, SWIZ(X, Y, Z, W), A1R5G5B5),
+ _T(B5G5R5X1_UNORM, X1R5G5B5, SWIZ(X, Y, Z, W), X1R5G5B5),
V_(R8G8_UNORM, UNSIGNED_BYTE, NONE),
V_(R8G8_SNORM, BYTE, NONE),
@@ -147,25 +157,25 @@ static struct etna_format formats[PIPE_FORMAT_COUNT] = {
V_(R8G8B8A8_UNORM, UNSIGNED_BYTE, A8B8G8R8),
V_(R8G8B8A8_SNORM, BYTE, A8B8G8R8),
- _T(R8G8B8X8_UNORM, X8B8G8R8, X8B8G8R8),
+ _T(R8G8B8X8_UNORM, X8B8G8R8, SWIZ(X, Y, Z, W), X8B8G8R8),
V_(R8G8B8A8_UINT, UNSIGNED_BYTE, A8B8G8R8),
V_(R8G8B8A8_SINT, BYTE, A8B8G8R8),
V_(R8G8B8A8_USCALED, UNSIGNED_BYTE, A8B8G8R8),
V_(R8G8B8A8_SSCALED, BYTE, A8B8G8R8),
- _T(R8G8B8A8_UNORM, A8B8G8R8, A8B8G8R8),
- _T(R8G8B8X8_UNORM, X8B8G8R8, X8B8G8R8),
+ _T(R8G8B8A8_UNORM, A8B8G8R8, SWIZ(X, Y, Z, W), A8B8G8R8),
+ _T(R8G8B8X8_UNORM, X8B8G8R8, SWIZ(X, Y, Z, W), X8B8G8R8),
- _T(B8G8R8A8_UNORM, A8R8G8B8, A8R8G8B8),
- _T(B8G8R8X8_UNORM, X8R8G8B8, X8R8G8B8),
+ _T(B8G8R8A8_UNORM, A8R8G8B8, SWIZ(X, Y, Z, W), A8R8G8B8),
+ _T(B8G8R8X8_UNORM, X8R8G8B8, SWIZ(X, Y, Z, W), X8R8G8B8),
V_(R10G10B10A2_UNORM, UNSIGNED_INT_10_10_10_2, NONE),
V_(R10G10B10A2_SNORM, INT_10_10_10_2, NONE),
V_(R10G10B10A2_USCALED, UNSIGNED_INT_10_10_10_2, NONE),
V_(R10G10B10A2_SSCALED, INT_10_10_10_2, NONE),
- _T(X8Z24_UNORM, D24S8, A8R8G8B8),
- _T(S8_UINT_Z24_UNORM, D24S8, A8R8G8B8),
+ _T(X8Z24_UNORM, D24S8, SWIZ(X, Y, Z, W), A8R8G8B8),
+ _T(S8_UINT_Z24_UNORM, D24S8, SWIZ(X, Y, Z, W), A8R8G8B8),
/* 48-bit */
V_(R16G16B16_UNORM, UNSIGNED_SHORT, NONE),
@@ -215,30 +225,65 @@ static struct etna_format formats[PIPE_FORMAT_COUNT] = {
V_(R32G32B32A32_FIXED, FIXED, NONE),
/* compressed */
- _T(ETC1_RGB8, ETC1, NONE),
+ _T(ETC1_RGB8, ETC1, SWIZ(X, Y, Z, W), NONE),
- _T(DXT1_RGB, DXT1, NONE),
- _T(DXT1_RGBA, DXT1, NONE),
- _T(DXT3_RGBA, DXT2_DXT3, NONE),
- _T(DXT3_RGBA, DXT2_DXT3, NONE),
- _T(DXT5_RGBA, DXT4_DXT5, NONE),
+ _T(DXT1_RGB, DXT1, SWIZ(X, Y, Z, W), NONE),
+ _T(DXT1_RGBA, DXT1, SWIZ(X, Y, Z, W), NONE),
+ _T(DXT3_RGBA, DXT2_DXT3, SWIZ(X, Y, Z, W), NONE),
+ _T(DXT3_RGBA, DXT2_DXT3, SWIZ(X, Y, Z, W), NONE),
+ _T(DXT5_RGBA, DXT4_DXT5, SWIZ(X, Y, Z, W), NONE),
/* YUV */
- _T(YUYV, YUY2, YUY2),
- _T(UYVY, UYVY, NONE),
+ _T(YUYV, YUY2, SWIZ(X, Y, Z, W), YUY2),
+ _T(UYVY, UYVY, SWIZ(X, Y, Z, W), NONE),
};
uint32_t
translate_texture_format(enum pipe_format fmt)
{
- /* XXX with swizzle on newer chips we can
- * support much more */
if (!formats[fmt].present)
return ETNA_NO_MATCH;
return formats[fmt].tex;
}
+bool
+texture_format_needs_swiz(enum pipe_format fmt)
+{
+ static const unsigned char def[4] = SWIZ(X, Y, Z, W);
+ bool swiz = false;
+
+ if (formats[fmt].present)
+ swiz = !memcmp(def, formats[fmt].tex_swiz, sizeof(formats[fmt].tex_swiz));
+
+ return swiz;
+}
+
+uint32_t
+get_texture_swiz(enum pipe_format fmt, unsigned swizzle_r,
+ unsigned swizzle_g, unsigned swizzle_b, unsigned swizzle_a)
+{
+ unsigned char swiz[4] = {
+ swizzle_r, swizzle_g, swizzle_b, swizzle_a,
+ }, rswiz[4];
+
+ assert(formats[fmt].present);
+ util_format_compose_swizzles(formats[fmt].tex_swiz, swiz, rswiz);
+
+ /* PIPE_SWIZZLE_ maps 1:1 to TEXTURE_SWIZZLE_ */
+ STATIC_ASSERT(PIPE_SWIZZLE_X == TEXTURE_SWIZZLE_RED);
+ STATIC_ASSERT(PIPE_SWIZZLE_Y == TEXTURE_SWIZZLE_GREEN);
+ STATIC_ASSERT(PIPE_SWIZZLE_Z == TEXTURE_SWIZZLE_BLUE);
+ STATIC_ASSERT(PIPE_SWIZZLE_W == TEXTURE_SWIZZLE_ALPHA);
+ STATIC_ASSERT(PIPE_SWIZZLE_0 == TEXTURE_SWIZZLE_ZERO);
+ STATIC_ASSERT(PIPE_SWIZZLE_1 == TEXTURE_SWIZZLE_ONE);
+
+ return VIVS_TE_SAMPLER_CONFIG1_SWIZZLE_R(rswiz[0]) |
+ VIVS_TE_SAMPLER_CONFIG1_SWIZZLE_G(rswiz[1]) |
+ VIVS_TE_SAMPLER_CONFIG1_SWIZZLE_B(rswiz[2]) |
+ VIVS_TE_SAMPLER_CONFIG1_SWIZZLE_A(rswiz[3]);
+}
+
uint32_t
translate_rs_format(enum pipe_format fmt)
{
diff --git a/src/gallium/drivers/etnaviv/etnaviv_format.h b/src/gallium/drivers/etnaviv/etnaviv_format.h
index 1170d79a6c1..543e30965d2 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_format.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_format.h
@@ -36,6 +36,13 @@
uint32_t
translate_texture_format(enum pipe_format fmt);
+bool
+texture_format_needs_swiz(enum pipe_format fmt);
+
+uint32_t
+get_texture_swiz(enum pipe_format fmt, unsigned swizzle_r,
+ unsigned swizzle_g, unsigned swizzle_b, unsigned swizzle_a);
+
uint32_t
translate_rs_format(enum pipe_format fmt);
diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.c b/src/gallium/drivers/etnaviv/etnaviv_screen.c
index a69aef09cdd..19d3d91192b 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_screen.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_screen.c
@@ -155,6 +155,7 @@ etna_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
return true; /* VIV_FEATURE(priv->dev, chipMinorFeatures1,
NON_POWER_OF_TWO); */
+ case PIPE_CAP_TEXTURE_SWIZZLE:
case PIPE_CAP_PRIMITIVE_RESTART:
return VIV_FEATURE(screen, chipMinorFeatures1, HALTI0);
@@ -164,7 +165,6 @@ etna_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
/* Unsupported features. */
case PIPE_CAP_SEAMLESS_CUBE_MAP:
- case PIPE_CAP_TEXTURE_SWIZZLE: /* XXX supported on gc2000 */
case PIPE_CAP_COMPUTE: /* XXX supported on gc2000 */
case PIPE_CAP_MIXED_COLORBUFFER_FORMATS: /* only one colorbuffer supported, so mixing makes no sense */
case PIPE_CAP_CONDITIONAL_RENDER: /* no occlusion queries */
@@ -459,15 +459,24 @@ etna_screen_get_timestamp(struct pipe_screen *pscreen)
}
static bool
-gpu_supports_texure_format(struct etna_screen *screen, uint32_t fmt)
+gpu_supports_texure_format(struct etna_screen *screen, uint32_t fmt,
+ enum pipe_format format)
{
+ bool supported = true;
+
if (fmt == TEXTURE_FORMAT_ETC1)
- return VIV_FEATURE(screen, chipFeatures, ETC1_TEXTURE_COMPRESSION);
+ supported = VIV_FEATURE(screen, chipFeatures, ETC1_TEXTURE_COMPRESSION);
if (fmt >= TEXTURE_FORMAT_DXT1 && fmt <= TEXTURE_FORMAT_DXT4_DXT5)
- return VIV_FEATURE(screen, chipFeatures, DXT_TEXTURE_COMPRESSION);
+ supported = VIV_FEATURE(screen, chipFeatures, DXT_TEXTURE_COMPRESSION);
if (fmt & EXT_FORMAT)
+ supported = VIV_FEATURE(screen, chipMinorFeatures1, HALTI0);
+
+ if (!supported)
+ return false;
+
+ if (texture_format_needs_swiz(format))
return VIV_FEATURE(screen, chipMinorFeatures1, HALTI0);
return true;
@@ -514,7 +523,7 @@ etna_screen_is_format_supported(struct pipe_screen *pscreen,
if (usage & PIPE_BIND_SAMPLER_VIEW) {
uint32_t fmt = translate_texture_format(format);
- if (!gpu_supports_texure_format(screen, fmt))
+ if (!gpu_supports_texure_format(screen, fmt, format))
fmt = ETNA_NO_MATCH;
if (sample_count < 2 && fmt != ETNA_NO_MATCH)
diff --git a/src/gallium/drivers/etnaviv/etnaviv_texture.c b/src/gallium/drivers/etnaviv/etnaviv_texture.c
index f973bcb77eb..05fc7da58f8 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_texture.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_texture.c
@@ -163,6 +163,9 @@ etna_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *prsc,
struct etna_context *ctx = etna_context(pctx);
const uint32_t format = translate_texture_format(so->format);
const bool ext = !!(format & EXT_FORMAT);
+ const uint32_t swiz = get_texture_swiz(so->format, so->swizzle_r,
+ so->swizzle_g, so->swizzle_b,
+ so->swizzle_a);
if (!sv)
return NULL;
@@ -217,11 +220,7 @@ etna_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *prsc,
}
sv->TE_SAMPLER_CONFIG1 = COND(ext, VIVS_TE_SAMPLER_CONFIG1_FORMAT_EXT(format)) |
- VIVS_TE_SAMPLER_CONFIG1_SWIZZLE_R(so->swizzle_r) |
- VIVS_TE_SAMPLER_CONFIG1_SWIZZLE_G(so->swizzle_g) |
- VIVS_TE_SAMPLER_CONFIG1_SWIZZLE_B(so->swizzle_b) |
- VIVS_TE_SAMPLER_CONFIG1_SWIZZLE_A(so->swizzle_a) |
- VIVS_TE_SAMPLER_CONFIG1_HALIGN(res->halign);
+ VIVS_TE_SAMPLER_CONFIG1_HALIGN(res->halign) | swiz;
sv->TE_SAMPLER_SIZE = VIVS_TE_SAMPLER_SIZE_WIDTH(res->base.width0) |
VIVS_TE_SAMPLER_SIZE_HEIGHT(res->base.height0);
sv->TE_SAMPLER_LOG_SIZE =