diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 415368bb..1d2b6b8f 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -44,30 +44,10 @@ jobs: run: msbuild -t:restore,build /p:Configuration=Release /p:Platform=x64 shell: cmd - # Build the whole ComputeSharp solution with /p:DisableShaderCompilationSupport=True - build-solution-release-no-dynamic: - runs-on: windows-2022 - steps: - - name: Git checkout - uses: actions/checkout@v2 - - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1.0.3 - - name: Setup .NET Core 3.1 SDK - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 3.1.x - - name: Setup .NET 6 SDK - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 6.0.x - - name: Build - run: msbuild -t:restore,build /p:Configuration=Release /p:Platform=x64 /p:DisableShaderCompilationSupport=True - shell: cmd - # Run all the unit tests referencing the ComputeSharp project directly run-tests: if: success() - needs: [build-solution-debug, build-solution-release, build-solution-release-no-dynamic] + needs: [build-solution-debug, build-solution-release] runs-on: windows-2022 steps: - name: Git checkout @@ -84,7 +64,7 @@ jobs: run: dotnet test tests\ComputeSharp.Tests\ComputeSharp.Tests.csproj -c Release -f net6.0 -v n -l "console;verbosity=detailed" shell: cmd - name: Run ComputeSharp.Tests.DisableDynamicCompilation (.NET 6) - run: dotnet test tests\ComputeSharp.Tests.DisableDynamicCompilation\ComputeSharp.Tests.DisableDynamicCompilation.csproj -c Release -f net6.0 /p:DisableShaderCompilationSupport=True -v n -l "console;verbosity=detailed" + run: dotnet test tests\ComputeSharp.Tests.DisableDynamicCompilation\ComputeSharp.Tests.DisableDynamicCompilation.csproj -c Release -f net6.0 -v n -l "console;verbosity=detailed" shell: cmd - name: Run ComputeSharp.Tests.Internals (.NET 6) run: dotnet test tests\ComputeSharp.Tests.Internals\ComputeSharp.Tests.Internals.csproj -c Release -f net6.0 -v n -l "console;verbosity=detailed" @@ -93,7 +73,7 @@ jobs: run: dotnet test tests\ComputeSharp.Tests\ComputeSharp.Tests.csproj -c Release -f netcoreapp3.1 /p:Platform=x64 -v n -l "console;verbosity=detailed" shell: cmd - name: Run ComputeSharp.Tests.DisableDynamicCompilation (.NET Core 3.1) - run: dotnet test tests\ComputeSharp.Tests.DisableDynamicCompilation\ComputeSharp.Tests.DisableDynamicCompilation.csproj -c Release -f netcoreapp3.1 /p:Platform=x64 /p:DisableShaderCompilationSupport=True -v n -l "console;verbosity=detailed" + run: dotnet test tests\ComputeSharp.Tests.DisableDynamicCompilation\ComputeSharp.Tests.DisableDynamicCompilation.csproj -c Release -f netcoreapp3.1 /p:Platform=x64 -v n -l "console;verbosity=detailed" shell: cmd - name: Run ComputeSharp.Tests.Internals (.NET Core 3.1) run: dotnet test tests\ComputeSharp.Tests.Internals\ComputeSharp.Tests.Internals.csproj -c Release -f netcoreapp3.1 /p:Platform=x64 -v n -l "console;verbosity=detailed" @@ -102,7 +82,7 @@ jobs: run: dotnet test tests\ComputeSharp.Tests\ComputeSharp.Tests.csproj -c Release -f net472 /p:Platform=x64 -v n -l "console;verbosity=detailed" shell: cmd - name: Run ComputeSharp.Tests.DisableDynamicCompilation (.NET Framework 4.7.2) - run: dotnet test tests\ComputeSharp.Tests.DisableDynamicCompilation\ComputeSharp.Tests.DisableDynamicCompilation.csproj -c Release -f net472 /p:Platform=x64 /p:DisableShaderCompilationSupport=True -v n -l "console;verbosity=detailed" + run: dotnet test tests\ComputeSharp.Tests.DisableDynamicCompilation\ComputeSharp.Tests.DisableDynamicCompilation.csproj -c Release -f net472 /p:Platform=x64 -v n -l "console;verbosity=detailed" shell: cmd - name: Run ComputeSharp.Tests.Internals (.NET Framework 4.7.2) run: dotnet test tests\ComputeSharp.Tests.Internals\ComputeSharp.Tests.Internals.csproj -c Release -f net472 /p:Platform=x64 -v n -l "console;verbosity=detailed" @@ -180,7 +160,7 @@ jobs: # This workflow also uploads the resulting package as an artifact. build-package: if: success() - needs: [build-solution-debug, build-solution-release, build-solution-release-no-dynamic] + needs: [build-solution-debug, build-solution-release] runs-on: windows-2022 steps: - name: Git checkout @@ -189,14 +169,22 @@ jobs: uses: actions/setup-dotnet@v1 with: dotnet-version: 6.0.x - - name: Build + - name: Build ComputeSharp package run: dotnet build src\ComputeSharp.Package\ComputeSharp.Package.msbuildproj -c Release /p:ContinuousIntegrationBuild=True shell: cmd - - name: Upload package artifact + - name: Upload ComputeSharp package artifact uses: actions/upload-artifact@v2 with: name: ComputeSharp.nupkg path: src\ComputeSharp.Package\bin\Release\*.nupkg + - name: Build ComputeSharp.Dynamic package + run: dotnet build src\ComputeSharp.Dynamic.Package\ComputeSharp.Dynamic.Package.msbuildproj -c Release /p:ContinuousIntegrationBuild=True + shell: cmd + - name: Upload ComputeSharp.Dynamic package artifact + uses: actions/upload-artifact@v2 + with: + name: ComputeSharp.Dynamic.nupkg + path: src\ComputeSharp.Dynamic.Package\bin\Release\*.nupkg # Download the NuGet package generated in the previous job and use it # to build and run the sample project referencing it. This is used as @@ -215,11 +203,16 @@ jobs: - name: Create local NuGet feed run: mkdir src\ComputeSharp.Package\bin\Release shell: cmd - - name: Download package artifact + - name: Download ComputeSharp package artifact uses: actions/download-artifact@v2 with: name: ComputeSharp.nupkg path: src\ComputeSharp.Package\bin\Release\ComputeSharp.nupkg + - name: Download ComputeSharp.Dynamic package artifact + uses: actions/download-artifact@v2 + with: + name: ComputeSharp.Dynamic.nupkg + path: src\ComputeSharp.Dynamic.Package\bin\Release\ComputeSharp.Dynamic.nupkg - name: Build ComputeSharp.Sample.NuGet (.NET 6) run: dotnet build samples\ComputeSharp.Sample.NuGet\ComputeSharp.Sample.NuGet.csproj -c Release -f net6.0 shell: cmd diff --git a/ComputeSharp.NET.slnf b/ComputeSharp.NET.slnf index 9c25163a..a24c2c0f 100644 --- a/ComputeSharp.NET.slnf +++ b/ComputeSharp.NET.slnf @@ -12,6 +12,7 @@ "samples\\ComputeSharp.SwapChain.Shaders.Shared\\ComputeSharp.SwapChain.Shaders.Shared.csproj", "src\\ComputeSharp.SourceGenerators\\ComputeSharp.SourceGenerators.csproj", "src\\ComputeSharp\\ComputeSharp.csproj", + "src\\ComputeSharp.Dynamic\\ComputeSharp.Dynamic.csproj", "tests\\ComputeSharp.Tests.Internals\\ComputeSharp.Tests.Internals.csproj", "tests\\ComputeSharp.Tests.NativeLibrariesResolver\\ComputeSharp.Tests.NativeLibrariesResolver.csproj", "tests\\ComputeSharp.Tests.SourceGenerators\\ComputeSharp.Tests.SourceGenerators.csproj", diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 1c78842e..fe3ef9c6 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -30,6 +30,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.SourceGenerato EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{FB17EF84-9208-47AC-921F-680CB1DAD8BA}" ProjectSection(SolutionItems) = preProject + src\ComputeSharp.Dynamic.Package\ComputeSharp.Dynamic.Package.msbuildproj = src\ComputeSharp.Dynamic.Package\ComputeSharp.Dynamic.Package.msbuildproj src\ComputeSharp.Package\ComputeSharp.Package.msbuildproj = src\ComputeSharp.Package\ComputeSharp.Package.msbuildproj src\ComputeSharp.Package\icon.png = src\ComputeSharp.Package\icon.png EndProjectSection @@ -70,23 +71,30 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ComputeSharp.SwapChain.Core EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Tests.DisableDynamicCompilation", "tests\ComputeSharp.Tests.DisableDynamicCompilation\ComputeSharp.Tests.DisableDynamicCompilation.csproj", "{4A8FCE22-851C-442A-8BC9-3EC3FD00B637}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Dynamic", "src\ComputeSharp.Dynamic\ComputeSharp.Dynamic.csproj", "{76C66257-FDAA-47AB-85E7-EF757EAB10C0}" +EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "TerraFX.Interop.Windows.Dynamic", "src\TerraFX.Interop.Windows.Dynamic\TerraFX.Interop.Windows.Dynamic.shproj", "{158F984D-CD96-4062-BD02-2268946031A0}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution samples\ComputeSharp.SwapChain.Core.Shared\ComputeSharp.SwapChain.Core.Shared.projitems*{0071701e-b9c5-4098-be5f-ef556c4553c6}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{0071701e-b9c5-4098-be5f-ef556c4553c6}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{0800bd51-499d-44c2-9417-fd1f7fdfe9c4}*SharedItemsImports = 13 src\ComputeSharp.UI\ComputeSharp.UI.projitems*{0c82ede1-5b8a-4df3-87da-700b29d5e265}*SharedItemsImports = 13 + src\TerraFX.Interop.Windows.Dynamic\TerraFX.Interop.Windows.Dynamic.projitems*{158f984d-cd96-4062-bd02-2268946031a0}*SharedItemsImports = 13 src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{314eb353-e7e3-4146-8111-685cc83ec1de}*SharedItemsImports = 5 src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{314eb353-e7e3-4146-8111-685cc83ec1de}*SharedItemsImports = 5 src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{514ff00e-bbf0-4d55-a47c-eeeb6208adce}*SharedItemsImports = 13 samples\ComputeSharp.Sample.Shared\ComputeSharp.Sample.Shared.projitems*{7048deea-0a6f-46a0-b951-b682a8f1cb75}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Core.Shared\ComputeSharp.SwapChain.Core.Shared.projitems*{751bb05b-563d-4b3a-94c6-15e2d79d35ea}*SharedItemsImports = 13 + src\TerraFX.Interop.Windows.Dynamic\TerraFX.Interop.Windows.Dynamic.projitems*{76c66257-fdaa-47ab-85e7-ef757eab10c0}*SharedItemsImports = 5 samples\ComputeSharp.Sample.Shared\ComputeSharp.Sample.Shared.projitems*{8cefc324-ca6c-4845-9ad9-70b92bd87057}*SharedItemsImports = 13 src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{a5997814-d8d2-4541-87ac-c3e53caa67c0}*SharedItemsImports = 13 src\ComputeSharp.UI\ComputeSharp.UI.projitems*{afaafdc9-be42-45d4-8c79-0ee8c8edbf52}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{e7c9247d-016b-4819-af9f-0e9b3591e04b}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{e91f4d24-922a-4921-a8d7-9c45a143c45d}*SharedItemsImports = 5 src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{eb52cb67-4162-4722-874b-44ea8da5450e}*SharedItemsImports = 5 + src\TerraFX.Interop.Windows.Dynamic\TerraFX.Interop.Windows.Dynamic.projitems*{eb52cb67-4162-4722-874b-44ea8da5450e}*SharedItemsImports = 5 src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{eb52cb67-4162-4722-874b-44ea8da5450e}*SharedItemsImports = 5 src\ComputeSharp.UI\ComputeSharp.UI.projitems*{fa18ba9f-76bf-4de0-8d24-02fc7657e6cb}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Core.Shared\ComputeSharp.SwapChain.Core.Shared.projitems*{fbd388a5-7855-4408-98ff-e689f509db5a}*SharedItemsImports = 4 @@ -101,18 +109,18 @@ Global Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {314EB353-E7E3-4146-8111-685CC83EC1DE}.Debug|Any CPU.ActiveCfg = Debug|x64 - {314EB353-E7E3-4146-8111-685CC83EC1DE}.Debug|Any CPU.Build.0 = Debug|x64 - {314EB353-E7E3-4146-8111-685CC83EC1DE}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {314EB353-E7E3-4146-8111-685CC83EC1DE}.Debug|ARM64.Build.0 = Debug|ARM64 - {314EB353-E7E3-4146-8111-685CC83EC1DE}.Debug|x64.ActiveCfg = Debug|x64 - {314EB353-E7E3-4146-8111-685CC83EC1DE}.Debug|x64.Build.0 = Debug|x64 - {314EB353-E7E3-4146-8111-685CC83EC1DE}.Release|Any CPU.ActiveCfg = Release|x64 - {314EB353-E7E3-4146-8111-685CC83EC1DE}.Release|Any CPU.Build.0 = Release|x64 - {314EB353-E7E3-4146-8111-685CC83EC1DE}.Release|ARM64.ActiveCfg = Release|ARM64 - {314EB353-E7E3-4146-8111-685CC83EC1DE}.Release|ARM64.Build.0 = Release|ARM64 - {314EB353-E7E3-4146-8111-685CC83EC1DE}.Release|x64.ActiveCfg = Release|x64 - {314EB353-E7E3-4146-8111-685CC83EC1DE}.Release|x64.Build.0 = Release|x64 + {314EB353-E7E3-4146-8111-685CC83EC1DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {314EB353-E7E3-4146-8111-685CC83EC1DE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {314EB353-E7E3-4146-8111-685CC83EC1DE}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {314EB353-E7E3-4146-8111-685CC83EC1DE}.Debug|ARM64.Build.0 = Debug|Any CPU + {314EB353-E7E3-4146-8111-685CC83EC1DE}.Debug|x64.ActiveCfg = Debug|Any CPU + {314EB353-E7E3-4146-8111-685CC83EC1DE}.Debug|x64.Build.0 = Debug|Any CPU + {314EB353-E7E3-4146-8111-685CC83EC1DE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {314EB353-E7E3-4146-8111-685CC83EC1DE}.Release|Any CPU.Build.0 = Release|Any CPU + {314EB353-E7E3-4146-8111-685CC83EC1DE}.Release|ARM64.ActiveCfg = Release|Any CPU + {314EB353-E7E3-4146-8111-685CC83EC1DE}.Release|ARM64.Build.0 = Release|Any CPU + {314EB353-E7E3-4146-8111-685CC83EC1DE}.Release|x64.ActiveCfg = Release|Any CPU + {314EB353-E7E3-4146-8111-685CC83EC1DE}.Release|x64.Build.0 = Release|Any CPU {34AFE6E6-9A4C-4C3F-AE69-DD3693086DAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {34AFE6E6-9A4C-4C3F-AE69-DD3693086DAF}.Debug|Any CPU.Build.0 = Debug|Any CPU {34AFE6E6-9A4C-4C3F-AE69-DD3693086DAF}.Debug|ARM64.ActiveCfg = Debug|Any CPU @@ -317,6 +325,18 @@ Global {4A8FCE22-851C-442A-8BC9-3EC3FD00B637}.Release|ARM64.Build.0 = Release|Any CPU {4A8FCE22-851C-442A-8BC9-3EC3FD00B637}.Release|x64.ActiveCfg = Release|Any CPU {4A8FCE22-851C-442A-8BC9-3EC3FD00B637}.Release|x64.Build.0 = Release|Any CPU + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Debug|Any CPU.ActiveCfg = Debug|x64 + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Debug|Any CPU.Build.0 = Debug|x64 + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Debug|ARM64.Build.0 = Debug|ARM64 + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Debug|x64.ActiveCfg = Debug|x64 + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Debug|x64.Build.0 = Debug|x64 + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Release|Any CPU.ActiveCfg = Release|x64 + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Release|Any CPU.Build.0 = Release|x64 + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Release|ARM64.ActiveCfg = Release|ARM64 + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Release|ARM64.Build.0 = Release|ARM64 + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Release|x64.ActiveCfg = Release|x64 + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -340,6 +360,7 @@ Global {0800BD51-499D-44C2-9417-FD1F7FDFE9C4} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1} {751BB05B-563D-4B3A-94C6-15E2D79D35EA} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1} {4A8FCE22-851C-442A-8BC9-3EC3FD00B637} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7} + {158F984D-CD96-4062-BD02-2268946031A0} = {8DCE343F-BA78-4FE1-B562-B57C603A8BAA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4664C5E3-0340-4E22-BCFD-98AAEDF5F2DC} diff --git a/README.md b/README.md index fe2779a2..e897adae 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ![](https://user-images.githubusercontent.com/10199417/108635546-3512ea00-7480-11eb-8172-99bc59f4eb6f.png) -[![.NET](https://github.com/Sergio0694/ComputeSharp/workflows/.NET/badge.svg)](https://github.com/Sergio0694/ComputeSharp/actions) [![NuGet](https://img.shields.io/nuget/vpre/ComputeSharp.svg)](https://www.nuget.org/packages/ComputeSharp/) [![NuGet](https://img.shields.io/nuget/dt/ComputeSharp.svg)](https://www.nuget.org/stats/packages/ComputeSharp?groupby=Version) +[![.NET](https://github.com/Sergio0694/ComputeSharp/workflows/.NET/badge.svg)](https://github.com/Sergio0694/ComputeSharp/actions) [![NuGet](https://img.shields.io/nuget/dt/ComputeSharp.svg)](https://www.nuget.org/stats/packages/ComputeSharp?groupby=Version) # What is it? @@ -13,6 +13,7 @@ https://user-images.githubusercontent.com/10199417/126792509-c11feb11-a609-4fab- # Table of Contents +- [Available packages](#available-packages) - [Installing from NuGet](#installing-from-nuget) - [Quick start](#quick-start) - [Capturing variables](#capturing-variables) @@ -25,11 +26,21 @@ https://user-images.githubusercontent.com/10199417/126792509-c11feb11-a609-4fab- - [Shader metaprogramming](#shader-metaprogramming) - [Inspecting shaders](#inspecting-shaders) - [DirectX interop](#directx-interop) + - [Precompiled shaders](#precompiled-shaders) - [Requirements](#requirements) - [F# support](#f-support) - [Sponsors](#sponsors) - [Special thanks](#special-thanks) +# Available packages + +| Name | Description | Latest version | +| ------ | ------ | ------ | +| **ComputeSharp** | The core library, with compiled shaders support | [![NuGet](https://img.shields.io/nuget/vpre/ComputeSharp.svg)](https://www.nuget.org/packages/ComputeSharp/) | +| **ComputeSharp.Dynamic** | An extension for **ComputeSharp**, enabling dynamic shader compilation at runtime and shader metaprogramming | [![NuGet](https://img.shields.io/nuget/vpre/ComputeSharp.Dynamic.svg)](https://www.nuget.org/packages/ComputeSharp.Dynamic/) | +| **ComputeSharp.Uwp** | A UWP library (targeting .NET Standard 2.0) with controls to render DX12 shaders powered by **ComputeSharp** | [![NuGet](https://img.shields.io/nuget/vpre/ComputeSharp.Uwp.svg)](https://www.nuget.org/packages/ComputeSharp.Uwp/) | +| **ComputeSharp.WinUI** | A WinUI 3 library (targeting .NET 6) with controls to render DX12 shaders powered by **ComputeSharp** | [![NuGet](https://img.shields.io/nuget/vpre/ComputeSharp.WinUI.svg)](https://www.nuget.org/packages/ComputeSharp.WinUI/) | + # Installing from NuGet To install **ComputeSharp**, run the following command in the **Package Manager Console** @@ -38,6 +49,8 @@ To install **ComputeSharp**, run the following command in the **Package Manager Install-Package ComputeSharp ``` +Alternatively, use the NuGet package manager wizard in Visual Studio or your IDE of choice. + More details available [here](https://www.nuget.org/packages/ComputeSharp/). # Quick start @@ -85,6 +98,8 @@ GraphicsDevice.Default.For(buffer.Length, new MultiplyByTwo(buffer)); buffer.CopyTo(array); ``` +> **NOTE:** all these samples assume that **ComputeSharp.Dynamic** is also installed. For info on how to only use precompiled shaders with the base **ComputeSharp** package, see the [precompiled shaders](#precompiled-shaders) paragraph. + ## Capturing variables Shaders can store either GPU resources or custom values in their fields, so that they can be accessed when running on the GPU as well. This can be useful to pass some extra parameters to a shader (eg. some factor to multiply values by), that don't belong to a GPU buffer of their own. The captured variables need to be of a supported scalar or vector type so that they can be correctly used by the GPU shader in HLSL. Here is a list of the variable types currently supported: @@ -336,6 +351,27 @@ InteropServices.GetID3D12Resource(buffer, __uuidof(), (void**)d3 The `InteropServices` class is also used by the swap chain sample to access the underlying COM objects and use them the rendered frames in a Win32 window. The full source code is available [here](https://github.com/Sergio0694/ComputeSharp/blob/main/samples/ComputeSharp.SwapChain/Backend/SwapChainApplication%7BT%7D.cs), and it provides reference implementation of how these APIs can be used to interop with other DirectX objects. +## Precompiled shaders + +When only using the main **ComputeSharp** project, dynamic shader compilation is not available. This makes the library have a much smaller impact on binary size, as it will not bundle the native DirectX compiler dependencies (which add about 20MB per CPU architecture). Additionally, precompiling shaders makes the code less error prone and the startup time much faster. In order to precompile a shader, it must not have dynamic features (ie. it cannot capture delegates, see the [shader metaprogramming](#shader-metaprogramming) paragraph) and it must be annotated with the `[EmbeddedBytecode]` attribute: + +```csharp +[AutoConstructor] +[EmbeddedBytecode(8, 8, 1)] +public readonly partial struct MultiplyByTwo : IPixelShader +{ + public float4 Execute() + { + float2 uv = ThreadIds.Normalized.XY; + float3 col = 0.5f + 0.5f * Hlsl.Cos(new float3(uv, uv.X) + new float3(0, 2, 4)); + + return new(col, 1f); + } +} +``` + +The values in the `[EmbeddedBytecode]` attribute map to the [`[numthreads]` HLSL attribute](https://docs.microsoft.com/windows/win32/direct3dhlsl/sm5-attributes-numthreads) for the shader entry point. Make sure to use the same values when dispatching the shader at runtime (either using the `GraphicsDevice.For` overload with explicit parameters for the tread numbers, or by relying on `GraphicsDevice.ForEach` to always use `(8, 8, 1)` for thread numbers, as it will be dispatching shaders on a 2D texture). + # Requirements Building and running **ComputeSharp** from the .NET solution filter has the following prerequisites: @@ -380,11 +416,11 @@ For a complete example, check out the F# sample [here](https://github.com/Sergio Huge thanks to these sponsors for directly supporting my work on **ComputeSharp**, it means a lot! 🙌 - - + - + + # Special thanks diff --git a/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj b/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj index c32acece..1ea30a7a 100644 --- a/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj +++ b/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj @@ -24,6 +24,7 @@ + + + + + diff --git a/samples/ComputeSharp.Sample.NuGet/nuget.config b/samples/ComputeSharp.Sample.NuGet/nuget.config index d67dcaef..c3f2b513 100644 --- a/samples/ComputeSharp.Sample.NuGet/nuget.config +++ b/samples/ComputeSharp.Sample.NuGet/nuget.config @@ -1,6 +1,7 @@ - + + diff --git a/samples/ComputeSharp.Sample/ComputeSharp.Sample.csproj b/samples/ComputeSharp.Sample/ComputeSharp.Sample.csproj index ce698002..138428ab 100644 --- a/samples/ComputeSharp.Sample/ComputeSharp.Sample.csproj +++ b/samples/ComputeSharp.Sample/ComputeSharp.Sample.csproj @@ -8,6 +8,7 @@ + License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. /// [AutoConstructor] +#if SAMPLE_APP +[EmbeddedBytecode(8, 8, 1)] +#endif internal readonly partial struct ColorfulInfinity : IPixelShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/ContouredLayers.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/ContouredLayers.cs index d730bb65..a089be50 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/ContouredLayers.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/ContouredLayers.cs @@ -6,6 +6,9 @@ /// Created by Shane. /// [AutoConstructor] +#if SAMPLE_APP +[EmbeddedBytecode(8, 8, 1)] +#endif internal readonly partial struct ContouredLayers : IPixelShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/ExtrudedTruchetPattern.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/ExtrudedTruchetPattern.cs index 7e91f583..c1805a42 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/ExtrudedTruchetPattern.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/ExtrudedTruchetPattern.cs @@ -6,6 +6,9 @@ /// Created by Shane. /// [AutoConstructor] +#if SAMPLE_APP +[EmbeddedBytecode(8, 8, 1)] +#endif internal readonly partial struct ExtrudedTruchetPattern : IPixelShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/FourColorGradient.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/FourColorGradient.cs index 590d5236..27c56503 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/FourColorGradient.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/FourColorGradient.cs @@ -7,6 +7,9 @@ /// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. /// [AutoConstructor] +#if SAMPLE_APP +[EmbeddedBytecode(8, 8, 1)] +#endif internal readonly partial struct FourColorGradient : IPixelShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/FractalTiling.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/FractalTiling.cs index d02828d6..d9fc7195 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/FractalTiling.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/FractalTiling.cs @@ -7,6 +7,9 @@ /// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. /// [AutoConstructor] +#if SAMPLE_APP +[EmbeddedBytecode(8, 8, 1)] +#endif internal readonly partial struct FractalTiling : IPixelShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/HelloWorld.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/HelloWorld.cs index b3ab8088..0d2c3a80 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/HelloWorld.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/HelloWorld.cs @@ -5,6 +5,9 @@ /// Ported from . /// [AutoConstructor] +#if SAMPLE_APP +[EmbeddedBytecode(8, 8, 1)] +#endif internal readonly partial struct HelloWorld : IPixelShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/MengerJourney.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/MengerJourney.cs index 93463b30..915bfbba 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/MengerJourney.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/MengerJourney.cs @@ -6,6 +6,9 @@ /// Created by Syntopia. /// [AutoConstructor] +#if SAMPLE_APP +[EmbeddedBytecode(8, 8, 1)] +#endif internal readonly partial struct MengerJourney : IPixelShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/Octagrams.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/Octagrams.cs index ac9cb3a5..03b5d22b 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/Octagrams.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/Octagrams.cs @@ -6,6 +6,9 @@ /// Created by whisky_shusuky. /// [AutoConstructor] +#if SAMPLE_APP +[EmbeddedBytecode(8, 8, 1)] +#endif internal readonly partial struct Octagrams : IPixelShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/ProteanClouds.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/ProteanClouds.cs index 16d4e015..6ef57780 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/ProteanClouds.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/ProteanClouds.cs @@ -7,6 +7,9 @@ /// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. /// [AutoConstructor] +#if SAMPLE_APP +[EmbeddedBytecode(8, 8, 1)] +#endif internal readonly partial struct ProteanClouds : IPixelShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/PyramidPattern.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/PyramidPattern.cs index d1925bff..b682aa29 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/PyramidPattern.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/PyramidPattern.cs @@ -7,6 +7,9 @@ /// Created by Shane. /// [AutoConstructor] +#if SAMPLE_APP +[EmbeddedBytecode(8, 8, 1)] +#endif internal readonly partial struct PyramidPattern : IPixelShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/TriangleGridContouring.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/TriangleGridContouring.cs index 2303cb5e..3e4abfc0 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/TriangleGridContouring.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/TriangleGridContouring.cs @@ -6,6 +6,9 @@ /// Created by Shane. /// [AutoConstructor] +#if SAMPLE_APP +[EmbeddedBytecode(8, 8, 1)] +#endif internal readonly partial struct TriangleGridContouring : IPixelShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/TwoTiledTruchet.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/TwoTiledTruchet.cs index 9e4005e3..79b45dad 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/TwoTiledTruchet.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/TwoTiledTruchet.cs @@ -6,6 +6,9 @@ /// Created by Shane. /// [AutoConstructor] +#if SAMPLE_APP +[EmbeddedBytecode(8, 8, 1)] +#endif internal readonly partial struct TwoTiledTruchet : IPixelShader { /// diff --git a/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj b/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj index 0c8a51df..c183283c 100644 --- a/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj +++ b/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj @@ -112,6 +112,9 @@ true true + + $(DefineConstants);SAMPLE_APP + PackageReference diff --git a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj index 4d829db6..c27be298 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj +++ b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj @@ -10,6 +10,7 @@ win10-$(Platform).pubxml true true + $(DefineConstants);SAMPLE_APP diff --git a/samples/ComputeSharp.SwapChain/ComputeSharp.SwapChain.csproj b/samples/ComputeSharp.SwapChain/ComputeSharp.SwapChain.csproj index 0fa5b528..55a8d4f8 100644 --- a/samples/ComputeSharp.SwapChain/ComputeSharp.SwapChain.csproj +++ b/samples/ComputeSharp.SwapChain/ComputeSharp.SwapChain.csproj @@ -8,6 +8,7 @@ + + + + net6.0 + + + + ComputeSharp.Dynamic + ComputeSharp.Dynamic + An extension library for ComputeSharp to enable dynamic compilation of shaders at runtime + + + + + + + + + + + \ No newline at end of file diff --git a/src/ComputeSharp/Core/Attributes/ShaderMethodAttribute.cs b/src/ComputeSharp.Dynamic/Attributes/ShaderMethodAttribute.cs similarity index 100% rename from src/ComputeSharp/Core/Attributes/ShaderMethodAttribute.cs rename to src/ComputeSharp.Dynamic/Attributes/ShaderMethodAttribute.cs diff --git a/src/ComputeSharp/Core/Attributes/__Internals/ShaderMethodSourceAttribute.HlslGeneration.cs b/src/ComputeSharp.Dynamic/Attributes/__Internals/ShaderMethodSourceAttribute.HlslGeneration.cs similarity index 100% rename from src/ComputeSharp/Core/Attributes/__Internals/ShaderMethodSourceAttribute.HlslGeneration.cs rename to src/ComputeSharp.Dynamic/Attributes/__Internals/ShaderMethodSourceAttribute.HlslGeneration.cs diff --git a/src/ComputeSharp/Core/Attributes/__Internals/ShaderMethodSourceAttribute.cs b/src/ComputeSharp.Dynamic/Attributes/__Internals/ShaderMethodSourceAttribute.cs similarity index 100% rename from src/ComputeSharp/Core/Attributes/__Internals/ShaderMethodSourceAttribute.cs rename to src/ComputeSharp.Dynamic/Attributes/__Internals/ShaderMethodSourceAttribute.cs diff --git a/src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj b/src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj new file mode 100644 index 00000000..5ea50bd8 --- /dev/null +++ b/src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj @@ -0,0 +1,80 @@ + + + netstandard2.0;net6.0 + bin\Release + ComputeSharp.Dynamic.xml + AnyCPU;x64;ARM64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ComputeSharp/Libraries/arm64/dxcompiler.dll b/src/ComputeSharp.Dynamic/Libraries/arm64/dxcompiler.dll similarity index 100% rename from src/ComputeSharp/Libraries/arm64/dxcompiler.dll rename to src/ComputeSharp.Dynamic/Libraries/arm64/dxcompiler.dll diff --git a/src/ComputeSharp/Libraries/arm64/dxil.dll b/src/ComputeSharp.Dynamic/Libraries/arm64/dxil.dll similarity index 100% rename from src/ComputeSharp/Libraries/arm64/dxil.dll rename to src/ComputeSharp.Dynamic/Libraries/arm64/dxil.dll diff --git a/src/ComputeSharp/Libraries/x64/dxcompiler.dll b/src/ComputeSharp.Dynamic/Libraries/x64/dxcompiler.dll similarity index 100% rename from src/ComputeSharp/Libraries/x64/dxcompiler.dll rename to src/ComputeSharp.Dynamic/Libraries/x64/dxcompiler.dll diff --git a/src/ComputeSharp/Libraries/x64/dxil.dll b/src/ComputeSharp.Dynamic/Libraries/x64/dxil.dll similarity index 100% rename from src/ComputeSharp/Libraries/x64/dxil.dll rename to src/ComputeSharp.Dynamic/Libraries/x64/dxil.dll diff --git a/src/ComputeSharp.Dynamic/Properties/AssemblyInfo.cs b/src/ComputeSharp.Dynamic/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..1360be6d --- /dev/null +++ b/src/ComputeSharp.Dynamic/Properties/AssemblyInfo.cs @@ -0,0 +1,5 @@ +using System.Runtime.CompilerServices; + +[module: SkipLocalsInit] + +[assembly: InternalsVisibleTo("ComputeSharp.Tests.Internals")] \ No newline at end of file diff --git a/src/ComputeSharp/Shaders/Exceptions/HlslCompilationException.cs b/src/ComputeSharp.Dynamic/Shaders/Exceptions/HlslCompilationException.cs similarity index 100% rename from src/ComputeSharp/Shaders/Exceptions/HlslCompilationException.cs rename to src/ComputeSharp.Dynamic/Shaders/Exceptions/HlslCompilationException.cs diff --git a/src/ComputeSharp/Shaders/Interop/ReflectionServices.cs b/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs similarity index 93% rename from src/ComputeSharp/Shaders/Interop/ReflectionServices.cs rename to src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs index d7e61c80..f9cbd999 100644 --- a/src/ComputeSharp/Shaders/Interop/ReflectionServices.cs +++ b/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs @@ -1,17 +1,11 @@ using System; -#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT using System.Runtime.CompilerServices; -#endif using ComputeSharp.__Internals; -#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT using ComputeSharp.Core.Extensions; -using ComputeSharp.Shaders.Translation; -#else -using Microsoft.Toolkit.Diagnostics; -#endif -#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; +#if !NET6_0_OR_GREATER +using DirectX = TerraFX.Interop.DirectX.DirectX2; #endif #pragma warning disable CS0618 @@ -110,14 +104,9 @@ public static class ReflectionServices private static unsafe void GetNonGenericShaderInfo(in T shader, out ShaderInfo shaderInfo) where T : struct, IShader { -#if DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT - ThrowHelper.ThrowNotSupportedException("Runtime shader compilation is not supported by the current configuration."); - - shaderInfo = default; -#else Unsafe.AsRef(in shader).BuildHlslString(out ArrayPoolStringBuilder shaderSource, 1, 1, 1); - using ComPtr dxcBlobBytecode = ShaderCompiler.Instance.CompileShader(shaderSource.WrittenSpan); + using ComPtr dxcBlobBytecode = Shaders.Translation.ShaderCompiler.Instance.CompileShader(shaderSource.WrittenSpan); shaderSource.Dispose(); @@ -169,6 +158,5 @@ public static class ReflectionServices Unsafe.AsRef(shaderInfo.MovInstructionCount) = d3D12ShaderReflection.Get()->GetMovInstructionCount(); Unsafe.AsRef(shaderInfo.InterfaceSlotCount) = d3D12ShaderReflection.Get()->GetNumInterfaceSlots(); Unsafe.AsRef(shaderInfo.RequiresDoublePrecisionSupport) = (d3D12ShaderReflection.Get()->GetRequiresFlags() & (D3D.D3D_SHADER_REQUIRES_DOUBLES | D3D.D3D_SHADER_REQUIRES_11_1_DOUBLE_EXTENSIONS)) != 0; -#endif } } diff --git a/src/ComputeSharp/Shaders/Interop/ShaderInfo.cs b/src/ComputeSharp.Dynamic/Shaders/Interop/ShaderInfo.cs similarity index 100% rename from src/ComputeSharp/Shaders/Interop/ShaderInfo.cs rename to src/ComputeSharp.Dynamic/Shaders/Interop/ShaderInfo.cs diff --git a/src/ComputeSharp/Shaders/Translation/ShaderCompiler.LibraryLoading.cs b/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.LibraryLoading.cs similarity index 98% rename from src/ComputeSharp/Shaders/Translation/ShaderCompiler.LibraryLoading.cs rename to src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.LibraryLoading.cs index efd62ed7..52bf32ff 100644 --- a/src/ComputeSharp/Shaders/Translation/ShaderCompiler.LibraryLoading.cs +++ b/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.LibraryLoading.cs @@ -1,4 +1,4 @@ -#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT && NET6_0_OR_GREATER +#if NET6_0_OR_GREATER using System; using System.IO; diff --git a/src/ComputeSharp/Shaders/Translation/ShaderCompiler.cs b/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs similarity index 98% rename from src/ComputeSharp/Shaders/Translation/ShaderCompiler.cs rename to src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs index 63de1f27..170f5899 100644 --- a/src/ComputeSharp/Shaders/Translation/ShaderCompiler.cs +++ b/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs @@ -1,12 +1,13 @@ -#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT - -using System; +using System; using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; using ComputeSharp.Core.Extensions; using ComputeSharp.Exceptions; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; +#if !NET6_0_OR_GREATER +using DirectX = TerraFX.Interop.DirectX.DirectX2; +#endif namespace ComputeSharp.Shaders.Translation; @@ -155,5 +156,3 @@ internal sealed unsafe partial class ShaderCompiler throw new HlslCompilationException(message); } } - -#endif diff --git a/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs b/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs new file mode 100644 index 00000000..59c02eec --- /dev/null +++ b/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs @@ -0,0 +1,38 @@ +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; + +namespace ComputeSharp.__Internals; + +/// +/// A that uses the DXC APIs to compile compute shaders. +/// +[EditorBrowsable(EditorBrowsableState.Never)] +[Obsolete("This type is not intended to be used directly by user code")] +public static class ShaderCompiler +{ + /// + /// Compiles a new HLSL shader from the input source code. + /// + /// The type of bytecode loader being used. + /// The type of shader being dispatched. + /// The instance to use to load the bytecode. + /// The number of threads in each thread group for the X axis. + /// The number of threads in each thread group for the Y axis. + /// The number of threads in each thread group for the Z axis. + /// The input instance representing the compute shader to run. + public static unsafe void LoadDynamicBytecode(ref TLoadeer loader, int threadsX, int threadsY, int threadsZ, in T shader) + where TLoadeer : struct, IBytecodeLoader + where T : struct, IShader + { + Unsafe.AsRef(in shader).BuildHlslString(out ArrayPoolStringBuilder builder, threadsX, threadsY, threadsZ); + + using ComPtr dxcBlobBytecode = Shaders.Translation.ShaderCompiler.Instance.CompileShader(builder.WrittenSpan); + + builder.Dispose(); + + loader.LoadDynamicBytecode((IntPtr)dxcBlobBytecode.Get()); + } +} diff --git a/src/ComputeSharp.SourceGenerators/AnalyzerReleases.Shipped.md b/src/ComputeSharp.SourceGenerators/AnalyzerReleases.Shipped.md index 74fadd53..571bb103 100644 --- a/src/ComputeSharp.SourceGenerators/AnalyzerReleases.Shipped.md +++ b/src/ComputeSharp.SourceGenerators/AnalyzerReleases.Shipped.md @@ -53,3 +53,4 @@ CMPS0043 | ComputeSharp.IComputeShader | Error | IShaderGenerator, [Documentatio CMPS0044 | ComputeSharp.IComputeShader | Error | IShaderGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp) CMPS0045 | ComputeSharp.IComputeShader | Error | IShaderGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp) CMPS0046 | ComputeSharp.IComputeShader | Error | IShaderGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp) +CMPS0047 | ComputeSharp.IComputeShader | Error | IShaderGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp) diff --git a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj index 2814dcd1..c1dd63a2 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj +++ b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj @@ -18,8 +18,8 @@ - - + + @@ -72,9 +72,9 @@ - - - + + + @@ -93,10 +93,10 @@ - - - - + + + + @@ -104,5 +104,6 @@ + diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index 7f11ded0..4eedd7f1 100644 --- a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -576,7 +576,7 @@ internal static class DiagnosticDescriptors public static readonly DiagnosticDescriptor MultipleShaderTypesImplemented = new( id: "CMPS0042", title: "Multiple shader implementations for type declaration", - messageFormat: $"The shader of type {{0}} cannot implement more than one shader interface", + messageFormat: "The shader of type {0} cannot implement more than one shader interface", category: typeof(IShaderGenerator).FullName, defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -592,7 +592,7 @@ internal static class DiagnosticDescriptors public static readonly DiagnosticDescriptor EmbeddedBytecodeWithDynamicShader = new( id: "CMPS0043", title: "Embedded bytecode for dynamic shader", - messageFormat: $"The shader of type {{0}} cannot be precompiled, as it is dynamic (it captures delegate fields)", + messageFormat: "The shader of type {0} cannot be precompiled, as it is dynamic (it captures delegate fields)", category: typeof(IShaderGenerator).FullName, defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -608,7 +608,7 @@ internal static class DiagnosticDescriptors public static readonly DiagnosticDescriptor InvalidEmbeddedBytecodeThreadIds = new( id: "CMPS0044", title: "Invalid thread ids for shader with embedded bytecode", - messageFormat: $"The shader of type {{0}} is annotated with invalid thread ids values ({{1}}, {{2}}, {{3}})", + messageFormat: "The shader of type {0} is annotated with invalid thread ids values ({1}, {2}, {3})", category: typeof(IShaderGenerator).FullName, defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -618,13 +618,13 @@ internal static class DiagnosticDescriptors /// /// Gets a for an embedded bytecode shader failed due to a Win32 exception. /// - /// Format: "The shader of type {{0}} failed to compile due to a Win32 exception (HRESULT: {1:X8}, Message: "{2}")". + /// Format: "The shader of type {0} failed to compile due to a Win32 exception (HRESULT: {1:X8}, Message: "{2}")". /// /// public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithWin32Exception = new( id: "CMPS0045", title: "Embedded bytecode compilation failed due to Win32 exception", - messageFormat: $"The shader of type {{0}} failed to compile due to a Win32 exception (HRESULT: {{1:X8}}, Message: \"{{2}}\")", + messageFormat: "The shader of type {0} failed to compile due to a Win32 exception (HRESULT: {1:X8}, Message: \"{2}\")", category: typeof(IShaderGenerator).FullName, defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -640,10 +640,26 @@ internal static class DiagnosticDescriptors public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithHlslCompilationException = new( id: "CMPS0046", title: "Embedded bytecode compilation failed due to an HLSL compiler error", - messageFormat: $"The shader of type {{0}} failed to compile due to an HLSL compiler error (Message: \"{{1}}\")", + messageFormat: "The shader of type {0} failed to compile due to an HLSL compiler error (Message: \"{1}\")", category: typeof(IShaderGenerator).FullName, defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, description: "The embedded bytecode for a shader failed to be compiled due to an HLSL compiler error.", helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); + + /// + /// Gets a for a shader without the embedded bytecode attribute, when dynamic shaders are not supported. + /// + /// Format: "The shader of type {0} needs to be annotated as having embedded bytecode (using the [EmbeddedBytecode] attribute), as dynamic shader compilation is not supported". + /// + /// + public static readonly DiagnosticDescriptor MissingEmbeddedBytecodeAttributeWhenDynamicShaderCompilationIsNotSupported = new( + id: "CMPS0047", + title: "Embedded bytecode compilation failed due to an HLSL compiler error", + messageFormat: "The shader of type {0} needs to be annotated as having embedded bytecode (using the [EmbeddedBytecode] attribute), as dynamic shader compilation is not supported", + category: typeof(IShaderGenerator).FullName, + defaultSeverity: DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: "When dynamic shader compilation is not supported (ie. when ComputeSharp.Dynamic is not referenced), all shaders need to be annotated as having embedded bytecode (using the [EmbeddedBytecode] attribute).", + helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); } diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslStringMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslStringMethod.Syntax.cs index 5b4e860a..ce88d435 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslStringMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslStringMethod.Syntax.cs @@ -21,14 +21,18 @@ public sealed partial class IShaderGenerator /// Creates a instance for the BuildHlslString method. /// /// The input instance to use. + /// Indicates whether or not dynamic shaders are supported. /// The resulting instance for the BuildHlslString method. - public static MethodDeclarationSyntax GetSyntax(HlslShaderSourceInfo hlslSourceInfo) + public static MethodDeclarationSyntax GetSyntax(HlslShaderSourceInfo hlslSourceInfo, bool supportsDynamicShaders) { - ImmutableArray bodyStatements = GenerateRenderMethodBody(hlslSourceInfo); + // Generate the necessary body statements depending on whether dynamic shaders are supported + ImmutableArray bodyStatements = supportsDynamicShaders + ? GenerateRenderMethodBody(hlslSourceInfo) + : GenerateEmptyMethodBody(); // This code produces a method declaration as follows: // - // readonly void global::ComputeSharp.__Internals.IShader.BuildHlslString(ref global::ComputeSharp.__Internals.ArrayPoolStringBuilder builder, int threadsX, int threadsY, int threadsZ) + // readonly void global::ComputeSharp.__Internals.IShader.BuildHlslString(out global::ComputeSharp.__Internals.ArrayPoolStringBuilder builder, int threadsX, int threadsY, int threadsZ) // { // // } @@ -46,6 +50,30 @@ public sealed partial class IShaderGenerator .WithBody(Block(bodyStatements)); } + /// + /// Produces the series of statements for the empty fallback method. + /// + /// A series of statements for when dynamic shaders are not supported. + private static ImmutableArray GenerateEmptyMethodBody() + { + // builder = global::ComputeSharp.__Internals.ArrayPoolStringBuilder.Create(0); + return + ImmutableArray.Create( + ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + IdentifierName("builder"), + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("global::ComputeSharp.__Internals.ArrayPoolStringBuilder"), + IdentifierName("Create"))) + .AddArgumentListArguments( + Argument(LiteralExpression( + SyntaxKind.NumericLiteralExpression, + Literal(0))))))); + } + /// /// Produces the series of statements to build the current HLSL source. /// diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetDispatchIdMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetDispatchIdMethod.Syntax.cs index 273bf081..8272b543 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetDispatchIdMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetDispatchIdMethod.Syntax.cs @@ -19,9 +19,10 @@ public sealed partial class IShaderGenerator /// /// Creates a instance for the GetDispatchId method. /// - ///The names of all instance fields within the current shader type. + /// The names of all instance fields within the current shader type.\ + /// Indicates whether or not dynamic shaders are supported. /// The resulting instance for the GetDispatchId method. - public static MethodDeclarationSyntax GetSyntax(ImmutableArray delegateFieldNames) + public static MethodDeclarationSyntax GetSyntax(ImmutableArray delegateFieldNames, bool supportsDynamicShaders) { // This code produces a method declaration as follows: // @@ -35,18 +36,19 @@ public sealed partial class IShaderGenerator Identifier("GetDispatchId")) .WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.__Internals.{nameof(IShader)}"))) .AddModifiers(Token(SyntaxKind.ReadOnlyKeyword)) - .WithBody(GetShaderHashCodeBody(delegateFieldNames)); + .WithBody(GetShaderHashCodeBody(delegateFieldNames, supportsDynamicShaders)); } /// /// Gets a instance with the logic to compute the hashcode of a given shader type. /// /// The names of all instance fields within the current shader type. + /// Indicates whether or not dynamic shaders are supported. /// The instance to hash the input shader. [Pure] - private static BlockSyntax GetShaderHashCodeBody(ImmutableArray delegateFieldNames) + private static BlockSyntax GetShaderHashCodeBody(ImmutableArray delegateFieldNames, bool supportsDynamicShaders) { - if (delegateFieldNames.Length == 0) + if (delegateFieldNames.Length == 0 || !supportsDynamicShaders) { // return 0; return diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateTryGetBytecodeMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs similarity index 54% rename from src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateTryGetBytecodeMethod.Syntax.cs rename to src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs index ce084c18..d69fa0bf 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateTryGetBytecodeMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs @@ -15,17 +15,18 @@ namespace ComputeSharp.SourceGenerators; public sealed partial class IShaderGenerator { /// - private static partial class TryGetBytecode + private static partial class LoadBytecode { /// /// Creates a instance for the TryGetBytecode method. /// /// The input instance. + /// Indicates whether or not dynamic shaders are supported. /// An opaque instance to transform the final tree into text. /// The resulting instance for the BuildHlslString method. - public static MethodDeclarationSyntax GetSyntax(EmbeddedBytecodeInfo bytecodeInfo, out Func fixup) + public static MethodDeclarationSyntax GetSyntax(EmbeddedBytecodeInfo bytecodeInfo, bool supportsDynamicShaders, out Func fixup) { - BlockSyntax block = GetShaderBytecodeBody(bytecodeInfo, out string? bytecodeLiterals); + BlockSyntax block = GetShaderBytecodeBody(bytecodeInfo, supportsDynamicShaders, out string? bytecodeLiterals); if (bytecodeLiterals is not null) { @@ -38,21 +39,24 @@ public sealed partial class IShaderGenerator // This code produces a method declaration as follows: // - // readonly int global::ComputeSharp.__Internals.IShader.TryGetBytecode(int threadsX, int threadsY, int threadsZ, out ReadOnlySpan bytecode) + // readonly void global::ComputeSharp.__Internals.IShader.LoadBytecode(ref TLoader loader, int threadsX, int threadsY, int threadsZ) // { // // } return MethodDeclaration( - PredefinedType(Token(SyntaxKind.BoolKeyword)), - Identifier("TryGetBytecode")) + PredefinedType(Token(SyntaxKind.VoidKeyword)), + Identifier("LoadBytecode")) .WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.__Internals.{nameof(IShader)}"))) .AddModifiers(Token(SyntaxKind.ReadOnlyKeyword)) + .AddTypeParameterListParameters(TypeParameter(Identifier("TLoader"))) .AddParameterListParameters( + Parameter(Identifier("loader")) + .AddModifiers(Token(SyntaxKind.RefKeyword)) + .WithType(IdentifierName("TLoader")), Parameter(Identifier("threadsX")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))), Parameter(Identifier("threadsY")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))), - Parameter(Identifier("threadsZ")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))), - Parameter(Identifier("bytecode")).AddModifiers(Token(SyntaxKind.OutKeyword)).WithType(IdentifierName("global::System.ReadOnlySpan"))) + Parameter(Identifier("threadsZ")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword)))) .WithBody(block); } @@ -60,88 +64,147 @@ public sealed partial class IShaderGenerator /// Gets a instance with the logic to try to get a compiled shader bytecode. /// /// The input instance. + /// Indicates whether or not dynamic shaders are supported. /// The resulting bytecode literals to insert into the final source code. /// The instance trying to retrieve the precompiled shader. [Pure] - private static unsafe BlockSyntax GetShaderBytecodeBody(EmbeddedBytecodeInfo bytecodeInfo, out string? bytecodeLiterals) + private static unsafe BlockSyntax GetShaderBytecodeBody(EmbeddedBytecodeInfo bytecodeInfo, bool supportsDynamicShaders, out string? bytecodeLiterals) { if (bytecodeInfo.Bytecode.IsEmpty) { bytecodeLiterals = null; - // This code produces a method declaration as follows: - // - // bytecode = default; - // - // return false; - return - Block( - ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - IdentifierName("bytecode"), - LiteralExpression(SyntaxKind.DefaultLiteralExpression, Token(SyntaxKind.DefaultKeyword)))), - ReturnStatement( - LiteralExpression( - SyntaxKind.FalseLiteralExpression))); + if (supportsDynamicShaders) + { + // Return the dynamic compilation path + return Block(GetDynamicCompilationStatement()); + } + else + { + // Faulting path + return Block(GetDynamicCompilationFaultingBlock()); + } } bytecodeLiterals = BuildShaderBytecodeExpressionString(bytecodeInfo.Bytecode.AsSpan()); - // This code produces a method declaration as follows: + // This code produces a branch as follows: // // if (threadsX == && threadsY == && threadsZ == ) // { - // bytecode = new byte[] { __EMBEDDED_SHADER_BYTECODE }; - // - // return true; + // global::System.ReadOnlySpan bytecode = new byte[] { __EMBEDDED_SHADER_BYTECODE }; + // loader.LoadEmbeddedBytecode(bytecode); // } // - // bytecode = default; - // - // return false; - // // Note that the __EMBEDDED_SHADER_BYTECODE identifier will be replaced after the string // is created by the generator. This greatly speeds up the code generation, as it avoids // having to create/parse tens of thousands of literal expression nodes for every shader. - return - Block( - IfStatement( + IfStatementSyntax embeddedBranch = + IfStatement( + BinaryExpression( + SyntaxKind.LogicalAndExpression, BinaryExpression( SyntaxKind.LogicalAndExpression, BinaryExpression( - SyntaxKind.LogicalAndExpression, - BinaryExpression( - SyntaxKind.EqualsExpression, - IdentifierName("threadsX"), - LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(bytecodeInfo.X))), - BinaryExpression( - SyntaxKind.EqualsExpression, - IdentifierName("threadsY"), - LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(bytecodeInfo.Y)))), + SyntaxKind.EqualsExpression, + IdentifierName("threadsX"), + LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(bytecodeInfo.X))), BinaryExpression( SyntaxKind.EqualsExpression, - IdentifierName("threadsZ"), - LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(bytecodeInfo.Z)))), - Block( - ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - IdentifierName("bytecode"), - ArrayCreationExpression( + IdentifierName("threadsY"), + LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(bytecodeInfo.Y)))), + BinaryExpression( + SyntaxKind.EqualsExpression, + IdentifierName("threadsZ"), + LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(bytecodeInfo.Z)))), + Block( + LocalDeclarationStatement( + VariableDeclaration( + GenericName(Identifier("global::System.ReadOnlySpan")) + .AddTypeArgumentListArguments(PredefinedType(Token(SyntaxKind.ByteKeyword)))) + .AddVariables( + VariableDeclarator(Identifier("bytecode")) + .WithInitializer( + EqualsValueClause( + ArrayCreationExpression( ArrayType(PredefinedType(Token(SyntaxKind.ByteKeyword))) .AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList(OmittedArraySizeExpression())))) .WithInitializer( InitializerExpression( SyntaxKind.ArrayInitializerExpression, - SingletonSeparatedList(IdentifierName("__EMBEDDED_SHADER_BYTECODE")))))), - ReturnStatement(LiteralExpression(SyntaxKind.TrueLiteralExpression)))), - ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - IdentifierName("bytecode"), - LiteralExpression(SyntaxKind.DefaultLiteralExpression, Token(SyntaxKind.DefaultKeyword)))), - ReturnStatement(LiteralExpression(SyntaxKind.FalseLiteralExpression))); + SingletonSeparatedList(IdentifierName("__EMBEDDED_SHADER_BYTECODE")))))))), + ExpressionStatement( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("loader"), + IdentifierName("LoadEmbeddedBytecode"))) + .AddArgumentListArguments(Argument(IdentifierName("bytecode")))))); + + // If dynamic shaders are supported, return the combined block + if (supportsDynamicShaders) + { + return Block(embeddedBranch.WithElse(ElseClause(Block(GetDynamicCompilationStatement())))); + } + + // If there is no dynamic shader support, add the faulting path after the branch + return Block(embeddedBranch.WithElse(ElseClause(Block(GetDynamicCompilationFaultingBlock())))); + } + + /// + /// The cached tree of dynamic statements. + /// + private static StatementSyntax? dynamicStatement; + + /// + /// Returns the instance to create a new dynamic shader. + /// + /// The instance to create a new dynamic shader. + private static StatementSyntax GetDynamicCompilationStatement() + { + // This code produces a method declaration as follows: + // + // ComputeSharp.__Internals.ShaderCompiler.LoadDynamicBytecode(ref loader, threadsX, threadsY, threadsZ, in this); + return dynamicStatement ??= + ExpressionStatement( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("ComputeSharp.__Internals.ShaderCompiler"), + IdentifierName("LoadDynamicBytecode"))) + .AddArgumentListArguments( + Argument(IdentifierName("loader")).WithRefOrOutKeyword(Token(SyntaxKind.RefKeyword)), + Argument(IdentifierName("threadsX")), + Argument(IdentifierName("threadsY")), + Argument(IdentifierName("threadsZ")), + Argument(ThisExpression()).WithRefOrOutKeyword(Token(SyntaxKind.InKeyword)))); + } + + /// + /// The cached tree of dynamic fault statement. + /// + private static ExpressionStatementSyntax? dynamicFaultStatement; + + /// + /// Returns a instances to perform a faulting call to LoadDynamicBytecode(IntPtr). + /// + /// A instances to perform a faulting call to LoadDynamicBytecode(IntPtr). + private static ExpressionStatementSyntax GetDynamicCompilationFaultingBlock() + { + // This code produces a faulting call as follows: + // + // loader.LoadDynamicBytecode(default); + return dynamicFaultStatement ??= + ExpressionStatement( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("loader"), + IdentifierName("LoadDynamicBytecode"))) + .AddArgumentListArguments( + Argument(LiteralExpression( + SyntaxKind.DefaultLiteralExpression, + Token(SyntaxKind.DefaultKeyword))))); } /// diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateTryGetBytecodeMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs similarity index 92% rename from src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateTryGetBytecodeMethod.cs rename to src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs index 47fc3948..e53ac4c4 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateTryGetBytecodeMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs @@ -23,35 +23,43 @@ namespace ComputeSharp.SourceGenerators; public sealed partial class IShaderGenerator { /// - /// A helper with all logic to generate the TryGetBytecode method. + /// A helper with all logic to generate the LoadBytecode method. /// - private static partial class TryGetBytecode + private static partial class LoadBytecode { /// /// Gets the thread ids values for a given shader type, if available. /// /// The input instance to process. /// Indicates whether or not the shader is dynamic (ie. captures delegates). + /// Indicates whether or not dynamic shaders are supported. /// The resulting diagnostics from the processing operation. /// The thread ids for the precompiled shader, if available. public static ThreadIdsInfo GetInfo( INamedTypeSymbol structDeclarationSymbol, bool isDynamicShader, + bool supportsDynamicShaders, out ImmutableArray diagnostics) { + ImmutableArray.Builder builder = ImmutableArray.CreateBuilder(); + AttributeData? attribute = structDeclarationSymbol .GetAttributes() .FirstOrDefault(static a => a.AttributeClass?.ToDisplayString() == typeof(EmbeddedBytecodeAttribute).FullName); if (attribute is null) { - diagnostics = ImmutableArray.Empty; + // Emit the diagnostics if dynamic shaders are not supported + if (!supportsDynamicShaders) + { + builder.Add(MissingEmbeddedBytecodeAttributeWhenDynamicShaderCompilationIsNotSupported, structDeclarationSymbol, structDeclarationSymbol); + } + + diagnostics = builder.ToImmutable(); return new(true, 0, 0, 0); } - ImmutableArray.Builder builder = ImmutableArray.CreateBuilder(); - // Validate the thread number arguments if (attribute.ConstructorArguments.Length != 3 || attribute.ConstructorArguments[0].Value is not int threadsX || diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs index e834356d..2c9391cc 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs @@ -32,7 +32,7 @@ public sealed partial class IShaderGenerator { // This code produces a method declaration as follows: // - // readonly void global::ComputeSharp.__Internals.IShader.LoadDispatchData(ref TDataLoader loader, global::ComputeSharp.GraphicsDevice device, int x, int y, int z) + // readonly void global::ComputeSharp.__Internals.IShader.LoadDispatchData(ref TLoader loader, global::ComputeSharp.GraphicsDevice device, int x, int y, int z) // { // // } @@ -42,11 +42,11 @@ public sealed partial class IShaderGenerator Identifier("LoadDispatchData")) .WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.__Internals.{nameof(IShader)}"))) .AddModifiers(Token(SyntaxKind.ReadOnlyKeyword)) - .AddTypeParameterListParameters(TypeParameter(Identifier("TDataLoader"))) + .AddTypeParameterListParameters(TypeParameter(Identifier("TLoader"))) .AddParameterListParameters( Parameter(Identifier("loader")) .AddModifiers(Token(SyntaxKind.RefKeyword)) - .WithType(IdentifierName("TDataLoader")), + .WithType(IdentifierName("TLoader")), Parameter(Identifier("device")).WithType(IdentifierName("global::ComputeSharp.GraphicsDevice")), Parameter(Identifier("x")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))), Parameter(Identifier("y")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))), diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs index a886d33e..0e5f945f 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs @@ -25,7 +25,7 @@ public sealed partial class IShaderGenerator { // This code produces a method declaration as follows: // - // readonly void global::ComputeSharp.__Internals.IShader.LoadDispatchMetadata(ref TMetadataLoader loader, out global::System.IntPtr result) + // readonly void global::ComputeSharp.__Internals.IShader.LoadDispatchMetadata(ref TLoader loader, out global::System.IntPtr result) // { // // } @@ -35,11 +35,11 @@ public sealed partial class IShaderGenerator Identifier("LoadDispatchMetadata")) .WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.__Internals.{nameof(IShader)}"))) .AddModifiers(Token(SyntaxKind.ReadOnlyKeyword)) - .AddTypeParameterListParameters(TypeParameter(Identifier("TMetadataLoader"))) + .AddTypeParameterListParameters(TypeParameter(Identifier("TLoader"))) .AddParameterListParameters( Parameter(Identifier("loader")) .AddModifiers(Token(SyntaxKind.RefKeyword)) - .WithType(IdentifierName("TMetadataLoader")), + .WithType(IdentifierName("TLoader")), Parameter(Identifier("result")) .AddModifiers(Token(SyntaxKind.OutKeyword)) .WithType(IdentifierName($"global::System.{typeof(IntPtr).Name}"))) diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs index aabfe271..ba891525 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs @@ -29,6 +29,12 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator compilation.Options is CSharpCompilationOptions { AllowUnsafe: true } && compilation.GetTypeByMetadataName("System.Runtime.CompilerServices.SkipLocalsInitAttribute") is not null); + // Check whether or not dynamic shaders are supported + IncrementalValueProvider supportsDynamicShaders = + context.CompilationProvider + .Select(static (compilation, token) => compilation.ReferencedAssemblyNames.Any( + static identity => identity.Name is "ComputeSharp.Dynamic")); + // Get all declared struct types and their type symbols IncrementalValuesProvider<(StructDeclarationSyntax Syntax, INamedTypeSymbol Symbol)> structDeclarations = context.SyntaxProvider @@ -61,32 +67,33 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator .WithComparers(HierarchyInfo.Comparer.Default, DispatchIdInfo.Comparer.Default); // Generate the GetDispatchId() methods - context.RegisterSourceOutput(hierarchyAndDispatchIdInfo, static (context, item) => + context.RegisterSourceOutput(hierarchyAndDispatchIdInfo.Combine(supportsDynamicShaders), static (context, item) => { - MethodDeclarationSyntax getDispatchIdMethod = GetDispatchId.GetSyntax(item.Info.Delegates); - CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Hierarchy, getDispatchIdMethod, false); + MethodDeclarationSyntax getDispatchIdMethod = GetDispatchId.GetSyntax(item.Left.Info.Delegates, item.Right); + CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Left.Hierarchy, getDispatchIdMethod, false); - context.AddSource($"{item.Hierarchy.FilenameHint}.GetDispatchId", SourceText.From(compilationUnit.ToFullString(), Encoding.UTF8)); + context.AddSource($"{item.Left.Hierarchy.FilenameHint}.{nameof(GetDispatchId)}", SourceText.From(compilationUnit.ToFullString(), Encoding.UTF8)); }); // Get the dispatch data, HLSL source and embedded bytecode info. This info is computed on the // same step as parts are shared in following sub-branches in the incremental generator pipeline. IncrementalValuesProvider<(Result Dispatch, Result Hlsl, Result ThreadIds)> shaderInfoWithErrors = shaderDeclarations + .Combine(supportsDynamicShaders) .Combine(context.CompilationProvider) .Select(static (item, token) => { // LoadDispatchData() info ImmutableArray fieldInfos = LoadDispatchData.GetInfo( - item.Left.Symbol, - item.Left.Type, + item.Left.Left.Symbol, + item.Left.Left.Type, out int resourceCount, out int root32BitConstantCount, out ImmutableArray dispatchDataDiagnostics); DispatchDataInfo dispatchDataInfo = new( - item.Left.Hierarchy, - item.Left.Type, + item.Left.Left.Hierarchy, + item.Left.Left.Type, fieldInfos, resourceCount, root32BitConstantCount); @@ -94,14 +101,15 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator // BuildHlslString() info HlslShaderSourceInfo hlslSourceInfo = BuildHlslString.GetInfo( item.Right, - item.Left.Syntax, - item.Left.Symbol, + item.Left.Left.Syntax, + item.Left.Left.Symbol, out ImmutableArray hlslSourceDiagnostics); // TryGetBytecode() info - ThreadIdsInfo threadIds = TryGetBytecode.GetInfo( - item.Left.Symbol, + ThreadIdsInfo threadIds = LoadBytecode.GetInfo( + item.Left.Left.Symbol, !hlslSourceInfo.Delegates.IsEmpty, + item.Left.Right, out ImmutableArray threadIdsDiagnostics); return ( @@ -137,22 +145,23 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator item.Left.Root32BitConstantCount); CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Left.Hierarchy, loadDispatchDataMethod, item.Right); - context.AddSource($"{item.Left.Hierarchy.FilenameHint}.LoadDispatchData", SourceText.From(compilationUnit.ToFullString(), Encoding.UTF8)); - }); + context.AddSource($"{item.Left.Hierarchy.FilenameHint}.{nameof(LoadDispatchData)}", SourceText.From(compilationUnit.ToFullString(), Encoding.UTF8)); + }); // Get the filtered sequence to enable caching - IncrementalValuesProvider<(HierarchyInfo Hierarchy, HlslShaderSourceInfo SourceInfo)> hlslSourceInfo = + IncrementalValuesProvider<(HierarchyInfo Hierarchy, HlslShaderSourceInfo SourceInfo, bool SupportsDynamicShaders)> hlslSourceInfo = shaderInfo - .Select(static (item, token) => (item.Dispatch.Hierarchy, item.Hlsl)) - .WithComparers(HierarchyInfo.Comparer.Default, HlslShaderSourceInfo.Comparer.Default); + .Combine(supportsDynamicShaders) + .Select(static (item, token) => (item.Left.Dispatch.Hierarchy, item.Left.Hlsl, item.Right)) + .WithComparers(HierarchyInfo.Comparer.Default, HlslShaderSourceInfo.Comparer.Default, EqualityComparer.Default); // Generate the BuildHlslString() methods context.RegisterSourceOutput(hlslSourceInfo.Combine(canUseSkipLocalsInit), static (context, item) => { - MethodDeclarationSyntax buildHlslStringMethod = BuildHlslString.GetSyntax(item.Left.SourceInfo); + MethodDeclarationSyntax buildHlslStringMethod = BuildHlslString.GetSyntax(item.Left.SourceInfo, item.Left.SupportsDynamicShaders); CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Left.Hierarchy, buildHlslStringMethod, item.Right); - context.AddSource($"{item.Left.Hierarchy.FilenameHint}.BuildHlslString", SourceText.From(compilationUnit.ToFullString(), Encoding.UTF8)); + context.AddSource($"{item.Left.Hierarchy.FilenameHint}.{nameof(BuildHlslString)}", SourceText.From(compilationUnit.ToFullString(), Encoding.UTF8)); }); // Get the dispatch metadata info @@ -173,7 +182,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator MethodDeclarationSyntax buildHlslStringMethod = LoadDispatchMetadata.GetSyntax(item.Left.MetadataInfo); CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Left.Hierarchy, buildHlslStringMethod, item.Right); - context.AddSource($"{item.Left.Hierarchy.FilenameHint}.LoadDispatchMetadata", SourceText.From(compilationUnit.ToFullString(), Encoding.UTF8)); + context.AddSource($"{item.Left.Hierarchy.FilenameHint}.{nameof(LoadDispatchMetadata)}", SourceText.From(compilationUnit.ToFullString(), Encoding.UTF8)); }); // Transform the raw HLSL source to compile @@ -187,7 +196,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator shaderBytecodeInfo .Select(static (item, token) => { - ImmutableArray bytecode = TryGetBytecode.GetBytecode(item.ThreadIds, item.Hlsl, out DiagnosticInfo? diagnostic); + ImmutableArray bytecode = LoadBytecode.GetBytecode(item.ThreadIds, item.Hlsl, out DiagnosticInfo? diagnostic); EmbeddedBytecodeInfo bytecodeInfo = new( item.ThreadIds.X, @@ -225,13 +234,13 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator .WithComparers(HierarchyInfo.Comparer.Default, EmbeddedBytecodeInfo.Comparer.Default); // Generate the TryGetBytecode() methods - context.RegisterSourceOutput(embeddedBytecode, static (context, item) => + context.RegisterSourceOutput(embeddedBytecode.Combine(supportsDynamicShaders), static (context, item) => { - MethodDeclarationSyntax tryGetBytecodeMethod = TryGetBytecode.GetSyntax(item.BytecodeInfo, out Func fixup); - CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Hierarchy, tryGetBytecodeMethod, false); + MethodDeclarationSyntax tryGetBytecodeMethod = LoadBytecode.GetSyntax(item.Left.BytecodeInfo, item.Right, out Func fixup); + CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Left.Hierarchy, tryGetBytecodeMethod, false); string text = fixup(compilationUnit); - context.AddSource($"{item.Hierarchy.FilenameHint}.TryGetBytecode", SourceText.From(text, Encoding.UTF8)); + context.AddSource($"{item.Left.Hierarchy.FilenameHint}.{nameof(LoadBytecode)}", SourceText.From(text, Encoding.UTF8)); }); } } diff --git a/src/ComputeSharp.SourceGenerators/Models/HierarchyInfo.cs b/src/ComputeSharp.SourceGenerators/Models/HierarchyInfo.cs index 10039dac..a13ac620 100644 --- a/src/ComputeSharp.SourceGenerators/Models/HierarchyInfo.cs +++ b/src/ComputeSharp.SourceGenerators/Models/HierarchyInfo.cs @@ -79,7 +79,14 @@ internal sealed record HierarchyInfo(string FilenameHint, string MetadataName, s /// public int GetHashCode(HierarchyInfo obj) { - return HashCode.Combine(obj.Namespace, obj.MetadataName, obj.Names, obj.Names[0]); + HashCode hashCode = default; + + hashCode.Add(obj.FilenameHint); + hashCode.Add(obj.MetadataName); + hashCode.Add(obj.Namespace); + hashCode.AddRange(obj.Names); + + return hashCode.ToHashCode(); } } } diff --git a/src/ComputeSharp/ComputeSharp.csproj b/src/ComputeSharp/ComputeSharp.csproj index e97405a8..eb42dee5 100644 --- a/src/ComputeSharp/ComputeSharp.csproj +++ b/src/ComputeSharp/ComputeSharp.csproj @@ -3,9 +3,6 @@ netstandard2.0;net6.0 bin\Release ComputeSharp.xml - ComputeSharp - AnyCPU;x64;ARM64 - false @@ -24,90 +21,16 @@ - + - + $(NoWarn);CS1591 - - - $(DefineConstants);DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -306,4 +229,8 @@ UIntMxN.g.cs + + + + diff --git a/src/ComputeSharp/Core/Interfaces/__Internals/IBytecodeLoader.cs b/src/ComputeSharp/Core/Interfaces/__Internals/IBytecodeLoader.cs new file mode 100644 index 00000000..943cef72 --- /dev/null +++ b/src/ComputeSharp/Core/Interfaces/__Internals/IBytecodeLoader.cs @@ -0,0 +1,26 @@ +using System; +using System.ComponentModel; + +namespace ComputeSharp.__Internals; + +/// +/// A base representing a bytecode loader for a shader being dispatched. +/// +[EditorBrowsable(EditorBrowsableState.Never)] +[Obsolete("This interface is not intended to be used directly by user code")] +public interface IBytecodeLoader +{ + /// + /// Loads a dynamic shader bytecode. + /// + /// An opaque handle to the shader bytecode. + /// Thrown if the shader has already been initialized. + void LoadDynamicBytecode(IntPtr handle); + + /// + /// Loads the embedded shader bytecode for the shader being dispatched. + /// + /// The shader bytecode. + /// Thrown if the shader has already been initialized. + void LoadEmbeddedBytecode(ReadOnlySpan bytecode); +} diff --git a/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs b/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs index 8193efc6..262b7d0d 100644 --- a/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs +++ b/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs @@ -28,16 +28,16 @@ public interface IShader /// /// Loads the dispatch data for the shader. /// - /// The type of data loader being used. - /// The instance to use to load the data. + /// The type of data loader being used. + /// The instance to use to load the data. /// The device the shader is being dispatched on. /// 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. [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is not intended to be called directly by user code")] - void LoadDispatchData(ref TDataLoader loader, GraphicsDevice device, int x, int y, int z) - where TDataLoader : struct, IDispatchDataLoader + void LoadDispatchData(ref TLoader loader, GraphicsDevice device, int x, int y, int z) + where TLoader : struct, IDispatchDataLoader #if NET6_0_OR_GREATER { throw new NotImplementedException(); @@ -49,13 +49,13 @@ public interface IShader /// /// Loads an opaque metadata handle from the metadata of the current shader. /// - /// The type of data loader being used. - /// The instance to use to load the data. + /// The type of data loader being used. + /// The instance to use to load the data. /// The resulting opaque metadata handle. [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is not intended to be called directly by user code")] - void LoadDispatchMetadata(ref TMetadataLoader loader, out IntPtr result) - where TMetadataLoader : struct, IDispatchMetadataLoader + void LoadDispatchMetadata(ref TLoader loader, out IntPtr result) + where TLoader : struct, IDispatchMetadataLoader #if NET6_0_OR_GREATER { throw new NotImplementedException(); @@ -83,17 +83,17 @@ public interface IShader #endif /// - /// Tries to retrieve the precompiled bytecode for the current shader. + /// Loads the bytecode for the current shader. /// + /// The type of bytecode loader being used. + /// The instance to use to load the bytecode. /// The number of threads in each thread group for the X axis. /// The number of threads in each thread group for the Y axis. /// The number of threads in each thread group for the Z axis. - /// The resulting bytecode, if found. - /// Whether or not a precompiled bytecode was found. - /// The underlying buffer for , if found, can be assumed to always be pinned. [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is not intended to be used directly by user code")] - bool TryGetBytecode(int threadsX, int threadsY, int threadsZ, out ReadOnlySpan bytecode) + void LoadBytecode(ref TLoader loader, int threadsX, int threadsY, int threadsZ) + where TLoader : struct, IBytecodeLoader #if NET6_0_OR_GREATER { throw new NotImplementedException(); diff --git a/src/ComputeSharp/Properties/AssemblyInfo.cs b/src/ComputeSharp/Properties/AssemblyInfo.cs index bbec36ea..80e60132 100644 --- a/src/ComputeSharp/Properties/AssemblyInfo.cs +++ b/src/ComputeSharp/Properties/AssemblyInfo.cs @@ -2,6 +2,8 @@ [module: SkipLocalsInit] -[assembly: InternalsVisibleTo("ComputeSharp.Tests.Internals")] +[assembly: InternalsVisibleTo("ComputeSharp.Dynamic")] [assembly: InternalsVisibleTo("ComputeSharp.Uwp")] [assembly: InternalsVisibleTo("ComputeSharp.WinUI")] + +[assembly: InternalsVisibleTo("ComputeSharp.Tests.Internals")] \ No newline at end of file diff --git a/src/ComputeSharp/Shaders/Dispatching/ShaderBytecodeLoader.cs b/src/ComputeSharp/Shaders/Dispatching/ShaderBytecodeLoader.cs new file mode 100644 index 00000000..4f26a41f --- /dev/null +++ b/src/ComputeSharp/Shaders/Dispatching/ShaderBytecodeLoader.cs @@ -0,0 +1,65 @@ +using System; +using System.Runtime.CompilerServices; +using ComputeSharp.__Internals; +using Microsoft.Toolkit.Diagnostics; +using TerraFX.Interop.DirectX; +using ComputeSharp.Shaders.Translation.Models; + +#pragma warning disable CS0618 + +namespace ComputeSharp.Shaders.Dispatching; + +/// +/// A bytecode loader for compute shaders. +/// +internal struct ShaderBytecodeLoader : IBytecodeLoader +{ + /// + /// The current cached shader instance. + /// + private ICachedShader? cachedShader; + + /// + /// Gets the current cached shader instance. + /// + /// The current instance. + /// Thrown if the shader has not been initialized. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ICachedShader GetCachedShader() + { + if (this.cachedShader is not ICachedShader cachedShader) + { + return ThrowHelper.ThrowInvalidOperationException("The shader has not been initialized."); + } + + return cachedShader; + } + + /// + public unsafe void LoadDynamicBytecode(IntPtr handle) + { + if (this.cachedShader is not null) + { + ThrowHelper.ThrowInvalidOperationException("The shader has already been initialized."); + } + + if (handle == IntPtr.Zero) + { + ThrowHelper.ThrowNotSupportedException("Runtime shader compilation is not supported by the current configuration."); + } + + this.cachedShader = new ICachedShader.Dynamic((IDxcBlob*)handle); + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void LoadEmbeddedBytecode(ReadOnlySpan bytecode) + { + if (this.cachedShader is not null) + { + ThrowHelper.ThrowInvalidOperationException("The shader has already been initialized."); + } + + this.cachedShader = new ICachedShader.Embedded(bytecode); + } +} diff --git a/src/ComputeSharp/Shaders/Translation/__Internals/ArrayPoolStringBuilder.cs b/src/ComputeSharp/Shaders/Dispatching/__Internals/ArrayPoolStringBuilder.cs similarity index 100% rename from src/ComputeSharp/Shaders/Translation/__Internals/ArrayPoolStringBuilder.cs rename to src/ComputeSharp/Shaders/Dispatching/__Internals/ArrayPoolStringBuilder.cs diff --git a/src/ComputeSharp/Shaders/Translation/Models/ICachedShader.cs b/src/ComputeSharp/Shaders/Models/ICachedShader.cs similarity index 100% rename from src/ComputeSharp/Shaders/Translation/Models/ICachedShader.cs rename to src/ComputeSharp/Shaders/Models/ICachedShader.cs diff --git a/src/ComputeSharp/Shaders/Translation/Models/ShaderKey.cs b/src/ComputeSharp/Shaders/Models/ShaderKey.cs similarity index 100% rename from src/ComputeSharp/Shaders/Translation/Models/ShaderKey.cs rename to src/ComputeSharp/Shaders/Models/ShaderKey.cs diff --git a/src/ComputeSharp/Shaders/ShaderRunner{T}.cs b/src/ComputeSharp/Shaders/ShaderRunner{T}.cs index 0e926a5b..d7af2136 100644 --- a/src/ComputeSharp/Shaders/ShaderRunner{T}.cs +++ b/src/ComputeSharp/Shaders/ShaderRunner{T}.cs @@ -4,9 +4,6 @@ using System.Runtime.CompilerServices; using ComputeSharp.Graphics.Commands; using ComputeSharp.Shaders.Dispatching; using ComputeSharp.Shaders.Extensions; -#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT -using ComputeSharp.Shaders.Translation; -#endif using ComputeSharp.Shaders.Translation.Models; using ComputeSharp.__Internals; using Microsoft.Toolkit.Diagnostics; @@ -228,26 +225,11 @@ internal static class ShaderRunner [MethodImpl(MethodImplOptions.NoInlining)] private static unsafe void LoadShader(int threadsX, int threadsY, int threadsZ, ref T shader, out ICachedShader shaderData) { - if (Unsafe.NullRef().TryGetBytecode(threadsX, threadsY, threadsZ, out ReadOnlySpan bytecode)) - { - shaderData = new ICachedShader.Embedded(bytecode); - } - else - { -#if DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT - ThrowHelper.ThrowNotSupportedException("Runtime shader compilation is not supported by the current configuration."); + ShaderBytecodeLoader bytecodeLoader = default; - shaderData = null!; -#else - shader.BuildHlslString(out ArrayPoolStringBuilder builder, threadsX, threadsY, threadsZ); + shader.LoadBytecode(ref bytecodeLoader, threadsX, threadsY, threadsZ); - using ComPtr dxcBlobBytecode = ShaderCompiler.Instance.CompileShader(builder.WrittenSpan); - - builder.Dispose(); - - shaderData = new ICachedShader.Dynamic(dxcBlobBytecode.Get()); -#endif - } + shaderData = bytecodeLoader.GetCachedShader(); } /// diff --git a/src/TerraFX.Interop.Windows/DirectX/um/dxcapi/DirectX.cs b/src/TerraFX.Interop.Windows.Dynamic/DirectX.cs similarity index 84% rename from src/TerraFX.Interop.Windows/DirectX/um/dxcapi/DirectX.cs rename to src/TerraFX.Interop.Windows.Dynamic/DirectX.cs index 0448fa06..a408b343 100644 --- a/src/TerraFX.Interop.Windows/DirectX/um/dxcapi/DirectX.cs +++ b/src/TerraFX.Interop.Windows.Dynamic/DirectX.cs @@ -3,19 +3,16 @@ // Ported from um/dxcapi.h in the Windows SDK for Windows 10.0.20348.0 // Original source is Copyright © Microsoft. All rights reserved. Licensed under the University of Illinois Open Source License. -#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT - using System; using System.Runtime.InteropServices; using TerraFX.Interop.Windows; namespace TerraFX.Interop.DirectX { - internal static unsafe partial class DirectX + // This type is named DirectX2 to avoid naming conflicts in ComputeSharp.Dynamic + internal static unsafe partial class DirectX2 { [DllImport("dxcompiler", ExactSpelling = true)] public static extern HRESULT DxcCreateInstance([NativeTypeName("const IID &")] Guid* rclsid, [NativeTypeName("const IID &")] Guid* riid, [NativeTypeName("LPVOID *")] void** ppv); } } - -#endif diff --git a/src/TerraFX.Interop.Windows.Dynamic/TerraFX.Interop.Windows.Dynamic.projitems b/src/TerraFX.Interop.Windows.Dynamic/TerraFX.Interop.Windows.Dynamic.projitems new file mode 100644 index 00000000..de0ed572 --- /dev/null +++ b/src/TerraFX.Interop.Windows.Dynamic/TerraFX.Interop.Windows.Dynamic.projitems @@ -0,0 +1,14 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + 158f984d-cd96-4062-bd02-2268946031a0 + + + TerraFX.Interop.Windows.Dynamic + + + + + \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows.Dynamic/TerraFX.Interop.Windows.Dynamic.shproj b/src/TerraFX.Interop.Windows.Dynamic/TerraFX.Interop.Windows.Dynamic.shproj new file mode 100644 index 00000000..04db5f31 --- /dev/null +++ b/src/TerraFX.Interop.Windows.Dynamic/TerraFX.Interop.Windows.Dynamic.shproj @@ -0,0 +1,13 @@ + + + + 158f984d-cd96-4062-bd02-2268946031a0 + 14.0 + + + + + + + + diff --git a/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems b/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems index af64755d..69ea10d4 100644 --- a/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems +++ b/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems @@ -197,7 +197,6 @@ - diff --git a/tests/ComputeSharp.Tests.DisableDynamicCompilation/ComputeSharp.Tests.DisableDynamicCompilation.csproj b/tests/ComputeSharp.Tests.DisableDynamicCompilation/ComputeSharp.Tests.DisableDynamicCompilation.csproj index c38a80d2..6c45efbd 100644 --- a/tests/ComputeSharp.Tests.DisableDynamicCompilation/ComputeSharp.Tests.DisableDynamicCompilation.csproj +++ b/tests/ComputeSharp.Tests.DisableDynamicCompilation/ComputeSharp.Tests.DisableDynamicCompilation.csproj @@ -22,11 +22,6 @@ PrivateAssets="contentfiles;build" /> - - - $(DefineConstants);DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT - - diff --git a/tests/ComputeSharp.Tests.DisableDynamicCompilation/DispatchTests.cs b/tests/ComputeSharp.Tests.DisableDynamicCompilation/DispatchTests.cs index ca43ee2f..62549288 100644 --- a/tests/ComputeSharp.Tests.DisableDynamicCompilation/DispatchTests.cs +++ b/tests/ComputeSharp.Tests.DisableDynamicCompilation/DispatchTests.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using ComputeSharp.Interop; using ComputeSharp.Tests.Attributes; using ComputeSharp.Tests.Extensions; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -11,22 +10,10 @@ namespace ComputeSharp.Tests.DisableDynamicCompilation; [TestCategory("Dispatch")] public partial class DispatchTests { - private static readonly bool IsDynamicCompilationDisabled = -#if DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT - true; -#else - false; -#endif - [CombinatorialTestMethod] [AllDevices] public void ComputeShader_Test_Ok(Device device) { - if (!IsDynamicCompilationDisabled) - { - Assert.Inconclusive(); - } - float[] array = Enumerable.Range(0, 128).Select(static i => (float)i).ToArray(); using ReadWriteBuffer buffer = device.Get().AllocateReadWriteBuffer(array); @@ -48,11 +35,6 @@ public partial class DispatchTests [ExpectedException(typeof(NotSupportedException))] public void ComputeShader_Test_Fail(Device device) { - if (!IsDynamicCompilationDisabled) - { - Assert.Inconclusive(); - } - using ReadWriteBuffer buffer = device.Get().AllocateReadWriteBuffer(128); device.Get().For(128, 1, 1, 64, 1, 1, new ComputeShader(buffer, 2.0f)); @@ -76,11 +58,6 @@ public partial class DispatchTests [AllDevices] public void PixelShader_Test_Ok(Device device) { - if (!IsDynamicCompilationDisabled) - { - Assert.Inconclusive(); - } - using ReadWriteTexture2D texture = device.Get().AllocateReadWriteTexture2D(128, 128); device.Get().ForEach(texture, new PixelShader(0.3f, 0.6f)); @@ -120,28 +97,4 @@ public partial class DispatchTests return new(ThreadIds.Normalized.X, ThreadIds.Normalized.Y, b, a); } } - - [TestMethod] - [ExpectedException(typeof(NotSupportedException))] - public void ReflectionService_ComputeShader() - { - if (!IsDynamicCompilationDisabled) - { - Assert.Inconclusive(); - } - - ReflectionServices.GetShaderInfo(out _); - } - - [TestMethod] - [ExpectedException(typeof(NotSupportedException))] - public void ReflectionService_PixelShader() - { - if (!IsDynamicCompilationDisabled) - { - Assert.Inconclusive(); - } - - ReflectionServices.GetShaderInfo(out _); - } } diff --git a/tests/ComputeSharp.Tests.Internals/ComputeSharp.Tests.Internals.csproj b/tests/ComputeSharp.Tests.Internals/ComputeSharp.Tests.Internals.csproj index 190815c1..156a2712 100644 --- a/tests/ComputeSharp.Tests.Internals/ComputeSharp.Tests.Internals.csproj +++ b/tests/ComputeSharp.Tests.Internals/ComputeSharp.Tests.Internals.csproj @@ -4,12 +4,6 @@ net472;netcoreapp3.1;net6.0 false AnyCPU;x64;ARM64 - false - - - - - $(DefineConstants);DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT @@ -20,6 +14,7 @@ + bytecode)); - Assert.IsFalse(bytecode.Length > 0); - } - - [AutoConstructor] - internal readonly partial struct NonPrecompiledShader : IComputeShader - { - public readonly ReadWriteBuffer buffer; - public readonly float factor; - - /// - public void Execute() - { - buffer[ThreadIds.X] *= factor; - } - } - - [TestMethod] - public void ComputeShader_Test() - { - Assert.IsTrue(((IComputeShader)default(ComputeShader)).TryGetBytecode(32, 1, 1, out ReadOnlySpan bytecode)); - Assert.IsTrue(bytecode.Length > 0); - - Assert.IsFalse(((IComputeShader)default(ComputeShader)).TryGetBytecode(64, 1, 1, out bytecode)); - Assert.IsFalse(bytecode.Length > 0); - } - - [AutoConstructor] - [EmbeddedBytecode(32, 1, 1)] - internal readonly partial struct ComputeShader : IComputeShader - { - public readonly ReadWriteBuffer buffer; - public readonly float factor; - - /// - public void Execute() - { - buffer[ThreadIds.X] *= factor; - } - } - - [TestMethod] - public void PixelShader_Test() - { - Assert.IsTrue(((IPixelShader)default(PixelShader)).TryGetBytecode(8, 8, 1, out ReadOnlySpan bytecode)); - Assert.IsTrue(bytecode.Length > 0); - - Assert.IsFalse(((IPixelShader)default(PixelShader)).TryGetBytecode(32, 1, 1, out bytecode)); - Assert.IsFalse(bytecode.Length > 0); - } - - [AutoConstructor] - [EmbeddedBytecode(8, 8, 1)] - internal readonly partial struct PixelShader : IPixelShader - { - public readonly ReadWriteTexture2D buffer; - public readonly float factor; - - /// - public float4 Execute() - { - return buffer[ThreadIds.XY] * factor; - } - } -} diff --git a/tests/ComputeSharp.Tests.Internals/ShaderCompilerTests.cs b/tests/ComputeSharp.Tests.Internals/ShaderCompilerTests.cs index 0c10427f..e563da4a 100644 --- a/tests/ComputeSharp.Tests.Internals/ShaderCompilerTests.cs +++ b/tests/ComputeSharp.Tests.Internals/ShaderCompilerTests.cs @@ -1,6 +1,4 @@ -#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT - -using System; +using System; using ComputeSharp.Exceptions; using ComputeSharp.Shaders.Translation; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -47,5 +45,3 @@ public class ShaderCompilerTests using ComPtr dxcBlob = ShaderCompiler.Instance.CompileShader(faultyShader.AsSpan()); } } - -#endif diff --git a/tests/ComputeSharp.Tests.NativeLibrariesResolver/NativeLibrariesResolverTests.cs b/tests/ComputeSharp.Tests.NativeLibrariesResolver/NativeLibrariesResolverTests.cs index 64b123f5..c949a9f3 100644 --- a/tests/ComputeSharp.Tests.NativeLibrariesResolver/NativeLibrariesResolverTests.cs +++ b/tests/ComputeSharp.Tests.NativeLibrariesResolver/NativeLibrariesResolverTests.cs @@ -27,9 +27,11 @@ public class NativeLibrariesResolverTests SampleProjectDirectory = Path.Combine(path, "samples", "ComputeSharp.Sample.NuGet"); string packagingProjectPath = Path.Combine(path, "src", "ComputeSharp.Package", "ComputeSharp.Package.msbuildproj"); + string dynamicPackagingProjectPath = Path.Combine(path, "src", "ComputeSharp.Dynamic.Package", "ComputeSharp.Dynamic.Package.msbuildproj"); - // Run dotnet pack and on the packaging project, to ensure the local NuGet package is available + // Run dotnet pack and on the packaging projects, to ensure the local NuGet packages are available Process.Start("dotnet", $"pack {packagingProjectPath} -c Release").WaitForExit(); + Process.Start("dotnet", $"pack {dynamicPackagingProjectPath} -c Release").WaitForExit(); } /// diff --git a/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs index 4cb19f28..bce97fe5 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs @@ -35,7 +35,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0001"); + VerifyGeneratedDiagnostics(source, "CMPS0001", "CMPS0047"); } [TestMethod] @@ -60,7 +60,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0001"); + VerifyGeneratedDiagnostics(source, "CMPS0001", "CMPS0047"); } [TestMethod] @@ -88,7 +88,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0002"); + VerifyGeneratedDiagnostics(source, "CMPS0002", "CMPS0047"); } [TestMethod] @@ -116,7 +116,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0003"); + VerifyGeneratedDiagnostics(source, "CMPS0003", "CMPS0047"); } [TestMethod] @@ -142,7 +142,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0004"); + VerifyGeneratedDiagnostics(source, "CMPS0004", "CMPS0047"); } [TestMethod] @@ -159,7 +159,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0005"); + VerifyGeneratedDiagnostics(source, "CMPS0005", "CMPS0047"); } [TestMethod] @@ -194,7 +194,7 @@ public class DiagnosticsTests }} }}"; - VerifyGeneratedDiagnostics(source, diagnosticsId); + VerifyGeneratedDiagnostics(source, diagnosticsId, "CMPS0047"); } [TestMethod] @@ -226,7 +226,7 @@ public class DiagnosticsTests }} }}"; - VerifyGeneratedDiagnostics(source, diagnosticsId); + VerifyGeneratedDiagnostics(source, diagnosticsId, "CMPS0047"); } [TestMethod] @@ -256,7 +256,7 @@ public class DiagnosticsTests }} }}"; - VerifyGeneratedDiagnostics(source, "CMPS0006"); + VerifyGeneratedDiagnostics(source, "CMPS0006", "CMPS0047"); } [TestMethod] @@ -283,7 +283,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0010", "CMPS0031"); + VerifyGeneratedDiagnostics(source, "CMPS0010", "CMPS0031", "CMPS0047"); } [TestMethod] @@ -310,7 +310,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0010", "CMPS0031"); + VerifyGeneratedDiagnostics(source, "CMPS0010", "CMPS0031", "CMPS0047"); } [TestMethod] @@ -337,7 +337,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0011", "CMPS0031"); + VerifyGeneratedDiagnostics(source, "CMPS0011", "CMPS0031", "CMPS0047"); } [TestMethod] @@ -366,7 +366,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0012"); + VerifyGeneratedDiagnostics(source, "CMPS0012", "CMPS0047"); } [TestMethod] @@ -392,7 +392,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0012"); + VerifyGeneratedDiagnostics(source, "CMPS0012", "CMPS0047"); } [TestMethod] @@ -419,7 +419,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0012", "CMPS0013"); + VerifyGeneratedDiagnostics(source, "CMPS0012", "CMPS0013", "CMPS0047"); } [TestMethod] @@ -448,7 +448,7 @@ public class DiagnosticsTests }} }}"; - VerifyGeneratedDiagnostics(source, "CMPS0014"); + VerifyGeneratedDiagnostics(source, "CMPS0014", "CMPS0047"); } [TestMethod] @@ -480,7 +480,7 @@ public class DiagnosticsTests }} }}"; - VerifyGeneratedDiagnostics(source, "CMPS0015"); + VerifyGeneratedDiagnostics(source, "CMPS0015", "CMPS0047"); } [TestMethod] @@ -512,7 +512,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0016", "CMPS0032"); + VerifyGeneratedDiagnostics(source, "CMPS0016", "CMPS0032", "CMPS0047"); } [TestMethod] @@ -544,7 +544,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0017"); + VerifyGeneratedDiagnostics(source, "CMPS0017", "CMPS0047"); } [TestMethod] @@ -573,7 +573,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0018"); + VerifyGeneratedDiagnostics(source, "CMPS0018", "CMPS0047"); } [TestMethod] @@ -603,7 +603,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0019"); + VerifyGeneratedDiagnostics(source, "CMPS0019", "CMPS0047"); } [TestMethod] @@ -633,7 +633,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0020"); + VerifyGeneratedDiagnostics(source, "CMPS0020", "CMPS0047"); } [TestMethod] @@ -665,7 +665,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0021"); + VerifyGeneratedDiagnostics(source, "CMPS0021", "CMPS0047"); } [TestMethod] @@ -695,7 +695,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0022"); + VerifyGeneratedDiagnostics(source, "CMPS0022", "CMPS0047"); } [TestMethod] @@ -727,7 +727,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0023"); + VerifyGeneratedDiagnostics(source, "CMPS0023", "CMPS0047"); } [TestMethod] @@ -754,7 +754,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0024"); + VerifyGeneratedDiagnostics(source, "CMPS0024", "CMPS0047"); } [TestMethod] @@ -781,7 +781,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0032", "CMPS0025"); + VerifyGeneratedDiagnostics(source, "CMPS0032", "CMPS0025", "CMPS0047"); } [TestMethod] @@ -808,7 +808,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0026"); + VerifyGeneratedDiagnostics(source, "CMPS0026", "CMPS0047"); } [TestMethod] @@ -840,7 +840,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0027"); + VerifyGeneratedDiagnostics(source, "CMPS0027", "CMPS0047"); } [TestMethod] @@ -867,7 +867,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0028"); + VerifyGeneratedDiagnostics(source, "CMPS0028", "CMPS0047"); } [TestMethod] @@ -894,7 +894,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0029", "CMPS0031"); + VerifyGeneratedDiagnostics(source, "CMPS0029", "CMPS0031", "CMPS0047"); } [TestMethod] @@ -923,7 +923,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0029", "CMPS0031"); + VerifyGeneratedDiagnostics(source, "CMPS0029", "CMPS0031", "CMPS0047"); } [TestMethod] @@ -956,7 +956,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0030"); + VerifyGeneratedDiagnostics(source, "CMPS0030", "CMPS0047"); } [TestMethod] @@ -983,7 +983,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0031"); + VerifyGeneratedDiagnostics(source, "CMPS0031", "CMPS0047"); } [TestMethod] @@ -1010,7 +1010,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0032"); + VerifyGeneratedDiagnostics(source, "CMPS0032", "CMPS0047"); } [TestMethod] @@ -1037,7 +1037,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0033"); + VerifyGeneratedDiagnostics(source, "CMPS0033", "CMPS0047"); } [TestMethod] @@ -1066,7 +1066,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0034"); + VerifyGeneratedDiagnostics(source, "CMPS0034", "CMPS0047"); } [TestMethod] @@ -1095,7 +1095,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0035"); + VerifyGeneratedDiagnostics(source, "CMPS0035", "CMPS0047"); } [TestMethod] @@ -1124,7 +1124,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0035"); + VerifyGeneratedDiagnostics(source, "CMPS0035", "CMPS0047"); } [TestMethod] @@ -1151,7 +1151,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0036"); + VerifyGeneratedDiagnostics(source, "CMPS0036", "CMPS0047"); } [TestMethod] @@ -1194,7 +1194,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0037"); + VerifyGeneratedDiagnostics(source, "CMPS0037", "CMPS0047"); } [TestMethod] @@ -1222,7 +1222,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0038"); + VerifyGeneratedDiagnostics(source, "CMPS0038", "CMPS0047"); } [TestMethod] @@ -1250,7 +1250,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0040"); + VerifyGeneratedDiagnostics(source, "CMPS0040", "CMPS0047"); } [TestMethod] @@ -1281,7 +1281,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0040"); + VerifyGeneratedDiagnostics(source, "CMPS0040", "CMPS0047"); } [TestMethod] @@ -1309,7 +1309,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0040"); + VerifyGeneratedDiagnostics(source, "CMPS0040", "CMPS0047"); } [TestMethod] @@ -1337,7 +1337,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0040"); + VerifyGeneratedDiagnostics(source, "CMPS0040", "CMPS0047"); } [TestMethod] @@ -1371,7 +1371,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0041"); + VerifyGeneratedDiagnostics(source, "CMPS0041", "CMPS0047"); } [TestMethod] @@ -1396,7 +1396,7 @@ public class DiagnosticsTests } }"; - VerifyGeneratedDiagnostics(source, "CMPS0042"); + VerifyGeneratedDiagnostics(source, "CMPS0042", "CMPS0047"); } [TestMethod] diff --git a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj index d4c166a1..e8d85f91 100644 --- a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj +++ b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj @@ -16,6 +16,7 @@ +