Add ResourceState type and internal IGraphicsResource helpers

このコミットが含まれているのは:
Sergio Pedri committed 2022-01-17 00:29:37 +01:00
1 親 44e28ebd49
コミット 189da1aa11
5ファイル変更
+115 -10

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

+9
ファイルの表示
@@ -40,6 +40,15 @@ public static class GraphicsResourceHelper
/// <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>
/// Validates the given resource for usage with a specified device, and retrieves the underlying <see cref="ID3D12Resource"/> object, along with the transition states.
/// </summary>
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
/// <param name="resourceState">The target state to transition the resource to.</param>
/// <param name="d3D12Resource">The the underlying <see cref="ID3D12Resource"/> object.</param>
/// <returns>The resource states for <paramref name="d3D12Resource"/>, before and after the transition.</returns>
(D3D12_RESOURCE_STATES Before, D3D12_RESOURCE_STATES After) ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource);
}
/// <summary>
+28 -5
ファイルの表示
@@ -5,6 +5,7 @@ using ComputeSharp.Graphics.Commands;
using ComputeSharp.Graphics.Commands.Interop;
using ComputeSharp.Graphics.Extensions;
using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Graphics.Resources.Helpers;
using ComputeSharp.Graphics.Resources.Interop;
using ComputeSharp.Interop;
using Microsoft.Toolkit.Diagnostics;
@@ -44,11 +45,6 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
/// </summary>
private readonly ID3D12ResourceDescriptorHandles d3D12ResourceDescriptorHandles;
/// <summary>
/// The default <see cref="D3D12_RESOURCE_STATES"/> value for the current resource.
/// </summary>
private readonly D3D12_RESOURCE_STATES d3D12ResourceState;
/// <summary>
/// The <see cref="D3D12_COMMAND_LIST_TYPE"/> value to use for copy operations.
/// </summary>
@@ -59,6 +55,11 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
/// </summary>
private readonly D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint;
/// <summary>
/// The current <see cref="D3D12_RESOURCE_STATES"/> value for the current resource.
/// </summary>
private D3D12_RESOURCE_STATES d3D12ResourceState;
/// <summary>
/// Creates a new <see cref="Texture2D{T}"/> instance with the specified parameters.
/// </summary>
@@ -572,6 +573,22 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
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)
{
ThrowIfDisposed();
ThrowIfDeviceMismatch(device);
D3D12_RESOURCE_STATES d3D12ResourceStatesBefore = this.d3D12ResourceState;
D3D12_RESOURCE_STATES d3D12ResourceStatesAfter = ResourceStateHelper.GetD3D12ResourceStates(resourceState);
this.d3D12ResourceState = d3D12ResourceStatesAfter;
d3D12Resource = D3D12Resource;
return (d3D12ResourceStatesBefore, d3D12ResourceStatesAfter);
}
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
@@ -592,4 +609,10 @@ public unsafe abstract class Texture2D<T> : NativeObject, IGraphicsResource, Gra
{
return ValidateAndGetID3D12Resource(device);
}
/// <inheritdoc/>
(D3D12_RESOURCE_STATES, D3D12_RESOURCE_STATES) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource)
{
return ValidateAndGetID3D12ResourceAndTransitionStates(device, resourceState, out d3D12Resource);
}
}
+28 -5
ファイルの表示
@@ -5,6 +5,7 @@ using ComputeSharp.Graphics.Commands;
using ComputeSharp.Graphics.Commands.Interop;
using ComputeSharp.Graphics.Extensions;
using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Graphics.Resources.Helpers;
using ComputeSharp.Graphics.Resources.Interop;
using ComputeSharp.Interop;
using Microsoft.Toolkit.Diagnostics;
@@ -44,11 +45,6 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
/// </summary>
private readonly ID3D12ResourceDescriptorHandles d3D12ResourceDescriptorHandles;
/// <summary>
/// The default <see cref="D3D12_RESOURCE_STATES"/> value for the current resource.
/// </summary>
private readonly D3D12_RESOURCE_STATES d3D12ResourceState;
/// <summary>
/// The <see cref="D3D12_COMMAND_LIST_TYPE"/> value to use for copy operations.
/// </summary>
@@ -59,6 +55,11 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
/// </summary>
private readonly D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint;
/// <summary>
/// The current <see cref="D3D12_RESOURCE_STATES"/> value for the current resource.
/// </summary>
private D3D12_RESOURCE_STATES d3D12ResourceState;
/// <summary>
/// Creates a new <see cref="Texture3D{T}"/> instance with the specified parameters.
/// </summary>
@@ -625,6 +626,22 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
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)
{
ThrowIfDisposed();
ThrowIfDeviceMismatch(device);
D3D12_RESOURCE_STATES d3D12ResourceStatesBefore = this.d3D12ResourceState;
D3D12_RESOURCE_STATES d3D12ResourceStatesAfter = ResourceStateHelper.GetD3D12ResourceStates(resourceState);
this.d3D12ResourceState = d3D12ResourceStatesAfter;
d3D12Resource = D3D12Resource;
return (d3D12ResourceStatesBefore, d3D12ResourceStatesAfter);
}
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
@@ -645,4 +662,10 @@ public unsafe abstract class Texture3D<T> : NativeObject, IGraphicsResource, Gra
{
return ValidateAndGetID3D12Resource(device);
}
/// <inheritdoc/>
(D3D12_RESOURCE_STATES, D3D12_RESOURCE_STATES) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource)
{
return ValidateAndGetID3D12ResourceAndTransitionStates(device, resourceState, out d3D12Resource);
}
}
+17
ファイルの表示
@@ -0,0 +1,17 @@
namespace ComputeSharp;
/// <summary>
/// An <see langword="enum"/> that indicates the state of a resource after a given transition.
/// </summary>
public enum ResourceState
{
/// <summary>
/// A readonly resource, that can only be read from by the GPU and supports texture sampling.
/// </summary>
ReadOnly,
/// <summary>
/// A read write resource, with both read and write access for the GPU, but without support for texture sampling.
/// </summary>
ReadWrite
}
+33
ファイルの表示
@@ -0,0 +1,33 @@
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Diagnostics;
using TerraFX.Interop.DirectX;
using static TerraFX.Interop.DirectX.D3D12_RESOURCE_STATES;
namespace ComputeSharp.Graphics.Resources.Helpers;
/// <summary>
/// A helper type with utility methods for <see cref="ResourceState"/>.
/// </summary>
internal static class ResourceStateHelper
{
/// <summary>
/// Gets the corresponding <see cref="D3D12_RESOURCE_STATES"/> value for the input resource state.
/// </summary>
/// <returns>The <see cref="D3D12_RESOURCE_STATES"/> value corresponding to the input resource state.</returns>
/// <exception cref="System.ArgumentException">Thrown when the input value is not valid.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static D3D12_RESOURCE_STATES GetD3D12ResourceStates(ResourceState resourceState)
{
if (resourceState == ResourceState.ReadOnly)
{
return D3D12_RESOURCE_STATE_COMMON;
}
if (resourceState == ResourceState.ReadWrite)
{
return D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
}
return ThrowHelper.ThrowArgumentException<D3D12_RESOURCE_STATES>("The target resource state is not valid.");
}
}