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>
monroegm-disable-blank-issue-2
Qing Tao 4 years ago committed by GitHub
parent 280796e1f4
commit d9cbc97ec0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,51 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <viewsrg.srgi>
#include <Atom/RPI/Assets/ShaderLib/Atom/RPI/ShaderResourceGroups/DefaultObjectSrg.azsli>
#include <Atom/RPI/Assets/ShaderLib/Atom/RPI/TangentSpace.azsli>
struct VertexInput
{
float3 m_position : POSITION;
float3 m_normal : NORMAL;
float4 m_tangent : TANGENT;
float3 m_bitangent : BITANGENT;
float2 m_uv : UV0;
};
struct VertexOutput
{
float4 m_position : SV_Position;
float3 m_normal : NORMAL;
float3 m_tangent : TANGENT;
float3 m_bitangent : BITANGENT;
float2 m_uv : UV0;
float3 m_view : VIEW;
};
VertexOutput CommonVS(VertexInput input)
{
float4x4 objectToWorld = ObjectSrg::GetWorldMatrix();
float3x3 objectToWorldIT = ObjectSrg::GetWorldMatrixInverseTranspose();
VertexOutput output;
float3 worldPosition = mul(objectToWorld, float4(input.m_position, 1)).xyz;
output.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(worldPosition, 1.0));
output.m_uv = input.m_uv;
output.m_view = worldPosition - ViewSrg::m_worldPosition;
ConstructTBN(input.m_normal, input.m_tangent, input.m_bitangent, objectToWorld, objectToWorldIT, output.m_normal, output.m_tangent, output.m_bitangent);
return output;
}

@ -253,34 +253,6 @@ namespace AZ
RPI::SceneDescriptor sceneDesc; RPI::SceneDescriptor sceneDesc;
AZ::RPI::ScenePtr atomScene = RPI::Scene::CreateScene(sceneDesc); AZ::RPI::ScenePtr atomScene = RPI::Scene::CreateScene(sceneDesc);
atomScene->EnableAllFeatureProcessors(); atomScene->EnableAllFeatureProcessors();
// Setup scene srg modification callback.
RPI::ShaderResourceGroupCallback callback = [this](RPI::ShaderResourceGroup* srg)
{
if (srg == nullptr)
{
return;
}
bool needCompile = false;
RHI::ShaderInputConstantIndex timeIndex = srg->FindShaderInputConstantIndex(Name{ "m_time" });
if (timeIndex.IsValid())
{
srg->SetConstant(timeIndex, m_simulateTime);
needCompile = true;
}
RHI::ShaderInputConstantIndex deltaTimeIndex = srg->FindShaderInputConstantIndex(Name{ "m_deltaTime" });
if (deltaTimeIndex.IsValid())
{
srg->SetConstant(deltaTimeIndex, m_deltaTime);
needCompile = true;
}
if (needCompile)
{
srg->Compile();
}
};
atomScene->SetShaderResourceGroupCallback(callback);
atomScene->Activate(); atomScene->Activate();
// Register scene to RPI system so it will be processed/rendered per tick // Register scene to RPI system so it will be processed/rendered per tick
@ -408,11 +380,8 @@ namespace AZ
m_renderPipelineId = ""; m_renderPipelineId = "";
} }
void BootstrapSystemComponent::OnTick(float deltaTime, [[maybe_unused]] ScriptTimePoint time) void BootstrapSystemComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] ScriptTimePoint time)
{ {
m_simulateTime += deltaTime;
m_deltaTime = deltaTime;
// Temp: When running in the launcher without the legacy renderer // Temp: When running in the launcher without the legacy renderer
// we need to call RenderTick on the viewport context each frame. // we need to call RenderTick on the viewport context each frame.
if (m_viewportContext) if (m_viewportContext)

@ -105,9 +105,6 @@ namespace AZ
RPI::ScenePtr m_defaultScene = nullptr; RPI::ScenePtr m_defaultScene = nullptr;
AZStd::shared_ptr<AzFramework::Scene> m_defaultFrameworkScene = nullptr; AZStd::shared_ptr<AzFramework::Scene> m_defaultFrameworkScene = nullptr;
float m_simulateTime = 0;
float m_deltaTime = 0.016f;
bool m_isAssetCatalogLoaded = false; bool m_isAssetCatalogLoaded = false;
// The id of the render pipeline created by this component // The id of the render pipeline created by this component

@ -11,6 +11,6 @@
// Please review README.md to understand how this file is used in SceneSrg.azsrg generation // Please review README.md to understand how this file is used in SceneSrg.azsrg generation
#ifdef AZ_COLLECTING_PARTIAL_SRGS #ifdef AZ_COLLECTING_PARTIAL_SRGS
#include <Atom/Feature/Common/Assets/ShaderResourceGroups/SceneTimeSrg.azsli> #include <Atom/RPI/ShaderResourceGroups/DefaultSceneSrg.azsli>
#include <Atom/Feature/Common/Assets/ShaderResourceGroups/SceneSrg.azsli> #include <Atom/Feature/Common/Assets/ShaderResourceGroups/SceneSrg.azsli>
#endif #endif

@ -78,10 +78,12 @@ void MainCS(uint3 dispatch_id : SV_DispatchThreadID)
const float speed = exposureDifference > 0.0 ? ViewSrg::m_exposureControl.m_speedUp : ViewSrg::m_exposureControl.m_speedDown; const float speed = exposureDifference > 0.0 ? ViewSrg::m_exposureControl.m_speedUp : ViewSrg::m_exposureControl.m_speedDown;
// Update the adjustment for this frame based on the frame deltaTime and speed // Update the adjustment for this frame based on the frame deltaTime and speed
float exposureAdjustment = exposureDifference * SceneSrg::m_deltaTime * speed; float deltaTime = clamp(SceneSrg::m_time - PassSrg::m_eyeAdaptationData[0].m_setValueTime, 0.0f, 1.0f);
float exposureAdjustment = exposureDifference * deltaTime * speed;
float newExposureLog2 = previousFrameExposureLog2 + exposureAdjustment; float newExposureLog2 = previousFrameExposureLog2 + exposureAdjustment;
// Store the linear exposure so it can be used by the look modification transform later. // Store the linear exposure so it can be used by the look modification transform later.
// newExposureLog2 is negated because m_exposureValue is used to correct for a given exposure. // newExposureLog2 is negated because m_exposureValue is used to correct for a given exposure.
PassSrg::m_eyeAdaptationData[0].m_exposureValue = pow(2.0f, -newExposureLog2); PassSrg::m_eyeAdaptationData[0].m_exposureValue = pow(2.0f, -newExposureLog2);
PassSrg::m_eyeAdaptationData[0].m_setValueTime = SceneSrg::m_time;
} }

