diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/ColorfulInfinity.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/ColorfulInfinity.cs index 224ba76f..8d4b2b1d 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/ColorfulInfinity.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/ColorfulInfinity.cs @@ -8,7 +8,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] -internal readonly partial struct ColorfulInfinity : IPixelShader +internal readonly partial struct ColorfulInfinity : IComputeShader { /// /// The current time since the start of the application. diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/ContouredLayers.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/ContouredLayers.cs index 99b50e94..52cd77f2 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/ContouredLayers.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/ContouredLayers.cs @@ -7,7 +7,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] -internal readonly partial struct ContouredLayers : IPixelShader +internal readonly partial struct ContouredLayers : IComputeShader { /// /// The current time Hlsl.Since the start of the application. diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/ExtrudedTruchetPattern.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/ExtrudedTruchetPattern.cs index ceea8dce..44905851 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/ExtrudedTruchetPattern.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/ExtrudedTruchetPattern.cs @@ -7,7 +7,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] -internal readonly partial struct ExtrudedTruchetPattern : IPixelShader +internal readonly partial struct ExtrudedTruchetPattern : IComputeShader { /// /// The current time since the start of the application. diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/FourColorGradient.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/FourColorGradient.cs index 92bff991..123f0575 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/FourColorGradient.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/FourColorGradient.cs @@ -8,7 +8,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] -internal readonly partial struct FourColorGradient : IPixelShader +internal readonly partial struct FourColorGradient : IComputeShader { /// /// The current time since the start of the application. diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/FractalTiling.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/FractalTiling.cs index 4478d2dc..156ece01 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/FractalTiling.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/FractalTiling.cs @@ -8,7 +8,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] -internal readonly partial struct FractalTiling : IPixelShader +internal readonly partial struct FractalTiling : IComputeShader { /// /// The current time since the start of the application. diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/HelloWorld.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/HelloWorld.cs index 192ec941..75fc97c1 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/HelloWorld.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/HelloWorld.cs @@ -6,7 +6,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] -internal readonly partial struct HelloWorld : IPixelShader +internal readonly partial struct HelloWorld : IComputeShader { /// /// The current time since the start of the application. diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/MengerJourney.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/MengerJourney.cs index 958726ae..1b006248 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/MengerJourney.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/MengerJourney.cs @@ -7,7 +7,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] -internal readonly partial struct MengerJourney : IPixelShader +internal readonly partial struct MengerJourney : IComputeShader { /// /// The current time since the start of the application. diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/Octagrams.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/Octagrams.cs index 3190d925..1fc1f0a6 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/Octagrams.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/Octagrams.cs @@ -7,7 +7,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] -internal readonly partial struct Octagrams : IPixelShader +internal readonly partial struct Octagrams : IComputeShader { /// /// The current time since the start of the application. diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/ProteanClouds.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/ProteanClouds.cs index ef98690e..6799eda1 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/ProteanClouds.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/ProteanClouds.cs @@ -8,7 +8,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] -internal readonly partial struct ProteanClouds : IPixelShader +internal readonly partial struct ProteanClouds : IComputeShader { /// /// The current time Hlsl.Since the start of the application. diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/PyramidPattern.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/PyramidPattern.cs index 5ffc2fa2..f4260f4c 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/PyramidPattern.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/PyramidPattern.cs @@ -8,7 +8,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] -internal readonly partial struct PyramidPattern : IPixelShader +internal readonly partial struct PyramidPattern : IComputeShader { /// /// The current time Hlsl.Since the start of the application. diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/TerracedHills.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/TerracedHills.cs index 1d8ab189..6eeff2ba 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/TerracedHills.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/TerracedHills.cs @@ -7,7 +7,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] -internal readonly partial struct TerracedHills : IPixelShader +internal readonly partial struct TerracedHills : IComputeShader { /// /// The current time since the start of the application. diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/TriangleGridContouring.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/TriangleGridContouring.cs index 60e1af58..a3c03f54 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/TriangleGridContouring.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/TriangleGridContouring.cs @@ -7,7 +7,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] -internal readonly partial struct TriangleGridContouring : IPixelShader +internal readonly partial struct TriangleGridContouring : IComputeShader { /// /// The current time Hlsl.Since the start of the application. diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/TwoTiledTruchet.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/TwoTiledTruchet.cs index 3e44c208..091813da 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/TwoTiledTruchet.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/TwoTiledTruchet.cs @@ -7,7 +7,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] -internal readonly partial struct TwoTiledTruchet : IPixelShader +internal readonly partial struct TwoTiledTruchet : IComputeShader { /// /// The current time since the start of the application. diff --git a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationFactory{T}.cs b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationFactory{T}.cs index 24fe342a..91592432 100644 --- a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationFactory{T}.cs +++ b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationFactory{T}.cs @@ -1,4 +1,5 @@ using System; +using ComputeSharp.Descriptors; using TerraFX.Interop.Windows; namespace ComputeSharp.SwapChain.Backend; @@ -11,7 +12,7 @@ namespace ComputeSharp.SwapChain.Backend; /// The main point of this type is to hide the complexity of from the non-NativeAOT sample. /// internal static class Win32ApplicationFactory - where T : struct, IPixelShader + where T : struct, IComputeShader, IComputeShaderDescriptor { /// /// The instance used to create shaders to run. 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.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.NumericProperties.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.NumericProperties.Syntax.cs index a4896594..0efc43fd 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.NumericProperties.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.NumericProperties.Syntax.cs @@ -10,7 +10,7 @@ partial class D2DPixelShaderDescriptorGenerator /// /// A helper with all logic to generate the available numeric properties. /// - private static partial class NumericProperties + private static class NumericProperties { /// /// Writes the ConstantBufferSize property. diff --git a/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs b/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs index 7ebb877f..adfff47f 100644 --- a/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs +++ b/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs @@ -1,15 +1,13 @@ using System; using System.Runtime.CompilerServices; -using ComputeSharp.__Internals; using ComputeSharp.Core.Extensions; +using ComputeSharp.Descriptors; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; #if !NET6_0_OR_GREATER using DirectX = TerraFX.Interop.DirectX.DirectX2; #endif -#pragma warning disable CS0618 - namespace ComputeSharp.Interop; /// @@ -32,7 +30,7 @@ public static class ReflectionServices /// the APIs to dispatch a shader, the thread sizes would actually be set to a proper value insead. /// public static ShaderInfo GetShaderInfo() - where T : struct, IComputeShader + where T : struct, IComputeShader, IComputeShaderDescriptor { return GetNonGenericShaderInfo(default(T)); } @@ -49,7 +47,7 @@ public static class ReflectionServices /// the APIs to dispatch a shader, the thread sizes would actually be set to a proper value insead. /// public static unsafe ShaderInfo GetShaderInfo(in T shader) - where T : struct, IComputeShader + where T : struct, IComputeShader, IComputeShaderDescriptor { return GetNonGenericShaderInfo(in shader); } @@ -70,7 +68,7 @@ public static class ReflectionServices /// the APIs to dispatch a shader, the thread sizes would actually be set to a proper value insead. /// public static ShaderInfo GetShaderInfo() - where T : struct, IPixelShader + where T : struct, IComputeShader, IComputeShaderDescriptor where TPixel : unmanaged { return GetNonGenericShaderInfo(default(T)); @@ -89,7 +87,7 @@ public static class ReflectionServices /// the APIs to dispatch a shader, the thread sizes would actually be set to a proper value insead. /// public static unsafe ShaderInfo GetShaderInfo(in T shader) - where T : struct, IPixelShader + where T : struct, IComputeShader, IComputeShaderDescriptor where TPixel : unmanaged { return GetNonGenericShaderInfo(in shader); @@ -102,7 +100,7 @@ public static class ReflectionServices /// The input shader to retrieve info for. /// The resulting instance. private static unsafe ShaderInfo GetNonGenericShaderInfo(in T shader) - where T : struct, IShader + where T : struct, IComputeShaderDescriptor { string hlslSource = Unsafe.AsRef(in shader).HlslSource; diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.DispatchDataLoading.Syntax.cs similarity index 86% rename from src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.DispatchDataLoading.Syntax.cs index 652ee3ba..9deae88d 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.DispatchDataLoading.Syntax.cs @@ -5,10 +5,10 @@ using ComputeSharp.SourceGenerators.Models; namespace ComputeSharp.SourceGenerators; /// -partial class IShaderGenerator +partial class ComputeShaderDescriptorGenerator { /// - partial class LoadDispatchData + partial class DispatchDataLoading { /// /// Writes the LoadConstantBuffer method. @@ -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/ComputeShaderDescriptorGenerator.DispatchDataLoading.cs similarity index 95% rename from src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.DispatchDataLoading.cs index 6048c79b..e95b012a 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.DispatchDataLoading.cs @@ -15,12 +15,12 @@ using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors; namespace ComputeSharp.SourceGenerators; /// -partial class IShaderGenerator +partial class ComputeShaderDescriptorGenerator { /// - /// A helper with all logic to generate the LoadDispatchData method. + /// A helper with all logic to generate the dispatch data loading methods. /// - private static partial class LoadDispatchData + private static partial class DispatchDataLoading { /// /// Explores a given type hierarchy and generates statements to load fields. @@ -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.Helpers.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.Helpers.cs similarity index 94% rename from src/ComputeSharp.SourceGenerators/IShaderGenerator.Helpers.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.Helpers.cs index f12485d9..aaa4bcc4 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.Helpers.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.Helpers.cs @@ -3,7 +3,7 @@ using Microsoft.CodeAnalysis; namespace ComputeSharp.SourceGenerators; /// -partial class IShaderGenerator +partial class ComputeShaderDescriptorGenerator { /// /// Gets whether a given type is a compute shader type (ie. implements any of the interfaces). @@ -15,7 +15,7 @@ partial class IShaderGenerator private static bool TryGetIsPixelShaderLike(INamedTypeSymbol typeSymbol, Compilation compilation, out bool result) { INamedTypeSymbol computeShaderSymbol = compilation.GetTypeByMetadataName("ComputeSharp.IComputeShader")!; - INamedTypeSymbol pixelShaderSymbol = compilation.GetTypeByMetadataName("ComputeSharp.IPixelShader`1")!; + INamedTypeSymbol pixelShaderSymbol = compilation.GetTypeByMetadataName("ComputeSharp.IComputeShader`1")!; foreach (INamedTypeSymbol interfaceSymbol in typeSymbol.AllInterfaces) { diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.Syntax.cs similarity index 93% rename from src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.Syntax.cs index bd414527..dcee6b1c 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.Syntax.cs @@ -6,10 +6,10 @@ using ComputeSharp.SourceGenerators.Models; namespace ComputeSharp.SourceGenerators; /// -partial class IShaderGenerator +partial class ComputeShaderDescriptorGenerator { /// - partial class LoadBytecode + partial class HlslBytecode { /// /// Writes the HlslBytecode property. @@ -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.CreateLoadBytecodeMethod.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs similarity index 67% rename from src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs index e21a34e2..adcd069d 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs @@ -22,12 +22,12 @@ using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors; namespace ComputeSharp.SourceGenerators; /// -partial class IShaderGenerator +partial class ComputeShaderDescriptorGenerator { /// - /// A helper with all logic to generate the LoadBytecode method. + /// A helper with all logic to generate the HlslBytecode property. /// - private static partial class LoadBytecode + private static partial class HlslBytecode { /// /// The shared cache of values. @@ -39,91 +39,6 @@ partial class IShaderGenerator /// private static volatile bool areDxcLibrariesLoaded; - /// - /// Gets the thread ids values for a given shader type, if available. - /// - /// The collection of produced instances. - /// The input instance to process. - /// The thread ids value for the X axis. - /// The thread ids value for the Y axis. - /// The thread ids value for the Z axis. - /// Whether compilation should be attempted for the current info. - public static void GetInfo( - ImmutableArrayBuilder diagnostics, - INamedTypeSymbol structDeclarationSymbol, - out int threadsX, - out int threadsY, - out int threadsZ, - out bool isCompilationEnabled) - { - // Try to get the attribute that controls shader precompilation (has to be present when ComputeSharp.Dynamic is not referenced) - if (!structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName(typeof(EmbeddedBytecodeAttribute).FullName, out AttributeData? attribute)) - { - // Emit the diagnostics if dynamic shaders are not supported - diagnostics.Add(MissingEmbeddedBytecodeAttributeWhenDynamicShaderCompilationIsNotSupported, structDeclarationSymbol, structDeclarationSymbol); - - threadsX = threadsY = threadsZ = 0; - isCompilationEnabled = false; - - return; - } - - // Check for a dispatch axis argument first - if (attribute.ConstructorArguments.Length == 1) - { - int dispatchAxis = (int)attribute.ConstructorArguments[0].Value!; - - (threadsX, threadsY, threadsZ) = (DispatchAxis)dispatchAxis switch - { - DispatchAxis.X => (64, 1, 1), - DispatchAxis.Y => (1, 64, 1), - DispatchAxis.Z => (1, 1, 64), - DispatchAxis.XY => (8, 8, 1), - DispatchAxis.XZ => (8, 1, 8), - DispatchAxis.YZ => (1, 8, 8), - DispatchAxis.XYZ => (4, 4, 4), - _ => (0, 0, 0) - }; - - // Validate the dispatch axis argument - if ((threadsX, threadsY, threadsZ) is (0, 0, 0)) - { - diagnostics.Add(InvalidEmbeddedBytecodeDispatchAxis, structDeclarationSymbol, structDeclarationSymbol); - - threadsX = threadsY = threadsZ = 0; - isCompilationEnabled = false; - - return; - } - - isCompilationEnabled = true; - } - else if ( - attribute.ConstructorArguments.Length != 3 || - attribute.ConstructorArguments[0].Value is not int explicitThreadsX || - attribute.ConstructorArguments[1].Value is not int explicitThreadsY || - attribute.ConstructorArguments[2].Value is not int explicitThreadsZ || - explicitThreadsX is < 1 or > 1024 || - explicitThreadsY is < 1 or > 1024 || - explicitThreadsZ is < 1 or > 64) - { - // Failed to validate the thread number arguments - diagnostics.Add(InvalidEmbeddedBytecodeThreadIds, structDeclarationSymbol, structDeclarationSymbol); - - threadsX = threadsY = threadsZ = 0; - isCompilationEnabled = false; - - return; - } - else - { - threadsX = explicitThreadsX; - threadsY = explicitThreadsY; - threadsZ = explicitThreadsZ; - isCompilationEnabled = true; - } - } - /// /// Gets the instance for the input shader info. /// diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.Syntax.cs similarity index 81% rename from src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.Syntax.cs index 555652a0..fdb68dae 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.Syntax.cs @@ -5,13 +5,13 @@ using ComputeSharp.SourceGenerators.Models; namespace ComputeSharp.SourceGenerators; /// -partial class IShaderGenerator +partial class ComputeShaderDescriptorGenerator { /// - partial class BuildHlslSource + partial class HlslSource { /// - /// Writes the BuildHlslSource method. + /// Writes the HlslSource property. /// /// The input instance with gathered shader info. /// The instance to write into. @@ -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.CreateBuildHlslSourceMethod.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs similarity index 98% rename from src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs index 92d1d182..7d6dd476 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs @@ -17,12 +17,12 @@ using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; namespace ComputeSharp.SourceGenerators; /// -partial class IShaderGenerator +partial class ComputeShaderDescriptorGenerator { /// - /// A helper with all logic to generate the BuildHlslSource method. + /// A helper with all logic to generate the HlslSource property. /// - internal static partial class BuildHlslSource + internal static partial class HlslSource { /// /// Gathers all necessary information on a transpiled HLSL source for a given shader type. @@ -59,14 +59,14 @@ partial class IShaderGenerator Dictionary constantDefinitions = new(SymbolEqualityComparer.Default); // A given type can only represent a single shader type - if (structDeclarationSymbol.AllInterfaces.Count(static interfaceSymbol => interfaceSymbol is { Name: nameof(IComputeShader) } or { IsGenericType: true, Name: nameof(IPixelShader) }) > 1) + if (structDeclarationSymbol.AllInterfaces.Count(static interfaceSymbol => interfaceSymbol is { Name: nameof(IComputeShader) } or { IsGenericType: true, Name: nameof(IComputeShader) }) > 1) { diagnostics.Add(MultipleShaderTypesImplemented, structDeclarationSymbol, structDeclarationSymbol); } // Explore the syntax tree and extract the processed info SemanticModelProvider semanticModelProvider = new(compilation); - INamedTypeSymbol? pixelShaderSymbol = structDeclarationSymbol.AllInterfaces.FirstOrDefault(static interfaceSymbol => interfaceSymbol is { IsGenericType: true, Name: nameof(IPixelShader) }); + INamedTypeSymbol? pixelShaderSymbol = structDeclarationSymbol.AllInterfaces.FirstOrDefault(static interfaceSymbol => interfaceSymbol is { IsGenericType: true, Name: nameof(IComputeShader) }); bool isComputeShader = pixelShaderSymbol is null; string? implicitTextureType = isComputeShader ? null : HlslKnownTypes.GetMappedNameForPixelShaderType(pixelShaderSymbol!); (ImmutableArray<(string MetadataName, string Name, string HlslType)> resourceFields, ImmutableArray<(string Name, string HlslType)> valueFields) = GetInstanceFields(diagnostics, structDeclarationSymbol, discoveredTypes, isComputeShader); @@ -364,7 +364,7 @@ partial class IShaderGenerator methodDeclarationSymbol.TypeParameters.Length == 0 && methodDeclarationSymbol.Parameters.Length == 0) || (!isComputeShader && - methodDeclarationSymbol.Name == nameof(IPixelShader.Execute) && + methodDeclarationSymbol.Name == nameof(IComputeShader.Execute) && methodDeclarationSymbol.ReturnType is not null && // TODO: match for pixel type methodDeclarationSymbol.TypeParameters.Length == 0 && methodDeclarationSymbol.Parameters.Length == 0); diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.MetadataProperties.Syntax.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.MetadataProperties.Syntax.cs new file mode 100644 index 00000000..c13050d1 --- /dev/null +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.MetadataProperties.Syntax.cs @@ -0,0 +1,39 @@ +using ComputeSharp.SourceGeneration.Extensions; +using ComputeSharp.SourceGeneration.Helpers; +using ComputeSharp.SourceGenerators.Models; + +namespace ComputeSharp.SourceGenerators; + +/// +partial class ComputeShaderDescriptorGenerator +{ + /// + /// A helper with all logic to generate additional metadata properties + /// + private static class MetadataProperties + { + /// + /// Writes the ConstantBufferSize property. + /// + /// The input instance with gathered shader info. + /// The instance to write into. + public static void WriteConstantBufferSizeSyntax(ShaderInfo info, IndentedTextWriter writer) + { + writer.WriteLine("/// "); + writer.WriteGeneratedAttributes(GeneratorName); + writer.WriteLine($"readonly int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ConstantBufferSize => {info.ConstantBufferSizeInBytes};"); + } + + /// + /// Writes the IsStaticSamplerRequired property. + /// + /// The input instance with gathered shader info. + /// The instance to write into. + public static void WriteIsStaticSamplerRequiredSyntax(ShaderInfo info, IndentedTextWriter writer) + { + writer.WriteLine("/// "); + writer.WriteGeneratedAttributes(GeneratorName); + writer.WriteLine($"readonly bool global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.IsStaticSamplerRequired => {info.IsSamplerUsed.ToString().ToLowerInvariant()};"); + } + } +} \ No newline at end of file diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.NumThreads.Syntax.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.NumThreads.Syntax.cs new file mode 100644 index 00000000..deafb48c --- /dev/null +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.NumThreads.Syntax.cs @@ -0,0 +1,49 @@ +using ComputeSharp.SourceGeneration.Extensions; +using ComputeSharp.SourceGeneration.Helpers; +using ComputeSharp.SourceGenerators.Models; + +namespace ComputeSharp.SourceGenerators; + +/// +partial class ComputeShaderDescriptorGenerator +{ + /// + partial class NumThreads + { + /// + /// Writes the ThreadsX property. + /// + /// The input instance with gathered shader info. + /// The instance to write into. + public static void WriteThreadsXSyntax(ShaderInfo info, IndentedTextWriter writer) + { + writer.WriteLine("/// "); + writer.WriteGeneratedAttributes(GeneratorName); + writer.WriteLine($"readonly int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ThreadsX => {info.ThreadsX};"); + } + + /// + /// Writes the ThreadsY property. + /// + /// The input instance with gathered shader info. + /// The instance to write into. + public static void WriteThreadsYSyntax(ShaderInfo info, IndentedTextWriter writer) + { + writer.WriteLine("/// "); + writer.WriteGeneratedAttributes(GeneratorName); + writer.WriteLine($"readonly int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ThreadsY => {info.ThreadsY};"); + } + + /// + /// Writes the ThreadsZ property. + /// + /// The input instance with gathered shader info. + /// The instance to write into. + public static void WriteThreadsZSyntax(ShaderInfo info, IndentedTextWriter writer) + { + writer.WriteLine("/// "); + writer.WriteGeneratedAttributes(GeneratorName); + 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/ComputeShaderDescriptorGenerator.NumThreads.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.NumThreads.cs new file mode 100644 index 00000000..0efd19fb --- /dev/null +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.NumThreads.cs @@ -0,0 +1,103 @@ +using System; +using ComputeSharp.SourceGeneration.Extensions; +using ComputeSharp.SourceGeneration.Helpers; +using ComputeSharp.SourceGeneration.Models; +using Microsoft.CodeAnalysis; +using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors; + +namespace ComputeSharp.SourceGenerators; + +/// +partial class ComputeShaderDescriptorGenerator +{ + /// + /// A helper with all logic to generate the [numthreads] properties. + /// + private static partial class NumThreads + { + /// + /// Gets the thread ids values for a given shader type, if available. + /// + /// The collection of produced instances. + /// The input instance to process. + /// The thread ids value for the X axis. + /// The thread ids value for the Y axis. + /// The thread ids value for the Z axis. + /// Whether compilation should be attempted for the current info. + public static void GetInfo( + ImmutableArrayBuilder diagnostics, + INamedTypeSymbol structDeclarationSymbol, + out int threadsX, + out int threadsY, + out int threadsZ, + out bool isCompilationEnabled) + { + // Try to get the attribute that controls shader precompilation (has to be present when ComputeSharp.Dynamic is not referenced) + if (!structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName(typeof(EmbeddedBytecodeAttribute).FullName, out AttributeData? attribute)) + { + // Emit the diagnostics if dynamic shaders are not supported + diagnostics.Add(MissingEmbeddedBytecodeAttributeWhenDynamicShaderCompilationIsNotSupported, structDeclarationSymbol, structDeclarationSymbol); + + threadsX = threadsY = threadsZ = 0; + isCompilationEnabled = false; + + return; + } + + // Check for a dispatch axis argument first + if (attribute.ConstructorArguments.Length == 1) + { + int dispatchAxis = (int)attribute.ConstructorArguments[0].Value!; + + (threadsX, threadsY, threadsZ) = (DispatchAxis)dispatchAxis switch + { + DispatchAxis.X => (64, 1, 1), + DispatchAxis.Y => (1, 64, 1), + DispatchAxis.Z => (1, 1, 64), + DispatchAxis.XY => (8, 8, 1), + DispatchAxis.XZ => (8, 1, 8), + DispatchAxis.YZ => (1, 8, 8), + DispatchAxis.XYZ => (4, 4, 4), + _ => (0, 0, 0) + }; + + // Validate the dispatch axis argument + if ((threadsX, threadsY, threadsZ) is (0, 0, 0)) + { + diagnostics.Add(InvalidEmbeddedBytecodeDispatchAxis, structDeclarationSymbol, structDeclarationSymbol); + + threadsX = threadsY = threadsZ = 0; + isCompilationEnabled = false; + + return; + } + + isCompilationEnabled = true; + } + else if ( + attribute.ConstructorArguments.Length != 3 || + attribute.ConstructorArguments[0].Value is not int explicitThreadsX || + attribute.ConstructorArguments[1].Value is not int explicitThreadsY || + attribute.ConstructorArguments[2].Value is not int explicitThreadsZ || + explicitThreadsX is < 1 or > 1024 || + explicitThreadsY is < 1 or > 1024 || + explicitThreadsZ is < 1 or > 64) + { + // Failed to validate the thread number arguments + diagnostics.Add(InvalidEmbeddedBytecodeThreadIds, structDeclarationSymbol, structDeclarationSymbol); + + threadsX = threadsY = threadsZ = 0; + isCompilationEnabled = false; + + return; + } + else + { + threadsX = explicitThreadsX; + threadsY = explicitThreadsY; + threadsZ = explicitThreadsZ; + isCompilationEnabled = true; + } + } + } +} \ No newline at end of file diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.ResourceDescriptorRanges.Syntax.cs similarity index 73% rename from src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.ResourceDescriptorRanges.Syntax.cs index 5e3a9eca..4a86db94 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.ResourceDescriptorRanges.Syntax.cs @@ -5,35 +5,11 @@ using ComputeSharp.SourceGenerators.Models; namespace ComputeSharp.SourceGenerators; /// -partial class IShaderGenerator +partial class ComputeShaderDescriptorGenerator { /// - partial class LoadDispatchMetadata + partial class ResourceDescriptorRanges { - /// - /// Writes the ConstantBufferSize property. - /// - /// The input instance with gathered shader info. - /// The instance to write into. - public static void WriteConstantBufferSizeSyntax(ShaderInfo info, IndentedTextWriter writer) - { - writer.WriteLine("/// "); - writer.WriteGeneratedAttributes(GeneratorName); - writer.WriteLine($"readonly int global::ComputeSharp.__Internals.IShader.ConstantBufferSize => {info.ConstantBufferSizeInBytes};"); - } - - /// - /// Writes the IsStaticSamplerRequired property. - /// - /// The input instance with gathered shader info. - /// The instance to write into. - public static void WriteIsStaticSamplerRequiredSyntax(ShaderInfo info, IndentedTextWriter writer) - { - writer.WriteLine("/// "); - writer.WriteGeneratedAttributes(GeneratorName); - writer.WriteLine($"readonly bool global::ComputeSharp.__Internals.IShader.IsStaticSamplerRequired => {info.IsSamplerUsed.ToString().ToLowerInvariant()};"); - } - /// /// Writes the ResourceDescriptorRanges property. /// @@ -43,7 +19,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.CreateLoadDispatchMetadataMethod.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.ResourceDescriptorRanges.cs similarity index 91% rename from src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.ResourceDescriptorRanges.cs index 55741a13..2adf9096 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.ResourceDescriptorRanges.cs @@ -6,12 +6,12 @@ using ComputeSharp.SourceGenerators.Models; namespace ComputeSharp.SourceGenerators; /// -partial class IShaderGenerator +partial class ComputeShaderDescriptorGenerator { /// - /// A helper with all logic to generate the LoadDispatchMetadata method. + /// A helper with all logic to generate the ResourceDescriptorRanges property. /// - private static partial class LoadDispatchMetadata + private static partial class ResourceDescriptorRanges { /// /// Gets the data related to the shader metadata for a given shader type. diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs similarity index 78% rename from src/ComputeSharp.SourceGenerators/IShaderGenerator.cs rename to src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs index f1d5f259..50d63776 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Immutable; using System.Linq; using ComputeSharp.SourceGeneration.Extensions; @@ -12,15 +11,15 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; namespace ComputeSharp.SourceGenerators; /// -/// A source generator creating data loaders for and types. +/// A source generator creating descriptors for and types. /// [Generator(LanguageNames.CSharp)] -public sealed partial class IShaderGenerator : IIncrementalGenerator +public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGenerator { /// /// The name of generator to include in the generated code. /// - private const string GeneratorName = "ComputeSharp.IShaderGenerator"; + private const string GeneratorName = "ComputeSharp.ComputeShaderDescriptorGenerator"; /// public void Initialize(IncrementalGeneratorInitializationContext context) @@ -54,8 +53,8 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator using ImmutableArrayBuilder diagnostics = new(); - // LoadDispatchData() info - ImmutableArray fieldInfos = LoadDispatchData.GetInfo( + // Dispatch data loading info + ImmutableArray fieldInfos = DispatchDataLoading.GetInfo( diagnostics, typeSymbol, isPixelShaderLike, @@ -64,8 +63,8 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator token.ThrowIfCancellationRequested(); - // TryGetBytecode() info - LoadBytecode.GetInfo( + // Thread group size info + NumThreads.GetInfo( diagnostics, typeSymbol, out int threadsX, @@ -75,8 +74,8 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator token.ThrowIfCancellationRequested(); - // BuildHlslSource() info - BuildHlslSource.GetInfo( + // Transpiled HLSL source info + HlslSource.GetInfo( diagnostics, context.SemanticModel.Compilation, typeDeclaration, @@ -90,8 +89,8 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator token.ThrowIfCancellationRequested(); - // GetDispatchMetadata() info - ImmutableArray resourceDescriptors = LoadDispatchMetadata.GetInfo( + // Resource descriptor ranges info + ImmutableArray resourceDescriptors = ResourceDescriptorRanges.GetInfo( isImplicitTextureUsed, isSamplerUsed, fieldInfos); @@ -102,11 +101,11 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator HlslBytecodeInfoKey hlslInfoKey = new(hlslSource, isCompilationEnabled); // Try to get the HLSL bytecode - HlslBytecodeInfo hlslInfo = LoadBytecode.GetBytecode(ref hlslInfoKey, token); + HlslBytecodeInfo hlslInfo = HlslBytecode.GetBytecode(ref hlslInfoKey, token); token.ThrowIfCancellationRequested(); - LoadBytecode.GetInfoDiagnostics(typeSymbol, hlslInfo, diagnostics); + HlslBytecode.GetInfoDiagnostics(typeSymbol, hlslInfo, diagnostics); token.ThrowIfCancellationRequested(); @@ -144,29 +143,29 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator { using ImmutableArrayBuilder> declaredMembers = new(); - declaredMembers.Add(LoadBytecode.WriteThreadsXSyntax); - declaredMembers.Add(LoadBytecode.WriteThreadsYSyntax); - declaredMembers.Add(LoadBytecode.WriteThreadsZSyntax); - declaredMembers.Add(LoadDispatchMetadata.WriteConstantBufferSizeSyntax); - declaredMembers.Add(LoadDispatchMetadata.WriteIsStaticSamplerRequiredSyntax); - declaredMembers.Add(LoadDispatchMetadata.WriteSyntax); - declaredMembers.Add(BuildHlslSource.WriteSyntax); - declaredMembers.Add(LoadBytecode.WriteHlslBytecodeSyntax); - declaredMembers.Add(LoadDispatchData.WriteLoadConstantBufferSyntax); - declaredMembers.Add(LoadDispatchData.WriteLoadGraphicsResourcesSyntax); + declaredMembers.Add(HlslBytecode.WriteThreadsXSyntax); + declaredMembers.Add(HlslBytecode.WriteThreadsYSyntax); + declaredMembers.Add(HlslBytecode.WriteThreadsZSyntax); + declaredMembers.Add(MetadataProperties.WriteConstantBufferSizeSyntax); + declaredMembers.Add(MetadataProperties.WriteIsStaticSamplerRequiredSyntax); + declaredMembers.Add(ResourceDescriptorRanges.WriteSyntax); + declaredMembers.Add(HlslSource.WriteSyntax); + declaredMembers.Add(HlslBytecode.WriteHlslBytecodeSyntax); + declaredMembers.Add(DispatchDataLoading.WriteLoadConstantBufferSyntax); + declaredMembers.Add(DispatchDataLoading.WriteLoadGraphicsResourcesSyntax); using ImmutableArrayBuilder> additionalTypes = new(); using ImmutableHashSetBuilder usingDirectives = new(); - LoadDispatchMetadata.RegisterAdditionalDataMemberSyntax(item, additionalTypes, usingDirectives); - LoadBytecode.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives); + ResourceDescriptorRanges.RegisterAdditionalDataMemberSyntax(item, additionalTypes, usingDirectives); + HlslBytecode.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives); using IndentedTextWriter writer = new(); 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/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj index ae2b90c9..d47c90c9 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj +++ b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj @@ -66,7 +66,7 @@ - + diff --git a/src/ComputeSharp.SourceGenerators/ComputeSharp/Core/Interfaces/__Internals/IShader.cs b/src/ComputeSharp.SourceGenerators/ComputeSharp/Core/Interfaces/__Internals/IShader.cs deleted file mode 100644 index 2a41f8d2..00000000 --- a/src/ComputeSharp.SourceGenerators/ComputeSharp/Core/Interfaces/__Internals/IShader.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.ComponentModel; - -namespace ComputeSharp.__Internals; - -/// -/// A base representing a given shader that can be dispatched. -/// -[EditorBrowsable(EditorBrowsableState.Never)] -[Obsolete("This interface is not intended to be used directly by user code")] -public interface IShader -{ -} \ No newline at end of file diff --git a/src/ComputeSharp.WinUI/ShaderRunner{T}.cs b/src/ComputeSharp.WinUI/ShaderRunner{T}.cs index 7ed4ce51..f8a9d82a 100644 --- a/src/ComputeSharp.WinUI/ShaderRunner{T}.cs +++ b/src/ComputeSharp.WinUI/ShaderRunner{T}.cs @@ -1,4 +1,5 @@ using System; +using ComputeSharp.Descriptors; namespace ComputeSharp.WinUI; @@ -8,7 +9,7 @@ namespace ComputeSharp.WinUI; /// /// The type of shader to use to render frames. public sealed class ShaderRunner : IShaderRunner - where T : struct, IPixelShader + where T : struct, IComputeShader, IComputeShaderDescriptor { /// /// The instance used to create shaders to run. diff --git a/src/ComputeSharp/Core/Attributes/EmbeddedBytecodeAttribute.cs b/src/ComputeSharp/Core/Attributes/EmbeddedBytecodeAttribute.cs index f614e7c9..fb39c5f0 100644 --- a/src/ComputeSharp/Core/Attributes/EmbeddedBytecodeAttribute.cs +++ b/src/ComputeSharp/Core/Attributes/EmbeddedBytecodeAttribute.cs @@ -18,7 +18,7 @@ namespace ComputeSharp; /// /// // A pixel shader that is dispatched on a target texture /// [EmbeddedBytecode(DispatchAxis.XY)] -/// struct MyShader : IPixelShader<float4> +/// struct MyShader : IComputeShader<float4> /// { /// } /// diff --git a/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs b/src/ComputeSharp/Core/Interfaces/Descriptors/IComputeShaderDescriptor{T}.cs similarity index 79% rename from src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs rename to src/ComputeSharp/Core/Interfaces/Descriptors/IComputeShaderDescriptor{T}.cs index 1669dcc5..55a550b6 100644 --- a/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs +++ b/src/ComputeSharp/Core/Interfaces/Descriptors/IComputeShaderDescriptor{T}.cs @@ -1,15 +1,16 @@ using System; -using System.ComponentModel; using ComputeSharp.Interop; -namespace ComputeSharp.__Internals; +namespace ComputeSharp.Descriptors; /// -/// A base representing a given shader that can be dispatched. +/// An interface for a descriptor for a given compute shader. +/// Descriptors contain metadata associated to compute shaders, +/// with all information needed to execute them at runtime. /// -[EditorBrowsable(EditorBrowsableState.Never)] -[Obsolete("This interface is not intended to be used directly by user code")] -public interface IShader +/// The type of compute shader being described. +public interface IComputeShaderDescriptor + where T : struct { /// /// The number of threads in each thread group for the X axis. @@ -63,18 +64,20 @@ public interface IShader /// Loads the constant buffer of a given input shader. /// /// The type of data loader being used. + /// The input shader to load the constant buffer for. /// The instance to use to load the data. /// The number of iterations to run on the X axis. /// The number of iterations to run on the Y axis. /// The number of iterations to run on the Z axis. - void LoadConstantBuffer(ref TLoader loader, int x, int y, int z) + void LoadConstantBuffer(in T shader, ref TLoader loader, int x, int y, int z) where TLoader : struct, IConstantBufferLoader; /// /// Loads the graphics resources for the shader. /// /// The type of graphics resource loader being used. + /// The input shader to load the graphics resources for. /// The instance to use to load the data. - void LoadGraphicsResources(ref TLoader loader) + void LoadGraphicsResources(in T shader, ref TLoader loader) where TLoader : struct, IGraphicsResourceLoader; } \ No newline at end of file diff --git a/src/ComputeSharp/Core/Interfaces/__Internals/IConstantBufferLoader.cs b/src/ComputeSharp/Core/Interfaces/Descriptors/IConstantBufferLoader.cs similarity index 94% rename from src/ComputeSharp/Core/Interfaces/__Internals/IConstantBufferLoader.cs rename to src/ComputeSharp/Core/Interfaces/Descriptors/IConstantBufferLoader.cs index 76c584af..07ffa616 100644 --- a/src/ComputeSharp/Core/Interfaces/__Internals/IConstantBufferLoader.cs +++ b/src/ComputeSharp/Core/Interfaces/Descriptors/IConstantBufferLoader.cs @@ -1,6 +1,6 @@ using System; -namespace ComputeSharp.__Internals; +namespace ComputeSharp.Descriptors; /// /// A type representing a data loader for the constant buffer of a compute shader. diff --git a/src/ComputeSharp/Core/Interfaces/__Internals/IGraphicsResourceLoader.cs b/src/ComputeSharp/Core/Interfaces/Descriptors/IGraphicsResourceLoader.cs similarity index 96% rename from src/ComputeSharp/Core/Interfaces/__Internals/IGraphicsResourceLoader.cs rename to src/ComputeSharp/Core/Interfaces/Descriptors/IGraphicsResourceLoader.cs index d5edd8c8..56cd09cc 100644 --- a/src/ComputeSharp/Core/Interfaces/__Internals/IGraphicsResourceLoader.cs +++ b/src/ComputeSharp/Core/Interfaces/Descriptors/IGraphicsResourceLoader.cs @@ -1,6 +1,6 @@ using System; -namespace ComputeSharp.__Internals; +namespace ComputeSharp.Descriptors; /// /// A type representing a loader object for values used in compute shaders. diff --git a/src/ComputeSharp/Core/Interfaces/IComputeShader.cs b/src/ComputeSharp/Core/Interfaces/IComputeShader.cs index 1b4e7727..430cc54c 100644 --- a/src/ComputeSharp/Core/Interfaces/IComputeShader.cs +++ b/src/ComputeSharp/Core/Interfaces/IComputeShader.cs @@ -1,13 +1,9 @@ -using ComputeSharp.__Internals; - -#pragma warning disable CS0618 - namespace ComputeSharp; /// /// An representing a compute shader. /// -public interface IComputeShader : IShader +public interface IComputeShader { /// /// Executes the current compute shader. diff --git a/src/ComputeSharp/Core/Interfaces/IComputeShader{TPixel}.cs b/src/ComputeSharp/Core/Interfaces/IComputeShader{TPixel}.cs new file mode 100644 index 00000000..614296c3 --- /dev/null +++ b/src/ComputeSharp/Core/Interfaces/IComputeShader{TPixel}.cs @@ -0,0 +1,18 @@ +namespace ComputeSharp; + +/// +/// An representing a compute shader writing into a target texture. +/// +/// The type of pixels being written by the compute shader. +/// +/// This interface allows implementing logic analogous of pixel shaders, but via compute shaders. +/// +public interface IComputeShader + where TPixel : unmanaged +{ + /// + /// Executes the current compute shader. + /// + /// The pixel value for the current invocation. + TPixel Execute(); +} \ No newline at end of file diff --git a/src/ComputeSharp/Core/Interfaces/IPixelShader{TPixel}.cs b/src/ComputeSharp/Core/Interfaces/IPixelShader{TPixel}.cs deleted file mode 100644 index b12cf074..00000000 --- a/src/ComputeSharp/Core/Interfaces/IPixelShader{TPixel}.cs +++ /dev/null @@ -1,18 +0,0 @@ -using ComputeSharp.__Internals; - -#pragma warning disable CS0618 - -namespace ComputeSharp; - -/// -/// An representing a pixel shader. -/// -public interface IPixelShader : IShader - where TPixel : unmanaged -{ - /// - /// Executes the current pixel shader. - /// - /// The pixel value for the current invocation. - TPixel Execute(); -} \ No newline at end of file diff --git a/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Dispatching.cs b/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Dispatching.cs index c492f2c4..74420060 100644 --- a/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Dispatching.cs +++ b/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Dispatching.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.CompilerServices; +using ComputeSharp.Descriptors; using ComputeSharp.Interop; namespace ComputeSharp; @@ -17,7 +18,7 @@ public static partial class GraphicsDeviceExtensions /// The number of iterations to run on the X axis. /// The input instance representing the compute shader to run. public static void For(this GraphicsDevice device, int x, in T shader) - where T : struct, IComputeShader + where T : struct, IComputeShader, IComputeShaderDescriptor { default(ArgumentNullException).ThrowIfNull(device); @@ -35,7 +36,7 @@ public static partial class GraphicsDeviceExtensions /// The number of iterations to run on the Y axis. /// The input instance representing the compute shader to run. public static void For(this GraphicsDevice device, int x, int y, in T shader) - where T : struct, IComputeShader + where T : struct, IComputeShader, IComputeShaderDescriptor { default(ArgumentNullException).ThrowIfNull(device); @@ -54,7 +55,7 @@ public static partial class GraphicsDeviceExtensions /// The number of iterations to run on the Z axis. /// The input instance representing the compute shader to run. public static void For(this GraphicsDevice device, int x, int y, int z, in T shader) - where T : struct, IComputeShader + where T : struct, IComputeShader, IComputeShaderDescriptor { default(ArgumentNullException).ThrowIfNull(device); @@ -71,7 +72,7 @@ public static partial class GraphicsDeviceExtensions /// The to use to run the shader. /// The target texture to apply the pixel shader to. public static void ForEach(this GraphicsDevice device, IReadWriteNormalizedTexture2D texture) - where T : struct, IPixelShader + where T : struct, IComputeShader, IComputeShaderDescriptor where TPixel : unmanaged { default(ArgumentNullException).ThrowIfNull(device); @@ -91,7 +92,7 @@ public static partial class GraphicsDeviceExtensions /// The target texture to apply the pixel shader to. /// The input instance representing the pixel shader to run. public static void ForEach(this GraphicsDevice device, IReadWriteNormalizedTexture2D texture, in T shader) - where T : struct, IPixelShader + where T : struct, IComputeShader, IComputeShaderDescriptor where TPixel : unmanaged { default(ArgumentNullException).ThrowIfNull(device); diff --git a/src/ComputeSharp/Shaders/ComputeContext.cs b/src/ComputeSharp/Shaders/ComputeContext.cs index 0f92e29f..abcc71f8 100644 --- a/src/ComputeSharp/Shaders/ComputeContext.cs +++ b/src/ComputeSharp/Shaders/ComputeContext.cs @@ -2,6 +2,7 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Threading.Tasks; +using ComputeSharp.Descriptors; using ComputeSharp.Graphics.Commands; using ComputeSharp.Graphics.Extensions; using ComputeSharp.Resources.Interop; @@ -9,8 +10,6 @@ using ComputeSharp.Shaders.Dispatching; using ComputeSharp.Shaders.Loading; using TerraFX.Interop.DirectX; -#pragma warning disable CS0618 - namespace ComputeSharp; /// @@ -123,7 +122,7 @@ public struct ComputeContext : IDisposable, IAsyncDisposable /// The number of iterations to run on the X axis. /// The input instance representing the compute shader to run. internal readonly unsafe void Run(int x, ref T shader) - where T : struct, IComputeShader + where T : struct, IComputeShader, IComputeShaderDescriptor { Run(x, 1, 1, ref shader); @@ -136,7 +135,7 @@ public struct ComputeContext : IDisposable, IAsyncDisposable /// The number of iterations to run on the Y axis. /// The input instance representing the compute shader to run. internal readonly unsafe void Run(int x, int y, ref T shader) - where T : struct, IComputeShader + where T : struct, IComputeShader, IComputeShaderDescriptor { Run(x, y, 1, ref shader); @@ -151,7 +150,7 @@ public struct ComputeContext : IDisposable, IAsyncDisposable /// The number of iterations to run on the Z axis. /// The input instance representing the compute shader to run. internal readonly unsafe void Run(int x, int y, int z, ref T shader) - where T : struct, IComputeShader + where T : struct, IComputeShader, IComputeShaderDescriptor { default(InvalidOperationException).ThrowIf(this.device is null); default(ArgumentOutOfRangeException).ThrowIfNegativeOrZero(x); @@ -174,11 +173,11 @@ public struct ComputeContext : IDisposable, IAsyncDisposable D3D12GraphicsCommandListConstantBufferLoader dataLoader = new(commandList.D3D12GraphicsCommandList); - shader.LoadConstantBuffer(ref dataLoader, x, y, z); + shader.LoadConstantBuffer(in shader, ref dataLoader, x, y, z); D3D12GraphicsCommandListGraphicsResourceLoader graphicsResourceLoader = new(commandList.D3D12GraphicsCommandList, this.device, rootParameterOffset: 1); - shader.LoadGraphicsResources(ref graphicsResourceLoader); + shader.LoadGraphicsResources(in shader, ref graphicsResourceLoader); commandList.D3D12GraphicsCommandList->Dispatch((uint)groupsX, (uint)groupsY, (uint)groupsZ); } @@ -191,7 +190,7 @@ public struct ComputeContext : IDisposable, IAsyncDisposable /// The target texture to invoke the pixel shader upon. /// The input instance representing the pixel shader to run. internal readonly unsafe void Run(IReadWriteNormalizedTexture2D texture, ref T shader) - where T : struct, IPixelShader + where T : struct, IComputeShader, IComputeShaderDescriptor where TPixel : unmanaged { default(InvalidOperationException).ThrowIf(this.device is null); @@ -212,11 +211,11 @@ public struct ComputeContext : IDisposable, IAsyncDisposable D3D12GraphicsCommandListConstantBufferLoader constantBufferLoader = new(commandList.D3D12GraphicsCommandList); - shader.LoadConstantBuffer(ref constantBufferLoader, x, y, 1); + shader.LoadConstantBuffer(in shader, ref constantBufferLoader, x, y, 1); D3D12GraphicsCommandListGraphicsResourceLoader graphicsResourceLoader = new(commandList.D3D12GraphicsCommandList, this.device, rootParameterOffset: 2); - shader.LoadGraphicsResources(ref graphicsResourceLoader); + shader.LoadGraphicsResources(in shader, ref graphicsResourceLoader); // Load the implicit output texture commandList.D3D12GraphicsCommandList->SetComputeRootDescriptorTable( diff --git a/src/ComputeSharp/Shaders/Dispatching/D3D12GraphicsCommandListConstantBufferLoader.cs b/src/ComputeSharp/Shaders/Dispatching/D3D12GraphicsCommandListConstantBufferLoader.cs index 5d8056a5..5984feb7 100644 --- a/src/ComputeSharp/Shaders/Dispatching/D3D12GraphicsCommandListConstantBufferLoader.cs +++ b/src/ComputeSharp/Shaders/Dispatching/D3D12GraphicsCommandListConstantBufferLoader.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.CompilerServices; +using ComputeSharp.Descriptors; using ComputeSharp.Graphics.Extensions; -using ComputeSharp.__Internals; using TerraFX.Interop.DirectX; namespace ComputeSharp.Shaders.Dispatching; diff --git a/src/ComputeSharp/Shaders/Dispatching/D3D12GraphicsCommandListGraphicsResourceLoader.cs b/src/ComputeSharp/Shaders/Dispatching/D3D12GraphicsCommandListGraphicsResourceLoader.cs index 4858ee7e..80391e0f 100644 --- a/src/ComputeSharp/Shaders/Dispatching/D3D12GraphicsCommandListGraphicsResourceLoader.cs +++ b/src/ComputeSharp/Shaders/Dispatching/D3D12GraphicsCommandListGraphicsResourceLoader.cs @@ -1,8 +1,8 @@ using System; using System.Runtime.CompilerServices; -using ComputeSharp.__Internals; -using TerraFX.Interop.DirectX; using ComputeSharp.Resources.Interop; +using ComputeSharp.Descriptors; +using TerraFX.Interop.DirectX; namespace ComputeSharp.Shaders.Dispatching; diff --git a/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs b/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs index 163037a3..dcf2ad53 100644 --- a/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs +++ b/src/ComputeSharp/Shaders/Extensions/ComputeContextExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.CompilerServices; +using ComputeSharp.Descriptors; using ComputeSharp.Graphics.Helpers; using ComputeSharp.Interop; using ComputeSharp.Resources.Interop; @@ -484,7 +485,7 @@ public static class ComputeContextExtensions /// The number of iterations to run on the X axis. /// The input instance representing the compute shader to run. public static void For(this in ComputeContext context, int x, in T shader) - where T : struct, IComputeShader + where T : struct, IComputeShader, IComputeShaderDescriptor { context.Run(x, ref Unsafe.AsRef(in shader)); } @@ -498,7 +499,7 @@ public static class ComputeContextExtensions /// The number of iterations to run on the Y axis. /// The input instance representing the compute shader to run. public static void For(this in ComputeContext context, int x, int y, in T shader) - where T : struct, IComputeShader + where T : struct, IComputeShader, IComputeShaderDescriptor { context.Run(x, y, ref Unsafe.AsRef(in shader)); } @@ -513,7 +514,7 @@ public static class ComputeContextExtensions /// The number of iterations to run on the Z axis. /// The input instance representing the compute shader to run. public static void For(this in ComputeContext context, int x, int y, int z, in T shader) - where T : struct, IComputeShader + where T : struct, IComputeShader, IComputeShaderDescriptor { context.Run(x, y, z, ref Unsafe.AsRef(in shader)); } @@ -526,7 +527,7 @@ public static class ComputeContextExtensions /// The to use to run the shader. /// The target texture to apply the pixel shader to. public static void ForEach(this in ComputeContext context, IReadWriteNormalizedTexture2D texture) - where T : struct, IPixelShader + where T : struct, IComputeShader, IComputeShaderDescriptor where TPixel : unmanaged { default(ArgumentNullException).ThrowIfNull(texture); @@ -543,7 +544,7 @@ public static class ComputeContextExtensions /// The target texture to apply the pixel shader to. /// The input instance representing the pixel shader to run. public static void ForEach(this in ComputeContext context, IReadWriteNormalizedTexture2D texture, in T shader) - where T : struct, IPixelShader + where T : struct, IComputeShader, IComputeShaderDescriptor where TPixel : unmanaged { default(ArgumentNullException).ThrowIfNull(texture); diff --git a/src/ComputeSharp/Shaders/Loading/PipelineDataLoader{T}.cs b/src/ComputeSharp/Shaders/Loading/PipelineDataLoader{T}.cs index 3366a4d6..ee9f2acd 100644 --- a/src/ComputeSharp/Shaders/Loading/PipelineDataLoader{T}.cs +++ b/src/ComputeSharp/Shaders/Loading/PipelineDataLoader{T}.cs @@ -2,14 +2,12 @@ using System; using System.Buffers; using System.Runtime.CompilerServices; using ComputeSharp.Shaders.Extensions; +using ComputeSharp.Descriptors; using ComputeSharp.Interop; -using ComputeSharp.__Internals; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; using static TerraFX.Interop.DirectX.D3D12_DESCRIPTOR_RANGE_FLAGS; -#pragma warning disable CS0618 - namespace ComputeSharp.Shaders.Loading; /// @@ -17,7 +15,7 @@ namespace ComputeSharp.Shaders.Loading; /// /// The type of compute shader to load. internal static unsafe class PipelineDataLoader - where T : struct, IShader + where T : struct, IComputeShaderDescriptor { /// /// The map of cached instances for each GPU in use. diff --git a/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs b/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs index af76a1ac..c1fcf6a7 100644 --- a/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs +++ b/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs @@ -177,7 +177,7 @@ public partial class DeviceDisposalTests } [EmbeddedBytecode(DispatchAxis.XY)] - private partial struct HelloWorldShader : IPixelShader + private partial struct HelloWorldShader : IComputeShader { public float4 Execute() { diff --git a/tests/ComputeSharp.Tests.DisableDynamicCompilation/DispatchTests.cs b/tests/ComputeSharp.Tests.DisableDynamicCompilation/DispatchTests.cs index 775d0256..b0d1ec55 100644 --- a/tests/ComputeSharp.Tests.DisableDynamicCompilation/DispatchTests.cs +++ b/tests/ComputeSharp.Tests.DisableDynamicCompilation/DispatchTests.cs @@ -76,7 +76,7 @@ public partial class DispatchTests [AutoConstructor] [EmbeddedBytecode(8, 8, 1)] - internal readonly partial struct PixelShader : IPixelShader + internal readonly partial struct PixelShader : IComputeShader { private readonly float b; private readonly float a; 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.SourceGenerators/DiagnosticsTests.cs b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs index 9352326b..4d701d54 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs @@ -36,7 +36,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0001", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0001", "CMPS0047"); } [TestMethod] @@ -62,7 +62,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0001", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0001", "CMPS0047"); } [TestMethod] @@ -91,7 +91,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0002", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0002", "CMPS0047"); } [TestMethod] @@ -120,7 +120,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0003", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0003", "CMPS0047"); } [TestMethod] @@ -147,7 +147,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0004", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0004", "CMPS0047"); } [TestMethod] @@ -165,7 +165,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0005", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0005", "CMPS0047"); } [TestMethod] @@ -201,7 +201,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, diagnosticsId, "CMPS0047"); + VerifyGeneratedDiagnostics(source, diagnosticsId, "CMPS0047"); } [TestMethod] @@ -234,7 +234,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, diagnosticsId, "CMPS0047"); + VerifyGeneratedDiagnostics(source, diagnosticsId, "CMPS0047"); } [TestMethod] @@ -265,7 +265,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0006", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0006", "CMPS0047"); } [TestMethod] @@ -293,7 +293,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0010", "CMPS0031", "CMPS0047", "CMPS0050"); + VerifyGeneratedDiagnostics(source, "CMPS0010", "CMPS0031", "CMPS0047", "CMPS0050"); } [TestMethod] @@ -321,7 +321,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0010", "CMPS0031", "CMPS0047", "CMPS0050"); + VerifyGeneratedDiagnostics(source, "CMPS0010", "CMPS0031", "CMPS0047", "CMPS0050"); } [TestMethod] @@ -349,7 +349,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0011", "CMPS0031", "CMPS0047", "CMPS0050"); + VerifyGeneratedDiagnostics(source, "CMPS0011", "CMPS0031", "CMPS0047", "CMPS0050"); } [TestMethod] @@ -379,7 +379,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0012", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0012", "CMPS0047"); } [TestMethod] @@ -406,7 +406,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0012", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0012", "CMPS0047"); } [TestMethod] @@ -434,7 +434,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0012", "CMPS0013", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0012", "CMPS0013", "CMPS0047"); } [TestMethod] @@ -464,7 +464,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0014", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0014", "CMPS0047"); } [TestMethod] @@ -497,7 +497,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0015", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0015", "CMPS0047"); } [TestMethod] @@ -530,7 +530,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0016", "CMPS0032", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0016", "CMPS0032", "CMPS0047"); } [TestMethod] @@ -563,7 +563,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0017", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0017", "CMPS0047"); } [TestMethod] @@ -593,7 +593,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0018", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0018", "CMPS0047"); } [TestMethod] @@ -624,7 +624,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0019", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0019", "CMPS0047"); } [TestMethod] @@ -655,7 +655,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0020", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0020", "CMPS0047"); } [TestMethod] @@ -688,7 +688,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0021", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0021", "CMPS0047"); } [TestMethod] @@ -719,7 +719,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0022", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0022", "CMPS0047"); } [TestMethod] @@ -752,7 +752,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0023", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0023", "CMPS0047"); } [TestMethod] @@ -780,7 +780,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0024", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0024", "CMPS0047"); } [TestMethod] @@ -808,7 +808,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0032", "CMPS0025", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0032", "CMPS0025", "CMPS0047"); } [TestMethod] @@ -836,7 +836,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0026", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0026", "CMPS0047"); } [TestMethod] @@ -869,7 +869,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0027", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0027", "CMPS0047"); } [TestMethod] @@ -897,7 +897,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0028", "CMPS0047", "CMPS0050"); + VerifyGeneratedDiagnostics(source, "CMPS0028", "CMPS0047", "CMPS0050"); } [TestMethod] @@ -925,7 +925,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0029", "CMPS0031", "CMPS0047", "CMPS0050"); + VerifyGeneratedDiagnostics(source, "CMPS0029", "CMPS0031", "CMPS0047", "CMPS0050"); } [TestMethod] @@ -955,7 +955,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0029", "CMPS0031", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0029", "CMPS0031", "CMPS0047"); } [TestMethod] @@ -989,7 +989,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0030", "CMPS0047", "CMPS0050"); + VerifyGeneratedDiagnostics(source, "CMPS0030", "CMPS0047", "CMPS0050"); } [TestMethod] @@ -1017,7 +1017,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0031", "CMPS0047", "CMPS0050"); + VerifyGeneratedDiagnostics(source, "CMPS0031", "CMPS0047", "CMPS0050"); } [TestMethod] @@ -1045,7 +1045,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0032", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0032", "CMPS0047"); } [TestMethod] @@ -1073,7 +1073,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0033", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0033", "CMPS0047"); } [TestMethod] @@ -1103,7 +1103,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0034", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0034", "CMPS0047"); } [TestMethod] @@ -1133,7 +1133,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0035", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0035", "CMPS0047"); } [TestMethod] @@ -1163,7 +1163,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0035", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0035", "CMPS0047"); } [TestMethod] @@ -1191,7 +1191,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0036", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0036", "CMPS0047"); } [TestMethod] @@ -1235,7 +1235,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0037", "CMPS0047", "CMPS0050"); + VerifyGeneratedDiagnostics(source, "CMPS0037", "CMPS0047", "CMPS0050"); } [TestMethod] @@ -1264,7 +1264,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0038", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0038", "CMPS0047"); } [TestMethod] @@ -1293,7 +1293,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0040", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0040", "CMPS0047"); } [TestMethod] @@ -1327,7 +1327,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0040", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0040", "CMPS0047"); } [TestMethod] @@ -1359,7 +1359,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0040", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0040", "CMPS0047"); } [TestMethod] @@ -1388,7 +1388,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0040", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0040", "CMPS0047"); } [TestMethod] @@ -1417,7 +1417,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0040", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0040", "CMPS0047"); } [TestMethod] @@ -1452,7 +1452,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0041", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0041", "CMPS0047"); } [TestMethod] @@ -1464,12 +1464,12 @@ public class DiagnosticsTests namespace ComputeSharp { public interface IComputeShader { } - public interface IPixelShader { } + public interface IComputeShader { } } namespace MyFancyApp.Sample { - public struct MyShader : IComputeShader, IPixelShader + public struct MyShader : IComputeShader, IComputeShader { public void Execute() { @@ -1478,7 +1478,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0042", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0042", "CMPS0047"); } [TestMethod] @@ -1518,7 +1518,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0044"); + VerifyGeneratedDiagnostics(source, "CMPS0044"); } [TestMethod] @@ -1553,7 +1553,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0048"); + VerifyGeneratedDiagnostics(source, "CMPS0048"); } [TestMethod] @@ -1588,7 +1588,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0048"); + VerifyGeneratedDiagnostics(source, "CMPS0048"); } [TestMethod] @@ -1623,7 +1623,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0048"); + VerifyGeneratedDiagnostics(source, "CMPS0048"); } [TestMethod] @@ -1652,7 +1652,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0049", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0049", "CMPS0047"); } [TestMethod] @@ -1681,7 +1681,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0047", "CMPS0050"); + VerifyGeneratedDiagnostics(source, "CMPS0047", "CMPS0050"); } [TestMethod] @@ -1716,7 +1716,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0047", "CMPS0050"); + VerifyGeneratedDiagnostics(source, "CMPS0047", "CMPS0050"); } [TestMethod] @@ -1749,7 +1749,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0047", "CMPS0050"); + VerifyGeneratedDiagnostics(source, "CMPS0047", "CMPS0050"); } /// diff --git a/tests/ComputeSharp.Tests/ComputeContextTests.cs b/tests/ComputeSharp.Tests/ComputeContextTests.cs index 07f12e49..adff51ed 100644 --- a/tests/ComputeSharp.Tests/ComputeContextTests.cs +++ b/tests/ComputeSharp.Tests/ComputeContextTests.cs @@ -1309,7 +1309,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] - internal readonly partial struct ClearPixelShader : IPixelShader + internal readonly partial struct ClearPixelShader : IComputeShader { /// public float4 Execute() @@ -1320,7 +1320,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] - internal readonly partial struct ColorPixelShader : IPixelShader + internal readonly partial struct ColorPixelShader : IComputeShader { public readonly float4 color; @@ -1333,7 +1333,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] - internal readonly partial struct LinearSampling2DPixelShader : IPixelShader + internal readonly partial struct LinearSampling2DPixelShader : IComputeShader { public readonly IReadOnlyTexture2D source; @@ -1365,7 +1365,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] - internal readonly partial struct LinearSamplingFromNormalized2DPixelShader : IPixelShader + internal readonly partial struct LinearSamplingFromNormalized2DPixelShader : IComputeShader { public readonly IReadOnlyNormalizedTexture2D source; @@ -1378,7 +1378,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] - internal readonly partial struct CopyToOutputPixelShader : IPixelShader + internal readonly partial struct CopyToOutputPixelShader : IComputeShader { public readonly IReadOnlyNormalizedTexture2D source; @@ -1391,7 +1391,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] - internal readonly partial struct InvertPixelShader : IPixelShader + internal readonly partial struct InvertPixelShader : IComputeShader { public readonly IReadWriteNormalizedTexture2D source; diff --git a/tests/ComputeSharp.Tests/DispatchTests.cs b/tests/ComputeSharp.Tests/DispatchTests.cs index 1bd1c4e0..8c0f47f4 100644 --- a/tests/ComputeSharp.Tests/DispatchTests.cs +++ b/tests/ComputeSharp.Tests/DispatchTests.cs @@ -291,7 +291,7 @@ public partial class DispatchTests } [EmbeddedBytecode(DispatchAxis.XY)] - internal readonly partial struct DispatchPixelShader : IPixelShader + internal readonly partial struct DispatchPixelShader : IComputeShader { public float4 Execute() { diff --git a/tests/ComputeSharp.Tests/IPixelShaderTests.cs b/tests/ComputeSharp.Tests/IPixelShaderTests.cs index f81606a4..7fad3712 100644 --- a/tests/ComputeSharp.Tests/IPixelShaderTests.cs +++ b/tests/ComputeSharp.Tests/IPixelShaderTests.cs @@ -36,7 +36,7 @@ public partial class IPixelShaderTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] - internal readonly partial struct EarlyReturnShader : IPixelShader + internal readonly partial struct EarlyReturnShader : IComputeShader { public float4 Execute() { diff --git a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs index 34ee62e0..b44ddc23 100644 --- a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs +++ b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs @@ -294,7 +294,7 @@ namespace ComputeSharp.Tests } [EmbeddedBytecode(DispatchAxis.XY)] - public readonly partial struct StatelessPixelShader : IPixelShader + public readonly partial struct StatelessPixelShader : IComputeShader { /// public float4 Execute() @@ -406,7 +406,7 @@ namespace ComputeSharp.Tests _ = ReflectionServices.GetShaderInfo(); } - public interface IMyBaseShader : IPixelShader + public interface IMyBaseShader : IComputeShader where T : unmanaged { public int A { get; } diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/HelloWorld.cs b/tests/ComputeSharp.Tests/Shaders/Compute/HelloWorld.cs index 5b0a6bad..43c0573f 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/HelloWorld.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/HelloWorld.cs @@ -8,7 +8,7 @@ namespace ComputeSharp.SwapChain.Shaders.Compute; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] -internal readonly partial struct HelloWorld : IPixelShader +internal readonly partial struct HelloWorld : IComputeShader { /// /// The current time since the start of the application. diff --git a/tests/ComputeSharp.Tests/ShadersTests.cs b/tests/ComputeSharp.Tests/ShadersTests.cs index e765128a..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, IPixelShader + 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, IPixelShader + where TCompute : struct, IComputeShader, IComputeShaderDescriptor + where TPixel : struct, IComputeShader, IComputeShaderDescriptor { _ = device.Get(); diff --git a/tests/ComputeSharp.Tests/Texture2DTests.Pixels.cs b/tests/ComputeSharp.Tests/Texture2DTests.Pixels.cs index f204cb24..dbc26b43 100644 --- a/tests/ComputeSharp.Tests/Texture2DTests.Pixels.cs +++ b/tests/ComputeSharp.Tests/Texture2DTests.Pixels.cs @@ -107,7 +107,7 @@ partial class Texture2DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] - public readonly partial struct SamplingPixelShader : IPixelShader + public readonly partial struct SamplingPixelShader : IComputeShader { public readonly IReadOnlyNormalizedTexture2D texture; 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]