Added interface APIs to load shader metadata

このコミットが含まれているのは:
Sergio Pedri committed 2021-07-12 15:58:52 +02:00
1 親 e432a197a0
コミット fdb0f691a2
5ファイル変更
+100 -12

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

+8 -8
ファイルの表示
@@ -98,7 +98,7 @@ namespace ComputeSharp.SourceGenerators
// [EditorBrowsable(EditorBrowsableState.Never)]
// [Obsolete("This method is not intended to be called directly by user code")]
// [return: ComputeRoot32BitConstants(42)]
// public readonly void LoadDispatchData<TDataLoader>(in TDataLoader dataLoader, GraphicsDevice device, int x, int y, int z)
// public readonly void LoadDispatchData<TDataLoader>(ref TDataLoader loader, GraphicsDevice device, int x, int y, int z)
// where TDataLoader : struct, IDispatchDataLoader
// {
// <BODY>
@@ -122,8 +122,8 @@ namespace ComputeSharp.SourceGenerators
.AddModifiers(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.ReadOnlyKeyword))
.AddTypeParameterListParameters(TypeParameter(Identifier("TDataLoader")))
.AddParameterListParameters(
Parameter(Identifier("dataLoader"))
.AddModifiers(Token(SyntaxKind.InKeyword))
Parameter(Identifier("loader"))
.AddModifiers(Token(SyntaxKind.RefKeyword))
.WithType(IdentifierName("TDataLoader")),
Parameter(Identifier("device")).WithType(IdentifierName("GraphicsDevice")),
Parameter(Identifier("x")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))),
@@ -288,13 +288,13 @@ namespace ComputeSharp.SourceGenerators
SyntaxKind.NumericLiteralExpression,
Literal(0))))))))));
// dataLoader.LoadCapturedValues(span0);
// loader.LoadCapturedValues(span0);
statements.Add(
ExpressionStatement(
InvocationExpression(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("dataLoader"),
IdentifierName("loader"),
IdentifierName("LoadCapturedValues")))
.AddArgumentListArguments(Argument(IdentifierName("span0")))));
@@ -329,13 +329,13 @@ namespace ComputeSharp.SourceGenerators
SyntaxKind.NumericLiteralExpression,
Literal(0))))))))));
// dataLoader.LoadCapturedResources(span1);
// loader.LoadCapturedResources(span1);
statements.Add(
ExpressionStatement(
InvocationExpression(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("dataLoader"),
IdentifierName("loader"),
IdentifierName("LoadCapturedResources")))
.AddArgumentListArguments(Argument(IdentifierName("span1")))));
}
@@ -367,7 +367,7 @@ namespace ComputeSharp.SourceGenerators
typeName = fieldSymbol.Type.GetFullMetadataName();
// Disambiguates the name of target fields against the current input parameters
if (fieldName is "dataLoader" or "device" or "x" or "y" or "z")
if (fieldName is "loader" or "device" or "x" or "y" or "z")
{
fieldName = $"this.{fieldName}";
}
+23
ファイルの表示
@@ -0,0 +1,23 @@
using System;
using System.ComponentModel;
namespace ComputeSharp.__Internals
{
/// <summary>
/// A base <see langword="interface"/> representing a metadatadata loader for a shader being dispatched.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This interface is not intended to be used directly by user code")]
public interface IDispatchMetadataLoader
{
/// <summary>
/// Loads an opaque metadata handle from the given shader metadata.
/// </summary>
/// <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>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
void LoadMetadataHandle(ReadOnlySpan<byte> serializedMetadata, ReadOnlySpan<ResourceDescriptor> resourceDescriptors, out IntPtr result);
}
}
+13 -2
ファイルの表示
@@ -24,16 +24,27 @@ namespace ComputeSharp.__Internals
/// Loads the dispatch data for the shader.
/// </summary>
/// <typeparam name="TDataLoader">The type of data loader being used.</typeparam>
/// <param name="dataLoader">The <typeparamref name="TDataLoader"/> instance to use to load the data.</param>
/// <param name="loader">The <typeparamref name="TDataLoader"/> instance to use to load the data.</param>
/// <param name="device">The device the shader is being dispatched on.</param>
/// <param name="x">The number of iterations to run on the X axis.</param>
/// <param name="y">The number of iterations to run on the Y axis.</param>
/// <param name="z">The number of iterations to run on the Z axis.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
void LoadDispatchData<TDataLoader>(in TDataLoader dataLoader, GraphicsDevice device, int x, int y, int z)
void LoadDispatchData<TDataLoader>(ref TDataLoader loader, GraphicsDevice device, int x, int y, int z)
where TDataLoader : struct, IDispatchDataLoader;
/// <summary>
/// Loads an opaque metadata handle from the metadata of the current shader.
/// </summary>
/// <typeparam name="TMetadataLoader">The type of data loader being used.</typeparam>
/// <param name="loader">The <typeparamref name="TMetadataLoader"/> instance to use to load the data.</param>
/// <param name="result">The resulting opaque metadata handle.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
void LoadDispatchMetadata<TMetadataLoader>(ref TMetadataLoader loader, out IntPtr result)
where TMetadataLoader : struct, IDispatchMetadataLoader;
/// <summary>
/// Builds the HLSL source code for the current shader instance.
/// </summary>
+54
ファイルの表示
@@ -0,0 +1,54 @@
using System;
using System.ComponentModel;
using TerraFX.Interop;
using FX = TerraFX.Interop.Windows;
using static TerraFX.Interop.D3D12_DESCRIPTOR_RANGE_FLAGS;
#pragma warning disable IDE0052
namespace ComputeSharp.__Internals
{
/// <summary>
/// An opaque type describing a captured resource to be used in a shader.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This interface 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>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
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 = FX.D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
}
}
}
+2 -2
ファイルの表示
@@ -157,7 +157,7 @@ namespace ComputeSharp.Shaders
ComputeShaderDispatchDataLoader dataLoader = new(commandList.D3D12GraphicsCommandList);
shader.LoadDispatchData(in dataLoader, device, x, y, z);
shader.LoadDispatchData(ref dataLoader, device, x, y, z);
commandList.D3D12GraphicsCommandList->Dispatch((uint)groupsX, (uint)groupsY, (uint)groupsZ);
commandList.ExecuteAndWaitForCompletion();
@@ -216,7 +216,7 @@ namespace ComputeSharp.Shaders
PixelShaderDispatchDataLoader dataLoader = new(commandList.D3D12GraphicsCommandList);
shader.LoadDispatchData(in dataLoader, device, x, y, 1);
shader.LoadDispatchData(ref dataLoader, device, x, y, 1);
// Load the implicit output texture
commandList.D3D12GraphicsCommandList->SetComputeRootDescriptorTable(