Blender V4.5
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
28 protected:
29 static void SetUpTestSuite(GHOST_TDrawingContextType draw_context_type,
30 eGPUBackendType gpu_backend_type,
31 int32_t g_debug_flags);
32 static void TearDownTestSuite();
33};
34
35#ifdef WITH_OPENGL_BACKEND
36class GPUOpenGLTest : public GPUTest {
37 public:
38 static void SetUpTestSuite()
39 {
41 GHOST_kDrawingContextTypeOpenGL, GPU_BACKEND_OPENGL, G_DEBUG_GPU | G_DEBUG_GPU_RENDERDOC);
42 }
43 static void TearDownTestSuite()
44 {
45 GPUTest::TearDownTestSuite();
46 }
47};
48
49class GPUOpenGLWorkaroundsTest : public GPUTest {
50 public:
51 static void SetUpTestSuite()
52 {
53 GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeOpenGL,
56 }
57 static void TearDownTestSuite()
58 {
59 GPUTest::TearDownTestSuite();
60 }
61};
62# define GPU_OPENGL_TEST(test_name) \
63 TEST_F(GPUOpenGLTest, test_name) \
64 { \
65 test_##test_name(); \
66 } \
67 TEST_F(GPUOpenGLWorkaroundsTest, test_name) \
68 { \
69 test_##test_name(); \
70 }
71#else
72# define GPU_OPENGL_TEST(test_name)
73#endif
74
75#ifdef WITH_METAL_BACKEND
76class GPUMetalTest : public GPUTest {
77 public:
78 static void SetUpTestSuite()
79 {
80 GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeMetal, GPU_BACKEND_METAL, G_DEBUG_GPU);
81 }
82 static void TearDownTestSuite()
83 {
84 GPUTest::TearDownTestSuite();
85 }
86};
87
88class GPUMetalWorkaroundsTest : public GPUTest {
89 public:
90 static void SetUpTestSuite()
91 {
92 GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeMetal,
95 }
96 static void TearDownTestSuite()
97 {
98 GPUTest::TearDownTestSuite();
99 }
100};
101# define GPU_METAL_TEST(test_name) \
102 TEST_F(GPUMetalTest, test_name) \
103 { \
104 test_##test_name(); \
105 } \
106 TEST_F(GPUMetalWorkaroundsTest, test_name) \
107 { \
108 test_##test_name(); \
109 }
110#else
111# define GPU_METAL_TEST(test_name)
112#endif
113
114#ifdef WITH_VULKAN_BACKEND
115class GPUVulkanTest : public GPUTest {
116 public:
117 static void SetUpTestSuite()
118 {
119 GPUTest::SetUpTestSuite(
120 GHOST_kDrawingContextTypeVulkan, GPU_BACKEND_VULKAN, G_DEBUG_GPU | G_DEBUG_GPU_RENDERDOC);
121 }
122 static void TearDownTestSuite()
123 {
124 GPUTest::TearDownTestSuite();
125 }
126};
127
128class GPUVulkanWorkaroundsTest : public GPUTest {
129 public:
130 static void SetUpTestSuite()
131 {
132 GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeVulkan,
135 }
136 static void TearDownTestSuite()
137 {
138 GPUTest::TearDownTestSuite();
139 }
140};
141# define GPU_VULKAN_TEST(test_name) \
142 TEST_F(GPUVulkanTest, test_name) \
143 { \
144 test_##test_name(); \
145 } \
146 TEST_F(GPUVulkanWorkaroundsTest, test_name) \
147 { \
148 test_##test_name(); \
149 }
150#else
151# define GPU_VULKAN_TEST(test_name)
152#endif
153
154#define GPU_TEST(test_name) \
155 GPU_OPENGL_TEST(test_name) \
156 GPU_METAL_TEST(test_name) \
157 GPU_VULKAN_TEST(test_name)
158
159} // namespace blender::gpu
@ G_DEBUG_GPU
@ G_DEBUG_GPU_FORCE_WORKAROUNDS
@ G_DEBUG_GPU_RENDERDOC
GHOST C-API function and type declarations.
GHOST_TDrawingContextType
static void TearDownTestSuite()
static void SetUpTestSuite(GHOST_TDrawingContextType draw_context_type, eGPUBackendType gpu_backend_type, int32_t g_debug_flags)