Prevent bool fields in custom struct types in shaders
These are not allowed due to alignment reasons
このコミットが含まれているのは:
1 親
f68d56fcec
コミット
1e3611a060
4ファイル変更
+44
-4
検索条件に一致するファイルはありません
@@ -578,11 +578,11 @@ partial class DiagnosticDescriptors
|
||||
public static readonly DiagnosticDescriptor InvalidDiscoveredType = new DiagnosticDescriptor(
|
||||
id: "CMPSD2D0041",
|
||||
title: "Invalid discovered type",
|
||||
messageFormat: "The D2D1 shader of type {0} uses the invalid type {1} (only some .NET primitives and vector types, HLSL primitive, vector and matrix types, and custom types containing these types can be used)",
|
||||
messageFormat: "The D2D1 shader of type {0} uses the invalid type {1} (only some .NET primitives and vector types, HLSL primitive, vector and matrix types, and custom types containing these types can be used, and custom types containing these types can be used, and bool fields in custom struct types have to be replaced with the ComputeSharp.Bool type for alignment reasons)",
|
||||
category: "ComputeSharp.D2D1.Shaders",
|
||||
defaultSeverity: DiagnosticSeverity.Error,
|
||||
isEnabledByDefault: true,
|
||||
description: "D2D1 shaders can only use supported types (some .NET primitives and vector types, HLSL primitive, vector and matrix types, and custom types containing these types can be used).",
|
||||
description: "D2D1 shaders can only use supported types (some .NET primitives and vector types, HLSL primitive, vector and matrix types, and custom types containing these types can be used, and custom types containing these types can be used, and bool fields in custom struct types have to be replaced with the ComputeSharp.Bool type for alignment reasons).",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -218,6 +218,14 @@ internal static partial class HlslKnownTypes
|
||||
// Local function to recursively gather nested types
|
||||
static void ExploreTypes(INamedTypeSymbol type, HashSet<INamedTypeSymbol> customTypes, HashSet<INamedTypeSymbol> invalidTypes)
|
||||
{
|
||||
// Explicitly prevent bool from being a field in a custom struct
|
||||
if (type.SpecialType == SpecialType.System_Boolean)
|
||||
{
|
||||
invalidTypes.Add(type);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (KnownHlslTypes.ContainsKey(type.GetFullMetadataName())) return;
|
||||
|
||||
// Check if the type is unsupported
|
||||
|
||||
@@ -707,10 +707,10 @@ partial class DiagnosticDescriptors
|
||||
public static readonly DiagnosticDescriptor InvalidDiscoveredType = new DiagnosticDescriptor(
|
||||
id: "CMPS0050",
|
||||
title: "Invalid discovered type",
|
||||
messageFormat: "The compute shader or method {0} uses the invalid type {1} (only some .NET primitives and vector types, HLSL primitive, vector and matrix types, and custom types containing these types can be used)",
|
||||
messageFormat: "The compute shader or method {0} uses the invalid type {1} (only some .NET primitives and vector types, HLSL primitive, vector and matrix types, and custom types containing these types can be used, and bool fields in custom struct types have to be replaced with the ComputeSharp.Bool type for alignment reasons)",
|
||||
category: "ComputeSharp.Shaders",
|
||||
defaultSeverity: DiagnosticSeverity.Error,
|
||||
isEnabledByDefault: true,
|
||||
description: "Shaders and shader methods can only use supported types (some .NET primitives and vector types, HLSL primitive, vector and matrix types, and custom types containing these types can be used).",
|
||||
description: "Shaders and shader methods can only use supported types (some .NET primitives and vector types, HLSL primitive, vector and matrix types, and custom types containing these types can be used, and bool fields in custom struct types have to be replaced with the ComputeSharp.Bool type for alignment reasons).",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
}
|
||||
@@ -1697,6 +1697,38 @@ public class DiagnosticsTests
|
||||
VerifyGeneratedDiagnostics<IShaderGenerator>(source, "CMPS0047", "CMPS0050");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void InvalidDiscoveredType_CustomType_SystemBoolean()
|
||||
{
|
||||
string source = @"
|
||||
using System;
|
||||
using ComputeSharp;
|
||||
|
||||
namespace ComputeSharp
|
||||
{
|
||||
public class ReadWriteBuffer<T> { }
|
||||
}
|
||||
|
||||
namespace MyFancyApp.Sample
|
||||
{
|
||||
public struct Foo
|
||||
{
|
||||
public bool bar;
|
||||
}
|
||||
|
||||
public struct MyShader : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteBuffer<Foo> buffer;
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
VerifyGeneratedDiagnostics<IShaderGenerator>(source, "CMPS0047", "CMPS0050");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the output of a source generator.
|
||||
/// </summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする