etnaviv: implement texture comparator
[mesa.git] / src / gallium / drivers / etnaviv / etnaviv_translate.h
index e8466d63ff109a8f0e7b08ad527befaacb3889b8..4e9b2d5249ad7a7058d174ec33b94d349ff3ce68 100644 (file)
 
 #include "etnaviv_debug.h"
 #include "etnaviv_format.h"
-#include "etnaviv_tiling.h"
 #include "etnaviv_util.h"
 #include "hw/cmdstream.xml.h"
+#include "hw/common_3d.xml.h"
 #include "hw/state.xml.h"
 #include "hw/state_3d.xml.h"
 
 #include "util/u_format.h"
-
-#include <stdio.h>
+#include "util/u_math.h"
 
 /* Returned when there is no match of pipe value to etna value */
 #define ETNA_NO_MATCH (~0)
@@ -277,24 +276,33 @@ translate_depth_format(enum pipe_format fmt)
 
 /* render target format for MSAA */
 static inline uint32_t
-translate_msaa_format(enum pipe_format fmt)
+translate_ts_format(enum pipe_format fmt)
 {
    /* Note: Pipe format convention is LSB to MSB, VIVS is MSB to LSB */
    switch (fmt) {
    case PIPE_FORMAT_B4G4R4X4_UNORM:
-      return VIVS_TS_MEM_CONFIG_MSAA_FORMAT_A4R4G4B4;
    case PIPE_FORMAT_B4G4R4A4_UNORM:
-      return VIVS_TS_MEM_CONFIG_MSAA_FORMAT_A4R4G4B4;
+      return COMPRESSION_FORMAT_A4R4G4B4;
    case PIPE_FORMAT_B5G5R5X1_UNORM:
-      return VIVS_TS_MEM_CONFIG_MSAA_FORMAT_A1R5G5B5;
+      return COMPRESSION_FORMAT_A1R5G5B5;
    case PIPE_FORMAT_B5G5R5A1_UNORM:
-      return VIVS_TS_MEM_CONFIG_MSAA_FORMAT_A1R5G5B5;
+      return COMPRESSION_FORMAT_A1R5G5B5;
    case PIPE_FORMAT_B5G6R5_UNORM:
-      return VIVS_TS_MEM_CONFIG_MSAA_FORMAT_R5G6B5;
+      return COMPRESSION_FORMAT_R5G6B5;
    case PIPE_FORMAT_B8G8R8X8_UNORM:
-      return VIVS_TS_MEM_CONFIG_MSAA_FORMAT_X8R8G8B8;
+   case PIPE_FORMAT_B8G8R8X8_SRGB:
+   case PIPE_FORMAT_R8G8B8X8_UNORM:
+      return COMPRESSION_FORMAT_X8R8G8B8;
    case PIPE_FORMAT_B8G8R8A8_UNORM:
-      return VIVS_TS_MEM_CONFIG_MSAA_FORMAT_A8R8G8B8;
+   case PIPE_FORMAT_B8G8R8A8_SRGB:
+   case PIPE_FORMAT_R8G8B8A8_UNORM:
+      return COMPRESSION_FORMAT_A8R8G8B8;
+   case PIPE_FORMAT_S8_UINT_Z24_UNORM:
+      return COMPRESSION_FORMAT_D24S8;
+   case PIPE_FORMAT_X8Z24_UNORM:
+      return COMPRESSION_FORMAT_D24X8;
+   case PIPE_FORMAT_Z16_UNORM:
+      return COMPRESSION_FORMAT_D16;
    /* MSAA with YUYV not supported */
    default:
       return ETNA_NO_MATCH;
@@ -405,53 +413,6 @@ etna_layout_multiple(unsigned layout, unsigned pixel_pipes, bool rs_align,
    }
 }
 
-/* return 32-bit clear pattern for color */
-static inline uint32_t
-translate_clear_color(enum pipe_format format,
-                      const union pipe_color_union *color)
-{
-   uint32_t clear_value = 0;
-
-   // XXX util_pack_color
-   switch (format) {
-   case PIPE_FORMAT_B8G8R8A8_UNORM:
-   case PIPE_FORMAT_B8G8R8X8_UNORM:
-   case PIPE_FORMAT_R8G8B8A8_UNORM:
-   case PIPE_FORMAT_R8G8B8X8_UNORM:
-      clear_value = etna_cfloat_to_uintN(color->f[2], 8) |
-                    (etna_cfloat_to_uintN(color->f[1], 8) << 8) |
-                    (etna_cfloat_to_uintN(color->f[0], 8) << 16) |
-                    (etna_cfloat_to_uintN(color->f[3], 8) << 24);
-      break;
-   case PIPE_FORMAT_B4G4R4X4_UNORM:
-   case PIPE_FORMAT_B4G4R4A4_UNORM:
-      clear_value = etna_cfloat_to_uintN(color->f[2], 4) |
-                    (etna_cfloat_to_uintN(color->f[1], 4) << 4) |
-                    (etna_cfloat_to_uintN(color->f[0], 4) << 8) |
-                    (etna_cfloat_to_uintN(color->f[3], 4) << 12);
-      clear_value |= clear_value << 16;
-      break;
-   case PIPE_FORMAT_B5G5R5X1_UNORM:
-   case PIPE_FORMAT_B5G5R5A1_UNORM:
-      clear_value = etna_cfloat_to_uintN(color->f[2], 5) |
-                    (etna_cfloat_to_uintN(color->f[1], 5) << 5) |
-                    (etna_cfloat_to_uintN(color->f[0], 5) << 10) |
-                    (etna_cfloat_to_uintN(color->f[3], 1) << 15);
-      clear_value |= clear_value << 16;
-      break;
-   case PIPE_FORMAT_B5G6R5_UNORM:
-      clear_value = etna_cfloat_to_uintN(color->f[2], 5) |
-                    (etna_cfloat_to_uintN(color->f[1], 6) << 5) |
-                    (etna_cfloat_to_uintN(color->f[0], 5) << 11);
-      clear_value |= clear_value << 16;
-      break;
-   default:
-      DBG("Unhandled pipe format for color clear: %i", format);
-   }
-
-   return clear_value;
-}
-
 static inline uint32_t
 translate_clear_depth_stencil(enum pipe_format format, float depth,
                               unsigned stencil)
@@ -515,4 +476,50 @@ translate_samples_to_xyscale(int num_samples, int *xscale_out, int *yscale_out,
    return true;
 }
 
+static inline uint32_t
+translate_texture_target(unsigned target)
+{
+   switch (target) {
+   case PIPE_TEXTURE_1D:
+      return TEXTURE_TYPE_1D;
+   case PIPE_TEXTURE_2D:
+   case PIPE_TEXTURE_RECT:
+   case PIPE_TEXTURE_1D_ARRAY:
+      return TEXTURE_TYPE_2D;
+   case PIPE_TEXTURE_CUBE:
+      return TEXTURE_TYPE_CUBE_MAP;
+   case PIPE_TEXTURE_3D:
+   case PIPE_TEXTURE_2D_ARRAY:
+      return TEXTURE_TYPE_3D;
+   default:
+      DBG("Unhandled texture target: %i", target);
+      return ETNA_NO_MATCH;
+   }
+}
+
+static inline uint32_t
+translate_texture_compare(enum pipe_compare_func compare_func)
+{
+   switch (compare_func) {
+   case PIPE_FUNC_NEVER:
+      return TEXTURE_COMPARE_FUNC_NEVER;
+   case PIPE_FUNC_LESS:
+      return TEXTURE_COMPARE_FUNC_LESS;
+   case PIPE_FUNC_EQUAL:
+      return TEXTURE_COMPARE_FUNC_EQUAL;
+   case PIPE_FUNC_LEQUAL:
+      return TEXTURE_COMPARE_FUNC_LEQUAL;
+   case PIPE_FUNC_GREATER:
+      return TEXTURE_COMPARE_FUNC_GREATER;
+   case PIPE_FUNC_NOTEQUAL:
+      return TEXTURE_COMPARE_FUNC_NOTEQUAL;
+   case PIPE_FUNC_GEQUAL:
+      return TEXTURE_COMPARE_FUNC_GEQUAL;
+   case PIPE_FUNC_ALWAYS:
+      return TEXTURE_COMPARE_FUNC_ALWAYS;
+   default:
+      unreachable("Invalid compare func");
+   }
+}
+
 #endif