Add [Start|End|Full]Barrier APIs to ComputeContext type

このコミットが含まれているのは:
Sergio Pedri committed 2021-12-28 16:58:16 +01:00
1 親 c50ab7954f
コミット db01f40030
6ファイル変更
+319 -1

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

+8 -1
ファイルの表示
@@ -17,7 +17,7 @@ public static class GraphicsResourceHelper
/// <summary>
/// An interface for non-generic graphics resource types.
/// </summary>
internal interface IGraphicsResource
internal unsafe interface IGraphicsResource
{
/// <summary>
/// Validates the given resource for usage with a specified device, and retrieves its GPU descriptor handle.
@@ -25,6 +25,13 @@ public static class GraphicsResourceHelper
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
/// <returns>The GPU descriptor handle for the resource.</returns>
D3D12_GPU_DESCRIPTOR_HANDLE ValidateAndGetGpuDescriptorHandle(GraphicsDevice device);
/// <summary>
/// Validates the given resource for usage with a specified device, and retrieves the underlying <see cref="ID3D12Resource"/> object.
/// </summary>
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
/// <returns>The the underlying <see cref="ID3D12Resource"/> object.</returns>
ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device);
}
/// <summary>
+9
ファイルの表示
@@ -306,4 +306,13 @@ public abstract class StructuredBuffer<T> : Buffer<T>
copyCommandList.ExecuteAndWaitForCompletion();
}
}
/// <inheritdoc cref="__Internals.GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice)"/>
internal unsafe ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device)
{
ThrowIfDisposed();
ThrowIfDeviceMismatch(device);
return D3D12Resource;
}
}
+15
ファイルの表示
@@ -555,6 +555,15 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
}
}
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice)"/>
internal ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device)
{
ThrowIfDisposed();
ThrowIfDeviceMismatch(device);
return D3D12Resource;
}
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
@@ -563,4 +572,10 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
return D3D12GpuDescriptorHandle;
}
/// <inheritdoc/>
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device)
{
return ValidateAndGetID3D12Resource(device);
}
}
+15
ファイルの表示
@@ -608,6 +608,15 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
}
}
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice)"/>
internal ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device)
{
ThrowIfDisposed();
ThrowIfDeviceMismatch(device);
return D3D12Resource;
}
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
@@ -616,4 +625,10 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
return D3D12GpuDescriptorHandle;
}
/// <inheritdoc/>
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device)
{
return ValidateAndGetID3D12Resource(device);
}
}
+5
ファイルの表示
@@ -37,6 +37,11 @@ public ref struct ComputeContext
this.commandList = default;
}
/// <summary>
/// Gets the <see cref="ComputeSharp.GraphicsDevice"/> associated with the current instance.
/// </summary>
public GraphicsDevice GraphicsDevice => this.device;
/// <summary>
/// Starts a resource barrier for a specific resource.
/// </summary>
+267
ファイルの表示
@@ -1,4 +1,7 @@
using System.Runtime.CompilerServices;
using ComputeSharp.__Internals;
#pragma warning disable CS0618
namespace ComputeSharp;
@@ -7,6 +10,270 @@ namespace ComputeSharp;
/// </summary>
public static partial class ComputeContextExtensions
{
/// <summary>
/// Starts a resource barrier for 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 insert the resource barrier.</param>
/// <param name="buffer">The input <see cref="ReadWriteBuffer{T}"/> instance to start the barrier for.</param>
public static unsafe void StartBarrier<T>(this in ComputeContext context, ReadWriteBuffer<T> buffer)
where T : unmanaged
{
context.StartBarrier(buffer.ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Starts a resource barrier for a specific resource.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="context">The <see cref="ComputeContext"/> to use to insert the resource barrier.</param>
/// <param name="texture">The input <see cref="ReadWriteTexture2D{T}"/> instance to start the barrier for.</param>
public static unsafe void StartBarrier<T>(this in ComputeContext context, ReadWriteTexture2D<T> texture)
where T : unmanaged
{
context.StartBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Starts a resource barrier for a specific resource.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="context">The <see cref="ComputeContext"/> to use to insert the resource barrier.</param>
/// <param name="texture">The input <see cref="ReadWriteBuffer{T}"/> instance to start the barrier for.</param>
public static unsafe void StartBarrier<T>(this in ComputeContext context, ReadWriteTexture3D<T> texture)
where T : unmanaged
{
context.StartBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Starts a resource barrier for a specific resource.
/// </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 insert the resource barrier.</param>
/// <param name="texture">The input <see cref="ReadWriteTexture2D{T,TPixel}"/> instance to start the barrier for.</param>
public static unsafe void StartBarrier<T, TPixel>(this in ComputeContext context, ReadWriteTexture2D<T, TPixel> texture)
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
context.StartBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Starts a resource barrier for a specific resource.
/// </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 insert the resource barrier.</param>
/// <param name="texture">The input <see cref="ReadWriteTexture3D{T,TPixel}"/> instance to start the barrier for.</param>
public static unsafe void StartBarrier<T, TPixel>(this in ComputeContext context, ReadWriteTexture3D<T, TPixel> texture)
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
context.StartBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Starts a resource barrier for a specific resource.
/// </summary>
/// <typeparam name="TPixel">The type of pixels stored on the texture.</typeparam>
/// <param name="context">The <see cref="ComputeContext"/> to use to insert the resource barrier.</param>
/// <param name="texture">The input <see cref="IReadWriteTexture2D{TPixel}"/> instance to start the barrier for.</param>
public static unsafe void StartBarrier<TPixel>(this in ComputeContext context, IReadWriteTexture2D<TPixel> texture)
where TPixel : unmanaged
{
context.StartBarrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Starts a resource barrier for a specific resource.
/// </summary>
/// <typeparam name="TPixel">The type of pixels stored on the texture.</typeparam>
/// <param name="context">The <see cref="ComputeContext"/> to use to insert the resource barrier.</param>
/// <param name="texture">The input <see cref="IReadWriteTexture3D{TPixel}"/> instance to start the barrier for.</param>
public static unsafe void StartBarrier<TPixel>(this in ComputeContext context, IReadWriteTexture3D<TPixel> texture)
where TPixel : unmanaged
{
context.StartBarrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Ends a resource barrier for 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 insert the resource barrier.</param>
/// <param name="buffer">The input <see cref="ReadWriteBuffer{T}"/> instance to end the barrier for.</param>
public static unsafe void EndBarrier<T>(this in ComputeContext context, ReadWriteBuffer<T> buffer)
where T : unmanaged
{
context.EndBarrier(buffer.ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Ends a resource barrier for a specific resource.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="context">The <see cref="ComputeContext"/> to use to insert the resource barrier.</param>
/// <param name="texture">The input <see cref="ReadWriteTexture2D{T}"/> instance to end the barrier for.</param>
public static unsafe void EndBarrier<T>(this in ComputeContext context, ReadWriteTexture2D<T> texture)
where T : unmanaged
{
context.EndBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Ends a resource barrier for a specific resource.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="context">The <see cref="ComputeContext"/> to use to insert the resource barrier.</param>
/// <param name="texture">The input <see cref="ReadWriteBuffer{T}"/> instance to end the barrier for.</param>
public static unsafe void EndBarrier<T>(this in ComputeContext context, ReadWriteTexture3D<T> texture)
where T : unmanaged
{
context.EndBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Ends a resource barrier for a specific resource.
/// </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 insert the resource barrier.</param>
/// <param name="texture">The input <see cref="ReadWriteTexture2D{T,TPixel}"/> instance to end the barrier for.</param>
public static unsafe void EndBarrier<T, TPixel>(this in ComputeContext context, ReadWriteTexture2D<T, TPixel> texture)
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
context.EndBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Ends a resource barrier for a specific resource.
/// </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 insert the resource barrier.</param>
/// <param name="texture">The input <see cref="ReadWriteTexture3D{T,TPixel}"/> instance to end the barrier for.</param>
public static unsafe void EndBarrier<T, TPixel>(this in ComputeContext context, ReadWriteTexture3D<T, TPixel> texture)
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
context.EndBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Ends a resource barrier for a specific resource.
/// </summary>
/// <typeparam name="TPixel">The type of pixels stored on the texture.</typeparam>
/// <param name="context">The <see cref="ComputeContext"/> to use to insert the resource barrier.</param>
/// <param name="texture">The input <see cref="IReadWriteTexture2D{TPixel}"/> instance to end the barrier for.</param>
public static unsafe void EndBarrier<TPixel>(this in ComputeContext context, IReadWriteTexture2D<TPixel> texture)
where TPixel : unmanaged
{
context.EndBarrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Ends a resource barrier for a specific resource.
/// </summary>
/// <typeparam name="TPixel">The type of pixels stored on the texture.</typeparam>
/// <param name="context">The <see cref="ComputeContext"/> to use to insert the resource barrier.</param>
/// <param name="texture">The input <see cref="IReadWriteTexture3D{TPixel}"/> instance to end the barrier for.</param>
public static unsafe void EndBarrier<TPixel>(this in ComputeContext context, IReadWriteTexture3D<TPixel> texture)
where TPixel : unmanaged
{
context.EndBarrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Inserts a full resource barrier for 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 insert the resource barrier.</param>
/// <param name="buffer">The input <see cref="ReadWriteBuffer{T}"/> instance to insert the barrier for.</param>
public static unsafe void FullBarrier<T>(this in ComputeContext context, ReadWriteBuffer<T> buffer)
where T : unmanaged
{
context.FullBarrier(buffer.ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Inserts a full resource barrier for a specific resource.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="context">The <see cref="ComputeContext"/> to use to insert the resource barrier.</param>
/// <param name="texture">The input <see cref="ReadWriteTexture2D{T}"/> instance to insert the barrier for.</param>
public static unsafe void FullBarrier<T>(this in ComputeContext context, ReadWriteTexture2D<T> texture)
where T : unmanaged
{
context.FullBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Inserts a full resource barrier for a specific resource.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="context">The <see cref="ComputeContext"/> to use to insert the resource barrier.</param>
/// <param name="texture">The input <see cref="ReadWriteBuffer{T}"/> instance to insert the barrier for.</param>
public static unsafe void FullBarrier<T>(this in ComputeContext context, ReadWriteTexture3D<T> texture)
where T : unmanaged
{
context.FullBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Inserts a full resource barrier for a specific resource.
/// </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 insert the resource barrier.</param>
/// <param name="texture">The input <see cref="ReadWriteTexture2D{T,TPixel}"/> instance to insert the barrier for.</param>
public static unsafe void FullBarrier<T, TPixel>(this in ComputeContext context, ReadWriteTexture2D<T, TPixel> texture)
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
context.FullBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Inserts a full resource barrier for a specific resource.
/// </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 insert the resource barrier.</param>
/// <param name="texture">The input <see cref="ReadWriteTexture3D{T,TPixel}"/> instance to insert the barrier for.</param>
public static unsafe void FullBarrier<T, TPixel>(this in ComputeContext context, ReadWriteTexture3D<T, TPixel> texture)
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
context.FullBarrier(texture.ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Inserts a full resource barrier for a specific resource.
/// </summary>
/// <typeparam name="TPixel">The type of pixels stored on the texture.</typeparam>
/// <param name="context">The <see cref="ComputeContext"/> to use to insert the resource barrier.</param>
/// <param name="texture">The input <see cref="IReadWriteTexture2D{TPixel}"/> instance to insert the barrier for.</param>
public static unsafe void FullBarrier<TPixel>(this in ComputeContext context, IReadWriteTexture2D<TPixel> texture)
where TPixel : unmanaged
{
context.FullBarrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Inserts a full resource barrier for a specific resource.
/// </summary>
/// <typeparam name="TPixel">The type of pixels stored on the texture.</typeparam>
/// <param name="context">The <see cref="ComputeContext"/> to use to insert the resource barrier.</param>
/// <param name="texture">The input <see cref="IReadWriteTexture3D{TPixel}"/> instance to insert the barrier for.</param>
public static unsafe void FullBarrier<TPixel>(this in ComputeContext context, IReadWriteTexture3D<TPixel> texture)
where TPixel : unmanaged
{
context.FullBarrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice));
}
/// <summary>
/// Runs the input shader on a target <see cref="ComputeContext"/> instance, with the specified parameters.
/// </summary>