util: Move gallium's PIPE_FORMAT utils to /util/format/
[mesa.git] / src / gallium / drivers / freedreno / freedreno_util.c
index c8f2127c9100203df7d06fd03f7b11d887b0ba44..bf1e05ba740ac0f4089b1cfa0d3b44539f56d699 100644 (file)
@@ -1,5 +1,3 @@
-/* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
-
 /*
  * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
  *
@@ -27,7 +25,7 @@
  */
 
 #include "pipe/p_defines.h"
-#include "util/u_format.h"
+#include "util/format/u_format.h"
 
 #include "freedreno_util.h"
 
@@ -67,6 +65,26 @@ fd_pipe2index(enum pipe_format format)
        }
 }
 
+/* we need to special case a bit the depth/stencil restore, because we are
+ * using the texture sampler to blit into the depth/stencil buffer, *not*
+ * into a color buffer.  Otherwise fdN_tex_swiz() will do the wrong thing,
+ * as it is assuming that you are sampling into normal render target..
+ */
+enum pipe_format
+fd_gmem_restore_format(enum pipe_format format)
+{
+       switch (format) {
+       case PIPE_FORMAT_Z24X8_UNORM:
+       case PIPE_FORMAT_Z24_UNORM_S8_UINT:
+               return PIPE_FORMAT_R8G8B8A8_UNORM;
+       case PIPE_FORMAT_Z16_UNORM:
+               return PIPE_FORMAT_R8G8_UNORM;
+       case PIPE_FORMAT_S8_UINT:
+               return PIPE_FORMAT_R8_UNORM;
+       default:
+               return format;
+       }
+}
 
 enum adreno_rb_blend_factor
 fd_blend_factor(unsigned factor)