Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #12485: O3DE: p_PopcornFXMaxSlices (enable slicing) has no effect #54

Merged
merged 2 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Assets/shaders/Billboard/Default/Billboard.azsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct VertexOutput
VertexOutput BillboardVS(VertexInput input)
{
VertexOutput output;
uint particleIdx = RendererSrg::m_indices[input.m_instanceID];
uint particleIdx = RendererSrg::m_indices[GetParticleId_Sliced(input.m_instanceID)];

// Billboarding outputs:
float3 vtxWorldPos;
Expand Down
2 changes: 1 addition & 1 deletion Assets/shaders/Billboard/Default/BillboardDistortion.azsl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct VertexOutput
VertexOutput BillboardVS(VertexInput input)
{
VertexOutput output;
uint particleIdx = RendererSrg::m_indices[input.m_instanceID];
uint particleIdx = RendererSrg::m_indices[GetParticleId_Sliced(input.m_instanceID)];

// Billboarding outputs:
float3 vtxWorldPos;
Expand Down
2 changes: 1 addition & 1 deletion Assets/shaders/Billboard/Legacy/BillboardLit_Legacy.azsl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct VSOutput
VSOutput BillboardVS(VertexInput input)
{
VSOutput output;
uint particleIdx = RendererSrg::m_indices[input.m_instanceID];
uint particleIdx = RendererSrg::m_indices[GetParticleId_Sliced(input.m_instanceID)];

// Billboarding outputs:
float3 vtxWorldPos;
Expand Down
2 changes: 1 addition & 1 deletion Assets/shaders/Billboard/Legacy/Billboard_Legacy.azsl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct VertexOutput
VertexOutput BillboardVS(VertexInput input)
{
VertexOutput output;
uint particleIdx = RendererSrg::m_indices[input.m_instanceID];
uint particleIdx = RendererSrg::m_indices[GetParticleId_Sliced(input.m_instanceID)];

// Billboarding outputs:
float3 vtxWorldPos;
Expand Down
8 changes: 8 additions & 0 deletions Assets/shaders/Common/BillboardSrg.azsli
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ ShaderResourceGroup RendererSrg : SRG_PerDraw
StructuredBuffer<SBillboardDrawRequest> m_drawRequests;
}

// Slice instance offset
rootconstant uint m_instanceOffset;

#include "RendererSrg.azsli"

// Billboarder Types:
Expand Down Expand Up @@ -88,4 +91,9 @@ float3 GetParticleAxis1(uint particleIdx)
RendererSrg::m_axis1[particleIdx * 3 + 2]);
}

uint GetParticleId_Sliced(uint particleIdx)
{
return particleIdx + m_instanceOffset;
}

#include "RendererSrg.azsli"
3 changes: 1 addition & 2 deletions Code/Source/Integration/Managers/RenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,9 @@ void CRenderManager::StopUpdate(CParticleMediumCollection *mediumCollection)

m_FrameCollector.SetDrawCallsSortMethod(slicesMaxCount == 1 ? Sort_None : Sort_Slices);


PopcornFX::TStaticArray<SSceneView, 1> viewsArray;
viewsArray[0].m_InvViewMatrix = m_SceneViews->m_Views[0].m_InvViewMatrix;
viewsArray[0].m_MaxSliceCount = 1;
viewsArray[0].m_MaxSliceCount = slicesMaxCount;
viewsArray[0].m_NeedsSortedIndices = true;
m_RenderContext.m_Views = viewsArray;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct SAtomRenderContext : public SRenderContext
ERendererClass m_RendererType = Renderer_Invalid;
bool m_CastShadows = false;
s32 m_GlobalSortOverride = 0;
u32 m_InstanceOffset = 0; // Slices

CAABB m_BoundingBox;
AZ::RHI::DrawIndexed m_DrawIndexed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,12 @@ void CAtomPipelineCache::ConfigureDrawCall(SAtomRenderContext::SDrawCall &drawCa
drawCall.m_TransparentDepthMinDrawList = m_TransparentDepthMinDrawList;
drawCall.m_TransparentDepthMaxPipelineState = m_TransparentDepthMaxPipelineState;
drawCall.m_TransparentDepthMaxDrawList = m_TransparentDepthMaxDrawList;
}

//----------------------------------------------------------------------------

void CAtomPipelineCache::Clear()
{
// Reset vertex and index buffers:
m_VertexInputs.Clear();
m_IndexBuffer = AZ::RHI::IndexBufferView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class CAtomPipelineCache
~CAtomPipelineCache();

bool InitFromRendererCacheIFN(const CAtomRendererCache *rendererCache);
void Clear();

void SetBillboardingSrgBuffer(BillboardSrg::EBuffersSemantic semantic, const AZ::RHI::Ptr<AZ::RHI::BufferView> bufferView);
template<typename T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ bool CBillboardBatchDrawer::AllocBuffers(SRenderContext &ctx, const SRendererBat
return false;

for (auto &pipelineCache : m_PipelineCaches)
{
pipelineCache.Clear();
pipelineCache.InitFromRendererCacheIFN(rendererCache);
}
if (rendererCache->m_CachesModified)
_UnflagModifiedCaches(drawPass.m_RendererCaches);

Expand Down Expand Up @@ -331,6 +334,9 @@ bool CBillboardBatchDrawer::EmitDrawCall(SRenderContext &ctx, const SRendererBat
if (!PK_VERIFY(m_PipelineCaches.Count() == 1 && m_PipelineCaches[0].IsInitialized()))
return false;

// Configure pipeline cache only for the first slice. Following slices will configure the draw call with the same pipeline cache.
if (toEmit.m_IndexOffset == 0)
{
// ----------------------------------------------------------------
// The pipeline cache handles the buffer bindings for the draw call:
// Add draw instance vertex and index buffers:
Expand Down Expand Up @@ -425,6 +431,7 @@ bool CBillboardBatchDrawer::EmitDrawCall(SRenderContext &ctx, const SRendererBat
AZ::RHI::Ptr<AZ::RHI::BufferView> buff = viewIndependent.m_DrawRequests->GetBufferView(AZ::RHI::BufferViewDescriptor::CreateStructured(0, drawRequestsCount, sizeof(Drawers::SBillboardDrawRequest)));
m_PipelineCaches[0].SetBillboardingSrgBuffer(BillboardSrg::DrawRequest_ShaderRead, buff);
}
}

// Fill the draw call:
m_PipelineCaches[0].ConfigureDrawCall(dc);
Expand All @@ -436,10 +443,13 @@ bool CBillboardBatchDrawer::EmitDrawCall(SRenderContext &ctx, const SRendererBat
// Draw call description:
dc.m_DrawIndexed.m_indexCount = m_DrawInstanceIdxCount;
dc.m_DrawIndexed.m_indexOffset = 0;
dc.m_DrawIndexed.m_instanceCount = particleCount;
dc.m_DrawIndexed.m_instanceCount = toEmit.m_TotalParticleCount; // Sliced draw calls can draw < drawPass.m_TotalParticleCount
dc.m_DrawIndexed.m_instanceOffset = 0;
dc.m_DrawIndexed.m_vertexOffset = 0;

// See CPopcornFXFeatureProcessor::BuildDrawPacket()
dc.m_InstanceOffset = toEmit.m_IndexOffset; // Sliced draw calls can have a non-zero offset

// Draw instance indices and tex-coords:
return PK_VERIFY(m_RenderContext->m_DrawCalls.PushBack(dc).Valid());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ bool CMeshBatchDrawer::AllocBuffers(SRenderContext &ctx, const SRendererBatchDra
m_PipelineCaches.Resize(m_GeometryCache->m_PerGeometryViews.Count());

for (auto &pipelineCache : m_PipelineCaches)
{
pipelineCache.Clear();
pipelineCache.InitFromRendererCacheIFN(rendererCache);
}
if (rendererCache->m_CachesModified)
_UnflagModifiedCaches(drawPass.m_RendererCaches);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ const AZ::RHI::DrawPacket *CPopcornFXFeatureProcessor::BuildDrawPacket( const SA
dpBuilder.AddShaderResourceGroup(objectSrg->GetRHIShaderResourceGroup());
}

if (pkfxDrawCall.m_RendererType == Renderer_Billboard)
{
// See BillboardSrg.azsli, "m_instanceOffset"
dpBuilder.SetRootConstants(AZStd::span<const uint8_t>(reinterpret_cast<const uint8_t*>(&pkfxDrawCall.m_InstanceOffset), sizeof(u32)));
}

return dpBuilder.End();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ bool CRibbonBatchDrawer::AllocBuffers(SRenderContext &ctx, const SRendererBatchD
return false;

for (auto &pipelineCache : m_PipelineCaches)
{
pipelineCache.Clear();
pipelineCache.InitFromRendererCacheIFN(rendererCache);
}
if (rendererCache->m_CachesModified)
_UnflagModifiedCaches(drawPass.m_RendererCaches);

Expand Down Expand Up @@ -281,6 +284,9 @@ bool CRibbonBatchDrawer::EmitDrawCall(SRenderContext &ctx, const SRendererBatchD
if (!PK_VERIFY(m_PipelineCaches.Count() == 1 && m_PipelineCaches[0].IsInitialized()))
return false;

// Configure pipeline cache only for the first slice. Following slices will configure the draw call with the same pipeline cache.
if (toEmit.m_IndexOffset == 0)
{
// Position:
if (viewIndependent.m_GenBuffers[CParticleBuffers::GenBuffer_Position] != null)
m_PipelineCaches[0].SetVertexInputBuffer(Position_Vertex, AZ::RHI::StreamBufferView(*viewIndependent.m_GenBuffers[CParticleBuffers::GenBuffer_Position], 0, vertexCount * sizeof(CFloat4), sizeof(CFloat4)));
Expand Down Expand Up @@ -355,6 +361,7 @@ bool CRibbonBatchDrawer::EmitDrawCall(SRenderContext &ctx, const SRendererBatchD
AZ::RHI::Ptr<AZ::RHI::BufferView> buff = alphaRemapCursor->GetBufferView(AZ::RHI::BufferViewDescriptor::CreateStructured(0, particleCount, sizeof(float)));
m_PipelineCaches[0].SetRibbonSrgBuffer(RibbonSrg::ParticleAlphaCursor_ShaderRead, buff);
}
}

// Fill the draw call:
m_PipelineCaches[0].ConfigureDrawCall(dc);
Expand All @@ -364,8 +371,8 @@ bool CRibbonBatchDrawer::EmitDrawCall(SRenderContext &ctx, const SRendererBatchD
dc.m_BoundingBox = toEmit.m_BBox;

// Draw call description:
dc.m_DrawIndexed.m_indexCount = indexCount;
dc.m_DrawIndexed.m_indexOffset = 0;
dc.m_DrawIndexed.m_indexCount = toEmit.m_TotalIndexCount; // Sliced draw calls can draw < drawPass.m_TotalIndexCount
dc.m_DrawIndexed.m_indexOffset = toEmit.m_IndexOffset; // Sliced draw calls can have a non-zero offset
dc.m_DrawIndexed.m_instanceCount = 1;
dc.m_DrawIndexed.m_instanceOffset = 0;
dc.m_DrawIndexed.m_vertexOffset = 0;
Expand Down