Skip to content

Commit d6d5b75

Browse files
committed
Editing: Select All and Invert Selection now skip over cut splats
1 parent 30cc3e5 commit d6d5b75

File tree

3 files changed

+164
-93
lines changed

3 files changed

+164
-93
lines changed

Assets/GaussianSplatting/Scripts/Editor/GaussianSplatRendererEditor.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,15 @@ public class GaussianSplatRendererEditor : Editor
3131
bool m_ResourcesExpanded = false;
3232
int m_CameraIndex = 0;
3333

34+
static int s_EditStatsUpdateCounter = 0;
35+
3436
static HashSet<GaussianSplatRendererEditor> s_AllEditors = new();
3537

38+
public static void BumpGUICounter()
39+
{
40+
++s_EditStatsUpdateCounter;
41+
}
42+
3643
public static void RepaintAll()
3744
{
3845
foreach (var e in s_AllEditors)
@@ -140,6 +147,8 @@ void EditCameras(GaussianSplatRenderer gs)
140147

141148
void EditGUI(GaussianSplatRenderer gs)
142149
{
150+
++s_EditStatsUpdateCounter;
151+
143152
EditorGUILayout.Space(12f, true);
144153
GUILayout.Box(GUIContent.none, "sv_iconselector_sep", GUILayout.Height(2), GUILayout.ExpandWidth(true));
145154
EditorGUILayout.Space();
@@ -160,18 +169,21 @@ void EditGUI(GaussianSplatRenderer gs)
160169
cutoutTr.localScale = (gs.asset.m_BoundsMax - gs.asset.m_BoundsMin) * 0.25f;
161170
gs.m_Cutouts ??= Array.Empty<GaussianCutout>();
162171
ArrayUtility.Add(ref gs.m_Cutouts, cutout);
172+
gs.UpdateEditCountsAndBounds();
163173
EditorUtility.SetDirty(gs);
164174
Selection.activeGameObject = cutout.gameObject;
165175
}
166176
if (GUILayout.Button("Use All Cutouts"))
167177
{
168178
gs.m_Cutouts = FindObjectsByType<GaussianCutout>(FindObjectsSortMode.InstanceID);
179+
gs.UpdateEditCountsAndBounds();
169180
EditorUtility.SetDirty(gs);
170181
}
171182

172183
if (GUILayout.Button("No Cutouts"))
173184
{
174185
gs.m_Cutouts = Array.Empty<GaussianCutout>();
186+
gs.UpdateEditCountsAndBounds();
175187
EditorUtility.SetDirty(gs);
176188
}
177189
GUILayout.EndHorizontal();
@@ -186,6 +198,7 @@ void EditGUI(GaussianSplatRenderer gs)
186198
{
187199
var asset = gs.asset;
188200
EditorGUILayout.LabelField("Splats", $"{asset.m_SplatCount:N0}");
201+
EditorGUILayout.LabelField("Cut", $"{gs.editCutSplats:N0}");
189202
EditorGUILayout.LabelField("Deleted", $"{gs.editDeletedSplats:N0}");
190203
EditorGUILayout.LabelField("Selected", $"{gs.editSelectedSplats:N0}");
191204
if (modifiedOrHasCutouts)
@@ -202,6 +215,15 @@ void EditGUI(GaussianSplatRenderer gs)
202215
MessageType.Warning);
203216
}
204217
}
218+
219+
if (hasCutouts)
220+
{
221+
if (s_EditStatsUpdateCounter > 10)
222+
{
223+
gs.UpdateEditCountsAndBounds();
224+
s_EditStatsUpdateCounter = 0;
225+
}
226+
}
205227
}
206228
}
207229

@@ -358,6 +380,8 @@ public override void OnToolGUI(EditorWindow window)
358380
var gs = target as GaussianSplatRenderer;
359381
if (!gs)
360382
return;
383+
384+
GaussianSplatRendererEditor.BumpGUICounter();
361385