@ -8,5 +8,6 @@
struct EyeAdaptation struct EyeAdaptation
{ {
float m_exposureValue; // current frame's exposure value in stops (logarithmic space) float m_exposureValue; // current frame's exposure value in stops (logarithmic space)
float m_setValueTime; // the time when the m_exposureValue was set
}; };

@ -289,7 +289,6 @@ set(FILES
ShaderLib/Atom/Features/Vertex/VertexHelper.azsli ShaderLib/Atom/Features/Vertex/VertexHelper.azsli
ShaderResourceGroups/SceneSrg.azsli ShaderResourceGroups/SceneSrg.azsli
ShaderResourceGroups/SceneSrgAll.azsli ShaderResourceGroups/SceneSrgAll.azsli
ShaderResourceGroups/SceneTimeSrg.azsli
ShaderResourceGroups/ViewSrg.azsli ShaderResourceGroups/ViewSrg.azsli
ShaderResourceGroups/ViewSrgAll.azsli ShaderResourceGroups/ViewSrgAll.azsli
ShaderResourceGroups/CoreLights/SceneSrg.azsli ShaderResourceGroups/CoreLights/SceneSrg.azsli

@ -12,6 +12,7 @@
#include <Atom/RHI/Buffer.h> #include <Atom/RHI/Buffer.h>
#include <Atom/RHI/BufferPool.h> #include <Atom/RHI/BufferPool.h>
#include <Atom/RPI.Public/FeatureProcessor.h> #include <Atom/RPI.Public/FeatureProcessor.h>
#include <Atom/RPI.Public/Scene.h>
#include <Atom/RPI.Public/Shader/ShaderResourceGroup.h> #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
namespace AZ namespace AZ
@ -36,8 +37,6 @@ namespace AZ
void Activate() override; void Activate() override;
//! Releases GPU resources. //! Releases GPU resources.
void Deactivate() override; void Deactivate() override;
//! Binds buffers
void Render(const FeatureProcessor::RenderPacket& packet) override;
// RPI::SceneNotificationBus overrides ... // RPI::SceneNotificationBus overrides ...
void OnBeginPrepareRender() override; void OnBeginPrepareRender() override;
@ -68,11 +67,13 @@ namespace AZ
// Prepare GPU buffers for object transformation matrices // Prepare GPU buffers for object transformation matrices
// Create the buffers if they don't exist. Otherwise, resize them if they are not large enough for the matrices // Create the buffers if they don't exist. Otherwise, resize them if they are not large enough for the matrices
void PrepareBuffers(); void PrepareBuffers();
Data::Instance<RPI::ShaderResourceGroup> m_sceneSrg; void UpdateSceneSrg(RPI::ShaderResourceGroup *sceneSrg);
RHI::ShaderInputBufferIndex m_objectToWorldBufferIndex;
RHI::ShaderInputBufferIndex m_objectToWorldInverseTransposeBufferIndex; RPI::Scene::PrepareSceneSrgEvent::Handler m_updateSceneSrgHandler;
RHI::ShaderInputBufferIndex m_objectToWorldHistoryBufferIndex; RHI::ShaderInputNameIndex m_objectToWorldBufferIndex = "m_objectToWorldBuffer";
RHI::ShaderInputNameIndex m_objectToWorldInverseTransposeBufferIndex = "m_objectToWorldInverseTransposeBuffer";
RHI::ShaderInputNameIndex m_objectToWorldHistoryBufferIndex = "m_objectToWorldHistoryBuffer";
// Stores transforms that are uploaded to a GPU buffer. Used slots have float12(matrix3x4) values, empty slots // Stores transforms that are uploaded to a GPU buffer. Used slots have float12(matrix3x4) values, empty slots
// have a uint32_t that points to the next empty slot like a linked list. m_firstAvailableMeshTransformIndex stores the first // have a uint32_t that points to the next empty slot like a linked list. m_firstAvailableMeshTransformIndex stores the first

@ -36,8 +36,6 @@ namespace AZ
m_viewPtr = view; m_viewPtr = view;
m_viewSrg = view->GetShaderResourceGroup(); m_viewSrg = view->GetShaderResourceGroup();
m_exposureControlBufferInputIndex = m_viewSrg->FindShaderInputBufferIndex(Name("m_exposureControl"));
m_eyeAdaptationBuffer.Init(m_viewSrg, idNumber); m_eyeAdaptationBuffer.Init(m_viewSrg, idNumber);
} }
@ -109,14 +107,10 @@ namespace AZ
m_eyeAdaptationBuffer.UpdateSrg(); m_eyeAdaptationBuffer.UpdateSrg();
if (m_exposureControlBufferInputIndex.IsValid()) m_viewSrg->SetBufferView(m_exposureControlBufferInputIndex, m_buffer->GetBufferView());
if (m_viewPtr)
{ {
m_viewSrg->SetBufferView(m_exposureControlBufferInputIndex, m_buffer->GetBufferView()); m_viewPtr->InvalidateSrg();
if (m_viewPtr)
{
m_viewPtr->InvalidateSrg();
}
} }
} }

