Skip to content

Commit 8db150e

Browse files
committed
- grim: optimize bind groups
1 parent 36aac6f commit 8db150e

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

shared/grim/GrimBaseRenderer.cpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -765,23 +765,27 @@ void GRIMBaseRenderer::FilterInstances_Compute(IntermediateState& intermediate)
765765
{
766766
IGPUComputePassRecorderPtr computeRecorder = intermediate.cmdRecorder->BeginComputePass("FilterInstances");
767767

768-
// filter instances by group mask
769-
computeRecorder->SetPipeline(m_filterInstancesPipeline);
770-
computeRecorder->SetBindGroup(0, g_renderAPI->CreateBindGroup(m_filterInstancesPipeline,
768+
IGPUBindGroupPtr srcInstancesBindGroup = g_renderAPI->CreateBindGroup(m_filterInstancesPipeline,
771769
Builder<BindGroupDesc>()
772770
.GroupIndex(0)
773771
.Buffer(StringIdConst24("archetypeIds"), m_instAllocator.GetInstanceArchetypesBuffer())
774772
.Buffer(StringIdConst24("groupMasks"), m_instAllocator.GetInstanceGroupMaskBuffer())
775773
.Buffer(StringIdConst24("drawParams"), rendState.filterParamsBuffer, 0, sizeof(params))
776774
.End()
777-
));
778-
computeRecorder->SetBindGroup(1, g_renderAPI->CreateBindGroup(m_filterInstancesPipeline,
775+
);
776+
777+
IGPUBindGroupPtr drawnInstancesBindGroup = g_renderAPI->CreateBindGroup(m_filterInstancesPipeline,
779778
Builder<BindGroupDesc>()
780779
.GroupIndex(1)
781780
.Buffer(StringIdConst24("instanceInfos"), filteredInstanceInfosBuffer)
782781
.Buffer(StringIdConst24("countBuffer"), filteredInstanceCountBuffer)
783782
.End()
784-
));
783+
);
784+
785+
// filter instances by group mask
786+
computeRecorder->SetPipeline(m_filterInstancesPipeline);
787+
computeRecorder->SetBindGroup(0, srcInstancesBindGroup);
788+
computeRecorder->SetBindGroup(1, drawnInstancesBindGroup);
785789

786790
const IVector2D workGroups = VisCalcWorkSize(params.maxInstanceIds);
787791
computeRecorder->DispatchWorkgroups(workGroups.x, workGroups.y);
@@ -856,22 +860,24 @@ void GRIMBaseRenderer::UpdateInstanceBounds_Compute(IntermediateState& intermedi
856860

857861
GRIMRenderState& rendState = intermediate.renderState;
858862

859-
IGPUComputePassRecorderPtr computeRecorder = intermediate.cmdRecorder->BeginComputePass("CalcInstanceBounds");
860-
computeRecorder->SetPipeline(m_instCalcBoundsPipeline);
861-
computeRecorder->SetBindGroup(0, g_renderAPI->CreateBindGroup(m_instCalcBoundsPipeline,
863+
IGPUBindGroupPtr instancesBindGroup = g_renderAPI->CreateBindGroup(m_instCalcBoundsPipeline,
862864
Builder<BindGroupDesc>()
863865
.GroupIndex(0)
864866
.Buffer(StringIdConst24("instanceInfos"), rendState.culledInstanceInfosBuffer)
865867
.Buffer(StringIdConst24("instanceSrcIds"), rendState.sortedInstanceIdsBuffer)
866-
.End())
867-
);
868-
computeRecorder->SetBindGroup(1, g_renderAPI->CreateBindGroup(m_instCalcBoundsPipeline,
868+
.End());
869+
870+
IGPUBindGroupPtr drawDataBindGroup = g_renderAPI->CreateBindGroup(m_instCalcBoundsPipeline,
869871
Builder<BindGroupDesc>()
870872
.GroupIndex(1)
871873
.Buffer(StringIdConst24("drawInstanceBounds"), rendState.drawInstanceBoundsBuffer)
872874
.Buffer(StringIdConst24("instanceIds"), rendState.instanceIdsBuffer)
873-
.End())
874-
);
875+
.End());
876+
877+
IGPUComputePassRecorderPtr computeRecorder = intermediate.cmdRecorder->BeginComputePass("CalcInstanceBounds");
878+
computeRecorder->SetPipeline(m_instCalcBoundsPipeline);
879+
computeRecorder->SetBindGroup(0, instancesBindGroup);
880+
computeRecorder->SetBindGroup(1, drawDataBindGroup);
875881

876882
// TODO: DispatchWorkgroupsIndirect (use as result from VisibilityCullInstances)
877883
IVector2D workGroups = VisCalcWorkSize(intermediate.maxNumberOfObjects);
@@ -885,21 +891,17 @@ void GRIMBaseRenderer::UpdateIndirectInstances_Compute(IntermediateState& interm
885891

886892
GRIMRenderState& rendState = intermediate.renderState;
887893

888-
IGPUComputePassRecorderPtr computeRecorder = intermediate.cmdRecorder->BeginComputePass("UpdateIndirectInstances");
889-
computeRecorder->SetPipeline(m_instPrepareDrawIndirectPipeline);
890-
computeRecorder->SetBindGroup(0, m_updateBindGroup0);
891-
computeRecorder->SetBindGroup(1, g_renderAPI->CreateBindGroup(m_instPrepareDrawIndirectPipeline,
894+
IGPUBindGroupPtr drawDataBindGroup = g_renderAPI->CreateBindGroup(m_instPrepareDrawIndirectPipeline,
892895
Builder<BindGroupDesc>()
893896
.GroupIndex(1)
894897
.Buffer(StringIdConst24("drawInstanceBounds"), rendState.drawInstanceBoundsBuffer)
895-
.End())
896-
);
897-
computeRecorder->SetBindGroup(2, g_renderAPI->CreateBindGroup(m_instPrepareDrawIndirectPipeline,
898-
Builder<BindGroupDesc>()
899-
.GroupIndex(2)
900898
.Buffer(StringIdConst24("indirectDraws"), rendState.drawInvocationsBuffer)
901-
.End())
902-
);
899+
.End());
900+
901+
IGPUComputePassRecorderPtr computeRecorder = intermediate.cmdRecorder->BeginComputePass("UpdateIndirectInstances");
902+
computeRecorder->SetPipeline(m_instPrepareDrawIndirectPipeline);
903+
computeRecorder->SetBindGroup(0, m_updateBindGroup0);
904+
computeRecorder->SetBindGroup(1, drawDataBindGroup);
903905

904906
constexpr int GROUP_SIZE = 32;
905907
const int numBounds = m_drawLodsList.NumSlots() * GRIM_MAX_INSTANCE_LODS;

shared/grim/GrimBaseRenderer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ struct GRIMBaseRenderer::GPULodList
216216
int firstLodInfo = -1; // item index in buffer pointing to GPULodInfo
217217
};
218218

219-
// this is only here for software reference impl
220219
struct GRIMBaseRenderer::GPUInstanceBound
221220
{
222221
int first{ 0 };

0 commit comments

Comments
 (0)