Merge branch 'main' into Atom/antonmic/PassChanges

This commit is contained in:
antonmic
2021-06-07 08:41:31 -07:00
171 changed files with 8369 additions and 4764 deletions
@@ -902,23 +902,40 @@ namespace AZ
{
// make sure to only import the resource one time
RHI::AttachmentId attachmentId = attachment->GetAttachmentId();
if (!attachmentDatabase.IsAttachmentValid(attachmentId))
const RHI::FrameAttachment* currentAttachment = attachmentDatabase.FindAttachment(attachmentId);
if (azrtti_istypeof<Image>(attachment->m_importedResource.get()))
{
if (azrtti_istypeof<Image>(attachment->m_importedResource.get()))
Image* image = static_cast<Image*>(attachment->m_importedResource.get());
if (currentAttachment == nullptr)
{
Image* image = static_cast<Image*>(attachment->m_importedResource.get());
attachmentDatabase.ImportImage(attachmentId, image->GetRHIImage());
}
else if (azrtti_istypeof<Buffer>(attachment->m_importedResource.get()))
else
{
AZ_Assert(currentAttachment->GetResource() == image->GetRHIImage(),
"Importing image attachment named \"%s\" but a different attachment with the "
"same name already exists in the database.\n", attachmentId.GetCStr());
}
}
else if (azrtti_istypeof<Buffer>(attachment->m_importedResource.get()))
{
Buffer* buffer = static_cast<Buffer*>(attachment->m_importedResource.get());
if (currentAttachment == nullptr)
{
Buffer* buffer = static_cast<Buffer*>(attachment->m_importedResource.get());
attachmentDatabase.ImportBuffer(attachmentId, buffer->GetRHIBuffer());
}
else
{
AZ_RPI_PASS_ERROR(false, "Can't import unknown resource type");
AZ_Assert(currentAttachment->GetResource() == buffer->GetRHIBuffer(),
"Importing buffer attachment named \"%s\" but a different attachment with the "
"same name already exists in the database.\n", attachmentId.GetCStr());
}
}
else
{
AZ_RPI_PASS_ERROR(false, "Can't import unknown resource type");
}
}
}
}
@@ -114,9 +114,9 @@ namespace AZ
return RHI::TransientBufferDescriptor(GetAttachmentId(), m_descriptor.m_buffer);
}
void PassAttachment::Update()
void PassAttachment::Update(bool updateImportedAttachments)
{
if (m_descriptor.m_type == RHI::AttachmentType::Image && m_lifetime == RHI::AttachmentLifetimeType::Transient)
if (m_descriptor.m_type == RHI::AttachmentType::Image && (m_lifetime == RHI::AttachmentLifetimeType::Transient || updateImportedAttachments == true))
{
if (m_settingFlags.m_getFormatFromPipeline && m_renderPipelineSource)
{
+52 -33
View File
@@ -127,7 +127,6 @@ namespace AZ
m_worldToViewMatrix = worldToView;
m_worldToClipMatrix = m_viewToClipMatrix * m_worldToViewMatrix;
m_worldToClipMatrixChanged = true;
m_onWorldToViewMatrixChange.Signal(m_worldToViewMatrix);
m_onWorldToClipMatrixChange.Signal(m_worldToClipMatrix);
@@ -166,8 +165,6 @@ namespace AZ
m_worldToViewMatrix = m_viewToWorldMatrix.GetInverseFast();
m_worldToClipMatrix = m_viewToClipMatrix * m_worldToViewMatrix;
m_clipToWorldMatrix = m_viewToWorldMatrix * m_clipToViewMatrix;
m_worldToClipMatrixChanged = true;
m_onWorldToViewMatrixChange.Signal(m_worldToViewMatrix);
m_onWorldToClipMatrixChange.Signal(m_worldToClipMatrix);
@@ -178,12 +175,8 @@ namespace AZ
void View::SetViewToClipMatrix(const AZ::Matrix4x4& viewToClip)
{
m_viewToClipMatrix = viewToClip;
m_clipToViewMatrix = viewToClip.GetInverseFull();
m_worldToClipMatrix = m_viewToClipMatrix * m_worldToViewMatrix;
m_worldToClipMatrixChanged = true;
m_clipToWorldMatrix = m_viewToWorldMatrix * m_clipToViewMatrix;
// Update z depth constant simultaneously
// zNear -> n, zFar -> f
@@ -210,6 +203,12 @@ namespace AZ
InvalidateSrg();
}
void View::SetClipSpaceOffset(float xOffset, float yOffset)
{
m_clipSpaceOffset.Set(xOffset, yOffset);
InvalidateSrg();
}
const AZ::Matrix4x4& View::GetWorldToViewMatrix() const
{
@@ -368,36 +367,56 @@ namespace AZ
void View::UpdateSrg()
{
if (m_worldToClipPrevMatrixNeedsUpdate)
if (m_needBuildSrg)
{
m_shaderResourceGroup->SetConstant(m_worldToClipPrevMatrixConstantIndex, m_worldToClipPrevMatrix);
m_worldToClipPrevMatrixNeedsUpdate = false;
if (m_clipSpaceOffset.IsZero())
{
Matrix4x4 worldToClipPrevMatrix = m_viewToClipPrevMatrix * m_worldToViewPrevMatrix;
m_shaderResourceGroup->SetConstant(m_worldToClipPrevMatrixConstantIndex, worldToClipPrevMatrix);
m_shaderResourceGroup->SetConstant(m_viewProjectionMatrixConstantIndex, m_worldToClipMatrix);
m_shaderResourceGroup->SetConstant(m_projectionMatrixConstantIndex, m_viewToClipMatrix);
m_shaderResourceGroup->SetConstant(m_clipToWorldMatrixConstantIndex, m_clipToWorldMatrix);
m_shaderResourceGroup->SetConstant(m_projectionMatrixInverseConstantIndex, m_viewToClipMatrix.GetInverseFull());
}
else
{
// Offset the current and previous frame clip matricies
Matrix4x4 offsetViewToClipMatrix = m_viewToClipMatrix;
offsetViewToClipMatrix.SetElement(0, 2, m_clipSpaceOffset.GetX());
offsetViewToClipMatrix.SetElement(1, 2, m_clipSpaceOffset.GetY());
Matrix4x4 offsetViewToClipPrevMatrix = m_viewToClipPrevMatrix;
offsetViewToClipPrevMatrix.SetElement(0, 2, m_clipSpaceOffset.GetX());
offsetViewToClipPrevMatrix.SetElement(1, 2, m_clipSpaceOffset.GetY());
// Build other matricies dependent on the view to clip matricies
Matrix4x4 offsetWorldToClipMatrix = offsetViewToClipMatrix * m_worldToViewMatrix;
Matrix4x4 offsetWorldToClipPrevMatrix = offsetViewToClipPrevMatrix * m_worldToViewPrevMatrix;
Matrix4x4 offsetClipToViewMatrix = offsetViewToClipMatrix.GetInverseFull();
Matrix4x4 offsetClipToWorldMatrix = m_viewToWorldMatrix * offsetClipToViewMatrix;
m_shaderResourceGroup->SetConstant(m_worldToClipPrevMatrixConstantIndex, offsetWorldToClipPrevMatrix);
m_shaderResourceGroup->SetConstant(m_viewProjectionMatrixConstantIndex, offsetWorldToClipMatrix);
m_shaderResourceGroup->SetConstant(m_projectionMatrixConstantIndex, offsetViewToClipMatrix);
m_shaderResourceGroup->SetConstant(m_clipToWorldMatrixConstantIndex, offsetClipToWorldMatrix);
m_shaderResourceGroup->SetConstant(m_projectionMatrixInverseConstantIndex, offsetViewToClipMatrix.GetInverseFull());
}
m_shaderResourceGroup->SetConstant(m_worldPositionConstantIndex, m_position);
m_shaderResourceGroup->SetConstant(m_viewMatrixConstantIndex, m_worldToViewMatrix);
m_shaderResourceGroup->SetConstant(m_viewMatrixInverseConstantIndex, m_worldToViewMatrix.GetInverseFull());
m_shaderResourceGroup->SetConstant(m_zConstantsConstantIndex, m_nearZ_farZ_farZTimesNearZ_farZMinusNearZ);
m_shaderResourceGroup->SetConstant(m_unprojectionConstantsIndex, m_unprojectionConstants);
m_shaderResourceGroup->Compile();
m_needBuildSrg = false;
}
if (m_worldToClipMatrixChanged)
{
m_worldToClipPrevMatrix = m_worldToClipMatrix;
m_worldToClipPrevMatrixNeedsUpdate = true;
m_worldToClipMatrixChanged = false;
}
m_viewToClipPrevMatrix = m_viewToClipMatrix;
m_worldToViewPrevMatrix = m_worldToViewMatrix;
if (!m_needBuildSrg)
{
return;
}
m_shaderResourceGroup->SetConstant(m_worldPositionConstantIndex, m_position);
m_shaderResourceGroup->SetConstant(m_viewProjectionMatrixConstantIndex, m_worldToClipMatrix);
m_shaderResourceGroup->SetConstant(m_viewMatrixConstantIndex, m_worldToViewMatrix);
m_shaderResourceGroup->SetConstant(m_viewMatrixInverseConstantIndex, m_worldToViewMatrix.GetInverseFull());
m_shaderResourceGroup->SetConstant(m_projectionMatrixConstantIndex, m_viewToClipMatrix);
m_shaderResourceGroup->SetConstant(m_projectionMatrixInverseConstantIndex, m_viewToClipMatrix.GetInverseFull());
m_shaderResourceGroup->SetConstant(m_zConstantsConstantIndex, m_nearZ_farZ_farZTimesNearZ_farZMinusNearZ);
m_shaderResourceGroup->SetConstant(m_clipToWorldMatrixConstantIndex, m_clipToWorldMatrix);
m_shaderResourceGroup->SetConstant(m_unprojectionConstantsIndex, m_unprojectionConstants);
m_shaderResourceGroup->Compile();
m_needBuildSrg = false;
m_clipSpaceOffset.Set(0);
}
void View::BeginCulling()