@ -52,6 +52,7 @@ namespace AZ
struct ExposureCalculationData struct ExposureCalculationData
{ {
float m_exposureValue = 1.0f; float m_exposureValue = 1.0f;
float m_setValueTime = 0;
}; };
void BuildInternal() override; void BuildInternal() override;

@ -36,11 +36,8 @@ namespace AZ
void TransformServiceFeatureProcessor::Activate() void TransformServiceFeatureProcessor::Activate()
{ {
m_sceneSrg = GetParentScene()->GetShaderResourceGroup(); m_updateSceneSrgHandler = RPI::Scene::PrepareSceneSrgEvent::Handler([this](RPI::ShaderResourceGroup *sceneSrg) { this->UpdateSceneSrg(sceneSrg); });
GetParentScene()->ConnectEvent(m_updateSceneSrgHandler);
m_objectToWorldBufferIndex = m_sceneSrg->FindShaderInputBufferIndex(Name{"m_objectToWorldBuffer"});
m_objectToWorldInverseTransposeBufferIndex = m_sceneSrg->FindShaderInputBufferIndex(Name{"m_objectToWorldInverseTransposeBuffer"});
m_objectToWorldHistoryBufferIndex = m_sceneSrg->FindShaderInputBufferIndex(Name{"m_objectToWorldHistoryBuffer"});
m_deviceBufferNeedsUpdate = true; m_deviceBufferNeedsUpdate = true;
m_objectToWorldTransforms.reserve(BufferReserveCount); m_objectToWorldTransforms.reserve(BufferReserveCount);
@ -62,9 +59,14 @@ namespace AZ
m_firstAvailableTransformIndex = NoAvailableTransformIndices; m_firstAvailableTransformIndex = NoAvailableTransformIndices;
m_objectToWorldBufferIndex.Reset();
m_objectToWorldInverseTransposeBufferIndex.Reset();
m_objectToWorldHistoryBufferIndex.Reset();
m_isWriteable = false; m_isWriteable = false;
RPI::SceneNotificationBus::Handler::BusDisconnect(); RPI::SceneNotificationBus::Handler::BusDisconnect();
m_updateSceneSrgHandler.Disconnect();
} }
void TransformServiceFeatureProcessor::PrepareBuffers() void TransformServiceFeatureProcessor::PrepareBuffers()
@ -131,16 +133,11 @@ namespace AZ
} }
} }
void TransformServiceFeatureProcessor::Render([[maybe_unused]] const FeatureProcessor::RenderPacket& packet) void TransformServiceFeatureProcessor::UpdateSceneSrg(RPI::ShaderResourceGroup *sceneSrg)
{ {
AZ_ATOM_PROFILE_FUNCTION("RPI", "TransformServiceFeatureProcessor: Render"); sceneSrg->SetBufferView(m_objectToWorldBufferIndex, m_objectToWorldBuffer->GetBufferView());
AZ_UNUSED(packet); sceneSrg->SetBufferView(m_objectToWorldInverseTransposeBufferIndex, m_objectToWorldInverseTransposeBuffer->GetBufferView());
sceneSrg->SetBufferView(m_objectToWorldHistoryBufferIndex, m_objectToWorldHistoryBuffer->GetBufferView());
AZ_Assert(!m_isWriteable, "Must be called between OnBeginPrepareRender() and OnEndPrepareRender()");
m_sceneSrg->SetBufferView(m_objectToWorldBufferIndex, m_objectToWorldBuffer->GetBufferView());
m_sceneSrg->SetBufferView(m_objectToWorldInverseTransposeBufferIndex, m_objectToWorldInverseTransposeBuffer->GetBufferView());
m_sceneSrg->SetBufferView(m_objectToWorldHistoryBufferIndex, m_objectToWorldHistoryBuffer->GetBufferView());
} }
void TransformServiceFeatureProcessor::OnBeginPrepareRender() void TransformServiceFeatureProcessor::OnBeginPrepareRender()

