Skip shader fields of not accessible types

このコミットが含まれているのは:
Sergio Pedri committed 2023-10-19 14:04:43 +02:00
1 親 17527764b9
コミット 76f27250f4
4ファイル変更
+24 -2

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

@@ -25,16 +25,19 @@ partial class D2DPixelShaderDescriptorGenerator
/// Explores a given type hierarchy and generates statements to load fields.
/// </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="constantBufferSizeInBytes">The size of the shader constant buffer.</param>
/// <returns>The sequence of <see cref="FieldInfo"/> instances for all captured resources and values.</returns>
public static ImmutableArray<FieldInfo> GetInfo(
ImmutableArrayBuilder<DiagnosticInfo> diagnostics,
Compilation compilation,
ITypeSymbol structDeclarationSymbol,
out int constantBufferSizeInBytes)
{
// Helper method that uses boxes instead of ref-s (illegal in enumerators)
static IEnumerable<FieldInfo> GetCapturedFieldInfos(
Compilation compilation,
ITypeSymbol currentTypeSymbol,
ImmutableArray<string> fieldPath,
StrongBox<int> rawDataOffset)
@@ -47,6 +50,12 @@ partial class D2DPixelShaderDescriptorGenerator
where fieldSymbol is { Type: INamedTypeSymbol { IsStatic: false }, IsConst: false, IsStatic: false, IsFixedSizeBuffer: false, IsImplicitlyDeclared: false }
select fieldSymbol)
{
// Skip fields of not accessible types (the analyzer will handle this)
if (!fieldSymbol.Type.IsAccessibleFromCompilationAssembly(compilation))
{
continue;
}
string fieldName = fieldSymbol.Name;
string typeName = fieldSymbol.Type.GetFullyQualifiedMetadataName();
@@ -65,7 +74,7 @@ partial class D2DPixelShaderDescriptorGenerator
else if (fieldSymbol.Type.IsUnmanagedType)
{
// Custom struct type defined by the user
foreach (FieldInfo fieldInfo in GetCapturedFieldInfos(fieldSymbol.Type, fieldPath.Add(fieldName), rawDataOffset))
foreach (FieldInfo fieldInfo in GetCapturedFieldInfos(compilation, fieldSymbol.Type, fieldPath.Add(fieldName), rawDataOffset))
{
yield return fieldInfo;
}
@@ -78,6 +87,7 @@ partial class D2DPixelShaderDescriptorGenerator
// Traverse all shader fields and gather info, and update the tracking offsets
ImmutableArray<FieldInfo> fieldInfos = GetCapturedFieldInfos(
compilation,
structDeclarationSymbol,
ImmutableArray<string>.Empty,
rawDataOffsetAsBox).ToImmutableArray();
+1
ファイルの表示
@@ -85,6 +85,7 @@ public sealed partial class D2DPixelShaderDescriptorGenerator : IIncrementalGene
// LoadDispatchData() info
ImmutableArray<FieldInfo> fieldInfos = LoadConstantBuffer.GetInfo(
diagnostics,
context.SemanticModel.Compilation,
typeSymbol,
out int constantBufferSizeInBytes);
@@ -23,6 +23,7 @@ partial class ComputeShaderDescriptorGenerator
/// Explores a given type hierarchy and generates statements to load fields.
/// </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="isPixelShaderLike">Whether the compute shader is "pixel shader like", ie. outputting a pixel into a target texture.</param>
/// <param name="constantBufferSizeInBytes">The size of the shader constant buffer.</param>
@@ -31,6 +32,7 @@ partial class ComputeShaderDescriptorGenerator
/// <param name="resources">The sequence of <see cref="ResourceInfo"/> instances for all captured resources.</param>
public static void GetInfo(
ImmutableArrayBuilder<DiagnosticInfo> diagnostics,
Compilation compilation,
ITypeSymbol structDeclarationSymbol,
bool isPixelShaderLike,
out int constantBufferSizeInBytes,
@@ -39,6 +41,7 @@ partial class ComputeShaderDescriptorGenerator
out ImmutableArray<ResourceInfo> resources)
{
static void GetInfo(
Compilation compilation,
ITypeSymbol currentTypeSymbol,
ImmutableArray<string> fieldPath,
ref int resourceOffset,
@@ -56,6 +59,12 @@ partial class ComputeShaderDescriptorGenerator
continue;
}
// Skip fields of not accessible types (the analyzer will handle this)
if (!fieldSymbol.Type.IsAccessibleFromCompilationAssembly(compilation))
{
continue;
}
string fieldName = fieldSymbol.Name;
string typeName = fieldSymbol.Type.GetFullyQualifiedMetadataName();
@@ -78,7 +87,7 @@ partial class ComputeShaderDescriptorGenerator
else if (fieldSymbol.Type.IsUnmanagedType)
{
// Custom struct type defined by the user
GetInfo(fieldSymbol.Type, fieldPath.Add(fieldName), ref resourceOffset, ref rawDataOffset, fields, resources);
GetInfo(compilation, fieldSymbol.Type, fieldPath.Add(fieldName), ref resourceOffset, ref rawDataOffset, fields, resources);
}
}
}
@@ -93,6 +102,7 @@ partial class ComputeShaderDescriptorGenerator
{
// Traverse all shader fields and gather info, and update the tracking offsets
GetInfo(
compilation,
structDeclarationSymbol,
ImmutableArray<string>.Empty,
ref resourceOffset,
+1
ファイルの表示
@@ -60,6 +60,7 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener
// Get the fields info
DispatchDataLoading.GetInfo(
diagnostics,
context.SemanticModel.Compilation,
typeSymbol,
isPixelShaderLike,
out int constantBufferSizeInBytes,