Unify camera frame graph resource binding helpers
This commit is contained in:
@@ -759,6 +759,18 @@ public:
|
||||
|
||||
bool RecordRenderGraph(const RenderPassRenderGraphContext& context) override {
|
||||
m_state->eventLog.push_back(std::string("record:") + m_label);
|
||||
lastRecordedSourceColorTextureValid = context.sourceColorTexture.IsValid();
|
||||
lastRecordedRenderGraphBlackboard = context.blackboard != nullptr;
|
||||
if (const CameraFrameRenderGraphResources* frameResources =
|
||||
TryGetCameraFrameRenderGraphResources(context.blackboard)) {
|
||||
lastRecordedBlackboardMainSceneColorValid =
|
||||
frameResources->mainScene.color.IsValid();
|
||||
lastRecordedBlackboardPostProcessColorValid =
|
||||
frameResources->postProcess.color.IsValid();
|
||||
} else {
|
||||
lastRecordedBlackboardMainSceneColorValid = false;
|
||||
lastRecordedBlackboardPostProcessColorValid = false;
|
||||
}
|
||||
const bool writesColor =
|
||||
context.sourceSurface != nullptr ||
|
||||
!context.colorTargets.empty();
|
||||
@@ -815,6 +827,10 @@ public:
|
||||
bool lastSourceSurfaceAutoTransitionEnabled = true;
|
||||
XCEngine::RHI::RHIResourceView* lastSourceColorView = nullptr;
|
||||
XCEngine::RHI::ResourceStates lastSourceColorState = XCEngine::RHI::ResourceStates::Common;
|
||||
bool lastRecordedSourceColorTextureValid = false;
|
||||
bool lastRecordedRenderGraphBlackboard = false;
|
||||
bool lastRecordedBlackboardMainSceneColorValid = false;
|
||||
bool lastRecordedBlackboardPostProcessColorValid = false;
|
||||
};
|
||||
|
||||
RenderContext CreateValidContext() {
|
||||
@@ -1791,6 +1807,105 @@ TEST(CameraRenderer_Test, RecordsGraphCapableSinglePassSequenceStagesInDocumente
|
||||
EXPECT_FALSE(overlayPassRaw->lastSurfaceAutoTransitionEnabled);
|
||||
}
|
||||
|
||||
TEST(CameraRenderer_Test, ResolvesGraphManagedFullscreenSequenceSourcesFromFrameResources) {
|
||||
Scene scene("CameraRendererGraphManagedFullscreenSources");
|
||||
|
||||
GameObject* cameraObject = scene.CreateGameObject("Camera");
|
||||
auto* camera = cameraObject->AddComponent<CameraComponent>();
|
||||
camera->SetPrimary(true);
|
||||
camera->SetDepth(3.0f);
|
||||
|
||||
auto state = std::make_shared<MockPipelineState>();
|
||||
state->supportsMainSceneRenderGraph = true;
|
||||
CameraRenderer renderer(std::make_unique<MockPipeline>(state));
|
||||
auto allocationState = std::make_shared<MockShadowAllocationState>();
|
||||
MockShadowDevice device(allocationState);
|
||||
MockShadowView colorView(
|
||||
allocationState,
|
||||
XCEngine::RHI::ResourceViewType::RenderTarget,
|
||||
XCEngine::RHI::Format::R8G8B8A8_UNorm,
|
||||
XCEngine::RHI::ResourceViewDimension::Texture2D);
|
||||
MockShadowView depthView(
|
||||
allocationState,
|
||||
XCEngine::RHI::ResourceViewType::DepthStencil,
|
||||
XCEngine::RHI::Format::D24_UNorm_S8_UInt,
|
||||
XCEngine::RHI::ResourceViewDimension::Texture2D);
|
||||
|
||||
auto postProcessPass = std::make_unique<TrackingPass>(state, "postProcess", true, true, true);
|
||||
TrackingPass* postProcessPassRaw = postProcessPass.get();
|
||||
RenderPassSequence postProcessPasses;
|
||||
postProcessPasses.AddPass(std::move(postProcessPass));
|
||||
|
||||
auto finalOutputPass = std::make_unique<TrackingPass>(state, "finalOutput", true, true, true);
|
||||
TrackingPass* finalOutputPassRaw = finalOutputPass.get();
|
||||
RenderPassSequence finalOutputPasses;
|
||||
finalOutputPasses.AddPass(std::move(finalOutputPass));
|
||||
|
||||
CameraRenderRequest request;
|
||||
request.scene = &scene;
|
||||
request.camera = camera;
|
||||
request.context = CreateValidContext();
|
||||
request.context.device = &device;
|
||||
request.surface = RenderSurface(320, 180);
|
||||
request.surface.SetColorAttachment(&colorView);
|
||||
request.surface.SetDepthAttachment(&depthView);
|
||||
request.cameraDepth = camera->GetDepth();
|
||||
request.postProcess.passes = &postProcessPasses;
|
||||
request.finalOutput.passes = &finalOutputPasses;
|
||||
request.finalOutput.destinationSurface = request.surface;
|
||||
|
||||
CameraFramePlan plan = CameraFramePlan::FromRequest(request);
|
||||
plan.usesGraphManagedMainSceneColor = true;
|
||||
plan.ConfigureGraphManagedMainSceneSurface();
|
||||
plan.usesGraphManagedPostProcessColor = true;
|
||||
plan.postProcessSource = CameraFrameColorSource::MainSceneColor;
|
||||
plan.finalOutputSource = CameraFrameColorSource::PostProcessColor;
|
||||
|
||||
ASSERT_TRUE(plan.IsPostProcessStageValid());
|
||||
ASSERT_TRUE(plan.IsFinalOutputStageValid());
|
||||
const bool renderResult = renderer.Render(plan);
|
||||
EXPECT_TRUE(renderResult);
|
||||
EXPECT_EQ(state->recordMainSceneCalls, 1);
|
||||
EXPECT_EQ(state->executeRecordedMainSceneCalls, 1);
|
||||
|
||||
EXPECT_EQ(
|
||||
state->eventLog,
|
||||
(std::vector<std::string>{
|
||||
"record:postProcess",
|
||||
"record:finalOutput",
|
||||
"pipelineGraph",
|
||||
"init:postProcess",
|
||||
"postProcess",
|
||||
"init:finalOutput",
|
||||
"finalOutput" }));
|
||||
|
||||
ASSERT_NE(postProcessPassRaw, nullptr);
|
||||
EXPECT_TRUE(postProcessPassRaw->lastRecordedRenderGraphBlackboard);
|
||||
EXPECT_TRUE(postProcessPassRaw->lastRecordedSourceColorTextureValid);
|
||||
EXPECT_TRUE(postProcessPassRaw->lastRecordedBlackboardMainSceneColorValid);
|
||||
EXPECT_NE(postProcessPassRaw->lastSourceColorView, nullptr);
|
||||
EXPECT_TRUE(postProcessPassRaw->lastHasSourceSurface);
|
||||
EXPECT_EQ(postProcessPassRaw->lastSourceSurfaceWidth, 320u);
|
||||
EXPECT_EQ(postProcessPassRaw->lastSourceSurfaceHeight, 180u);
|
||||
EXPECT_FALSE(postProcessPassRaw->lastSourceSurfaceAutoTransitionEnabled);
|
||||
EXPECT_EQ(
|
||||
postProcessPassRaw->lastSourceColorState,
|
||||
XCEngine::RHI::ResourceStates::PixelShaderResource);
|
||||
|
||||
ASSERT_NE(finalOutputPassRaw, nullptr);
|
||||
EXPECT_TRUE(finalOutputPassRaw->lastRecordedRenderGraphBlackboard);
|
||||
EXPECT_TRUE(finalOutputPassRaw->lastRecordedSourceColorTextureValid);
|
||||
EXPECT_TRUE(finalOutputPassRaw->lastRecordedBlackboardPostProcessColorValid);
|
||||
EXPECT_NE(finalOutputPassRaw->lastSourceColorView, nullptr);
|
||||
EXPECT_TRUE(finalOutputPassRaw->lastHasSourceSurface);
|
||||
EXPECT_EQ(finalOutputPassRaw->lastSourceSurfaceWidth, 320u);
|
||||
EXPECT_EQ(finalOutputPassRaw->lastSourceSurfaceHeight, 180u);
|
||||
EXPECT_FALSE(finalOutputPassRaw->lastSourceSurfaceAutoTransitionEnabled);
|
||||
EXPECT_EQ(
|
||||
finalOutputPassRaw->lastSourceColorState,
|
||||
XCEngine::RHI::ResourceStates::PixelShaderResource);
|
||||
}
|
||||
|
||||
TEST(CameraRenderer_Test, ExecutesShadowCasterAndDepthOnlyRequestsBeforeMainPipeline) {
|
||||
Scene scene("CameraRendererDepthAndShadowScene");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user