Move all Guard checks at the start of each method
このコミットが含まれているのは:
1 親
149a03d92b
コミット
5100ab471a
9ファイル変更
+224
-226
検索条件に一致するファイルはありません
@@ -27,27 +27,25 @@ 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)
|
||||
{
|
||||
Guard.IsNotNull(shaderRunner);
|
||||
|
||||
using (GetReferenceTracker().GetLease())
|
||||
using (await this.setupSemaphore.LockAsync())
|
||||
{
|
||||
Guard.IsNotNull(shaderRunner);
|
||||
this.renderCancellationTokenSource?.Cancel();
|
||||
|
||||
using (await this.setupSemaphore.LockAsync())
|
||||
{
|
||||
this.renderCancellationTokenSource?.Cancel();
|
||||
await this.renderSemaphore.WaitAsync();
|
||||
|
||||
await this.renderSemaphore.WaitAsync();
|
||||
Thread newRenderThread = new(static args => ((SwapChainManager<TOwner>)args!).SwitchAndStartRenderLoop());
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
newRenderThread.Start(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,20 +65,20 @@ public unsafe abstract class Buffer<T> : NativeObject, IGraphicsResource
|
||||
/// <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)
|
||||
{
|
||||
if (resourceType == ResourceType.Constant)
|
||||
{
|
||||
Guard.IsBetweenOrEqualTo(length, 1, D3D12.D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The maximum length is set such that the aligned buffer size can't exceed uint.MaxValue
|
||||
Guard.IsBetweenOrEqualTo(length, 1, (uint.MaxValue / elementSizeInBytes) & ~255);
|
||||
}
|
||||
|
||||
using (device.GetReferenceTracker().GetLease())
|
||||
{
|
||||
device.ThrowIfDeviceLost();
|
||||
|
||||
if (resourceType == ResourceType.Constant)
|
||||
{
|
||||
Guard.IsBetweenOrEqualTo(length, 1, D3D12.D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The maximum length is set such that the aligned buffer size can't exceed uint.MaxValue
|
||||
Guard.IsBetweenOrEqualTo(length, 1, (uint.MaxValue / elementSizeInBytes) & ~255);
|
||||
}
|
||||
|
||||
if (TypeInfo<T>.IsDoubleOrContainsDoubles &&
|
||||
device.D3D12Device->CheckFeatureSupport<D3D12_FEATURE_DATA_D3D12_OPTIONS>(D3D12_FEATURE_D3D12_OPTIONS).DoublePrecisionFloatShaderOps == 0)
|
||||
{
|
||||
|
||||
@@ -32,15 +32,15 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
/// <inheritdoc/>
|
||||
internal override unsafe void CopyTo(ref T destination, int sourceOffset, int count)
|
||||
{
|
||||
Guard.IsBetweenOrEqualTo(count, 0, Length);
|
||||
Guard.IsInRange(sourceOffset, 0, Length);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffset + count, Length, nameof(sourceOffset));
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
{
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
Guard.IsBetweenOrEqualTo(count, 0, Length);
|
||||
Guard.IsInRange(sourceOffset, 0, Length);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffset + count, Length, nameof(sourceOffset));
|
||||
|
||||
if (GraphicsDevice.IsCacheCoherentUMA)
|
||||
{
|
||||
using ID3D12ResourceMap resource = D3D12Resource->Map();
|
||||
@@ -105,6 +105,13 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
/// <inheritdoc/>
|
||||
internal override unsafe void CopyTo(Buffer<T> destination, int sourceOffset, int destinationOffset, int count)
|
||||
{
|
||||
Guard.IsBetweenOrEqualTo(count, 0, Length);
|
||||
Guard.IsBetweenOrEqualTo(count, 0, destination.Length);
|
||||
Guard.IsInRange(sourceOffset, 0, Length);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffset + count, Length, nameof(sourceOffset));
|
||||
Guard.IsInRange(destinationOffset, 0, destination.Length);
|
||||
Guard.IsLessThanOrEqualTo(destinationOffset + count, destination.Length, nameof(destinationOffset));
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
using (destination.GetReferenceTracker().GetLease())
|
||||
@@ -113,13 +120,6 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
|
||||
destination.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
|
||||
Guard.IsBetweenOrEqualTo(count, 0, Length);
|
||||
Guard.IsBetweenOrEqualTo(count, 0, destination.Length);
|
||||
Guard.IsInRange(sourceOffset, 0, Length);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffset + count, Length, nameof(sourceOffset));
|
||||
Guard.IsInRange(destinationOffset, 0, destination.Length);
|
||||
Guard.IsLessThanOrEqualTo(destinationOffset + count, destination.Length, nameof(destinationOffset));
|
||||
|
||||
if (!destination.IsPaddingPresent)
|
||||
{
|
||||
nint sourceByteOffset = (nint)sourceOffset * sizeof(T);
|
||||
@@ -151,6 +151,13 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
/// <param name="count">The number of items to read.</param>
|
||||
internal unsafe void CopyTo(ReadBackBuffer<T> destination, int sourceOffset, int destinationOffset, int count)
|
||||
{
|
||||
Guard.IsBetweenOrEqualTo(count, 0, Length);
|
||||
Guard.IsBetweenOrEqualTo(count, 0, destination.Length);
|
||||
Guard.IsInRange(sourceOffset, 0, Length);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffset + count, Length, nameof(sourceOffset));
|
||||
Guard.IsInRange(destinationOffset, 0, destination.Length);
|
||||
Guard.IsLessThanOrEqualTo(destinationOffset + count, destination.Length, nameof(destinationOffset));
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
using (destination.GetReferenceTracker().GetLease())
|
||||
@@ -159,13 +166,6 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
|
||||
destination.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
|
||||
Guard.IsBetweenOrEqualTo(count, 0, Length);
|
||||
Guard.IsBetweenOrEqualTo(count, 0, destination.Length);
|
||||
Guard.IsInRange(sourceOffset, 0, Length);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffset + count, Length, nameof(sourceOffset));
|
||||
Guard.IsInRange(destinationOffset, 0, destination.Length);
|
||||
Guard.IsLessThanOrEqualTo(destinationOffset + count, destination.Length, nameof(destinationOffset));
|
||||
|
||||
if (GraphicsDevice.IsCacheCoherentUMA)
|
||||
{
|
||||
using ID3D12ResourceMap resource = D3D12Resource->Map();
|
||||
@@ -196,15 +196,15 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
/// <inheritdoc/>
|
||||
internal override unsafe void CopyFrom(ref T source, int offset, int length)
|
||||
{
|
||||
Guard.IsBetweenOrEqualTo(length, 0, Length);
|
||||
Guard.IsInRange(offset, 0, Length);
|
||||
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(offset));
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
{
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
Guard.IsBetweenOrEqualTo(length, 0, Length);
|
||||
Guard.IsInRange(offset, 0, Length);
|
||||
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(offset));
|
||||
|
||||
if (GraphicsDevice.IsCacheCoherentUMA)
|
||||
{
|
||||
using ID3D12ResourceMap resource = D3D12Resource->Map();
|
||||
@@ -273,6 +273,13 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
/// <param name="count">The number of items to read.</param>
|
||||
internal unsafe void CopyFrom(UploadBuffer<T> source, int sourceOffset, int destinationOffset, int count)
|
||||
{
|
||||
Guard.IsBetweenOrEqualTo(count, 0, Length);
|
||||
Guard.IsBetweenOrEqualTo(count, 0, source.Length);
|
||||
Guard.IsInRange(sourceOffset, 0, source.Length);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffset + count, source.Length, nameof(sourceOffset));
|
||||
Guard.IsInRange(destinationOffset, 0, Length);
|
||||
Guard.IsLessThanOrEqualTo(destinationOffset + count, Length, nameof(destinationOffset));
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
using (source.GetReferenceTracker().GetLease())
|
||||
@@ -281,13 +288,6 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
|
||||
source.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
|
||||
Guard.IsBetweenOrEqualTo(count, 0, Length);
|
||||
Guard.IsBetweenOrEqualTo(count, 0, source.Length);
|
||||
Guard.IsInRange(sourceOffset, 0, source.Length);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffset + count, source.Length, nameof(sourceOffset));
|
||||
Guard.IsInRange(destinationOffset, 0, Length);
|
||||
Guard.IsLessThanOrEqualTo(destinationOffset + count, Length, nameof(destinationOffset));
|
||||
|
||||
if (GraphicsDevice.IsCacheCoherentUMA)
|
||||
{
|
||||
using ID3D12ResourceMap resource = D3D12Resource->Map();
|
||||
|
||||
@@ -72,13 +72,13 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
|
||||
/// <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)
|
||||
{
|
||||
Guard.IsBetweenOrEqualTo(width, 1, D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION);
|
||||
|
||||
using (device.GetReferenceTracker().GetLease())
|
||||
{
|
||||
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);
|
||||
|
||||
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), d3D12FormatSupport))
|
||||
{
|
||||
UnsupportedTextureTypeException.ThrowForTexture2D<T>();
|
||||
@@ -171,26 +171,26 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
internal void CopyTo(ref T destination, int size, int sourceOffsetX, int sourceOffsetY, int width, int height)
|
||||
{
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width);
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height);
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
{
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width);
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height);
|
||||
|
||||
GraphicsDevice.D3D12Device->GetCopyableFootprint(
|
||||
DXGIFormatHelper.GetForType<T>(),
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprintDestination,
|
||||
out ulong rowSizeInBytes,
|
||||
out ulong totalSizeInBytes);
|
||||
DXGIFormatHelper.GetForType<T>(),
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprintDestination,
|
||||
out ulong rowSizeInBytes,
|
||||
out ulong totalSizeInBytes);
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
|
||||
@@ -262,6 +262,19 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
internal void CopyTo(Texture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
{
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width);
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height);
|
||||
Guard.IsInRange(destinationOffsetX, 0, destination.Width);
|
||||
Guard.IsInRange(destinationOffsetY, 0, destination.Height);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, destination.Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, destination.Height);
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetX + width, 1, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetY + height, 1, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
using (destination.GetReferenceTracker().GetLease())
|
||||
@@ -270,19 +283,6 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
|
||||
|
||||
destination.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width);
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height);
|
||||
Guard.IsInRange(destinationOffsetX, 0, destination.Width);
|
||||
Guard.IsInRange(destinationOffsetY, 0, destination.Height);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, destination.Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, destination.Height);
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetX + width, 1, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetY + height, 1, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
|
||||
D3D12_COMMAND_LIST_TYPE d3D12CommandListType =
|
||||
this.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE ||
|
||||
destination.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE
|
||||
@@ -332,6 +332,19 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
internal void CopyTo(ReadBackTexture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
{
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width);
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height);
|
||||
Guard.IsInRange(destinationOffsetX, 0, destination.Width);
|
||||
Guard.IsInRange(destinationOffsetY, 0, destination.Height);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, destination.Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, destination.Height);
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetX + width, 1, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetY + height, 1, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
using (destination.GetReferenceTracker().GetLease())
|
||||
@@ -340,19 +353,6 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
|
||||
|
||||
destination.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width);
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height);
|
||||
Guard.IsInRange(destinationOffsetX, 0, destination.Width);
|
||||
Guard.IsInRange(destinationOffsetY, 0, destination.Height);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, destination.Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, destination.Height);
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetX + width, 1, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetY + height, 1, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
|
||||
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
|
||||
|
||||
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
|
||||
@@ -397,19 +397,19 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
|
||||
/// <param name="height">The height of the memory area to write to.</param>
|
||||
internal void CopyFrom(ref T source, int size, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
{
|
||||
Guard.IsInRange(destinationOffsetX, 0, Width);
|
||||
Guard.IsInRange(destinationOffsetY, 0, Height);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetX + width, Width, nameof(destinationOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetY + height, Height, nameof(destinationOffsetY));
|
||||
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height);
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
{
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
Guard.IsInRange(destinationOffsetX, 0, Width);
|
||||
Guard.IsInRange(destinationOffsetY, 0, Height);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetX + width, Width, nameof(destinationOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetY + height, Height, nameof(destinationOffsetY));
|
||||
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height);
|
||||
|
||||
GraphicsDevice.D3D12Device->GetCopyableFootprint(
|
||||
DXGIFormatHelper.GetForType<T>(),
|
||||
(uint)width,
|
||||
@@ -486,6 +486,19 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
|
||||
/// <param name="height">The height of the memory area to write to.</param>
|
||||
internal void CopyFrom(UploadTexture2D<T> source, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
{
|
||||
Guard.IsInRange(sourceOffsetX, 0, source.Width);
|
||||
Guard.IsInRange(sourceOffsetY, 0, source.Height);
|
||||
Guard.IsInRange(destinationOffsetX, 0, Width);
|
||||
Guard.IsInRange(destinationOffsetY, 0, Height);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, source.Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, source.Height);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, source.Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, source.Height, nameof(sourceOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetX + width, Width, nameof(destinationOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetY + height, Height, nameof(destinationOffsetY));
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
using (source.GetReferenceTracker().GetLease())
|
||||
@@ -494,19 +507,6 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
|
||||
|
||||
source.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
|
||||
Guard.IsInRange(sourceOffsetX, 0, source.Width);
|
||||
Guard.IsInRange(sourceOffsetY, 0, source.Height);
|
||||
Guard.IsInRange(destinationOffsetX, 0, Width);
|
||||
Guard.IsInRange(destinationOffsetY, 0, Height);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, source.Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, source.Height);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, source.Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, source.Height, nameof(sourceOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetX + width, Width, nameof(destinationOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetY + height, Height, nameof(destinationOffsetY));
|
||||
|
||||
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
|
||||
|
||||
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
|
||||
|
||||
@@ -73,14 +73,14 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
|
||||
/// <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)
|
||||
{
|
||||
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);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, D3D12.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION);
|
||||
|
||||
using (device.GetReferenceTracker().GetLease())
|
||||
{
|
||||
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);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, D3D12.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION);
|
||||
|
||||
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), d3D12FormatSupport))
|
||||
{
|
||||
UnsupportedTextureTypeException.ThrowForTexture3D<T>();
|
||||
@@ -183,22 +183,22 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
internal void CopyTo(ref T destination, int size, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int width, int height, int depth)
|
||||
{
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width);
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height);
|
||||
Guard.IsInRange(sourceOffsetZ, 0, Depth);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, Depth);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetZ + depth, Depth, nameof(sourceOffsetZ));
|
||||
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height * depth);
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
{
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width);
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height);
|
||||
Guard.IsInRange(sourceOffsetZ, 0, Depth);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, Depth);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetZ + depth, Depth, nameof(sourceOffsetZ));
|
||||
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height * depth);
|
||||
|
||||
GraphicsDevice.D3D12Device->GetCopyableFootprint(
|
||||
DXGIFormatHelper.GetForType<T>(),
|
||||
(uint)width,
|
||||
@@ -283,6 +283,25 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
internal void CopyTo(Texture3D<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
{
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width);
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height);
|
||||
Guard.IsInRange(sourceOffsetZ, 0, Depth);
|
||||
Guard.IsInRange(destinationOffsetX, 0, destination.Width);
|
||||
Guard.IsInRange(destinationOffsetY, 0, destination.Height);
|
||||
Guard.IsInRange(destinationOffsetZ, 0, destination.Depth);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, Depth);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, destination.Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, destination.Height);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, destination.Depth);
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetX + width, 1, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetY + height, 1, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetZ + depth, 1, destination.Depth, nameof(destinationOffsetZ));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetZ + depth, Depth, nameof(sourceOffsetZ));
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
using (destination.GetReferenceTracker().GetLease())
|
||||
@@ -291,25 +310,6 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
|
||||
|
||||
destination.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width);
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height);
|
||||
Guard.IsInRange(sourceOffsetZ, 0, Depth);
|
||||
Guard.IsInRange(destinationOffsetX, 0, destination.Width);
|
||||
Guard.IsInRange(destinationOffsetY, 0, destination.Height);
|
||||
Guard.IsInRange(destinationOffsetZ, 0, destination.Depth);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, Depth);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, destination.Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, destination.Height);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, destination.Depth);
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetX + width, 1, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetY + height, 1, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetZ + depth, 1, destination.Depth, nameof(destinationOffsetZ));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetZ + depth, Depth, nameof(sourceOffsetZ));
|
||||
|
||||
D3D12_COMMAND_LIST_TYPE d3D12CommandListType =
|
||||
this.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE ||
|
||||
destination.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE
|
||||
@@ -362,6 +362,25 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
internal void CopyTo(ReadBackTexture3D<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
{
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width);
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height);
|
||||
Guard.IsInRange(sourceOffsetZ, 0, Depth);
|
||||
Guard.IsInRange(destinationOffsetX, 0, destination.Width);
|
||||
Guard.IsInRange(destinationOffsetY, 0, destination.Height);
|
||||
Guard.IsInRange(destinationOffsetZ, 0, destination.Depth);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, Depth);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, destination.Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, destination.Height);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, destination.Depth);
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetX + width, 1, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetY + height, 1, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetZ + depth, 1, destination.Depth, nameof(destinationOffsetZ));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetZ + depth, Depth, nameof(sourceOffsetZ));
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
using (destination.GetReferenceTracker().GetLease())
|
||||
@@ -370,25 +389,6 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
|
||||
|
||||
destination.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width);
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height);
|
||||
Guard.IsInRange(sourceOffsetZ, 0, Depth);
|
||||
Guard.IsInRange(destinationOffsetX, 0, destination.Width);
|
||||
Guard.IsInRange(destinationOffsetY, 0, destination.Height);
|
||||
Guard.IsInRange(destinationOffsetZ, 0, destination.Depth);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, Depth);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, destination.Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, destination.Height);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, destination.Depth);
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetX + width, 1, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetY + height, 1, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetZ + depth, 1, destination.Depth, nameof(destinationOffsetZ));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetZ + depth, Depth, nameof(sourceOffsetZ));
|
||||
|
||||
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
|
||||
|
||||
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
|
||||
@@ -435,22 +435,22 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
|
||||
/// <param name="depth">The depth of the memory area to write to.</param>
|
||||
internal void CopyFrom(ref T source, int size, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
{
|
||||
Guard.IsInRange(destinationOffsetX, 0, Width);
|
||||
Guard.IsInRange(destinationOffsetY, 0, Height);
|
||||
Guard.IsInRange(destinationOffsetZ, 0, Depth);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, Depth);
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetX + width, Width, nameof(destinationOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetY + height, Height, nameof(destinationOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetZ + depth, Depth, nameof(destinationOffsetZ));
|
||||
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height * depth);
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
{
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
Guard.IsInRange(destinationOffsetX, 0, Width);
|
||||
Guard.IsInRange(destinationOffsetY, 0, Height);
|
||||
Guard.IsInRange(destinationOffsetZ, 0, Depth);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, Depth);
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetX + width, Width, nameof(destinationOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetY + height, Height, nameof(destinationOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetZ + depth, Depth, nameof(destinationOffsetZ));
|
||||
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height * depth);
|
||||
|
||||
GraphicsDevice.D3D12Device->GetCopyableFootprint(
|
||||
DXGIFormatHelper.GetForType<T>(),
|
||||
(uint)width,
|
||||
@@ -533,6 +533,25 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
|
||||
/// <param name="depth">The depth of the memory area to write to.</param>
|
||||
internal void CopyFrom(UploadTexture3D<T> source, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
{
|
||||
Guard.IsInRange(sourceOffsetX, 0, source.Width);
|
||||
Guard.IsInRange(sourceOffsetY, 0, source.Height);
|
||||
Guard.IsInRange(sourceOffsetZ, 0, source.Depth);
|
||||
Guard.IsInRange(destinationOffsetX, 0, Width);
|
||||
Guard.IsInRange(destinationOffsetY, 0, Height);
|
||||
Guard.IsInRange(destinationOffsetZ, 0, Depth);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, Depth);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, source.Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, source.Height);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, source.Depth);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, source.Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, source.Height, nameof(sourceOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetZ + depth, source.Depth, nameof(sourceOffsetZ));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetX + width, Width, nameof(destinationOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetY + height, Height, nameof(destinationOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetZ + depth, Depth, nameof(destinationOffsetZ));
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
using (source.GetReferenceTracker().GetLease())
|
||||
@@ -541,25 +560,6 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
|
||||
|
||||
source.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
|
||||
Guard.IsInRange(sourceOffsetX, 0, source.Width);
|
||||
Guard.IsInRange(sourceOffsetY, 0, source.Height);
|
||||
Guard.IsInRange(sourceOffsetZ, 0, source.Depth);
|
||||
Guard.IsInRange(destinationOffsetX, 0, Width);
|
||||
Guard.IsInRange(destinationOffsetY, 0, Height);
|
||||
Guard.IsInRange(destinationOffsetZ, 0, Depth);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, Depth);
|
||||
Guard.IsBetweenOrEqualTo(width, 1, source.Width);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, source.Height);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, source.Depth);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, source.Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, source.Height, nameof(sourceOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetZ + depth, source.Depth, nameof(sourceOffsetZ));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetX + width, Width, nameof(destinationOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetY + height, Height, nameof(destinationOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetZ + depth, Depth, nameof(destinationOffsetZ));
|
||||
|
||||
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
|
||||
|
||||
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
|
||||
|
||||
@@ -44,13 +44,13 @@ public abstract unsafe class TransferBuffer<T> : NativeObject, IGraphicsResource
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
private protected TransferBuffer(GraphicsDevice device, int length, ResourceType resourceType, AllocationMode allocationMode)
|
||||
{
|
||||
// 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);
|
||||
|
||||
using (device.GetReferenceTracker().GetLease())
|
||||
{
|
||||
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);
|
||||
|
||||
GraphicsDevice = device;
|
||||
Length = length;
|
||||
|
||||
|
||||
@@ -50,13 +50,13 @@ public unsafe abstract class TransferTexture2D<T> : NativeObject, IGraphicsResou
|
||||
/// <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)
|
||||
{
|
||||
Guard.IsBetweenOrEqualTo(width, 1, D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION);
|
||||
Guard.IsBetweenOrEqualTo(height, 1, D3D12.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION);
|
||||
|
||||
using (device.GetReferenceTracker().GetLease())
|
||||
{
|
||||
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);
|
||||
|
||||
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE2D))
|
||||
{
|
||||
UnsupportedTextureTypeException.ThrowForTexture2D<T>();
|
||||
|
||||
@@ -51,14 +51,14 @@ public unsafe abstract class TransferTexture3D<T> : NativeObject, IGraphicsResou
|
||||
/// <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)
|
||||
{
|
||||
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);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, D3D12.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION);
|
||||
|
||||
using (device.GetReferenceTracker().GetLease())
|
||||
{
|
||||
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);
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, D3D12.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION);
|
||||
|
||||
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE3D))
|
||||
{
|
||||
UnsupportedTextureTypeException.ThrowForTexture3D<T>();
|
||||
|
||||
@@ -57,15 +57,15 @@ public sealed class ConstantBuffer<T> : Buffer<T>
|
||||
/// <inheritdoc/>
|
||||
internal override unsafe void CopyTo(ref T destination, int offset, int length)
|
||||
{
|
||||
Guard.IsBetweenOrEqualTo(length, 0, Length);
|
||||
Guard.IsInRange(offset, 0, Length);
|
||||
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(offset));
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
{
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
Guard.IsBetweenOrEqualTo(length, 0, Length);
|
||||
Guard.IsInRange(offset, 0, Length);
|
||||
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(offset));
|
||||
|
||||
using ID3D12ResourceMap resource = D3D12Resource->Map();
|
||||
|
||||
fixed (void* destinationPointer = &destination)
|
||||
@@ -85,6 +85,13 @@ public sealed class ConstantBuffer<T> : Buffer<T>
|
||||
/// <inheritdoc/>
|
||||
internal override unsafe void CopyTo(Buffer<T> destination, int sourceOffset, int destinationOffset, int length)
|
||||
{
|
||||
Guard.IsBetweenOrEqualTo(length, 0, Length);
|
||||
Guard.IsBetweenOrEqualTo(length, 0, destination.Length);
|
||||
Guard.IsInRange(sourceOffset, 0, Length);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffset + length, Length, nameof(sourceOffset));
|
||||
Guard.IsInRange(destinationOffset, 0, destination.Length);
|
||||
Guard.IsLessThanOrEqualTo(destinationOffset + length, destination.Length, nameof(destinationOffset));
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
using (destination.GetReferenceTracker().GetLease())
|
||||
@@ -93,13 +100,6 @@ public sealed class ConstantBuffer<T> : Buffer<T>
|
||||
|
||||
destination.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
|
||||
Guard.IsBetweenOrEqualTo(length, 0, Length);
|
||||
Guard.IsBetweenOrEqualTo(length, 0, destination.Length);
|
||||
Guard.IsInRange(sourceOffset, 0, Length);
|
||||
Guard.IsLessThanOrEqualTo(sourceOffset + length, Length, nameof(sourceOffset));
|
||||
Guard.IsInRange(destinationOffset, 0, destination.Length);
|
||||
Guard.IsLessThanOrEqualTo(destinationOffset + length, destination.Length, nameof(destinationOffset));
|
||||
|
||||
if (destination is ConstantBuffer<T> buffer)
|
||||
{
|
||||
using ID3D12ResourceMap sourceMap = D3D12Resource->Map();
|
||||
@@ -121,15 +121,15 @@ public sealed class ConstantBuffer<T> : Buffer<T>
|
||||
/// <inheritdoc/>
|
||||
internal override unsafe void CopyFrom(ref T source, int offset, int length)
|
||||
{
|
||||
Guard.IsBetweenOrEqualTo(length, 0, Length);
|
||||
Guard.IsInRange(offset, 0, Length);
|
||||
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(offset));
|
||||
|
||||
using (GraphicsDevice.GetReferenceTracker().GetLease())
|
||||
using (GetReferenceTracker().GetLease())
|
||||
{
|
||||
GraphicsDevice.ThrowIfDeviceLost();
|
||||
|
||||
Guard.IsBetweenOrEqualTo(length, 0, Length);
|
||||
Guard.IsInRange(offset, 0, Length);
|
||||
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(offset));
|
||||
|
||||
using ID3D12ResourceMap resource = D3D12Resource->Map();
|
||||
|
||||
fixed (void* sourcePointer = &source)
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする