This commit is contained in:
2026-08-15 19:58:39 +08:00
parent 8bfaeeb265
commit 26bbc29a16
29 changed files with 622 additions and 201 deletions
@@ -1,12 +1,12 @@
#include "render_3D/detail/Gpu_Completion_Service.h"
#include "render_3D/detail/Render_Domain.h"
#include <gtest/gtest.h>
#include <atomic>
#include <chrono>
#include <thread>
#include <utility>
namespace renderive::render_3d::detail {
namespace {
static_assert(noexcept(std::declval<Gpu_Completion_Service::Reservation&>().watch(VK_NULL_HANDLE, VK_NULL_HANDLE)));
static_assert(noexcept(std::declval<Render_Domain&>().post(std::declval<Render_Domain::Prepared_Task>())));
TEST(GpuCompletionService, UsesOneProcessWideService) {
EXPECT_EQ(&Gpu_Completion_Service::instance(), &Gpu_Completion_Service::instance());
}
@@ -20,29 +20,18 @@ TEST(GpuCompletionService, AbandonedReservationDoesNotComplete) {
}
EXPECT_EQ(completion_count.load(std::memory_order_relaxed), 0);
}
TEST(RenderDomain, SharesDomainPerGpuIndex) {
auto first = Render_Domain::acquire(0);
auto second = Render_Domain::acquire(0);
auto other = Render_Domain::acquire(1);
EXPECT_EQ(first, second);
EXPECT_NE(first, other);
}
TEST(RenderDomain, PreparedTaskRunsAfterNoThrowHandoff) {
auto domain = Render_Domain::acquire(0);
std::atomic<bool> executed{};
auto task = domain->prepare([&] {
executed.store(true, std::memory_order_release);
});
domain->post(std::move(task));
domain->invoke([] {});
EXPECT_TRUE(executed.load(std::memory_order_acquire));
}
TEST(RenderDomain, AbandonedPreparedTasksReleaseReservedCapacity) {
auto domain = Render_Domain::acquire(2);
for (std::size_t index = 0; index < 128; ++index) {
auto task = domain->prepare([] {});
TEST(GpuCompletionService, CanceledReservationWakesIdleService) {
auto& service = Gpu_Completion_Service::instance();
const auto baseline = service.statistics().in_flight;
{
auto reservation = service.prepare([](Gpu_Completion_Service::Result) {}, false);
EXPECT_EQ(service.statistics().in_flight, baseline + 1);
}
domain->invoke([] {});
const auto deadline = std::chrono::steady_clock::now() + std::chrono::milliseconds(100);
while (service.statistics().in_flight != baseline &&
std::chrono::steady_clock::now() < deadline)
std::this_thread::sleep_for(std::chrono::milliseconds(1));
EXPECT_EQ(service.statistics().in_flight, baseline);
}
}
}
+47
View File
@@ -0,0 +1,47 @@
#include "render_3D/detail/Render_Domain.h"
#include <gtest/gtest.h>
#include <atomic>
#include <utility>
namespace renderive::render_3d::detail {
namespace {
static_assert(noexcept(std::declval<Render_Domain&>().post(std::declval<Render_Domain::Prepared_Task>())));
TEST(RenderDomain, SharesDomainPerGpuIndex) {
auto first = Render_Domain::acquire(0x7ffffffcU);
auto second = Render_Domain::acquire(0x7ffffffcU);
auto other = Render_Domain::acquire(0x7ffffffbU);
EXPECT_EQ(first, second);
EXPECT_NE(first, other);
}
TEST(RenderDomain, PreparedTaskRunsAfterNoThrowHandoff) {
auto domain = Render_Domain::acquire(0x7ffffffaU);
std::atomic<bool> executed{};
auto task = domain->prepare([&] {
executed.store(true, std::memory_order_release);
});
domain->post(std::move(task));
domain->invoke([] {});
EXPECT_TRUE(executed.load(std::memory_order_acquire));
}
TEST(RenderDomain, AbandonedPreparedTasksReleaseReservedCapacity) {
auto domain = Render_Domain::acquire(0x7ffffff9U);
for (std::size_t index = 0; index < 128; ++index) {
auto task = domain->prepare([] {});
}
domain->invoke([] {});
}
TEST(RenderDomain, NestedInvokeExecutesInlineOnTheAffinityThread) {
auto domain = Render_Domain::acquire(0x7ffffff8U);
const int value = domain->invoke([domain] {
return domain->invoke([] { return 42; });
});
EXPECT_EQ(value, 42);
}
TEST(RenderDomain, ReportsBoundedAdmissionStatistics) {
auto domain = Render_Domain::acquire(0x7ffffff7U);
const auto statistics = domain->statistics();
EXPECT_EQ(statistics.capacity, 64U);
EXPECT_TRUE(statistics.admitted <= statistics.capacity);
EXPECT_TRUE(statistics.queued <= statistics.capacity);
}
}
}