修复若干问题

This commit is contained in:
2026-08-15 02:51:11 +08:00
parent 282768e0ea
commit 04a9156cd6
25 changed files with 631 additions and 176 deletions
@@ -0,0 +1,63 @@
#include "render_3D/detail/Gpu_Completion_Service.h"
#include "render_3D/detail/Render_Domain.h"
#include <gtest/gtest.h>
#include <atomic>
#include <stdexcept>
#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, AbandonedReservationCancelsBeforeFenceWait) {
Gpu_Completion_Service service;
std::atomic<int> completion_count{};
{
auto reservation = service.prepare(
[&](Gpu_Completion_Service::Result) {
completion_count.fetch_add(1, std::memory_order_relaxed);
},
false);
}
service.shutdown();
EXPECT_EQ(completion_count.load(std::memory_order_relaxed), 0);
}
TEST(GpuCompletionService, PrepareRejectsAStoppedServiceBeforeSubmission) {
Gpu_Completion_Service service;
service.shutdown();
EXPECT_THROW({
auto reservation = service.prepare(
[](Gpu_Completion_Service::Result) {}, false);
static_cast<void>(reservation);
}, std::runtime_error);
}
TEST(GpuCompletionService, ShutdownCancelsAnUnarmedReservation) {
Gpu_Completion_Service service;
auto reservation = service.prepare(
[](Gpu_Completion_Service::Result) {}, false);
service.shutdown();
}
TEST(RenderDomain, PreparedTaskRunsAfterNoThrowHandoff) {
Render_Domain domain;
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));
}
} // namespace
} // namespace renderive::render_3d::detail
@@ -139,8 +139,36 @@ TEST(PointRenderIntegration,
Node_Metric_Kind::gpu_fence_wait_ns));
EXPECT_TRUE(execution.metrics.contains(
Node_Metric_Kind::readback_duration_ns));
EXPECT_GT(execution.metrics.get(
Node_Metric_Kind::backend_artifact_json_bytes), 0U);
const auto artifact_bytes = execution.metrics.get(
Node_Metric_Kind::backend_artifact_json_bytes);
EXPECT_GT(artifact_bytes, 0U);
const auto artifact = std::find_if(
execution.attachments.begin(), execution.attachments.end(),
[](const Node_Diagnostic_Attachment& attachment) {
return attachment.type == "datoviz.drp2.artifact.json";
});
ASSERT_NE(artifact, execution.attachments.end());
EXPECT_EQ(artifact->content.size(), artifact_bytes);
EXPECT_FALSE(artifact->content.empty());
const bool gpu_timing = execution.metrics.contains(
Node_Metric_Kind::gpu_render_duration_ns);
EXPECT_EQ(gpu_timing, execution.metrics.contains(
Node_Metric_Kind::gpu_transition_duration_ns));
EXPECT_EQ(gpu_timing, execution.metrics.contains(
Node_Metric_Kind::gpu_copy_duration_ns));
EXPECT_EQ(gpu_timing, execution.metrics.contains(
Node_Metric_Kind::gpu_total_duration_ns));
if (gpu_timing) {
const auto total = execution.metrics.get(
Node_Metric_Kind::gpu_total_duration_ns);
EXPECT_GE(total, execution.metrics.get(
Node_Metric_Kind::gpu_render_duration_ns));
EXPECT_GE(total, execution.metrics.get(
Node_Metric_Kind::gpu_transition_duration_ns));
EXPECT_GE(total, execution.metrics.get(
Node_Metric_Kind::gpu_copy_duration_ns));
}
} catch (const std::exception& error) {
GTEST_SKIP() << "Vulkan/Datoviz unavailable: " << error.what();
}