summaryrefslogtreecommitdiffstats
path: root/src/mesa/state_tracker
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2014-03-06 11:45:42 -0700
committerBrian Paul <[email protected]>2014-03-07 07:31:29 -0700
commit6d2dffe8b143b2f81179279d25d3ac247f4e278f (patch)
treec7742c4466316e97eea1aef47b709ef665522c6a /src/mesa/state_tracker
parentd8f7e3d79ede749e59af9092acac4405e5c7866c (diff)
st/mesa: add test_format_conversion() debug function
To check that the st_mesa_format_to_pipe_format() and st_pipe_format_to_mesa_format() functions correctly convert all corresponding Mesa/Gallium formats. This found that MESA_FORMAT_YCBCR_REV was missing in st_mesa_format_to_pipe_format(). Fixed that too. Reviewed-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r--src/mesa/state_tracker/st_format.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
index 0be900e7777..a55ee307979 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -121,6 +121,8 @@ st_mesa_format_to_pipe_format(mesa_format mesaFormat)
return PIPE_FORMAT_Z32_FLOAT_S8X24_UINT;
case MESA_FORMAT_YCBCR:
return PIPE_FORMAT_UYVY;
+ case MESA_FORMAT_YCBCR_REV:
+ return PIPE_FORMAT_YUYV;
case MESA_FORMAT_RGB_DXT1:
return PIPE_FORMAT_DXT1_RGB;
case MESA_FORMAT_RGBA_DXT1:
@@ -759,13 +761,41 @@ st_pipe_format_to_mesa_format(enum pipe_format format)
return MESA_FORMAT_R8G8B8A8_SRGB;
default:
- assert(0);
return MESA_FORMAT_NONE;
}
}
/**
+ * Debug only: check that the two functions above correctly map
+ * Mesa formats to Gallium formats and back again.
+ */
+static void
+test_format_conversion(void)
+{
+ GLuint i;
+
+ /* test all Mesa formats */
+ for (i = 1; i < MESA_FORMAT_COUNT; i++) {
+ enum pipe_format pf = st_mesa_format_to_pipe_format(i);
+ if (pf != PIPE_FORMAT_NONE) {
+ mesa_format mf = st_pipe_format_to_mesa_format(pf);
+ assert(mf == i);
+ }
+ }
+
+ /* Test all Gallium formats */
+ for (i = 1; i < PIPE_FORMAT_COUNT; i++) {
+ mesa_format mf = st_pipe_format_to_mesa_format(i);
+ if (mf != MESA_FORMAT_NONE) {
+ enum pipe_format pf = st_mesa_format_to_pipe_format(mf);
+ assert(pf == i);
+ }
+ }
+}
+
+
+/**
* Map GL texture formats to Gallium pipe formats.
*/
struct format_mapping
@@ -1641,6 +1671,18 @@ st_choose_format(struct st_context *st, GLenum internalFormat,
int i, j;
enum pipe_format pf;
+#ifdef DEBUG
+ {
+ static boolean firstCall = TRUE;
+ if (firstCall) {
+ test_format_conversion();
+ firstCall = FALSE;
+ }
+ }
+#else
+ (void) test_format_conversion;
+#endif
+
/* can't render to compressed formats at this time */
if (_mesa_is_compressed_format(st->ctx, internalFormat)
&& (bindings & ~PIPE_BIND_SAMPLER_VIEW)) {