From dd899fd43ebc56fee6ad41126db340a9c2f7bc72 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 14 Jan 2020 16:17:39 -0800 Subject: [PATCH] gallium/osmesa: Fill out other format tests. 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 Part-of: --- src/gallium/targets/osmesa/test-render.cpp | 110 +++++++++++++-------- 1 file changed, 68 insertions(+), 42 deletions(-) diff --git a/src/gallium/targets/osmesa/test-render.cpp b/src/gallium/targets/osmesa/test-render.cpp index feff9f420c6..55d449c2132 100644 --- a/src/gallium/targets/osmesa/test-render.cpp +++ b/src/gallium/targets/osmesa/test-render.cpp @@ -7,9 +7,14 @@ #include #include "GL/osmesa.h" +#include "util/macros.h" - -typedef std::array Params; +typedef struct { + unsigned format; + GLenum type; + int bpp; + uint64_t expected; +} Params; class OSMesaRenderTestFixture : public testing::TestWithParam {}; @@ -17,7 +22,7 @@ std::string name_params(const testing::TestParamInfo 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) { 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) { 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 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 ); -- 2.30.2