Code refactoring in IShaderGenerator

このコミットが含まれているのは:
Sergio Pedri committed 2021-12-08 11:17:06 +01:00
1 親 1262bf6e0e
コミット 0004353052
13ファイル変更
+1897 -1835

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

+44 -38
ファイルの表示
@@ -8,51 +8,57 @@ namespace ComputeSharp.SourceGenerators;
public sealed partial class IShaderGenerator
{
/// <summary>
/// Gets the data related to the shader metadata for a given shader type.
/// A helper with all logic to generate the <c>LoadDispatchMetadata</c> method.
/// </summary>
/// <param name="root32BitConstantCount">The total number of needed 32 bit constants in the shader root signature.</param>
/// <param name="isImplicitTextureUsed">Indicates whether the current shader uses an implicit texture.</param>
/// <param name="isSamplerUsed">Whether the static sampler is used by the shader.</param>
/// <param name="capturedFields">The sequence of captured fields for the shader.</param>
/// <returns>The metadata info for the shader.</returns>
private static DispatchMetadataInfo GetDispatchMetadataInfo(
int root32BitConstantCount,
bool isImplicitTextureUsed,
bool isSamplerUsed,
ImmutableArray<FieldInfo> capturedFields)
private static partial class LoadDispatchMetadata
{
ImmutableArray<ResourceDescriptor>.Builder descriptors = ImmutableArray.CreateBuilder<ResourceDescriptor>();
int constantBufferOffset = 1;
int readOnlyResourceOffset = 0;
int readWriteResourceOffset = 0;
int resourceOffset = 0;
// Add the implicit texture descriptor, if needed
if (isImplicitTextureUsed)
/// <summary>
/// Gets the data related to the shader metadata for a given shader type.
/// </summary>
/// <param name="root32BitConstantCount">The total number of needed 32 bit constants in the shader root signature.</param>
/// <param name="isImplicitTextureUsed">Indicates whether the current shader uses an implicit texture.</param>
/// <param name="isSamplerUsed">Whether the static sampler is used by the shader.</param>
/// <param name="capturedFields">The sequence of captured fields for the shader.</param>
/// <returns>The metadata info for the shader.</returns>
public static DispatchMetadataInfo GetInfo(
int root32BitConstantCount,
bool isImplicitTextureUsed,
bool isSamplerUsed,
ImmutableArray<FieldInfo> capturedFields)
{
descriptors.Add(new ResourceDescriptor(1, readWriteResourceOffset++, resourceOffset++));
}
ImmutableArray<ResourceDescriptor>.Builder descriptors = ImmutableArray.CreateBuilder<ResourceDescriptor>();
int constantBufferOffset = 1;
int readOnlyResourceOffset = 0;
int readWriteResourceOffset = 0;
int resourceOffset = 0;
// Populate the sequence of resource descriptors
foreach (FieldInfo.Resource resource in capturedFields.OfType<FieldInfo.Resource>())
{
if (HlslKnownTypes.IsConstantBufferType(resource.TypeName))
{
descriptors.Add(new ResourceDescriptor(2, constantBufferOffset++, resourceOffset++));
}
else if (HlslKnownTypes.IsReadOnlyTypedResourceType(resource.TypeName))
{
descriptors.Add(new ResourceDescriptor(0, readOnlyResourceOffset++, resourceOffset++));
}
else
// Add the implicit texture descriptor, if needed
if (isImplicitTextureUsed)
{
descriptors.Add(new ResourceDescriptor(1, readWriteResourceOffset++, resourceOffset++));
}
}
return new(
root32BitConstantCount,
isSamplerUsed,
descriptors.ToImmutable());
// Populate the sequence of resource descriptors
foreach (FieldInfo.Resource resource in capturedFields.OfType<FieldInfo.Resource>())
{
if (HlslKnownTypes.IsConstantBufferType(resource.TypeName))
{
descriptors.Add(new ResourceDescriptor(2, constantBufferOffset++, resourceOffset++));
}
else if (HlslKnownTypes.IsReadOnlyTypedResourceType(resource.TypeName))
{
descriptors.Add(new ResourceDescriptor(0, readOnlyResourceOffset++, resourceOffset++));
}
else
{
descriptors.Add(new ResourceDescriptor(1, readWriteResourceOffset++, resourceOffset++));
}
}
return new(
root32BitConstantCount,
isSamplerUsed,
descriptors.ToImmutable());
}
}
}