Blender V5.0
gpu_testing.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "testing/testing.h"
6
7#include "BKE_global.hh"
8
9#include "GHOST_C-api.h"
10
11#include "GPU_platform.hh"
12
13struct GPUContext;
14
15namespace blender::gpu {
16
20class GPUTest : public ::testing::Test {
21 private:
22 static GHOST_SystemHandle ghost_system_;
23 static GHOST_ContextHandle ghost_context_;
24 static GPUContext *context_;
25
26 static int32_t prev_g_debug_;
27 std::string debug_group_name_;
28
29 protected:
30 static void SetUpTestSuite(GHOST_TDrawingContextType draw_context_type,
31 GPUBackendType gpu_backend_type,
32 int32_t g_debug_flags);
33 static void TearDownTestSuite();
34
35 void SetUp() override;
36 void TearDown() override;
37};
38
39#ifdef WITH_OPENGL_BACKEND
40class GPUOpenGLTest : public GPUTest {
41 public:
42 static void SetUpTestSuite()
43 {
44 GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeOpenGL,
47 }
48 static void TearDownTestSuite()
49 {
50 GPUTest::TearDownTestSuite();
51 }
52};
53
54class GPUOpenGLWorkaroundsTest : public GPUTest {
55 public:
56 static void SetUpTestSuite()
57 {
58 GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeOpenGL,
62 }
63 static void TearDownTestSuite()
64 {
65 GPUTest::TearDownTestSuite();
66 }
67};
68# define GPU_OPENGL_TEST(test_name) \
69 TEST_F(GPUOpenGLTest, test_name) \
70 { \
71 test_##test_name(); \
72 } \
73 TEST_F(GPUOpenGLWorkaroundsTest, test_name) \
74 { \
75 test_##test_name(); \
76 }
77#else
78# define GPU_OPENGL_TEST(test_name)
79#endif
80
81#ifdef WITH_METAL_BACKEND
82class GPUMetalTest : public GPUTest {
83 public:
84 static void SetUpTestSuite()
85 {
86 GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeMetal, GPU_BACKEND_METAL, G_DEBUG_GPU);
87 }
88 static void TearDownTestSuite()
89 {
90 GPUTest::TearDownTestSuite();
91 }
92};
93
94class GPUMetalWorkaroundsTest : public GPUTest {
95 public:
96 static void SetUpTestSuite()
97 {
98 GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeMetal,
101 }
102 static void TearDownTestSuite()
103 {
104 GPUTest::TearDownTestSuite();
105 }
106};
107# define GPU_METAL_TEST(test_name) \
108 TEST_F(GPUMetalTest, test_name) \
109 { \
110 test_##test_name(); \
111 } \
112 TEST_F(GPUMetalWorkaroundsTest, test_name) \
113 { \
114 test_##test_name(); \
115 }
116#else
117# define GPU_METAL_TEST(test_name)
118#endif
119
120#ifdef WITH_VULKAN_BACKEND
121class GPUVulkanTest : public GPUTest {
122 public:
123 static void SetUpTestSuite()
124 {
125 GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeVulkan,
128 }
129 static void TearDownTestSuite()
130 {
131 GPUTest::TearDownTestSuite();
132 }
133};
134
135class GPUVulkanWorkaroundsTest : public GPUTest {
136 public:
137 static void SetUpTestSuite()
138 {
139 GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeVulkan,
143 }
144 static void TearDownTestSuite()
145 {
146 GPUTest::TearDownTestSuite();
147 }
148};
149# define GPU_VULKAN_TEST(test_name) \
150 TEST_F(GPUVulkanTest, test_name) \
151 { \
152 test_##test_name(); \
153 } \
154 TEST_F(GPUVulkanWorkaroundsTest, test_name) \
155 { \
156 test_##test_name(); \
157 }
158#else
159# define GPU_VULKAN_TEST(test_name)
160#endif
161
162#define GPU_TEST(test_name) \
163 GPU_OPENGL_TEST(test_name) \
164 GPU_METAL_TEST(test_name) \
165 GPU_VULKAN_TEST(test_name)
166
167#define BLOCK_GPU_TEST_ON(device_type, os_type, driver_type, backend_type) \
168 if (!blender::tests::should_ignore_blocklist() && \
169 GPU_type_matches_ex(device_type, os_type, driver_type, backend_type)) \
170 { \
171 GTEST_SKIP(); \
172 return; \
173 }
174
175} // namespace blender::gpu
@ G_DEBUG_GPU
@ G_DEBUG_GPU_FORCE_WORKAROUNDS
@ G_DEBUG_GPU_SHADER_DEBUG_INFO
@ G_DEBUG_GPU_RENDERDOC
@ G_DEBUG_GPU_COMPILE_SHADERS
GHOST C-API function and type declarations.
GHOST_TDrawingContextType
static void TearDownTestSuite()
void TearDown() override
void SetUp() override
static void SetUpTestSuite(GHOST_TDrawingContextType draw_context_type, GPUBackendType gpu_backend_type, int32_t g_debug_flags)