362386
int id = GUIUtility.GetControlID(FocusType.Passive);
363387
Event evt = Event.current;

Assets/GaussianSplatting/Scripts/GaussianSplatRenderer.cs

Lines changed: 60 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void UnregisterSplat(GaussianSplatRenderer r)
6565
}
6666
}
6767

68+
// ReSharper disable once MemberCanBePrivate.Global - used by HDRP/URP features that are not always compiled
6869
public bool GatherSplatsForCamera(Camera cam)
6970
{
7071
if (cam.cameraType == CameraType.Preview)
@@ -95,6 +96,7 @@ public bool GatherSplatsForCamera(Camera cam)
9596
return true;
9697
}
9798

99+
// ReSharper disable once MemberCanBePrivate.Global - used by HDRP/URP features that are not always compiled
98100
public Material SortAndRenderSplats(Camera cam, CommandBuffer cmb)
99101
{
100102
Material matComposite = null;
@@ -158,6 +160,8 @@ public Material SortAndRenderSplats(Camera cam, CommandBuffer cmb)
158160
return matComposite;
159161
}
160162

163+
// ReSharper disable once MemberCanBePrivate.Global - used by HDRP/URP features that are not always compiled
164+
// ReSharper disable once UnusedMethodReturnValue.Global - used by HDRP/URP features that are not always compiled
161165
public CommandBuffer InitialClearCmdBuffer(Camera cam)
162166
{
163167
m_CommandBuffer ??= new CommandBuffer {name = "RenderGaussianSplats"};
@@ -288,7 +292,6 @@ internal static class Props
288292
public static readonly int SrcBuffer = Shader.PropertyToID("_SrcBuffer");
289293
public static readonly int DstBuffer = Shader.PropertyToID("_DstBuffer");
290294
public static readonly int BufferSize = Shader.PropertyToID("_BufferSize");
291-
public static readonly int DstBufferValue = Shader.PropertyToID("_DstBufferValue");
292295
public static readonly int MatrixVP = Shader.PropertyToID("_MatrixVP");
293296
public static readonly int MatrixMV = Shader.PropertyToID("_MatrixMV");
294297
public static readonly int MatrixP = Shader.PropertyToID("_MatrixP");
@@ -303,6 +306,7 @@ internal static class Props
303306
[field: NonSerialized] public bool editModified { get; private set; }
304307
[field: NonSerialized] public uint editSelectedSplats { get; private set; }
305308
[field: NonSerialized] public uint editDeletedSplats { get; private set; }
309+
[field: NonSerialized] public uint editCutSplats { get; private set; }
306310
[field: NonSerialized] public Bounds editSelectedBounds { get; private set; }
307311

308312
public GaussianSplatAsset asset => m_Asset;
@@ -315,7 +319,8 @@ enum KernelIndices
315319
UpdateEditData,
316320
InitEditData,
317321
ClearBuffer,
318-
InvertBuffer,
322+
InvertSelection,
323+
SelectAll,
319324
OrBuffers,
320325
SelectionUpdate,
321326
ExportData,
@@ -397,17 +402,28 @@ public void OnEnable()
397402
CreateResourcesForAsset();
398403
}
399404

