From 13055024659e513d4741df78823e9d9073925ea2 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 13 Dec 2021 20:31:58 +0100 Subject: [PATCH 01/26] Add ComputeSharp.Dynamic project --- ComputeSharp.sln | 14 ++++ .../ComputeSharp.Dynamic.csproj | 71 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 1c78842e..185c9468 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -70,6 +70,8 @@ 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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.Dynamic", "src\ComputeSharp.Dynamic\ComputeSharp.Dynamic.csproj", "{76C66257-FDAA-47AB-85E7-EF757EAB10C0}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution samples\ComputeSharp.SwapChain.Core.Shared\ComputeSharp.SwapChain.Core.Shared.projitems*{0071701e-b9c5-4098-be5f-ef556c4553c6}*SharedItemsImports = 5 @@ -317,6 +319,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|Any CPU + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Debug|ARM64.Build.0 = Debug|Any CPU + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Debug|x64.ActiveCfg = Debug|Any CPU + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Debug|x64.Build.0 = Debug|Any CPU + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Release|Any CPU.Build.0 = Release|Any CPU + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Release|ARM64.ActiveCfg = Release|Any CPU + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Release|ARM64.Build.0 = Release|Any CPU + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Release|x64.ActiveCfg = Release|Any CPU + {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj b/src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj new file mode 100644 index 00000000..acc4d503 --- /dev/null +++ b/src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj @@ -0,0 +1,71 @@ + + + netstandard2.0;net6.0 + bin\Release + ComputeSharp.Dynamic.xml + ComputeSharp.Dynamic + AnyCPU;x64;ARM64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 5f8196716b14581b508803193f76975903760df3 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 13 Dec 2021 20:33:55 +0100 Subject: [PATCH 02/26] Move native libraries to ComputeSharp.Dynamic --- ComputeSharp.sln | 50 ++++++------ .../Libraries/arm64/dxcompiler.dll | Bin .../Libraries/arm64/dxil.dll | Bin .../Libraries/x64/dxcompiler.dll | Bin .../Libraries/x64/dxil.dll | Bin src/ComputeSharp/ComputeSharp.csproj | 72 ------------------ 6 files changed, 25 insertions(+), 97 deletions(-) rename src/{ComputeSharp => ComputeSharp.Dynamic}/Libraries/arm64/dxcompiler.dll (100%) rename src/{ComputeSharp => ComputeSharp.Dynamic}/Libraries/arm64/dxil.dll (100%) rename src/{ComputeSharp => ComputeSharp.Dynamic}/Libraries/x64/dxcompiler.dll (100%) rename src/{ComputeSharp => ComputeSharp.Dynamic}/Libraries/x64/dxil.dll (100%) diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 185c9468..7f34c92f 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -70,7 +70,7 @@ 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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.Dynamic", "src\ComputeSharp.Dynamic\ComputeSharp.Dynamic.csproj", "{76C66257-FDAA-47AB-85E7-EF757EAB10C0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Dynamic", "src\ComputeSharp.Dynamic\ComputeSharp.Dynamic.csproj", "{76C66257-FDAA-47AB-85E7-EF757EAB10C0}" EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution @@ -103,18 +103,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 @@ -319,18 +319,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|Any CPU - {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Debug|ARM64.ActiveCfg = Debug|Any CPU - {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Debug|ARM64.Build.0 = Debug|Any CPU - {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Debug|x64.ActiveCfg = Debug|Any CPU - {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Debug|x64.Build.0 = Debug|Any CPU - {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Release|Any CPU.Build.0 = Release|Any CPU - {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Release|ARM64.ActiveCfg = Release|Any CPU - {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Release|ARM64.Build.0 = Release|Any CPU - {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.Release|x64.ActiveCfg = Release|Any CPU - {76C66257-FDAA-47AB-85E7-EF757EAB10C0}.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 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/ComputeSharp.csproj b/src/ComputeSharp/ComputeSharp.csproj index e97405a8..b25ccef4 100644 --- a/src/ComputeSharp/ComputeSharp.csproj +++ b/src/ComputeSharp/ComputeSharp.csproj @@ -4,8 +4,6 @@ bin\Release ComputeSharp.xml ComputeSharp - AnyCPU;x64;ARM64 - false @@ -38,76 +36,6 @@ $(NoWarn);CS1591 - - - $(DefineConstants);DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 3bbf7754ba92d4998143cc360a55dcccc2e3fc27 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 13 Dec 2021 20:46:31 +0100 Subject: [PATCH 03/26] Move dynamic shader types to ComputeSharp.Dynamic --- .../Attributes/ShaderMethodAttribute.cs | 0 .../__Internals/ShaderMethodSourceAttribute.HlslGeneration.cs | 0 .../Attributes/__Internals/ShaderMethodSourceAttribute.cs | 0 src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj | 4 ++++ .../Shaders/Exceptions/HlslCompilationException.cs | 0 .../Shaders/Interop/ReflectionServices.cs | 0 .../Shaders/Interop/ShaderInfo.cs | 0 .../Shaders/Translation/ShaderCompiler.LibraryLoading.cs | 0 .../Shaders/Translation/ShaderCompiler.cs | 0 .../Shaders/Translation/__Internals/ArrayPoolStringBuilder.cs | 0 src/ComputeSharp/Properties/AssemblyInfo.cs | 4 +++- .../Shaders/{Translation => }/Models/ICachedShader.cs | 0 .../Shaders/{Translation => }/Models/ShaderKey.cs | 0 13 files changed, 7 insertions(+), 1 deletion(-) rename src/{ComputeSharp/Core => ComputeSharp.Dynamic}/Attributes/ShaderMethodAttribute.cs (100%) rename src/{ComputeSharp/Core => ComputeSharp.Dynamic}/Attributes/__Internals/ShaderMethodSourceAttribute.HlslGeneration.cs (100%) rename src/{ComputeSharp/Core => ComputeSharp.Dynamic}/Attributes/__Internals/ShaderMethodSourceAttribute.cs (100%) rename src/{ComputeSharp => ComputeSharp.Dynamic}/Shaders/Exceptions/HlslCompilationException.cs (100%) rename src/{ComputeSharp => ComputeSharp.Dynamic}/Shaders/Interop/ReflectionServices.cs (100%) rename src/{ComputeSharp => ComputeSharp.Dynamic}/Shaders/Interop/ShaderInfo.cs (100%) rename src/{ComputeSharp => ComputeSharp.Dynamic}/Shaders/Translation/ShaderCompiler.LibraryLoading.cs (100%) rename src/{ComputeSharp => ComputeSharp.Dynamic}/Shaders/Translation/ShaderCompiler.cs (100%) rename src/{ComputeSharp => ComputeSharp.Dynamic}/Shaders/Translation/__Internals/ArrayPoolStringBuilder.cs (100%) rename src/ComputeSharp/Shaders/{Translation => }/Models/ICachedShader.cs (100%) rename src/ComputeSharp/Shaders/{Translation => }/Models/ShaderKey.cs (100%) 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 index acc4d503..d0b11a00 100644 --- a/src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj +++ b/src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj @@ -68,4 +68,8 @@ + + + + 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 100% rename from src/ComputeSharp/Shaders/Interop/ReflectionServices.cs rename to src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs 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 100% rename from src/ComputeSharp/Shaders/Translation/ShaderCompiler.LibraryLoading.cs rename to src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.LibraryLoading.cs diff --git a/src/ComputeSharp/Shaders/Translation/ShaderCompiler.cs b/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs similarity index 100% rename from src/ComputeSharp/Shaders/Translation/ShaderCompiler.cs rename to src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs diff --git a/src/ComputeSharp/Shaders/Translation/__Internals/ArrayPoolStringBuilder.cs b/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ArrayPoolStringBuilder.cs similarity index 100% rename from src/ComputeSharp/Shaders/Translation/__Internals/ArrayPoolStringBuilder.cs rename to src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ArrayPoolStringBuilder.cs 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/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 From f9a4477b692505fd4ea8b5efcf41ead9c8bbcd56 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 13 Dec 2021 22:32:52 +0100 Subject: [PATCH 04/26] Move DxcCreateInstance to standalone shared project --- ComputeSharp.sln | 4 ++++ .../DirectX.cs | 4 ---- .../TerraFX.Interop.Windows.Dynamic.projitems | 14 ++++++++++++++ .../TerraFX.Interop.Windows.Dynamic.shproj | 13 +++++++++++++ .../TerraFX.Interop.Windows.projitems | 1 - 5 files changed, 31 insertions(+), 5 deletions(-) rename src/{TerraFX.Interop.Windows/DirectX/um/dxcapi => TerraFX.Interop.Windows.Dynamic}/DirectX.cs (93%) create mode 100644 src/TerraFX.Interop.Windows.Dynamic/TerraFX.Interop.Windows.Dynamic.projitems create mode 100644 src/TerraFX.Interop.Windows.Dynamic/TerraFX.Interop.Windows.Dynamic.shproj diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 7f34c92f..579c65bc 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -72,12 +72,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Tests.DisableD 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 @@ -354,6 +357,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/src/TerraFX.Interop.Windows/DirectX/um/dxcapi/DirectX.cs b/src/TerraFX.Interop.Windows.Dynamic/DirectX.cs similarity index 93% rename from src/TerraFX.Interop.Windows/DirectX/um/dxcapi/DirectX.cs rename to src/TerraFX.Interop.Windows.Dynamic/DirectX.cs index 0448fa06..0963b55b 100644 --- a/src/TerraFX.Interop.Windows/DirectX/um/dxcapi/DirectX.cs +++ b/src/TerraFX.Interop.Windows.Dynamic/DirectX.cs @@ -3,8 +3,6 @@ // 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; @@ -17,5 +15,3 @@ namespace TerraFX.Interop.DirectX 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 @@ - From b532a9cdfbd7b6e513a358f32aaca7070e25fa18 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 13 Dec 2021 22:33:12 +0100 Subject: [PATCH 05/26] Restructure ComputeSharp to support dynamic plugin --- .../Interfaces/__Internals/IBytecodeLoader.cs | 26 ++++++++ .../Core/Interfaces/__Internals/IShader.cs | 28 ++------- .../Dispatching/ShaderBytecodeLoader.cs | 60 +++++++++++++++++++ src/ComputeSharp/Shaders/ShaderRunner{T}.cs | 24 +------- 4 files changed, 94 insertions(+), 44 deletions(-) create mode 100644 src/ComputeSharp/Core/Interfaces/__Internals/IBytecodeLoader.cs create mode 100644 src/ComputeSharp/Shaders/Dispatching/ShaderBytecodeLoader.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..40989e59 100644 --- a/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs +++ b/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs @@ -65,35 +65,17 @@ public interface IShader #endif /// - /// Builds the HLSL source code for the current shader instance. + /// Loads the bytecode for the current shader. /// - /// The resulting instance containing the HLSL source. + /// 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. [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method is not intended to be called directly by user code")] - void BuildHlslString(out ArrayPoolStringBuilder builder, int threadsX, int threadsY, int threadsZ) -#if NET6_0_OR_GREATER - { - throw new NotImplementedException(); - } -#else - ; -#endif - - /// - /// Tries to retrieve the precompiled bytecode for the current shader. - /// - /// 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 TBytecodeLoader loader, int threadsX, int threadsY, int threadsZ) + where TBytecodeLoader : struct, IBytecodeLoader #if NET6_0_OR_GREATER { throw new NotImplementedException(); diff --git a/src/ComputeSharp/Shaders/Dispatching/ShaderBytecodeLoader.cs b/src/ComputeSharp/Shaders/Dispatching/ShaderBytecodeLoader.cs new file mode 100644 index 00000000..68971f12 --- /dev/null +++ b/src/ComputeSharp/Shaders/Dispatching/ShaderBytecodeLoader.cs @@ -0,0 +1,60 @@ +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"); + } + + 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/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(); } /// From d17c9ab0048c6e2ccb76b71b36eb13d6759ecc31 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 13 Dec 2021 23:59:10 +0100 Subject: [PATCH 06/26] Fix build errors in ComputeSharp.Dynamic --- ComputeSharp.sln | 1 + .../ComputeSharp.Dynamic.csproj | 14 ++++++++++---- .../Shaders/Interop/ReflectionServices.cs | 15 ++------------- .../ShaderCompiler.LibraryLoading.cs | 2 +- .../Shaders/Translation/ShaderCompiler.cs | 9 ++++----- src/ComputeSharp/ComputeSharp.csproj | 12 ++++++------ .../Core/Interfaces/__Internals/IShader.cs | 18 ++++++++++++++++++ .../__Internals/ArrayPoolStringBuilder.cs | 0 src/TerraFX.Interop.Windows.Dynamic/DirectX.cs | 3 ++- 9 files changed, 44 insertions(+), 30 deletions(-) rename src/{ComputeSharp.Dynamic/Shaders/Translation => ComputeSharp/Shaders/Dispatching}/__Internals/ArrayPoolStringBuilder.cs (100%) diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 579c65bc..c3545c64 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -86,6 +86,7 @@ Global 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 diff --git a/src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj b/src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj index d0b11a00..ec15565d 100644 --- a/src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj +++ b/src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj @@ -7,6 +7,16 @@ AnyCPU;x64;ARM64 + + + + + + + + - + - + @@ -234,4 +230,8 @@ UIntMxN.g.cs + + + + diff --git a/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs b/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs index 40989e59..dc4495b0 100644 --- a/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs +++ b/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs @@ -64,6 +64,24 @@ public interface IShader ; #endif + /// + /// Builds the HLSL source code for the current shader instance. + /// + /// The resulting instance containing the HLSL source. + /// 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. + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be called directly by user code")] + void BuildHlslString(out ArrayPoolStringBuilder builder, int threadsX, int threadsY, int threadsZ) +#if NET6_0_OR_GREATER + { + throw new NotImplementedException(); + } +#else + ; +#endif + /// /// Loads the bytecode for the current shader. /// diff --git a/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ArrayPoolStringBuilder.cs b/src/ComputeSharp/Shaders/Dispatching/__Internals/ArrayPoolStringBuilder.cs similarity index 100% rename from src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ArrayPoolStringBuilder.cs rename to src/ComputeSharp/Shaders/Dispatching/__Internals/ArrayPoolStringBuilder.cs diff --git a/src/TerraFX.Interop.Windows.Dynamic/DirectX.cs b/src/TerraFX.Interop.Windows.Dynamic/DirectX.cs index 0963b55b..a408b343 100644 --- a/src/TerraFX.Interop.Windows.Dynamic/DirectX.cs +++ b/src/TerraFX.Interop.Windows.Dynamic/DirectX.cs @@ -9,7 +9,8 @@ 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); From 405f92d48115c00886eec85dc6485fe770869d66 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 14 Dec 2021 00:07:15 +0100 Subject: [PATCH 07/26] Fix build issues in source generator --- ComputeSharp.sln | 1 + .../ComputeSharp.SourceGenerators.csproj | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ComputeSharp.sln b/ComputeSharp.sln index c3545c64..a9db8b7e 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -93,6 +93,7 @@ Global 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 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 @@ + From 80044d69fd8e29fed95c1812e870ca1735b9e65e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 14 Dec 2021 01:03:04 +0100 Subject: [PATCH 08/26] Update source generators to support dynamic plugin --- .../Translation/__Internals/ShaderCompiler.cs | 25 ++ ...enerator.CreateGetBytecodeMethod.Syntax.cs | 301 ++++++++++++++++++ ...haderGenerator.CreateGetBytecodeMethod.cs} | 0 ...rator.CreateTryGetBytecodeMethod.Syntax.cs | 191 ----------- .../IShaderGenerator.cs | 13 +- 5 files changed, 335 insertions(+), 195 deletions(-) create mode 100644 src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs create mode 100644 src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetBytecodeMethod.Syntax.cs rename src/ComputeSharp.SourceGenerators/{IShaderGenerator.CreateTryGetBytecodeMethod.cs => IShaderGenerator.CreateGetBytecodeMethod.cs} (100%) delete mode 100644 src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateTryGetBytecodeMethod.Syntax.cs 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..fc51c97c --- /dev/null +++ b/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs @@ -0,0 +1,25 @@ +using System; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; + +namespace ComputeSharp.__Internals; + +/// +/// A that uses the DXC APIs to compile compute shaders. +/// +public static class ShaderCompiler +{ + /// + /// Compiles a new HLSL shader from the input source code. + /// + /// The HLSL source code to compile. + /// The bytecode for the compiled shader. + public static unsafe IntPtr CompileShader(ReadOnlySpan source) + { + using ComPtr shader = Shaders.Translation.ShaderCompiler.Instance.CompileShader(source); + + _ = shader.Get()->AddRef(); + + return (IntPtr)shader.Get(); + } +} diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetBytecodeMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetBytecodeMethod.Syntax.cs new file mode 100644 index 00000000..bb0a41ce --- /dev/null +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetBytecodeMethod.Syntax.cs @@ -0,0 +1,301 @@ +using System; +using System.Collections.Immutable; +using System.Diagnostics.Contracts; +using System.Linq; +using ComputeSharp.__Internals; +using ComputeSharp.SourceGenerators.Models; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; + +#pragma warning disable CS0618 + +namespace ComputeSharp.SourceGenerators; + +/// +public sealed partial class IShaderGenerator +{ + /// + private static partial class TryGetBytecode + { + /// + /// 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, bool supportsDynamicShaders, out Func fixup) + { + BlockSyntax block = GetShaderBytecodeBody(bytecodeInfo, supportsDynamicShaders, out string? bytecodeLiterals); + + if (bytecodeLiterals is not null) + { + fixup = tree => tree.ToFullString().Replace("__EMBEDDED_SHADER_BYTECODE", bytecodeLiterals); + } + else + { + fixup = static tree => tree.ToFullString(); + } + + // This code produces a method declaration as follows: + // + // readonly void global::ComputeSharp.__Internals.IShader.GetBytecode(ref TBytecodeLoader loader, int threadsX, int threadsY, int threadsZ) + // { + // + // } + return + MethodDeclaration( + PredefinedType(Token(SyntaxKind.VoidKeyword)), + Identifier("GetBytecode")) + .WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.__Internals.{nameof(IShader)}"))) + .AddModifiers(Token(SyntaxKind.ReadOnlyKeyword)) + .AddTypeParameterListParameters(TypeParameter(Identifier("TBytecodeLoader"))) + .AddParameterListParameters( + Parameter(Identifier("loader")) + .AddModifiers(Token(SyntaxKind.RefKeyword)) + .WithType(IdentifierName("TBytecodeLoader")), + Parameter(Identifier("threadsX")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))), + Parameter(Identifier("threadsY")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))), + Parameter(Identifier("threadsZ")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword)))) + .WithBody(block); + } + + /// + /// 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, bool supportsDynamicShaders, out string? bytecodeLiterals) + { + if (bytecodeInfo.Bytecode.IsEmpty) + { + bytecodeLiterals = null; + + if (supportsDynamicShaders) + { + // Return the dynamic compilation path + return Block(GetDynamicCompilationStatements()); + } + else + { + // Faulting path + return Block(GetDynamicCompilationFaultingBlock()); + } + } + + bytecodeLiterals = BuildShaderBytecodeExpressionString(bytecodeInfo.Bytecode.AsSpan()); + + // This code produces a branch as follows: + // + // if (threadsX == && threadsY == && threadsZ == ) + // { + // global::System.ReadOnlySpan bytecode = new byte[] { __EMBEDDED_SHADER_BYTECODE }; + // loader.LoadEmbeddedBytecode(bytecode); + // } + // + // 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. + IfStatementSyntax embeddedBranch = + IfStatement( + 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)))), + 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")))))))), + 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).AddStatements(GetDynamicCompilationStatements().ToArray()); + } + + // If there is no dynamic shader support, add the faulting path after the branch + return Block(embeddedBranch).AddStatements(GetDynamicCompilationFaultingBlock()); + } + + /// + /// The cached tree of dynamic statements. + /// + private static ImmutableArray dynamicStatements; + + /// + /// Returns a sequence of instances to create a new dynamic shader. + /// + /// A sequence of instances to create a new dynamic shader. + private static ImmutableArray GetDynamicCompilationStatements() + { + if (dynamicStatements.IsEmpty) + { + // This code produces a method declaration as follows: + // + // BuildHlslString(out global::ComputeSharp.__Internals.ArrayPoolStringBuilder builder, threadsX, threadsY, threadsZ); + // global::System.IntPtr bytecode = ShaderCompiler.CompileShader(builder.WrittenSpan); + // builder.Dispose(); + // loader.LoadDynamicBytecode(bytecode); + dynamicStatements = ImmutableArray.Create( + ExpressionStatement( + InvocationExpression(IdentifierName("BuildHlslString")) + .AddArgumentListArguments( + Argument(DeclarationExpression( + IdentifierName("global::ComputeSharp.__Internals.ArrayPoolStringBuilder"), + SingleVariableDesignation(Identifier("builder")))) + .WithRefOrOutKeyword(Token(SyntaxKind.OutKeyword)), + Argument(IdentifierName("threadsX")), + Argument(IdentifierName("threadsY")), + Argument(IdentifierName("threadsZ")))), + LocalDeclarationStatement( + VariableDeclaration(IdentifierName("global::System.IntPtr")) + .AddVariables(VariableDeclarator(Identifier("bytecode")) + .WithInitializer( + EqualsValueClause( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("ShaderCompiler"), + IdentifierName("CompileShader"))) + .AddArgumentListArguments( + Argument( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("builder"), + IdentifierName("WrittenSpan")))))))), + ExpressionStatement( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("builder"), + IdentifierName("Dispose")))), + ExpressionStatement( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("loader"), + IdentifierName("LoadDynamicBytecode"))) + .AddArgumentListArguments(Argument(IdentifierName("bytecode"))))); + } + + return dynamicStatements; + } + + /// + /// 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() + { + if (dynamicFaultStatement is null) + { + // This code produces a faulting call as follows: + // + // loader.LoadDynamicBytecode(global::System.IntPtr.Zero); + return + ExpressionStatement( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("loader"), + IdentifierName("LoadDynamicBytecode"))) + .AddArgumentListArguments( + Argument( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("global::System.IntPtr"), + IdentifierName("IntPtr")), + IdentifierName("Zero"))))); + } + + return dynamicFaultStatement; + } + + /// + /// A mapping of precomputed literals for all values. + /// + private static readonly string[] formattedBytes = + { + "0x00", "0x01", "0x02", "0x03", "0x04", "0x05", "0x06", "0x07", "0x08", "0x09", "0x0A", "0x0B", "0x0C", "0x0D", "0x0E", "0x0F", + "0x10", "0x11", "0x12", "0x13", "0x14", "0x15", "0x16", "0x17", "0x18", "0x19", "0x1A", "0x1B", "0x1C", "0x1D", "0x1E", "0x1F", + "0x20", "0x21", "0x22", "0x23", "0x24", "0x25", "0x26", "0x27", "0x28", "0x29", "0x2A", "0x2B", "0x2C", "0x2D", "0x2E", "0x2F", + "0x30", "0x31", "0x32", "0x33", "0x34", "0x35", "0x36", "0x37", "0x38", "0x39", "0x3A", "0x3B", "0x3C", "0x3D", "0x3E", "0x3F", + "0x40", "0x41", "0x42", "0x43", "0x44", "0x45", "0x46", "0x47", "0x48", "0x49", "0x4A", "0x4B", "0x4C", "0x4D", "0x4E", "0x4F", + "0x50", "0x51", "0x52", "0x53", "0x54", "0x55", "0x56", "0x57", "0x58", "0x59", "0x5A", "0x5B", "0x5C", "0x5D", "0x5E", "0x5F", + "0x60", "0x61", "0x62", "0x63", "0x64", "0x65", "0x66", "0x67", "0x68", "0x69", "0x6A", "0x6B", "0x6C", "0x6D", "0x6E", "0x6F", + "0x70", "0x71", "0x72", "0x73", "0x74", "0x75", "0x76", "0x77", "0x78", "0x79", "0x7A", "0x7B", "0x7C", "0x7D", "0x7E", "0x7F", + "0x80", "0x81", "0x82", "0x83", "0x84", "0x85", "0x86", "0x87", "0x88", "0x89", "0x8A", "0x8B", "0x8C", "0x8D", "0x8E", "0x8F", + "0x90", "0x91", "0x92", "0x93", "0x94", "0x95", "0x96", "0x97", "0x98", "0x99", "0x9A", "0x9B", "0x9C", "0x9D", "0x9E", "0x9F", + "0xA0", "0xA1", "0xA2", "0xA3", "0xA4", "0xA5", "0xA6", "0xA7", "0xA8", "0xA9", "0xAA", "0xAB", "0xAC", "0xAD", "0xAE", "0xAF", + "0xB0", "0xB1", "0xB2", "0xB3", "0xB4", "0xB5", "0xB6", "0xB7", "0xB8", "0xB9", "0xBA", "0xBB", "0xBC", "0xBD", "0xBE", "0xBF", + "0xC0", "0xC1", "0xC2", "0xC3", "0xC4", "0xC5", "0xC6", "0xC7", "0xC8", "0xC9", "0xCA", "0xCB", "0xCC", "0xCD", "0xCE", "0xCF", + "0xD0", "0xD1", "0xD2", "0xD3", "0xD4", "0xD5", "0xD6", "0xD7", "0xD8", "0xD9", "0xDA", "0xDB", "0xDC", "0xDD", "0xDE", "0xDF", + "0xE0", "0xE1", "0xE2", "0xE3", "0xE4", "0xE5", "0xE6", "0xE7", "0xE8", "0xE9", "0xEA", "0xEB", "0xEC", "0xED", "0xEE", "0xEF", + "0xF0", "0xF1", "0xF2", "0xF3", "0xF4", "0xF5", "0xF6", "0xF7", "0xF8", "0xF9", "0xFA", "0xFB", "0xFC", "0xFD", "0xFE", "0xFF" + }; + + /// + /// Creates a formatted expression to initialize a with a given shader data. + /// + /// The input shader bytecode to serialize. + /// A formatted with the serialized data. + private static string BuildShaderBytecodeExpressionString(ReadOnlySpan bytecode) + { + //The estimation is 4 characters per byte (up to "255" in hex), plus ", " to separate sequential values + using ArrayPoolStringBuilder builder = ArrayPoolStringBuilder.Create(bytecode.Length * 6); + + builder.Append(formattedBytes[bytecode[0]]); + + foreach (byte b in bytecode.Slice(1)) + { + builder.Append(", "); + builder.Append(formattedBytes[b]); + } + + return builder.WrittenSpan.ToString(); + } + } +} diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateTryGetBytecodeMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetBytecodeMethod.cs similarity index 100% rename from src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateTryGetBytecodeMethod.cs rename to src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetBytecodeMethod.cs diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateTryGetBytecodeMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateTryGetBytecodeMethod.Syntax.cs deleted file mode 100644 index ce084c18..00000000 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateTryGetBytecodeMethod.Syntax.cs +++ /dev/null @@ -1,191 +0,0 @@ -using System; -using System.Diagnostics.Contracts; -using ComputeSharp.__Internals; -using ComputeSharp.SourceGenerators.Models; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; - -#pragma warning disable CS0618 - -namespace ComputeSharp.SourceGenerators; - -/// -public sealed partial class IShaderGenerator -{ - /// - private static partial class TryGetBytecode - { - /// - /// Creates a instance for the TryGetBytecode method. - /// - /// The input instance. - /// 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) - { - BlockSyntax block = GetShaderBytecodeBody(bytecodeInfo, out string? bytecodeLiterals); - - if (bytecodeLiterals is not null) - { - fixup = tree => tree.ToFullString().Replace("__EMBEDDED_SHADER_BYTECODE", bytecodeLiterals); - } - else - { - fixup = static tree => tree.ToFullString(); - } - - // This code produces a method declaration as follows: - // - // readonly int global::ComputeSharp.__Internals.IShader.TryGetBytecode(int threadsX, int threadsY, int threadsZ, out ReadOnlySpan bytecode) - // { - // - // } - return - MethodDeclaration( - PredefinedType(Token(SyntaxKind.BoolKeyword)), - Identifier("TryGetBytecode")) - .WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.__Internals.{nameof(IShader)}"))) - .AddModifiers(Token(SyntaxKind.ReadOnlyKeyword)) - .AddParameterListParameters( - 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"))) - .WithBody(block); - } - - /// - /// Gets a instance with the logic to try to get a compiled shader bytecode. - /// - /// The input instance. - /// 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) - { - 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))); - } - - bytecodeLiterals = BuildShaderBytecodeExpressionString(bytecodeInfo.Bytecode.AsSpan()); - - // This code produces a method declaration as follows: - // - // if (threadsX == && threadsY == && threadsZ == ) - // { - // bytecode = new byte[] { __EMBEDDED_SHADER_BYTECODE }; - // - // return true; - // } - // - // 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( - 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)))), - BinaryExpression( - SyntaxKind.EqualsExpression, - IdentifierName("threadsZ"), - LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(bytecodeInfo.Z)))), - Block( - ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - IdentifierName("bytecode"), - 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))); - } - - /// - /// A mapping of precomputed literals for all values. - /// - private static readonly string[] formattedBytes = - { - "0x00", "0x01", "0x02", "0x03", "0x04", "0x05", "0x06", "0x07", "0x08", "0x09", "0x0A", "0x0B", "0x0C", "0x0D", "0x0E", "0x0F", - "0x10", "0x11", "0x12", "0x13", "0x14", "0x15", "0x16", "0x17", "0x18", "0x19", "0x1A", "0x1B", "0x1C", "0x1D", "0x1E", "0x1F", - "0x20", "0x21", "0x22", "0x23", "0x24", "0x25", "0x26", "0x27", "0x28", "0x29", "0x2A", "0x2B", "0x2C", "0x2D", "0x2E", "0x2F", - "0x30", "0x31", "0x32", "0x33", "0x34", "0x35", "0x36", "0x37", "0x38", "0x39", "0x3A", "0x3B", "0x3C", "0x3D", "0x3E", "0x3F", - "0x40", "0x41", "0x42", "0x43", "0x44", "0x45", "0x46", "0x47", "0x48", "0x49", "0x4A", "0x4B", "0x4C", "0x4D", "0x4E", "0x4F", - "0x50", "0x51", "0x52", "0x53", "0x54", "0x55", "0x56", "0x57", "0x58", "0x59", "0x5A", "0x5B", "0x5C", "0x5D", "0x5E", "0x5F", - "0x60", "0x61", "0x62", "0x63", "0x64", "0x65", "0x66", "0x67", "0x68", "0x69", "0x6A", "0x6B", "0x6C", "0x6D", "0x6E", "0x6F", - "0x70", "0x71", "0x72", "0x73", "0x74", "0x75", "0x76", "0x77", "0x78", "0x79", "0x7A", "0x7B", "0x7C", "0x7D", "0x7E", "0x7F", - "0x80", "0x81", "0x82", "0x83", "0x84", "0x85", "0x86", "0x87", "0x88", "0x89", "0x8A", "0x8B", "0x8C", "0x8D", "0x8E", "0x8F", - "0x90", "0x91", "0x92", "0x93", "0x94", "0x95", "0x96", "0x97", "0x98", "0x99", "0x9A", "0x9B", "0x9C", "0x9D", "0x9E", "0x9F", - "0xA0", "0xA1", "0xA2", "0xA3", "0xA4", "0xA5", "0xA6", "0xA7", "0xA8", "0xA9", "0xAA", "0xAB", "0xAC", "0xAD", "0xAE", "0xAF", - "0xB0", "0xB1", "0xB2", "0xB3", "0xB4", "0xB5", "0xB6", "0xB7", "0xB8", "0xB9", "0xBA", "0xBB", "0xBC", "0xBD", "0xBE", "0xBF", - "0xC0", "0xC1", "0xC2", "0xC3", "0xC4", "0xC5", "0xC6", "0xC7", "0xC8", "0xC9", "0xCA", "0xCB", "0xCC", "0xCD", "0xCE", "0xCF", - "0xD0", "0xD1", "0xD2", "0xD3", "0xD4", "0xD5", "0xD6", "0xD7", "0xD8", "0xD9", "0xDA", "0xDB", "0xDC", "0xDD", "0xDE", "0xDF", - "0xE0", "0xE1", "0xE2", "0xE3", "0xE4", "0xE5", "0xE6", "0xE7", "0xE8", "0xE9", "0xEA", "0xEB", "0xEC", "0xED", "0xEE", "0xEF", - "0xF0", "0xF1", "0xF2", "0xF3", "0xF4", "0xF5", "0xF6", "0xF7", "0xF8", "0xF9", "0xFA", "0xFB", "0xFC", "0xFD", "0xFE", "0xFF" - }; - - /// - /// Creates a formatted expression to initialize a with a given shader data. - /// - /// The input shader bytecode to serialize. - /// A formatted with the serialized data. - private static string BuildShaderBytecodeExpressionString(ReadOnlySpan bytecode) - { - //The estimation is 4 characters per byte (up to "255" in hex), plus ", " to separate sequential values - using ArrayPoolStringBuilder builder = ArrayPoolStringBuilder.Create(bytecode.Length * 6); - - builder.Append(formattedBytes[bytecode[0]]); - - foreach (byte b in bytecode.Slice(1)) - { - builder.Append(", "); - builder.Append(formattedBytes[b]); - } - - return builder.WrittenSpan.ToString(); - } - } -} diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs index aabfe271..3a92a278 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs @@ -224,14 +224,19 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator .Select(static (item, token) => (item.Hierarchy, item.BytecodeInfo)) .WithComparers(HierarchyInfo.Comparer.Default, EmbeddedBytecodeInfo.Comparer.Default); + // Check whether or not dynamic shaders are supported + IncrementalValueProvider supportsDynamicShaders = + context.CompilationProvider + .Select(static (compilation, token) => compilation.GetTypeByMetadataName("ComputeSharp.__Internals.ShaderCompiler") is not null); + // 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 = TryGetBytecode.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}.TryGetBytecode", SourceText.From(text, Encoding.UTF8)); }); } } From 23b500fe8198e4e1b1bc5e60ae242c86a4a204c4 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 14 Dec 2021 01:20:04 +0100 Subject: [PATCH 09/26] Improve source generator support for dynamic shaders --- .../Shaders/Interop/ReflectionServices.cs | 3 +- .../Translation/__Internals/ShaderCompiler.cs | 11 +++++-- ...enerator.CreateGetBytecodeMethod.Syntax.cs | 31 +++++-------------- .../IShaderGenerator.cs | 3 +- .../Dispatching/ShaderBytecodeLoader.cs | 11 +++++-- 5 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs b/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs index 4cdeb8c5..f9cbd999 100644 --- a/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs +++ b/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs @@ -2,7 +2,6 @@ using System.Runtime.CompilerServices; using ComputeSharp.__Internals; using ComputeSharp.Core.Extensions; -using ComputeSharp.Shaders.Translation; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; #if !NET6_0_OR_GREATER @@ -107,7 +106,7 @@ public static class ReflectionServices { 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(); diff --git a/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs b/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs index fc51c97c..6ff54932 100644 --- a/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs +++ b/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; @@ -7,16 +8,20 @@ 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 HLSL source code to compile. + /// The instance with the HLSL source code to compile. /// The bytecode for the compiled shader. - public static unsafe IntPtr CompileShader(ReadOnlySpan source) + public static unsafe IntPtr CompileShader(ref ArrayPoolStringBuilder builder) { - using ComPtr shader = Shaders.Translation.ShaderCompiler.Instance.CompileShader(source); + using ComPtr shader = Shaders.Translation.ShaderCompiler.Instance.CompileShader(builder.WrittenSpan); + + builder.Dispose(); _ = shader.Get()->AddRef(); diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetBytecodeMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetBytecodeMethod.Syntax.cs index bb0a41ce..4b41b8ec 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetBytecodeMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetBytecodeMethod.Syntax.cs @@ -169,8 +169,7 @@ public sealed partial class IShaderGenerator // This code produces a method declaration as follows: // // BuildHlslString(out global::ComputeSharp.__Internals.ArrayPoolStringBuilder builder, threadsX, threadsY, threadsZ); - // global::System.IntPtr bytecode = ShaderCompiler.CompileShader(builder.WrittenSpan); - // builder.Dispose(); + // global::System.IntPtr bytecode = ShaderCompiler.CompileShader(ref builder); // loader.LoadDynamicBytecode(bytecode); dynamicStatements = ImmutableArray.Create( ExpressionStatement( @@ -194,24 +193,15 @@ public sealed partial class IShaderGenerator IdentifierName("ShaderCompiler"), IdentifierName("CompileShader"))) .AddArgumentListArguments( - Argument( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("builder"), - IdentifierName("WrittenSpan")))))))), - ExpressionStatement( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("builder"), - IdentifierName("Dispose")))), + Argument(IdentifierName("builder")) + .WithRefKindKeyword(Token(SyntaxKind.RefKeyword))))))), ExpressionStatement( InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, IdentifierName("loader"), IdentifierName("LoadDynamicBytecode"))) - .AddArgumentListArguments(Argument(IdentifierName("bytecode"))))); + .AddArgumentListArguments(Argument(IdentifierName("bytecode")))));; } return dynamicStatements; @@ -232,7 +222,7 @@ public sealed partial class IShaderGenerator { // This code produces a faulting call as follows: // - // loader.LoadDynamicBytecode(global::System.IntPtr.Zero); + // loader.LoadDynamicBytecode(default); return ExpressionStatement( InvocationExpression( @@ -241,14 +231,9 @@ public sealed partial class IShaderGenerator IdentifierName("loader"), IdentifierName("LoadDynamicBytecode"))) .AddArgumentListArguments( - Argument( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("global::System.IntPtr"), - IdentifierName("IntPtr")), - IdentifierName("Zero"))))); + Argument(LiteralExpression( + SyntaxKind.DefaultLiteralExpression, + Token(SyntaxKind.DefaultKeyword))))); } return dynamicFaultStatement; diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs index 3a92a278..35b829a8 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs @@ -227,7 +227,8 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator // Check whether or not dynamic shaders are supported IncrementalValueProvider supportsDynamicShaders = context.CompilationProvider - .Select(static (compilation, token) => compilation.GetTypeByMetadataName("ComputeSharp.__Internals.ShaderCompiler") is not null); + .Select(static (compilation, token) => compilation.ReferencedAssemblyNames.Any( + static identity => identity.Name is "ComputeSharp.Dynamic")); // Generate the TryGetBytecode() methods context.RegisterSourceOutput(embeddedBytecode.Combine(supportsDynamicShaders), static (context, item) => diff --git a/src/ComputeSharp/Shaders/Dispatching/ShaderBytecodeLoader.cs b/src/ComputeSharp/Shaders/Dispatching/ShaderBytecodeLoader.cs index 68971f12..4f26a41f 100644 --- a/src/ComputeSharp/Shaders/Dispatching/ShaderBytecodeLoader.cs +++ b/src/ComputeSharp/Shaders/Dispatching/ShaderBytecodeLoader.cs @@ -29,7 +29,7 @@ internal struct ShaderBytecodeLoader : IBytecodeLoader { if (this.cachedShader is not ICachedShader cachedShader) { - return ThrowHelper.ThrowInvalidOperationException("The shader has not been initialized"); + return ThrowHelper.ThrowInvalidOperationException("The shader has not been initialized."); } return cachedShader; @@ -40,7 +40,12 @@ internal struct ShaderBytecodeLoader : IBytecodeLoader { if (this.cachedShader is not null) { - ThrowHelper.ThrowInvalidOperationException("The shader has already been initialized"); + 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); @@ -52,7 +57,7 @@ internal struct ShaderBytecodeLoader : IBytecodeLoader { if (this.cachedShader is not null) { - ThrowHelper.ThrowInvalidOperationException("The shader has already been initialized"); + ThrowHelper.ThrowInvalidOperationException("The shader has already been initialized."); } this.cachedShader = new ICachedShader.Embedded(bytecode); From 16ef5f82e95492d6a26848c5048ba4cb9ce51575 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 14 Dec 2021 01:28:15 +0100 Subject: [PATCH 10/26] Minor fixes to source generators --- ...Generator.CreateLoadBytecodeMethod.Syntax.cs} | 8 ++++---- ...IShaderGenerator.CreateLoadBytecodeMethod.cs} | 4 ++-- .../IShaderGenerator.cs | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) rename src/ComputeSharp.SourceGenerators/{IShaderGenerator.CreateGetBytecodeMethod.Syntax.cs => IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs} (98%) rename src/ComputeSharp.SourceGenerators/{IShaderGenerator.CreateGetBytecodeMethod.cs => IShaderGenerator.CreateLoadBytecodeMethod.cs} (98%) diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetBytecodeMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs similarity index 98% rename from src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetBytecodeMethod.Syntax.cs rename to src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs index 4b41b8ec..e7dc8be6 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetBytecodeMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs @@ -17,7 +17,7 @@ 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. @@ -41,14 +41,14 @@ public sealed partial class IShaderGenerator // This code produces a method declaration as follows: // - // readonly void global::ComputeSharp.__Internals.IShader.GetBytecode(ref TBytecodeLoader loader, int threadsX, int threadsY, int threadsZ) + // readonly void global::ComputeSharp.__Internals.IShader.LoadBytecode(ref TBytecodeLoader loader, int threadsX, int threadsY, int threadsZ) // { // // } return MethodDeclaration( PredefinedType(Token(SyntaxKind.VoidKeyword)), - Identifier("GetBytecode")) + Identifier("LoadBytecode")) .WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.__Internals.{nameof(IShader)}"))) .AddModifiers(Token(SyntaxKind.ReadOnlyKeyword)) .AddTypeParameterListParameters(TypeParameter(Identifier("TBytecodeLoader"))) @@ -164,7 +164,7 @@ public sealed partial class IShaderGenerator /// A sequence of instances to create a new dynamic shader. private static ImmutableArray GetDynamicCompilationStatements() { - if (dynamicStatements.IsEmpty) + if (dynamicStatements.IsDefault) { // This code produces a method declaration as follows: // diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetBytecodeMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs similarity index 98% rename from src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetBytecodeMethod.cs rename to src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs index 47fc3948..8a75495f 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetBytecodeMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs @@ -23,9 +23,9 @@ 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. diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs index 35b829a8..4507d253 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs @@ -66,7 +66,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator MethodDeclarationSyntax getDispatchIdMethod = GetDispatchId.GetSyntax(item.Info.Delegates); CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Hierarchy, getDispatchIdMethod, false); - context.AddSource($"{item.Hierarchy.FilenameHint}.GetDispatchId", SourceText.From(compilationUnit.ToFullString(), Encoding.UTF8)); + context.AddSource($"{item.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 @@ -99,7 +99,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator out ImmutableArray hlslSourceDiagnostics); // TryGetBytecode() info - ThreadIdsInfo threadIds = TryGetBytecode.GetInfo( + ThreadIdsInfo threadIds = LoadBytecode.GetInfo( item.Left.Symbol, !hlslSourceInfo.Delegates.IsEmpty, out ImmutableArray threadIdsDiagnostics); @@ -137,7 +137,7 @@ 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 @@ -152,7 +152,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator MethodDeclarationSyntax buildHlslStringMethod = BuildHlslString.GetSyntax(item.Left.SourceInfo); 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 +173,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 +187,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, @@ -233,11 +233,11 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator // Generate the TryGetBytecode() methods context.RegisterSourceOutput(embeddedBytecode.Combine(supportsDynamicShaders), static (context, item) => { - MethodDeclarationSyntax tryGetBytecodeMethod = TryGetBytecode.GetSyntax(item.Left.BytecodeInfo, item.Right, out Func fixup); + 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.Left.Hierarchy.FilenameHint}.TryGetBytecode", SourceText.From(text, Encoding.UTF8)); + context.AddSource($"{item.Left.Hierarchy.FilenameHint}.{nameof(LoadBytecode)}", SourceText.From(text, Encoding.UTF8)); }); } } From 0675dd667cfd039d02775c2c9e46108220e05049 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 14 Dec 2021 22:45:40 +0100 Subject: [PATCH 11/26] Fix codegen for dynamic shaders --- .../Translation/__Internals/ShaderCompiler.cs | 22 ++-- ...nerator.CreateLoadBytecodeMethod.Syntax.cs | 106 ++++++------------ 2 files changed, 52 insertions(+), 76 deletions(-) diff --git a/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs b/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs index 6ff54932..b61ec078 100644 --- a/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs +++ b/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using System.Runtime.CompilerServices; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; @@ -15,16 +16,23 @@ public static class ShaderCompiler /// /// Compiles a new HLSL shader from the input source code. /// - /// The instance with the HLSL source code to compile. - /// The bytecode for the compiled shader. - public static unsafe IntPtr CompileShader(ref ArrayPoolStringBuilder builder) + /// 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 TBytecodeLoader loader, int threadsX, int threadsY, int threadsZ, in T shader) + where TBytecodeLoader : struct, IBytecodeLoader + where T : struct, IShader { - using ComPtr shader = Shaders.Translation.ShaderCompiler.Instance.CompileShader(builder.WrittenSpan); + Unsafe.AsRef(in shader).BuildHlslString(out ArrayPoolStringBuilder builder, threadsX, threadsY, threadsZ); + + using ComPtr dxcBlobBytecode = Shaders.Translation.ShaderCompiler.Instance.CompileShader(builder.WrittenSpan); builder.Dispose(); - _ = shader.Get()->AddRef(); - - return (IntPtr)shader.Get(); + loader.LoadDynamicBytecode((IntPtr)dxcBlobBytecode.Get()); } } diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs index e7dc8be6..d85f10f8 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Immutable; using System.Diagnostics.Contracts; -using System.Linq; using ComputeSharp.__Internals; using ComputeSharp.SourceGenerators.Models; using Microsoft.CodeAnalysis; @@ -79,7 +77,7 @@ public sealed partial class IShaderGenerator if (supportsDynamicShaders) { // Return the dynamic compilation path - return Block(GetDynamicCompilationStatements()); + return Block(GetDynamicCompilationStatement()); } else { @@ -146,65 +144,40 @@ public sealed partial class IShaderGenerator // If dynamic shaders are supported, return the combined block if (supportsDynamicShaders) { - return Block(embeddedBranch).AddStatements(GetDynamicCompilationStatements().ToArray()); + return Block(embeddedBranch.WithElse(ElseClause(Block(GetDynamicCompilationStatement())))); } // If there is no dynamic shader support, add the faulting path after the branch - return Block(embeddedBranch).AddStatements(GetDynamicCompilationFaultingBlock()); + return Block(embeddedBranch.WithElse(ElseClause(Block(GetDynamicCompilationFaultingBlock())))); } /// /// The cached tree of dynamic statements. /// - private static ImmutableArray dynamicStatements; + private static StatementSyntax? dynamicStatement; /// - /// Returns a sequence of instances to create a new dynamic shader. + /// Returns the instance to create a new dynamic shader. /// - /// A sequence of instances to create a new dynamic shader. - private static ImmutableArray GetDynamicCompilationStatements() + /// The instance to create a new dynamic shader. + private static StatementSyntax GetDynamicCompilationStatement() { - if (dynamicStatements.IsDefault) - { - // This code produces a method declaration as follows: - // - // BuildHlslString(out global::ComputeSharp.__Internals.ArrayPoolStringBuilder builder, threadsX, threadsY, threadsZ); - // global::System.IntPtr bytecode = ShaderCompiler.CompileShader(ref builder); - // loader.LoadDynamicBytecode(bytecode); - dynamicStatements = ImmutableArray.Create( - ExpressionStatement( - InvocationExpression(IdentifierName("BuildHlslString")) - .AddArgumentListArguments( - Argument(DeclarationExpression( - IdentifierName("global::ComputeSharp.__Internals.ArrayPoolStringBuilder"), - SingleVariableDesignation(Identifier("builder")))) - .WithRefOrOutKeyword(Token(SyntaxKind.OutKeyword)), - Argument(IdentifierName("threadsX")), - Argument(IdentifierName("threadsY")), - Argument(IdentifierName("threadsZ")))), - LocalDeclarationStatement( - VariableDeclaration(IdentifierName("global::System.IntPtr")) - .AddVariables(VariableDeclarator(Identifier("bytecode")) - .WithInitializer( - EqualsValueClause( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("ShaderCompiler"), - IdentifierName("CompileShader"))) - .AddArgumentListArguments( - Argument(IdentifierName("builder")) - .WithRefKindKeyword(Token(SyntaxKind.RefKeyword))))))), - ExpressionStatement( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("loader"), - IdentifierName("LoadDynamicBytecode"))) - .AddArgumentListArguments(Argument(IdentifierName("bytecode")))));; - } - - return dynamicStatements; + // 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)))); } /// @@ -218,25 +191,20 @@ public sealed partial class IShaderGenerator /// A instances to perform a faulting call to LoadDynamicBytecode(IntPtr). private static ExpressionStatementSyntax GetDynamicCompilationFaultingBlock() { - if (dynamicFaultStatement is null) - { - // This code produces a faulting call as follows: - // - // loader.LoadDynamicBytecode(default); - return - ExpressionStatement( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("loader"), - IdentifierName("LoadDynamicBytecode"))) - .AddArgumentListArguments( - Argument(LiteralExpression( - SyntaxKind.DefaultLiteralExpression, - Token(SyntaxKind.DefaultKeyword))))); - } - - return dynamicFaultStatement; + // 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))))); } /// From ea6517794173a05922c5b031bb4fd8a98047be9f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 14 Dec 2021 23:02:54 +0100 Subject: [PATCH 12/26] Add Dynamic package project and missing assembly info --- ComputeSharp.sln | 1 + .../ComputeSharp.Dynamic.Package.msbuildproj | 21 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 5 +++++ 3 files changed, 27 insertions(+) create mode 100644 src/ComputeSharp.Dynamic.Package/ComputeSharp.Dynamic.Package.msbuildproj create mode 100644 src/ComputeSharp.Dynamic/Properties/AssemblyInfo.cs diff --git a/ComputeSharp.sln b/ComputeSharp.sln index a9db8b7e..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 diff --git a/src/ComputeSharp.Dynamic.Package/ComputeSharp.Dynamic.Package.msbuildproj b/src/ComputeSharp.Dynamic.Package/ComputeSharp.Dynamic.Package.msbuildproj new file mode 100644 index 00000000..a0bf822c --- /dev/null +++ b/src/ComputeSharp.Dynamic.Package/ComputeSharp.Dynamic.Package.msbuildproj @@ -0,0 +1,21 @@ + + + + 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.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 From a48290873e98b746e59a8425d1d03bbbe875d388 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 14 Dec 2021 23:05:09 +0100 Subject: [PATCH 13/26] Update unit test projects --- .github/workflows/dotnet.yml | 26 +----- ...arp.Tests.DisableDynamicCompilation.csproj | 5 -- .../DispatchTests.cs | 47 ----------- .../ComputeSharp.Tests.Internals.csproj | 7 +- .../ShaderBytecodeTests.cs | 79 ------------------- .../ShaderCompilerTests.cs | 6 +- .../ComputeSharp.Tests.csproj | 1 + 7 files changed, 6 insertions(+), 165 deletions(-) delete mode 100644 tests/ComputeSharp.Tests.Internals/ShaderBytecodeTests.cs diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 415368bb..61a00d20 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -44,26 +44,6 @@ 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() @@ -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" 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/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 @@ + Date: Tue, 14 Dec 2021 23:12:14 +0100 Subject: [PATCH 14/26] Update CI script --- .github/workflows/dotnet.yml | 23 +++++++++++++++---- .../ComputeSharp.Sample.NuGet.csproj | 1 + .../ComputeSharp.Sample.NuGet/nuget.config | 1 + .../NativeLibrariesResolverTests.cs | 4 +++- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 61a00d20..1d2b6b8f 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -47,7 +47,7 @@ jobs: # 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 @@ -160,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 @@ -169,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 @@ -195,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/samples/ComputeSharp.Sample.NuGet/ComputeSharp.Sample.NuGet.csproj b/samples/ComputeSharp.Sample.NuGet/ComputeSharp.Sample.NuGet.csproj index a518813b..dd2769fd 100644 --- a/samples/ComputeSharp.Sample.NuGet/ComputeSharp.Sample.NuGet.csproj +++ b/samples/ComputeSharp.Sample.NuGet/ComputeSharp.Sample.NuGet.csproj @@ -8,6 +8,7 @@ + diff --git a/samples/ComputeSharp.Sample.NuGet/nuget.config b/samples/ComputeSharp.Sample.NuGet/nuget.config index d67dcaef..e07ed6c0 100644 --- a/samples/ComputeSharp.Sample.NuGet/nuget.config +++ b/samples/ComputeSharp.Sample.NuGet/nuget.config @@ -2,5 +2,6 @@ + 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(); } /// From efafd188ea79c49fa502a4992f0e34ee6267798e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 14 Dec 2021 23:26:21 +0100 Subject: [PATCH 15/26] Add missing ComputeSharp.Dynamic reference to sample projects --- samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj | 1 + .../ComputeSharp.ImageProcessing.csproj | 1 + .../ComputeSharp.Sample.FSharp.Shaders.csproj | 1 + .../ComputeSharp.Sample.FSharp/ComputeSharp.Sample.FSharp.fsproj | 1 + samples/ComputeSharp.Sample/ComputeSharp.Sample.csproj | 1 + .../ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj | 1 + .../ComputeSharp.SwapChain.WinUI.csproj | 1 + samples/ComputeSharp.SwapChain/ComputeSharp.SwapChain.csproj | 1 + 8 files changed, 8 insertions(+) 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.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj index 4d829db6..54802961 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj +++ b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj @@ -41,6 +41,7 @@ + + Date: Tue, 14 Dec 2021 23:44:33 +0100 Subject: [PATCH 16/26] Fix local NuGet paths in NuGet sample --- samples/ComputeSharp.Sample.NuGet/nuget.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/ComputeSharp.Sample.NuGet/nuget.config b/samples/ComputeSharp.Sample.NuGet/nuget.config index e07ed6c0..c3f2b513 100644 --- a/samples/ComputeSharp.Sample.NuGet/nuget.config +++ b/samples/ComputeSharp.Sample.NuGet/nuget.config @@ -1,7 +1,7 @@ - - + + From 91f2b0903897cd1e4a5768113a9da66f96b50e32 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 15 Dec 2021 17:57:54 +0100 Subject: [PATCH 17/26] Fix incorrect HierarchyInfo.Comparer.GetHashCode --- .../Models/HierarchyInfo.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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(); } } } From 547eff9fd19fb68e3ca5ed7e8f818b9caf1e4b43 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 18 Dec 2021 12:27:30 +0100 Subject: [PATCH 18/26] Minor code style tweaks --- .../Translation/__Internals/ShaderCompiler.cs | 8 +++---- ...nerator.CreateLoadBytecodeMethod.Syntax.cs | 6 ++--- ...tor.CreateLoadDispatchDataMethod.Syntax.cs | 6 ++--- ...CreateLoadDispatchMetadataMethod.Syntax.cs | 6 ++--- .../Core/Interfaces/__Internals/IShader.cs | 24 +++++++++---------- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs b/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs index b61ec078..59c02eec 100644 --- a/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs +++ b/src/ComputeSharp.Dynamic/Shaders/Translation/__Internals/ShaderCompiler.cs @@ -16,15 +16,15 @@ public static class ShaderCompiler /// /// Compiles a new HLSL shader from the input source code. /// - /// The type of bytecode loader being used. + /// The type of bytecode loader being used. /// The type of shader being dispatched. - /// The instance to use to load the bytecode. + /// 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 TBytecodeLoader loader, int threadsX, int threadsY, int threadsZ, in T shader) - where TBytecodeLoader : struct, IBytecodeLoader + 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); diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs index d85f10f8..d69fa0bf 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs @@ -39,7 +39,7 @@ public sealed partial class IShaderGenerator // This code produces a method declaration as follows: // - // readonly void global::ComputeSharp.__Internals.IShader.LoadBytecode(ref TBytecodeLoader loader, int threadsX, int threadsY, int threadsZ) + // readonly void global::ComputeSharp.__Internals.IShader.LoadBytecode(ref TLoader loader, int threadsX, int threadsY, int threadsZ) // { // // } @@ -49,11 +49,11 @@ public sealed partial class IShaderGenerator Identifier("LoadBytecode")) .WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.__Internals.{nameof(IShader)}"))) .AddModifiers(Token(SyntaxKind.ReadOnlyKeyword)) - .AddTypeParameterListParameters(TypeParameter(Identifier("TBytecodeLoader"))) + .AddTypeParameterListParameters(TypeParameter(Identifier("TLoader"))) .AddParameterListParameters( Parameter(Identifier("loader")) .AddModifiers(Token(SyntaxKind.RefKeyword)) - .WithType(IdentifierName("TBytecodeLoader")), + .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)))) 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/Core/Interfaces/__Internals/IShader.cs b/src/ComputeSharp/Core/Interfaces/__Internals/IShader.cs index dc4495b0..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(); @@ -85,15 +85,15 @@ public interface IShader /// /// Loads the bytecode for the current shader. /// - /// The type of bytecode loader being used. - /// The instance to use to load the bytecode. + /// 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. [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is not intended to be used directly by user code")] - void LoadBytecode(ref TBytecodeLoader loader, int threadsX, int threadsY, int threadsZ) - where TBytecodeLoader : struct, IBytecodeLoader + void LoadBytecode(ref TLoader loader, int threadsX, int threadsY, int threadsZ) + where TLoader : struct, IBytecodeLoader #if NET6_0_OR_GREATER { throw new NotImplementedException(); From b9313ca6d89806e4f3f8e4961796b17e321e6c7a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 18 Dec 2021 12:43:59 +0100 Subject: [PATCH 19/26] Skip generating BuildHlslString body when dynamic support is missing --- ...ator.CreateBuildHlslStringMethod.Syntax.cs | 34 +++++++++++++++++-- .../IShaderGenerator.cs | 23 +++++++------ 2 files changed, 43 insertions(+), 14 deletions(-) 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.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs index 4507d253..6e59bbf6 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs @@ -138,18 +138,25 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Left.Hierarchy, loadDispatchDataMethod, item.Right); context.AddSource($"{item.Left.Hierarchy.FilenameHint}.{nameof(LoadDispatchData)}", SourceText.From(compilationUnit.ToFullString(), Encoding.UTF8)); - }); + }); + + // 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 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}.{nameof(BuildHlslString)}", SourceText.From(compilationUnit.ToFullString(), Encoding.UTF8)); @@ -224,12 +231,6 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator .Select(static (item, token) => (item.Hierarchy, item.BytecodeInfo)) .WithComparers(HierarchyInfo.Comparer.Default, EmbeddedBytecodeInfo.Comparer.Default); - // 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")); - // Generate the TryGetBytecode() methods context.RegisterSourceOutput(embeddedBytecode.Combine(supportsDynamicShaders), static (context, item) => { From 71fad3a8fdaa8ea910aa8fea7f66d07e9e82baf5 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 18 Dec 2021 13:11:19 +0100 Subject: [PATCH 20/26] Add diagnostic when [EmbeddedBytecode] is missing --- .../AnalyzerReleases.Shipped.md | 1 + .../Diagnostics/DiagnosticDescriptors.cs | 28 +++++++++++++++---- ...haderGenerator.CreateLoadBytecodeMethod.cs | 14 ++++++++-- .../IShaderGenerator.cs | 28 ++++++++++--------- 4 files changed, 49 insertions(+), 22 deletions(-) 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/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.CreateLoadBytecodeMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs index 8a75495f..e53ac4c4 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs @@ -32,26 +32,34 @@ public sealed partial class IShaderGenerator /// /// 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.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs index 6e59bbf6..0e42e6af 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 @@ -73,20 +79,21 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator // 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 = LoadBytecode.GetInfo( - item.Left.Symbol, + item.Left.Left.Symbol, !hlslSourceInfo.Delegates.IsEmpty, + item.Left.Right, out ImmutableArray threadIdsDiagnostics); return ( @@ -140,12 +148,6 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator context.AddSource($"{item.Left.Hierarchy.FilenameHint}.{nameof(LoadDispatchData)}", SourceText.From(compilationUnit.ToFullString(), Encoding.UTF8)); }); - // 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 the filtered sequence to enable caching IncrementalValuesProvider<(HierarchyInfo Hierarchy, HlslShaderSourceInfo SourceInfo, bool SupportsDynamicShaders)> hlslSourceInfo = shaderInfo From 0508887482c17204e13e16cdfcbe0946698c22a4 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 18 Dec 2021 13:13:40 +0100 Subject: [PATCH 21/26] Skip generating full GetDispatchId() when dynamic support is missing --- ...aderGenerator.CreateGetDispatchIdMethod.Syntax.cs | 12 +++++++----- .../IShaderGenerator.cs | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) 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.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs index 0e42e6af..ba891525 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs @@ -67,12 +67,12 @@ 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}.{nameof(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 From ed8f75a08d0e5fd71e472e056c564b526467c6d5 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 18 Dec 2021 14:16:48 +0100 Subject: [PATCH 22/26] Enable embedded shaders for UWP/WinUI sample apps --- .../ComputeSharp.SwapChain.Shaders.Shared/ColorfulInfinity.cs | 3 +++ .../ComputeSharp.SwapChain.Shaders.Shared/ContouredLayers.cs | 3 +++ .../ExtrudedTruchetPattern.cs | 3 +++ .../FourColorGradient.cs | 3 +++ .../ComputeSharp.SwapChain.Shaders.Shared/FractalTiling.cs | 3 +++ samples/ComputeSharp.SwapChain.Shaders.Shared/HelloWorld.cs | 3 +++ .../ComputeSharp.SwapChain.Shaders.Shared/MengerJourney.cs | 3 +++ samples/ComputeSharp.SwapChain.Shaders.Shared/Octagrams.cs | 3 +++ .../ComputeSharp.SwapChain.Shaders.Shared/ProteanClouds.cs | 3 +++ .../ComputeSharp.SwapChain.Shaders.Shared/PyramidPattern.cs | 3 +++ .../TriangleGridContouring.cs | 3 +++ .../ComputeSharp.SwapChain.Shaders.Shared/TwoTiledTruchet.cs | 3 +++ .../ComputeSharp.SwapChain.Uwp.csproj | 4 +++- .../ComputeSharp.SwapChain.WinUI.csproj | 2 +- 14 files changed, 40 insertions(+), 2 deletions(-) diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/ColorfulInfinity.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/ColorfulInfinity.cs index a68e508e..fbb83865 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/ColorfulInfinity.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/ColorfulInfinity.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 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 f5c66c16..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 @@ -212,7 +215,6 @@ - diff --git a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj index 54802961..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 @@ -41,7 +42,6 @@ - Date: Sat, 18 Dec 2021 14:42:25 +0100 Subject: [PATCH 23/26] Update readme with [EmbeddedBytecode] info --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) 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 From 9c18a0ca0e4b23769b999c5abe4c979b4cd0cfa2 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 18 Dec 2021 15:55:32 +0100 Subject: [PATCH 24/26] Add workaround for source generator diagnostics tests --- .../DiagnosticsTests.cs | 96 +++++++++---------- 1 file changed, 48 insertions(+), 48 deletions(-) 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] From d69d7d69ee2b1d9739f4725c2f7da33c7bf03059 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 19 Dec 2021 14:59:48 +0100 Subject: [PATCH 25/26] Remove duplicate tags in .csproj files --- src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj | 1 - src/ComputeSharp/ComputeSharp.csproj | 1 - 2 files changed, 2 deletions(-) diff --git a/src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj b/src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj index ec15565d..5ea50bd8 100644 --- a/src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj +++ b/src/ComputeSharp.Dynamic/ComputeSharp.Dynamic.csproj @@ -3,7 +3,6 @@ netstandard2.0;net6.0 bin\Release ComputeSharp.Dynamic.xml - ComputeSharp.Dynamic AnyCPU;x64;ARM64 diff --git a/src/ComputeSharp/ComputeSharp.csproj b/src/ComputeSharp/ComputeSharp.csproj index 9b3dca25..eb42dee5 100644 --- a/src/ComputeSharp/ComputeSharp.csproj +++ b/src/ComputeSharp/ComputeSharp.csproj @@ -3,7 +3,6 @@ netstandard2.0;net6.0 bin\Release ComputeSharp.xml - ComputeSharp From 606c28c23067ae5b5ac31babca923b1b11b7401a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 19 Dec 2021 16:55:59 +0100 Subject: [PATCH 26/26] Add ComputeSharp.Dynamic to solution filter --- ComputeSharp.NET.slnf | 1 + 1 file changed, 1 insertion(+) 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",