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
160 lines
3.6 KiB
C++
160 lines
3.6 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
|
|
|
#include "testing/testing.h"
|
|
|
|
#include "BKE_global.hh"
|
|
|
|
#include "GHOST_C-api.h"
|
|
|
|
#include "GPU_platform.hh"
|
|
|
|
struct GPUContext;
|
|
|
|
namespace blender::gpu {
|
|
|
|
/**
|
|
* Test class that setups a GPUContext for test cases.
|
|
*/
|
|
class GPUTest : public ::testing::Test {
|
|
private:
|
|
static GHOST_SystemHandle ghost_system_;
|
|
static GHOST_ContextHandle ghost_context_;
|
|
static GPUContext *context_;
|
|
|
|
static int32_t prev_g_debug_;
|
|
|
|
protected:
|
|
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:
|
|
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:
|
|
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) \
|
|
TEST_F(GPUOpenGLTest, test_name) \
|
|
{ \
|
|
test_##test_name(); \
|
|
} \
|
|
TEST_F(GPUOpenGLWorkaroundsTest, test_name) \
|
|
{ \
|
|
test_##test_name(); \
|
|
}
|
|
#else
|
|
# define GPU_OPENGL_TEST(test_name)
|
|
#endif
|
|
|
|
#ifdef WITH_METAL_BACKEND
|
|
class GPUMetalTest : public GPUTest {
|
|
public:
|
|
static void SetUpTestSuite()
|
|
{
|
|
GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeMetal, GPU_BACKEND_METAL, G_DEBUG_GPU);
|
|
}
|
|
static void TearDownTestSuite()
|
|
{
|
|
GPUTest::TearDownTestSuite();
|
|
}
|
|
};
|
|
|
|
class GPUMetalWorkaroundsTest : public GPUTest {
|
|
public:
|
|
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) \
|
|
TEST_F(GPUMetalTest, test_name) \
|
|
{ \
|
|
test_##test_name(); \
|
|
} \
|
|
TEST_F(GPUMetalWorkaroundsTest, test_name) \
|
|
{ \
|
|
test_##test_name(); \
|
|
}
|
|
#else
|
|
# define GPU_METAL_TEST(test_name)
|
|
#endif
|
|
|
|
#ifdef WITH_VULKAN_BACKEND
|
|
class GPUVulkanTest : public GPUTest {
|
|
public:
|
|
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:
|
|
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) \
|
|
TEST_F(GPUVulkanTest, test_name) \
|
|
{ \
|
|
test_##test_name(); \
|
|
} \
|
|
TEST_F(GPUVulkanWorkaroundsTest, test_name) \
|
|
{ \
|
|
test_##test_name(); \
|
|
}
|
|
#else
|
|
# define GPU_VULKAN_TEST(test_name)
|
|
#endif
|
|
|
|
#define GPU_TEST(test_name) \
|
|
GPU_OPENGL_TEST(test_name) \
|
|
GPU_METAL_TEST(test_name) \
|
|
GPU_VULKAN_TEST(test_name)
|
|
|
|
} // namespace blender::gpu
|