400-
void SetAssetDataOnCS(CommandBuffer cmb, ComputeShader cs, int kernelIndex)
405+
void SetAssetDataOnCS(CommandBuffer cmb, KernelIndices kernel)
401406
{
402-
cmb.SetComputeBufferParam(cs, kernelIndex, "_SplatPos", m_GpuPosData);
403-
cmb.SetComputeBufferParam(cs, kernelIndex, "_SplatOther", m_GpuOtherData);
404-
cmb.SetComputeBufferParam(cs, kernelIndex, "_SplatSH", m_GpuSHData);
405-
cmb.SetComputeTextureParam(cs, kernelIndex, "_SplatColor", m_GpuColorData);
407+
ComputeShader cs = m_CSSplatUtilities;
408+
int kernelIndex = (int) kernel;
409+
cmb.SetComputeBufferParam(cs, kernelIndex, Props.SplatPos, m_GpuPosData);
410+
cmb.SetComputeBufferParam(cs, kernelIndex, Props.SplatChunks, m_GpuChunks);
411+
cmb.SetComputeBufferParam(cs, kernelIndex, Props.SplatOther, m_GpuOtherData);
412+
cmb.SetComputeBufferParam(cs, kernelIndex, Props.SplatSH, m_GpuSHData);
413+
cmb.SetComputeTextureParam(cs, kernelIndex, Props.SplatColor, m_GpuColorData);
406414
cmb.SetComputeBufferParam(cs, kernelIndex, Props.SplatSelectedBits, m_GpuSplatSelectedBuffer ?? m_GpuPosData);
407415
cmb.SetComputeBufferParam(cs, kernelIndex, Props.SplatDeletedBits, m_GpuSplatDeletedBuffer ?? m_GpuPosData);
408-
cmb.SetComputeIntParam(cs, "_SplatBitsValid", m_GpuSplatSelectedBuffer != null && m_GpuSplatDeletedBuffer != null ? 1 : 0);
416+
cmb.SetComputeBufferParam(cs, kernelIndex, Props.SplatViewData, m_GpuView);
417+
cmb.SetComputeBufferParam(cs, kernelIndex, Props.OrderBuffer, m_GpuSortKeys);
418+
419+
cmb.SetComputeIntParam(cs, Props.SplatBitsValid, m_GpuSplatSelectedBuffer != null && m_GpuSplatDeletedBuffer != null ? 1 : 0);
409420
uint format = (uint)m_Asset.m_PosFormat | ((uint)m_Asset.m_ScaleFormat << 8) | ((uint)m_Asset.m_SHFormat << 16);
410-
cmb.SetComputeIntParam(cs, "_SplatFormat", (int)format);
421+
cmb.SetComputeIntParam(cs, Props.SplatFormat, (int)format);
422+
cmb.SetComputeIntParam(cs, Props.SplatCount, m_Asset.m_SplatCount);
423+
424+
UpdateCutoutsBuffer();
425+
cmb.SetComputeIntParam(cs, Props.SplatCutoutsCount, m_Cutouts?.Length ?? 0);
426+
cmb.SetComputeBufferParam(cs, kernelIndex, Props.SplatCutouts, m_GpuSplatCutoutsBuffer);
411427
}
412428

413429
internal void SetAssetDataOnMaterial(MaterialPropertyBlock mat)
@@ -458,6 +474,7 @@ void DisposeResourcesForAsset()
458474

459475
editSelectedSplats = 0;
460476
editDeletedSplats = 0;
477+
editCutSplats = 0;
461478
editModified = false;
462479
editSelectedBounds = default;
463480
}
@@ -489,12 +506,7 @@ internal void CalcViewData(CommandBuffer cmb, Camera cam, Matrix4x4 matrix)
489506
Vector4 camPos = cam.transform.position;
490507

491508
// calculate view dependent data for each splat
492-
SetAssetDataOnCS(cmb, m_CSSplatUtilities, (int)KernelIndices.CalcViewData);
493-
494-
cmb.SetComputeIntParam(m_CSSplatUtilities, Props.SplatCount, m_GpuView.count);
495-
cmb.SetComputeBufferParam(m_CSSplatUtilities, (int)KernelIndices.CalcViewData, Props.SplatViewData, m_GpuView);
496-
cmb.SetComputeBufferParam(m_CSSplatUtilities, (int)KernelIndices.CalcViewData, Props.OrderBuffer, m_GpuSortKeys);
497-
cmb.SetComputeBufferParam(m_CSSplatUtilities, (int)KernelIndices.CalcViewData, Props.SplatChunks, m_GpuChunks);
509+
SetAssetDataOnCS(cmb, KernelIndices.CalcViewData);
498510

