Blender V5.3
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_IContext.hh"
10#include "GHOST_ISystem.hh"
11
12#include "GPU_platform.hh"
13
14namespace blender {
15struct GPUContext;
16}
17
18namespace blender::gpu {
19
23class GPUTest : public ::testing::Test {
24 private:
25 static GHOST_ISystem *ghost_system_;
26 static GHOST_IContext *ghost_context_;
27 static GPUContext *context_;
28
29 static int32_t prev_g_debug_;
30 std::string debug_group_name_;
31
32 protected:
33 static void SetUpTestSuite(GHOST_TDrawingContextType draw_context_type,
34 GPUBackendType gpu_backend_type,
35 int32_t g_debug_flags);
36 static void TearDownTestSuite();
37
38 void SetUp() override;
39 void TearDown() override;
40};
41
42#ifdef WITH_OPENGL_BACKEND
43class GPUOpenGLTest : public GPUTest {
44 public:
45 static void SetUpTestSuite()
46 {
47 GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeOpenGL,
50 }
51 static void TearDownTestSuite()
52 {
54 }
55};
56
57class GPUOpenGLWorkaroundsTest : public GPUTest {
58 public:
59 static void SetUpTestSuite()
60 {
61 GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeOpenGL,
62 GPU_BACKEND_OPENGL,
63 G_DEBUG_GPU | G_DEBUG_GPU_COMPILE_SHADERS | G_DEBUG_GPU_RENDERDOC |
64 G_DEBUG_GPU_FORCE_WORKAROUNDS);
65 }
66 static void TearDownTestSuite()
67 {
68 GPUTest::TearDownTestSuite();
69 }
70};
71# define GPU_OPENGL_TEST(test_name) \
72 TEST_F(GPUOpenGLTest, test_name) \
73 { \
74 test_##test_name(); \
75 } \
76 TEST_F(GPUOpenGLWorkaroundsTest, test_name) \
77 { \
78 test_##test_name(); \
79 }
80#else
81# define GPU_OPENGL_TEST(test_name)
82#endif
83
84#ifdef WITH_METAL_BACKEND
85class GPUMetalTest : public GPUTest {
86 public:
87 static void SetUpTestSuite()
88 {
89 GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeMetal, GPU_BACKEND_METAL, G_DEBUG_GPU);
90 }
91 static void TearDownTestSuite()
92 {
93 GPUTest::TearDownTestSuite();
94 }
95};
96
97class GPUMetalWorkaroundsTest : public GPUTest {
98 public:
99 static void SetUpTestSuite()
100 {
101 GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeMetal,
102 GPU_BACKEND_METAL,
103 G_DEBUG_GPU | G_DEBUG_GPU_FORCE_WORKAROUNDS);
104 }
105 static void TearDownTestSuite()
106 {
107 GPUTest::TearDownTestSuite();
108 }
109};
110# define GPU_METAL_TEST(test_name) \
111 TEST_F(GPUMetalTest, test_name) \
112 { \
113 test_##test_name(); \
114 } \
115 TEST_F(GPUMetalWorkaroundsTest, test_name) \
116 { \
117 test_##test_name(); \
118 }
119#else
120# define GPU_METAL_TEST(test_name)
121#endif
122
123#ifdef WITH_VULKAN_BACKEND
124class GPUVulkanTest : public GPUTest {
125 public:
126 static void SetUpTestSuite()
127 {
128 GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeVulkan,
129 GPU_BACKEND_VULKAN,
130 G_DEBUG_GPU | G_DEBUG_GPU_SHADER_DEBUG_INFO | G_DEBUG_GPU_RENDERDOC);
131 }
132 static void TearDownTestSuite()
133 {
134 GPUTest::TearDownTestSuite();
135 }
136};
137
138class GPUVulkanWorkaroundsTest : public GPUTest {
139 public:
140 static void SetUpTestSuite()
141 {
142 GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeVulkan,
143 GPU_BACKEND_VULKAN,
144 G_DEBUG_GPU | G_DEBUG_GPU_SHADER_DEBUG_INFO | G_DEBUG_GPU_RENDERDOC |
145 G_DEBUG_GPU_FORCE_WORKAROUNDS);
146 }
147 static void TearDownTestSuite()
148 {
149 GPUTest::TearDownTestSuite();
150 }
151};
152# define GPU_VULKAN_TEST(test_name) \
153 TEST_F(GPUVulkanTest, test_name) \
154 { \
155 test_##test_name(); \
156 } \
157 TEST_F(GPUVulkanWorkaroundsTest, test_name) \
158 { \
159 test_##test_name(); \
160 }
161#else
162# define GPU_VULKAN_TEST(test_name)
163#endif
164
165#define GPU_TEST(test_name) \
166 GPU_OPENGL_TEST(test_name) \
167 GPU_METAL_TEST(test_name) \
168 GPU_VULKAN_TEST(test_name)
169
170#define BLOCK_GPU_TEST_ON(device_type, os_type, driver_type, backend_type) \
171 if (!blender::tests::should_ignore_blocklist(device_type == GPU_DEVICE_ANY) && \
172 GPU_type_matches_ex(device_type, os_type, driver_type, backend_type)) \
173 { \
174 GTEST_SKIP(); \
175 return; \
176 }
177
178} // namespace blender::gpu
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)
BMesh Iterators.
@ G_DEBUG_GPU_RENDERDOC
@ G_DEBUG_GPU_COMPILE_SHADERS
signed int int32_t
Definition BKE_text.h:78