Add render graph depth access semantics

This commit is contained in:
2026-04-14 13:56:08 +08:00
parent 9950e0a44f
commit 87bf83451b
7 changed files with 93 additions and 5 deletions

View File

@@ -279,6 +279,17 @@ RenderGraphTextureDesc BuildTestTextureDesc() {
return desc;
}
RenderGraphTextureDesc BuildTestDepthTextureDesc() {
RenderGraphTextureDesc desc = {};
desc.width = 1024u;
desc.height = 1024u;
desc.format = static_cast<XCEngine::Core::uint32>(Format::D24_UNorm_S8_UInt);
desc.textureType = static_cast<XCEngine::Core::uint32>(TextureType::Texture2D);
desc.sampleCount = 1u;
desc.sampleQuality = 0u;
return desc;
}
} // namespace
TEST(RenderGraph_Test, CompilesDeclaredPassOrderAndTracksTextureLifetimes) {
@@ -533,6 +544,36 @@ TEST(RenderGraph_Test, RejectsGraphOwnedImportedTextureWithoutView) {
EXPECT_FALSE(errorMessage.Empty());
}
TEST(RenderGraph_Test, TracksDepthAttachmentTransitionPlan) {
RenderGraph graph;
RenderGraphBuilder builder(graph);
const RenderGraphTextureDesc depthDesc = BuildTestDepthTextureDesc();
const RenderGraphTextureHandle depthTexture =
builder.CreateTransientTexture("SceneDepth", depthDesc);
builder.AddRasterPass(
"DepthPrepass",
[&](RenderGraphPassBuilder& pass) {
pass.WriteDepthTexture(depthTexture);
});
CompiledRenderGraph compiledGraph;
XCEngine::Containers::String errorMessage;
ASSERT_TRUE(RenderGraphCompiler::Compile(graph, compiledGraph, &errorMessage))
<< errorMessage.CStr();
RenderGraphTextureTransitionPlan transitionPlan = {};
ASSERT_TRUE(compiledGraph.TryGetTextureTransitionPlan(depthTexture, transitionPlan));
EXPECT_TRUE(transitionPlan.graphOwnsTransitions);
EXPECT_TRUE(transitionPlan.hasFirstAccessState);
EXPECT_TRUE(transitionPlan.hasLastAccessState);
EXPECT_EQ(transitionPlan.initialState, ResourceStates::Common);
EXPECT_EQ(transitionPlan.firstAccessState, ResourceStates::DepthWrite);
EXPECT_EQ(transitionPlan.lastAccessState, ResourceStates::DepthWrite);
EXPECT_EQ(transitionPlan.finalState, ResourceStates::DepthWrite);
}
TEST(RenderGraph_Test, ExecutesCompiledPassCallbacksInCompiledOrder) {
RenderGraph graph;
RenderGraphBuilder builder(graph);