Skip to content

Commit 8b314aa

Browse files
Remove TryGetOrCreateSharedBuffer
1 parent 24c7c6e commit 8b314aa

1 file changed

Lines changed: 2 additions & 88 deletions

File tree

src/ImageSharp.Drawing.WebGPU/WebGPURuntime.DeviceSharedState.cs

Lines changed: 2 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Collections.Concurrent;
55
using System.Runtime.InteropServices;
66
using Silk.NET.WebGPU;
7-
using WgpuBuffer = Silk.NET.WebGPU.Buffer;
87

98
namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
109

@@ -53,14 +52,13 @@ private static void ClearDeviceStateCache()
5352
}
5453

5554
/// <summary>
56-
/// Shared device-scoped caches for pipelines, bind groups, and reusable GPU resources.
55+
/// Shared device-scoped caches for pipelines and pipeline layouts.
5756
/// </summary>
5857
internal sealed class DeviceSharedState : IDisposable
5958
{
6059
private const nuint DefaultMaxStorageBufferBindingSize = 128U * 1024U * 1024U;
6160
private readonly ConcurrentDictionary<string, CompositePipelineInfrastructure> compositePipelines = new(StringComparer.Ordinal);
6261
private readonly ConcurrentDictionary<string, CompositeComputePipelineInfrastructure> compositeComputePipelines = new(StringComparer.Ordinal);
63-
private readonly ConcurrentDictionary<string, SharedBufferInfrastructure> sharedBuffers = new(StringComparer.Ordinal);
6462
private readonly HashSet<FeatureName> deviceFeatures;
6563
private WebGPUHandle.HandleReference deviceReference;
6664
private PfnErrorCallback uncapturedErrorCallback;
@@ -350,68 +348,7 @@ infrastructure.PipelineLayout is null ||
350348
}
351349

352350
/// <summary>
353-
/// Gets or creates a reusable shared buffer for device-scoped operations.
354-
/// </summary>
355-
public bool TryGetOrCreateSharedBuffer(
356-
string bufferKey,
357-
BufferUsage usage,
358-
nuint requiredSize,
359-
out WgpuBuffer* buffer,
360-
out nuint capacity,
361-
out string? error)
362-
{
363-
buffer = null;
364-
capacity = 0;
365-
366-
ObjectDisposedException.ThrowIf(this.disposed, this);
367-
368-
SharedBufferInfrastructure infrastructure = this.sharedBuffers.GetOrAdd(
369-
bufferKey,
370-
static _ => new SharedBufferInfrastructure());
371-
lock (infrastructure)
372-
{
373-
if (infrastructure.Buffer is not null &&
374-
infrastructure.Capacity >= requiredSize &&
375-
infrastructure.Usage == usage)
376-
{
377-
buffer = infrastructure.Buffer;
378-
capacity = infrastructure.Capacity;
379-
error = null;
380-
return true;
381-
}
382-
383-
if (infrastructure.Buffer is not null)
384-
{
385-
this.Api.BufferRelease(infrastructure.Buffer);
386-
infrastructure.Buffer = null;
387-
infrastructure.Capacity = 0;
388-
}
389-
390-
BufferDescriptor descriptor = new()
391-
{
392-
Usage = usage,
393-
Size = requiredSize
394-
};
395-
396-
WgpuBuffer* createdBuffer = this.Api.DeviceCreateBuffer(this.Device, in descriptor);
397-
if (createdBuffer is null)
398-
{
399-
error = $"Failed to create shared buffer '{bufferKey}'.";
400-
return false;
401-
}
402-
403-
infrastructure.Buffer = createdBuffer;
404-
infrastructure.Capacity = requiredSize;
405-
infrastructure.Usage = usage;
406-
buffer = createdBuffer;
407-
capacity = requiredSize;
408-
error = null;
409-
return true;
410-
}
411-
}
412-
413-
/// <summary>
414-
/// Releases all cached pipelines and buffers owned by this state.
351+
/// Releases all cached pipelines owned by this state.
415352
/// </summary>
416353
public void Dispose()
417354
{
@@ -434,21 +371,6 @@ public void Dispose()
434371

435372
this.compositeComputePipelines.Clear();
436373

437-
foreach (SharedBufferInfrastructure infrastructure in this.sharedBuffers.Values)
438-
{
439-
lock (infrastructure)
440-
{
441-
if (infrastructure.Buffer is not null)
442-
{
443-
this.Api.BufferRelease(infrastructure.Buffer);
444-
infrastructure.Buffer = null;
445-
infrastructure.Capacity = 0;
446-
}
447-
}
448-
}
449-
450-
this.sharedBuffers.Clear();
451-
452374
// Clear the native callback slot before freeing Silk's delegate thunk.
453375
this.Api.DeviceSetUncapturedErrorCallback(this.Device, default, null);
454376
this.uncapturedErrorCallback.Dispose();
@@ -730,13 +652,5 @@ private sealed class CompositeComputePipelineInfrastructure
730652
public ComputePipeline* Pipeline { get; set; }
731653
}
732654

733-
private sealed class SharedBufferInfrastructure
734-
{
735-
public WgpuBuffer* Buffer { get; set; }
736-
737-
public nuint Capacity { get; set; }
738-
739-
public BufferUsage Usage { get; set; }
740-
}
741655
}
742656
}

0 commit comments

Comments
 (0)