Merge remote-tracking branch 'upstream/development' into Atom/rbarrand/MaterialVersionUpdate
This commit is contained in:
@@ -518,7 +518,6 @@ namespace AZ
|
||||
if (drawSrg)
|
||||
{
|
||||
drawItem.m_uniqueShaderResourceGroup = drawSrg->GetRHIShaderResourceGroup();
|
||||
m_cachedDrawSrg.push_back(drawSrg);
|
||||
}
|
||||
|
||||
// Set scissor per draw if scissor is enabled.
|
||||
@@ -608,7 +607,6 @@ namespace AZ
|
||||
if (drawSrg)
|
||||
{
|
||||
drawItem.m_uniqueShaderResourceGroup = drawSrg->GetRHIShaderResourceGroup();
|
||||
m_cachedDrawSrg.push_back(drawSrg);
|
||||
}
|
||||
|
||||
// Set scissor per draw if scissor is enabled.
|
||||
@@ -635,7 +633,22 @@ namespace AZ
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
auto drawSrg = AZ::RPI::ShaderResourceGroup::Create(m_shader->GetAsset(), m_shader->GetSupervariantIndex(), m_drawSrgLayout->GetName());
|
||||
|
||||
Data::Instance<ShaderResourceGroup> drawSrg;
|
||||
if (m_nextDrawSrgIdx == m_cachedDrawSrg.size())
|
||||
{
|
||||
drawSrg = AZ::RPI::ShaderResourceGroup::Create(m_shader->GetAsset(), m_shader->GetSupervariantIndex(), m_drawSrgLayout->GetName());
|
||||
m_cachedDrawSrg.push_back(drawSrg);
|
||||
}
|
||||
else if (m_nextDrawSrgIdx < m_cachedDrawSrg.size())
|
||||
{
|
||||
drawSrg = m_cachedDrawSrg[m_nextDrawSrgIdx];
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Assert(false, "Unexpected next draw srg index");
|
||||
}
|
||||
m_nextDrawSrgIdx++;
|
||||
|
||||
// Set fallback value for shader variant if draw srg contains constant for shader variant fallback
|
||||
if (m_hasShaderVariantKeyFallbackEntry)
|
||||
@@ -727,7 +740,7 @@ namespace AZ
|
||||
}
|
||||
|
||||
for (auto& drawItemProperties : m_cachedDrawList)
|
||||
{
|
||||
{
|
||||
view->AddDrawItem(m_drawListTag, drawItemProperties);
|
||||
}
|
||||
}
|
||||
@@ -743,9 +756,14 @@ namespace AZ
|
||||
m_cachedDrawItems.clear();
|
||||
m_cachedStreamBufferViews.clear();
|
||||
m_cachedIndexBufferViews.clear();
|
||||
m_cachedDrawSrg.clear();
|
||||
m_cachedDrawList.clear();
|
||||
m_nextDrawSrgIdx = 0;
|
||||
m_drawFinalized = false;
|
||||
|
||||
for (auto srg:m_cachedDrawSrg)
|
||||
{
|
||||
srg->ResetViews();
|
||||
}
|
||||
}
|
||||
|
||||
const RHI::PipelineState* DynamicDrawContext::GetCurrentPipelineState()
|
||||
|
||||
@@ -107,30 +107,13 @@ namespace AZ
|
||||
dispatchArgs.m_totalNumberOfThreadsY = passData->m_totalNumberOfThreadsY;
|
||||
dispatchArgs.m_totalNumberOfThreadsZ = passData->m_totalNumberOfThreadsZ;
|
||||
|
||||
const auto numThreads = m_shader->GetAsset()->GetAttribute(RHI::ShaderStage::Compute, Name{ "numthreads" });
|
||||
if (numThreads)
|
||||
const auto outcome = RPI::GetComputeShaderNumThreads(m_shader->GetAsset(), dispatchArgs);
|
||||
if (!outcome.IsSuccess())
|
||||
{
|
||||
const RHI::ShaderStageAttributeArguments& args = *numThreads;
|
||||
bool validArgs = args.size() == 3;
|
||||
if (validArgs)
|
||||
{
|
||||
validArgs &= args[0].type() == azrtti_typeid<int>();
|
||||
validArgs &= args[1].type() == azrtti_typeid<int>();
|
||||
validArgs &= args[2].type() == azrtti_typeid<int>();
|
||||
}
|
||||
|
||||
if (!validArgs)
|
||||
{
|
||||
AZ_Error("PassSystem", false, "[ComputePass '%s']: Shader '%s' contains invalid numthreads arguments.",
|
||||
GetPathName().GetCStr(),
|
||||
passData->m_shaderReference.m_filePath.data());
|
||||
return;
|
||||
}
|
||||
|
||||
dispatchArgs.m_threadsPerGroupX = aznumeric_cast<uint16_t>(AZStd::any_cast<int>(args[0]));
|
||||
dispatchArgs.m_threadsPerGroupY = aznumeric_cast<uint16_t>(AZStd::any_cast<int>(args[1]));
|
||||
dispatchArgs.m_threadsPerGroupZ = aznumeric_cast<uint16_t>(AZStd::any_cast<int>(args[2]));
|
||||
AZ_Error("PassSystem", false, "[ComputePass '%s']: Shader '%.*s' contains invalid numthreads arguments:\n%s",
|
||||
GetPathName().GetCStr(), passData->m_shaderReference.m_filePath.size(), passData->m_shaderReference.m_filePath.data(), outcome.GetError().c_str());
|
||||
}
|
||||
|
||||
m_dispatchItem.m_arguments = dispatchArgs;
|
||||
|
||||
m_isFullscreenPass = passData->m_makeFullscreenPass;
|
||||
|
||||
@@ -263,7 +263,7 @@ namespace AZ
|
||||
AZ::TickRequestBus::BroadcastResult(m_tickTime.m_gameDeltaTime, &AZ::TickRequestBus::Events::GetTickDeltaTime);
|
||||
ScriptTimePoint currentTime;
|
||||
AZ::TickRequestBus::BroadcastResult(currentTime, &AZ::TickRequestBus::Events::GetTimeAtCurrentTick);
|
||||
m_tickTime.m_currentGameTime = static_cast<float>(currentTime.GetMilliseconds());
|
||||
m_tickTime.m_currentGameTime = static_cast<float>(currentTime.GetSeconds());
|
||||
}
|
||||
|
||||
void RPISystem::RenderTick()
|
||||
|
||||
@@ -143,5 +143,79 @@ namespace AZ
|
||||
|
||||
return RPI::StreamingImage::FindOrCreate(streamingImageAsset);
|
||||
}
|
||||
|
||||
//! A helper function for GetComputeShaderNumThreads(), to consolidate error messages, etc.
|
||||
static bool GetAttributeArgumentByIndex(const Data::Asset<ShaderAsset>& shaderAsset, const AZ::Name& attributeName, const RHI::ShaderStageAttributeArguments& args, const size_t argIndex, uint16_t* value, AZStd::string& errorMsg)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
const auto numArguments = args.size();
|
||||
if (numArguments > argIndex)
|
||||
{
|
||||
if (args[argIndex].type() == azrtti_typeid<int>())
|
||||
{
|
||||
*value = aznumeric_caster(AZStd::any_cast<int>(args[argIndex]));
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMsg = AZStd::string::format("Was expecting argument '%zu' in attribute '%s' to be of type 'int' from shader asset '%s'", argIndex, attributeName.GetCStr(), shaderAsset.GetHint().c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMsg = AZStd::string::format("Was expecting at least '%zu' arguments in attribute '%s' from shader asset '%s'", argIndex + 1, attributeName.GetCStr(), shaderAsset.GetHint().c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
AZ::Outcome<void, AZStd::string> GetComputeShaderNumThreads(const Data::Asset<ShaderAsset>& shaderAsset, const AZ::Name& attributeName, uint16_t* numThreadsX, uint16_t* numThreadsY, uint16_t* numThreadsZ)
|
||||
{
|
||||
// Set default 1, 1, 1 now. In case of errors later this is what the caller will get.
|
||||
if (numThreadsX)
|
||||
{
|
||||
*numThreadsX = 1;
|
||||
}
|
||||
if (numThreadsY)
|
||||
{
|
||||
*numThreadsY = 1;
|
||||
}
|
||||
if (numThreadsZ)
|
||||
{
|
||||
*numThreadsZ = 1;
|
||||
}
|
||||
const auto numThreads = shaderAsset->GetAttribute(RHI::ShaderStage::Compute, attributeName);
|
||||
if (!numThreads)
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("Couldn't find attribute '%s' in shader asset '%s'", attributeName.GetCStr(), shaderAsset.GetHint().c_str()));
|
||||
}
|
||||
const RHI::ShaderStageAttributeArguments& args = *numThreads;
|
||||
AZStd::string errorMsg;
|
||||
if (!GetAttributeArgumentByIndex(shaderAsset, attributeName, args, 0, numThreadsX, errorMsg))
|
||||
{
|
||||
return AZ::Failure(errorMsg);
|
||||
}
|
||||
if (!GetAttributeArgumentByIndex(shaderAsset, attributeName, args, 1, numThreadsY, errorMsg))
|
||||
{
|
||||
return AZ::Failure(errorMsg);
|
||||
}
|
||||
if (!GetAttributeArgumentByIndex(shaderAsset, attributeName, args, 2, numThreadsZ, errorMsg))
|
||||
{
|
||||
return AZ::Failure(errorMsg);
|
||||
}
|
||||
return AZ::Success();
|
||||
}
|
||||
|
||||
AZ::Outcome<void, AZStd::string> GetComputeShaderNumThreads(const Data::Asset<ShaderAsset>& shaderAsset, uint16_t* numThreadsX, uint16_t* numThreadsY, uint16_t* numThreadsZ)
|
||||
{
|
||||
return GetComputeShaderNumThreads(shaderAsset, Name{ "numthreads" }, numThreadsX, numThreadsY, numThreadsZ);
|
||||
}
|
||||
|
||||
AZ::Outcome<void, AZStd::string> GetComputeShaderNumThreads(const Data::Asset<ShaderAsset>& shaderAsset, RHI::DispatchDirect& dispatchDirect)
|
||||
{
|
||||
return GetComputeShaderNumThreads(shaderAsset, &dispatchDirect.m_threadsPerGroupX, &dispatchDirect.m_threadsPerGroupY, &dispatchDirect.m_threadsPerGroupZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,12 +375,10 @@ namespace AZ
|
||||
m_scene->RemoveRenderPipeline(m_nameId);
|
||||
}
|
||||
|
||||
void RenderPipeline::OnStartFrame(const TickTimeInfo& tick)
|
||||
void RenderPipeline::OnStartFrame([[maybe_unused]] const TickTimeInfo& tick)
|
||||
{
|
||||
AZ_PROFILE_SCOPE(RPI, "RenderPipeline: OnStartFrame");
|
||||
|
||||
m_lastRenderStartTime = tick.m_currentGameTime;
|
||||
|
||||
OnPassModified();
|
||||
|
||||
for (auto& viewItr : m_pipelineViewsByTag)
|
||||
|
||||
@@ -114,6 +114,10 @@ namespace AZ
|
||||
void ShaderResourceGroup::Compile()
|
||||
{
|
||||
m_shaderResourceGroup->Compile(m_data);
|
||||
|
||||
//Disable compilation for all resource types as a performance optimization
|
||||
//No need to re-update SRG data on GPU timeline if nothing was updated.
|
||||
m_data.DisableCompilationForAllResourceTypes();
|
||||
}
|
||||
|
||||
bool ShaderResourceGroup::IsQueuedForCompile() const
|
||||
@@ -580,6 +584,11 @@ namespace AZ
|
||||
return {};
|
||||
}
|
||||
|
||||
void ShaderResourceGroup::ResetViews()
|
||||
{
|
||||
m_data.ResetViews();
|
||||
}
|
||||
|
||||
const RHI::SamplerState& ShaderResourceGroup::GetSampler(RHI::ShaderInputNameIndex& inputIndex, uint32_t arrayIndex) const
|
||||
{
|
||||
inputIndex.ValidateOrFindSamplerIndex(GetLayout());
|
||||
|
||||
Reference in New Issue
Block a user