Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion GameKit.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<Project Path="src/GameKit.Events/GameKit.Events.csproj" />
<Project Path="src/GameKit.RenderOrchestration/GameKit.RenderOrchestration.csproj" />
<Project Path="src/GameKit.SdlangCompileLib/GameKit.SdlangCompileLib.csproj" />
<Project Path="src/GameKit.SdlangCompilerCli/GameKit.SdlangCompilerCli.csproj" />
<Project Path="src/GameKit.SdlangCompileTask/GameKit.SdlangCompileTask.csproj" />
<Project Path="src/GameKit.ShaderCommon/GameKit.ShaderCommon.csproj" />
<Project Path="src/GameKit.DependencyInjection/GameKit.DependencyInjection.csproj" />
Expand Down
4 changes: 1 addition & 3 deletions docs/shaders.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ The targets file compiles every `SdlangShader` item before `CoreCompile` and exp

Generated shaders are runtime content. See [Content distribution](content-distribution.md) for the loose-directory, embedded-resource, and ZIP policies, with runnable tutorials for embedding generated shaders in an assembly and publishing content in a ZIP archive.

The Slang compiler is downloaded from [`stanoddly/slang-dxc-bundle`](https://github.com/stanoddly/slang-dxc-bundle) into `GameKit.SdlangCompileLib`'s `obj/` directory and stays there. The distribution includes the DXC downstream compiler required for DXIL output and provides bundles for every supported shader-compilation host: Linux x64/ARM64, Windows x64, and macOS x64/ARM64. DXIL generation is therefore required on every supported host and is never silently omitted. `GameKit.SdlangCompileLib` alone owns the shared download and extraction. Slang and DXC are build-host tooling and are never copied into the output or publish directory of a project that only compiles shaders. A project that needs Slang next to its own binaries opts in with `<CopySlangToOutput>true</CopySlangToOutput>` and imports `GameKit.SdlangCompileLib`'s props and targets directly. The property copies the complete Slang distribution, including DXC, to build and publish outputs. They remain external when publishing a single-file application because `slangc` must be executable by path.

Standalone applications should call `SdlangCompiler.CreateFromApplicationDirectory()`. It locates Slang relative to the application directory and supports single-file publishing. `SdlangCompiler.CreateFromAssemblyDirectory()` locates Slang relative to `GameKit.SdlangCompileLib.dll` and requires assembly files on disk, so it is not compatible with single-file applications. Build integrations should pass `$(SlangCompilerPath)` to the `SdlangCompiler` constructor instead of using either factory.
The Slang compiler is downloaded from [`stanoddly/slang-dxc-bundle`](https://github.com/stanoddly/slang-dxc-bundle) into `GameKit.SdlangCompileLib`'s `obj/` directory and stays there. The distribution includes the DXC downstream compiler required for DXIL output and provides bundles for every supported shader-compilation host: Linux x64/ARM64, Windows x64, and macOS x64/ARM64. DXIL generation is therefore required on every supported host and is never silently omitted. `GameKit.SdlangCompileLib` alone owns the shared download and extraction. Slang and DXC are build-host tooling and are never copied into application build or publish output. Build integrations pass `$(SlangCompilerPath)` to `SdlangCompiler`.

### Custom compilation targets

Expand Down
32 changes: 0 additions & 32 deletions src/GameKit.SdlangCompileLib/SdlangCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Buffers.Binary;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
Expand Down Expand Up @@ -63,37 +62,6 @@ public SdlangCompiler(string slangCompilerPath)
_slangCompilerPath = slangCompilerPath;
}

/// <summary>
/// Creates a compiler that uses the Slang distribution shipped next to the executing assembly.
/// Intended for standalone tools that carry their own copy of Slang; build integrations should
/// pass the path explicitly instead.
/// </summary>
[RequiresAssemblyFiles("Use CreateFromApplicationDirectory() for single-file applications.")]
public static SdlangCompiler CreateFromAssemblyDirectory()
{
string? assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (string.IsNullOrEmpty(assemblyDir))
{
throw new InvalidOperationException("Unable to determine assembly directory");
}

string slangExe = OperatingSystem.IsWindows() ? "slangc.exe" : "slangc";

return new SdlangCompiler(Path.Combine(assemblyDir, "bin", slangExe));
}

/// <summary>
/// Creates a compiler that uses the Slang distribution shipped next to the application.
/// Compatible with single-file applications because the distribution remains external to the
/// application bundle.
/// </summary>
public static SdlangCompiler CreateFromApplicationDirectory()
{
string slangExe = OperatingSystem.IsWindows() ? "slangc.exe" : "slangc";

return new SdlangCompiler(Path.Combine(AppContext.BaseDirectory, "bin", slangExe));
}

private static string GetSlangVersion()
{
AssemblyMetadataAttribute? attribute = typeof(SdlangCompiler).Assembly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,45 +42,4 @@
<Message Text="Slang extracted and cleaned up at $(SlangBaseDir)" Importance="high" Condition="'$(NeedsExtraction)' == 'true'" />
</Target>

<!-- Opt-in for tools that use a directory-based SdlangCompiler factory and therefore ship the
Slang distribution next to their own binaries. Build must finish first so the project
reference to the Slang installation owner has prepared the shared directory. Projects that
only compile shaders during the build should not enable this: Slang does not belong in their runtime bundle. -->
<Target Name="CopySlangToOutput" AfterTargets="Build"
Condition="'$(CopySlangToOutput)' == 'true'">
<ItemGroup>
<SlangBinFile Include="$(SlangBinDir)/**/*" />
<SlangLibFile Include="$(SlangLibDir)/**/*" />
</ItemGroup>

<Copy SourceFiles="@(SlangBinFile)"
DestinationFiles="@(SlangBinFile->'$(OutputPath)bin/%(RecursiveDir)%(Filename)%(Extension)')"
SkipUnchangedFiles="true" />
<Copy SourceFiles="@(SlangLibFile)"
DestinationFiles="@(SlangLibFile->'$(OutputPath)lib/%(RecursiveDir)%(Filename)%(Extension)')"
SkipUnchangedFiles="true" />
</Target>

<!-- Publish the Slang distribution as external files. slangc must be executable by path, so it
and its native libraries cannot be embedded in a single-file application bundle. -->
<Target Name="IncludeSlangInPublish"
AfterTargets="ComputeResolvedFilesToPublishList"
Condition="'$(CopySlangToOutput)' == 'true'">
<ItemGroup>
<SlangBinPublishFile Include="$(SlangBinDir)/**/*" />
<SlangLibPublishFile Include="$(SlangLibDir)/**/*" />

<ResolvedFileToPublish Include="@(SlangBinPublishFile)">
<RelativePath>bin/%(SlangBinPublishFile.RecursiveDir)%(Filename)%(Extension)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</ResolvedFileToPublish>
<ResolvedFileToPublish Include="@(SlangLibPublishFile)">
<RelativePath>lib/%(SlangLibPublishFile.RecursiveDir)%(Filename)%(Extension)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</ResolvedFileToPublish>
</ItemGroup>
</Target>

</Project>
24 changes: 0 additions & 24 deletions src/GameKit.SdlangCompilerCli/GameKit.SdlangCompilerCli.csproj

This file was deleted.

44 changes: 0 additions & 44 deletions src/GameKit.SdlangCompilerCli/Program.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<!-- The tests drive the compiler through SdlangCompiler.CreateFromAssemblyDirectory() -->
<CopySlangToOutput>true</CopySlangToOutput>
</PropertyGroup>

<Import Project="../../src/GameKit.SdlangCompileLib/build/GameKit.SdlangCompileLib.props" />
<Import Project="../../src/GameKit.SdlangCompileLib/build/GameKit.SdlangCompileLib.targets" />

<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>SlangCompilerPath</_Parameter1>
<_Parameter2>$(SlangCompilerPath)</_Parameter2>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="10.0.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.8.1"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private GraphicsShaderProgramMetadataDto Compile(string source)
{
string shaderPath = Path.Combine(_testDirectory, "program.slang");
File.WriteAllText(shaderPath, source);
SdlangCompiler compiler = SdlangCompiler.CreateFromAssemblyDirectory();
SdlangCompiler compiler = SdlangCompilerTestFactory.Create();
compiler.Compile([shaderPath], force: true);

string metadataPath = Path.Combine(_testDirectory, ".generated", "program.metadata.json");
Expand Down
Loading
Loading