diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml
index 7bc4b50e..73a2a5a9 100644
--- a/.github/workflows/dotnet.yml
+++ b/.github/workflows/dotnet.yml
@@ -44,10 +44,30 @@ jobs:
run: msbuild -t:restore,build /p:Configuration=Release /p:Platform=x64
shell: cmd
+ # Build the whole ComputeSharp solution with /p:DisableShaderCompilationSupport=True
+ build-solution-release-no-dynamic:
+ runs-on: windows-2022
+ steps:
+ - name: Git checkout
+ uses: actions/checkout@v2
+ - name: Add msbuild to PATH
+ uses: microsoft/setup-msbuild@v1.0.3
+ - name: Setup .NET Core 3.1 SDK
+ uses: actions/setup-dotnet@v1
+ with:
+ dotnet-version: 3.1.x
+ - name: Setup .NET 6 SDK
+ uses: actions/setup-dotnet@v1
+ with:
+ dotnet-version: 6.0.x
+ - name: Build
+ run: msbuild -t:restore,build /p:Configuration=Release /p:Platform=x64 /p:DisableShaderCompilationSupport=True
+ shell: cmd
+
# Run all the unit tests referencing the ComputeSharp project directly
run-tests:
if: success()
- needs: [build-solution-debug, build-solution-release]
+ needs: [build-solution-debug, build-solution-release, build-solution-release-no-dynamic]
runs-on: windows-2022
steps:
- name: Git checkout
@@ -151,7 +171,7 @@ jobs:
# This workflow also uploads the resulting package as an artifact.
build-package:
if: success()
- needs: [build-solution-debug, build-solution-release]
+ needs: [build-solution-debug, build-solution-release, build-solution-release-no-dynamic]
runs-on: windows-2022
steps:
- name: Git checkout
diff --git a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj
index 5ba5ade8..5a76a335 100644
--- a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj
+++ b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj
@@ -8,7 +8,7 @@
- SOURCE_GENERATOR
+ $(DefineConstants);SOURCE_GENERATOR
+
+ $(DefineConstants);DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
+
+
+
+
+
diff --git a/src/ComputeSharp/Shaders/Interop/ReflectionServices.cs b/src/ComputeSharp/Shaders/Interop/ReflectionServices.cs
index 2d9467c4..c54769da 100644
--- a/src/ComputeSharp/Shaders/Interop/ReflectionServices.cs
+++ b/src/ComputeSharp/Shaders/Interop/ReflectionServices.cs
@@ -1,10 +1,18 @@
using System;
+#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
using System.Runtime.CompilerServices;
+#endif
using ComputeSharp.__Internals;
+#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
using ComputeSharp.Core.Extensions;
using ComputeSharp.Shaders.Translation;
+#else
+using Microsoft.Toolkit.Diagnostics;
+#endif
+#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
+#endif
#pragma warning disable CS0618
@@ -102,6 +110,11 @@ public static class ReflectionServices
private static unsafe void GetNonGenericShaderInfo(in T shader, out ShaderInfo shaderInfo)
where T : struct, IShader
{
+#if DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
+ ThrowHelper.ThrowNotSupportedException("Runtime shader compilation is not supported by the current configuration.");
+
+ shaderInfo = default;
+#else
Unsafe.AsRef(in shader).BuildHlslString(out ArrayPoolStringBuilder shaderSource, 1, 1, 1);
using ComPtr dxcBlobBytecode = ShaderCompiler.Instance.CompileShader(shaderSource.WrittenSpan);
@@ -155,5 +168,6 @@ public static class ReflectionServices
Unsafe.AsRef(shaderInfo.MovcInstructionCount) = d3D12ShaderReflection.Get()->GetMovcInstructionCount();
Unsafe.AsRef(shaderInfo.MovInstructionCount) = d3D12ShaderReflection.Get()->GetMovInstructionCount();
Unsafe.AsRef(shaderInfo.InterfaceSlotCount) = d3D12ShaderReflection.Get()->GetNumInterfaceSlots();
+#endif
}
}
diff --git a/src/ComputeSharp/Shaders/ShaderRunner{T}.cs b/src/ComputeSharp/Shaders/ShaderRunner{T}.cs
index 5cbc9b8a..3f9d462a 100644
--- a/src/ComputeSharp/Shaders/ShaderRunner{T}.cs
+++ b/src/ComputeSharp/Shaders/ShaderRunner{T}.cs
@@ -4,7 +4,9 @@ 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;
@@ -232,6 +234,11 @@ internal static class ShaderRunner
}
else
{
+#if DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
+ ThrowHelper.ThrowNotSupportedException("Runtime shader compilation is not supported by the current configuration.");
+
+ shaderData = null!;
+#else
shader.BuildHlslString(out ArrayPoolStringBuilder builder, threadsX, threadsY, threadsZ);
using ComPtr dxcBlobBytecode = ShaderCompiler.Instance.CompileShader(builder.WrittenSpan);
@@ -239,6 +246,7 @@ internal static class ShaderRunner
builder.Dispose();
shaderData = new ICachedShader.Dynamic(dxcBlobBytecode.Get());
+#endif
}
}
diff --git a/src/ComputeSharp/Shaders/Translation/ShaderCompiler.LibraryLoading.cs b/src/ComputeSharp/Shaders/Translation/ShaderCompiler.LibraryLoading.cs
index 52bf32ff..efd62ed7 100644
--- a/src/ComputeSharp/Shaders/Translation/ShaderCompiler.LibraryLoading.cs
+++ b/src/ComputeSharp/Shaders/Translation/ShaderCompiler.LibraryLoading.cs
@@ -1,4 +1,4 @@
-#if NET6_0_OR_GREATER
+#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT && NET6_0_OR_GREATER
using System;
using System.IO;
diff --git a/src/ComputeSharp/Shaders/Translation/ShaderCompiler.cs b/src/ComputeSharp/Shaders/Translation/ShaderCompiler.cs
index 21da886d..63de1f27 100644
--- a/src/ComputeSharp/Shaders/Translation/ShaderCompiler.cs
+++ b/src/ComputeSharp/Shaders/Translation/ShaderCompiler.cs
@@ -1,4 +1,6 @@
-using System;
+#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
+
+using System;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using ComputeSharp.Core.Extensions;
@@ -153,3 +155,5 @@ internal sealed unsafe partial class ShaderCompiler
throw new HlslCompilationException(message);
}
}
+
+#endif
diff --git a/src/TerraFX.Interop.Windows/DirectX/um/dxcapi/DirectX.cs b/src/TerraFX.Interop.Windows/DirectX/um/dxcapi/DirectX.cs
index 0963b55b..0448fa06 100644
--- a/src/TerraFX.Interop.Windows/DirectX/um/dxcapi/DirectX.cs
+++ b/src/TerraFX.Interop.Windows/DirectX/um/dxcapi/DirectX.cs
@@ -3,6 +3,8 @@
// 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;
@@ -15,3 +17,5 @@ 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/tests/ComputeSharp.Tests.Internals/ComputeSharp.Tests.Internals.csproj b/tests/ComputeSharp.Tests.Internals/ComputeSharp.Tests.Internals.csproj
index bb8d58fb..190815c1 100644
--- a/tests/ComputeSharp.Tests.Internals/ComputeSharp.Tests.Internals.csproj
+++ b/tests/ComputeSharp.Tests.Internals/ComputeSharp.Tests.Internals.csproj
@@ -4,6 +4,12 @@
net472;netcoreapp3.1;net6.0
false
AnyCPU;x64;ARM64
+ false
+
+
+
+
+ $(DefineConstants);DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
diff --git a/tests/ComputeSharp.Tests.Internals/ShaderCompilerTests.cs b/tests/ComputeSharp.Tests.Internals/ShaderCompilerTests.cs
index e563da4a..0c10427f 100644
--- a/tests/ComputeSharp.Tests.Internals/ShaderCompilerTests.cs
+++ b/tests/ComputeSharp.Tests.Internals/ShaderCompilerTests.cs
@@ -1,4 +1,6 @@
-using System;
+#if !DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
+
+using System;
using ComputeSharp.Exceptions;
using ComputeSharp.Shaders.Translation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -45,3 +47,5 @@ public class ShaderCompilerTests
using ComPtr dxcBlob = ShaderCompiler.Instance.CompileShader(faultyShader.AsSpan());
}
}
+
+#endif