From f5b38e1af8c64bf9dfc3ba116e71a4dab60a2110 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 15 Oct 2023 20:50:15 +0200 Subject: [PATCH] Update D3D12 generator to implement descriptor interface --- ...rDescriptorGenerator.LoadConstantBuffer.cs | 6 -- ...ator.CreateBuildHlslSourceMethod.Syntax.cs | 2 +- ...nerator.CreateLoadBytecodeMethod.Syntax.cs | 8 +-- ...tor.CreateLoadDispatchDataMethod.Syntax.cs | 16 +++-- ...rGenerator.CreateLoadDispatchDataMethod.cs | 6 -- ...CreateLoadDispatchMetadataMethod.Syntax.cs | 6 +- .../IShaderGenerator.cs | 3 +- .../Helpers/DebugDispatchDataLoader.cs | 2 +- .../ShaderDataLoaderTests.cs | 58 +++++++++---------- tests/ComputeSharp.Tests/ShadersTests.cs | 9 +-- .../ThreadGroupSizeTests.cs | 26 ++++----- 11 files changed, 67 insertions(+), 75 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.LoadConstantBuffer.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.LoadConstantBuffer.cs index 8b644d65..7f7dd538 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.LoadConstantBuffer.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.LoadConstantBuffer.cs @@ -51,12 +51,6 @@ partial class D2DPixelShaderDescriptorGenerator string fieldName = fieldSymbol.Name; string typeName = fieldSymbol.Type.GetFullyQualifiedMetadataName(); - // Disambiguates the name of target fields against the current input parameters - if (fieldName is "loader") - { - fieldName = $"this.{fieldName}"; - } - // The first item in each nested struct needs to be aligned to 16 bytes if (isFirstField && fieldPath.Length > 0) { diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs index 555652a0..1c221929 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs @@ -19,7 +19,7 @@ partial class IShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(GeneratorName); - writer.WriteLine($"readonly string global::ComputeSharp.__Internals.IShader.HlslSource =>"); + writer.WriteLine($"readonly string global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.HlslSource =>"); writer.IncreaseIndent(); writer.WriteLine("\"\"\""); writer.Write(info.HlslInfoKey.HlslSource, isMultiline: true); diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs index bd414527..ba585943 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs @@ -20,7 +20,7 @@ partial class IShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(GeneratorName); - writer.Write($"readonly global::System.ReadOnlyMemory global::ComputeSharp.__Internals.IShader.HlslBytecode => "); + writer.Write($"readonly global::System.ReadOnlyMemory global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.HlslBytecode => "); // Just like with the D2D1 generator, only return the MemoryManager if we do have HLSL bytecode if (info.HlslInfo is not HlslBytecodeInfo.Success) @@ -129,7 +129,7 @@ partial class IShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(GeneratorName); - writer.WriteLine($"readonly int global::ComputeSharp.__Internals.IShader.ThreadsX => {info.ThreadsX};"); + writer.WriteLine($"readonly int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ThreadsX => {info.ThreadsX};"); } /// @@ -141,7 +141,7 @@ partial class IShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(GeneratorName); - writer.WriteLine($"readonly int global::ComputeSharp.__Internals.IShader.ThreadsY => {info.ThreadsY};"); + writer.WriteLine($"readonly int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ThreadsY => {info.ThreadsY};"); } /// @@ -153,7 +153,7 @@ partial class IShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(GeneratorName); - writer.WriteLine($"readonly int global::ComputeSharp.__Internals.IShader.ThreadsZ => {info.ThreadsZ};"); + writer.WriteLine($"readonly int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ThreadsZ => {info.ThreadsZ};"); } } } \ No newline at end of file diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs index 652ee3ba..0b05d98b 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs @@ -17,10 +17,12 @@ partial class IShaderGenerator /// The instance to write into. public static void WriteLoadConstantBufferSyntax(ShaderInfo info, IndentedTextWriter writer) { + string typeName = info.Hierarchy.Hierarchy[0].QualifiedName; + writer.WriteLine("/// "); writer.WriteGeneratedAttributes(GeneratorName); writer.WriteLine("[global::System.Runtime.CompilerServices.SkipLocalsInit]"); - writer.WriteLine("readonly void global::ComputeSharp.__Internals.IShader.LoadConstantBuffer(ref TLoader loader, int x, int y, int z)"); + writer.WriteLine($"readonly void global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{typeName}>.LoadConstantBuffer(in {typeName} shader, ref TLoader loader, int x, int y, int z)"); using (writer.WriteBlock()) { @@ -41,14 +43,14 @@ partial class IShaderGenerator // Read a boolean value and cast it to Bool first, which will apply the correct size expansion writer.WriteLine( $"global::System.Runtime.CompilerServices.Unsafe.As(ref span[{primitive.Offset}]) = " + - $"(global::ComputeSharp.Bool){string.Join(".", primitive.FieldPath)};"); + $"(global::ComputeSharp.Bool)shader.{string.Join(".", primitive.FieldPath)};"); break; case FieldInfo.Primitive primitive: // Read a primitive value and serialize it into the target buffer writer.WriteLine( $"global::System.Runtime.CompilerServices.Unsafe.As(ref span[{primitive.Offset}]) = " + - $"{string.Join(".", primitive.FieldPath)};"); + $"shader.{string.Join(".", primitive.FieldPath)};"); break; case FieldInfo.NonLinearMatrix matrix: @@ -61,7 +63,7 @@ partial class IShaderGenerator // ref global::System.Runtime.CompilerServices.Unsafe.AsRef(in )); writer.WriteLine( $"ref {rowTypeName} {rowLocalName} = ref global::System.Runtime.CompilerServices.Unsafe.As(" + - $"ref global::System.Runtime.CompilerServices.Unsafe.AsRef(in {string.Join(".", matrix.FieldPath)}));"); + $"ref global::System.Runtime.CompilerServices.Unsafe.AsRef(in shader.{string.Join(".", matrix.FieldPath)}));"); // Generate the loading code for each individual row, with proper alignment. // This will result in the following (assuming Float2x3 m): @@ -92,9 +94,11 @@ partial class IShaderGenerator /// The instance to write into. public static void WriteLoadGraphicsResourcesSyntax(ShaderInfo info, IndentedTextWriter writer) { + string typeName = info.Hierarchy.Hierarchy[0].QualifiedName; + writer.WriteLine("/// "); writer.WriteGeneratedAttributes(GeneratorName); - writer.WriteLine("readonly void global::ComputeSharp.__Internals.IShader.LoadGraphicsResources(ref TLoader loader)"); + writer.WriteLine($"readonly void global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{typeName}>.LoadGraphicsResources(in {typeName} shader, ref TLoader loader)"); using (writer.WriteBlock()) { @@ -103,7 +107,7 @@ partial class IShaderGenerator { if (fieldInfo is FieldInfo.Resource resource) { - writer.WriteLine($"loader.LoadGraphicsResource({resource.FieldName}, {resource.Offset});"); + writer.WriteLine($"loader.LoadGraphicsResource(shader.{resource.FieldName}, {resource.Offset});"); } } } diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs index 6048c79b..3dc48d0b 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs @@ -56,12 +56,6 @@ partial class IShaderGenerator string fieldName = fieldSymbol.Name; string typeName = fieldSymbol.Type.GetFullyQualifiedMetadataName(); - // Disambiguates the name of target fields against the current input parameters - if (fieldName is "loader" or "device" or "x" or "y" or "z") - { - fieldName = $"this.{fieldName}"; - } - // The first item in each nested struct needs to be aligned to 16 bytes if (isFirstField && fieldPath.Length > 0) { diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs index 5e3a9eca..9529d180 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs @@ -19,7 +19,7 @@ partial class IShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(GeneratorName); - writer.WriteLine($"readonly int global::ComputeSharp.__Internals.IShader.ConstantBufferSize => {info.ConstantBufferSizeInBytes};"); + writer.WriteLine($"readonly int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ConstantBufferSize => {info.ConstantBufferSizeInBytes};"); } /// @@ -31,7 +31,7 @@ partial class IShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(GeneratorName); - writer.WriteLine($"readonly bool global::ComputeSharp.__Internals.IShader.IsStaticSamplerRequired => {info.IsSamplerUsed.ToString().ToLowerInvariant()};"); + writer.WriteLine($"readonly bool global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.IsStaticSamplerRequired => {info.IsSamplerUsed.ToString().ToLowerInvariant()};"); } /// @@ -43,7 +43,7 @@ partial class IShaderGenerator { writer.WriteLine("/// "); writer.WriteGeneratedAttributes(GeneratorName); - writer.Write($"readonly global::System.ReadOnlyMemory global::ComputeSharp.__Internals.IShader.ResourceDescriptorRanges => "); + writer.Write($"readonly global::System.ReadOnlyMemory global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ResourceDescriptorRanges => "); // If there are no declared resources, just return an empty collection if (info.ResourceDescriptors.IsEmpty) diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs index 24559ce2..d7cd5c30 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Immutable; using System.Linq; using ComputeSharp.SourceGeneration.Extensions; @@ -166,7 +165,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator item.Hierarchy.WriteSyntax( state: item, writer: writer, - baseTypes: ReadOnlySpan.Empty, + baseTypes: new[] { $"global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{item.Hierarchy.Hierarchy[0].QualifiedName}>" }, memberCallbacks: declaredMembers.WrittenSpan); // Append any additional types as well diff --git a/tests/ComputeSharp.Tests.Internals/Helpers/DebugDispatchDataLoader.cs b/tests/ComputeSharp.Tests.Internals/Helpers/DebugDispatchDataLoader.cs index 820ee39e..57d537d3 100644 --- a/tests/ComputeSharp.Tests.Internals/Helpers/DebugDispatchDataLoader.cs +++ b/tests/ComputeSharp.Tests.Internals/Helpers/DebugDispatchDataLoader.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using ComputeSharp.__Internals; +using ComputeSharp.Descriptors; namespace ComputeSharp.Tests.Internals.Helpers; diff --git a/tests/ComputeSharp.Tests.Internals/ShaderDataLoaderTests.cs b/tests/ComputeSharp.Tests.Internals/ShaderDataLoaderTests.cs index 66eb2daf..0562dc04 100644 --- a/tests/ComputeSharp.Tests.Internals/ShaderDataLoaderTests.cs +++ b/tests/ComputeSharp.Tests.Internals/ShaderDataLoaderTests.cs @@ -1,5 +1,5 @@ using System.Runtime.CompilerServices; -using ComputeSharp.__Internals; +using ComputeSharp.Descriptors; using ComputeSharp.Tests.Internals.Helpers; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -28,18 +28,18 @@ public partial class ShaderDataLoaderTests CapturedResourceShader shader = new(buffer); DebugDispatchDataLoader dataLoader = new(); - ((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333); + ((IComputeShaderDescriptor)shader).LoadConstantBuffer(in shader, ref dataLoader, 111, 222, 333); - Assert.AreEqual(12, ((IShader)shader).ConstantBufferSize); + Assert.AreEqual(12, ((IComputeShaderDescriptor)shader).ConstantBufferSize); Assert.IsNotNull(dataLoader.ConstantBuffer); Assert.AreEqual(12, dataLoader.ConstantBuffer.Length); Assert.AreEqual(111, Unsafe.As(ref dataLoader.ConstantBuffer[0])); Assert.AreEqual(222, Unsafe.As(ref dataLoader.ConstantBuffer[4])); Assert.AreEqual(333, Unsafe.As(ref dataLoader.ConstantBuffer[8])); - ((IShader)shader).LoadGraphicsResources(ref dataLoader); + ((IComputeShaderDescriptor)shader).LoadGraphicsResources(in shader, ref dataLoader); - Assert.AreEqual(1, ((IShader)shader).ResourceDescriptorRanges.Length); + Assert.AreEqual(1, ((IComputeShaderDescriptor)shader).ResourceDescriptorRanges.Length); Assert.AreSame(buffer, dataLoader.GraphicsResources[0].Resource); Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index); } @@ -68,9 +68,9 @@ public partial class ShaderDataLoaderTests MultipleResourcesAndPrimitivesShader shader = new(buffer0, buffer1, 1, 22, 77); DebugDispatchDataLoader dataLoader = new(); - ((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333); + ((IComputeShaderDescriptor)shader).LoadConstantBuffer(in shader, ref dataLoader, 111, 222, 333); - Assert.AreEqual(24, ((IShader)shader).ConstantBufferSize); + Assert.AreEqual(24, ((IComputeShaderDescriptor)shader).ConstantBufferSize); Assert.IsNotNull(dataLoader.ConstantBuffer); Assert.AreEqual(24, dataLoader.ConstantBuffer.Length); Assert.AreEqual(111, Unsafe.As(ref dataLoader.ConstantBuffer[0])); @@ -80,9 +80,9 @@ public partial class ShaderDataLoaderTests Assert.AreEqual(22, Unsafe.As(ref dataLoader.ConstantBuffer[16])); Assert.AreEqual(77, Unsafe.As(ref dataLoader.ConstantBuffer[20])); - ((IShader)shader).LoadGraphicsResources(ref dataLoader); + ((IComputeShaderDescriptor)shader).LoadGraphicsResources(in shader, ref dataLoader); - Assert.AreEqual(2, ((IShader)shader).ResourceDescriptorRanges.Length); + Assert.AreEqual(2, ((IComputeShaderDescriptor)shader).ResourceDescriptorRanges.Length); Assert.AreSame(buffer0, dataLoader.GraphicsResources[0].Resource); Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index); Assert.AreSame(buffer1, dataLoader.GraphicsResources[1].Resource); @@ -114,9 +114,9 @@ public partial class ShaderDataLoaderTests ScalarAndVectorTypesShader shader = new(buffer, new(55, 44, 888), 22, 77, new(3.14, 6.28), 42, 9999); DebugDispatchDataLoader dataLoader = new(); - ((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333); + ((IComputeShaderDescriptor)shader).LoadConstantBuffer(in shader, ref dataLoader, 111, 222, 333); - Assert.AreEqual(72, ((IShader)shader).ConstantBufferSize); + Assert.AreEqual(72, ((IComputeShaderDescriptor)shader).ConstantBufferSize); Assert.IsNotNull(dataLoader.ConstantBuffer); Assert.AreEqual(72, dataLoader.ConstantBuffer.Length); Assert.AreEqual(111, Unsafe.As(ref dataLoader.ConstantBuffer[0])); @@ -132,9 +132,9 @@ public partial class ShaderDataLoaderTests Assert.AreEqual(42, Unsafe.As(ref dataLoader.ConstantBuffer[64])); Assert.AreEqual(9999, Unsafe.As(ref dataLoader.ConstantBuffer[68])); - ((IShader)shader).LoadGraphicsResources(ref dataLoader); + ((IComputeShaderDescriptor)shader).LoadGraphicsResources(in shader, ref dataLoader); - Assert.AreEqual(1, ((IShader)shader).ResourceDescriptorRanges.Length); + Assert.AreEqual(1, ((IComputeShaderDescriptor)shader).ResourceDescriptorRanges.Length); Assert.AreSame(buffer, dataLoader.GraphicsResources[0].Resource); Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index); } @@ -175,9 +175,9 @@ public partial class ShaderDataLoaderTests d: 9999); DebugDispatchDataLoader dataLoader = new(); - ((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333); + ((IComputeShaderDescriptor)shader).LoadConstantBuffer(in shader, ref dataLoader, 111, 222, 333); - Assert.AreEqual(124, ((IShader)shader).ConstantBufferSize); + Assert.AreEqual(124, ((IComputeShaderDescriptor)shader).ConstantBufferSize); Assert.IsNotNull(dataLoader.ConstantBuffer); Assert.AreEqual(124, dataLoader.ConstantBuffer.Length); Assert.AreEqual(111, Unsafe.As(ref dataLoader.ConstantBuffer[0])); @@ -204,9 +204,9 @@ public partial class ShaderDataLoaderTests Assert.AreEqual(44, Unsafe.As(ref dataLoader.ConstantBuffer[116])); Assert.AreEqual(9999, Unsafe.As(ref dataLoader.ConstantBuffer[120])); - ((IShader)shader).LoadGraphicsResources(ref dataLoader); + ((IComputeShaderDescriptor)shader).LoadGraphicsResources(in shader, ref dataLoader); - Assert.AreEqual(1, ((IShader)shader).ResourceDescriptorRanges.Length); + Assert.AreEqual(1, ((IComputeShaderDescriptor)shader).ResourceDescriptorRanges.Length); Assert.AreSame(buffer, dataLoader.GraphicsResources[0].Resource); Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index); } @@ -254,9 +254,9 @@ public partial class ShaderDataLoaderTests d: 9999)); DebugDispatchDataLoader dataLoader = new(); - ((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333); + ((IComputeShaderDescriptor)shader).LoadConstantBuffer(in shader, ref dataLoader, 111, 222, 333); - Assert.AreEqual(124, ((IShader)shader).ConstantBufferSize); + Assert.AreEqual(124, ((IComputeShaderDescriptor)shader).ConstantBufferSize); Assert.IsNotNull(dataLoader.ConstantBuffer); Assert.AreEqual(124, dataLoader.ConstantBuffer.Length); Assert.AreEqual(111, Unsafe.As(ref dataLoader.ConstantBuffer[0])); @@ -283,9 +283,9 @@ public partial class ShaderDataLoaderTests Assert.AreEqual(44, Unsafe.As(ref dataLoader.ConstantBuffer[116])); Assert.AreEqual(9999, Unsafe.As(ref dataLoader.ConstantBuffer[120])); - ((IShader)shader).LoadGraphicsResources(ref dataLoader); + ((IComputeShaderDescriptor)shader).LoadGraphicsResources(in shader, ref dataLoader); - Assert.AreEqual(1, ((IShader)shader).ResourceDescriptorRanges.Length); + Assert.AreEqual(1, ((IComputeShaderDescriptor)shader).ResourceDescriptorRanges.Length); Assert.AreSame(buffer, dataLoader.GraphicsResources[0].Resource); Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index); } @@ -357,9 +357,9 @@ public partial class ShaderDataLoaderTests b: new(333.3f, 444.4f)))); DebugDispatchDataLoader dataLoader = new(); - ((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333); + ((IComputeShaderDescriptor)shader).LoadConstantBuffer(in shader, ref dataLoader, 111, 222, 333); - Assert.AreEqual(188, ((IShader)shader).ConstantBufferSize); + Assert.AreEqual(188, ((IComputeShaderDescriptor)shader).ConstantBufferSize); Assert.IsNotNull(dataLoader.ConstantBuffer); Assert.AreEqual(188, dataLoader.ConstantBuffer.Length); Assert.AreEqual(111, Unsafe.As(ref dataLoader.ConstantBuffer[0])); @@ -399,9 +399,9 @@ public partial class ShaderDataLoaderTests Assert.AreEqual(333.3f, Unsafe.As(ref dataLoader.ConstantBuffer[180])); Assert.AreEqual(444.4f, Unsafe.As(ref dataLoader.ConstantBuffer[184])); - ((IShader)shader).LoadGraphicsResources(ref dataLoader); + ((IComputeShaderDescriptor)shader).LoadGraphicsResources(in shader, ref dataLoader); - Assert.AreEqual(1, ((IShader)shader).ResourceDescriptorRanges.Length); + Assert.AreEqual(1, ((IComputeShaderDescriptor)shader).ResourceDescriptorRanges.Length); Assert.AreSame(buffer, dataLoader.GraphicsResources[0].Resource); Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index); } @@ -438,9 +438,9 @@ public partial class ShaderDataLoaderTests AmbiguousNamesShader shader = new(a, b, c, x, y, z, 7777, 8888, 9999); DebugDispatchDataLoader dataLoader = new(); - ((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333); + ((IComputeShaderDescriptor)shader).LoadConstantBuffer(in shader, ref dataLoader, 111, 222, 333); - Assert.AreEqual(24, ((IShader)shader).ConstantBufferSize); + Assert.AreEqual(24, ((IComputeShaderDescriptor)shader).ConstantBufferSize); Assert.IsNotNull(dataLoader.ConstantBuffer); Assert.AreEqual(24, dataLoader.ConstantBuffer.Length); Assert.AreEqual(111, Unsafe.As(ref dataLoader.ConstantBuffer[0])); @@ -450,9 +450,9 @@ public partial class ShaderDataLoaderTests Assert.AreEqual(8888, Unsafe.As(ref dataLoader.ConstantBuffer[16])); Assert.AreEqual(9999, Unsafe.As(ref dataLoader.ConstantBuffer[20])); - ((IShader)shader).LoadGraphicsResources(ref dataLoader); + ((IComputeShaderDescriptor)shader).LoadGraphicsResources(in shader, ref dataLoader); - Assert.AreEqual(6, ((IShader)shader).ResourceDescriptorRanges.Length); + Assert.AreEqual(6, ((IComputeShaderDescriptor)shader).ResourceDescriptorRanges.Length); Assert.AreSame(a, dataLoader.GraphicsResources[0].Resource); Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index); Assert.AreSame(b, dataLoader.GraphicsResources[1].Resource); diff --git a/tests/ComputeSharp.Tests/ShadersTests.cs b/tests/ComputeSharp.Tests/ShadersTests.cs index b49e9af8..4592bcf7 100644 --- a/tests/ComputeSharp.Tests/ShadersTests.cs +++ b/tests/ComputeSharp.Tests/ShadersTests.cs @@ -2,6 +2,7 @@ using System; using System.IO; using System.Reflection; using System.Runtime.InteropServices; +using ComputeSharp.Descriptors; using ComputeSharp.Interop; using ComputeSharp.SwapChain.Shaders; using ComputeSharp.Tests.Attributes; @@ -169,7 +170,7 @@ public class ShadersTests if (typeof(IComputeShader).IsAssignableFrom(shaderType)) { static void RunComputeShader(ReadWriteTexture2D texture) - where T : struct, IComputeShader + where T : struct, IComputeShader, IComputeShaderDescriptor { ShaderInfo info = ReflectionServices.GetShaderInfo(); @@ -185,7 +186,7 @@ public class ShadersTests else { static void RunPixelShader(ReadWriteTexture2D texture) - where T : struct, IComputeShader + where T : struct, IComputeShader, IComputeShaderDescriptor { ShaderInfo info = ReflectionServices.GetShaderInfo(); @@ -229,8 +230,8 @@ public class ShadersTests Func, TCompute> computeFactory, Func, TPixel> pixelFactory, float delta) - where TCompute : struct, IComputeShader - where TPixel : struct, IComputeShader + where TCompute : struct, IComputeShader, IComputeShaderDescriptor + where TPixel : struct, IComputeShader, IComputeShaderDescriptor { _ = device.Get(); diff --git a/tests/ComputeSharp.Tests/ThreadGroupSizeTests.cs b/tests/ComputeSharp.Tests/ThreadGroupSizeTests.cs index ca32174b..b36df45e 100644 --- a/tests/ComputeSharp.Tests/ThreadGroupSizeTests.cs +++ b/tests/ComputeSharp.Tests/ThreadGroupSizeTests.cs @@ -1,4 +1,4 @@ -using ComputeSharp.__Internals; +using ComputeSharp.Descriptors; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace ComputeSharp.Tests; @@ -10,21 +10,21 @@ public partial class ThreadGroupSizeTests [TestMethod] public unsafe void Verify_ThreadGroupSize() { - Assert.AreEqual(64, ((IShader)default(DispatchXShader)).ThreadsX); - Assert.AreEqual(1, ((IShader)default(DispatchXShader)).ThreadsY); - Assert.AreEqual(1, ((IShader)default(DispatchXShader)).ThreadsZ); + Assert.AreEqual(64, ((IComputeShaderDescriptor)default(DispatchXShader)).ThreadsX); + Assert.AreEqual(1, ((IComputeShaderDescriptor)default(DispatchXShader)).ThreadsY); + Assert.AreEqual(1, ((IComputeShaderDescriptor)default(DispatchXShader)).ThreadsZ); - Assert.AreEqual(8, ((IShader)default(DispatchXYShader)).ThreadsX); - Assert.AreEqual(8, ((IShader)default(DispatchXYShader)).ThreadsY); - Assert.AreEqual(1, ((IShader)default(DispatchXYShader)).ThreadsZ); + Assert.AreEqual(8, ((IComputeShaderDescriptor)default(DispatchXYShader)).ThreadsX); + Assert.AreEqual(8, ((IComputeShaderDescriptor)default(DispatchXYShader)).ThreadsY); + Assert.AreEqual(1, ((IComputeShaderDescriptor)default(DispatchXYShader)).ThreadsZ); - Assert.AreEqual(4, ((IShader)default(DispatchXYZShader)).ThreadsX); - Assert.AreEqual(4, ((IShader)default(DispatchXYZShader)).ThreadsY); - Assert.AreEqual(4, ((IShader)default(DispatchXYZShader)).ThreadsZ); + Assert.AreEqual(4, ((IComputeShaderDescriptor)default(DispatchXYZShader)).ThreadsX); + Assert.AreEqual(4, ((IComputeShaderDescriptor)default(DispatchXYZShader)).ThreadsY); + Assert.AreEqual(4, ((IComputeShaderDescriptor)default(DispatchXYZShader)).ThreadsZ); - Assert.AreEqual(11, ((IShader)default(DispatchCustomShader)).ThreadsX); - Assert.AreEqual(14, ((IShader)default(DispatchCustomShader)).ThreadsY); - Assert.AreEqual(6, ((IShader)default(DispatchCustomShader)).ThreadsZ); + Assert.AreEqual(11, ((IComputeShaderDescriptor)default(DispatchCustomShader)).ThreadsX); + Assert.AreEqual(14, ((IComputeShaderDescriptor)default(DispatchCustomShader)).ThreadsY); + Assert.AreEqual(6, ((IComputeShaderDescriptor)default(DispatchCustomShader)).ThreadsZ); } [AutoConstructor]