GPU: Tests: Move context creation to SetUpTestSuite

This avoid recreating the GPU context for each individual
tests. This reduces the overhead drastically.

Excluding static_shaders and texture_pool tests I get for GPUVulkanTest:
`Before: 129 tests from 1 test suite ran. (26304 ms total) `
`After: 129 tests from 1 test suite ran. (6965 ms total) `

Including static_shaders and texture_pool tests I get for GPUMetalTest:
`Before: 124 tests from 1 test suite ran. (54654 ms total)`
`After: 124 tests from 1 test suite ran. (1870 ms total)`

Given the tests are run twice for the workarounds versions, the
speedup can be multiplied by 2.

Overall tests time is still largely dominated by shader compilation time.
However, there is still 3x improvement using this patch:

Including static_shaders and texture_pool tests I get for GPUVulkanTest,
GPUVulkanWorkaroundTest, GPUOpenGLTest, GPUOpenGLWorkaroundTest:
`Before: 516 tests from 4 test suites ran. (318878 ms total)`
`After: 516 tests from 4 test suites ran. (106593 ms total)`

Pull Request: https://projects.blender.org/blender/blender/pulls/138097
This commit is contained in:
Clément Foucault
2025-04-29 14:02:38 +02:00
committed by Clément Foucault
parent 802addc180
commit ca013ae67a
2 changed files with 75 additions and 52 deletions

View File

