Skip to content

Commit fd5a72d

Browse files
Refactor WebGPU buffer creation helpers to remove Try
1 parent 8b314aa commit fd5a72d

5 files changed

Lines changed: 141 additions & 425 deletions

File tree

src/ImageSharp.Drawing.WebGPU/WebGPUDrawingBackend.Readback.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,6 @@ public void ReadRegion<TPixel>(
108108
};
109109

110110
readbackBuffer = api.DeviceCreateBuffer(device, in bufferDescriptor);
111-
if (readbackBuffer is null)
112-
{
113-
throw new InvalidOperationException("The WebGPU device could not create a readback buffer.");
114-
}
115-
116111
CommandEncoderDescriptor encoderDescriptor = default;
117112
commandEncoder = api.DeviceCreateCommandEncoder(device, in encoderDescriptor);
118113
if (commandEncoder is null)

src/ImageSharp.Drawing.WebGPU/WebGPUFlushContext.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,11 @@ private WebGPUFlushContext(
223223
/// </summary>
224224
/// <param name="requiredBytes">The required number of bytes for the current flush.</param>
225225
/// <param name="minimumCapacityBytes">The minimum allocation size to enforce when creating a new buffer.</param>
226-
/// <returns><see langword="true"/> if the buffer is available with sufficient capacity; otherwise <see langword="false"/>.</returns>
227-
public bool EnsureInstanceBufferCapacity(nuint requiredBytes, nuint minimumCapacityBytes)
226+
public void EnsureInstanceBufferCapacity(nuint requiredBytes, nuint minimumCapacityBytes)
228227
{
229228
if (this.InstanceBuffer is not null && this.InstanceBufferCapacity >= requiredBytes)
230229
{
231-
return true;
230+
return;
232231
}
233232

234233
if (this.InstanceBuffer is not null)
@@ -247,13 +246,7 @@ public bool EnsureInstanceBufferCapacity(nuint requiredBytes, nuint minimumCapac
247246

248247
using WebGPUHandle.HandleReference deviceReference = this.DeviceHandle.AcquireReference();
249248
this.InstanceBuffer = this.Api.DeviceCreateBuffer((Device*)deviceReference.Handle, in descriptor);
250-
if (this.InstanceBuffer is null)
251-
{
252-
return false;
253-
}
254-
255249
this.InstanceBufferCapacity = targetSize;
256-
return true;
257250
}
258251

259252
/// <summary>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,5 @@ private sealed class CompositeComputePipelineInfrastructure
651651

652652
public ComputePipeline* Pipeline { get; set; }
653653
}
654-
655654
}
656655
}

0 commit comments

Comments
 (0)