2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2022-02-11 14:56:03 +11:00
|
|
|
|
2020-09-08 11:31:47 +02:00
|
|
|
#include "testing/testing.h"
|
|
|
|
|
|
2024-02-10 18:25:14 +01:00
|
|
|
#include "BKE_global.hh"
|
2023-12-12 10:14:13 +01:00
|
|
|
|
2020-09-08 11:31:47 +02:00
|
|
|
#include "GHOST_C-api.h"
|
2023-12-12 10:14:13 +01:00
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
#include "GPU_platform.hh"
|
2020-09-08 11:31:47 +02:00
|
|
|
|
|
|
|
|
struct GPUContext;
|
|
|
|
|
|
|
|
|
|
namespace blender::gpu {
|
|
|
|
|
|
2023-12-12 10:14:13 +01:00
|
|
|
/**
|
|
|
|
|
* Test class that setups a GPUContext for test cases.
|
2020-09-08 11:31:47 +02:00
|
|
|
*/
|
|
|
|
|
class GPUTest : public ::testing::Test {
|
|
|
|
|
private:
|
2025-04-29 14:02:38 +02:00
|
|
|
static GHOST_SystemHandle ghost_system_;
|
|
|
|
|
static GHOST_ContextHandle ghost_context_;
|
|
|
|
|
static GPUContext *context_;
|
2020-09-08 11:31:47 +02:00
|
|
|
|
2025-04-29 14:02:38 +02:00
|
|
|
static int32_t prev_g_debug_;
|
2023-03-23 16:37:52 +01:00
|
|
|
|
2020-09-08 11:31:47 +02:00
|
|
|
protected:
|
2025-04-29 14:02:38 +02:00
|
|
|
static void SetUpTestSuite(GHOST_TDrawingContextType draw_context_type,
|
|
|
|
|
eGPUBackendType gpu_backend_type,
|
|
|
|
|
int32_t g_debug_flags);
|
|
|
|
|
static void TearDownTestSuite();
|
2020-09-08 11:31:47 +02:00
|
|
|
};
|
|
|
|
|
|
2023-07-21 14:03:27 +10:00
|
|
|
#ifdef WITH_OPENGL_BACKEND
|
2021-06-28 08:28:56 +02:00
|
|
|
class GPUOpenGLTest : public GPUTest {
|
|
|
|
|
public:
|
2025-04-29 14:02:38 +02:00
|
|
|
static void SetUpTestSuite()
|
|
|
|
|
{
|
|
|
|
|
GPUTest::SetUpTestSuite(
|
|
|
|
|
GHOST_kDrawingContextTypeOpenGL, GPU_BACKEND_OPENGL, G_DEBUG_GPU | G_DEBUG_GPU_RENDERDOC);
|
|
|
|
|
}
|
|
|
|
|
static void TearDownTestSuite()
|
2023-12-12 10:14:13 +01:00
|
|
|
{
|
2025-04-29 14:02:38 +02:00
|
|
|
GPUTest::TearDownTestSuite();
|
2023-12-12 10:14:13 +01:00
|
|
|
}
|
2021-06-28 08:28:56 +02:00
|
|
|
};
|
2024-07-02 08:37:50 +02:00
|
|
|
|
|
|
|
|
class GPUOpenGLWorkaroundsTest : public GPUTest {
|
|
|
|
|
public:
|
2025-04-29 14:02:38 +02:00
|
|
|
static void SetUpTestSuite()
|
2024-07-02 08:37:50 +02:00
|
|
|
{
|
2025-04-29 14:02:38 +02:00
|
|
|
GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeOpenGL,
|
|
|
|
|
GPU_BACKEND_OPENGL,
|
|
|
|
|
G_DEBUG_GPU | G_DEBUG_GPU_FORCE_WORKAROUNDS);
|
|
|
|
|
}
|
|
|
|
|
static void TearDownTestSuite()
|
|
|
|
|
{
|
|
|
|
|
GPUTest::TearDownTestSuite();
|
2024-07-02 08:37:50 +02:00
|
|
|
}
|
|
|
|
|
};
|
2023-08-13 23:38:07 +02:00
|
|
|
# define GPU_OPENGL_TEST(test_name) \
|
|
|
|
|
TEST_F(GPUOpenGLTest, test_name) \
|
2024-07-02 08:37:50 +02:00
|
|
|
{ \
|
|
|
|
|
test_##test_name(); \
|
|
|
|
|
} \
|
|
|
|
|
TEST_F(GPUOpenGLWorkaroundsTest, test_name) \
|
2023-08-13 23:38:07 +02:00
|
|
|
{ \
|
|
|
|
|
test_##test_name(); \
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
# define GPU_OPENGL_TEST(test_name)
|
2023-07-21 14:03:27 +10:00
|
|
|
#endif
|
2021-06-28 08:28:56 +02:00
|
|
|
|
2022-11-15 13:12:05 +01:00
|
|
|
#ifdef WITH_METAL_BACKEND
|
|
|
|
|
class GPUMetalTest : public GPUTest {
|
|
|
|
|
public:
|
2025-04-29 14:02:38 +02:00
|
|
|
static void SetUpTestSuite()
|
|
|
|
|
{
|
|
|
|
|
GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeMetal, GPU_BACKEND_METAL, G_DEBUG_GPU);
|
|
|
|
|
}
|
|
|
|
|
static void TearDownTestSuite()
|
|
|
|
|
{
|
|
|
|
|
GPUTest::TearDownTestSuite();
|
|
|
|
|
}
|
2023-12-12 10:14:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class GPUMetalWorkaroundsTest : public GPUTest {
|
|
|
|
|
public:
|
2025-04-29 14:02:38 +02:00
|
|
|
static void SetUpTestSuite()
|
|
|
|
|
{
|
|
|
|
|
GPUTest::SetUpTestSuite(GHOST_kDrawingContextTypeMetal,
|
|
|
|
|
GPU_BACKEND_METAL,
|
|
|
|
|
G_DEBUG_GPU | G_DEBUG_GPU_FORCE_WORKAROUNDS);
|
|
|
|
|
}
|
|
|
|
|
static void TearDownTestSuite()
|
2023-12-12 10:14:13 +01:00
|
|
|
{
|
2025-04-29 14:02:38 +02:00
|
|
|
GPUTest::TearDownTestSuite();
|
2023-12-12 10:14:13 +01:00
|
|
|
}
|
2022-11-15 13:12:05 +01:00
|
|
|
};
|
|
|
|
|
# define GPU_METAL_TEST(test_name) \
|
|
|
|
|
TEST_F(GPUMetalTest, test_name) \
|
2023-12-12 10:14:13 +01:00
|
|
|
{ \
|
|
|
|
|
test_##test_name(); \
|
|
|
|
|
} \
|
|
|
|
|
TEST_F(GPUMetalWorkaroundsTest, test_name) \
|
2022-11-15 13:12:05 +01:00
|
|
|
{ \
|
|
|
|
|
test_##test_name(); \
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
# define GPU_METAL_TEST(test_name)
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-01-31 08:48:52 +01:00
|
|
|
#ifdef WITH_VULKAN_BACKEND
|
|
|
|
|
class GPUVulkanTest : public GPUTest {
|
|
|
|
|
public:
|
2025-04-29 14:02:38 +02:00
|
|
|
static void SetUpTestSuite()
|
2023-12-12 10:14:13 +01:00
|
|
|
{
|
2025-04-29 14:02:38 +02:00
|
|
|
GPUTest::SetUpTestSuite(
|
|
|
|
|
GHOST_kDrawingContextTypeVulkan, GPU_BACKEND_VULKAN, G_DEBUG_GPU | G_DEBUG_GPU_RENDERDOC);
|
|
|
|
|
}
|
|
|
|
|
static void TearDownTestSuite()
|
|
|
|
|
{
|
|
|
|
|
GPUTest::TearDownTestSuite();
|
2023-12-12 10:14:13 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class GPUVulkanWorkaroundsTest : public GPUTest {
|
|
|
|
|
public:
|
2025-04-29 14:02:38 +02:00
|
|
|
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()
|
2023-12-12 10:14:13 +01:00
|
|
|
{
|
2025-04-29 14:02:38 +02:00
|
|
|
GPUTest::TearDownTestSuite();
|
2023-12-12 10:14:13 +01:00
|
|
|
}
|
2023-01-31 08:48:52 +01:00
|
|
|
};
|
|
|
|
|
# define GPU_VULKAN_TEST(test_name) \
|
|
|
|
|
TEST_F(GPUVulkanTest, test_name) \
|
2023-12-12 10:14:13 +01:00
|
|
|
{ \
|
|
|
|
|
test_##test_name(); \
|
|
|
|
|
} \
|
|
|
|
|
TEST_F(GPUVulkanWorkaroundsTest, test_name) \
|
2023-01-31 08:48:52 +01:00
|
|
|
{ \
|
|
|
|
|
test_##test_name(); \
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
# define GPU_VULKAN_TEST(test_name)
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-11-15 13:12:05 +01:00
|
|
|
#define GPU_TEST(test_name) \
|
|
|
|
|
GPU_OPENGL_TEST(test_name) \
|
2023-01-31 08:48:52 +01:00
|
|
|
GPU_METAL_TEST(test_name) \
|
|
|
|
|
GPU_VULKAN_TEST(test_name)
|
2022-11-15 13:12:05 +01:00
|
|
|
|
2020-10-02 09:48:41 +10:00
|
|
|
} // namespace blender::gpu
|