Blender V5.0
gpu_testing.cc
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 "CLG_log.h"
8
9#include "BLI_math_color.h"
10#include "BLI_threads.h"
11
12#include "GPU_context.hh"
13#include "GPU_debug.hh"
14#include "GPU_init_exit.hh"
15
16#include "gpu_testing.hh"
17
18#include "GHOST_C-api.h"
19#include "GHOST_Path-api.hh"
20
21namespace blender::gpu {
22
23GHOST_SystemHandle GPUTest::ghost_system_;
24GHOST_ContextHandle GPUTest::ghost_context_;
25GPUContext *GPUTest::context_;
26
27int32_t GPUTest::prev_g_debug_;
28
30 GPUBackendType gpu_backend_type,
31 int32_t g_debug_flags)
32{
33 prev_g_debug_ = G.debug;
34 G.debug |= g_debug_flags;
35
36 CLG_init();
38 GPU_backend_type_selection_set(gpu_backend_type);
39 if (!GPU_backend_supported()) {
40 GTEST_SKIP() << "GPU backend not supported";
41 }
42 GHOST_GPUSettings gpu_settings = {};
43 gpu_settings.context_type = draw_context_type;
44 gpu_settings.flags = GHOST_gpuDebugContext;
45 ghost_system_ = GHOST_CreateSystemBackground();
46 GPU_backend_ghost_system_set(ghost_system_);
47 ghost_context_ = GHOST_CreateGPUContext(ghost_system_, gpu_settings);
48 GHOST_ActivateGPUContext(ghost_context_);
49 context_ = GPU_context_create(nullptr, ghost_context_);
50 GPU_init();
51
53
57}
58
60{
62 GPU_context_end_frame(context_);
64
65 GPU_exit();
66 GPU_context_discard(context_);
67 GHOST_DisposeGPUContext(ghost_system_, ghost_context_);
68 GHOST_DisposeSystem(ghost_system_);
70 CLG_exit();
71
72 G.debug = prev_g_debug_;
73}
74
76{
77 const ::testing::TestInfo *info = ::testing::UnitTest::GetInstance()->current_test_info();
78 std::stringstream ss;
79 ss << info->test_suite_name() << "." << info->name();
80 debug_group_name_ = ss.str();
81 GPU_debug_group_begin(debug_group_name_.c_str());
82}
83
88
89} // namespace blender::gpu
void BLI_init_srgb_conversion(void)
void BLI_threadapi_init(void)
Definition threads.cc:114
void CLG_exit()
Definition clog.cc:880
void CLG_init()
Definition clog.cc:873
GHOST C-API function and type declarations.
GHOST_ContextHandle GHOST_CreateGPUContext(GHOST_SystemHandle systemhandle, GHOST_GPUSettings gpu_settings)
GHOST_SystemHandle GHOST_CreateSystemBackground(void)
GHOST_TSuccess GHOST_ActivateGPUContext(GHOST_ContextHandle contexthandle)
GHOST_TSuccess GHOST_DisposeGPUContext(GHOST_SystemHandle systemhandle, GHOST_ContextHandle contexthandle)
GHOST_TSuccess GHOST_DisposeSystem(GHOST_SystemHandle systemhandle)
GHOST_TSuccess GHOST_DisposeSystemPaths()
GHOST_TDrawingContextType
@ GHOST_gpuDebugContext
void GPU_render_end()
GPUContext * GPU_context_create(void *ghost_window, void *ghost_context)
bool GPU_backend_supported()
void GPU_context_begin_frame(GPUContext *ctx)
void GPU_render_begin()
void GPU_backend_type_selection_set(const GPUBackendType backend)
void GPU_context_discard(GPUContext *)
void GPU_context_end_frame(GPUContext *ctx)
void GPU_backend_ghost_system_set(void *ghost_system_handle)
void GPU_debug_group_end()
Definition gpu_debug.cc:33
void GPU_debug_capture_end()
Definition gpu_debug.cc:93
void GPU_debug_capture_begin(const char *title)
Definition gpu_debug.cc:78
void GPU_debug_group_begin(const char *name)
Definition gpu_debug.cc:22
void GPU_init()
void GPU_exit()
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)
#define G(x, y, z)
GHOST_TDrawingContextType context_type