499511
cmb.SetComputeMatrixParam(m_CSSplatUtilities, Props.MatrixVP, matProj * matView);
500512
cmb.SetComputeMatrixParam(m_CSSplatUtilities, Props.MatrixMV, matView * matO2W);
@@ -508,10 +520,6 @@ internal void CalcViewData(CommandBuffer cmb, Camera cam, Matrix4x4 matrix)
508520
cmb.SetComputeFloatParam(m_CSSplatUtilities, Props.SplatOpacityScale, m_OpacityScale);
509521
cmb.SetComputeIntParam(m_CSSplatUtilities, Props.SHOrder, m_SHOrder);
510522

511-
UpdateCutoutsBuffer();
512-
cmb.SetComputeIntParam(m_CSSplatUtilities, Props.SplatCutoutsCount, m_Cutouts?.Length ?? 0);
513-
cmb.SetComputeBufferParam(m_CSSplatUtilities, (int)KernelIndices.CalcViewData, Props.SplatCutouts, m_GpuSplatCutoutsBuffer);
514-
515523
m_CSSplatUtilities.GetKernelThreadGroupSizes((int)KernelIndices.CalcViewData, out uint gsX, out _, out _);
516524
cmb.DispatchCompute(m_CSSplatUtilities, (int)KernelIndices.CalcViewData, (m_GpuView.count + (int)gsX - 1)/(int)gsX, 1, 1);
517525
}
@@ -577,23 +585,14 @@ public void ActivateCamera(int index)
577585
#endif
578586
}
579587

580-
void ClearGraphicsBuffer(GraphicsBuffer buf, uint value = 0)
588+
void ClearGraphicsBuffer(GraphicsBuffer buf)
581589
{
582590
m_CSSplatUtilities.SetBuffer((int)KernelIndices.ClearBuffer, Props.DstBuffer, buf);
583591
m_CSSplatUtilities.SetInt(Props.BufferSize, buf.count);
584-
m_CSSplatUtilities.SetInt(Props.DstBufferValue, (int)value);
585592
m_CSSplatUtilities.GetKernelThreadGroupSizes((int)KernelIndices.ClearBuffer, out uint gsX, out _, out _);
586593
m_CSSplatUtilities.Dispatch((int)KernelIndices.ClearBuffer, (int)((buf.count+gsX-1)/gsX), 1, 1);
587594
}
588-
589-
void InvertGraphicsBuffer(GraphicsBuffer buf)
590-
{
591-
m_CSSplatUtilities.SetBuffer((int)KernelIndices.InvertBuffer, Props.DstBuffer, buf);
592-
m_CSSplatUtilities.SetInt(Props.BufferSize, buf.count);
593-
m_CSSplatUtilities.GetKernelThreadGroupSizes((int)KernelIndices.InvertBuffer, out uint gsX, out _, out _);
594-
m_CSSplatUtilities.Dispatch((int)KernelIndices.InvertBuffer, (int)((buf.count+gsX-1)/gsX), 1, 1);
595-
}
596-
595+
597596
void UnionGraphicsBuffers(GraphicsBuffer dst, GraphicsBuffer src)
598597
{
599598
m_CSSplatUtilities.SetBuffer((int)KernelIndices.OrBuffers, Props.SrcBuffer, src);
@@ -609,12 +608,13 @@ static float SortableUintToFloat(uint v)
609608
return math.asfloat(v ^ mask);
610609
}
611610

