Switch all GetLease() calls to using declarations

このコミットが含まれているのは:
Sergio Pedri committed 2022-07-31 23:26:12 +02:00
1 親 5100ab471a
コミット 65fe7f53c6
17ファイル変更
+1165 -1229

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

+28 -29
ファイルの表示
@@ -29,7 +29,8 @@ partial class SwapChainManager<TOwner>
{
Guard.IsNotNull(shaderRunner);
using (GetReferenceTracker().GetLease())
using var _0 = GetReferenceTracker().GetLease();
using (await this.setupSemaphore.LockAsync())
{
this.renderCancellationTokenSource?.Cancel();
@@ -54,7 +55,8 @@ partial class SwapChainManager<TOwner>
/// </summary>
public async void StopRenderLoop()
{
using (GetReferenceTracker().GetLease())
using var _0 = GetReferenceTracker().GetLease();
using (await this.setupSemaphore.LockAsync())
{
this.renderCancellationTokenSource?.Cancel();
@@ -67,7 +69,8 @@ partial class SwapChainManager<TOwner>
/// <param name="isDynamicResolutionEnabled">Whether or not to use dynamic resolution.</param>
public async void QueueDynamicResolutionModeChange(bool isDynamicResolutionEnabled)
{
using (GetReferenceTracker().GetLease())
using var _0 = GetReferenceTracker().GetLease();
using (await this.setupSemaphore.LockAsync())
{
// If there is a render thread currently running, stop it and restart it
@@ -100,7 +103,8 @@ partial class SwapChainManager<TOwner>
/// <param name="isVerticalSyncEnabled">Whether or not to use vertical sync.</param>
public async void QueueVerticalSyncModeChange(bool isVerticalSyncEnabled)
{
using (GetReferenceTracker().GetLease())
using var _0 = GetReferenceTracker().GetLease();
using (await this.setupSemaphore.LockAsync())
{
// The v-sync option can be toggled on the fly when not using dynamic resolution
@@ -134,13 +138,12 @@ partial class SwapChainManager<TOwner>
/// <param name="height">The height of the render resolution.</param>
public void QueueResize(double width, double height)
{
using (GetReferenceTracker().GetLease())
{
this.width = (float)width;
this.height = (float)height;
using var _0 = GetReferenceTracker().GetLease();
this.isResizePending = true;
}
this.width = (float)width;
this.height = (float)height;
this.isResizePending = true;
}
/// <summary>
@@ -150,13 +153,12 @@ partial class SwapChainManager<TOwner>
/// <param name="compositionScaleY">The composition scale on the Y axis</param>
public void QueueCompositionScaleChange(double compositionScaleX, double compositionScaleY)
{
using (GetReferenceTracker().GetLease())
{
this.compositionScaleX = (float)compositionScaleX;
this.compositionScaleY = (float)compositionScaleY;
using var _0 = GetReferenceTracker().GetLease();
this.isResizePending = true;
}
this.compositionScaleX = (float)compositionScaleX;
this.compositionScaleY = (float)compositionScaleY;
this.isResizePending = true;
}
/// <summary>
@@ -165,12 +167,11 @@ partial class SwapChainManager<TOwner>
/// <param name="resolutionScale">The resolution scale factor to use.</param>
public void QueueResolutionScaleChange(double resolutionScale)
{
using (GetReferenceTracker().GetLease())
{
this.resolutionScale = (float)resolutionScale;
using var _0 = GetReferenceTracker().GetLease();
this.isResizePending = true;
}
this.resolutionScale = (float)resolutionScale;
this.isResizePending = true;
}
/// <summary>
@@ -187,17 +188,15 @@ partial class SwapChainManager<TOwner>
this.dynamicResolutionScale = this.resolutionScale;
// These two leases are needed to ensure the manager isn't disposed while rendering is running
using (GetReferenceTracker().GetLease())
{
RenderLoopWithDynamicResolution();
}
using var _0 = GetReferenceTracker().GetLease();
RenderLoopWithDynamicResolution();
}
else
{
using (GetReferenceTracker().GetLease())
{
RenderLoop();
}
using var _0 = GetReferenceTracker().GetLease();
RenderLoop();
}
this.renderStopwatch?.Stop();
+4 -5
ファイルの表示
@@ -150,11 +150,10 @@ public static partial class GraphicsDeviceExtensions
{
Guard.IsNotNull(device);
using (device.GetReferenceTracker().GetLease())
{
device.ThrowIfDeviceLost();
using var _0 = device.GetReferenceTracker().GetLease();
return new(device);
}
device.ThrowIfDeviceLost();
return new(device);
}
}
+21 -22
ファイルの表示
@@ -48,32 +48,31 @@ unsafe partial class GraphicsDevice
/// </summary>
private void QueueRaiseDeviceLostEventIfNeeded()
{
using (GetReferenceTracker().TryGetLease(out bool leaseTaken))
using var _0 = GetReferenceTracker().TryGetLease(out bool leaseTaken);
if (!leaseTaken)
{
if (!leaseTaken)
{
return;
}
return;
}
// If the current device removed reason is not S_OK, it means the event
// has already been raised (but the device will keep reporting that reason).
// In that case, do nothing to avoid raising it again while the device is alive.
if (Volatile.Read(ref Unsafe.As<HRESULT, int>(ref this.deviceRemovedReason)) != S.S_OK)
{
return;
}
// If the current device removed reason is not S_OK, it means the event
// has already been raised (but the device will keep reporting that reason).
// In that case, do nothing to avoid raising it again while the device is alive.
if (Volatile.Read(ref Unsafe.As<HRESULT, int>(ref this.deviceRemovedReason)) != S.S_OK)
{
return;
}
HRESULT result = this.d3D12Device.Get()->GetDeviceRemovedReason();
HRESULT result = this.d3D12Device.Get()->GetDeviceRemovedReason();
// Only raise the event once, and store the device removed reason to track it
if (result != S.S_OK &&
Interlocked.CompareExchange(
ref Unsafe.As<HRESULT, int>(ref this.deviceRemovedReason),
(int)result,
S.S_OK) == S.S_OK)
{
QueueRaiseDeviceLostEvent();
}
// Only raise the event once, and store the device removed reason to track it
if (result != S.S_OK &&
Interlocked.CompareExchange(
ref Unsafe.As<HRESULT, int>(ref this.deviceRemovedReason),
(int)result,
S.S_OK) == S.S_OK)
{
QueueRaiseDeviceLostEvent();
}
}
+25 -30
ファイルの表示
@@ -238,14 +238,13 @@ public sealed unsafe partial class GraphicsDevice : NativeObject
/// <returns>Whether the current device supports double precision floating point operations in shaders.</returns>
public bool IsDoublePrecisionSupportAvailable()
{
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceLost();
using var _0 = GetReferenceTracker().GetLease();
var d3D12OptionsData = this.d3D12Device.Get()->CheckFeatureSupport<D3D12_FEATURE_DATA_D3D12_OPTIONS>(D3D12_FEATURE_D3D12_OPTIONS);
ThrowIfDeviceLost();
return d3D12OptionsData.DoublePrecisionFloatShaderOps;
}
var d3D12OptionsData = this.d3D12Device.Get()->CheckFeatureSupport<D3D12_FEATURE_DATA_D3D12_OPTIONS>(D3D12_FEATURE_D3D12_OPTIONS);
return d3D12OptionsData.DoublePrecisionFloatShaderOps;
}
/// <summary>
@@ -257,12 +256,11 @@ public sealed unsafe partial class GraphicsDevice : NativeObject
public bool IsReadOnlyTexture2DSupportedForType<T>()
where T : unmanaged
{
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceLost();
using var _0 = GetReferenceTracker().GetLease();
return this.d3D12Device.Get()->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE2D);
}
ThrowIfDeviceLost();
return this.d3D12Device.Get()->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE2D);
}
/// <summary>
@@ -274,14 +272,13 @@ public sealed unsafe partial class GraphicsDevice : NativeObject
public bool IsReadWriteTexture2DSupportedForType<T>()
where T : unmanaged
{
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceLost();
using var _0 = GetReferenceTracker().GetLease();
return this.d3D12Device.Get()->IsDxgiFormatSupported(
DXGIFormatHelper.GetForType<T>(),
D3D12_FORMAT_SUPPORT1_TEXTURE2D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW);
}
ThrowIfDeviceLost();
return this.d3D12Device.Get()->IsDxgiFormatSupported(
DXGIFormatHelper.GetForType<T>(),
D3D12_FORMAT_SUPPORT1_TEXTURE2D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW);
}
/// <summary>
@@ -293,12 +290,11 @@ public sealed unsafe partial class GraphicsDevice : NativeObject
public bool IsReadOnlyTexture3DSupportedForType<T>()
where T : unmanaged
{
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceLost();
using var _0 = GetReferenceTracker().GetLease();
return this.d3D12Device.Get()->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE3D);
}
ThrowIfDeviceLost();
return this.d3D12Device.Get()->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE3D);
}
/// <summary>
@@ -310,14 +306,13 @@ public sealed unsafe partial class GraphicsDevice : NativeObject
public bool IsReadWriteTexture3DSupportedForType<T>()
where T : unmanaged
{
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceLost();
using var _0 = GetReferenceTracker().GetLease();
return this.d3D12Device.Get()->IsDxgiFormatSupported(
DXGIFormatHelper.GetForType<T>(),
D3D12_FORMAT_SUPPORT1_TEXTURE3D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW);
}
ThrowIfDeviceLost();
return this.d3D12Device.Get()->IsDxgiFormatSupported(
DXGIFormatHelper.GetForType<T>(),
D3D12_FORMAT_SUPPORT1_TEXTURE3D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW);
}
/// <summary>
+25 -30
ファイルの表示
@@ -64,14 +64,13 @@ public static class GraphicsResourceHelper
{
Guard.IsNotNull(buffer);
using (buffer.GetReferenceTracker().GetLease())
{
buffer.ThrowIfDeviceMismatch(device);
using var _0 = buffer.GetReferenceTracker().GetLease();
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = buffer.D3D12GpuDescriptorHandle;
buffer.ThrowIfDeviceMismatch(device);
return *(ulong*)&d3D12GpuDescriptorHandle;
}
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = buffer.D3D12GpuDescriptorHandle;
return *(ulong*)&d3D12GpuDescriptorHandle;
}
/// <summary>
@@ -87,14 +86,13 @@ public static class GraphicsResourceHelper
{
Guard.IsNotNull(texture);
using (texture.GetReferenceTracker().GetLease())
{
texture.ThrowIfDeviceMismatch(device);
using var _0 = texture.GetReferenceTracker().GetLease();
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = texture.D3D12GpuDescriptorHandle;
texture.ThrowIfDeviceMismatch(device);
return *(ulong*)&d3D12GpuDescriptorHandle;
}
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = texture.D3D12GpuDescriptorHandle;
return *(ulong*)&d3D12GpuDescriptorHandle;
}
/// <summary>
@@ -110,14 +108,13 @@ public static class GraphicsResourceHelper
{
Guard.IsNotNull(texture);
using (texture.GetReferenceTracker().GetLease())
{
texture.ThrowIfDeviceMismatch(device);
using var _0 = texture.GetReferenceTracker().GetLease();
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = texture.D3D12GpuDescriptorHandle;
texture.ThrowIfDeviceMismatch(device);
return *(ulong*)&d3D12GpuDescriptorHandle;
}
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = texture.D3D12GpuDescriptorHandle;
return *(ulong*)&d3D12GpuDescriptorHandle;
}
/// <summary>
@@ -202,14 +199,13 @@ public static class GraphicsResourceHelper
{
Guard.IsNotNull(texture);
using (texture.GetReferenceTracker().GetLease())
{
texture.ThrowIfDeviceMismatch(device);
using var _0 = texture.GetReferenceTracker().GetLease();
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = texture.D3D12GpuDescriptorHandle;
texture.ThrowIfDeviceMismatch(device);
return *(ulong*)&d3D12GpuDescriptorHandle;
}
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = texture.D3D12GpuDescriptorHandle;
return *(ulong*)&d3D12GpuDescriptorHandle;
}
/// <summary>
@@ -225,14 +221,13 @@ public static class GraphicsResourceHelper
{
Guard.IsNotNull(texture);
using (texture.GetReferenceTracker().GetLease())
{
texture.ThrowIfDeviceMismatch(device);
using var _0 = texture.GetReferenceTracker().GetLease();
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = texture.D3D12GpuDescriptorHandle;
texture.ThrowIfDeviceMismatch(device);
return *(ulong*)&d3D12GpuDescriptorHandle;
}
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = texture.D3D12GpuDescriptorHandle;
return *(ulong*)&d3D12GpuDescriptorHandle;
}
/// <summary>
+48 -51
ファイルの表示
@@ -75,55 +75,54 @@ public unsafe abstract class Buffer<T> : NativeObject, IGraphicsResource
Guard.IsBetweenOrEqualTo(length, 1, (uint.MaxValue / elementSizeInBytes) & ~255);
}
using (device.GetReferenceTracker().GetLease())
using var _0 = device.GetReferenceTracker().GetLease();
device.ThrowIfDeviceLost();
if (TypeInfo<T>.IsDoubleOrContainsDoubles &&
device.D3D12Device->CheckFeatureSupport<D3D12_FEATURE_DATA_D3D12_OPTIONS>(D3D12_FEATURE_D3D12_OPTIONS).DoublePrecisionFloatShaderOps == 0)
{
device.ThrowIfDeviceLost();
UnsupportedDoubleOperationException.Throw<T>();
}
if (TypeInfo<T>.IsDoubleOrContainsDoubles &&
device.D3D12Device->CheckFeatureSupport<D3D12_FEATURE_DATA_D3D12_OPTIONS>(D3D12_FEATURE_D3D12_OPTIONS).DoublePrecisionFloatShaderOps == 0)
{
UnsupportedDoubleOperationException.Throw<T>();
}
nint usableSizeInBytes = checked((nint)(length * elementSizeInBytes));
nint effectiveSizeInBytes = resourceType == ResourceType.Constant ? AlignmentHelper.Pad(usableSizeInBytes, D3D12.D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT) : usableSizeInBytes;
nint usableSizeInBytes = checked((nint)(length * elementSizeInBytes));
nint effectiveSizeInBytes = resourceType == ResourceType.Constant ? AlignmentHelper.Pad(usableSizeInBytes, D3D12.D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT) : usableSizeInBytes;
SizeInBytes = usableSizeInBytes;
GraphicsDevice = device;
Length = length;
SizeInBytes = usableSizeInBytes;
GraphicsDevice = device;
Length = length;
#if NET6_0_OR_GREATER
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, (ulong)effectiveSizeInBytes);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, (ulong)effectiveSizeInBytes);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
#else
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, (ulong)effectiveSizeInBytes, device.IsCacheCoherentUMA);
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, (ulong)effectiveSizeInBytes, device.IsCacheCoherentUMA);
#endif
device.RegisterAllocatedResource();
device.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandles);
device.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandlesForTypedUnorderedAccessView);
device.RegisterAllocatedResource();
device.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandles);
device.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandlesForTypedUnorderedAccessView);
switch (resourceType)
{
case ResourceType.Constant:
device.D3D12Device->CreateConstantBufferView(this.d3D12Resource.Get(), effectiveSizeInBytes, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
break;
case ResourceType.ReadOnly:
device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), (uint)length, elementSizeInBytes, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
break;
case ResourceType.ReadWrite:
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), (uint)length, elementSizeInBytes, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
device.D3D12Device->CreateUnorderedAccessViewForClear(
this.d3D12Resource.Get(),
DXGI_FORMAT_R32_UINT,
(uint)(usableSizeInBytes / sizeof(uint)),
this.d3D12ResourceDescriptorHandlesForTypedUnorderedAccessView.D3D12CpuDescriptorHandle,
this.d3D12ResourceDescriptorHandlesForTypedUnorderedAccessView.D3D12CpuDescriptorHandleNonShaderVisible);
break;
}
this.d3D12Resource.Get()->SetName(this);
switch (resourceType)
{
case ResourceType.Constant:
device.D3D12Device->CreateConstantBufferView(this.d3D12Resource.Get(), effectiveSizeInBytes, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
break;
case ResourceType.ReadOnly:
device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), (uint)length, elementSizeInBytes, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
break;
case ResourceType.ReadWrite:
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), (uint)length, elementSizeInBytes, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
device.D3D12Device->CreateUnorderedAccessViewForClear(
this.d3D12Resource.Get(),
DXGI_FORMAT_R32_UINT,
(uint)(usableSizeInBytes / sizeof(uint)),
this.d3D12ResourceDescriptorHandlesForTypedUnorderedAccessView.D3D12CpuDescriptorHandle,
this.d3D12ResourceDescriptorHandlesForTypedUnorderedAccessView.D3D12CpuDescriptorHandleNonShaderVisible);
break;
}
this.d3D12Resource.Get()->SetName(this);
}
/// <inheritdoc/>
@@ -234,24 +233,22 @@ public unsafe abstract class Buffer<T> : NativeObject, IGraphicsResource
/// <inheritdoc cref="__Internals.GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice, out bool)"/>
internal (D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device)
{
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
return (
this.d3D12ResourceDescriptorHandlesForTypedUnorderedAccessView.D3D12GpuDescriptorHandle,
this.d3D12ResourceDescriptorHandlesForTypedUnorderedAccessView.D3D12CpuDescriptorHandleNonShaderVisible);
}
ThrowIfDeviceMismatch(device);
return (
this.d3D12ResourceDescriptorHandlesForTypedUnorderedAccessView.D3D12GpuDescriptorHandle,
this.d3D12ResourceDescriptorHandlesForTypedUnorderedAccessView.D3D12CpuDescriptorHandleNonShaderVisible);
}
/// <inheritdoc cref="__Internals.GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice)"/>
internal unsafe ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device)
{
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
return D3D12Resource;
}
ThrowIfDeviceMismatch(device);
return D3D12Resource;
}
}
+181 -186
ファイルの表示
@@ -36,68 +36,67 @@ public abstract class StructuredBuffer<T> : Buffer<T>
Guard.IsInRange(sourceOffset, 0, Length);
Guard.IsLessThanOrEqualTo(sourceOffset + count, Length, nameof(sourceOffset));
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (GetReferenceTracker().GetLease())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
if (GraphicsDevice.IsCacheCoherentUMA)
{
GraphicsDevice.ThrowIfDeviceLost();
using ID3D12ResourceMap resource = D3D12Resource->Map();
if (GraphicsDevice.IsCacheCoherentUMA)
fixed (void* destinationPointer = &destination)
{
using ID3D12ResourceMap resource = D3D12Resource->Map();
fixed (void* destinationPointer = &destination)
{
MemoryHelper.Copy<T>(
source: resource.Pointer,
destination: destinationPointer,
sourceElementOffset: (uint)sourceOffset,
destinationElementOffset: 0,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)count);
}
MemoryHelper.Copy<T>(
source: resource.Pointer,
destination: destinationPointer,
sourceElementOffset: (uint)sourceOffset,
destinationElementOffset: 0,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)count);
}
else
}
else
{
nint byteOffset = (nint)sourceOffset * sizeof(T);
nint byteLength = count * sizeof(T);
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.ReadBack, AllocationMode.Default, (ulong)byteLength);
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.ReadBack,
(ulong)byteLength,
GraphicsDevice.IsCacheCoherentUMA);
#endif
using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY))
{
nint byteOffset = (nint)sourceOffset * sizeof(T);
nint byteLength = count * sizeof(T);
#if NET6_0_OR_GREATER
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(allocation.Get()->GetResource(), 0, D3D12Resource, (ulong)byteOffset, (ulong)byteLength);
#else
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(d3D12Resource.Get(), 0, D3D12Resource, (ulong)byteOffset, (ulong)byteLength);
#endif
copyCommandList.ExecuteAndWaitForCompletion();
}
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.ReadBack, AllocationMode.Default, (ulong)byteLength);
using ID3D12ResourceMap resource = allocation.Get()->GetResource()->Map();
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.ReadBack,
(ulong)byteLength,
GraphicsDevice.IsCacheCoherentUMA);
using ID3D12ResourceMap resource = d3D12Resource.Get()->Map();
#endif
using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY))
{
#if NET6_0_OR_GREATER
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(allocation.Get()->GetResource(), 0, D3D12Resource, (ulong)byteOffset, (ulong)byteLength);
#else
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(d3D12Resource.Get(), 0, D3D12Resource, (ulong)byteOffset, (ulong)byteLength);
#endif
copyCommandList.ExecuteAndWaitForCompletion();
}
#if NET6_0_OR_GREATER
using ID3D12ResourceMap resource = allocation.Get()->GetResource()->Map();
#else
using ID3D12ResourceMap resource = d3D12Resource.Get()->Map();
#endif
fixed (void* destinationPointer = &destination)
{
MemoryHelper.Copy<T>(
source: resource.Pointer,
destination: destinationPointer,
sourceElementOffset: 0,
destinationElementOffset: 0,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)count);
}
fixed (void* destinationPointer = &destination)
{
MemoryHelper.Copy<T>(
source: resource.Pointer,
destination: destinationPointer,
sourceElementOffset: 0,
destinationElementOffset: 0,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)count);
}
}
}
@@ -112,34 +111,33 @@ public abstract class StructuredBuffer<T> : Buffer<T>
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())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
using var _2 = destination.GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
destination.ThrowIfDeviceMismatch(GraphicsDevice);
if (!destination.IsPaddingPresent)
{
GraphicsDevice.ThrowIfDeviceLost();
nint sourceByteOffset = (nint)sourceOffset * sizeof(T);
nint destinationByteOffset = (nint)destinationOffset * sizeof(T);
nint byteLength = count * sizeof(T);
destination.ThrowIfDeviceMismatch(GraphicsDevice);
// Directly copy the input buffer
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
if (!destination.IsPaddingPresent)
{
nint sourceByteOffset = (nint)sourceOffset * sizeof(T);
nint destinationByteOffset = (nint)destinationOffset * sizeof(T);
nint byteLength = count * sizeof(T);
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(
destination.D3D12Resource,
(ulong)destinationByteOffset,
D3D12Resource,
(ulong)sourceByteOffset,
(ulong)byteLength);
// Directly copy the input buffer
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(
destination.D3D12Resource,
(ulong)destinationByteOffset,
D3D12Resource,
(ulong)sourceByteOffset,
(ulong)byteLength);
copyCommandList.ExecuteAndWaitForCompletion();
}
else CopyToWithCpuBuffer(destination, sourceOffset, destinationOffset, count);
copyCommandList.ExecuteAndWaitForCompletion();
}
else CopyToWithCpuBuffer(destination, sourceOffset, destinationOffset, count);
}
/// <summary>
@@ -158,38 +156,37 @@ public abstract class StructuredBuffer<T> : Buffer<T>
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())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
using var _2 = destination.GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
destination.ThrowIfDeviceMismatch(GraphicsDevice);
if (GraphicsDevice.IsCacheCoherentUMA)
{
GraphicsDevice.ThrowIfDeviceLost();
using ID3D12ResourceMap resource = D3D12Resource->Map();
destination.ThrowIfDeviceMismatch(GraphicsDevice);
MemoryHelper.Copy<T>(
source: resource.Pointer,
destination: destination.MappedData,
sourceElementOffset: (uint)sourceOffset,
destinationElementOffset: (uint)destinationOffset,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)count);
}
else
{
ulong byteDestinationOffset = (uint)destinationOffset * (uint)sizeof(T);
ulong byteOffset = (uint)sourceOffset * (uint)sizeof(T);
ulong byteLength = (uint)count * (uint)sizeof(T);
if (GraphicsDevice.IsCacheCoherentUMA)
{
using ID3D12ResourceMap resource = D3D12Resource->Map();
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
MemoryHelper.Copy<T>(
source: resource.Pointer,
destination: destination.MappedData,
sourceElementOffset: (uint)sourceOffset,
destinationElementOffset: (uint)destinationOffset,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)count);
}
else
{
ulong byteDestinationOffset = (uint)destinationOffset * (uint)sizeof(T);
ulong byteOffset = (uint)sourceOffset * (uint)sizeof(T);
ulong byteLength = (uint)count * (uint)sizeof(T);
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(destination.D3D12Resource, byteDestinationOffset, D3D12Resource, byteOffset, byteLength);
copyCommandList.ExecuteAndWaitForCompletion();
}
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(destination.D3D12Resource, byteDestinationOffset, D3D12Resource, byteOffset, byteLength);
copyCommandList.ExecuteAndWaitForCompletion();
}
}
@@ -200,67 +197,66 @@ public abstract class StructuredBuffer<T> : Buffer<T>
Guard.IsInRange(offset, 0, Length);
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(offset));
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (GetReferenceTracker().GetLease())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
if (GraphicsDevice.IsCacheCoherentUMA)
{
GraphicsDevice.ThrowIfDeviceLost();
using ID3D12ResourceMap resource = D3D12Resource->Map();
if (GraphicsDevice.IsCacheCoherentUMA)
fixed (void* sourcePointer = &source)
{
using ID3D12ResourceMap resource = D3D12Resource->Map();
fixed (void* sourcePointer = &source)
{
MemoryHelper.Copy<T>(
source: sourcePointer,
destination: resource.Pointer,
sourceElementOffset: 0,
destinationElementOffset: (uint)offset,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)length);
}
MemoryHelper.Copy<T>(
source: sourcePointer,
destination: resource.Pointer,
sourceElementOffset: 0,
destinationElementOffset: (uint)offset,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)length);
}
else
}
else
{
nint byteOffset = (nint)offset * sizeof(T);
nint byteLength = length * sizeof(T);
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.Upload, AllocationMode.Default, (ulong)byteLength);
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.Upload,
(ulong)byteLength,
GraphicsDevice.IsCacheCoherentUMA);
#endif
#if NET6_0_OR_GREATER
using (ID3D12ResourceMap resource = allocation.Get()->GetResource()->Map())
#else
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
#endif
fixed (void* sourcePointer = &source)
{
nint byteOffset = (nint)offset * sizeof(T);
nint byteLength = length * sizeof(T);
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.Upload, AllocationMode.Default, (ulong)byteLength);
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.Upload,
(ulong)byteLength,
GraphicsDevice.IsCacheCoherentUMA);
#endif
#if NET6_0_OR_GREATER
using (ID3D12ResourceMap resource = allocation.Get()->GetResource()->Map())
#else
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
#endif
fixed (void* sourcePointer = &source)
{
MemoryHelper.Copy<T>(
source: sourcePointer,
destination: resource.Pointer,
sourceElementOffset: 0,
destinationElementOffset: 0,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)length);
}
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
#if NET6_0_OR_GREATER
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, (ulong)byteOffset, allocation.Get()->GetResource(), 0, (ulong)byteLength);
#else
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, (ulong)byteOffset, d3D12Resource.Get(), 0, (ulong)byteLength);
#endif
copyCommandList.ExecuteAndWaitForCompletion();
MemoryHelper.Copy<T>(
source: sourcePointer,
destination: resource.Pointer,
sourceElementOffset: 0,
destinationElementOffset: 0,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)length);
}
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
#if NET6_0_OR_GREATER
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, (ulong)byteOffset, allocation.Get()->GetResource(), 0, (ulong)byteLength);
#else
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, (ulong)byteOffset, d3D12Resource.Get(), 0, (ulong)byteLength);
#endif
copyCommandList.ExecuteAndWaitForCompletion();
}
}
@@ -280,38 +276,37 @@ public abstract class StructuredBuffer<T> : Buffer<T>
Guard.IsInRange(destinationOffset, 0, Length);
Guard.IsLessThanOrEqualTo(destinationOffset + count, Length, nameof(destinationOffset));
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (GetReferenceTracker().GetLease())
using (source.GetReferenceTracker().GetLease())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
using var _2 = source.GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
source.ThrowIfDeviceMismatch(GraphicsDevice);
if (GraphicsDevice.IsCacheCoherentUMA)
{
GraphicsDevice.ThrowIfDeviceLost();
using ID3D12ResourceMap resource = D3D12Resource->Map();
source.ThrowIfDeviceMismatch(GraphicsDevice);
MemoryHelper.Copy<T>(
source: source.MappedData,
destination: resource.Pointer,
sourceElementOffset: (uint)sourceOffset,
destinationElementOffset: (uint)destinationOffset,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)count);
}
else
{
ulong byteSourceOffset = (uint)sourceOffset * (uint)sizeof(T);
ulong byteOffset = (uint)destinationOffset * (uint)sizeof(T);
ulong byteLength = (uint)count * (uint)sizeof(T);
if (GraphicsDevice.IsCacheCoherentUMA)
{
using ID3D12ResourceMap resource = D3D12Resource->Map();
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
MemoryHelper.Copy<T>(
source: source.MappedData,
destination: resource.Pointer,
sourceElementOffset: (uint)sourceOffset,
destinationElementOffset: (uint)destinationOffset,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)count);
}
else
{
ulong byteSourceOffset = (uint)sourceOffset * (uint)sizeof(T);
ulong byteOffset = (uint)destinationOffset * (uint)sizeof(T);
ulong byteLength = (uint)count * (uint)sizeof(T);
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, byteOffset, source.D3D12Resource, byteSourceOffset, byteLength);
copyCommandList.ExecuteAndWaitForCompletion();
}
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, byteOffset, source.D3D12Resource, byteSourceOffset, byteLength);
copyCommandList.ExecuteAndWaitForCompletion();
}
}
}
+291 -301
ファイルの表示
@@ -75,66 +75,65 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
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())
using var _0 = device.GetReferenceTracker().GetLease();
device.ThrowIfDeviceLost();
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), d3D12FormatSupport))
{
device.ThrowIfDeviceLost();
UnsupportedTextureTypeException.ThrowForTexture2D<T>();
}
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), d3D12FormatSupport))
{
UnsupportedTextureTypeException.ThrowForTexture2D<T>();
}
GraphicsDevice = device;
GraphicsDevice = device;
#if NET6_0_OR_GREATER
this.allocation = device.Allocator->CreateResource(
device.Pool,
resourceType,
allocationMode,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
out this.d3D12ResourceState);
this.allocation = device.Allocator->CreateResource(
device.Pool,
resourceType,
allocationMode,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
out this.d3D12ResourceState);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
#else
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
resourceType,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
device.IsCacheCoherentUMA,
out this.d3D12ResourceState);
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
resourceType,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
device.IsCacheCoherentUMA,
out this.d3D12ResourceState);
#endif
this.d3D12CommandListType = this.d3D12ResourceState == D3D12_RESOURCE_STATE_COMMON
? D3D12_COMMAND_LIST_TYPE_COPY
: D3D12_COMMAND_LIST_TYPE_COMPUTE;
this.d3D12CommandListType = this.d3D12ResourceState == D3D12_RESOURCE_STATE_COMMON
? D3D12_COMMAND_LIST_TYPE_COPY
: D3D12_COMMAND_LIST_TYPE_COMPUTE;
device.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
out this.d3D12PlacedSubresourceFootprint,
out _,
out _);
device.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
out this.d3D12PlacedSubresourceFootprint,
out _,
out _);
device.RegisterAllocatedResource();
device.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandles);
device.RegisterAllocatedResource();
device.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandles);
switch (resourceType)
{
case ResourceType.ReadOnly:
device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_SRV_DIMENSION_TEXTURE2D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
break;
case ResourceType.ReadWrite:
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE2D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE2D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible);
break;
}
this.d3D12Resource.Get()->SetName(this);
switch (resourceType)
{
case ResourceType.ReadOnly:
device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_SRV_DIMENSION_TEXTURE2D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
break;
case ResourceType.ReadWrite:
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE2D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE2D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible);
break;
}
this.d3D12Resource.Get()->SetName(this);
}
/// <inheritdoc/>
@@ -179,74 +178,73 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height);
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (GetReferenceTracker().GetLease())
{
GraphicsDevice.ThrowIfDeviceLost();
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
GraphicsDevice.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprintDestination,
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
GraphicsDevice.ThrowIfDeviceLost();
GraphicsDevice.D3D12Device->GetCopyableFootprint(
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(
GraphicsDevice.Pool,
ResourceType.ReadBack,
AllocationMode.Default,
totalSizeInBytes);
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
GraphicsDevice.Pool,
ResourceType.ReadBack,
AllocationMode.Default,
totalSizeInBytes);
using ComPtr<ID3D12Resource> d3D12Resource = new(allocation.Get()->GetResource());
using ComPtr<ID3D12Resource> d3D12Resource = new(allocation.Get()->GetResource());
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.ReadBack,
totalSizeInBytes,
GraphicsDevice.IsCacheCoherentUMA);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.ReadBack,
totalSizeInBytes,
GraphicsDevice.IsCacheCoherentUMA);
#endif
using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
{
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: d3D12Resource.Get(),
&d3D12PlacedSubresourceFootprintDestination,
destinationX: 0,
destinationY: 0,
destinationZ: 0,
d3D12ResourceSource: D3D12Resource,
sourceX: (uint)sourceOffsetX,
sourceY: (uint)sourceOffsetY,
sourceZ: 0,
(uint)width,
(uint)height,
depth: 1);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
}
using ID3D12ResourceMap resource = d3D12Resource.Get()->Map();
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: d3D12Resource.Get(),
&d3D12PlacedSubresourceFootprintDestination,
destinationX: 0,
destinationY: 0,
destinationZ: 0,
d3D12ResourceSource: D3D12Resource,
sourceX: (uint)sourceOffsetX,
sourceY: (uint)sourceOffsetY,
sourceZ: 0,
(uint)width,
(uint)height,
depth: 1);
fixed (void* destinationPointer = &destination)
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
MemoryHelper.Copy(
resource.Pointer,
(uint)height,
rowSizeInBytes,
d3D12PlacedSubresourceFootprintDestination.Footprint.RowPitch,
destinationPointer);
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
}
using ID3D12ResourceMap resource = d3D12Resource.Get()->Map();
fixed (void* destinationPointer = &destination)
{
MemoryHelper.Copy(
resource.Pointer,
(uint)height,
rowSizeInBytes,
d3D12PlacedSubresourceFootprintDestination.Footprint.RowPitch,
destinationPointer);
}
}
@@ -275,49 +273,48 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
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())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
using var _2 = destination.GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
destination.ThrowIfDeviceMismatch(GraphicsDevice);
D3D12_COMMAND_LIST_TYPE d3D12CommandListType =
this.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE ||
destination.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE
? D3D12_COMMAND_LIST_TYPE_COMPUTE
: D3D12_COMMAND_LIST_TYPE_COPY;
using CommandList copyCommandList = new(GraphicsDevice, d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
GraphicsDevice.ThrowIfDeviceLost();
destination.ThrowIfDeviceMismatch(GraphicsDevice);
D3D12_COMMAND_LIST_TYPE d3D12CommandListType =
this.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE ||
destination.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE
? D3D12_COMMAND_LIST_TYPE_COMPUTE
: D3D12_COMMAND_LIST_TYPE_COPY;
using CommandList copyCommandList = new(GraphicsDevice, d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(destination.D3D12Resource, destination.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: destination.D3D12Resource,
(uint)destinationOffsetX,
(uint)destinationOffsetY,
destinationZ: 0,
d3D12ResourceSource: D3D12Resource,
(uint)sourceOffsetX,
(uint)sourceOffsetY,
sourceZ: 0,
(uint)width,
(uint)height,
1);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState);
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(destination.D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, destination.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(destination.D3D12Resource, destination.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: destination.D3D12Resource,
(uint)destinationOffsetX,
(uint)destinationOffsetY,
destinationZ: 0,
d3D12ResourceSource: D3D12Resource,
(uint)sourceOffsetX,
(uint)sourceOffsetY,
sourceZ: 0,
(uint)width,
(uint)height,
1);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState);
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(destination.D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, destination.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
}
/// <summary>
@@ -345,45 +342,44 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
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())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
using var _2 = destination.GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
destination.ThrowIfDeviceMismatch(GraphicsDevice);
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
GraphicsDevice.ThrowIfDeviceLost();
destination.ThrowIfDeviceMismatch(GraphicsDevice);
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
}
fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintDestination = &destination.D3D12PlacedSubresourceFootprint)
{
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: destination.D3D12Resource,
d3D12PlacedSubresourceFootprintDestination,
(uint)destinationOffsetX,
(uint)destinationOffsetY,
destinationZ: 0,
d3D12ResourceSource: D3D12Resource,
(uint)sourceOffsetX,
(uint)sourceOffsetY,
sourceZ: 0,
(uint)width,
(uint)height,
1);
}
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
}
fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintDestination = &destination.D3D12PlacedSubresourceFootprint)
{
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: destination.D3D12Resource,
d3D12PlacedSubresourceFootprintDestination,
(uint)destinationOffsetX,
(uint)destinationOffsetY,
destinationZ: 0,
d3D12ResourceSource: D3D12Resource,
(uint)sourceOffsetX,
(uint)sourceOffsetY,
sourceZ: 0,
(uint)width,
(uint)height,
1);
}
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
}
/// <summary>
@@ -405,73 +401,72 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
Guard.IsLessThanOrEqualTo(destinationOffsetY + height, Height, nameof(destinationOffsetY));
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height);
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (GetReferenceTracker().GetLease())
{
GraphicsDevice.ThrowIfDeviceLost();
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
GraphicsDevice.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprintSource,
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
GraphicsDevice.ThrowIfDeviceLost();
GraphicsDevice.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprintSource,
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
GraphicsDevice.Pool,
ResourceType.Upload,
AllocationMode.Default,
totalSizeInBytes);
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
GraphicsDevice.Pool,
ResourceType.Upload,
AllocationMode.Default,
totalSizeInBytes);
using ComPtr<ID3D12Resource> d3D12Resource = new(allocation.Get()->GetResource());
using ComPtr<ID3D12Resource> d3D12Resource = new(allocation.Get()->GetResource());
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.Upload,
totalSizeInBytes,
GraphicsDevice.IsCacheCoherentUMA);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.Upload,
totalSizeInBytes,
GraphicsDevice.IsCacheCoherentUMA);
#endif
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
fixed (void* sourcePointer = &source)
{
MemoryHelper.Copy(
sourcePointer,
resource.Pointer,
(uint)height,
rowSizeInBytes,
d3D12PlacedSubresourceFootprintSource.Footprint.RowPitch);
}
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: D3D12Resource,
destinationX: (uint)destinationOffsetX,
destinationY: (uint)destinationOffsetY,
destinationZ: 0,
d3D12ResourceSource: d3D12Resource.Get(),
&d3D12PlacedSubresourceFootprintSource,
sourceX: 0,
sourceY: 0,
sourceZ: 0,
(uint)width,
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
fixed (void* sourcePointer = &source)
{
MemoryHelper.Copy(
sourcePointer,
resource.Pointer,
(uint)height,
depth: 1);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
rowSizeInBytes,
d3D12PlacedSubresourceFootprintSource.Footprint.RowPitch);
}
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: D3D12Resource,
destinationX: (uint)destinationOffsetX,
destinationY: (uint)destinationOffsetY,
destinationZ: 0,
d3D12ResourceSource: d3D12Resource.Get(),
&d3D12PlacedSubresourceFootprintSource,
sourceX: 0,
sourceY: 0,
sourceZ: 0,
(uint)width,
(uint)height,
depth: 1);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
}
/// <summary>
@@ -499,45 +494,44 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
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())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
using var _2 = source.GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
source.ThrowIfDeviceMismatch(GraphicsDevice);
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
GraphicsDevice.ThrowIfDeviceLost();
source.ThrowIfDeviceMismatch(GraphicsDevice);
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
}
fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintSource = &source.D3D12PlacedSubresourceFootprint)
{
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: D3D12Resource,
(uint)destinationOffsetX,
(uint)destinationOffsetY,
destinationZ: 0,
d3D12ResourceSource: source.D3D12Resource,
d3D12PlacedSubresourceFootprintSource,
(uint)sourceOffsetX,
(uint)sourceOffsetY,
sourceZ: 0,
(uint)width,
(uint)height,
depth: 1);
}
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
}
fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintSource = &source.D3D12PlacedSubresourceFootprint)
{
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: D3D12Resource,
(uint)destinationOffsetX,
(uint)destinationOffsetY,
destinationZ: 0,
d3D12ResourceSource: source.D3D12Resource,
d3D12PlacedSubresourceFootprintSource,
(uint)sourceOffsetX,
(uint)sourceOffsetY,
sourceZ: 0,
(uint)width,
(uint)height,
depth: 1);
}
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
}
/// <inheritdoc/>
@@ -589,54 +583,50 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
/// <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 (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
isNormalized = DXGIFormatHelper.IsNormalizedType<T>();
ThrowIfDeviceMismatch(device);
return (this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible);
}
isNormalized = DXGIFormatHelper.IsNormalizedType<T>();
return (this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible);
}
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice)"/>
internal ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device)
{
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
return D3D12Resource;
}
ThrowIfDeviceMismatch(device);
return D3D12Resource;
}
/// <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 (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
D3D12_RESOURCE_STATES d3D12ResourceStatesBefore = this.d3D12ResourceState;
D3D12_RESOURCE_STATES d3D12ResourceStatesAfter = ResourceStateHelper.GetD3D12ResourceStates(resourceState);
ThrowIfDeviceMismatch(device);
this.d3D12ResourceState = d3D12ResourceStatesAfter;
D3D12_RESOURCE_STATES d3D12ResourceStatesBefore = this.d3D12ResourceState;
D3D12_RESOURCE_STATES d3D12ResourceStatesAfter = ResourceStateHelper.GetD3D12ResourceStates(resourceState);
d3D12Resource = D3D12Resource;
this.d3D12ResourceState = d3D12ResourceStatesAfter;
return (d3D12ResourceStatesBefore, d3D12ResourceStatesAfter);
}
d3D12Resource = D3D12Resource;
return (d3D12ResourceStatesBefore, d3D12ResourceStatesAfter);
}
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
return D3D12GpuDescriptorHandle;
}
ThrowIfDeviceMismatch(device);
return D3D12GpuDescriptorHandle;
}
/// <inheritdoc/>
+300 -310
ファイルの表示
@@ -77,69 +77,68 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
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())
using var _0 = device.GetReferenceTracker().GetLease();
device.ThrowIfDeviceLost();
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), d3D12FormatSupport))
{
device.ThrowIfDeviceLost();
UnsupportedTextureTypeException.ThrowForTexture3D<T>();
}
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), d3D12FormatSupport))
{
UnsupportedTextureTypeException.ThrowForTexture3D<T>();
}
GraphicsDevice = device;
GraphicsDevice = device;
#if NET6_0_OR_GREATER
this.allocation = device.Allocator->CreateResource(
device.Pool,
resourceType,
allocationMode,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
out this.d3D12ResourceState);
this.allocation = device.Allocator->CreateResource(
device.Pool,
resourceType,
allocationMode,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
out this.d3D12ResourceState);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
#else
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
resourceType,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
device.IsCacheCoherentUMA,
out this.d3D12ResourceState);
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
resourceType,
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
device.IsCacheCoherentUMA,
out this.d3D12ResourceState);
#endif
this.d3D12CommandListType = this.d3D12ResourceState == D3D12_RESOURCE_STATE_COMMON
? D3D12_COMMAND_LIST_TYPE_COPY
: D3D12_COMMAND_LIST_TYPE_COMPUTE;
this.d3D12CommandListType = this.d3D12ResourceState == D3D12_RESOURCE_STATE_COMMON
? D3D12_COMMAND_LIST_TYPE_COPY
: D3D12_COMMAND_LIST_TYPE_COMPUTE;
device.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
out this.d3D12PlacedSubresourceFootprint,
out _,
out _);
device.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
out this.d3D12PlacedSubresourceFootprint,
out _,
out _);
device.RegisterAllocatedResource();
device.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandles);
device.RegisterAllocatedResource();
device.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandles);
switch (resourceType)
{
case ResourceType.ReadOnly:
device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_SRV_DIMENSION_TEXTURE3D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
break;
case ResourceType.ReadWrite:
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE3D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE3D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible);
break;
}
this.d3D12Resource.Get()->SetName(this);
switch (resourceType)
{
case ResourceType.ReadOnly:
device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_SRV_DIMENSION_TEXTURE3D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
break;
case ResourceType.ReadWrite:
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE3D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE3D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible);
break;
}
this.d3D12Resource.Get()->SetName(this);
}
/// <inheritdoc/>
@@ -194,77 +193,76 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
Guard.IsLessThanOrEqualTo(sourceOffsetZ + depth, Depth, nameof(sourceOffsetZ));
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height * depth);
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (GetReferenceTracker().GetLease())
{
GraphicsDevice.ThrowIfDeviceLost();
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
GraphicsDevice.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprintDestination,
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
GraphicsDevice.ThrowIfDeviceLost();
GraphicsDevice.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
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(
GraphicsDevice.Pool,
ResourceType.ReadBack,
AllocationMode.Default,
totalSizeInBytes);
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
GraphicsDevice.Pool,
ResourceType.ReadBack,
AllocationMode.Default,
totalSizeInBytes);
using ComPtr<ID3D12Resource> d3D12Resource = new(allocation.Get()->GetResource());
using ComPtr<ID3D12Resource> d3D12Resource = new(allocation.Get()->GetResource());
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.ReadBack,
totalSizeInBytes,
GraphicsDevice.IsCacheCoherentUMA);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.ReadBack,
totalSizeInBytes,
GraphicsDevice.IsCacheCoherentUMA);
#endif
using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
{
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: d3D12Resource.Get(),
&d3D12PlacedSubresourceFootprintDestination,
destinationX: 0,
destinationY: 0,
destinationZ: 0,
d3D12ResourceSource: D3D12Resource,
sourceX: (uint)sourceOffsetX,
sourceY: (uint)sourceOffsetY,
sourceZ: (ushort)sourceOffsetZ,
(uint)width,
(uint)height,
(ushort)depth);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
}
using ID3D12ResourceMap resource = d3D12Resource.Get()->Map();
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: d3D12Resource.Get(),
&d3D12PlacedSubresourceFootprintDestination,
destinationX: 0,
destinationY: 0,
destinationZ: 0,
d3D12ResourceSource: D3D12Resource,
sourceX: (uint)sourceOffsetX,
sourceY: (uint)sourceOffsetY,
sourceZ: (ushort)sourceOffsetZ,
(uint)width,
(uint)height,
(ushort)depth);
fixed (void* destinationPointer = &destination)
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
MemoryHelper.Copy(
resource.Pointer,
(uint)height,
(uint)depth,
rowSizeInBytes,
d3D12PlacedSubresourceFootprintDestination.Footprint.RowPitch,
d3D12PlacedSubresourceFootprintDestination.Footprint.RowPitch * (uint)height,
destinationPointer);
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
}
using ID3D12ResourceMap resource = d3D12Resource.Get()->Map();
fixed (void* destinationPointer = &destination)
{
MemoryHelper.Copy(
resource.Pointer,
(uint)height,
(uint)depth,
rowSizeInBytes,
d3D12PlacedSubresourceFootprintDestination.Footprint.RowPitch,
d3D12PlacedSubresourceFootprintDestination.Footprint.RowPitch * (uint)height,
destinationPointer);
}
}
@@ -302,49 +300,48 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
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())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
using var _2 = destination.GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
destination.ThrowIfDeviceMismatch(GraphicsDevice);
D3D12_COMMAND_LIST_TYPE d3D12CommandListType =
this.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE ||
destination.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE
? D3D12_COMMAND_LIST_TYPE_COMPUTE
: D3D12_COMMAND_LIST_TYPE_COPY;
using CommandList copyCommandList = new(GraphicsDevice, d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
GraphicsDevice.ThrowIfDeviceLost();
destination.ThrowIfDeviceMismatch(GraphicsDevice);
D3D12_COMMAND_LIST_TYPE d3D12CommandListType =
this.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE ||
destination.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE
? D3D12_COMMAND_LIST_TYPE_COMPUTE
: D3D12_COMMAND_LIST_TYPE_COPY;
using CommandList copyCommandList = new(GraphicsDevice, d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(destination.D3D12Resource, destination.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: destination.D3D12Resource,
(uint)destinationOffsetX,
(uint)destinationOffsetY,
(ushort)destinationOffsetZ,
d3D12ResourceSource: D3D12Resource,
(uint)sourceOffsetX,
(uint)sourceOffsetY,
(ushort)sourceOffsetZ,
(uint)width,
(uint)height,
(ushort)depth);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState);
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(destination.D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, destination.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(destination.D3D12Resource, destination.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: destination.D3D12Resource,
(uint)destinationOffsetX,
(uint)destinationOffsetY,
(ushort)destinationOffsetZ,
d3D12ResourceSource: D3D12Resource,
(uint)sourceOffsetX,
(uint)sourceOffsetY,
(ushort)sourceOffsetZ,
(uint)width,
(uint)height,
(ushort)depth);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState);
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(destination.D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, destination.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
}
/// <summary>
@@ -381,45 +378,44 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
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())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
using var _2 = destination.GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
destination.ThrowIfDeviceMismatch(GraphicsDevice);
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
GraphicsDevice.ThrowIfDeviceLost();
destination.ThrowIfDeviceMismatch(GraphicsDevice);
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
}
fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintDestination = &destination.D3D12PlacedSubresourceFootprint)
{
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: destination.D3D12Resource,
d3D12PlacedSubresourceFootprintDestination,
(uint)destinationOffsetX,
(uint)destinationOffsetY,
(ushort)destinationOffsetZ,
d3D12ResourceSource: D3D12Resource,
(uint)sourceOffsetX,
(uint)sourceOffsetY,
(ushort)sourceOffsetZ,
(uint)width,
(uint)height,
(ushort)depth);
}
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
}
fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintDestination = &destination.D3D12PlacedSubresourceFootprint)
{
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: destination.D3D12Resource,
d3D12PlacedSubresourceFootprintDestination,
(uint)destinationOffsetX,
(uint)destinationOffsetY,
(ushort)destinationOffsetZ,
d3D12ResourceSource: D3D12Resource,
(uint)sourceOffsetX,
(uint)sourceOffsetY,
(ushort)sourceOffsetZ,
(uint)width,
(uint)height,
(ushort)depth);
}
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
}
/// <summary>
@@ -446,76 +442,75 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
Guard.IsLessThanOrEqualTo(destinationOffsetZ + depth, Depth, nameof(destinationOffsetZ));
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height * depth);
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (GetReferenceTracker().GetLease())
{
GraphicsDevice.ThrowIfDeviceLost();
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
GraphicsDevice.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprintSource,
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
GraphicsDevice.ThrowIfDeviceLost();
GraphicsDevice.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprintSource,
out ulong rowSizeInBytes,
out ulong totalSizeInBytes);
#if NET6_0_OR_GREATER
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
GraphicsDevice.Pool,
ResourceType.Upload,
AllocationMode.Default,
totalSizeInBytes);
using ComPtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(
GraphicsDevice.Pool,
ResourceType.Upload,
AllocationMode.Default,
totalSizeInBytes);
using ComPtr<ID3D12Resource> d3D12Resource = new(allocation.Get()->GetResource());
using ComPtr<ID3D12Resource> d3D12Resource = new(allocation.Get()->GetResource());
#else
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.Upload,
totalSizeInBytes,
GraphicsDevice.IsCacheCoherentUMA);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(
ResourceType.Upload,
totalSizeInBytes,
GraphicsDevice.IsCacheCoherentUMA);
#endif
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
fixed (void* sourcePointer = &source)
{
MemoryHelper.Copy(
sourcePointer,
resource.Pointer,
(uint)height,
(uint)depth,
rowSizeInBytes,
d3D12PlacedSubresourceFootprintSource.Footprint.RowPitch,
d3D12PlacedSubresourceFootprintSource.Footprint.RowPitch * (uint)height);
}
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: D3D12Resource,
destinationX: (uint)destinationOffsetX,
destinationY: (uint)destinationOffsetY,
destinationZ: (ushort)destinationOffsetZ,
d3D12ResourceSource: d3D12Resource.Get(),
&d3D12PlacedSubresourceFootprintSource,
sourceX: 0,
sourceY: 0,
sourceZ: 0,
(uint)width,
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
fixed (void* sourcePointer = &source)
{
MemoryHelper.Copy(
sourcePointer,
resource.Pointer,
(uint)height,
(ushort)depth);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
(uint)depth,
rowSizeInBytes,
d3D12PlacedSubresourceFootprintSource.Footprint.RowPitch,
d3D12PlacedSubresourceFootprintSource.Footprint.RowPitch * (uint)height);
}
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
}
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: D3D12Resource,
destinationX: (uint)destinationOffsetX,
destinationY: (uint)destinationOffsetY,
destinationZ: (ushort)destinationOffsetZ,
d3D12ResourceSource: d3D12Resource.Get(),
&d3D12PlacedSubresourceFootprintSource,
sourceX: 0,
sourceY: 0,
sourceZ: 0,
(uint)width,
(uint)height,
(ushort)depth);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
}
/// <summary>
@@ -552,45 +547,44 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
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())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
using var _2 = source.GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
source.ThrowIfDeviceMismatch(GraphicsDevice);
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
GraphicsDevice.ThrowIfDeviceLost();
source.ThrowIfDeviceMismatch(GraphicsDevice);
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
}
fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintSource = &source.D3D12PlacedSubresourceFootprint)
{
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: D3D12Resource,
(uint)destinationOffsetX,
(uint)destinationOffsetY,
(ushort)destinationOffsetZ,
d3D12ResourceSource: source.D3D12Resource,
d3D12PlacedSubresourceFootprintSource,
(uint)sourceOffsetX,
(uint)sourceOffsetY,
(ushort)sourceOffsetZ,
(uint)width,
(uint)height,
(ushort)depth);
}
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
}
fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintSource = &source.D3D12PlacedSubresourceFootprint)
{
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: D3D12Resource,
(uint)destinationOffsetX,
(uint)destinationOffsetY,
(ushort)destinationOffsetZ,
d3D12ResourceSource: source.D3D12Resource,
d3D12PlacedSubresourceFootprintSource,
(uint)sourceOffsetX,
(uint)sourceOffsetY,
(ushort)sourceOffsetZ,
(uint)width,
(uint)height,
(ushort)depth);
}
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
{
copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState);
}
copyCommandList.ExecuteAndWaitForCompletion();
}
/// <inheritdoc/>
@@ -642,54 +636,50 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
/// <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 (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
isNormalized = DXGIFormatHelper.IsNormalizedType<T>();
ThrowIfDeviceMismatch(device);
return (this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible);
}
isNormalized = DXGIFormatHelper.IsNormalizedType<T>();
return (this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible);
}
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice)"/>
internal ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device)
{
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
return D3D12Resource;
}
ThrowIfDeviceMismatch(device);
return D3D12Resource;
}
/// <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 (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
D3D12_RESOURCE_STATES d3D12ResourceStatesBefore = this.d3D12ResourceState;
D3D12_RESOURCE_STATES d3D12ResourceStatesAfter = ResourceStateHelper.GetD3D12ResourceStates(resourceState);
ThrowIfDeviceMismatch(device);
this.d3D12ResourceState = d3D12ResourceStatesAfter;
D3D12_RESOURCE_STATES d3D12ResourceStatesBefore = this.d3D12ResourceState;
D3D12_RESOURCE_STATES d3D12ResourceStatesAfter = ResourceStateHelper.GetD3D12ResourceStates(resourceState);
d3D12Resource = D3D12Resource;
this.d3D12ResourceState = d3D12ResourceStatesAfter;
return (d3D12ResourceStatesBefore, d3D12ResourceStatesAfter);
}
d3D12Resource = D3D12Resource;
return (d3D12ResourceStatesBefore, d3D12ResourceStatesAfter);
}
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
using (GetReferenceTracker().GetLease())
{
ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
return D3D12GpuDescriptorHandle;
}
ThrowIfDeviceMismatch(device);
return D3D12GpuDescriptorHandle;
}
/// <inheritdoc/>
+22 -26
ファイルの表示
@@ -47,28 +47,27 @@ public abstract unsafe class TransferBuffer<T> : NativeObject, IGraphicsResource
// 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();
using var _0 = device.GetReferenceTracker().GetLease();
GraphicsDevice = device;
Length = length;
device.ThrowIfDeviceLost();
ulong sizeInBytes = (uint)length * (uint)sizeof(T);
GraphicsDevice = device;
Length = length;
ulong sizeInBytes = (uint)length * (uint)sizeof(T);
#if NET6_0_OR_GREATER
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, sizeInBytes);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, sizeInBytes);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
#else
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, sizeInBytes, device.IsCacheCoherentUMA);
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, sizeInBytes, device.IsCacheCoherentUMA);
#endif
device.RegisterAllocatedResource();
device.RegisterAllocatedResource();
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
this.d3D12Resource.Get()->SetName(this);
}
this.d3D12Resource.Get()->SetName(this);
}
/// <inheritdoc/>
@@ -95,10 +94,9 @@ public abstract unsafe class TransferBuffer<T> : NativeObject, IGraphicsResource
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
using (GetReferenceTracker().GetLease())
{
return new MemoryManager(this).Memory;
}
using var _0 = GetReferenceTracker().GetLease();
return new MemoryManager(this).Memory;
}
}
@@ -108,10 +106,9 @@ public abstract unsafe class TransferBuffer<T> : NativeObject, IGraphicsResource
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
using (GetReferenceTracker().GetLease())
{
return new(this.mappedData, Length);
}
using var _0 = GetReferenceTracker().GetLease();
return new(this.mappedData, Length);
}
}
@@ -175,12 +172,11 @@ public abstract unsafe class TransferBuffer<T> : NativeObject, IGraphicsResource
/// <inheritdoc/>
public override MemoryHandle Pin(int elementIndex = 0)
{
using (this.buffer.GetReferenceTracker().GetLease())
{
Guard.IsEqualTo(elementIndex, 0);
Guard.IsEqualTo(elementIndex, 0);
return new(this.buffer.mappedData);
}
using var _0 = this.buffer.GetReferenceTracker().GetLease();
return new(this.buffer.mappedData);
}
/// <inheritdoc/>
+24 -26
ファイルの表示
@@ -53,38 +53,37 @@ public unsafe abstract class TransferTexture2D<T> : NativeObject, IGraphicsResou
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())
using var _0 = device.GetReferenceTracker().GetLease();
device.ThrowIfDeviceLost();
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE2D))
{
device.ThrowIfDeviceLost();
UnsupportedTextureTypeException.ThrowForTexture2D<T>();
}
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE2D))
{
UnsupportedTextureTypeException.ThrowForTexture2D<T>();
}
GraphicsDevice = device;
GraphicsDevice = device;
device.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
out this.d3D12PlacedSubresourceFootprint,
out _,
out ulong totalSizeInBytes);
device.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
out this.d3D12PlacedSubresourceFootprint,
out _,
out ulong totalSizeInBytes);
#if NET6_0_OR_GREATER
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, totalSizeInBytes);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, totalSizeInBytes);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
#else
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, totalSizeInBytes, device.IsCacheCoherentUMA);
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, totalSizeInBytes, device.IsCacheCoherentUMA);
#endif
device.RegisterAllocatedResource();
device.RegisterAllocatedResource();
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
this.d3D12Resource.Get()->SetName(this);
}
this.d3D12Resource.Get()->SetName(this);
}
/// <inheritdoc/>
@@ -116,10 +115,9 @@ public unsafe abstract class TransferTexture2D<T> : NativeObject, IGraphicsResou
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
using (this.GetReferenceTracker().GetLease())
{
return new(this.mappedData, Width, Height, (int)this.d3D12PlacedSubresourceFootprint.Footprint.RowPitch);
}
using var _0 = this.GetReferenceTracker().GetLease();
return new(this.mappedData, Width, Height, (int)this.d3D12PlacedSubresourceFootprint.Footprint.RowPitch);
}
}
+25 -27
ファイルの表示
@@ -55,39 +55,38 @@ public unsafe abstract class TransferTexture3D<T> : NativeObject, IGraphicsResou
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())
using var _0 = device.GetReferenceTracker().GetLease();
device.ThrowIfDeviceLost();
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE3D))
{
device.ThrowIfDeviceLost();
UnsupportedTextureTypeException.ThrowForTexture3D<T>();
}
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE3D))
{
UnsupportedTextureTypeException.ThrowForTexture3D<T>();
}
GraphicsDevice = device;
GraphicsDevice = device;
device.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
out this.d3D12PlacedSubresourceFootprint,
out _,
out ulong totalSizeInBytes);
device.D3D12Device->GetCopyableFootprint(
DXGIFormatHelper.GetForType<T>(),
(uint)width,
(uint)height,
(ushort)depth,
out this.d3D12PlacedSubresourceFootprint,
out _,
out ulong totalSizeInBytes);
#if NET6_0_OR_GREATER
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, totalSizeInBytes);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, totalSizeInBytes);
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
#else
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, totalSizeInBytes, device.IsCacheCoherentUMA);
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, totalSizeInBytes, device.IsCacheCoherentUMA);
#endif
device.RegisterAllocatedResource();
device.RegisterAllocatedResource();
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
this.d3D12Resource.Get()->SetName(this);
}
this.d3D12Resource.Get()->SetName(this);
}
/// <inheritdoc/>
@@ -124,10 +123,9 @@ public unsafe abstract class TransferTexture3D<T> : NativeObject, IGraphicsResou
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
using (this.GetReferenceTracker().GetLease())
{
return new(this.mappedData, Width, Height, Depth, (int)this.d3D12PlacedSubresourceFootprint.Footprint.RowPitch);
}
using var _0 = this.GetReferenceTracker().GetLease();
return new(this.mappedData, Width, Height, Depth, (int)this.d3D12PlacedSubresourceFootprint.Footprint.RowPitch);
}
}
+52 -55
ファイルの表示
@@ -61,24 +61,23 @@ public sealed class ConstantBuffer<T> : Buffer<T>
Guard.IsInRange(offset, 0, Length);
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(offset));
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (GetReferenceTracker().GetLease())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
using ID3D12ResourceMap resource = D3D12Resource->Map();
fixed (void* destinationPointer = &destination)
{
GraphicsDevice.ThrowIfDeviceLost();
using ID3D12ResourceMap resource = D3D12Resource->Map();
fixed (void* destinationPointer = &destination)
{
MemoryHelper.Copy<T>(
source: resource.Pointer,
destination: destinationPointer,
sourceElementOffset: (uint)offset,
destinationElementOffset: 0,
sourceElementPitchInBytes: (uint)GetPaddedSize(),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)length);
}
MemoryHelper.Copy<T>(
source: resource.Pointer,
destination: destinationPointer,
sourceElementOffset: (uint)offset,
destinationElementOffset: 0,
sourceElementPitchInBytes: (uint)GetPaddedSize(),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)length);
}
}
@@ -92,30 +91,29 @@ public sealed class ConstantBuffer<T> : Buffer<T>
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())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
using var _2 = destination.GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
destination.ThrowIfDeviceMismatch(GraphicsDevice);
if (destination is ConstantBuffer<T> buffer)
{
GraphicsDevice.ThrowIfDeviceLost();
using ID3D12ResourceMap sourceMap = D3D12Resource->Map();
using ID3D12ResourceMap destinationMap = buffer.D3D12Resource->Map();
destination.ThrowIfDeviceMismatch(GraphicsDevice);
if (destination is ConstantBuffer<T> buffer)
{
using ID3D12ResourceMap sourceMap = D3D12Resource->Map();
using ID3D12ResourceMap destinationMap = buffer.D3D12Resource->Map();
MemoryHelper.Copy<T>(
source: sourceMap.Pointer,
destination: destinationMap.Pointer,
sourceElementOffset: (uint)sourceOffset,
destinationElementOffset: (uint)destinationOffset,
sourceElementPitchInBytes: (uint)GetPaddedSize(),
destinationElementPitchInBytes: (uint)GetPaddedSize(),
count: (uint)length);
}
else CopyToWithCpuBuffer(destination, sourceOffset, destinationOffset, length);
MemoryHelper.Copy<T>(
source: sourceMap.Pointer,
destination: destinationMap.Pointer,
sourceElementOffset: (uint)sourceOffset,
destinationElementOffset: (uint)destinationOffset,
sourceElementPitchInBytes: (uint)GetPaddedSize(),
destinationElementPitchInBytes: (uint)GetPaddedSize(),
count: (uint)length);
}
else CopyToWithCpuBuffer(destination, sourceOffset, destinationOffset, length);
}
/// <inheritdoc/>
@@ -125,24 +123,23 @@ public sealed class ConstantBuffer<T> : Buffer<T>
Guard.IsInRange(offset, 0, Length);
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(offset));
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (GetReferenceTracker().GetLease())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
using ID3D12ResourceMap resource = D3D12Resource->Map();
fixed (void* sourcePointer = &source)
{
GraphicsDevice.ThrowIfDeviceLost();
using ID3D12ResourceMap resource = D3D12Resource->Map();
fixed (void* sourcePointer = &source)
{
MemoryHelper.Copy<T>(
source: sourcePointer,
destination: resource.Pointer,
sourceElementOffset: 0,
destinationElementOffset: (uint)offset,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)GetPaddedSize(),
count: (uint)length);
}
MemoryHelper.Copy<T>(
source: sourcePointer,
destination: resource.Pointer,
sourceElementOffset: 0,
destinationElementOffset: (uint)offset,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)GetPaddedSize(),
count: (uint)length);
}
}
+29 -32
ファイルの表示
@@ -24,28 +24,27 @@ partial class ReadWriteTexture2D<T, TPixel>
/// <inheritdoc cref="ReadWriteTexture2DExtensions.AsReadOnly{T, TPixel}(ReadWriteTexture2D{T, TPixel})"/>
internal IReadOnlyNormalizedTexture2D<TPixel> AsReadOnly()
{
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (GetReferenceTracker().GetLease())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
ThrowIfIsNotInReadOnlyState();
ReadOnly? readOnlyWrapper = this.readOnlyWrapper;
if (readOnlyWrapper is not null)
{
GraphicsDevice.ThrowIfDeviceLost();
ThrowIfIsNotInReadOnlyState();
ReadOnly? readOnlyWrapper = this.readOnlyWrapper;
if (readOnlyWrapper is not null)
{
return readOnlyWrapper;
}
[MethodImpl(MethodImplOptions.NoInlining)]
static ReadOnly InitializeWrapper(ReadWriteTexture2D<T, TPixel> texture)
{
return texture.readOnlyWrapper = new(texture);
}
return InitializeWrapper(this);
return readOnlyWrapper;
}
[MethodImpl(MethodImplOptions.NoInlining)]
static ReadOnly InitializeWrapper(ReadWriteTexture2D<T, TPixel> texture)
{
return texture.readOnlyWrapper = new(texture);
}
return InitializeWrapper(this);
}
/// <inheritdoc/>
@@ -108,13 +107,12 @@ partial class ReadWriteTexture2D<T, TPixel>
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
using (GetReferenceTracker().GetLease())
using (this.owner.GetReferenceTracker().GetLease())
{
this.owner.ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
using var _1 = this.owner.GetReferenceTracker().GetLease();
return this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle;
}
this.owner.ThrowIfDeviceMismatch(device);
return this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle;
}
/// <inheritdoc/>
@@ -126,13 +124,12 @@ partial class ReadWriteTexture2D<T, TPixel>
/// <inheritdoc/>
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device)
{
using (GetReferenceTracker().GetLease())
using (this.owner.GetReferenceTracker().GetLease())
{
this.owner.ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
using var _1 = this.owner.GetReferenceTracker().GetLease();
return this.owner.D3D12Resource;
}
this.owner.ThrowIfDeviceMismatch(device);
return this.owner.D3D12Resource;
}
/// <inheritdoc/>
+32 -35
ファイルの表示
@@ -24,31 +24,30 @@ partial class ReadWriteTexture2D<T>
/// <inheritdoc cref="ReadWriteTexture2DExtensions.AsReadOnly(ReadWriteTexture2D{float})"/>
public IReadOnlyTexture2D<T> AsReadOnly()
{
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (GetReferenceTracker().GetLease())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
ThrowIfIsNotInReadOnlyState();
ReadOnly? readOnlyWrapper = this.readOnlyWrapper;
if (readOnlyWrapper is not null)
{
GraphicsDevice.ThrowIfDeviceLost();
ThrowIfIsNotInReadOnlyState();
ReadOnly? readOnlyWrapper = this.readOnlyWrapper;
if (readOnlyWrapper is not null)
{
return readOnlyWrapper;
}
// The wrapper initialization is moved to a non inlined helper to keep the codegen of this method
// as compact as possible. If the current wrapper is not initialized, control goes directly to the
// helper that will initialize and return it, which translates to a single jump.
[MethodImpl(MethodImplOptions.NoInlining)]
static ReadOnly InitializeWrapper(ReadWriteTexture2D<T> texture)
{
return texture.readOnlyWrapper = new(texture);
}
return InitializeWrapper(this);
return readOnlyWrapper;
}
// The wrapper initialization is moved to a non inlined helper to keep the codegen of this method
// as compact as possible. If the current wrapper is not initialized, control goes directly to the
// helper that will initialize and return it, which translates to a single jump.
[MethodImpl(MethodImplOptions.NoInlining)]
static ReadOnly InitializeWrapper(ReadWriteTexture2D<T> texture)
{
return texture.readOnlyWrapper = new(texture);
}
return InitializeWrapper(this);
}
/// <inheritdoc/>
@@ -111,13 +110,12 @@ partial class ReadWriteTexture2D<T>
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
using (GetReferenceTracker().GetLease())
using (this.owner.GetReferenceTracker().GetLease())
{
this.owner.ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
using var _1 = this.owner.GetReferenceTracker().GetLease();
return this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle;
}
this.owner.ThrowIfDeviceMismatch(device);
return this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle;
}
/// <inheritdoc/>
@@ -129,13 +127,12 @@ partial class ReadWriteTexture2D<T>
/// <inheritdoc/>
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device)
{
using (GetReferenceTracker().GetLease())
using (this.owner.GetReferenceTracker().GetLease())
{
this.owner.ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
using var _1 = this.owner.GetReferenceTracker().GetLease();
return this.owner.D3D12Resource;
}
this.owner.ThrowIfDeviceMismatch(device);
return this.owner.D3D12Resource;
}
/// <inheritdoc/>
+29 -32
ファイルの表示
@@ -24,28 +24,27 @@ partial class ReadWriteTexture3D<T, TPixel>
/// <inheritdoc cref="ReadWriteTexture3DExtensions.AsReadOnly{T, TPixel}(ReadWriteTexture3D{T, TPixel})"/>
public IReadOnlyNormalizedTexture3D<TPixel> AsReadOnly()
{
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (GetReferenceTracker().GetLease())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
ThrowIfIsNotInReadOnlyState();
ReadOnly? readOnlyWrapper = this.readOnlyWrapper;
if (readOnlyWrapper is not null)
{
GraphicsDevice.ThrowIfDeviceLost();
ThrowIfIsNotInReadOnlyState();
ReadOnly? readOnlyWrapper = this.readOnlyWrapper;
if (readOnlyWrapper is not null)
{
return readOnlyWrapper;
}
[MethodImpl(MethodImplOptions.NoInlining)]
static ReadOnly InitializeWrapper(ReadWriteTexture3D<T, TPixel> texture)
{
return texture.readOnlyWrapper = new(texture);
}
return InitializeWrapper(this);
return readOnlyWrapper;
}
[MethodImpl(MethodImplOptions.NoInlining)]
static ReadOnly InitializeWrapper(ReadWriteTexture3D<T, TPixel> texture)
{
return texture.readOnlyWrapper = new(texture);
}
return InitializeWrapper(this);
}
/// <inheritdoc/>
@@ -111,13 +110,12 @@ partial class ReadWriteTexture3D<T, TPixel>
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
using (GetReferenceTracker().GetLease())
using (this.owner.GetReferenceTracker().GetLease())
{
this.owner.ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
using var _1 = this.owner.GetReferenceTracker().GetLease();
return this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle;
}
this.owner.ThrowIfDeviceMismatch(device);
return this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle;
}
/// <inheritdoc/>
@@ -129,13 +127,12 @@ partial class ReadWriteTexture3D<T, TPixel>
/// <inheritdoc/>
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device)
{
using (GetReferenceTracker().GetLease())
using (this.owner.GetReferenceTracker().GetLease())
{
this.owner.ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
using var _1 = this.owner.GetReferenceTracker().GetLease();
return this.owner.D3D12Resource;
}
this.owner.ThrowIfDeviceMismatch(device);
return this.owner.D3D12Resource;
}
/// <inheritdoc/>
+29 -32
ファイルの表示
@@ -24,28 +24,27 @@ partial class ReadWriteTexture3D<T>
/// <inheritdoc cref="ReadWriteTexture3DExtensions.AsReadOnly(ReadWriteTexture3D{float})"/>
public IReadOnlyTexture3D<T> AsReadOnly()
{
using (GraphicsDevice.GetReferenceTracker().GetLease())
using (GetReferenceTracker().GetLease())
using var _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using var _1 = GetReferenceTracker().GetLease();
GraphicsDevice.ThrowIfDeviceLost();
ThrowIfIsNotInReadOnlyState();
ReadOnly? readOnlyWrapper = this.readOnlyWrapper;
if (readOnlyWrapper is not null)
{
GraphicsDevice.ThrowIfDeviceLost();
ThrowIfIsNotInReadOnlyState();
ReadOnly? readOnlyWrapper = this.readOnlyWrapper;
if (readOnlyWrapper is not null)
{
return readOnlyWrapper;
}
[MethodImpl(MethodImplOptions.NoInlining)]
static ReadOnly InitializeWrapper(ReadWriteTexture3D<T> texture)
{
return texture.readOnlyWrapper = new(texture);
}
return InitializeWrapper(this);
return readOnlyWrapper;
}
[MethodImpl(MethodImplOptions.NoInlining)]
static ReadOnly InitializeWrapper(ReadWriteTexture3D<T> texture)
{
return texture.readOnlyWrapper = new(texture);
}
return InitializeWrapper(this);
}
/// <inheritdoc/>
@@ -111,13 +110,12 @@ partial class ReadWriteTexture3D<T>
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
using (GetReferenceTracker().GetLease())
using (this.owner.GetReferenceTracker().GetLease())
{
this.owner.ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
using var _1 = this.owner.GetReferenceTracker().GetLease();
return this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle;
}
this.owner.ThrowIfDeviceMismatch(device);
return this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle;
}
/// <inheritdoc/>
@@ -129,13 +127,12 @@ partial class ReadWriteTexture3D<T>
/// <inheritdoc/>
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device)
{
using (GetReferenceTracker().GetLease())
using (this.owner.GetReferenceTracker().GetLease())
{
this.owner.ThrowIfDeviceMismatch(device);
using var _0 = GetReferenceTracker().GetLease();
using var _1 = this.owner.GetReferenceTracker().GetLease();
return this.owner.D3D12Resource;
}
this.owner.ThrowIfDeviceMismatch(device);
return this.owner.D3D12Resource;
}
/// <inheritdoc/>