From ef9362acb81bd8615cd2f9014ca9880ae3d7e738 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 2 Dec 2020 17:03:33 -0800 Subject: [PATCH] gallium/osmesa: Return cleanly for OSMesaGetDepthBuffer() with no depth. This makes our behavior match classic. Closes: #2034 Reviewed-by: Adam Jackson Part-of: --- src/gallium/frontends/osmesa/osmesa.c | 8 ++++++++ src/gallium/targets/osmesa/test-render.cpp | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/gallium/frontends/osmesa/osmesa.c b/src/gallium/frontends/osmesa/osmesa.c index 5c7f27d..7d06c8d 100644 --- a/src/gallium/frontends/osmesa/osmesa.c +++ b/src/gallium/frontends/osmesa/osmesa.c @@ -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); diff --git a/src/gallium/targets/osmesa/test-render.cpp b/src/gallium/targets/osmesa/test-render.cpp index 39638f6..0ab1d55 100644 --- a/src/gallium/targets/osmesa/test-render.cpp +++ b/src/gallium/targets/osmesa/test-render.cpp @@ -216,6 +216,25 @@ TEST(OSMesaRenderTest, depth) EXPECT_EQ(depth[w * 1 + 1], 0x00000000); } +TEST(OSMesaRenderTest, depth_get_no_attachment) +{ + std::unique_ptr 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) -- 2.7.4