Skip to content

Commit

Permalink
Generate input descriptions as ReadOnlyMemory<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Sep 23, 2023
1 parent 52c6281 commit 4a4bc33
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<Compile Include="..\ComputeSharp.D2D1\Interfaces\__Internals\ID2D1Shader.cs" Link="ComputeSharp.D2D1\Interfaces\__Internals\ID2D1Shader.cs" />
<Compile Include="..\ComputeSharp.D2D1\Intrinsics\D2D.cs" Link="ComputeSharp.D2D1\Intrinsics\D2D.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Exceptions\FxcCompilationException.cs" Link="ComputeSharp.D2D1\Shaders\Exceptions\FxcCompilationException.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Interop\D2D1InputDescription.cs" Link="ComputeSharp.D2D1\Shaders\Interop\D2D1InputDescription.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Interop\D2D1PixelShaderInputType.cs" Link="ComputeSharp.D2D1\Shaders\Interop\D2D1PixelShaderInputType.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Translation\D3DCompiler.cs" Link="ComputeSharp.D2D1\Shaders\Translation\D3DCompiler.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Translation\D3DCompiler.ID3DInclude.cs" Link="ComputeSharp.D2D1\Shaders\Translation\D3DCompiler.ID3DInclude.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static TypeDeclarationSyntax GetMemoryManagerDeclaration(ImmutableArray<
// Create the MemoryManager<T> declaration:
//
// /// <summary>
// /// <see cref="global::System.Buffers.MemoryManager{T}"/> implementation to get the input types.
// /// A <see cref="global::System.Buffers.MemoryManager{T}"/> implementation to get the input types.
// /// </summary>
// [global::System.CodeDom.Compiler.GeneratedCode("...", "...")]
// [global::System.Diagnostics.DebuggerNonUserCode]
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static void GetInfo(

_ = attributeData.TryGetNamedArgument("LevelOfDetailCount", out int levelOfDetailCount);

inputDescriptionsBuilder.Add(new InputDescription((uint)index, filter, levelOfDetailCount));
inputDescriptionsBuilder.Add(new InputDescription(index, filter, levelOfDetailCount));
}

break;
Expand Down Expand Up @@ -82,7 +82,7 @@ public static void GetInfo(
// All input description indices must be unique
foreach (InputDescription inputDescription in inputDescriptionsBuilder.WrittenSpan)
{
ref bool isInputDescriptionIndexUsed = ref selectedInputDescriptionIndices[(int)inputDescription.Index];
ref bool isInputDescriptionIndexUsed = ref selectedInputDescriptionIndices[inputDescription.Index];

if (isInputDescriptionIndexUsed)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
// Generate the LoadInputDescriptions() methods
context.RegisterSourceOutput(inputDescriptionsInfo, static (context, item) =>
{
MethodDeclarationSyntax loadInputDescriptionsMethod = LoadInputDescriptions.GetSyntax(item.Info.InputDescriptions);
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Info.Hierarchy, loadInputDescriptionsMethod, item.CanUseSkipLocalsInit);
PropertyDeclarationSyntax inputDescriptionsProperty = LoadInputDescriptions.GetSyntax(item.Info.InputDescriptions, out TypeDeclarationSyntax[] additionalTypes);
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Info.Hierarchy, inputDescriptionsProperty, item.CanUseSkipLocalsInit, additionalMemberDeclarations: additionalTypes);
context.AddSource($"{item.Info.Hierarchy.FullyQualifiedMetadataName}.{nameof(LoadInputDescriptions)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
/// </summary>
/// <param name="Index">The index of the input resource the description is for.</param>
/// <param name="Filter">The input filter to use.</param>
/// <param name="LevelOfDetail">The level of detail to use.</param>
internal sealed record InputDescription(uint Index, D2D1Filter Filter, int LevelOfDetail);
/// <param name="LevelOfDetailCount">The level of detail to use.</param>
internal sealed record InputDescription(int Index, D2D1Filter Filter, int LevelOfDetailCount);
7 changes: 7 additions & 0 deletions src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public interface ID2D1Shader
[Obsolete("This method is not intended to be used directly by user code")]
ReadOnlyMemory<D2D1PixelShaderInputType> InputTypes { get; }

/// <summary>
/// Gets the input descriptions for the current shader.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
ReadOnlyMemory<D2D1InputDescription> InputDescriptions { get; }

/// <summary>
/// Loads the input descriptions for the shader, if any.
/// </summary>
Expand Down
17 changes: 16 additions & 1 deletion src/ComputeSharp.D2D1/Shaders/Interop/D2D1InputDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ public readonly struct D2D1InputDescription
/// </summary>
private readonly int levelOfDetailCount;

/// <summary>
/// Creates a new <see cref="D2D1InputDescription"/> instance with the specified parameters.
/// </summary>
/// <param name="index">The index of the resource the description belongs to.</param>
/// <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;
}

/// <summary>
/// Gets the index of the resource the description belongs to.
/// </summary>
Expand All @@ -46,5 +57,9 @@ public readonly struct D2D1InputDescription
/// <summary>
/// Gets the mip level to retrieve from the upstream transform, if specified.
/// </summary>
public int LevelOfDetailCount => this.levelOfDetailCount;
public int LevelOfDetailCount
{
get => this.levelOfDetailCount;
init => this.levelOfDetailCount = value;
}
}

0 comments on commit 4a4bc33

Please sign in to comment.