@@ -194,11 +194,11 @@ internal class SurfaceCacheResourceSet
194194 internal int TemporalFilteringKernel ;
195195 internal uint3 TemporalFilteringKernelGroupSize ;
196196
197- internal readonly uint SubGroupSize ;
197+ internal readonly uint ComputeSubGroupSize ;
198198
199- internal SurfaceCacheResourceSet ( uint subGroupSize )
199+ internal SurfaceCacheResourceSet ( uint computeSubGroupSize )
200200 {
201- SubGroupSize = subGroupSize ;
201+ ComputeSubGroupSize = computeSubGroupSize ;
202202 }
203203
204204 internal bool LoadFromRenderPipelineResources ( RayTracingContext rtContext )
@@ -223,9 +223,9 @@ internal bool LoadFromRenderPipelineResources(RayTracingContext rtContext)
223223 TemporalFilteringKernel = TemporalFilteringShader . FindKernel ( "FilterTemporally" ) ;
224224 TemporalFilteringShader . GetKernelThreadGroupSizes ( TemporalFilteringKernel , out TemporalFilteringKernelGroupSize . x , out TemporalFilteringKernelGroupSize . y , out TemporalFilteringKernelGroupSize . z ) ;
225225
226- Debug . Assert ( SubGroupSize == 8 || SubGroupSize == 16 || SubGroupSize == 32 || SubGroupSize == 48 || SubGroupSize == 64 ) ;
226+ Debug . Assert ( ComputeSubGroupSize == 8 || ComputeSubGroupSize == 16 || ComputeSubGroupSize == 32 || ComputeSubGroupSize == 48 || ComputeSubGroupSize == 64 ) ;
227227 DefragShader = rpResources . defragShader ;
228- var defragKeyword = "SUB_GROUP_SIZE_" + SubGroupSize ;
228+ var defragKeyword = "SUB_GROUP_SIZE_" + ComputeSubGroupSize ;
229229 DefragShader . EnableKeyword ( defragKeyword ) ;
230230 DefragKernel = DefragShader . FindKernel ( "Defrag" ) ;
231231 DefragShader . GetKernelThreadGroupSizes ( DefragKernel , out DefragKernelGroupSize . x , out DefragKernelGroupSize . y , out DefragKernelGroupSize . z ) ;
@@ -256,6 +256,7 @@ internal bool LoadFromRenderPipelineResources(RayTracingContext rtContext)
256256 internal class SurfaceCache : IDisposable
257257 {
258258 public const uint CascadeMax = 8 ;
259+
259260 private readonly GraphicsBuffer _punctualLightSamples ;
260261 private readonly SurfaceCachePatchList _patches ;
261262 private readonly SurfaceCacheVolume _volume ;
@@ -267,7 +268,8 @@ internal class SurfaceCache : IDisposable
267268 private SurfaceCachePatchFilteringParameterSet _patchFilteringParams ;
268269
269270 private float _shortHysteresis ;
270- readonly private uint _defragCount ;
271+ private uint _defragCount = 1 ;
272+ private uint _defragOffset = 0 ;
271273 readonly private float _albedoBoost = 1.0f ;
272274
273275 public GraphicsBuffer PunctualLightSamples => _punctualLightSamples ;
@@ -323,7 +325,7 @@ private class DefragPassData
323325 internal GraphicsBuffer PatchStatistics ;
324326 internal GraphicsBuffer CellPatchIndices ;
325327 internal uint RingConfigStartFlipflop ;
326- internal uint EvenIterationPatchOffset ;
328+ internal uint ComputeSubGroupSize ;
327329 internal uint OddIterationPatchOffset ;
328330 }
329331
@@ -442,7 +444,6 @@ internal static class ShaderIDs
442444
443445 public SurfaceCache (
444446 SurfaceCacheResourceSet resources ,
445- uint defragCount ,
446447 SurfaceCacheVolumeParameterSet volParams )
447448 {
448449 Debug . Assert ( volParams . CascadeCount != 0 ) ;
@@ -457,23 +458,26 @@ public SurfaceCache(
457458 _ringConfig = new SurfaceCacheRingConfig ( ) ;
458459 _patches = new SurfaceCachePatchList ( patchCapacity ) ;
459460 _punctualLightSamples = new GraphicsBuffer ( GraphicsBuffer . Target . Structured , ( int ) punctualLightSampleCount , sizeof ( float ) * 17 ) ;
460-
461- _defragCount = defragCount ;
462461 }
463462
464463 public void SetEstimationParams ( SurfaceCacheEstimationParameterSet estimationParams )
465464 {
466465 _estimationParams = estimationParams ;
467466 }
468467
468+ public void SetDefragCount ( uint count )
469+ {
470+ _defragCount = count ;
471+ }
472+
469473 public void SetPatchFilteringParams ( SurfaceCachePatchFilteringParameterSet patchFilteringParams )
470474 {
471475 Debug . Assert ( 0.0f <= patchFilteringParams . TemporalSmoothing && patchFilteringParams . TemporalSmoothing <= 1.0f ) ;
472476 _patchFilteringParams = patchFilteringParams ;
473477 _shortHysteresis = Mathf . Lerp ( 0.75f , 0.95f , patchFilteringParams . TemporalSmoothing ) ;
474478 }
475479
476- public void UpdateVolumeSize ( float size )
480+ public void SetVolumeSize ( float size )
477481 {
478482 _volume . VoxelMinSize = size / ( _volume . SpatialResolution * ( float ) ( 1u << ( int ) ( _volume . CascadeCount - 1u ) ) ) ;
479483 }
@@ -495,7 +499,7 @@ private void RecordDefragmentation(RenderGraph renderGraph, uint frameIdx)
495499 {
496500 using ( var builder = renderGraph . AddComputePass ( "Surface Cache Defrag" , out DefragPassData passData ) )
497501 {
498- passData . IterationOffset = frameIdx * _defragCount ;
502+ passData . IterationOffset = _defragOffset ;
499503 passData . IterationCount = _defragCount ;
500504 passData . Shader = _resources . DefragShader ;
501505 passData . Keyword = _resources . DefragKeyword ;
@@ -510,15 +514,16 @@ private void RecordDefragmentation(RenderGraph renderGraph, uint frameIdx)
510514 passData . PatchGeometries = Patches . Geometries ;
511515 passData . PatchStatistics = Patches . Statistics ;
512516 passData . CellPatchIndices = Volume . CellPatchIndices ;
513- passData . EvenIterationPatchOffset = 0 ;
514- passData . OddIterationPatchOffset = _resources . SubGroupSize / 2 ;
517+ passData . ComputeSubGroupSize = _resources . ComputeSubGroupSize ;
515518
516519 builder . AllowGlobalStateModification ( true ) ; // Set to ensure ordering.
517520 builder . SetRenderFunc ( ( DefragPassData data , ComputeGraphContext cgContext ) => Defrag ( data , cgContext ) ) ;
518521
519522 if ( _defragCount % 2 == 1 )
520523 RingConfig . Flip ( ) ;
521524 }
525+
526+ _defragOffset += _defragCount ;
522527 }
523528
524529 private void RecordEviction ( RenderGraph renderGraph , uint frameIdx )
@@ -770,7 +775,7 @@ static void Defrag(DefragPassData data, ComputeGraphContext cgContext)
770775 {
771776 uint readOffset = SurfaceCacheRingConfig . GetOffsetA ( flipflop ) ;
772777 uint writeOffset = SurfaceCacheRingConfig . GetOffsetB ( flipflop ) ;
773- uint patchOffset = iterationIndex % 2 == 0 ? data . EvenIterationPatchOffset : data . OddIterationPatchOffset ;
778+ uint patchOffset = iterationIndex % 2 * ( data . ComputeSubGroupSize / 2 ) ;
774779
775780 cmd . SetComputeIntParam ( shader , ShaderIDs . _RingConfigReadOffset , ( int ) readOffset ) ;
776781 cmd . SetComputeIntParam ( shader , ShaderIDs . _RingConfigWriteOffset , ( int ) writeOffset ) ;
0 commit comments