[PATCH 1/3] etnaviv: Add support for extended texture formats
Wladimir J. van der Laan
laanwj at gmail.com
Tue May 16 08:41:00 UTC 2017
This adds support for extended texture formats through
TEXTURE_FORMAT_EXT.
Two of these extended formats are added:
- R8_SNORM
- R8G8_UNORM
---
src/gallium/drivers/etnaviv/etnaviv_format.c | 49 ++++++++++++++++++++++-----
src/gallium/drivers/etnaviv/etnaviv_format.h | 3 ++
src/gallium/drivers/etnaviv/etnaviv_texture.c | 3 +-
3 files changed, 45 insertions(+), 10 deletions(-)
This patch series adds support for extended and swizzled texture formats
on GC2000+. More can be added later, this just provides the base
infrastructure.
diff --git a/src/gallium/drivers/etnaviv/etnaviv_format.c b/src/gallium/drivers/etnaviv/etnaviv_format.c
index 6935584..88bb520 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_format.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_format.c
@@ -51,8 +51,13 @@ 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)
-/* vertex + texture */
-#define VT(pipe, vtxfmt, texfmt, rsfmt) \
+/* shift for extended texture formats */
+#define TX_FORMAT_MASK 0xff
+#define TX_FORMAT_EXT_SHIFT 8
+#define TX_FORMAT_EXT_MASK 0xff00
+
+/* vertex + texture (base) */
+#define VT(pipe, vtxfmt, texfmt, rsfmt) \
[PIPE_FORMAT_##pipe] = { \
.vtx = VIVS_FE_VERTEX_ELEMENT_CONFIG_TYPE_##vtxfmt, \
.tex = TEXTURE_FORMAT_##texfmt, \
@@ -60,7 +65,16 @@ struct etna_format {
.present = 1, \
}
-/* texture-only */
+/* vertex + texture (extended) */
+#define VTE(pipe, vtxfmt, extfmt, rsfmt) \
+ [PIPE_FORMAT_##pipe] = { \
+ .vtx = VIVS_FE_VERTEX_ELEMENT_CONFIG_TYPE_##vtxfmt, \
+ .tex = TEXTURE_FORMAT_EXT_##extfmt << TX_FORMAT_EXT_SHIFT, \
+ .rs = RS_FORMAT_##rsfmt, \
+ .present = 1, \
+ }
+
+/* texture-only (base) */
#define _T(pipe, fmt, rsfmt) \
[PIPE_FORMAT_##pipe] = { \
.vtx = ETNA_NO_MATCH, \
@@ -69,6 +83,15 @@ struct etna_format {
.present = 1, \
}
+/* texture-only (extended) */
+#define _TE(pipe, fmt, rsfmt) \
+ [PIPE_FORMAT_##pipe] = { \
+ .vtx = ETNA_NO_MATCH, \
+ .tex = TEXTURE_FORMAT_EXT_##fmt << TX_FORMAT_EXT_SHIFT, \
+ .rs = RS_FORMAT_##rsfmt, \
+ .present = 1, \
+ }
+
/* vertex-only */
#define V_(pipe, fmt, rsfmt) \
[PIPE_FORMAT_##pipe] = { \
@@ -81,7 +104,7 @@ struct etna_format {
static struct etna_format formats[PIPE_FORMAT_COUNT] = {
/* 8-bit */
V_(R8_UNORM, UNSIGNED_BYTE, NONE),
- V_(R8_SNORM, BYTE, NONE),
+ VTE(R8_SNORM, BYTE, R8_SNORM, NONE),
V_(R8_UINT, UNSIGNED_BYTE, NONE),
V_(R8_SINT, BYTE, NONE),
V_(R8_USCALED, UNSIGNED_BYTE, NONE),
@@ -108,7 +131,7 @@ static struct etna_format formats[PIPE_FORMAT_COUNT] = {
_T(B5G5R5A1_UNORM, A1R5G5B5, A1R5G5B5),
_T(B5G5R5X1_UNORM, X1R5G5B5, X1R5G5B5),
- V_(R8G8_UNORM, UNSIGNED_BYTE, NONE),
+ VTE(R8G8_UNORM, UNSIGNED_BYTE, G8R8, NONE),
V_(R8G8_SNORM, BYTE, NONE),
V_(R8G8_UINT, UNSIGNED_BYTE, NONE),
V_(R8G8_SINT, BYTE, NONE),
@@ -224,12 +247,20 @@ static struct etna_format formats[PIPE_FORMAT_COUNT] = {
uint32_t
translate_texture_format(enum pipe_format fmt)
{
- /* XXX with TEXTURE_FORMAT_EXT and swizzle on newer chips we can
- * support much more */
- if (!formats[fmt].present)
+ /* XXX with swizzle on newer chips we can support much more */
+ if (!formats[fmt].present || formats[fmt].tex == ETNA_NO_MATCH)
+ return ETNA_NO_MATCH;
+
+ return formats[fmt].tex & TX_FORMAT_MASK;
+}
+
+uint32_t
+translate_texture_format_ext(enum pipe_format fmt)
+{
+ if (!formats[fmt].present || formats[fmt].tex == ETNA_NO_MATCH)
return ETNA_NO_MATCH;
- return formats[fmt].tex;
+ return (formats[fmt].tex & TX_FORMAT_EXT_MASK) >> TX_FORMAT_EXT_SHIFT;
}
uint32_t
diff --git a/src/gallium/drivers/etnaviv/etnaviv_format.h b/src/gallium/drivers/etnaviv/etnaviv_format.h
index 549dfda..5dbab4d 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_format.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_format.h
@@ -36,6 +36,9 @@ uint32_t
translate_texture_format(enum pipe_format fmt);
uint32_t
+translate_texture_format_ext(enum pipe_format fmt);
+
+uint32_t
translate_rs_format(enum pipe_format fmt);
int
diff --git a/src/gallium/drivers/etnaviv/etnaviv_texture.c b/src/gallium/drivers/etnaviv/etnaviv_texture.c
index 3a84238..28df5b2 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_texture.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_texture.c
@@ -212,7 +212,8 @@ etna_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *prsc,
return NULL;
}
- sv->TE_SAMPLER_CONFIG1 = VIVS_TE_SAMPLER_CONFIG1_SWIZZLE_R(so->swizzle_r) |
+ sv->TE_SAMPLER_CONFIG1 = VIVS_TE_SAMPLER_CONFIG1_FORMAT_EXT(translate_texture_format_ext(sv->base.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) |
--
2.7.4
More information about the etnaviv
mailing list