Added diagnostics for shaders exceeding root signature size

このコミットが含まれているのは:
Sergio Pedri committed 2021-03-12 14:55:30 +01:00
1 親 33c1415f2d
コミット a94e5559a0
4ファイル変更
+67 -2

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

+1
ファイルの表示
@@ -52,3 +52,4 @@ CMPS0042 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator,
CMPS0043 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0044 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0045 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0046 | ComputeSharp.IComputeShader | Error | IComputeShaderDataLoaderGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
+16
ファイルの表示
@@ -630,5 +630,21 @@ namespace ComputeSharp.SourceGenerators.Diagnostics
isEnabledByDefault: true,
description: "Property declarations cannot be used in a compute shader.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for a shader with a root signature that is too large.
/// <para>
/// Format: <c>"The compute shader of type {0} has exceeded the maximum allowed size for captured values and resources"</c>.
/// </para>
/// </summary>
public static readonly DiagnosticDescriptor ShaderDispatchDataSizeExceeded = new(
id: "CMPS0046",
title: "Shader dispatch data size exceeded",
messageFormat: "The compute shader of type {0} has exceeded the maximum allowed size for captured values and resources",
category: typeof(IComputeShader).FullName,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "The compute shader of type {0} has exceeded the maximum allowed size for captured values and resources.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
}
}
+18 -2
ファイルの表示
@@ -79,7 +79,7 @@ namespace ComputeSharp.SourceGenerators
if (!structDeclarationSymbol.Interfaces.Any(static interfaceSymbol => interfaceSymbol.Name == nameof(IComputeShader))) return;
TypeSyntax shaderType = ParseTypeName(structDeclarationSymbol.ToDisplayString());
BlockSyntax block = Block(GetDispatchDataLoadingStatements(structDeclarationSymbol, out int root32BitConstantsCount));
BlockSyntax block = Block(GetDispatchDataLoadingStatements(context, structDeclarationSymbol, out int root32BitConstantsCount));
// Create a static method to create the combined hashcode for a given shader type.
// This code takes a block syntax and produces a compilation unit as follows:
@@ -148,11 +148,12 @@ namespace ComputeSharp.SourceGenerators
/// <summary>
/// Gets a sequence of statements to load the dispatch data for a given shader
/// </summary>
/// <param name="context">The current generator context in use.</param>
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
/// <param name="count">The total number of 32 bit root constants to load.</param>
/// <returns>The sequence of <see cref="StatementSyntax"/> instances to load shader dispatch data.</returns>
[Pure]
private static IEnumerable<StatementSyntax> GetDispatchDataLoadingStatements(INamedTypeSymbol structDeclarationSymbol, out int count)
private static IEnumerable<StatementSyntax> GetDispatchDataLoadingStatements(GeneratorExecutionContext context, INamedTypeSymbol structDeclarationSymbol, out int count)
{
List<StatementSyntax> statements = new();
@@ -172,6 +173,21 @@ namespace ComputeSharp.SourceGenerators
count = rawDataOffset / sizeof(int);
// A shader root signature has a maximum size of 64 DWORDs, so 256 bytes.
// Loaded values in the root signature have the following costs:
// - Root constants cost 1 DWORD each, since they are 32-bit values.
// - Descriptor tables cost 1 DWORD each.
// - Root descriptors (64-bit GPU virtual addresses) cost 2 DWORDs each.
// So here we check whether the current signature respects that constraint,
// and emit a build error otherwise. For more info on this, see the docs here:
// https://docs.microsoft.com/windows/win32/direct3d12/root-signature-limits.
int rootSignatureDwordSize = count + resourceOffset;
if (rootSignatureDwordSize > 64)
{
context.ReportDiagnostic(ShaderDispatchDataSizeExceeded, structDeclarationSymbol, structDeclarationSymbol);
}
return statements;
}
+32
ファイルの表示
@@ -1338,6 +1338,38 @@ namespace ComputeSharp.Tests.SourceGenerators
VerifyGeneratedDiagnostics<IComputeShaderSourceGenerator>(source, "CMPS0045");
}
[TestMethod]
public void ShaderDispatchDataSizeExceeded()
{
string source = @"
using ComputeSharp;
namespace ComputeSharp
{
public class ReadWriteBuffer<T> { }
public struct Double4x4 { }
public struct Float4 { }
}
namespace MyFancyApp.Sample
{
public struct MyShader : IComputeShader
{
public readonly ReadWriteBuffer<float> buffer;
public readonly Double4x4 a;
public readonly Double4x4 b;
public readonly int c;
public readonly Float4 d;
public void Execute()
{
}
}
}";
VerifyGeneratedDiagnostics<IComputeShaderDataLoaderGenerator>(source, "CMPS0046");
}
/// <summary>
/// Verifies the output of a source generator.
/// </summary>