@ -13,6 +13,5 @@
partial ShaderResourceGroup SceneSrg partial ShaderResourceGroup SceneSrg
{ {
float m_time; float m_time;
float m_deltaTime;
} }

@ -129,10 +129,6 @@ namespace AZ
void RemoveRenderPipeline(const RenderPipelineId& pipelineId); void RemoveRenderPipeline(const RenderPipelineId& pipelineId);
//! Set a callback function to set values for scene's srg.
//! The callback function is usually defined by the one who create the scene since it knows how the layout look like.
void SetShaderResourceGroupCallback(ShaderResourceGroupCallback callback);
const RHI::ShaderResourceGroup* GetRHIShaderResourceGroup() const; const RHI::ShaderResourceGroup* GetRHIShaderResourceGroup() const;
Data::Instance<ShaderResourceGroup> GetShaderResourceGroup() const; Data::Instance<ShaderResourceGroup> GetShaderResourceGroup() const;
@ -166,9 +162,13 @@ namespace AZ
RenderPipelinePtr FindRenderPipelineForWindow(AzFramework::NativeWindowHandle windowHandle); RenderPipelinePtr FindRenderPipelineForWindow(AzFramework::NativeWindowHandle windowHandle);
using PrepareSceneSrgEvent = AZ::Event<RPI::ShaderResourceGroup*>;
//! Connect a handler to listen to the event that the Scene is ready to update and compile its scene srg
//! User should use this event to update the part scene srg they know of
void ConnectEvent(PrepareSceneSrgEvent::Handler& handler);
protected: protected:
// SceneFinder overrides... // SceneFinder overrides...
Scene* FindSelf();
void OnSceneNotifictaionHandlerConnected(SceneNotification* handler); void OnSceneNotifictaionHandlerConnected(SceneNotification* handler);
// Cpu simulation which runs all active FeatureProcessor Simulate() functions. // Cpu simulation which runs all active FeatureProcessor Simulate() functions.
@ -183,7 +183,7 @@ namespace AZ
// Function called when the current frame is finished rendering. // Function called when the current frame is finished rendering.
void OnFrameEnd(); void OnFrameEnd();
// Update and compile view srgs // Update and compile scene and view srgs
// This is called after PassSystem's FramePrepare so passes can still modify view srgs in its FramePrepareIntenal function before they are submitted to command list // This is called after PassSystem's FramePrepare so passes can still modify view srgs in its FramePrepareIntenal function before they are submitted to command list
void UpdateSrgs(); void UpdateSrgs();
@ -200,6 +200,10 @@ namespace AZ
// Add a created feature processor to this scene // Add a created feature processor to this scene
void AddFeatureProcessor(FeatureProcessorPtr fp); void AddFeatureProcessor(FeatureProcessorPtr fp);
// Send out event to PrepareSceneSrgEvent::Handlers so they can update scene srg as needed
// This happens in UpdateSrgs()
void PrepareSceneSrg();
// List of feature processors that are active for this scene // List of feature processors that are active for this scene
AZStd::vector<FeatureProcessorPtr> m_featureProcessors; AZStd::vector<FeatureProcessorPtr> m_featureProcessors;
@ -215,9 +219,10 @@ namespace AZ
AZ::RPI::FeatureProcessor::SimulatePacket m_simulatePacket; AZ::RPI::FeatureProcessor::SimulatePacket m_simulatePacket;
AZ::RPI::FeatureProcessor::RenderPacket m_renderPacket; AZ::RPI::FeatureProcessor::RenderPacket m_renderPacket;
// Scene's srg and its set function // Scene's srg
Data::Instance<ShaderResourceGroup> m_srg; Data::Instance<ShaderResourceGroup> m_srg;
ShaderResourceGroupCallback m_srgCallback; // Event to for prepare scene srg
PrepareSceneSrgEvent m_prepareSrgEvent;
// The uuid to identify this scene. // The uuid to identify this scene.
SceneId m_id; SceneId m_id;
@ -234,6 +239,8 @@ namespace AZ
// Registry which allocates draw filter tag for RenderPipeline // Registry which allocates draw filter tag for RenderPipeline
RHI::Ptr<RHI::DrawFilterTagRegistry> m_drawFilterTagRegistry; RHI::Ptr<RHI::DrawFilterTagRegistry> m_drawFilterTagRegistry;
float m_simulationTime;
}; };
// --- Template functions --- // --- Template functions ---

