Blender V4.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_C-api.h"
10
11#include "GPU_platform.hh"
12
13struct GPUContext;
14
15namespace blender::gpu {
16
20class GPUTest : public ::testing::Test {
21 private:
23 eGPUBackendType gpu_backend_type;
24 GHOST_SystemHandle ghost_system;
25 GHOST_ContextHandle ghost_context;
26 GPUContext *context;
27
28 int32_t g_debug_flags_;
29 int32_t prev_g_debug_;
30
31 protected:
33 eGPUBackendType gpu_backend_type,
34 int32_t g_debug_flags)
35 : draw_context_type(draw_context_type),
36 gpu_backend_type(gpu_backend_type),
37 g_debug_flags_(g_debug_flags)
38 {
39 }
40
41 void SetUp() override;
42 void TearDown() override;
43};
44
45#ifdef WITH_OPENGL_BACKEND
46class GPUOpenGLTest : public GPUTest {
47 public:
48 GPUOpenGLTest()
49 : GPUTest(GHOST_kDrawingContextTypeOpenGL,
52 {
53 }
54};
55
56class GPUOpenGLWorkaroundsTest : public GPUTest {
57 public:
58 GPUOpenGLWorkaroundsTest()
59 : GPUTest(GHOST_kDrawingContextTypeOpenGL,
62 {
63 }
64};
65# define GPU_OPENGL_TEST(test_name) \
66 TEST_F(GPUOpenGLTest, test_name) \
67 { \
68 test_##test_name(); \
69 } \
70 TEST_F(GPUOpenGLWorkaroundsTest, test_name) \
71 { \
72 test_##test_name(); \
73 }
74#else
75# define GPU_OPENGL_TEST(test_name)
76#endif
77
78#ifdef WITH_METAL_BACKEND
79class GPUMetalTest : public GPUTest {
80 public:
81 GPUMetalTest() : GPUTest(GHOST_kDrawingContextTypeMetal, GPU_BACKEND_METAL, G_DEBUG_GPU) {}
82};
83
84class GPUMetalWorkaroundsTest : public GPUTest {
85 public:
86 GPUMetalWorkaroundsTest()
87 : GPUTest(GHOST_kDrawingContextTypeMetal,
90 {
91 }
92};
93# define GPU_METAL_TEST(test_name) \
94 TEST_F(GPUMetalTest, test_name) \
95 { \
96 test_##test_name(); \
97 } \
98 TEST_F(GPUMetalWorkaroundsTest, test_name) \
99 { \
100 test_##test_name(); \
101 }
102#else
103# define GPU_METAL_TEST(test_name)
104#endif
105
106#ifdef WITH_VULKAN_BACKEND
107class GPUVulkanTest : public GPUTest {
108 public:
109 GPUVulkanTest()
110 : GPUTest(GHOST_kDrawingContextTypeVulkan,
113 {
114 }
115};
116
117class GPUVulkanWorkaroundsTest : public GPUTest {
118 public:
119 GPUVulkanWorkaroundsTest()
120 : GPUTest(GHOST_kDrawingContextTypeVulkan,
123 {
124 }
125};
126# define GPU_VULKAN_TEST(test_name) \
127 TEST_F(GPUVulkanTest, test_name) \
128 { \
129 test_##test_name(); \
130 } \
131 TEST_F(GPUVulkanWorkaroundsTest, test_name) \
132 { \
133 test_##test_name(); \
134 }
135#else
136# define GPU_VULKAN_TEST(test_name)
137#endif
138
139#define GPU_TEST(test_name) \
140 GPU_OPENGL_TEST(test_name) \
141 GPU_METAL_TEST(test_name) \
142 GPU_VULKAN_TEST(test_name)
143
144} // namespace blender::gpu
@ G_DEBUG_GPU
@ G_DEBUG_GPU_FORCE_WORKAROUNDS
@ G_DEBUG_GPU_RENDERDOC
GHOST C-API function and type declarations.
GHOST_TDrawingContextType
@ GHOST_kDrawingContextTypeNone
struct GPUContext GPUContext
GPUTest(GHOST_TDrawingContextType draw_context_type, eGPUBackendType gpu_backend_type, int32_t g_debug_flags)
void TearDown() override
void SetUp() override
signed int int32_t
Definition stdint.h:77