612-
void UpdateEditCountsAndBounds()
611+
public void UpdateEditCountsAndBounds()
613612
{
614613
if (m_GpuSplatSelectedBuffer == null)
615614
{
616615
editSelectedSplats = 0;
617616
editDeletedSplats = 0;
617+
editCutSplats = 0;
618618
editModified = false;
619619
editSelectedBounds = default;
620620
return;
@@ -624,13 +624,9 @@ void UpdateEditCountsAndBounds()
624624
m_CSSplatUtilities.Dispatch((int)KernelIndices.InitEditData, 1, 1, 1);
625625

626626
using CommandBuffer cmb = new CommandBuffer();
627-
SetAssetDataOnCS(cmb, m_CSSplatUtilities, (int)KernelIndices.UpdateEditData);
628-
cmb.SetComputeBufferParam(m_CSSplatUtilities, (int)KernelIndices.UpdateEditData, Props.SplatChunks, m_GpuChunks);
629-
cmb.SetComputeBufferParam(m_CSSplatUtilities, (int)KernelIndices.UpdateEditData, Props.SplatSelectedBits, m_GpuSplatSelectedBuffer);
630-
cmb.SetComputeBufferParam(m_CSSplatUtilities, (int)KernelIndices.UpdateEditData, Props.SplatDeletedBits, m_GpuSplatDeletedBuffer);
627+
SetAssetDataOnCS(cmb, KernelIndices.UpdateEditData);
631628
cmb.SetComputeBufferParam(m_CSSplatUtilities, (int)KernelIndices.UpdateEditData, Props.DstBuffer, m_GpuSplatEditDataBuffer);
632629
cmb.SetComputeIntParam(m_CSSplatUtilities, Props.BufferSize, m_GpuSplatSelectedBuffer.count);
633-
cmb.SetComputeIntParam(m_CSSplatUtilities, Props.SplatCount, m_Asset.m_SplatCount);
634630
m_CSSplatUtilities.GetKernelThreadGroupSizes((int)KernelIndices.UpdateEditData, out uint gsX, out _, out _);
635631
cmb.DispatchCompute(m_CSSplatUtilities, (int)KernelIndices.UpdateEditData, (int)((m_GpuSplatSelectedBuffer.count+gsX-1)/gsX), 1, 1);
636632
Graphics.ExecuteCommandBuffer(cmb);
@@ -639,10 +635,11 @@ void UpdateEditCountsAndBounds()
639635
m_GpuSplatEditDataBuffer.GetData(res);
640636
editSelectedSplats = res[0];
641637
editDeletedSplats = res[1];
642-
Vector3 bmin = new Vector3(SortableUintToFloat(res[2]), SortableUintToFloat(res[3]), SortableUintToFloat(res[4]));
643-
Vector3 bmax = new Vector3(SortableUintToFloat(res[5]), SortableUintToFloat(res[6]), SortableUintToFloat(res[7]));
638+
editCutSplats = res[2];
639+
Vector3 min = new Vector3(SortableUintToFloat(res[3]), SortableUintToFloat(res[4]), SortableUintToFloat(res[5]));
640+
Vector3 max = new Vector3(SortableUintToFloat(res[6]), SortableUintToFloat(res[7]), SortableUintToFloat(res[8]));
644641
Bounds bounds = default;
645-
bounds.SetMinMax(bmin, bmax);
642+
bounds.SetMinMax(min, max);
646643
if (bounds.extents.sqrMagnitude < 0.01)
647644
bounds.extents = new Vector3(0.1f,0.1f,0.1f);
648645
editSelectedBounds = bounds;
@@ -686,7 +683,7 @@ bool EnsureEditingBuffers()
686683
m_GpuSplatSelectedBuffer = new GraphicsBuffer(target, size, 4) {name = "GaussianSplatSelected"};
687684
m_GpuSplatSelectedInitBuffer = new GraphicsBuffer(target, size, 4) {name = "GaussianSplatSelectedInit"};
688685
m_GpuSplatDeletedBuffer = new GraphicsBuffer(target, size, 4) {name = "GaussianSplatDeleted"};
689-
m_GpuSplatEditDataBuffer = new GraphicsBuffer(target, 1 + 1 + 6, 4) {name = "GaussianSplatEditData"}; // selected count, deleted bound, float3 min, float3 max
686+
m_GpuSplatEditDataBuffer = new GraphicsBuffer(target, 3 + 6, 4) {name = "GaussianSplatEditData"}; // selected count, deleted bound, cut count, float3 min, float3 max
690687
ClearGraphicsBuffer(m_GpuSplatSelectedBuffer);
691688
ClearGraphicsBuffer(m_GpuSplatSelectedInitBuffer);
692689
ClearGraphicsBuffer(m_GpuSplatDeletedBuffer);
@@ -715,10 +712,8 @@ public void EditUpdateSelection(Vector2 rectMin, Vector2 rectMax, Camera cam)
715712
Vector4 screenPar = new Vector4(screenW, screenH, 0, 0);
716713
Vector4 camPos = cam.transform.position;
717714

718-
var cmb = new CommandBuffer { name = "SplatSelectionUpdate" };
719-
SetAssetDataOnCS(cmb, m_CSSplatUtilities, (int)KernelIndices.SelectionUpdate);
720-
cmb.SetComputeIntParam(m_CSSplatUtilities, Props.SplatCount, m_Asset.m_SplatCount);
721-
cmb.SetComputeBufferParam(m_CSSplatUtilities, (int)KernelIndices.SelectionUpdate, Props.SplatChunks, m_GpuChunks);
715+
using var cmb = new CommandBuffer { name = "SplatSelectionUpdate" };
716+
SetAssetDataOnCS(cmb, KernelIndices.SelectionUpdate);
722717

723718
cmb.SetComputeMatrixParam(m_CSSplatUtilities, Props.MatrixVP, matProj * matView);
724719
cmb.SetComputeMatrixParam(m_CSSplatUtilities, Props.MatrixMV, matView * matO2W);
@@ -729,16 +724,9 @@ public void EditUpdateSelection(Vector2 rectMin, Vector2 rectMax, Camera cam)
729724
cmb.SetComputeVectorParam(m_CSSplatUtilities, Props.VecScreenParams, screenPar);
730725
cmb.SetComputeVectorParam(m_CSSplatUtilities, Props.VecWorldSpaceCameraPos, camPos);
731726

732-
UpdateCutoutsBuffer();
733-
cmb.SetComputeIntParam(m_CSSplatUtilities, Props.SplatCutoutsCount, m_Cutouts?.Length ?? 0);
734-
cmb.SetComputeBufferParam(m_CSSplatUtilities, (int)KernelIndices.SelectionUpdate, Props.SplatCutouts, m_GpuSplatCutoutsBuffer);
735-
736727
cmb.SetComputeVectorParam(m_CSSplatUtilities, "_SelectionRect", new Vector4(rectMin.x, rectMax.y, rectMax.x, rectMin.y));
737728

738-
m_CSSplatUtilities.GetKernelThreadGroupSizes((int)KernelIndices.SelectionUpdate, out uint gsX, out _, out _);
739-
cmb.DispatchCompute(m_CSSplatUtilities, (int)KernelIndices.SelectionUpdate, (m_Asset.m_SplatCount + (int)gsX - 1)/(int)gsX, 1, 1);
740-
Graphics.ExecuteCommandBuffer(cmb);
741-
cmb.Dispose();
729+
DispatchUtilsAndExecute(cmb, KernelIndices.SelectionUpdate, m_Asset.m_SplatCount);
742730
UpdateEditCountsAndBounds();
743731
}
744732

@@ -755,7 +743,11 @@ public void EditDeleteSelected()
755743
public void EditSelectAll()
756744
{
757745
if (!EnsureEditingBuffers()) return;
758-
ClearGraphicsBuffer(m_GpuSplatSelectedBuffer, ~0u);
746+
using var cmb = new CommandBuffer { name = "SplatSelectAll" };
747+
SetAssetDataOnCS(cmb, KernelIndices.SelectAll);
748+
cmb.SetComputeBufferParam(m_CSSplatUtilities, (int)KernelIndices.SelectAll, Props.DstBuffer, m_GpuSplatSelectedBuffer);
749+
cmb.SetComputeIntParam(m_CSSplatUtilities, Props.BufferSize, m_GpuSplatSelectedBuffer.count);
750+
DispatchUtilsAndExecute(cmb, KernelIndices.SelectAll, m_GpuSplatSelectedBuffer.count);
759751
UpdateEditCountsAndBounds();
760752
}
761753

@@ -769,29 +761,32 @@ public void EditDeselectAll()
769761
public void EditInvertSelection()
770762
{
771763
if (!EnsureEditingBuffers()) return;
772-
InvertGraphicsBuffer(m_GpuSplatSelectedBuffer);
764+
765+
using var cmb = new CommandBuffer { name = "SplatInvertSelection" };
766+
SetAssetDataOnCS(cmb, KernelIndices.InvertSelection);
767+
cmb.SetComputeBufferParam(m_CSSplatUtilities, (int)KernelIndices.InvertSelection, Props.DstBuffer, m_GpuSplatSelectedBuffer);
768+
cmb.SetComputeIntParam(m_CSSplatUtilities, Props.BufferSize, m_GpuSplatSelectedBuffer.count);
769+
DispatchUtilsAndExecute(cmb, KernelIndices.InvertSelection, m_GpuSplatSelectedBuffer.count);
773770
UpdateEditCountsAndBounds();
774771
}
775772

776773
public bool EditExportData(GraphicsBuffer dstData)
777774
{
778775
if (!EnsureEditingBuffers()) return false;
779776

780-
var cmb = new CommandBuffer { name = "SplatExportData" };
781-
SetAssetDataOnCS(cmb, m_CSSplatUtilities, (int)KernelIndices.ExportData);
782-
cmb.SetComputeIntParam(m_CSSplatUtilities, Props.SplatCount, m_Asset.m_SplatCount);
783-
cmb.SetComputeBufferParam(m_CSSplatUtilities, (int)KernelIndices.ExportData, Props.SplatChunks, m_GpuChunks);
777+
using var cmb = new CommandBuffer { name = "SplatExportData" };
778+
SetAssetDataOnCS(cmb, KernelIndices.ExportData);
784779
cmb.SetComputeBufferParam(m_CSSplatUtilities, (int)KernelIndices.ExportData, "_ExportBuffer", dstData);
785780

786-
UpdateCutoutsBuffer();
787-
cmb.SetComputeIntParam(m_CSSplatUtilities, Props.SplatCutoutsCount, m_Cutouts?.Length ?? 0);
788-
cmb.SetComputeBufferParam(m_CSSplatUtilities, (int)KernelIndices.ExportData, Props.SplatCutouts, m_GpuSplatCutoutsBuffer);
781+
DispatchUtilsAndExecute(cmb, KernelIndices.ExportData, m_Asset.m_SplatCount);
782+
return true;
783+
}
789784

790-
m_CSSplatUtilities.GetKernelThreadGroupSizes((int)KernelIndices.ExportData, out uint gsX, out _, out _);
791-
cmb.DispatchCompute(m_CSSplatUtilities, (int)KernelIndices.ExportData, (m_Asset.m_SplatCount + (int)gsX - 1)/(int)gsX, 1, 1);
785+
void DispatchUtilsAndExecute(CommandBuffer cmb, KernelIndices kernel, int count)
786+
{
787+
m_CSSplatUtilities.GetKernelThreadGroupSizes((int)kernel, out uint gsX, out _, out _);
788+
cmb.DispatchCompute(m_CSSplatUtilities, (int)kernel, (int)((count + gsX - 1)/gsX), 1, 1);
792789
Graphics.ExecuteCommandBuffer(cmb);
793-
cmb.Dispose();
794-
return true;
795790
}
796791

797792
public GraphicsBuffer gpuSplatDeletedBuffer => m_GpuSplatDeletedBuffer;

0 commit comments

Comments
 (0)