@@ -19,10 +19,18 @@
namespace blender::gpu {
void GPUTest::SetUp()
GHOST_SystemHandle GPUTest::ghost_system_;
GHOST_ContextHandle GPUTest::ghost_context_;
GPUContext *GPUTest::context_;
int32_t GPUTest::prev_g_debug_;
void GPUTest::SetUpTestSuite(GHOST_TDrawingContextType draw_context_type,
eGPUBackendType gpu_backend_type,
int32_t g_debug_flags)
{
prev_g_debug_ = G.debug;
G.debug |= g_debug_flags_;
G.debug |= g_debug_flags;
CLG_init();
BLI_threadapi_init();
@@ -30,30 +38,30 @@ void GPUTest::SetUp()
GHOST_GPUSettings gpuSettings = {};
gpuSettings.context_type = draw_context_type;
gpuSettings.flags = GHOST_gpuDebugContext;
ghost_system = GHOST_CreateSystemBackground();
GPU_backend_ghost_system_set(ghost_system);
ghost_context = GHOST_CreateGPUContext(ghost_system, gpuSettings);
GHOST_ActivateGPUContext(ghost_context);
context = GPU_context_create(nullptr, ghost_context);
ghost_system_ = GHOST_CreateSystemBackground();
GPU_backend_ghost_system_set(ghost_system_);
ghost_context_ = GHOST_CreateGPUContext(ghost_system_, gpuSettings);
GHOST_ActivateGPUContext(ghost_context_);
context_ = GPU_context_create(nullptr, ghost_context_);
GPU_init();
BLI_init_srgb_conversion();
GPU_render_begin();
GPU_context_begin_frame(context);
GPU_context_begin_frame(context_);
GPU_debug_capture_begin(nullptr);
}
void GPUTest::TearDown()
void GPUTest::TearDownTestSuite()
{
GPU_debug_capture_end();
GPU_context_end_frame(context);
GPU_context_end_frame(context_);
GPU_render_end();
GPU_exit();
GPU_context_discard(context);
GHOST_DisposeGPUContext(ghost_system, ghost_context);
GHOST_DisposeSystem(ghost_system);
GPU_context_discard(context_);
GHOST_DisposeGPUContext(ghost_system_, ghost_context_);
GHOST_DisposeSystem(ghost_system_);
CLG_exit();
G.debug = prev_g_debug_;

View File

@@ -19,47 +19,44 @@ namespace blender::gpu {
*/
class GPUTest : public ::testing::Test {
private:
GHOST_TDrawingContextType draw_context_type = GHOST_kDrawingContextTypeNone;
eGPUBackendType gpu_backend_type;
GHOST_SystemHandle ghost_system;
GHOST_ContextHandle ghost_context;
GPUContext *context;
static GHOST_SystemHandle ghost_system_;
static GHOST_ContextHandle ghost_context_;
static GPUContext *context_;
int32_t g_debug_flags_;
int32_t prev_g_debug_;
static int32_t prev_g_debug_;
protected:
GPUTest(GHOST_TDrawingContextType draw_context_type,
eGPUBackendType gpu_backend_type,
int32_t g_debug_flags)
: draw_context_type(draw_context_type),
gpu_backend_type(gpu_backend_type),
g_debug_flags_(g_debug_flags)
{
}
void SetUp() override;
void TearDown() override;
static void SetUpTestSuite(GHOST_TDrawingContextType draw_context_type,
eGPUBackendType gpu_backend_type,
int32_t g_debug_flags);
static void TearDownTestSuite();
};
#ifdef WITH_OPENGL_BACKEND
class GPUOpenGLTest : public GPUTest {
public:
GPUOpenGLTest()
: GPUTest(GHOST_kDrawingContextTypeOpenGL,
GPU_BACKEND_OPENGL,
G_DEBUG_GPU | G_DEBUG_GPU_RENDERDOC)
static void SetUpTestSuite()
{
GPUTest::SetUpTestSuite(
GHOST_kDrawingContextTypeOpenGL, GPU_BACKEND_OPENGL, G_DEBUG_GPU | G_DEBUG_GPU_RENDERDOC);
}
static void TearDownTestSuite()
{
GPUTest::TearDownTestSuite();
}
};
class GPUOpenGLWorkaroundsTest : public GPUTest {
public:
GPUOpenGLWorkaroundsTest()
: GPUTest(GHOST_kDrawingContextTypeOpenGL,
GPU_BACKEND_OPENGL,
G_DEBUG_GPU | G_DEBUG_GPU_FORCE_WORKAROUNDS)
static void SetUpTestSuite()
{
GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeOpenGL,
GPU_BACKEND_OPENGL,
G_DEBUG_GPU | G_DEBUG_GPU_FORCE_WORKAROUNDS);
}
static void TearDownTestSuite()
{
GPUTest::TearDownTestSuite();
}
};
# define GPU_OPENGL_TEST(test_name) \
@@ -78,16 +75,27 @@ class GPUOpenGLWorkaroundsTest : public GPUTest {
#ifdef WITH_METAL_BACKEND
class GPUMetalTest : public GPUTest {
public:
GPUMetalTest() : GPUTest(GHOST_kDrawingContextTypeMetal, GPU_BACKEND_METAL, G_DEBUG_GPU) {}
static void SetUpTestSuite()
{
GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeMetal, GPU_BACKEND_METAL, G_DEBUG_GPU);
}
static void TearDownTestSuite()
{
GPUTest::TearDownTestSuite();
}
};
class GPUMetalWorkaroundsTest : public GPUTest {
public:
GPUMetalWorkaroundsTest()
: GPUTest(GHOST_kDrawingContextTypeMetal,
GPU_BACKEND_METAL,
G_DEBUG_GPU | G_DEBUG_GPU_FORCE_WORKAROUNDS)
static void SetUpTestSuite()
{
GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeMetal,
GPU_BACKEND_METAL,
G_DEBUG_GPU | G_DEBUG_GPU_FORCE_WORKAROUNDS);
}
static void TearDownTestSuite()
{
GPUTest::TearDownTestSuite();
}
};
# define GPU_METAL_TEST(test_name) \
@@ -106,21 +114,28 @@ class GPUMetalWorkaroundsTest : public GPUTest {
#ifdef WITH_VULKAN_BACKEND
class GPUVulkanTest : public GPUTest {
public:
GPUVulkanTest()
: GPUTest(GHOST_kDrawingContextTypeVulkan,
GPU_BACKEND_VULKAN,
G_DEBUG_GPU | G_DEBUG_GPU_RENDERDOC)
static void SetUpTestSuite()
{
GPUTest::SetUpTestSuite(
GHOST_kDrawingContextTypeVulkan, GPU_BACKEND_VULKAN, G_DEBUG_GPU | G_DEBUG_GPU_RENDERDOC);
}
static void TearDownTestSuite()
{
GPUTest::TearDownTestSuite();
}
};
class GPUVulkanWorkaroundsTest : public GPUTest {
public:
GPUVulkanWorkaroundsTest()
: GPUTest(GHOST_kDrawingContextTypeVulkan,
GPU_BACKEND_VULKAN,
G_DEBUG_GPU | G_DEBUG_GPU_RENDERDOC | G_DEBUG_GPU_FORCE_WORKAROUNDS)
static void SetUpTestSuite()
{
GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeVulkan,
GPU_BACKEND_VULKAN,
G_DEBUG_GPU | G_DEBUG_GPU_RENDERDOC | G_DEBUG_GPU_FORCE_WORKAROUNDS);
}
static void TearDownTestSuite()
{
GPUTest::TearDownTestSuite();
}
};
# define GPU_VULKAN_TEST(test_name) \