Move ReferenceTracker logic to NativeObject base class

このコミットが含まれているのは:
Sergio Pedri committed 2022-07-31 23:26:11 +02:00
1 親 297aa7ab36
コミット 149a03d92b
18ファイル変更
+157 -499

検索条件に一致するファイルはありません

+48 -40
ファイルの表示
@@ -9,14 +9,14 @@ using ComputeSharp.Uwp.Extensions;
using ComputeSharp.WinUI.Extensions;
#endif
#pragma warning disable CS0420
#if WINDOWS_UWP
namespace ComputeSharp.Uwp.Helpers;
#else
namespace ComputeSharp.WinUI.Helpers;
#endif
#pragma warning disable CS0420
/// <inheritdoc/>
partial class SwapChainManager<TOwner>
{
@@ -27,26 +27,27 @@ partial class SwapChainManager<TOwner>
/// <param name="shaderRunner">The <see cref="IShaderRunner"/> instance to use to render frames.</param>
public async void StartRenderLoop(IFrameRequestQueue? frameRequestQueue, IShaderRunner shaderRunner)
{
ThrowIfDisposed();
Guard.IsNotNull(shaderRunner);
using (await this.setupSemaphore.LockAsync())
using (GetReferenceTracker().GetLease())
{
this.renderCancellationTokenSource?.Cancel();
await this.renderSemaphore.WaitAsync();
Guard.IsNotNull(shaderRunner);
Thread newRenderThread = new(static args => ((SwapChainManager<TOwner>)args!).SwitchAndStartRenderLoop());
using (await this.setupSemaphore.LockAsync())
{
this.renderCancellationTokenSource?.Cancel();
this.frameRequestQueue = frameRequestQueue;
this.shaderRunner = shaderRunner;
this.renderCancellationTokenSource = new CancellationTokenSource();
this.renderThread = newRenderThread;
this.renderSemaphore = new SemaphoreSlim(0, 1);
this.isResizePending = true;
await this.renderSemaphore.WaitAsync();
newRenderThread.Start(this);
Thread newRenderThread = new(static args => ((SwapChainManager<TOwner>)args!).SwitchAndStartRenderLoop());
this.frameRequestQueue = frameRequestQueue;
this.shaderRunner = shaderRunner;
this.renderCancellationTokenSource = new CancellationTokenSource();
this.renderThread = newRenderThread;
this.renderSemaphore = new SemaphoreSlim(0, 1);
this.isResizePending = true;
newRenderThread.Start(this);
}
}
}
@@ -55,8 +56,7 @@ partial class SwapChainManager<TOwner>
/// </summary>
public async void StopRenderLoop()
{
ThrowIfDisposed();
using (GetReferenceTracker().GetLease())
using (await this.setupSemaphore.LockAsync())
{
this.renderCancellationTokenSource?.Cancel();
@@ -69,8 +69,7 @@ partial class SwapChainManager<TOwner>
/// <param name="isDynamicResolutionEnabled">Whether or not to use dynamic resolution.</param>
public async void QueueDynamicResolutionModeChange(bool isDynamicResolutionEnabled)
{
ThrowIfDisposed();
using (GetReferenceTracker().GetLease())
using (await this.setupSemaphore.LockAsync())
{
// If there is a render thread currently running, stop it and restart it
@@ -103,8 +102,7 @@ partial class SwapChainManager<TOwner>
/// <param name="isVerticalSyncEnabled">Whether or not to use vertical sync.</param>
public async void QueueVerticalSyncModeChange(bool isVerticalSyncEnabled)
{
ThrowIfDisposed();
using (GetReferenceTracker().GetLease())
using (await this.setupSemaphore.LockAsync())
{
// The v-sync option can be toggled on the fly when not using dynamic resolution
@@ -138,12 +136,13 @@ partial class SwapChainManager<TOwner>
/// <param name="height">The height of the render resolution.</param>
public void QueueResize(double width, double height)
{
ThrowIfDisposed();
using (GetReferenceTracker().GetLease())
{
this.width = (float)width;
this.height = (float)height;
this.width = (float)width;
this.height = (float)height;
this.isResizePending = true;
this.isResizePending = true;
}
}
/// <summary>
@@ -153,12 +152,13 @@ partial class SwapChainManager<TOwner>
/// <param name="compositionScaleY">The composition scale on the Y axis</param>
public void QueueCompositionScaleChange(double compositionScaleX, double compositionScaleY)
{
ThrowIfDisposed();
using (GetReferenceTracker().GetLease())
{
this.compositionScaleX = (float)compositionScaleX;
this.compositionScaleY = (float)compositionScaleY;
this.compositionScaleX = (float)compositionScaleX;
this.compositionScaleY = (float)compositionScaleY;
this.isResizePending = true;
this.isResizePending = true;
}
}
/// <summary>
@@ -167,11 +167,12 @@ partial class SwapChainManager<TOwner>
/// <param name="resolutionScale">The resolution scale factor to use.</param>
public void QueueResolutionScaleChange(double resolutionScale)
{
ThrowIfDisposed();
using (GetReferenceTracker().GetLease())
{
this.resolutionScale = (float)resolutionScale;
this.resolutionScale = (float)resolutionScale;
this.isResizePending = true;
this.isResizePending = true;
}
}
/// <summary>
@@ -187,11 +188,18 @@ partial class SwapChainManager<TOwner>
{
this.dynamicResolutionScale = this.resolutionScale;
RenderLoopWithDynamicResolution();
// These two leases are needed to ensure the manager isn't disposed while rendering is running
using (GetReferenceTracker().GetLease())
{
RenderLoopWithDynamicResolution();
}
}
else
{
RenderLoop();
using (GetReferenceTracker().GetLease())
{
RenderLoop();
}
}
this.renderStopwatch?.Stop();
+1 -1
ファイルの表示
@@ -497,7 +497,7 @@ internal sealed unsafe partial class SwapChainManager<TOwner> : NativeObject
}
/// <inheritdoc/>
protected override void OnDispose()
private protected override void OnDispose()
{
ThreadPool.UnsafeQueueUserWorkItem(static state =>
{
+1 -1
ファイルの表示
@@ -48,7 +48,7 @@ unsafe partial class GraphicsDevice
/// </summary>
private void QueueRaiseDeviceLostEventIfNeeded()
{
using (this.referenceTracker.TryGetLease(out bool leaseTaken))
using (GetReferenceTracker().TryGetLease(out bool leaseTaken))
{
if (!leaseTaken)
{
+7 -43
ファイルの表示
@@ -23,13 +23,8 @@ namespace ComputeSharp;
/// A <see langword="class"/> that represents an <see cref="ID3D12Device"/> instance that can be used to run compute shaders.
/// </summary>
[DebuggerDisplay("{ToString(),raw}")]
public sealed unsafe partial class GraphicsDevice : ReferenceTracker.ITrackedObject, IDisposable
public sealed unsafe partial class GraphicsDevice : NativeObject
{
/// <summary>
/// The owning <see cref="ReferenceTracker"/> object for the current instance.
/// </summary>
private ReferenceTracker referenceTracker;
/// <summary>
/// The underlying <see cref="ID3D12Device"/> wrapped by the current instance.
/// </summary>
@@ -139,8 +134,6 @@ public sealed unsafe partial class GraphicsDevice : ReferenceTracker.ITrackedObj
/// <param name="dxgiDescription1">The available info for the new <see cref="GraphicsDevice"/> instance.</param>
internal GraphicsDevice(ID3D12Device* d3D12Device, IDXGIAdapter* dxgiAdapter, DXGI_ADAPTER_DESC1* dxgiDescription1)
{
this.referenceTracker = new ReferenceTracker(this);
this.d3D12Device = new ComPtr<ID3D12Device>(d3D12Device);
this.d3D12ComputeCommandQueue = d3D12Device->CreateCommandQueue(D3D12_COMMAND_LIST_TYPE_COMPUTE);
@@ -181,14 +174,6 @@ public sealed unsafe partial class GraphicsDevice : ReferenceTracker.ITrackedObj
RegisterDeviceLostCallback(this, out this.deviceHandle, out this.deviceRemovedEvent, out this.deviceRemovedWaitHandle);
}
/// <summary>
/// Releases unmanaged resources for the current <see cref="GraphicsDevice"/> instance.
/// </summary>
~GraphicsDevice()
{
this.referenceTracker.Dispose();
}
/// <summary>
/// Gets the locally unique identifier for the current device.
/// </summary>
@@ -253,7 +238,7 @@ public sealed unsafe partial class GraphicsDevice : ReferenceTracker.ITrackedObj
/// <returns>Whether the current device supports double precision floating point operations in shaders.</returns>
public bool IsDoublePrecisionSupportAvailable()
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceLost();
@@ -272,7 +257,7 @@ public sealed unsafe partial class GraphicsDevice : ReferenceTracker.ITrackedObj
public bool IsReadOnlyTexture2DSupportedForType<T>()
where T : unmanaged
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceLost();
@@ -289,7 +274,7 @@ public sealed unsafe partial class GraphicsDevice : ReferenceTracker.ITrackedObj
public bool IsReadWriteTexture2DSupportedForType<T>()
where T : unmanaged
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceLost();
@@ -308,7 +293,7 @@ public sealed unsafe partial class GraphicsDevice : ReferenceTracker.ITrackedObj
public bool IsReadOnlyTexture3DSupportedForType<T>()
where T : unmanaged
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceLost();
@@ -325,7 +310,7 @@ public sealed unsafe partial class GraphicsDevice : ReferenceTracker.ITrackedObj
public bool IsReadWriteTexture3DSupportedForType<T>()
where T : unmanaged
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceLost();
@@ -423,28 +408,7 @@ public sealed unsafe partial class GraphicsDevice : ReferenceTracker.ITrackedObj
}
/// <inheritdoc/>
public void Dispose()
{
this.referenceTracker.Dispose();
GC.SuppressFinalize(this);
}
/// <inheritdoc cref="ReferenceTracker.ITrackedObject.GetReferenceTracker"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal ref ReferenceTracker GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
ref ReferenceTracker ReferenceTracker.ITrackedObject.GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
void ReferenceTracker.ITrackedObject.DangerousRelease()
private protected override void OnDispose()
{
DeviceHelper.NotifyDisposedDevice(this);
+1 -1
ファイルの表示
@@ -207,7 +207,7 @@ partial class DeviceHelper
}
/// <inheritdoc/>
protected override void OnDispose()
private protected override void OnDispose()
{
this.dxgiFactory6.Dispose();
}
+32 -48
ファイルの表示
@@ -1,77 +1,61 @@
using System;
using System.Runtime.CompilerServices;
using System.Threading;
namespace ComputeSharp.Interop;
/// <summary>
/// Base class for a <see cref="IDisposable"/> class.
/// </summary>
internal abstract class NativeObject : IDisposable
public abstract class NativeObject : IDisposable, ReferenceTracker.ITrackedObject
{
/// <summary>
/// Indicates whether or not the current instance has been disposed.
/// The owning <see cref="ReferenceTracker"/> object for the current instance.
/// </summary>
private volatile int isDisposed;
private ReferenceTracker referenceTracker;
/// <summary>
/// Creates a new <see cref="NativeObject"/> instance.
/// </summary>
internal NativeObject()
{
this.referenceTracker = new ReferenceTracker(this);
}
/// <summary>
/// Releases unmanaged resources and performs other cleanup operations.
/// </summary>
~NativeObject()
{
if (Interlocked.CompareExchange(ref this.isDisposed, 1, 0) == 0)
{
OnDispose();
}
}
/// <summary>
/// Gets whether or not the current instance has already been disposed.
/// </summary>
internal bool IsDisposed
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => this.isDisposed != 0;
this.referenceTracker.Dispose();
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose()
{
if (Interlocked.CompareExchange(ref this.isDisposed, 1, 0) == 0)
{
[MethodImpl(MethodImplOptions.NoInlining)]
void DisposeAndSuppressFinalize()
{
OnDispose();
this.referenceTracker.Dispose();
GC.SuppressFinalize(this);
}
DisposeAndSuppressFinalize();
}
GC.SuppressFinalize(this);
}
/// <summary>
/// Releases unmanaged and (optionally) managed resources.
/// </summary>
protected abstract void OnDispose();
/// <summary>
/// Throws an <see cref="ObjectDisposedException"/> if the current instance has been disposed.
/// </summary>
/// <exception cref="ObjectDisposedException">Thrown if the current instance is disposed.</exception>
/// <inheritdoc cref="ReferenceTracker.ITrackedObject.GetReferenceTracker"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ThrowIfDisposed()
internal ref ReferenceTracker GetReferenceTracker()
{
if (IsDisposed)
{
// We can't use ThrowHelper here as we only want to invoke ToString if we
// are about to throw an exception. The JIT will recognize this pattern
// as this method has a single basic block that always throws an exception.
static void Throw(object self) => throw new ObjectDisposedException(self.ToString());
Throw(this);
}
return ref this.referenceTracker;
}
/// <inheritdoc/>
ref ReferenceTracker ReferenceTracker.ITrackedObject.GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
void ReferenceTracker.ITrackedObject.DangerousRelease()
{
OnDispose();
}
/// <inheritdoc cref="ReferenceTracker.ITrackedObject.DangerousRelease"/>
private protected abstract void OnDispose();
}
+4 -40
ファイルの表示
@@ -25,14 +25,9 @@ namespace ComputeSharp.Resources;
/// A <see langword="class"/> representing a typed buffer stored on GPU memory.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
public unsafe abstract class Buffer<T> : ReferenceTracker.ITrackedObject, IDisposable, IGraphicsResource
public unsafe abstract class Buffer<T> : NativeObject, IGraphicsResource
where T : unmanaged
{
/// <summary>
/// The owning <see cref="ReferenceTracker"/> object for the current instance.
/// </summary>
private ReferenceTracker referenceTracker;
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
@@ -70,8 +65,6 @@ public unsafe abstract class Buffer<T> : ReferenceTracker.ITrackedObject, IDispo
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
private protected Buffer(GraphicsDevice device, int length, uint elementSizeInBytes, ResourceType resourceType, AllocationMode allocationMode)
{
this.referenceTracker = new ReferenceTracker(this);
using (device.GetReferenceTracker().GetLease())
{
device.ThrowIfDeviceLost();
@@ -133,14 +126,6 @@ public unsafe abstract class Buffer<T> : ReferenceTracker.ITrackedObject, IDispo
}
}
/// <summary>
/// Releases unmanaged resources for the current <see cref="Buffer{T}"/> instance.
/// </summary>
~Buffer()
{
this.referenceTracker.Dispose();
}
/// <inheritdoc/>
public GraphicsDevice GraphicsDevice { get; }
@@ -219,28 +204,7 @@ public unsafe abstract class Buffer<T> : ReferenceTracker.ITrackedObject, IDispo
internal abstract void CopyFrom(ref T source, int destinationOffset, int count);
/// <inheritdoc/>
public void Dispose()
{
this.referenceTracker.Dispose();
GC.SuppressFinalize(this);
}
/// <inheritdoc cref="ReferenceTracker.ITrackedObject.GetReferenceTracker"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal ref ReferenceTracker GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
ref ReferenceTracker ReferenceTracker.ITrackedObject.GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
void ReferenceTracker.ITrackedObject.DangerousRelease()
private protected sealed override void OnDispose()
{
this.d3D12Resource.Dispose();
#if NET6_0_OR_GREATER
@@ -270,7 +234,7 @@ public unsafe abstract class Buffer<T> : ReferenceTracker.ITrackedObject, IDispo
/// <inheritdoc cref="__Internals.GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice, out bool)"/>
internal (D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
@@ -283,7 +247,7 @@ public unsafe abstract class Buffer<T> : ReferenceTracker.ITrackedObject, IDispo
/// <inheritdoc cref="__Internals.GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice)"/>
internal unsafe ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
+12 -48
ファイルの表示
@@ -26,14 +26,9 @@ namespace ComputeSharp.Resources;
/// A <see langword="class"/> representing a typed 2D texture stored on GPU memory.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
public unsafe abstract class Texture2D<T> : ReferenceTracker.ITrackedObject, IDisposable, IGraphicsResource, GraphicsResourceHelper.IGraphicsResource
public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, GraphicsResourceHelper.IGraphicsResource
where T : unmanaged
{
/// <summary>
/// The owning <see cref="ReferenceTracker"/> object for the current instance.
/// </summary>
private ReferenceTracker referenceTracker;
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
@@ -77,8 +72,6 @@ public unsafe abstract class Texture2D<T> : ReferenceTracker.ITrackedObject, IDi
/// <param name="d3D12FormatSupport">The format support for the current texture type.</param>
private protected Texture2D(GraphicsDevice device, int width, int height, ResourceType resourceType, AllocationMode allocationMode, D3D12_FORMAT_SUPPORT1 d3D12FormatSupport)
{
this.referenceTracker = new ReferenceTracker(this);
using (device.GetReferenceTracker().GetLease())
{
device.ThrowIfDeviceLost();
@@ -144,14 +137,6 @@ public unsafe abstract class Texture2D<T> : ReferenceTracker.ITrackedObject, IDi
}
}
/// <summary>
/// Releases unmanaged resources for the current <see cref="Texture2D{T}"/> instance.
/// </summary>
~Texture2D()
{
this.referenceTracker.Dispose();
}
/// <inheritdoc/>
public GraphicsDevice GraphicsDevice { get; }
@@ -187,7 +172,7 @@ public unsafe abstract class Texture2D<T> : ReferenceTracker.ITrackedObject, IDi
internal void CopyTo(ref T destination, int size, int sourceOffsetX, int sourceOffsetY, int width, int height)
{
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
GraphicsDevice.ThrowIfDeviceLost();
@@ -278,8 +263,8 @@ public unsafe abstract class Texture2D<T> : ReferenceTracker.ITrackedObject, IDi
internal void CopyTo(Texture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
{
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (this.referenceTracker.GetLease())
using (destination.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
using (destination.GetReferenceTracker().GetLease())
{
GraphicsDevice.ThrowIfDeviceLost();
@@ -348,7 +333,7 @@ public unsafe abstract class Texture2D<T> : ReferenceTracker.ITrackedObject, IDi
internal void CopyTo(ReadBackTexture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
{
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
using (destination.GetReferenceTracker().GetLease())
{
GraphicsDevice.ThrowIfDeviceLost();
@@ -413,7 +398,7 @@ public unsafe abstract class Texture2D<T> : ReferenceTracker.ITrackedObject, IDi
internal void CopyFrom(ref T source, int size, int destinationOffsetX, int destinationOffsetY, int width, int height)
{
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
GraphicsDevice.ThrowIfDeviceLost();
@@ -502,7 +487,7 @@ public unsafe abstract class Texture2D<T> : ReferenceTracker.ITrackedObject, IDi
internal void CopyFrom(UploadTexture2D<T> source, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
{
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
using (source.GetReferenceTracker().GetLease())
{
GraphicsDevice.ThrowIfDeviceLost();
@@ -556,28 +541,7 @@ public unsafe abstract class Texture2D<T> : ReferenceTracker.ITrackedObject, IDi
}
/// <inheritdoc/>
public virtual void Dispose()
{
this.referenceTracker.Dispose();
GC.SuppressFinalize(this);
}
/// <inheritdoc cref="ReferenceTracker.ITrackedObject.GetReferenceTracker"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal ref ReferenceTracker GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
ref ReferenceTracker ReferenceTracker.ITrackedObject.GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
void ReferenceTracker.ITrackedObject.DangerousRelease()
private protected override void OnDispose()
{
this.d3D12Resource.Dispose();
#if NET6_0_OR_GREATER
@@ -625,7 +589,7 @@ public unsafe abstract class Texture2D<T> : ReferenceTracker.ITrackedObject, IDi
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice, out bool)"/>
internal (D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
@@ -638,7 +602,7 @@ public unsafe abstract class Texture2D<T> : ReferenceTracker.ITrackedObject, IDi
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice)"/>
internal ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
@@ -649,7 +613,7 @@ public unsafe abstract class Texture2D<T> : ReferenceTracker.ITrackedObject, IDi
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice, ResourceState, out ID3D12Resource*)"/>
internal (D3D12_RESOURCE_STATES Before, D3D12_RESOURCE_STATES After) ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
@@ -667,7 +631,7 @@ public unsafe abstract class Texture2D<T> : ReferenceTracker.ITrackedObject, IDi
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
+12 -48
ファイルの表示
@@ -26,14 +26,9 @@ namespace ComputeSharp.Resources;
/// A <see langword="class"/> representing a typed 3D texture stored on GPU memory.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
public unsafe abstract class Texture3D<T> : ReferenceTracker.ITrackedObject, IDisposable, IGraphicsResource, GraphicsResourceHelper.IGraphicsResource
public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, GraphicsResourceHelper.IGraphicsResource
where T : unmanaged
{
/// <summary>
/// The owning <see cref="ReferenceTracker"/> object for the current instance.
/// </summary>
private ReferenceTracker referenceTracker;
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
@@ -78,8 +73,6 @@ public unsafe abstract class Texture3D<T> : ReferenceTracker.ITrackedObject, IDi
/// <param name="d3D12FormatSupport">The format support for the current texture type.</param>
private protected Texture3D(GraphicsDevice device, int width, int height, int depth, ResourceType resourceType, AllocationMode allocationMode, D3D12_FORMAT_SUPPORT1 d3D12FormatSupport)
{
this.referenceTracker = new ReferenceTracker(this);
using (device.GetReferenceTracker().GetLease())
{
device.ThrowIfDeviceLost();
@@ -149,14 +142,6 @@ public unsafe abstract class Texture3D<T> : ReferenceTracker.ITrackedObject, IDi
}
}
/// <summary>
/// Releases unmanaged resources for the current <see cref="Texture3D{T}"/> instance.
/// </summary>
~Texture3D()
{
this.referenceTracker.Dispose();
}
/// <inheritdoc/>
public GraphicsDevice GraphicsDevice { get; }
@@ -199,7 +184,7 @@ public unsafe abstract class Texture3D<T> : ReferenceTracker.ITrackedObject, IDi
internal void CopyTo(ref T destination, int size, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int width, int height, int depth)
{
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
GraphicsDevice.ThrowIfDeviceLost();
@@ -299,8 +284,8 @@ public unsafe abstract class Texture3D<T> : ReferenceTracker.ITrackedObject, IDi
internal void CopyTo(Texture3D<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
{
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (this.referenceTracker.GetLease())
using (destination.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
using (destination.GetReferenceTracker().GetLease())
{
GraphicsDevice.ThrowIfDeviceLost();
@@ -378,7 +363,7 @@ public unsafe abstract class Texture3D<T> : ReferenceTracker.ITrackedObject, IDi
internal void CopyTo(ReadBackTexture3D<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
{
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
using (destination.GetReferenceTracker().GetLease())
{
GraphicsDevice.ThrowIfDeviceLost();
@@ -451,7 +436,7 @@ public unsafe abstract class Texture3D<T> : ReferenceTracker.ITrackedObject, IDi
internal void CopyFrom(ref T source, int size, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
{
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
GraphicsDevice.ThrowIfDeviceLost();
@@ -549,7 +534,7 @@ public unsafe abstract class Texture3D<T> : ReferenceTracker.ITrackedObject, IDi
internal void CopyFrom(UploadTexture3D<T> source, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
{
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
using (source.GetReferenceTracker().GetLease())
{
GraphicsDevice.ThrowIfDeviceLost();
@@ -609,28 +594,7 @@ public unsafe abstract class Texture3D<T> : ReferenceTracker.ITrackedObject, IDi
}
/// <inheritdoc/>
public virtual void Dispose()
{
this.referenceTracker.Dispose();
GC.SuppressFinalize(this);
}
/// <inheritdoc cref="ReferenceTracker.ITrackedObject.GetReferenceTracker"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal ref ReferenceTracker GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
ref ReferenceTracker ReferenceTracker.ITrackedObject.GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
void ReferenceTracker.ITrackedObject.DangerousRelease()
private protected override void OnDispose()
{
this.d3D12Resource.Dispose();
#if NET6_0_OR_GREATER
@@ -678,7 +642,7 @@ public unsafe abstract class Texture3D<T> : ReferenceTracker.ITrackedObject, IDi
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice, out bool)"/>
internal (D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
@@ -691,7 +655,7 @@ public unsafe abstract class Texture3D<T> : ReferenceTracker.ITrackedObject, IDi
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice)"/>
internal ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
@@ -702,7 +666,7 @@ public unsafe abstract class Texture3D<T> : ReferenceTracker.ITrackedObject, IDi
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice, ResourceState, out ID3D12Resource*)"/>
internal (D3D12_RESOURCE_STATES Before, D3D12_RESOURCE_STATES After) ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
@@ -720,7 +684,7 @@ public unsafe abstract class Texture3D<T> : ReferenceTracker.ITrackedObject, IDi
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
+5 -41
ファイルの表示
@@ -15,14 +15,9 @@ namespace ComputeSharp.Resources;
/// A <see langword="class"/> representing a typed buffer stored on CPU memory, that can be used to transfer data to/from the GPU.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
public abstract unsafe class TransferBuffer<T> : ReferenceTracker.ITrackedObject, IGraphicsResource, IMemoryOwner<T>
public abstract unsafe class TransferBuffer<T> : NativeObject, IGraphicsResource, IMemoryOwner<T>
where T : unmanaged
{
/// <summary>
/// The owning <see cref="ReferenceTracker"/> object for the current instance.
/// </summary>
private ReferenceTracker referenceTracker;
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
@@ -49,8 +44,6 @@ public abstract unsafe class TransferBuffer<T> : ReferenceTracker.ITrackedObject
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
private protected TransferBuffer(GraphicsDevice device, int length, ResourceType resourceType, AllocationMode allocationMode)
{
this.referenceTracker = new ReferenceTracker(this);
using (device.GetReferenceTracker().GetLease())
{
device.ThrowIfDeviceLost();
@@ -78,14 +71,6 @@ public abstract unsafe class TransferBuffer<T> : ReferenceTracker.ITrackedObject
}
}
/// <summary>
/// Releases unmanaged resources for the current <see cref="TransferBuffer{T}"/> instance.
/// </summary>
~TransferBuffer()
{
this.referenceTracker.Dispose();
}
/// <inheritdoc/>
public GraphicsDevice GraphicsDevice { get; }
@@ -110,7 +95,7 @@ public abstract unsafe class TransferBuffer<T> : ReferenceTracker.ITrackedObject
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
return new MemoryManager(this).Memory;
}
@@ -123,7 +108,7 @@ public abstract unsafe class TransferBuffer<T> : ReferenceTracker.ITrackedObject
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
{
return new(this.mappedData, Length);
}
@@ -131,28 +116,7 @@ public abstract unsafe class TransferBuffer<T> : ReferenceTracker.ITrackedObject
}
/// <inheritdoc/>
public void Dispose()
{
this.referenceTracker.Dispose();
GC.SuppressFinalize(this);
}
/// <inheritdoc cref="ReferenceTracker.ITrackedObject.GetReferenceTracker"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal ref ReferenceTracker GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
ref ReferenceTracker ReferenceTracker.ITrackedObject.GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
void ReferenceTracker.ITrackedObject.DangerousRelease()
private protected sealed override void OnDispose()
{
this.d3D12Resource.Dispose();
#if NET6_0_OR_GREATER
@@ -211,7 +175,7 @@ public abstract unsafe class TransferBuffer<T> : ReferenceTracker.ITrackedObject
/// <inheritdoc/>
public override MemoryHandle Pin(int elementIndex = 0)
{
using (this.buffer.referenceTracker.GetLease())
using (this.buffer.GetReferenceTracker().GetLease())
{
Guard.IsEqualTo(elementIndex, 0);
+4 -41
ファイルの表示
@@ -1,5 +1,4 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using CommunityToolkit.Diagnostics;
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Extensions;
@@ -16,14 +15,9 @@ namespace ComputeSharp.Resources;
/// A <see langword="class"/> representing a typed 2D texture stored on on CPU memory, that can be used to transfer data to/from the GPU.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
public unsafe abstract class TransferTexture2D<T> : ReferenceTracker.ITrackedObject, IDisposable, IGraphicsResource
public unsafe abstract class TransferTexture2D<T> : NativeObject, IGraphicsResource
where T : unmanaged
{
/// <summary>
/// The owning <see cref="ReferenceTracker"/> object for the current instance.
/// </summary>
private ReferenceTracker referenceTracker;
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
@@ -56,8 +50,6 @@ public unsafe abstract class TransferTexture2D<T> : ReferenceTracker.ITrackedObj
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
private protected TransferTexture2D(GraphicsDevice device, int width, int height, ResourceType resourceType, AllocationMode allocationMode)
{
this.referenceTracker = new ReferenceTracker(this);
using (device.GetReferenceTracker().GetLease())
{
device.ThrowIfDeviceLost();
@@ -95,14 +87,6 @@ public unsafe abstract class TransferTexture2D<T> : ReferenceTracker.ITrackedObj
}
}
/// <summary>
/// Releases unmanaged resources for the current <see cref="TransferTexture2D{T}"/> instance.
/// </summary>
~TransferTexture2D()
{
this.referenceTracker.Dispose();
}
/// <inheritdoc/>
public GraphicsDevice GraphicsDevice { get; }
@@ -132,7 +116,7 @@ public unsafe abstract class TransferTexture2D<T> : ReferenceTracker.ITrackedObj
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
using (this.referenceTracker.GetLease())
using (this.GetReferenceTracker().GetLease())
{
return new(this.mappedData, Width, Height, (int)this.d3D12PlacedSubresourceFootprint.Footprint.RowPitch);
}
@@ -140,28 +124,7 @@ public unsafe abstract class TransferTexture2D<T> : ReferenceTracker.ITrackedObj
}
/// <inheritdoc/>
public void Dispose()
{
this.referenceTracker.Dispose();
GC.SuppressFinalize(this);
}
/// <inheritdoc cref="ReferenceTracker.ITrackedObject.GetReferenceTracker"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal ref ReferenceTracker GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
ref ReferenceTracker ReferenceTracker.ITrackedObject.GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
void ReferenceTracker.ITrackedObject.DangerousRelease()
private protected sealed override void OnDispose()
{
this.d3D12Resource.Dispose();
#if NET6_0_OR_GREATER
+4 -41
ファイルの表示
@@ -1,5 +1,4 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using CommunityToolkit.Diagnostics;
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Extensions;
@@ -16,14 +15,9 @@ namespace ComputeSharp.Resources;
/// A <see langword="class"/> representing a typed 3D texture stored on on CPU memory, that can be used to transfer data to/from the GPU.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
public unsafe abstract class TransferTexture3D<T> : ReferenceTracker.ITrackedObject, IDisposable, IGraphicsResource
public unsafe abstract class TransferTexture3D<T> : NativeObject, IGraphicsResource
where T : unmanaged
{
/// <summary>
/// The owning <see cref="ReferenceTracker"/> object for the current instance.
/// </summary>
private ReferenceTracker referenceTracker;
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="D3D12MA_Allocation"/> instance used to retrieve <see cref="d3D12Resource"/>.
@@ -57,8 +51,6 @@ public unsafe abstract class TransferTexture3D<T> : ReferenceTracker.ITrackedObj
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
private protected TransferTexture3D(GraphicsDevice device, int width, int height, int depth, ResourceType resourceType, AllocationMode allocationMode)
{
this.referenceTracker = new ReferenceTracker(this);
using (device.GetReferenceTracker().GetLease())
{
device.ThrowIfDeviceLost();
@@ -98,14 +90,6 @@ public unsafe abstract class TransferTexture3D<T> : ReferenceTracker.ITrackedObj
}
}
/// <summary>
/// Releases unmanaged resources for the current <see cref="TransferTexture3D{T}"/> instance.
/// </summary>
~TransferTexture3D()
{
this.referenceTracker.Dispose();
}
/// <inheritdoc/>
public GraphicsDevice GraphicsDevice { get; }
@@ -140,7 +124,7 @@ public unsafe abstract class TransferTexture3D<T> : ReferenceTracker.ITrackedObj
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
using (this.referenceTracker.GetLease())
using (this.GetReferenceTracker().GetLease())
{
return new(this.mappedData, Width, Height, Depth, (int)this.d3D12PlacedSubresourceFootprint.Footprint.RowPitch);
}
@@ -148,28 +132,7 @@ public unsafe abstract class TransferTexture3D<T> : ReferenceTracker.ITrackedObj
}
/// <inheritdoc/>
public void Dispose()
{
this.referenceTracker.Dispose();
GC.SuppressFinalize(this);
}
/// <inheritdoc cref="ReferenceTracker.ITrackedObject.GetReferenceTracker"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal ref ReferenceTracker GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
ref ReferenceTracker ReferenceTracker.ITrackedObject.GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
void ReferenceTracker.ITrackedObject.DangerousRelease()
private protected sealed override void OnDispose()
{
this.d3D12Resource.Dispose();
#if NET6_0_OR_GREATER
+6 -26
ファイルの表示
@@ -49,9 +49,9 @@ partial class ReadWriteTexture2D<T, TPixel>
}
/// <inheritdoc/>
public override void Dispose()
private protected override void OnDispose()
{
base.Dispose();
base.OnDispose();
this.readOnlyWrapper?.Dispose();
}
@@ -59,13 +59,8 @@ partial class ReadWriteTexture2D<T, TPixel>
/// <summary>
/// A wrapper for a <see cref="ReadWriteTexture2D{T, TPixel}"/> resource that has been temporarily transitioned to readonly.
/// </summary>
private sealed unsafe class ReadOnly : ReferenceTracker.ITrackedObject, IDisposable, IReadOnlyNormalizedTexture2D<TPixel>, GraphicsResourceHelper.IGraphicsResource
private sealed unsafe class ReadOnly : NativeObject, IReadOnlyNormalizedTexture2D<TPixel>, GraphicsResourceHelper.IGraphicsResource
{
/// <summary>
/// The owning <see cref="ReferenceTracker"/> object for the current instance.
/// </summary>
private ReferenceTracker referenceTracker;
/// <summary>
/// The owning <see cref="ReadWriteTexture2D{T, TPixel}"/> instance being wrapped.
/// </summary>
@@ -82,7 +77,6 @@ partial class ReadWriteTexture2D<T, TPixel>
/// <param name="owner">The owning <see cref="ReadWriteTexture2D{T, TPixel}"/> instance to wrap.</param>
public ReadOnly(ReadWriteTexture2D<T, TPixel> owner)
{
this.referenceTracker = new ReferenceTracker(this);
this.owner = owner;
owner.GraphicsDevice.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandles);
@@ -114,7 +108,7 @@ partial class ReadWriteTexture2D<T, TPixel>
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
using (this.owner.GetReferenceTracker().GetLease())
{
this.owner.ThrowIfDeviceMismatch(device);
@@ -132,7 +126,7 @@ partial class ReadWriteTexture2D<T, TPixel>
/// <inheritdoc/>
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
using (this.owner.GetReferenceTracker().GetLease())
{
this.owner.ThrowIfDeviceMismatch(device);
@@ -148,21 +142,7 @@ partial class ReadWriteTexture2D<T, TPixel>
}
/// <inheritdoc/>
public void Dispose()
{
this.referenceTracker.Dispose();
GC.SuppressFinalize(this);
}
/// <inheritdoc/>
ref ReferenceTracker ReferenceTracker.ITrackedObject.GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
void ReferenceTracker.ITrackedObject.DangerousRelease()
private protected override void OnDispose()
{
if (this.owner.GraphicsDevice is GraphicsDevice device)
{
+6 -26
ファイルの表示
@@ -52,9 +52,9 @@ partial class ReadWriteTexture2D<T>
}
/// <inheritdoc/>
public override void Dispose()
private protected override void OnDispose()
{
base.Dispose();
base.OnDispose();
this.readOnlyWrapper?.Dispose();
}
@@ -62,13 +62,8 @@ partial class ReadWriteTexture2D<T>
/// <summary>
/// A wrapper for a <see cref="ReadWriteTexture2D{T}"/> resource that has been temporarily transitioned to readonly.
/// </summary>
private sealed unsafe class ReadOnly : ReferenceTracker.ITrackedObject, IDisposable, IReadOnlyTexture2D<T>, GraphicsResourceHelper.IGraphicsResource
private sealed unsafe class ReadOnly : NativeObject, IReadOnlyTexture2D<T>, GraphicsResourceHelper.IGraphicsResource
{
/// <summary>
/// The owning <see cref="ReferenceTracker"/> object for the current instance.
/// </summary>
private ReferenceTracker referenceTracker;
/// <summary>
/// The owning <see cref="ReadWriteTexture2D{T}"/> instance being wrapped.
/// </summary>
@@ -85,7 +80,6 @@ partial class ReadWriteTexture2D<T>
/// <param name="owner">The owning <see cref="ReadWriteTexture2D{T}"/> instance to wrap.</param>
public ReadOnly(ReadWriteTexture2D<T> owner)
{
this.referenceTracker = new ReferenceTracker(this);
this.owner = owner;
owner.GraphicsDevice.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandles);
@@ -117,7 +111,7 @@ partial class ReadWriteTexture2D<T>
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
using (this.owner.GetReferenceTracker().GetLease())
{
this.owner.ThrowIfDeviceMismatch(device);
@@ -135,7 +129,7 @@ partial class ReadWriteTexture2D<T>
/// <inheritdoc/>
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
using (this.owner.GetReferenceTracker().GetLease())
{
this.owner.ThrowIfDeviceMismatch(device);
@@ -151,21 +145,7 @@ partial class ReadWriteTexture2D<T>
}
/// <inheritdoc/>
public void Dispose()
{
this.referenceTracker.Dispose();
GC.SuppressFinalize(this);
}
/// <inheritdoc/>
ref ReferenceTracker ReferenceTracker.ITrackedObject.GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
void ReferenceTracker.ITrackedObject.DangerousRelease()
private protected override void OnDispose()
{
if (this.owner.GraphicsDevice is GraphicsDevice device)
{
+6 -26
ファイルの表示
@@ -49,9 +49,9 @@ partial class ReadWriteTexture3D<T, TPixel>
}
/// <inheritdoc/>
public override void Dispose()
private protected override void OnDispose()
{
base.Dispose();
base.OnDispose();
this.readOnlyWrapper?.Dispose();
}
@@ -59,13 +59,8 @@ partial class ReadWriteTexture3D<T, TPixel>
/// <summary>
/// A wrapper for a <see cref="ReadWriteTexture3D{T, TPixel}"/> resource that has been temporarily transitioned to readonly.
/// </summary>
private sealed unsafe class ReadOnly : ReferenceTracker.ITrackedObject, IDisposable, IReadOnlyNormalizedTexture3D<TPixel>, GraphicsResourceHelper.IGraphicsResource
private sealed unsafe class ReadOnly : NativeObject, IReadOnlyNormalizedTexture3D<TPixel>, GraphicsResourceHelper.IGraphicsResource
{
/// <summary>
/// The owning <see cref="ReferenceTracker"/> object for the current instance.
/// </summary>
private ReferenceTracker referenceTracker;
/// <summary>
/// The owning <see cref="ReadWriteTexture3D{T, TPixel}"/> instance being wrapped.
/// </summary>
@@ -82,7 +77,6 @@ partial class ReadWriteTexture3D<T, TPixel>
/// <param name="owner">The owning <see cref="ReadWriteTexture3D{T, TPixel}"/> instance to wrap.</param>
public ReadOnly(ReadWriteTexture3D<T, TPixel> owner)
{
this.referenceTracker = new ReferenceTracker(this);
this.owner = owner;
owner.GraphicsDevice.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandles);
@@ -117,7 +111,7 @@ partial class ReadWriteTexture3D<T, TPixel>
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
using (this.owner.GetReferenceTracker().GetLease())
{
this.owner.ThrowIfDeviceMismatch(device);
@@ -135,7 +129,7 @@ partial class ReadWriteTexture3D<T, TPixel>
/// <inheritdoc/>
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
using (this.owner.GetReferenceTracker().GetLease())
{
this.owner.ThrowIfDeviceMismatch(device);
@@ -151,21 +145,7 @@ partial class ReadWriteTexture3D<T, TPixel>
}
/// <inheritdoc/>
public void Dispose()
{
this.referenceTracker.Dispose();
GC.SuppressFinalize(this);
}
/// <inheritdoc/>
ref ReferenceTracker ReferenceTracker.ITrackedObject.GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
void ReferenceTracker.ITrackedObject.DangerousRelease()
private protected override void OnDispose()
{
if (this.owner.GraphicsDevice is GraphicsDevice device)
{
+6 -26
ファイルの表示
@@ -49,9 +49,9 @@ partial class ReadWriteTexture3D<T>
}
/// <inheritdoc/>
public override void Dispose()
private protected override void OnDispose()
{
base.Dispose();
base.OnDispose();
this.readOnlyWrapper?.Dispose();
}
@@ -59,13 +59,8 @@ partial class ReadWriteTexture3D<T>
/// <summary>
/// A wrapper for a <see cref="ReadWriteTexture3D{T}"/> resource that has been temporarily transitioned to readonly.
/// </summary>
private sealed unsafe class ReadOnly : ReferenceTracker.ITrackedObject, IDisposable, IReadOnlyTexture3D<T>, GraphicsResourceHelper.IGraphicsResource
private sealed unsafe class ReadOnly : NativeObject, IReadOnlyTexture3D<T>, GraphicsResourceHelper.IGraphicsResource
{
/// <summary>
/// The owning <see cref="ReferenceTracker"/> object for the current instance.
/// </summary>
private ReferenceTracker referenceTracker;
/// <summary>
/// The owning <see cref="ReadWriteTexture3D{T}"/> instance being wrapped.
/// </summary>
@@ -82,7 +77,6 @@ partial class ReadWriteTexture3D<T>
/// <param name="owner">The owning <see cref="ReadWriteTexture3D{T}"/> instance to wrap.</param>
public ReadOnly(ReadWriteTexture3D<T> owner)
{
this.referenceTracker = new ReferenceTracker(this);
this.owner = owner;
owner.GraphicsDevice.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandles);
@@ -117,7 +111,7 @@ partial class ReadWriteTexture3D<T>
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
using (this.owner.GetReferenceTracker().GetLease())
{
this.owner.ThrowIfDeviceMismatch(device);
@@ -135,7 +129,7 @@ partial class ReadWriteTexture3D<T>
/// <inheritdoc/>
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device)
{
using (this.referenceTracker.GetLease())
using (GetReferenceTracker().GetLease())
using (this.owner.GetReferenceTracker().GetLease())
{
this.owner.ThrowIfDeviceMismatch(device);
@@ -151,21 +145,7 @@ partial class ReadWriteTexture3D<T>
}
/// <inheritdoc/>
public void Dispose()
{
this.referenceTracker.Dispose();
GC.SuppressFinalize(this);
}
/// <inheritdoc/>
ref ReferenceTracker ReferenceTracker.ITrackedObject.GetReferenceTracker()
{
return ref this.referenceTracker;
}
/// <inheritdoc/>
void ReferenceTracker.ITrackedObject.DangerousRelease()
private protected override void OnDispose()
{
if (this.owner.GraphicsDevice is GraphicsDevice device)
{
+1 -1
ファイルの表示
@@ -86,7 +86,7 @@ internal interface ICachedShader
public D3D12_SHADER_BYTECODE D3D12ShaderBytecode => new ((ID3DBlob*)this.dxcBlobBytecode.Get());
/// <inheritdoc/>
protected override void OnDispose()
private protected override void OnDispose()
{
this.dxcBlobBytecode.Dispose();
}
+1 -1
ファイルの表示
@@ -41,7 +41,7 @@ internal sealed unsafe class PipelineData : NativeObject
public ID3D12PipelineState* D3D12PipelineState => this.d3D12PipelineState;
/// <inheritdoc/>
protected override void OnDispose()
private protected override void OnDispose()
{
this.d3D12RootSignature.Dispose();
this.d3D12PipelineState.Dispose();