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
@@ -46,8 +46,6 @@ namespace AZ
RPI::ViewPtr m_view = nullptr;
Entity* m_modelEntity = nullptr;
double m_simulateTime = 0.0f;
float m_deltaTime = 0.0f;
int m_thumbnailSize = 512;
//! Incoming thumbnail requests are appended to this queue and processed one at a time in OnTick function.
@@ -81,11 +81,8 @@ namespace AZ
m_context->GetData()->m_view->SetCameraTransform(Matrix3x4::CreateFromTransform(cameraTransform));
}
void CaptureStep::OnTick(float deltaTime, ScriptTimePoint time)
void CaptureStep::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] ScriptTimePoint time)
{
m_context->GetData()->m_deltaTime = deltaTime;
m_context->GetData()->m_simulateTime = time.GetSeconds();
if (m_readyToCapture && m_ticksToCapture-- <= 0)
{
m_context->GetData()->m_renderPipeline->AddToRenderTickOnce();
@@ -72,34 +72,6 @@ namespace AZ
data->m_scene = RPI::Scene::CreateScene(sceneDesc);
// Setup scene srg modification callback (to push per-frame values to the shaders)
RPI::ShaderResourceGroupCallback callback = [data](RPI::ShaderResourceGroup* srg)
{
if (srg == nullptr)
{
return;
}
bool needCompile = false;
RHI::ShaderInputConstantIndex timeIndex = srg->FindShaderInputConstantIndex(Name{ "m_time" });
if (timeIndex.IsValid())
{
srg->SetConstant(timeIndex, aznumeric_cast<float>(data->m_simulateTime));
needCompile = true;
}
RHI::ShaderInputConstantIndex deltaTimeIndex = srg->FindShaderInputConstantIndex(Name{ "m_deltaTime" });
if (deltaTimeIndex.IsValid())
{
srg->SetConstant(deltaTimeIndex, data->m_deltaTime);
needCompile = true;
}
if (needCompile)
{
srg->Compile();
}
};
data->m_scene->SetShaderResourceGroupCallback(callback);
// Bind m_defaultScene to the GameEntityContext's AzFramework::Scene
auto* sceneSystem = AzFramework::SceneSystemInterface::Get();
AZ_Assert(sceneSystem, "Thumbnail system failed to get scene system implementation.");