gallium/osmesa: Fill out other format tests.
authorEric Anholt <eric@anholt.net>
Wed, 15 Jan 2020 00:17:39 +0000 (16:17 -0800)
committerMarge Bot <eric+marge@anholt.net>
Tue, 4 Feb 2020 17:48:08 +0000 (17:48 +0000)
Move expected values/bpp into the test params, add more formats now that
we've fixed context setup so that they work.

Reviewed-by: Danylo Piliaiev <danylo.piliaiev@globallogic.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3216>

src/gallium/targets/osmesa/test-render.cpp

index feff9f420c694cf496b63938aaf82cc95759f952..55d449c2132de1cdaf27342b9b67f6d42e0b110c 100644 (file)
@@ -7,9 +7,14 @@
 #include <gtest/gtest.h>
 
 #include "GL/osmesa.h"
+#include "util/macros.h"
 
-
-typedef std::array<GLenum, 2> Params;
+typedef struct {
+   unsigned format;
+   GLenum type;
+   int bpp;
+   uint64_t expected;
+} Params;
 
 class OSMesaRenderTestFixture : public testing::TestWithParam<Params> {};
 
@@ -17,7 +22,7 @@ std::string
 name_params(const testing::TestParamInfo<Params> params) {
    auto p = params.param;
    std::string first, second;
-   switch (p[0]) {
+   switch (p.format) {
    case OSMESA_RGBA:
       first = "rgba";
       break;
@@ -35,7 +40,7 @@ name_params(const testing::TestParamInfo<Params> params) {
       break;
    }
 
-   switch (p[1]) {
+   switch (p.type) {
    case GL_UNSIGNED_SHORT:
       second = "unsigned_short";
       break;
@@ -55,52 +60,69 @@ name_params(const testing::TestParamInfo<Params> params) {
 
 TEST_P(OSMesaRenderTestFixture, Render)
 {
-   auto params = GetParam();
+   auto p = GetParam();
    const int w = 2, h = 2;
-   uint8_t pixels[w * h * 4] = { 0 };
-   uint32_t expected;  // This should be green for the given color model
+   uint8_t pixels[w * h * 8] = { 0 };
 
    std::unique_ptr<osmesa_context, decltype(&OSMesaDestroyContext)> ctx{
-      OSMesaCreateContext(params[0], NULL), &OSMesaDestroyContext};
+      OSMesaCreateContext(p.format, NULL), &OSMesaDestroyContext};
    ASSERT_TRUE(ctx);
 
-   auto ret = OSMesaMakeCurrent(ctx.get(), &pixels, params[1], w, h);
+   auto ret = OSMesaMakeCurrent(ctx.get(), &pixels, p.type, w, h);
    ASSERT_EQ(ret, GL_TRUE);
 
-   int bpp = 4;
-   switch (params[0]) {
-   case OSMESA_RGB:
-      bpp = 3;
-      break;
-   case OSMESA_RGB_565:
-      bpp = 2;
-      break;
-   }
+   glClearColor(0.25, 1.0, 0.5, 0.75);
+
+   uint64_t expected = p.expected;
 
-   switch (params[0]) {
-   case OSMESA_RGBA:
-   case OSMESA_BGRA:
-   case OSMESA_RGB:
-      expected = 0xff << 8;
-      glClearColor(0, 1, 0, 0);
-      break;
-   case OSMESA_RGB_565:
-      expected = 0x3f << 5;
-      glClearColor(0, 1, 0, 0);
-      break;
-   case OSMESA_ARGB:
-      expected = 0xff << 24;
-      glClearColor(0, 0, 1, 0);
-      break;
-   }
    glClear(GL_COLOR_BUFFER_BIT);
    glFinish();
 
-   for (unsigned i = 0; i < w * h; i++) {
-      uint32_t color = 0;
-      memcpy(&color, &pixels[i * bpp], bpp);
+#if 0 /* XXX */
+   for (unsigned i = 0; i < ARRAY_SIZE(pixels); i += 4) {
+      fprintf(stderr, "pixel %d: %02x %02x %02x %02x\n",
+              i / 4,
+              pixels[i + 0],
+              pixels[i + 1],
+              pixels[i + 2],
+              pixels[i + 3]);
+   }
+#endif
 
-      ASSERT_EQ(expected, color);
+   for (unsigned i = 0; i < w * h; i++) {
+      switch (p.bpp) {
+      case 2: {
+         uint16_t color = 0;
+         memcpy(&color, &pixels[i * p.bpp], p.bpp);
+         ASSERT_EQ(expected, color);
+         break;
+      }
+
+      case 3: {
+         uint32_t color = ((pixels[i * p.bpp + 0] << 0) |
+                           (pixels[i * p.bpp + 1] << 8) |
+                           (pixels[i * p.bpp + 2] << 16));
+         ASSERT_EQ(expected, color);
+         break;
+      }
+
+      case 4: {
+         uint32_t color = 0;
+         memcpy(&color, &pixels[i * p.bpp], p.bpp);
+         ASSERT_EQ(expected, color);
+         break;
+      }
+
+      case 8: {
+         uint64_t color = 0;
+         memcpy(&color, &pixels[i * p.bpp], p.bpp);
+         ASSERT_EQ(expected, color);
+         break;
+      }
+
+      default:
+         unreachable("bad bpp");
+      }
    }
 }
 
@@ -108,10 +130,14 @@ INSTANTIATE_TEST_CASE_P(
    OSMesaRenderTest,
    OSMesaRenderTestFixture,
    testing::Values(
-      Params{ OSMESA_RGBA, GL_UNSIGNED_BYTE },
-      Params{ OSMESA_BGRA, GL_UNSIGNED_BYTE },
-      Params{ OSMESA_ARGB, GL_UNSIGNED_BYTE },
-      Params{ OSMESA_RGB, GL_UNSIGNED_BYTE }
+      Params{ OSMESA_RGBA, GL_UNSIGNED_BYTE,  4, 0xbf80ff40 },
+      Params{ OSMESA_BGRA, GL_UNSIGNED_BYTE,  4, 0xbf40ff80 },
+      Params{ OSMESA_ARGB, GL_UNSIGNED_BYTE,  4, 0x80ff40bf},
+      Params{ OSMESA_RGB,  GL_UNSIGNED_BYTE,  3, 0x80ff40 },
+      Params{ OSMESA_RGBA, GL_UNSIGNED_SHORT, 8, 0xbfff8000ffff4000ull },
+      Params{ OSMESA_RGB_565, GL_UNSIGNED_SHORT_5_6_5, 2, ((0x10 << 0) |
+                                                           (0x3f << 5) |
+                                                           (0x8 << 11)) }
    ),
    name_params
 );