Harden render graph pass capture and feature source-color contract
This commit is contained in:
@@ -452,8 +452,20 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Execute(const RenderPassContext&) override {
|
||||
bool Execute(const RenderPassContext& context) override {
|
||||
++executeCallCount;
|
||||
lastHasSourceSurface = context.sourceSurface != nullptr;
|
||||
lastSourceColorView = context.sourceColorView;
|
||||
if (context.sourceSurface != nullptr) {
|
||||
lastSourceSurfaceWidth = context.sourceSurface->GetWidth();
|
||||
lastSourceSurfaceHeight = context.sourceSurface->GetHeight();
|
||||
lastSourceSurfaceRenderAreaWidth =
|
||||
context.sourceSurface->GetRenderAreaWidth();
|
||||
lastSourceSurfaceRenderAreaHeight =
|
||||
context.sourceSurface->GetRenderAreaHeight();
|
||||
lastSourceSurfaceAutoTransitionEnabled =
|
||||
context.sourceSurface->IsAutoTransitionEnabled();
|
||||
}
|
||||
RecordEvent("Execute");
|
||||
return true;
|
||||
}
|
||||
@@ -461,6 +473,7 @@ public:
|
||||
bool RecordRenderGraph(
|
||||
const SceneRenderFeaturePassRenderGraphContext& context) override {
|
||||
++recordGraphCallCount;
|
||||
lastReceivedSourceColorTextureValid = context.sourceColorTexture.IsValid();
|
||||
RecordEvent("RecordGraph");
|
||||
return SceneRenderFeaturePass::RecordRenderGraph(context);
|
||||
}
|
||||
@@ -471,6 +484,14 @@ public:
|
||||
size_t executeCallCount = 0u;
|
||||
size_t recordGraphCallCount = 0u;
|
||||
size_t shutdownCallCount = 0u;
|
||||
bool lastHasSourceSurface = false;
|
||||
uint32_t lastSourceSurfaceWidth = 0u;
|
||||
uint32_t lastSourceSurfaceHeight = 0u;
|
||||
uint32_t lastSourceSurfaceRenderAreaWidth = 0u;
|
||||
uint32_t lastSourceSurfaceRenderAreaHeight = 0u;
|
||||
bool lastSourceSurfaceAutoTransitionEnabled = true;
|
||||
XCEngine::RHI::RHIResourceView* lastSourceColorView = nullptr;
|
||||
bool lastReceivedSourceColorTextureValid = false;
|
||||
|
||||
private:
|
||||
void RecordEvent(const char* suffix) {
|
||||
@@ -719,6 +740,7 @@ TEST(SceneRenderFeaturePass_Test, RecordsDefaultGraphPassAndExecutesWrappedCallb
|
||||
nullptr,
|
||||
nullptr,
|
||||
ResourceStates::Common,
|
||||
{},
|
||||
{ colorTarget },
|
||||
depthTarget,
|
||||
{},
|
||||
@@ -756,6 +778,107 @@ TEST(SceneRenderFeaturePass_Test, RecordsDefaultGraphPassAndExecutesWrappedCallb
|
||||
"FeatureGraph:Execute" }));
|
||||
}
|
||||
|
||||
TEST(SceneRenderFeaturePass_Test, ReadsSourceColorTextureAndCopiesSourceSurfaceTemplateForGraphExecution) {
|
||||
TestSceneRenderFeaturePass feature(
|
||||
SceneRenderInjectionPoint::BeforeOpaque,
|
||||
true,
|
||||
nullptr,
|
||||
"FeatureReadSource");
|
||||
|
||||
RenderGraph graph = {};
|
||||
RenderGraphBuilder graphBuilder(graph);
|
||||
|
||||
RenderGraphTextureDesc colorDesc = {};
|
||||
colorDesc.width = 96u;
|
||||
colorDesc.height = 48u;
|
||||
colorDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||||
colorDesc.textureType = static_cast<uint32_t>(XCEngine::RHI::TextureType::Texture2D);
|
||||
colorDesc.sampleCount = 1u;
|
||||
|
||||
TestResourceView sourceRenderTargetView(
|
||||
ResourceViewType::RenderTarget,
|
||||
ResourceViewDimension::Texture2D,
|
||||
Format::R8G8B8A8_UNorm);
|
||||
TestResourceView sourceShaderView(
|
||||
ResourceViewType::ShaderResource,
|
||||
ResourceViewDimension::Texture2D,
|
||||
Format::R8G8B8A8_UNorm);
|
||||
TestResourceView outputView(
|
||||
ResourceViewType::RenderTarget,
|
||||
ResourceViewDimension::Texture2D,
|
||||
Format::R8G8B8A8_UNorm);
|
||||
const RenderGraphImportedTextureOptions graphManagedImport = {
|
||||
ResourceStates::Common,
|
||||
ResourceStates::Common,
|
||||
true
|
||||
};
|
||||
const RenderGraphTextureHandle sourceColor =
|
||||
graphBuilder.ImportTexture("SceneColor", colorDesc, &sourceRenderTargetView, graphManagedImport);
|
||||
const RenderGraphTextureHandle outputColor =
|
||||
graphBuilder.ImportTexture("OutputColor", colorDesc, &outputView, graphManagedImport);
|
||||
|
||||
RenderContext renderContext = {};
|
||||
MockForwardCommandList commandList;
|
||||
renderContext.commandList = &commandList;
|
||||
|
||||
RenderSceneData sceneData = {};
|
||||
RenderSurface outputSurface(96u, 48u);
|
||||
outputSurface.SetColorAttachment(&outputView);
|
||||
outputSurface.SetAutoTransitionEnabled(false);
|
||||
|
||||
RenderSurface sourceSurfaceTemplate(96u, 48u);
|
||||
sourceSurfaceTemplate.SetColorAttachment(&sourceRenderTargetView);
|
||||
sourceSurfaceTemplate.SetRenderArea(XCEngine::Math::RectInt(11, 7, 85, 41));
|
||||
|
||||
bool executionSucceeded = true;
|
||||
const SceneRenderFeaturePassRenderGraphContext context = {
|
||||
graphBuilder,
|
||||
"FeatureReadSourcePass",
|
||||
renderContext,
|
||||
sceneData,
|
||||
outputSurface,
|
||||
&sourceSurfaceTemplate,
|
||||
&sourceShaderView,
|
||||
ResourceStates::Common,
|
||||
sourceColor,
|
||||
{ outputColor },
|
||||
{},
|
||||
{},
|
||||
false,
|
||||
&executionSucceeded,
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
ASSERT_TRUE(feature.RecordRenderGraph(context));
|
||||
|
||||
sourceSurfaceTemplate = RenderSurface(8u, 8u);
|
||||
sourceSurfaceTemplate.SetRenderArea(XCEngine::Math::RectInt(1, 2, 8, 8));
|
||||
|
||||
CompiledRenderGraph compiledGraph = {};
|
||||
String errorMessage;
|
||||
ASSERT_TRUE(RenderGraphCompiler::Compile(graph, compiledGraph, &errorMessage))
|
||||
<< errorMessage.CStr();
|
||||
|
||||
RenderGraphTextureLifetime lifetime = {};
|
||||
ASSERT_TRUE(compiledGraph.TryGetTextureLifetime(sourceColor, lifetime));
|
||||
EXPECT_TRUE(lifetime.used);
|
||||
EXPECT_EQ(lifetime.firstPassIndex, 0u);
|
||||
EXPECT_EQ(lifetime.lastPassIndex, 0u);
|
||||
|
||||
ASSERT_TRUE(RenderGraphExecutor::Execute(compiledGraph, renderContext, &errorMessage))
|
||||
<< errorMessage.CStr();
|
||||
EXPECT_TRUE(executionSucceeded);
|
||||
EXPECT_TRUE(feature.lastReceivedSourceColorTextureValid);
|
||||
EXPECT_TRUE(feature.lastHasSourceSurface);
|
||||
EXPECT_EQ(feature.lastSourceSurfaceWidth, 96u);
|
||||
EXPECT_EQ(feature.lastSourceSurfaceHeight, 48u);
|
||||
EXPECT_EQ(feature.lastSourceSurfaceRenderAreaWidth, 85u);
|
||||
EXPECT_EQ(feature.lastSourceSurfaceRenderAreaHeight, 41u);
|
||||
EXPECT_FALSE(feature.lastSourceSurfaceAutoTransitionEnabled);
|
||||
EXPECT_NE(feature.lastSourceColorView, nullptr);
|
||||
}
|
||||
|
||||
TEST(BuiltinForwardPipeline_Test, RegistersBuiltinDefaultForwardSceneFeatures) {
|
||||
BuiltinForwardPipeline pipeline;
|
||||
|
||||
@@ -920,6 +1043,7 @@ TEST(SceneRenderFeatureHost_Test, RecordsActiveInjectionPointFeaturesIntoRenderG
|
||||
nullptr,
|
||||
nullptr,
|
||||
ResourceStates::Common,
|
||||
{},
|
||||
{ colorTarget },
|
||||
depthTarget,
|
||||
{},
|
||||
|
||||
Reference in New Issue
Block a user