ATOM-16063 Remove SetShaderResourceGroupCallback in scene and update scene srg handling (#3969)

ATOM-16273 Compiling SceneSRG before updating it can cause a gpu crash

Changes include:
1. Removed Scene::SetShaderResourceGroupCallback() function and clean up code which use this function.
2. Moved SceneTimeSrg.azsli to RPI's DefaultSceneSrg folder and setup the constants in RPI::Scene
3. Add AZ::Event for Scene's update srg event which features and update scene srg at proper place
4. UpdateTransformServcie FP to use PrepareSceneSrg event handler.
5. Clean up shaders and srgs used in project templates.

Signed-off-by: Qing Tao <qingtao@amazon.com>
This commit is contained in:
Qing Tao
2021-09-10 10:38:16 -07:00
committed by GitHub
parent 280796e1f4
commit d9cbc97ec0
30 changed files with 80 additions and 381 deletions
+27 -20
View File
@@ -352,6 +352,8 @@ namespace AZ
{
AZ_ATOM_PROFILE_FUNCTION("RPI", "Scene: Simulate");
m_simulationTime = tickInfo.m_currentGameTime;
// If previous simulation job wasn't done, wait for it to finish.
WaitAndCleanCompletionJob(m_simulationCompletion);
@@ -395,6 +397,29 @@ namespace AZ
}
}
void Scene::ConnectEvent(PrepareSceneSrgEvent::Handler& handler)
{
handler.Connect(m_prepareSrgEvent);
}
void Scene::PrepareSceneSrg()
{
if (m_srg)
{
// Set value for constants defined in SceneTimeSrg.azsli
RHI::ShaderInputConstantIndex timeIndex = m_srg->FindShaderInputConstantIndex(Name{ "m_time" });
if (timeIndex.IsValid())
{
m_srg->SetConstant(timeIndex, m_simulationTime);
}
// signal any handlers to update values for their partial scene srg
m_prepareSrgEvent.Signal(m_srg.get());
m_srg->Compile();
}
}
void Scene::PrepareRender(const TickTimeInfo& tickInfo, RHI::JobPolicy jobPolicy)
{
AZ_ATOM_PROFILE_FUNCTION("RPI", "Scene: PrepareRender");
@@ -407,16 +432,6 @@ namespace AZ
SceneNotificationBus::Event(GetId(), &SceneNotification::OnBeginPrepareRender);
{
AZ_PROFILE_SCOPE(RPI, "m_srgCallback");
AZ_ATOM_PROFILE_TIME_GROUP_REGION("RPI", "ShaderResourceGroupCallback: SrgCallback");
// Set values for scene srg
if (m_srg && m_srgCallback)
{
m_srgCallback(m_srg.get());
}
}
// Get active pipelines which need to be rendered and notify them frame started
AZStd::vector<RenderPipelinePtr> activePipelines;
{
@@ -587,17 +602,14 @@ namespace AZ
void Scene::UpdateSrgs()
{
PrepareSceneSrg();
for (auto& view : m_renderPacket.m_views)
{
view->UpdateSrg();
}
}
void Scene::SetShaderResourceGroupCallback(ShaderResourceGroupCallback callback)
{
m_srgCallback = callback;
}
const RHI::ShaderResourceGroup* Scene::GetRHIShaderResourceGroup() const
{
if (m_srg.get())
@@ -641,11 +653,6 @@ namespace AZ
return m_pipelines;
}
Scene* Scene::FindSelf()
{
return this;
}
void Scene::OnSceneNotifictaionHandlerConnected(SceneNotification* handler)
{
for (auto renderPipeline : m_pipelines)