@ -80,7 +80,6 @@ namespace AZ
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById; static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
using BusIdType = SceneId; using BusIdType = SceneId;
virtual Scene* FindSelf() = 0;
virtual void OnSceneNotifictaionHandlerConnected(SceneNotification* handler) = 0; virtual void OnSceneNotifictaionHandlerConnected(SceneNotification* handler) = 0;
}; };

@ -308,10 +308,10 @@ namespace AZ
// The fix is to clear the buffer outside of the callback. // The fix is to clear the buffer outside of the callback.
for (int32_t i = 0; i < RHI::Limits::Device::FrameCountMax; i++) for (int32_t i = 0; i < RHI::Limits::Device::FrameCountMax; i++)
{ {
if (m_isReadbackComplete[m_readbackBufferCurrentIndex]) if (m_isReadbackComplete[i])
{ {
m_isReadbackComplete[m_readbackBufferCurrentIndex] = false; m_isReadbackComplete[i] = false;
m_readbackBufferArray[m_readbackBufferCurrentIndex] = nullptr; m_readbackBufferArray[i] = nullptr;
} }
} }
// Loop the triple buffer index and cache the current index to the callback. // Loop the triple buffer index and cache the current index to the callback.

@ -293,7 +293,7 @@ namespace AZ
// scope producers only can be added to the frame when frame started which cleans up previous scope producers. // scope producers only can be added to the frame when frame started which cleans up previous scope producers.
m_passSystem.FrameUpdate(frameGraphBuilder); m_passSystem.FrameUpdate(frameGraphBuilder);
// Update View Srgs // Update Scene and View Srgs
for (auto& scenePtr : m_scenes) for (auto& scenePtr : m_scenes)
{ {
scenePtr->UpdateSrgs(); scenePtr->UpdateSrgs();

@ -352,6 +352,8 @@ namespace AZ
{ {
AZ_ATOM_PROFILE_FUNCTION("RPI", "Scene: Simulate"); AZ_ATOM_PROFILE_FUNCTION("RPI", "Scene: Simulate");
m_simulationTime = tickInfo.m_currentGameTime;
// If previous simulation job wasn't done, wait for it to finish. // If previous simulation job wasn't done, wait for it to finish.
WaitAndCleanCompletionJob(m_simulationCompletion); 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) void Scene::PrepareRender(const TickTimeInfo& tickInfo, RHI::JobPolicy jobPolicy)
{ {
AZ_ATOM_PROFILE_FUNCTION("RPI", "Scene: PrepareRender"); AZ_ATOM_PROFILE_FUNCTION("RPI", "Scene: PrepareRender");
@ -407,16 +432,6 @@ namespace AZ
SceneNotificationBus::Event(GetId(), &SceneNotification::OnBeginPrepareRender); 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 // Get active pipelines which need to be rendered and notify them frame started
AZStd::vector<RenderPipelinePtr> activePipelines; AZStd::vector<RenderPipelinePtr> activePipelines;
{ {
@ -587,17 +602,14 @@ namespace AZ
void Scene::UpdateSrgs() void Scene::UpdateSrgs()
{ {
PrepareSceneSrg();
for (auto& view : m_renderPacket.m_views) for (auto& view : m_renderPacket.m_views)
{ {
view->UpdateSrg(); view->UpdateSrg();
} }
} }
void Scene::SetShaderResourceGroupCallback(ShaderResourceGroupCallback callback)
{
m_srgCallback = callback;
}
const RHI::ShaderResourceGroup* Scene::GetRHIShaderResourceGroup() const const RHI::ShaderResourceGroup* Scene::GetRHIShaderResourceGroup() const
{ {
if (m_srg.get()) if (m_srg.get())
@ -641,11 +653,6 @@ namespace AZ
return m_pipelines; return m_pipelines;
} }
Scene* Scene::FindSelf()
{
return this;
}
void Scene::OnSceneNotifictaionHandlerConnected(SceneNotification* handler) void Scene::OnSceneNotifictaionHandlerConnected(SceneNotification* handler)
{ {
for (auto renderPipeline : m_pipelines) for (auto renderPipeline : m_pipelines)

@ -70,22 +70,6 @@ namespace MaterialEditor
m_scene = AZ::RPI::Scene::CreateScene(sceneDesc); m_scene = AZ::RPI::Scene::CreateScene(sceneDesc);
m_scene->EnableAllFeatureProcessors(); m_scene->EnableAllFeatureProcessors();
// Setup scene srg modification callback.
AZ::RPI::ShaderResourceGroupCallback callback = [this](AZ::RPI::ShaderResourceGroup* srg)
{
if (srg == nullptr)
{
return;
}
AZ::RHI::ShaderInputConstantIndex timeIndex = srg->FindShaderInputConstantIndex(AZ::Name{ "m_time" });
if (timeIndex.IsValid())
{
srg->SetConstant(timeIndex, m_simulateTime);
srg->Compile();
}
};
m_scene->SetShaderResourceGroupCallback(callback);
// Bind m_defaultScene to the GameEntityContext's AzFramework::Scene // Bind m_defaultScene to the GameEntityContext's AzFramework::Scene
auto sceneSystem = AzFramework::SceneSystemInterface::Get(); auto sceneSystem = AzFramework::SceneSystemInterface::Get();
AZ_Assert(sceneSystem, "MaterialViewportRenderer was unable to get the scene system during construction."); AZ_Assert(sceneSystem, "MaterialViewportRenderer was unable to get the scene system during construction.");
@ -448,14 +432,12 @@ namespace MaterialEditor
} }
} }
void MaterialViewportRenderer::OnTick(float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time) void MaterialViewportRenderer::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
{ {
m_renderPipeline->AddToRenderTickOnce(); m_renderPipeline->AddToRenderTickOnce();
PerformanceMonitorRequestBus::Broadcast(&PerformanceMonitorRequestBus::Handler::GatherMetrics); PerformanceMonitorRequestBus::Broadcast(&PerformanceMonitorRequestBus::Handler::GatherMetrics);
m_simulateTime += deltaTime;
if (m_shadowCatcherMaterial) if (m_shadowCatcherMaterial)
{ {
// Compile the m_shadowCatcherMaterial in OnTick because changes can only be compiled once per frame. // Compile the m_shadowCatcherMaterial in OnTick because changes can only be compiled once per frame.

@ -114,8 +114,6 @@ namespace MaterialEditor
AZ::Entity* m_iblEntity = nullptr; AZ::Entity* m_iblEntity = nullptr;
AZ::Render::SkyBoxFeatureProcessorInterface* m_skyboxFeatureProcessor = nullptr; AZ::Render::SkyBoxFeatureProcessorInterface* m_skyboxFeatureProcessor = nullptr;
float m_simulateTime = 0;
AZStd::shared_ptr<MaterialEditorViewportInputController> m_viewportController; AZStd::shared_ptr<MaterialEditorViewportInputController> m_viewportController;
}; };
} // namespace MaterialEditor } // namespace MaterialEditor

@ -46,8 +46,6 @@ namespace AZ
RPI::ViewPtr m_view = nullptr; RPI::ViewPtr m_view = nullptr;
Entity* m_modelEntity = nullptr; Entity* m_modelEntity = nullptr;
double m_simulateTime = 0.0f;
float m_deltaTime = 0.0f;
int m_thumbnailSize = 512; int m_thumbnailSize = 512;
//! Incoming thumbnail requests are appended to this queue and processed one at a time in OnTick function. //! 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)); 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) if (m_readyToCapture && m_ticksToCapture-- <= 0)
{ {
m_context->GetData()->m_renderPipeline->AddToRenderTickOnce(); m_context->GetData()->m_renderPipeline->AddToRenderTickOnce();

@ -72,34 +72,6 @@ namespace AZ
data->m_scene = RPI::Scene::CreateScene(sceneDesc); 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 // Bind m_defaultScene to the GameEntityContext's AzFramework::Scene
auto* sceneSystem = AzFramework::SceneSystemInterface::Get(); auto* sceneSystem = AzFramework::SceneSystemInterface::Get();
AZ_Assert(sceneSystem, "Thumbnail system failed to get scene system implementation."); AZ_Assert(sceneSystem, "Thumbnail system failed to get scene system implementation.");

@ -22,6 +22,5 @@ partial ShaderResourceGroup SceneSrg : SRG_PerScene
}; };
#define AZ_COLLECTING_PARTIAL_SRGS #define AZ_COLLECTING_PARTIAL_SRGS
#include <Shaders/ShaderResourceGroups/SceneSrg.azsli> #include <Atom/Feature/Common/Assets/ShaderResourceGroups/SceneSrgAll.azsli>
#include <Atom/Feature/Common/Assets/ShaderResourceGroups/SceneSrg.azsli>
#undef AZ_COLLECTING_PARTIAL_SRGS #undef AZ_COLLECTING_PARTIAL_SRGS

@ -1,52 +0,0 @@
// {BEGIN_LICENSE}
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// {END_LICENSE}
#pragma once
#include <viewsrg.srgi>
#include <Atom/RPI/Assets/ShaderLib/Atom/RPI/ShaderResourceGroups/DefaultObjectSrg.azsli>
#include <Atom/RPI/Assets/ShaderLib/Atom/RPI/TangentSpace.azsli>
struct VertexInput
{
float3 m_position : POSITION;
float3 m_normal : NORMAL;
float4 m_tangent : TANGENT;
float3 m_bitangent : BITANGENT;
float2 m_uv : UV0;
};
struct VertexOutput
{
float4 m_position : SV_Position;
float3 m_normal : NORMAL;
float3 m_tangent : TANGENT;
float3 m_bitangent : BITANGENT;
float2 m_uv : UV0;
float3 m_view : VIEW;
};
VertexOutput CommonVS(VertexInput input)
{
float4x4 objectToWorld = ObjectSrg::GetWorldMatrix();
float3x3 objectToWorldIT = ObjectSrg::GetWorldMatrixInverseTranspose();
VertexOutput output;
float3 worldPosition = mul(objectToWorld, float4(input.m_position, 1)).xyz;
output.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(worldPosition, 1.0));
output.m_uv = input.m_uv;
output.m_view = worldPosition - ViewSrg::m_worldPosition;
ConstructTBN(input.m_normal, input.m_tangent, input.m_bitangent, objectToWorld, objectToWorldIT, output.m_normal, output.m_tangent, output.m_bitangent);
return output;
}

@ -1,20 +0,0 @@
// {BEGIN_LICENSE}
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// {END_LICENSE}
#ifndef AZ_COLLECTING_PARTIAL_SRGS
#error Do not include this file directly. Include the main .srgi file instead.
#endif
partial ShaderResourceGroup SceneSrg
{
float m_time;
float m_deltaTime;
}

@ -504,18 +504,6 @@
"isTemplated": true, "isTemplated": true,
"isOptional": false "isOptional": false
}, },
{
"file": "Shaders/CommonVS.azsli",
"origin": "Shaders/CommonVS.azsli",
"isTemplated": true,
"isOptional": false
},
{
"file": "Shaders/ShaderResourceGroups/SceneSrg.azsli",
"origin": "Shaders/ShaderResourceGroups/SceneSrg.azsli",
"isTemplated": true,
"isOptional": false
},
{ {
"file": "autoexec.cfg", "file": "autoexec.cfg",
"origin": "autoexec.cfg", "origin": "autoexec.cfg",

@ -22,6 +22,5 @@ partial ShaderResourceGroup SceneSrg : SRG_PerScene
}; };
#define AZ_COLLECTING_PARTIAL_SRGS #define AZ_COLLECTING_PARTIAL_SRGS
#include <Shaders/ShaderResourceGroups/SceneSrg.azsli> #include <Atom/Feature/Common/Assets/ShaderResourceGroups/SceneSrgAll.azsli>
#include <Atom/Feature/Common/Assets/ShaderResourceGroups/SceneSrg.azsli>
#undef AZ_COLLECTING_PARTIAL_SRGS #undef AZ_COLLECTING_PARTIAL_SRGS

@ -1,52 +0,0 @@
// {BEGIN_LICENSE}
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// {END_LICENSE}
#pragma once
#include <viewsrg.srgi>
#include <Atom/RPI/Assets/ShaderLib/Atom/RPI/ShaderResourceGroups/DefaultObjectSrg.azsli>
#include <Atom/RPI/Assets/ShaderLib/Atom/RPI/TangentSpace.azsli>
struct VertexInput
{
float3 m_position : POSITION;
float3 m_normal : NORMAL;
float4 m_tangent : TANGENT;
float3 m_bitangent : BITANGENT;
float2 m_uv : UV0;
};
struct VertexOutput
{
float4 m_position : SV_Position;
float3 m_normal : NORMAL;
float3 m_tangent : TANGENT;
float3 m_bitangent : BITANGENT;
float2 m_uv : UV0;
float3 m_view : VIEW;
};
VertexOutput CommonVS(VertexInput input)
{
float4x4 objectToWorld = ObjectSrg::GetWorldMatrix();
float3x3 objectToWorldIT = ObjectSrg::GetWorldMatrixInverseTranspose();
VertexOutput output;
float3 worldPosition = mul(objectToWorld, float4(input.m_position, 1)).xyz;
output.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(worldPosition, 1.0));
output.m_uv = input.m_uv;
output.m_view = worldPosition - ViewSrg::m_worldPosition;
ConstructTBN(input.m_normal, input.m_tangent, input.m_bitangent, objectToWorld, objectToWorldIT, output.m_normal, output.m_tangent, output.m_bitangent);
return output;
}

@ -1,20 +0,0 @@
// {BEGIN_LICENSE}
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// {END_LICENSE}
#ifndef AZ_COLLECTING_PARTIAL_SRGS
#error Do not include this file directly. Include the main .srgi file instead.
#endif
partial ShaderResourceGroup SceneSrg
{
float m_time;
float m_deltaTime;
}

@ -490,18 +490,6 @@
"isTemplated": true, "isTemplated": true,
"isOptional": false "isOptional": false
}, },
{
"file": "Shaders/CommonVS.azsli",
"origin": "Shaders/CommonVS.azsli",
"isTemplated": true,
"isOptional": false
},
{
"file": "Shaders/ShaderResourceGroups/SceneSrg.azsli",
"origin": "Shaders/ShaderResourceGroups/SceneSrg.azsli",
"isTemplated": true,
"isOptional": false
},
{ {
"file": "autoexec.cfg", "file": "autoexec.cfg",
"origin": "autoexec.cfg", "origin": "autoexec.cfg",

Loading…
Cancel
Save