From 0919e5b1b47b2d2429025dfa8273a40d29c75c5a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 14 Oct 2023 01:08:06 +0200 Subject: [PATCH] Fix incorrect resource count in dispatch data --- ...ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs | 8 +++----- src/ComputeSharp.SourceGenerators/IShaderGenerator.cs | 1 + src/ComputeSharp.SourceGenerators/Models/ShaderInfo.cs | 2 ++ 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs index ee7c1249..6c272144 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs @@ -24,12 +24,10 @@ partial class IShaderGenerator using (writer.WriteBlock()) { - int numberOfResources = info.ResourceDescriptors.Length; - writer.WriteLine($"global::System.Span span0 = stackalloc uint[{info.Root32BitConstantCount}];"); - writer.WriteLineIf($"global::System.Span span1 = stackalloc ulong[{numberOfResources}];", numberOfResources > 0); + writer.WriteLineIf($"global::System.Span span1 = stackalloc ulong[{info.ResourceCount}];", info.ResourceCount > 0); writer.WriteLine("ref uint r0 = ref span0[0];"); - writer.WriteLineIf("ref ulong r1 = ref span1[0];", numberOfResources > 0); + writer.WriteLineIf("ref ulong r1 = ref span1[0];", info.ResourceCount > 0); // Append the statements for the dispatch ranges writer.WriteLine("span0[0] = (uint)x;"); @@ -94,7 +92,7 @@ partial class IShaderGenerator // Load the prepared buffers writer.WriteLine("loader.LoadCapturedValues(span0);"); - writer.WriteLineIf("loader.LoadCapturedResources(span1);", numberOfResources > 0); + writer.WriteLineIf("loader.LoadCapturedResources(span1);", info.ResourceCount > 0); } } } diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs index ecabb530..f7b11ec2 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs @@ -125,6 +125,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator IsSamplerUsed: isSamplerUsed, Fields: fieldInfos, ResourceDescriptors: resourceDescriptors, + ResourceCount: resourceCount, Root32BitConstantCount: root32BitConstantCount, HlslInfoKey: hlslInfoKey, HlslInfo: hlslInfo, diff --git a/src/ComputeSharp.SourceGenerators/Models/ShaderInfo.cs b/src/ComputeSharp.SourceGenerators/Models/ShaderInfo.cs index c9cd430a..cb51e35d 100644 --- a/src/ComputeSharp.SourceGenerators/Models/ShaderInfo.cs +++ b/src/ComputeSharp.SourceGenerators/Models/ShaderInfo.cs @@ -14,6 +14,7 @@ namespace ComputeSharp.SourceGenerators.Models; /// Whether or not the static sampler is used. /// The description on shader instance fields. /// The sequence of resource descriptors for the shader. +/// The total number of captured resources in the shader. /// The size of the shader root signature, in 32 bit constants. /// The key with processed info on the shader. /// The value with processed info on the shader. @@ -27,6 +28,7 @@ internal sealed record ShaderInfo( bool IsSamplerUsed, EquatableArray Fields, EquatableArray ResourceDescriptors, + int ResourceCount, int Root32BitConstantCount, HlslBytecodeInfoKey HlslInfoKey, HlslBytecodeInfo HlslInfo,