Refactor ResourceDescriptor, add ResourceDescriptorRangeType

このコミットが含まれているのは:
Sergio Pedri committed 2023-10-14 10:44:06 +02:00
1 親 30414faf40
コミット 104f216c61
7ファイル変更
+78 -92

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

+5 -24
ファイルの表示
@@ -12,21 +12,6 @@ namespace ComputeSharp.D2D1.Interop;
[StructLayout(LayoutKind.Sequential)]
public readonly struct D2D1InputDescription
{
/// <summary>
/// The index of the resource the description belongs to.
/// </summary>
private readonly int index;
/// <summary>
/// The type of filter to apply to the input texture.
/// </summary>
private readonly D2D1Filter filter;
/// <summary>
/// The mip level to retrieve from the upstream transform, if specified.
/// </summary>
private readonly int levelOfDetailCount;
/// <summary>
/// Creates a new <see cref="D2D1InputDescription"/> instance with the specified parameters.
/// </summary>
@@ -34,26 +19,22 @@ public readonly struct D2D1InputDescription
/// <param name="filter">The type of filter to apply to the input texture.</param>
public D2D1InputDescription(int index, D2D1Filter filter)
{
this.index = index;
this.filter = filter;
Index = index;
Filter = filter;
}
/// <summary>
/// Gets the index of the resource the description belongs to.
/// </summary>
public int Index => this.index;
public int Index { get; }
/// <summary>
/// Gets the type of filter to apply to the input texture.
/// </summary>
public D2D1Filter Filter => this.filter;
public D2D1Filter Filter { get; }
/// <summary>
/// Gets the mip level to retrieve from the upstream transform, if specified.
/// </summary>
public int LevelOfDetailCount
{
get => this.levelOfDetailCount;
init => this.levelOfDetailCount = value;
}
public int LevelOfDetailCount { get; init; }
}
+4 -15
ファイルの表示
@@ -8,17 +8,6 @@ namespace ComputeSharp.D2D1.Interop;
[StructLayout(LayoutKind.Sequential)]
public readonly struct D2D1ResourceTextureDescription
{
/// <summary>
/// The index of the resource texture the description belongs to.
/// </summary>
/// <remarks>See notes in <see cref="D2D1InputDescription"/> for why explicit fields are used here.</remarks>
private readonly int index;
/// <summary>
/// The number of dimensions of the resource texture the description belongs to.
/// </summary>
private readonly int dimensions;
/// <summary>
/// Creates a new <see cref="D2D1ResourceTextureDescription"/> instance with the specified parameters.
/// </summary>
@@ -26,17 +15,17 @@ public readonly struct D2D1ResourceTextureDescription
/// <param name="dimensions">The number of dimensions of the resource texture the description belongs to.</param>
public D2D1ResourceTextureDescription(int index, int dimensions)
{
this.index = index;
this.dimensions = dimensions;
Index = index;
Dimensions = dimensions;
}
/// <summary>
/// Gets the index of the resource texture the description belongs to.
/// </summary>
public int Index => this.index;
public int Index { get; }
/// <summary>
/// Gets the rank of the resource texture the description belongs to.
/// </summary>
public int Dimensions => this.dimensions;
public int Dimensions { get; }
}
+1 -1
ファイルの表示
@@ -16,5 +16,5 @@ public interface IDispatchMetadataLoader
/// <param name="serializedMetadata">The serialized metadata for the current shader.</param>
/// <param name="resourceDescriptors">The sequence of resource descriptors for the current shader.</param>
/// <param name="result">The resulting opaque metadata handle.</param>
void LoadMetadataHandle(ReadOnlySpan<byte> serializedMetadata, ReadOnlySpan<ResourceDescriptor> resourceDescriptors, out IntPtr result);
void LoadMetadataHandle(ReadOnlySpan<byte> serializedMetadata, ReadOnlySpan<ResourceDescriptorRange> resourceDescriptors, out IntPtr result);
}
+38
ファイルの表示
@@ -0,0 +1,38 @@
using System.Runtime.InteropServices;
namespace ComputeSharp.Interop;
/// <summary>
/// A type containing info on a descriptor for a given D3D12 shader resource range.
/// </summary>
/// <remarks>
/// This type exposes a subset of values from
/// <see href="https://learn.microsoft.com/windows/win32/api/d3d12/ns-d3d12-d3d12_descriptor_range1"><c>D3D12_DESCRIPTOR_RANGE1</c></see>.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
public readonly struct ResourceDescriptorRange
{
/// <summary>
/// Creates a new <see cref="ResourceDescriptorRange"/> instance with the specified parameters.
/// </summary>
/// <param name="type">The type of the descriptor range.</param>
/// <param name="register">The shader register in the range.</param>
public ResourceDescriptorRange(ResourceDescriptorRangeType type, uint register)
{
Type = type;
Register = register;
}
/// <summary>
/// Gets the type of the descriptor range.
/// </summary>
public ResourceDescriptorRangeType Type { get; }
/// <summary>
/// Gets the shader register in the range.
/// </summary>
/// <remarks>
/// For example, for shader-resource views (SRVs), 3 maps to <c>register(t3)</c> in HLSL.
/// </remarks>
public uint Register { get; }
}
+28
ファイルの表示
@@ -0,0 +1,28 @@
using static TerraFX.Interop.DirectX.D3D12_DESCRIPTOR_RANGE_TYPE;
namespace ComputeSharp.Interop;
/// <summary>
/// A type containing info on a descriptor type for a given D3D12 shader resource range.
/// </summary>
/// <remarks>
/// This type exposes the available values in
/// <see href="https://learn.microsoft.com/windows/win32/api/d3d12/ne-d3d12-d3d12_descriptor_range_type"><c>D3D12_DESCRIPTOR_RANGE_TYPE</c></see>.
/// </remarks>
public enum ResourceDescriptorRangeType
{
/// <summary>
/// Specifies a range of SRVs.
/// </summary>
ShaderResourceView = D3D12_DESCRIPTOR_RANGE_TYPE_SRV,
/// <summary>
/// Specifies a range of unordered-access views (UAVs).
/// </summary>
UnorderedAccessView = D3D12_DESCRIPTOR_RANGE_TYPE_UAV,
/// <summary>
/// Specifies a range of constant-buffer views (CBVs).
/// </summary>
ConstantBufferView = D3D12_DESCRIPTOR_RANGE_TYPE_CBV
}
-50
ファイルの表示
@@ -1,50 +0,0 @@
using System;
using System.ComponentModel;
using TerraFX.Interop.DirectX;
using static TerraFX.Interop.DirectX.D3D12_DESCRIPTOR_RANGE_FLAGS;
#pragma warning disable IDE0052, IDE1006, CS0414
namespace ComputeSharp.__Internals;
/// <summary>
/// An opaque type describing a captured resource to be used in a shader.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This type is not intended to be used directly by user code")]
public struct ResourceDescriptor
{
/// <inheritdoc cref="D3D12_DESCRIPTOR_RANGE1.RangeType"/>
private D3D12_DESCRIPTOR_RANGE_TYPE RangeType;
/// <inheritdoc cref="D3D12_DESCRIPTOR_RANGE1.NumDescriptors"/>
private uint NumDescriptors;
/// <inheritdoc cref="D3D12_DESCRIPTOR_RANGE1.BaseShaderRegister"/>
private uint BaseShaderRegister;
/// <inheritdoc cref="D3D12_DESCRIPTOR_RANGE1.RegisterSpace"/>
private uint RegisterSpace;
/// <inheritdoc cref="D3D12_DESCRIPTOR_RANGE1.Flags"/>
private D3D12_DESCRIPTOR_RANGE_FLAGS Flags;
/// <inheritdoc cref="D3D12_DESCRIPTOR_RANGE1.OffsetInDescriptorsFromTableStart"/>
private uint OffsetInDescriptorsFromTableStart;
/// <summary>
/// Initializes a new <see cref="ResourceDescriptor"/> instance.
/// </summary>
/// <param name="type">The type of resource to create the descriptor for.</param>
/// <param name="offset">The offset in the resource from the start of the shader mapping.</param>
/// <param name="descriptor">The resulting <see cref="ResourceDescriptor"/> instance.</param>
public static void Create(int type, uint offset, out ResourceDescriptor descriptor)
{
descriptor.RangeType = (D3D12_DESCRIPTOR_RANGE_TYPE)type;
descriptor.NumDescriptors = 1;
descriptor.BaseShaderRegister = offset;
descriptor.RegisterSpace = 0;
descriptor.Flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE;
descriptor.OffsetInDescriptorsFromTableStart = D3D12.D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
}
}
+2 -2
ファイルの表示
@@ -31,7 +31,7 @@ internal readonly unsafe struct ShaderDispatchMetadataLoader : IDispatchMetadata
}
/// <inheritdoc/>
public unsafe void LoadMetadataHandle(ReadOnlySpan<byte> serializedMetadata, ReadOnlySpan<ResourceDescriptor> resourceDescriptors, out IntPtr result)
public unsafe void LoadMetadataHandle(ReadOnlySpan<byte> serializedMetadata, ReadOnlySpan<ResourceDescriptorRange> resourceDescriptors, out IntPtr result)
{
default(ArgumentException).ThrowIf(serializedMetadata.Length != 5, nameof(serializedMetadata));
@@ -39,7 +39,7 @@ internal readonly unsafe struct ShaderDispatchMetadataLoader : IDispatchMetadata
{
*(ComPtr<ID3D12RootSignature>*)p = this.d3D12Device->CreateRootSignature(
MemoryMarshal.Read<int>(serializedMetadata),
MemoryMarshal.Cast<ResourceDescriptor, D3D12_DESCRIPTOR_RANGE1>(resourceDescriptors),
MemoryMarshal.Cast<ResourceDescriptorRange, D3D12_DESCRIPTOR_RANGE1>(resourceDescriptors),
MemoryMarshal.Read<bool>(serializedMetadata.Slice(4)));
}
}