Blender V5.3
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_c.hh"
10
11#include "BKE_gtest_base.hh"
12
13#include "GPU_context.hh"
14#include "GPU_debug.hh"
15#include "GPU_init_exit.hh"
16
17#include "gpu_testing.hh"
18
19#include "GHOST_ISystem.hh"
20#include "GHOST_ISystemPaths.hh"
21#include "GHOST_Types.hh"
22
23namespace blender::gpu {
24
25GHOST_ISystem *GPUTest::ghost_system_;
26GHOST_IContext *GPUTest::ghost_context_;
27GPUContext *GPUTest::context_;
28
29int32_t GPUTest::prev_g_debug_;
30
32 GPUBackendType gpu_backend_type,
33 int32_t g_debug_flags)
34{
35 prev_g_debug_ = G.debug;
36 G.debug |= g_debug_flags;
37
39 GPU_backend_type_selection_set(gpu_backend_type);
40 if (!GPU_backend_supported()) {
41 GTEST_SKIP() << "GPU backend not supported";
42 }
43 GHOST_GPUSettings gpu_settings = {};
44 gpu_settings.context_type = draw_context_type;
45 gpu_settings.flags = GHOST_gpuDebugContext;
47 ghost_system_ = GHOST_ISystem::getSystem();
48 GPU_backend_ghost_system_set(ghost_system_);
49 ghost_context_ = ghost_system_->createOffscreenContext(gpu_settings);
50 ghost_context_->activateDrawingContext();
51 context_ = GPU_context_create(nullptr, ghost_context_);
52 GPU_init();
53
55
59}
60
62{
64 GPU_context_end_frame(context_);
66
67 GPU_exit();
68 GPU_context_discard(context_);
69 ghost_system_->disposeContext(ghost_context_);
72
74
75 G.debug = prev_g_debug_;
76}
77
79{
80 const ::testing::TestInfo *info = ::testing::UnitTest::GetInstance()->current_test_info();
81 std::stringstream ss;
82 ss << info->test_suite_name() << "." << info->name();
83 debug_group_name_ = ss.str();
84 GPU_debug_group_begin(debug_group_name_.c_str());
85}
86
91
92} // namespace blender::gpu
GHOST_TDrawingContextType
@ GHOST_gpuDebugContext
static GHOST_TSuccess dispose()
static GHOST_ISystem * getSystem()
static GHOST_TSuccess disposeSystem()
static GHOST_TSuccess createSystemBackground()
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)
void gtest_teardown()
void gtest_setup()
void GPU_exit()
GPUContext * GPU_context_create(GHOST_IWindow *ghost_window, GHOST_IContext *ghost_context)
void GPU_debug_capture_begin(const char *title)
Definition gpu_debug.cc:101
void BLI_init_srgb_conversion()
void GPU_context_end_frame(GPUContext *ctx)
bool GPU_backend_supported()
void GPU_render_begin()
void GPU_debug_capture_end()
Definition gpu_debug.cc:116
void GPU_context_begin_frame(GPUContext *ctx)
Global G
Definition blender.cc:57
void GPU_init()
void GPU_render_end()
void GPU_debug_group_end()
Definition gpu_debug.cc:34
signed int int32_t
Definition BKE_text.h:78
void GPU_backend_ghost_system_set(GHOST_ISystem *ghost_system_handle)
void GPU_backend_type_selection_set(const GPUBackendType backend)
void GPU_context_discard(GPUContext *)
void GPU_debug_group_begin(const char *name)
Definition gpu_debug.cc:23
GHOST_TDrawingContextType context_type