Add device lost validation to public APIs
このコミットが含まれているのは:
1 親
041956b854
コミット
8a9368506b
15ファイル変更
+56
検索条件に一致するファイルはありません
@@ -151,6 +151,7 @@ public static partial class GraphicsDeviceExtensions
|
||||
Guard.IsNotNull(device);
|
||||
|
||||
device.ThrowIfDisposed();
|
||||
device.ThrowIfDeviceLost();
|
||||
|
||||
return new(device);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,28 @@ unsafe partial class GraphicsDevice
|
||||
private static readonly WaitForSingleObjectCallbackDelegate WaitForSingleObjectCallbackForRegisterDeviceLostCallbackWrapper = WaitForSingleObjectCallbackForWaitForFenceAsync;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="InvalidOperationException"/> if the current device has been lost.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">Thrown if the current device has been lost.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void ThrowIfDeviceLost()
|
||||
{
|
||||
// This method is called as a check before performing any operations. In order to minimize overhead,
|
||||
// the GetDeviceRemovedReason() method is not called here, and the local field is just used instead.
|
||||
// That field is set by the device lost callback anyway, and the extra precision of calling the API
|
||||
// explicitly is not needed since there are no thread safety guarantees in this scenario anyway.
|
||||
// That is, the check isn't meant to cover 100% of cases, as a device might be lost right after this
|
||||
// check is performed anyway. This check is only meant to catch the common scenarios to help users.
|
||||
// For the same reason, this method doesn't have to worry about raising the event either.
|
||||
if (Volatile.Read(ref Unsafe.As<HRESULT, int>(ref this.deviceRemovedReason)) != S.S_OK)
|
||||
{
|
||||
static void Throw(object self) => throw new InvalidOperationException($"The device \"{self}\" has been lost and can no longer be used.");
|
||||
|
||||
Throw(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="DeviceLost"/> event if needed.
|
||||
/// </summary>
|
||||
|
||||
@@ -234,6 +234,7 @@ public sealed unsafe partial class GraphicsDevice : NativeObject
|
||||
public bool IsDoublePrecisionSupportAvailable()
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
ThrowIfDeviceLost();
|
||||
|
||||
var d3D12OptionsData = this.d3D12Device.Get()->CheckFeatureSupport<D3D12_FEATURE_DATA_D3D12_OPTIONS>(D3D12_FEATURE_D3D12_OPTIONS);
|
||||
|
||||
@@ -250,6 +251,7 @@ public sealed unsafe partial class GraphicsDevice : NativeObject
|
||||
where T : unmanaged
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
ThrowIfDeviceLost();
|
||||
|
||||
return this.d3D12Device.Get()->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE2D);
|
||||
}
|
||||
@@ -264,6 +266,7 @@ public sealed unsafe partial class GraphicsDevice : NativeObject
|
||||
where T : unmanaged
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
ThrowIfDeviceLost();
|
||||
|
||||
return this.d3D12Device.Get()->IsDxgiFormatSupported(
|
||||
DXGIFormatHelper.GetForType<T>(),
|
||||
@@ -280,6 +283,7 @@ public sealed unsafe partial class GraphicsDevice : NativeObject
|
||||
where T : unmanaged
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
ThrowIfDeviceLost();
|
||||
|
||||
return this.d3D12Device.Get()->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE3D);
|
||||
}
|
||||
@@ -294,6 +298,7 @@ public sealed unsafe partial class GraphicsDevice : NativeObject
|
||||
where T : unmanaged
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
ThrowIfDeviceLost();
|
||||
|
||||
return this.d3D12Device.Get()->IsDxgiFormatSupported(
|
||||
DXGIFormatHelper.GetForType<T>(),
|
||||
|
||||
@@ -65,6 +65,7 @@ public unsafe abstract class Buffer<T> : NativeObject, IGraphicsResource
|
||||
private protected Buffer(GraphicsDevice device, int length, uint elementSizeInBytes, ResourceType resourceType, AllocationMode allocationMode)
|
||||
{
|
||||
device.ThrowIfDisposed();
|
||||
device.ThrowIfDeviceLost();
|
||||
|
||||
if (resourceType == ResourceType.Constant)
|
||||
{
|
||||
|
||||
@@ -33,6 +33,7 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
internal override unsafe void CopyTo(ref T destination, int sourceOffset, int count)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
@@ -104,6 +105,7 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
internal override unsafe void CopyTo(Buffer<T> destination, int sourceOffset, int destinationOffset, int count)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
@@ -148,6 +150,7 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
internal unsafe void CopyTo(ReadBackBuffer<T> destination, int sourceOffset, int destinationOffset, int count)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
@@ -191,6 +194,7 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
internal override unsafe void CopyFrom(ref T source, int offset, int length)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
@@ -266,6 +270,7 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
internal unsafe void CopyFrom(UploadBuffer<T> source, int sourceOffset, int destinationOffset, int count)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
|
||||
private protected Texture2D(GraphicsDevice device, int width, int height, ResourceType resourceType, AllocationMode allocationMode, D3D12_FORMAT_SUPPORT1 d3D12FormatSupport)
|
||||
{
|
||||
device.ThrowIfDisposed();
|
||||
device.ThrowIfDeviceLost();
|
||||
|
||||
Guard.IsBetweenOrEqualTo(width, 1, D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION);
|
||||
@@ -169,6 +170,7 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
|
||||
internal void CopyTo(ref T destination, int size, int sourceOffsetX, int sourceOffsetY, int width, int height)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
@@ -258,6 +260,7 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
|
||||
internal void CopyTo(Texture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
@@ -326,6 +329,7 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
|
||||
internal void CopyTo(ReadBackTexture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
@@ -389,6 +393,7 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
|
||||
internal void CopyFrom(ref T source, int size, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
@@ -476,6 +481,7 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
|
||||
internal void CopyFrom(UploadTexture2D<T> source, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
|
||||
private protected Texture3D(GraphicsDevice device, int width, int height, int depth, ResourceType resourceType, AllocationMode allocationMode, D3D12_FORMAT_SUPPORT1 d3D12FormatSupport)
|
||||
{
|
||||
device.ThrowIfDisposed();
|
||||
device.ThrowIfDeviceLost();
|
||||
|
||||
Guard.IsBetweenOrEqualTo(width, 1, D3D12.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, D3D12.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION);
|
||||
@@ -181,6 +182,7 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
|
||||
internal void CopyTo(ref T destination, int size, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int width, int height, int depth)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
@@ -279,6 +281,7 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
|
||||
internal void CopyTo(Texture3D<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
@@ -356,6 +359,7 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
|
||||
internal void CopyTo(ReadBackTexture3D<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
@@ -427,6 +431,7 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
|
||||
internal void CopyFrom(ref T source, int size, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
@@ -523,6 +528,7 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
|
||||
internal void CopyFrom(UploadTexture3D<T> source, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ public abstract unsafe class TransferBuffer<T> : NativeObject, IGraphicsResource
|
||||
private protected TransferBuffer(GraphicsDevice device, int length, ResourceType resourceType, AllocationMode allocationMode)
|
||||
{
|
||||
device.ThrowIfDisposed();
|
||||
device.ThrowIfDeviceLost();
|
||||
|
||||
// The maximum length is set such that the aligned buffer size can't exceed uint.MaxValue
|
||||
Guard.IsBetweenOrEqualTo(length, 1, (uint.MaxValue / (uint)sizeof(T)) & ~255);
|
||||
|
||||
@@ -51,6 +51,7 @@ public unsafe abstract class TransferTexture2D<T> : NativeObject, IGraphicsResou
|
||||
private protected TransferTexture2D(GraphicsDevice device, int width, int height, ResourceType resourceType, AllocationMode allocationMode)
|
||||
{
|
||||
device.ThrowIfDisposed();
|
||||
device.ThrowIfDeviceLost();
|
||||
|
||||
Guard.IsBetweenOrEqualTo(width, 1, D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION);
|
||||
|
||||
@@ -52,6 +52,7 @@ public unsafe abstract class TransferTexture3D<T> : NativeObject, IGraphicsResou
|
||||
private protected TransferTexture3D(GraphicsDevice device, int width, int height, int depth, ResourceType resourceType, AllocationMode allocationMode)
|
||||
{
|
||||
device.ThrowIfDisposed();
|
||||
device.ThrowIfDeviceLost();
|
||||
|
||||
Guard.IsBetweenOrEqualTo(width, 1, D3D12.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, D3D12.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION);
|
||||
|
||||
@@ -58,6 +58,7 @@ public sealed class ConstantBuffer<T> : Buffer<T>
|
||||
internal override unsafe void CopyTo(ref T destination, int offset, int length)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
@@ -84,6 +85,7 @@ public sealed class ConstantBuffer<T> : Buffer<T>
|
||||
internal override unsafe void CopyTo(Buffer<T> destination, int sourceOffset, int destinationOffset, int length)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
@@ -118,6 +120,7 @@ public sealed class ConstantBuffer<T> : Buffer<T>
|
||||
internal override unsafe void CopyFrom(ref T source, int offset, int length)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ partial class ReadWriteTexture2D<T, TPixel>
|
||||
internal IReadOnlyNormalizedTexture2D<TPixel> AsReadOnly()
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
ThrowIfIsNotInReadOnlyState();
|
||||
|
||||
@@ -25,6 +25,7 @@ partial class ReadWriteTexture2D<T>
|
||||
public IReadOnlyTexture2D<T> AsReadOnly()
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
ThrowIfIsNotInReadOnlyState();
|
||||
|
||||
@@ -25,6 +25,7 @@ partial class ReadWriteTexture3D<T, TPixel>
|
||||
public IReadOnlyNormalizedTexture3D<TPixel> AsReadOnly()
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
ThrowIfIsNotInReadOnlyState();
|
||||
|
||||
@@ -25,6 +25,7 @@ partial class ReadWriteTexture3D<T>
|
||||
public IReadOnlyTexture3D<T> AsReadOnly()
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
ThrowIfDisposed();
|
||||
ThrowIfIsNotInReadOnlyState();
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする