gallium/osmesa: Return cleanly for OSMesaGetDepthBuffer() with no depth.
authorEric Anholt <eric@anholt.net>
Thu, 3 Dec 2020 01:03:33 +0000 (17:03 -0800)
committerEric Anholt <eric@anholt.net>
Sat, 5 Dec 2020 00:01:00 +0000 (16:01 -0800)
This makes our behavior match classic.

Closes: #2034
Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7886>

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

index 5c7f27d..7d06c8d 100644 (file)
@@ -918,6 +918,14 @@ OSMesaGetDepthBuffer(OSMesaContext c, GLint *width, GLint *height,
    struct osmesa_buffer *osbuffer = c->current_buffer;
    struct pipe_resource *res = osbuffer->textures[ST_ATTACHMENT_DEPTH_STENCIL];
 
+   if (!res) {
+      *width = 0;
+      *height = 0;
+      *bytesPerValue = 0;
+      *buffer = NULL;
+      return GL_FALSE;
+   }
+
    *width = res->width0;
    *height = res->height0;
    *bytesPerValue = util_format_get_blocksize(res->format);
index 39638f6..0ab1d55 100644 (file)
@@ -216,6 +216,25 @@ TEST(OSMesaRenderTest, depth)
    EXPECT_EQ(depth[w * 1 + 1], 0x00000000);
 }
 
+TEST(OSMesaRenderTest, depth_get_no_attachment)
+{
+   std::unique_ptr<osmesa_context, decltype(&OSMesaDestroyContext)> ctx{
+      OSMesaCreateContextExt(OSMESA_RGBA, 0, 0, 0, NULL), &OSMesaDestroyContext};
+   ASSERT_TRUE(ctx);
+
+   uint32_t pixel;
+   auto ret = OSMesaMakeCurrent(ctx.get(), &pixel, GL_UNSIGNED_BYTE, 1, 1);
+   ASSERT_EQ(ret, GL_TRUE);
+
+   uint32_t *depth;
+   GLint dw = 1, dh = 1, depth_cpp = 1;
+   ASSERT_EQ(false, OSMesaGetDepthBuffer(ctx.get(), &dw, &dh, &depth_cpp, (void **)&depth));
+   ASSERT_EQ(depth_cpp, NULL);
+   ASSERT_EQ(dw, 0);
+   ASSERT_EQ(dh, 0);
+   ASSERT_EQ(depth_cpp, 0);
+}
+
 static uint32_t be_bswap32(uint32_t x)
 {
    if (UTIL_ARCH_BIG_ENDIAN)