From 673837bb8b4c41b002961d73388e96bd7f2426a7 Mon Sep 17 00:00:00 2001 From: Emma Anholt Date: Mon, 9 Jan 2023 13:29:13 -0800 Subject: [PATCH] gallium: Add a unit test for util_can_blit_via_copy_region(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Mike Blumenkrantz Reviewed-by: Marek Olšák Part-of: --- src/gallium/auxiliary/meson.build | 14 ++++ src/gallium/auxiliary/util/u_surface_test.cpp | 71 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/gallium/auxiliary/util/u_surface_test.cpp diff --git a/src/gallium/auxiliary/meson.build b/src/gallium/auxiliary/meson.build index 63a2a912092..0c6c1ee448b 100644 --- a/src/gallium/auxiliary/meson.build +++ b/src/gallium/auxiliary/meson.build @@ -508,6 +508,20 @@ libgallium = static_library( build_by_default : false ) +if with_tests + test('gallium-aux', + executable( + 'gallium-aux', + 'util/u_surface_test.cpp', + include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux], + link_with: libgallium, + dependencies : [idep_gtest], + ), + suite: 'gallium', + protocol : gtest_test_protocol, + ) +endif + libgalliumvl_stub = static_library( 'galliumvl_stub', 'vl/vl_stubs.c', diff --git a/src/gallium/auxiliary/util/u_surface_test.cpp b/src/gallium/auxiliary/util/u_surface_test.cpp new file mode 100644 index 00000000000..27f1352fcc8 --- /dev/null +++ b/src/gallium/auxiliary/util/u_surface_test.cpp @@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: MIT */ + +#include "u_box.h" +#include "u_surface.h" +#include + +struct pipe_resource +test_resource_with_format(pipe_format f) +{ + struct pipe_resource rsc; + memset(&rsc, 0, sizeof(rsc)); + + rsc.width0 = 1; + rsc.height0 = 1; + rsc.depth0 = 1; + rsc.format = f; + + return rsc; +} + +static struct pipe_blit_info +test_blit_with_formats(struct pipe_resource *src, pipe_format src_format, + struct pipe_resource *dst, pipe_format dst_format) +{ + struct pipe_blit_info info; + memset(&info, 0, sizeof(info)); + + info.dst.resource = dst; + info.dst.format = dst_format; + + info.src.resource = src; + info.src.format = src_format; + + info.mask = PIPE_MASK_RGBA; + info.filter = PIPE_TEX_FILTER_NEAREST; + info.scissor_enable = false; + info.alpha_blend = false, + + u_box_2d(0, 0, src->width0, src->height0, &info.src.box); + u_box_2d(0, 0, dst->width0, dst->height0, &info.dst.box); + + return info; +} + +TEST(util_can_blit_via_copy_region, formats) +{ + struct pipe_resource src_rgba8_unorm = test_resource_with_format(PIPE_FORMAT_R8G8B8A8_UNORM); + struct pipe_resource dst_rgba8_unorm = test_resource_with_format(PIPE_FORMAT_R8G8B8A8_UNORM); + struct pipe_resource src_rgbx8_unorm = test_resource_with_format(PIPE_FORMAT_R8G8B8X8_UNORM); + struct pipe_resource dst_rgbx8_unorm = test_resource_with_format(PIPE_FORMAT_R8G8B8X8_UNORM); + + /* Same-format blit should pass */ + struct pipe_blit_info rgba8_unorm_rgba8_unorm_blit = test_blit_with_formats(&src_rgba8_unorm, PIPE_FORMAT_R8G8B8A8_UNORM, + &dst_rgba8_unorm, PIPE_FORMAT_R8G8B8A8_UNORM); + ASSERT_TRUE(util_can_blit_via_copy_region(&rgba8_unorm_rgba8_unorm_blit, false, false)); + + /* Blit that should do sRGB encoding should fail. */ + struct pipe_blit_info rgba8_unorm_rgba8_srgb_blit = test_blit_with_formats(&src_rgba8_unorm, PIPE_FORMAT_R8G8B8A8_UNORM, + &dst_rgba8_unorm, PIPE_FORMAT_R8G8B8A8_SRGB); + ASSERT_FALSE(util_can_blit_via_copy_region(&rgba8_unorm_rgba8_srgb_blit, false, false)); + + /* RGBA->RGBX is fine, since A is ignored. */ + struct pipe_blit_info rgba8_unorm_rgbx8_unorm_blit = test_blit_with_formats(&src_rgba8_unorm, PIPE_FORMAT_R8G8B8A8_UNORM, + &dst_rgbx8_unorm, PIPE_FORMAT_R8G8B8X8_UNORM); + ASSERT_TRUE(util_can_blit_via_copy_region(&rgba8_unorm_rgbx8_unorm_blit, false, false)); + + /* RGBX->RGBA is invalid, since src A is undefined. */ + struct pipe_blit_info rgbx8_unorm_rgba8_unorm_blit = test_blit_with_formats(&src_rgbx8_unorm, PIPE_FORMAT_R8G8B8X8_UNORM, + &dst_rgba8_unorm, PIPE_FORMAT_R8G8B8A8_UNORM); + ASSERT_FALSE(util_can_blit_via_copy_region(&rgbx8_unorm_rgba8_unorm_blit, false, false)); +}