From 581eb40ed17915407e8a9c5766fe0e169d9a6249 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 27 Aug 2022 18:20:27 +0200 Subject: [PATCH] Fix handling of Bool/bool types in shader rewriter --- .../Mappings/HlslKnownTypes.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownTypes.cs b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownTypes.cs index af0b139b..9fef8219 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownTypes.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownTypes.cs @@ -67,6 +67,7 @@ internal static partial class HlslKnownTypes Dictionary knownTypes = new() { [typeof(bool).FullName] = "bool", + [typeof(Bool).FullName] = "bool", [typeof(int).FullName] = "int", [typeof(uint).FullName] = "uint", [typeof(float).FullName] = "float", @@ -256,6 +257,15 @@ internal static partial class HlslKnownTypes // Explore all input types and their nested types foreach (INamedTypeSymbol type in discoveredTypes) { + // Special case for bool types. These types are blocked if they appear as fields in custom struct types, + // but are otherwise allowed. For instance, it is fine to use them in captured values for a shader (as + // the dispatch data loader will perform the correct marshalling) as well as in locals/parameters. This + // branch prevents crawling a processed type if it's just bool at the top level (ie. not a custom struct). + if (type.SpecialType == SpecialType.System_Boolean) + { + continue; + } + ExploreTypes(type, customTypes, invalidTypes2); }