[Mesa-dev] [PATCH 2/2] gallium/util: add util_format_snorm8_to_sint8 (from radeonsi)
Marek Olšák
maraeo at gmail.com
Tue Jan 15 17:44:50 UTC 2019
From: Marek Olšák <marek.olsak at amd.com>
---
src/gallium/auxiliary/util/u_format.c | 40 ++++++++++++++++++++++++++
src/gallium/auxiliary/util/u_format.h | 3 ++
src/gallium/drivers/radeonsi/si_blit.c | 32 ++-------------------
3 files changed, 45 insertions(+), 30 deletions(-)
diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c
index 231e89017b4..862061a8ec2 100644
--- a/src/gallium/auxiliary/util/u_format.c
+++ b/src/gallium/auxiliary/util/u_format.c
@@ -879,10 +879,50 @@ void util_format_unswizzle_4f(float *dst, const float *src,
break;
case PIPE_SWIZZLE_Z:
dst[2] = src[i];
break;
case PIPE_SWIZZLE_W:
dst[3] = src[i];
break;
}
}
}
+
+enum pipe_format
+util_format_snorm8_to_sint8(enum pipe_format format)
+{
+ switch (format) {
+ case PIPE_FORMAT_R8_SNORM:
+ return PIPE_FORMAT_R8_SINT;
+ case PIPE_FORMAT_R8G8_SNORM:
+ return PIPE_FORMAT_R8G8_SINT;
+ case PIPE_FORMAT_R8G8B8_SNORM:
+ return PIPE_FORMAT_R8G8B8_SINT;
+ case PIPE_FORMAT_R8G8B8A8_SNORM:
+ return PIPE_FORMAT_R8G8B8A8_SINT;
+
+ case PIPE_FORMAT_A8_SNORM:
+ return PIPE_FORMAT_A8_SINT;
+ case PIPE_FORMAT_L8_SNORM:
+ return PIPE_FORMAT_L8_SINT;
+ case PIPE_FORMAT_L8A8_SNORM:
+ return PIPE_FORMAT_L8A8_SINT;
+ case PIPE_FORMAT_I8_SNORM:
+ return PIPE_FORMAT_I8_SINT;
+
+ case PIPE_FORMAT_R8G8B8X8_SNORM:
+ return PIPE_FORMAT_R8G8B8X8_SINT;
+ case PIPE_FORMAT_R8A8_SNORM:
+ return PIPE_FORMAT_R8A8_SINT;
+ case PIPE_FORMAT_A8L8_SNORM:
+ return PIPE_FORMAT_A8L8_SINT;
+ case PIPE_FORMAT_G8R8_SNORM:
+ return PIPE_FORMAT_G8R8_SINT;
+ case PIPE_FORMAT_A8B8G8R8_SNORM:
+ return PIPE_FORMAT_A8B8G8R8_SINT;
+ case PIPE_FORMAT_X8B8G8R8_SNORM:
+ return PIPE_FORMAT_X8B8G8R8_SINT;
+
+ default:
+ return format;
+ }
+}
diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h
index 8dcc438a4a1..0c0c505e391 100644
--- a/src/gallium/auxiliary/util/u_format.h
+++ b/src/gallium/auxiliary/util/u_format.h
@@ -1351,15 +1351,18 @@ void util_format_apply_color_swizzle(union pipe_color_union *dst,
const union pipe_color_union *src,
const unsigned char swz[4],
const boolean is_integer);
void pipe_swizzle_4f(float *dst, const float *src,
const unsigned char swz[4]);
void util_format_unswizzle_4f(float *dst, const float *src,
const unsigned char swz[4]);
+enum pipe_format
+util_format_snorm8_to_sint8(enum pipe_format format);
+
#ifdef __cplusplus
} // extern "C" {
#endif
#endif /* ! U_FORMAT_H */
diff --git a/src/gallium/drivers/radeonsi/si_blit.c b/src/gallium/drivers/radeonsi/si_blit.c
index 69b1af02db0..16be11247e4 100644
--- a/src/gallium/drivers/radeonsi/si_blit.c
+++ b/src/gallium/drivers/radeonsi/si_blit.c
@@ -1005,50 +1005,22 @@ void si_resource_copy_region(struct pipe_context *ctx,
assert(0);
}
}
}
/* SNORM8 blitting has precision issues on some chips. Use the SINT
* equivalent instead, which doesn't force DCC decompression.
* Note that some chips avoid this issue by using SDMA.
*/
if (util_format_is_snorm8(dst_templ.format)) {
- switch (dst_templ.format) {
- case PIPE_FORMAT_R8_SNORM:
- dst_templ.format = src_templ.format = PIPE_FORMAT_R8_SINT;
- break;
- case PIPE_FORMAT_R8G8_SNORM:
- dst_templ.format = src_templ.format = PIPE_FORMAT_R8G8_SINT;
- break;
- case PIPE_FORMAT_R8G8B8X8_SNORM:
- dst_templ.format = src_templ.format = PIPE_FORMAT_R8G8B8X8_SINT;
- break;
- case PIPE_FORMAT_R8G8B8A8_SNORM:
- /* There are no SINT variants for ABGR and XBGR, so we have to use RGBA. */
- case PIPE_FORMAT_A8B8G8R8_SNORM:
- case PIPE_FORMAT_X8B8G8R8_SNORM:
- dst_templ.format = src_templ.format = PIPE_FORMAT_R8G8B8A8_SINT;
- break;
- case PIPE_FORMAT_A8_SNORM:
- dst_templ.format = src_templ.format = PIPE_FORMAT_A8_SINT;
- break;
- case PIPE_FORMAT_L8_SNORM:
- dst_templ.format = src_templ.format = PIPE_FORMAT_L8_SINT;
- break;
- case PIPE_FORMAT_L8A8_SNORM:
- dst_templ.format = src_templ.format = PIPE_FORMAT_L8A8_SINT;
- break;
- case PIPE_FORMAT_I8_SNORM:
- dst_templ.format = src_templ.format = PIPE_FORMAT_I8_SINT;
- break;
- default:; /* fall through */
- }
+ dst_templ.format = src_templ.format =
+ util_format_snorm8_to_sint8(dst_templ.format);
}
vi_disable_dcc_if_incompatible_format(sctx, dst, dst_level,
dst_templ.format);
vi_disable_dcc_if_incompatible_format(sctx, src, src_level,
src_templ.format);
/* Initialize the surface. */
dst_view = si_create_surface_custom(ctx, dst, &dst_templ,
dst_width0, dst_height0,
--
2.17.1
More information about the mesa-dev
mailing list