Restructure resources info logic, drop unnecessary TypeName field
このコミットが含まれているのは:
1 親
1760c8d3ff
コミット
5811ba60cf
4ファイル変更
+42
-76
検索条件に一致するファイルはありません
-58
@@ -1,58 +0,0 @@
|
||||
using System.Collections.Immutable;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using ComputeSharp.SourceGeneration.Mappings;
|
||||
using ComputeSharp.SourceGenerators.Models;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ComputeShaderDescriptorGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the <c>ResourceDescriptorRanges</c> property.
|
||||
/// </summary>
|
||||
private static partial class ResourceDescriptorRanges
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the data related to the shader metadata for a given shader type.
|
||||
/// </summary>
|
||||
/// <param name="isImplicitTextureUsed">Indicates whether the current shader uses an implicit texture.</param>
|
||||
/// <param name="resources">The sequence of captured resources for the shader.</param>
|
||||
/// <returns>The metadata info for the shader.</returns>
|
||||
public static ImmutableArray<ResourceDescriptor> GetInfo(
|
||||
bool isImplicitTextureUsed,
|
||||
ImmutableArray<ResourceInfo> resources)
|
||||
{
|
||||
using ImmutableArrayBuilder<ResourceDescriptor> descriptors = new();
|
||||
|
||||
int constantBufferOffset = 1;
|
||||
int readOnlyResourceOffset = 0;
|
||||
int readWriteResourceOffset = 0;
|
||||
|
||||
// Add the implicit texture descriptor, if needed
|
||||
if (isImplicitTextureUsed)
|
||||
{
|
||||
descriptors.Add(new ResourceDescriptor(1, readWriteResourceOffset++));
|
||||
}
|
||||
|
||||
// Populate the sequence of resource descriptors
|
||||
foreach (ResourceInfo resource in resources)
|
||||
{
|
||||
if (HlslKnownTypes.IsConstantBufferType(resource.TypeName))
|
||||
{
|
||||
descriptors.Add(new ResourceDescriptor(2, constantBufferOffset++));
|
||||
}
|
||||
else if (HlslKnownTypes.IsReadOnlyTypedResourceType(resource.TypeName))
|
||||
{
|
||||
descriptors.Add(new ResourceDescriptor(0, readOnlyResourceOffset++));
|
||||
}
|
||||
else
|
||||
{
|
||||
descriptors.Add(new ResourceDescriptor(1, readWriteResourceOffset++));
|
||||
}
|
||||
}
|
||||
|
||||
return descriptors.ToImmutable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,21 +20,36 @@ partial class ComputeShaderDescriptorGenerator
|
||||
private static partial class Resources
|
||||
{
|
||||
/// <summary>
|
||||
/// Explores a given type hierarchy and generates statements to load fields.
|
||||
/// Gathers info on all resources captured by a given shader type.
|
||||
/// </summary>
|
||||
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
|
||||
/// <param name="compilation">The input <see cref="Compilation"/> object currently in use.</param>
|
||||
/// <param name="structDeclarationSymbol">The current shader type being explored.</param>
|
||||
/// <param name="isImplicitTextureUsed">Indicates whether the current shader uses an implicit texture.</param>
|
||||
/// <param name="constantBufferSizeInBytes">The size of the shader constant buffer.</param>
|
||||
/// <param name="resources">The sequence of <see cref="ResourceInfo"/> instances for all captured resources.</param>
|
||||
/// <param name="resourceDescriptors">The sequence of <see cref="ResourceDescriptor"/> instances for all captured resources.</param>
|
||||
public static void GetInfo(
|
||||
ImmutableArrayBuilder<DiagnosticInfo> diagnostics,
|
||||
Compilation compilation,
|
||||
ITypeSymbol structDeclarationSymbol,
|
||||
bool isImplicitTextureUsed,
|
||||
int constantBufferSizeInBytes,
|
||||
out ImmutableArray<ResourceInfo> resources)
|
||||
out ImmutableArray<ResourceInfo> resources,
|
||||
out ImmutableArray<ResourceDescriptor> resourceDescriptors)
|
||||
{
|
||||
using ImmutableArrayBuilder<ResourceInfo> resourceBuilder = new();
|
||||
using ImmutableArrayBuilder<ResourceDescriptor> resourceDescriptorBuilder = new();
|
||||
|
||||
int constantBufferOffset = 1;
|
||||
int readOnlyResourceOffset = 0;
|
||||
int readWriteResourceOffset = 0;
|
||||
|
||||
// Add the implicit texture descriptor, if needed
|
||||
if (isImplicitTextureUsed)
|
||||
{
|
||||
resourceDescriptorBuilder.Add(new ResourceDescriptor(1, readWriteResourceOffset++));
|
||||
}
|
||||
|
||||
foreach (ISymbol memberSymbol in structDeclarationSymbol.GetMembers())
|
||||
{
|
||||
@@ -61,11 +76,26 @@ partial class ComputeShaderDescriptorGenerator
|
||||
// Check if the field is a resource (note: resources can only be top level fields)
|
||||
if (HlslKnownTypes.IsTypedResourceType(typeName))
|
||||
{
|
||||
resourceBuilder.Add(new ResourceInfo(fieldName, unspeakableName, typeName));
|
||||
resourceBuilder.Add(new ResourceInfo(fieldName, unspeakableName));
|
||||
|
||||
// Populate the resource descriptors as well
|
||||
if (HlslKnownTypes.IsConstantBufferType(typeName))
|
||||
{
|
||||
resourceDescriptorBuilder.Add(new ResourceDescriptor(2, constantBufferOffset++));
|
||||
}
|
||||
else if (HlslKnownTypes.IsReadOnlyTypedResourceType(typeName))
|
||||
{
|
||||
resourceDescriptorBuilder.Add(new ResourceDescriptor(0, readOnlyResourceOffset++));
|
||||
}
|
||||
else
|
||||
{
|
||||
resourceDescriptorBuilder.Add(new ResourceDescriptor(1, readWriteResourceOffset++));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resources = resourceBuilder.ToImmutable();
|
||||
resourceDescriptors = resourceDescriptorBuilder.ToImmutable();
|
||||
|
||||
// A shader root signature has a maximum size of 64 DWORDs, so 256 bytes.
|
||||
// Loaded values in the root signature have the following costs:
|
||||
|
||||
@@ -69,16 +69,6 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
// Get the resources info
|
||||
Resources.GetInfo(
|
||||
diagnostics,
|
||||
context.SemanticModel.Compilation,
|
||||
typeSymbol,
|
||||
constantBufferSizeInBytes,
|
||||
out ImmutableArray<ResourceInfo> resourceInfo);
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
// Thread group size info
|
||||
NumThreads.GetInfo(
|
||||
diagnostics,
|
||||
@@ -105,10 +95,15 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
// Resource descriptor ranges info
|
||||
ImmutableArray<ResourceDescriptor> resourceDescriptors = ResourceDescriptorRanges.GetInfo(
|
||||
// Get the resources info
|
||||
Resources.GetInfo(
|
||||
diagnostics,
|
||||
context.SemanticModel.Compilation,
|
||||
typeSymbol,
|
||||
isImplicitTextureUsed,
|
||||
resourceInfo);
|
||||
constantBufferSizeInBytes,
|
||||
out ImmutableArray<ResourceInfo> resourceInfo,
|
||||
out ImmutableArray<ResourceDescriptor> resourceDescriptors);
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
|
||||
@@ -5,5 +5,4 @@ namespace ComputeSharp.SourceGenerators.Models;
|
||||
/// </summary>
|
||||
/// <param name="FieldName">The name of the resource field.</param>
|
||||
/// <param name="UnspeakableName">The unspeakable name of the field, if present.</param>
|
||||
/// <param name="TypeName">The full metadata name for the resource type.</param>
|
||||
public sealed record ResourceInfo(string FieldName, string? UnspeakableName, string TypeName);
|
||||
public sealed record ResourceInfo(string FieldName, string? UnspeakableName);
|
||||
新しいイシューから参照
ユーザーをブロックする