diff --git a/src/ComputeSharp/Shaders/ComputeContext.cs b/src/ComputeSharp/Shaders/ComputeContext.cs
index aa28245a..304ca785 100644
--- a/src/ComputeSharp/Shaders/ComputeContext.cs
+++ b/src/ComputeSharp/Shaders/ComputeContext.cs
@@ -253,6 +253,24 @@ public struct ComputeContext : IDisposable, IAsyncDisposable
commandList.D3D12GraphicsCommandList->Dispatch((uint)groupsX, (uint)groupsY, 1);
}
+ ///
+ /// Inserts a transition for a specific resource.
+ ///
+ /// The to change state for.
+ /// The starting value for the transition.
+ /// The destnation value for the transition.
+ internal readonly unsafe void Transition(
+ ID3D12Resource* d3D12Resource,
+ D3D12_RESOURCE_STATES d3D12ResourceStatesBefore,
+ D3D12_RESOURCE_STATES d3D12ResourceStatesAfter)
+ {
+ ThrowInvalidOperationExceptionIfDeviceIsNull();
+
+ ref CommandList commandList = ref GetCommandList(in this, null);
+
+ commandList.D3D12GraphicsCommandList->TransitionBarrier(d3D12Resource, d3D12ResourceStatesBefore, d3D12ResourceStatesAfter);
+ }
+
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose()
diff --git a/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs b/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs
index d288d243..0ef89976 100644
--- a/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs
+++ b/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs
@@ -1,6 +1,7 @@
using System.Runtime.CompilerServices;
using ComputeSharp.__Internals;
using ComputeSharp.Graphics.Helpers;
+using TerraFX.Interop.DirectX;
#pragma warning disable CS0618
@@ -361,4 +362,38 @@ public static class ComputeContextExtensions
{
context.Run(texture, ref Unsafe.AsRef(in shader));
}
+
+ ///
+ /// Transitions the state of a specific resource.
+ ///
+ /// The type of items stored on the texture.
+ /// The type of pixels used on the GPU side.
+ /// The to use to transition the resource.
+ /// The input instance to transition.
+ /// The state to transition the input resource to.
+ public static unsafe void Transition(this in ComputeContext context, ReadWriteTexture2D texture, ResourceState resourceState)
+ where T : unmanaged, IPixel
+ where TPixel : unmanaged
+ {
+ var states = texture.ValidateAndGetID3D12ResourceAndTransitionStates(context.GraphicsDevice, resourceState, out ID3D12Resource* d3D12Resource);
+
+ context.Transition(d3D12Resource, states.Before, states.After);
+ }
+
+ ///
+ /// Transitions the state of a specific resource.
+ ///
+ /// The type of items stored on the texture.
+ /// The type of pixels used on the GPU side.
+ /// The to use to transition the resource.
+ /// The input instance to transition.
+ /// The state to transition the input resource to.
+ public static unsafe void Transition(this in ComputeContext context, ReadWriteTexture3D texture, ResourceState resourceState)
+ where T : unmanaged, IPixel
+ where TPixel : unmanaged
+ {
+ var states = texture.ValidateAndGetID3D12ResourceAndTransitionStates(context.GraphicsDevice, resourceState, out ID3D12Resource* d3D12Resource);
+
+ context.Transition(d3D12Resource, states.Before, states.After);
+ }
}