Add initial prototype of Clear APIs
このコミットが含まれているのは:
1 親
81da448200
コミット
2ceb3b83f6
4ファイル変更
+177
-5
検索条件に一致するファイルはありません
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using static TerraFX.Interop.DirectX.D3D12_RESOURCE_BARRIER_FLAGS;
|
||||
using static TerraFX.Interop.DirectX.D3D12_RESOURCE_BARRIER_TYPE;
|
||||
|
||||
namespace ComputeSharp.Graphics.Extensions;
|
||||
|
||||
@@ -213,13 +212,58 @@ internal static unsafe class ID3D12GraphicsCommandListExtensions
|
||||
/// </summary>
|
||||
/// <param name="d3D12GraphicsCommandList">The <see cref="ID3D12GraphicsCommandList"/> instance in use.</param>
|
||||
/// <param name="d3D12Resource">The <see cref="ID3D12Resource"/> to insert the barrier for.</param>
|
||||
public static void UAVBarrier(this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList, ID3D12Resource* d3D12Resource)
|
||||
public static void UnorderedAccessViewBarrier(this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList, ID3D12Resource* d3D12Resource)
|
||||
{
|
||||
D3D12_RESOURCE_BARRIER d3D12ResourceBarrier = D3D12_RESOURCE_BARRIER.InitUAV(d3D12Resource);
|
||||
|
||||
d3D12GraphicsCommandList.ResourceBarrier(1, &d3D12ResourceBarrier);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears a target UAV resource.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="d3D12GraphicsCommandList">The <see cref="ID3D12GraphicsCommandList"/> instance in use.</param>
|
||||
/// <param name="d3D12Resource">The <see cref="ID3D12Resource"/> to clear.</param>
|
||||
/// <param name="d3D12GpuDescriptorHandle">The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value for the target resource.</param>
|
||||
/// <param name="d3D12CpuDescriptorHandle">The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value for the target resource.</param>
|
||||
public static unsafe void ClearUnorderedAccessView<T>(
|
||||
this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList,
|
||||
ID3D12Resource* d3D12Resource,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle)
|
||||
where T : unmanaged
|
||||
{
|
||||
if (typeof(T) == typeof(uint))
|
||||
{
|
||||
UInt4 values = default;
|
||||
|
||||
d3D12GraphicsCommandList.ClearUnorderedAccessViewUint(
|
||||
ViewGPUHandleInCurrentHeap: d3D12GpuDescriptorHandle,
|
||||
ViewCPUHandle: d3D12CpuDescriptorHandle,
|
||||
pResource: d3D12Resource,
|
||||
Values: (uint*)&values,
|
||||
NumRects: 0,
|
||||
pRects: null);
|
||||
}
|
||||
else if (typeof(T) == typeof(float))
|
||||
{
|
||||
Float4 values = default;
|
||||
|
||||
d3D12GraphicsCommandList.ClearUnorderedAccessViewFloat(
|
||||
ViewGPUHandleInCurrentHeap: d3D12GpuDescriptorHandle,
|
||||
ViewCPUHandle: d3D12CpuDescriptorHandle,
|
||||
pResource: d3D12Resource,
|
||||
Values: (float*)&values,
|
||||
NumRects: 0,
|
||||
pRects: null);
|
||||
}
|
||||
else
|
||||
{
|
||||
ThrowHelper.ThrowArgumentException("Invalid clear type");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Binds an input constant buffer to the first root parameter.
|
||||
/// </summary>
|
||||
|
||||
@@ -42,6 +42,25 @@ public ref struct ComputeContext
|
||||
/// </summary>
|
||||
public GraphicsDevice GraphicsDevice => this.device;
|
||||
|
||||
/// <summary>
|
||||
/// Clears a specific resource.
|
||||
/// </summary>
|
||||
/// <param name="d3D12Resource">The <see cref="ID3D12Resource"/> to clear.</param>
|
||||
/// <param name="d3D12GpuDescriptorHandle">The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value for the target resource.</param>
|
||||
/// <param name="d3D12CpuDescriptorHandle">The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value for the target resource.</param>
|
||||
internal readonly unsafe void Clear<T>(
|
||||
ID3D12Resource* d3D12Resource,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle)
|
||||
where T : unmanaged
|
||||
{
|
||||
ThrowInvalidOperationExceptionIfDeviceIsNull();
|
||||
|
||||
ref CommandList commandList = ref GetCommandList(in this, null);
|
||||
|
||||
commandList.D3D12GraphicsCommandList->ClearUnorderedAccessView<T>(d3D12Resource, d3D12GpuDescriptorHandle, d3D12CpuDescriptorHandle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts a resource barrier for a specific resource.
|
||||
/// </summary>
|
||||
@@ -52,7 +71,7 @@ public ref struct ComputeContext
|
||||
|
||||
ref CommandList commandList = ref GetCommandList(in this);
|
||||
|
||||
commandList.D3D12GraphicsCommandList->UAVBarrier(d3D12Resource);
|
||||
commandList.D3D12GraphicsCommandList->UnorderedAccessViewBarrier(d3D12Resource);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -253,7 +272,12 @@ public ref struct ComputeContext
|
||||
|
||||
if (context.commandList.IsAllocated)
|
||||
{
|
||||
context.commandList.D3D12GraphicsCommandList->SetPipelineState(pipelineState);
|
||||
// Skip setting the pipeline state if the new state is null. This is the case when the upcoming
|
||||
// operation is not a shader dispatch, but just a resource clear. In this case there is no state.
|
||||
if (pipelineState is not null)
|
||||
{
|
||||
context.commandList.D3D12GraphicsCommandList->SetPipelineState(pipelineState);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -98,6 +98,96 @@ public static partial class ComputeContextExtensions
|
||||
context.Barrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears a specific resource.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
|
||||
/// <param name="context">The <see cref="ComputeContext"/> to use to clear the resource.</param>
|
||||
/// <param name="buffer">The input <see cref="ReadWriteBuffer{T}"/> instance to clear.</param>
|
||||
public static unsafe void Clear<T>(this in ComputeContext context, ReadWriteBuffer<T> buffer)
|
||||
where T : unmanaged
|
||||
{
|
||||
var handles = buffer.ValidateAndGetGpuAndCpuDescriptorHandles(context.GraphicsDevice);
|
||||
|
||||
context.Clear<uint>(buffer.D3D12Resource, handles.Gpu, handles.Cpu);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears a specific resource, with a specified value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="context">The <see cref="ComputeContext"/> to use to clear the resource.</param>
|
||||
/// <param name="texture">The input <see cref="ReadWriteTexture2D{T}"/> instance to clear.</param>
|
||||
public static unsafe void Clear<T>(this in ComputeContext context, ReadWriteTexture2D<T> texture)
|
||||
where T : unmanaged
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears a specific resource, with a specified value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="context">The <see cref="ComputeContext"/> to use to clear the resource.</param>
|
||||
/// <param name="texture">The input <see cref="ReadWriteBuffer{T}"/> instance to clear.</param>
|
||||
public static unsafe void Clear<T>(this in ComputeContext context, ReadWriteTexture3D<T> texture)
|
||||
where T : unmanaged
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears a specific resource, with a specified value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
|
||||
/// <param name="context">The <see cref="ComputeContext"/> to use to clear the resource.</param>
|
||||
/// <param name="texture">The input <see cref="ReadWriteTexture2D{T,TPixel}"/> instance to clear.</param>
|
||||
public static unsafe void Clear<T, TPixel>(this in ComputeContext context, ReadWriteTexture2D<T, TPixel> texture)
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears a specific resource, with a specified value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
|
||||
/// <param name="context">The <see cref="ComputeContext"/> to use to clear the resource.</param>
|
||||
/// <param name="texture">The input <see cref="ReadWriteTexture3D{T,TPixel}"/> instance to clear.</param>
|
||||
public static unsafe void Clear<T, TPixel>(this in ComputeContext context, ReadWriteTexture3D<T, TPixel> texture)
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears a specific resource, with a specified value.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of pixels stored on the texture.</typeparam>
|
||||
/// <param name="context">The <see cref="ComputeContext"/> to use to clear the resource.</param>
|
||||
/// <param name="texture">The input <see cref="IReadWriteTexture2D{TPixel}"/> instance to clear.</param>
|
||||
public static unsafe void Clear<TPixel>(this in ComputeContext context, IReadWriteTexture2D<TPixel> texture)
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears a specific resource, with a specified value.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of pixels stored on the texture.</typeparam>
|
||||
/// <param name="context">The <see cref="ComputeContext"/> to use to clear the resource.</param>
|
||||
/// <param name="texture">The input <see cref="IReadWriteTexture3D{TPixel}"/> instance to clear.</param>
|
||||
public static unsafe void Clear<TPixel>(this in ComputeContext context, IReadWriteTexture3D<TPixel> texture)
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs the input shader on a target <see cref="ComputeContext"/> instance, with the specified parameters.
|
||||
/// </summary>
|
||||
|
||||
@@ -298,5 +298,19 @@ namespace TerraFX.Interop.DirectX
|
||||
{
|
||||
((delegate* unmanaged[Stdcall]<ID3D12GraphicsCommandList*, uint, ulong, void>)(lpVtbl[42]))((ID3D12GraphicsCommandList*)Unsafe.AsPointer(ref this), RootParameterIndex, BufferLocation);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(49)]
|
||||
public void ClearUnorderedAccessViewUint(D3D12_GPU_DESCRIPTOR_HANDLE ViewGPUHandleInCurrentHeap, D3D12_CPU_DESCRIPTOR_HANDLE ViewCPUHandle, ID3D12Resource* pResource, [NativeTypeName("const UINT [4]")] uint* Values, uint NumRects, [NativeTypeName("const D3D12_RECT *")] void* pRects)
|
||||
{
|
||||
((delegate* unmanaged[Stdcall]<ID3D12GraphicsCommandList*, D3D12_GPU_DESCRIPTOR_HANDLE, D3D12_CPU_DESCRIPTOR_HANDLE, ID3D12Resource*, uint*, uint, void*, void>)(lpVtbl[49]))((ID3D12GraphicsCommandList*)Unsafe.AsPointer(ref this), ViewGPUHandleInCurrentHeap, ViewCPUHandle, pResource, Values, NumRects, pRects);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(50)]
|
||||
public void ClearUnorderedAccessViewFloat(D3D12_GPU_DESCRIPTOR_HANDLE ViewGPUHandleInCurrentHeap, D3D12_CPU_DESCRIPTOR_HANDLE ViewCPUHandle, ID3D12Resource* pResource, [NativeTypeName("const FLOAT [4]")] float* Values, uint NumRects, [NativeTypeName("const D3D12_RECT *")] void* pRects)
|
||||
{
|
||||
((delegate* unmanaged[Stdcall]<ID3D12GraphicsCommandList*, D3D12_GPU_DESCRIPTOR_HANDLE, D3D12_CPU_DESCRIPTOR_HANDLE, ID3D12Resource*, float*, uint, void*, void>)(lpVtbl[50]))((ID3D12GraphicsCommandList*)Unsafe.AsPointer(ref this), ViewGPUHandleInCurrentHeap, ViewCPUHandle, pResource, Values, NumRects, pRects);
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする