diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml
index 0a269bd..982f35d 100644
--- a/.github/workflows/preview.yml
+++ b/.github/workflows/preview.yml
@@ -1,30 +1,44 @@
-name: Publish Preview NuGet Package
+name: Publish Development Preview NuGet Package
permissions:
- contents: write # needed to push tags and commits
- packages: write # optional – good practice when publishing packages
+ contents: read
+ packages: write
on:
push:
branches:
- - development # run on merge to develop (if you have a develop branch)
+ - development
jobs:
- build_and_publish:
+ build_and_publish_preview:
runs-on: ubuntu-latest
steps:
# Checkout repository
- uses: actions/checkout@v4
- with:
- fetch-depth: 0 # fetch full history for tags
- # Setup Git for committing and tagging
- - name: Set up Git
+ # Extract base version from CHANGELOG.md
+ - name: Extract version from CHANGELOG.md
+ id: extract_version
run: |
- git config user.name "github-actions[bot]"
- git config user.email "github-actions[bot]@users.noreply.github.com"
- git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
+ if [ ! -f CHANGELOG.md ]; then
+ echo "❌ CHANGELOG.md not found!"
+ exit 1
+ fi
+
+ BASE_VERSION=$(grep -m1 -oP '(?<=## \[)[^]]+' CHANGELOG.md)
+
+ if [ -z "$BASE_VERSION" ]; then
+ echo "❌ Could not extract version from CHANGELOG.md"
+ exit 1
+ fi
+
+ SHORT_SHA=$(git rev-parse --short HEAD)
+
+ PREVIEW_VERSION="${BASE_VERSION}-preview.${SHORT_SHA}"
+
+ echo "Preview version: $PREVIEW_VERSION"
+ echo "VERSION=$PREVIEW_VERSION" >> $GITHUB_ENV
# Setup .NET
- name: Setup .NET
@@ -32,82 +46,43 @@ jobs:
with:
dotnet-version: '8.0.x'
- # Bump preview version
- - name: Bump preview version
- run: |
- CSPROJS=(
- "./RisShaderToolkit/RisShaderToolkit/RisShaderToolkit.csproj"
- )
- for csproj in "${CSPROJS[@]}"; do
- echo "Processing $csproj"
- CURRENT_VERSION=$(grep -oP '(?<=).*?(?=)' "$csproj")
- if [[ -z "$CURRENT_VERSION" ]]; then
- echo "Warning: No found in $csproj"
- continue
- fi
- PREVIEW_NUMBER=$(echo "$CURRENT_VERSION" | grep -oP '(?<=-preview\.)\d+' || echo "0")
- NEW_PREVIEW_NUMBER=$((PREVIEW_NUMBER + 1))
- NEW_VERSION=$(echo "$CURRENT_VERSION" | sed -E "s/(.*-preview\.)[0-9]+/\1$NEW_PREVIEW_NUMBER/")
- if [[ "$CURRENT_VERSION" != *"-preview."* ]]; then
- NEW_VERSION="${CURRENT_VERSION}-preview.1"
- fi
- echo "Bumping $CURRENT_VERSION → $NEW_VERSION in $csproj"
- sed -i "s#.*#$NEW_VERSION#g" "$csproj"
- git add "$csproj"
- done
- git commit -m "Bump preview version to $NEW_VERSION" || echo "No changes to commit"
- git push origin development || echo "Push failed (maybe no changes)"
- echo "VERSION=$NEW_VERSION" >> "$GITHUB_ENV"
-
# Build
- name: Build
run: dotnet build ./RisShaderToolkit/RisShaderToolkit.sln --configuration Release
- # Pack
+ # Pack with preview version
- name: Pack
- run: dotnet pack ./RisShaderToolkit/RisShaderToolkit.sln --configuration Release --no-build
+ run: |
+ dotnet pack ./RisShaderToolkit/RisShaderToolkit.sln \
+ --configuration Release \
+ --no-build \
+ /p:PackageVersion=${{ env.VERSION }}
# Find NuGet package
- name: Find NuGet packages
id: find_pkgs
run: |
mapfile -t packages < <(find ./RisShaderToolkit -name "*.nupkg" ! -name "*symbols*.nupkg")
+
if [ ${#packages[@]} -eq 0 ]; then
- echo "Error: No .nupkg files found!"
+ echo "❌ No .nupkg files found!"
exit 1
fi
+
{
echo "packages<> $GITHUB_OUTPUT
- # Publish to NuGet
- - name: Publish all NuGet packages
+ # Publish preview packages
+ - name: Publish preview NuGet packages
run: |
while IFS= read -r pkg; do
[[ -z "$pkg" ]] && continue
- echo "Publishing $pkg"
+ echo "Publishing preview $pkg"
dotnet nuget push "$pkg" \
--api-key ${{ secrets.NUGET_API_KEY }} \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
done <<< "${{ steps.find_pkgs.outputs.packages }}"
-
- - name: Create and push git tag
- run: |
- git tag "v${{ env.VERSION }}"
- git push origin "v${{ env.VERSION }}"
-
- # Create GitHub Release
- - name: Create GitHub Release
- uses: softprops/action-gh-release@v2
- with:
- tag_name: v${{ env.VERSION }}
- name: Preview ${{ env.VERSION }}
- draft: false
- prerelease: true
- generate_release_notes: true
- files: |
- ${{ steps.find_pkgs.outputs.packages }}
- overwrite: true # equivalent to overwrite_files: true in newer versions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9f98958..a24ac7d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog
+## [0.2.0] - 2026-03-21
+
+### Added
+- `Slang` to `glsl` shader compilation is now supported.
+- `CompileSlangToGlsl` method was added to the `ShaderCompiler`.
+
## [0.1.0] - 2026-03-04
### Added
diff --git a/README.md b/README.md
index a8bd7a9..1b1aedd 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,9 @@ The toolkit consists of two main parts:
- Provides easy-to-use methods for compiling Slang shaders into multiple target formats:
- WGSL
- SPIR-V
+ - GLSL
- possibly others in the future
+
- Published as **NuGet package(s)**
- Used by **RisGameFramework** but can be used by any other .NET project
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client.Desktop/Program.cs b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client.Desktop/Program.cs
deleted file mode 100644
index 8a189d3..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client.Desktop/Program.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using System;
-
-using Avalonia;
-
-namespace RisGameFramework.ShaderToolkit.Client.Desktop;
-
-class Program
-{
- // Initialization code. Don't use any Avalonia, third-party APIs or any
- // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
- // yet and stuff might break.
- [STAThread]
- public static void Main(string[] args) => BuildAvaloniaApp()
- .StartWithClassicDesktopLifetime(args);
-
- // Avalonia configuration, don't remove; also used by visual designer.
- public static AppBuilder BuildAvaloniaApp()
- => AppBuilder.Configure()
- .UsePlatformDetect()
- .WithInterFont()
- .LogToTrace();
-
-}
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client.Desktop/RisGameFramework.ShaderToolkit.Client.Desktop.csproj b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client.Desktop/RisGameFramework.ShaderToolkit.Client.Desktop.csproj
deleted file mode 100644
index b4a898e..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client.Desktop/RisGameFramework.ShaderToolkit.Client.Desktop.csproj
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
- WinExe
-
- net8.0
- enable
- true
- app.manifest
-
-
-
-
-
-
-
-
-
-
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client.Desktop/app.manifest b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client.Desktop/app.manifest
deleted file mode 100644
index e0ce8d0..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client.Desktop/app.manifest
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/App.axaml b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/App.axaml
deleted file mode 100644
index cb427e8..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/App.axaml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/App.axaml.cs b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/App.axaml.cs
deleted file mode 100644
index b1ff05c..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/App.axaml.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using Avalonia;
-using Avalonia.Controls.ApplicationLifetimes;
-using Avalonia.Data.Core.Plugins;
-using Avalonia.Markup.Xaml;
-
-using RisGameFramework.ShaderToolkit.Client.ViewModels;
-using RisGameFramework.ShaderToolkit.Client.Views;
-
-namespace RisGameFramework.ShaderToolkit.Client;
-
-public partial class App : Application
-{
- public override void Initialize()
- {
- AvaloniaXamlLoader.Load(this);
- }
-
- public override void OnFrameworkInitializationCompleted()
- {
- // Line below is needed to remove Avalonia data validation.
- // Without this line you will get duplicate validations from both Avalonia and CT
- BindingPlugins.DataValidators.RemoveAt(0);
-
- if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
- {
- desktop.MainWindow = new MainWindow
- {
- DataContext = new MainViewModel()
- };
- }
- else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
- {
- singleViewPlatform.MainView = new MainView
- {
- DataContext = new MainViewModel()
- };
- }
-
- base.OnFrameworkInitializationCompleted();
- }
-}
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Assets/avalonia-logo.ico b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Assets/avalonia-logo.ico
deleted file mode 100644
index da8d49f..0000000
Binary files a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Assets/avalonia-logo.ico and /dev/null differ
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Controls/Editor.axaml b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Controls/Editor.axaml
deleted file mode 100644
index 36cc1ce..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Controls/Editor.axaml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Controls/Editor.axaml.cs b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Controls/Editor.axaml.cs
deleted file mode 100644
index f761a0e..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Controls/Editor.axaml.cs
+++ /dev/null
@@ -1,65 +0,0 @@
-using Avalonia;
-using Avalonia.Controls;
-using AvaloniaEdit.TextMate;
-using System;
-using TextMateSharp.Grammars;
-using static AvaloniaEdit.TextMate.TextMate;
-
-namespace RisGameFramework.ShaderToolkit.Client.Controls;
-
-///
-/// The shader editor control.
-///
-public partial class Editor : UserControl
-{
- private const string HLSL_GRAMMAR_EXTENSION = ".hlsl";
-
- private RegistryOptions _registryOptions;
- private Installation _textMateInstallation;
-
- ///
- /// The constructor.
- ///
- public Editor()
- {
- InitializeComponent();
-
- // Setup TextMate with a VS Code-like dark theme
- _registryOptions = new RegistryOptions(ThemeName.DarkPlus);
- _textMateInstallation = ShaderEditorInstance.InstallTextMate(_registryOptions);
- Language language = _registryOptions.GetLanguageByExtension(HLSL_GRAMMAR_EXTENSION);
- _textMateInstallation.SetGrammar(_registryOptions.GetScopeByLanguageId(_registryOptions.GetLanguageByExtension(HLSL_GRAMMAR_EXTENSION).Id));
-
- ShaderEditorInstance.TextChanged += (s, e) =>
- {
- SetValue(SourceProperty, ShaderEditorInstance.Text);
- SourceChanged?.Invoke(this, e);
- };
- }
-
- ///
- /// Invoked whenever source text is changed.
- ///
- public event EventHandler SourceChanged;
-
- ///
- /// The source property.
- ///
- public static readonly StyledProperty SourceProperty = AvaloniaProperty.Register(nameof(Source), "");
-
- ///
- /// The source shader text.
- ///
- public string Source
- {
- get
- {
- return GetValue(SourceProperty);
- }
- set
- {
- SetValue(SourceProperty, value);
- ShaderEditorInstance?.Text = value;
- }
- }
-}
\ No newline at end of file
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Controls/TextViewer.axaml b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Controls/TextViewer.axaml
deleted file mode 100644
index 5b822d8..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Controls/TextViewer.axaml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Controls/TextViewer.axaml.cs b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Controls/TextViewer.axaml.cs
deleted file mode 100644
index 8670c78..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Controls/TextViewer.axaml.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-using Avalonia;
-using Avalonia.Controls;
-using Avalonia.Reactive;
-using AvaloniaEdit.TextMate;
-using System;
-using TextMateSharp.Grammars;
-using static AvaloniaEdit.TextMate.TextMate;
-
-namespace RisGameFramework.ShaderToolkit.Client.Controls;
-
-///
-/// The component which is created to view compiled shader content.
-///
-public partial class TextViewer : UserControl
-{
- private const string HLSL_GRAMMAR_EXTENSION = ".hlsl";
-
- private RegistryOptions _registryOptions;
- private Installation _textMateInstallation;
-
- ///
- /// The constructor.
- ///
- public TextViewer()
- {
- InitializeComponent();
-
- // Setup TextMate with a VS Code-like dark theme
- _registryOptions = new RegistryOptions(ThemeName.DarkPlus);
- _textMateInstallation = ShaderViewerInstance.InstallTextMate(_registryOptions);
- Language language = _registryOptions.GetLanguageByExtension(HLSL_GRAMMAR_EXTENSION);
- _textMateInstallation.SetGrammar(_registryOptions.GetScopeByLanguageId(_registryOptions.GetLanguageByExtension(HLSL_GRAMMAR_EXTENSION).Id));
-
-
- IObserver> observer = new AnonymousObserver>(args =>
- {
- ShaderViewerInstance.Text = args.NewValue.Value;
- });
- TextProperty.Changed.Subscribe(observer);
- }
-
- ///
- /// Invoked whenever source text is changed.
- ///
- public event EventHandler SourceChanged;
-
- ///
- /// The compiled shader text property.
- ///
- public static readonly StyledProperty TextProperty = AvaloniaProperty.Register(nameof(Text), "");
-
- ///
- /// The compiled shader text.
- ///
- public string Text
- {
- get
- {
- return GetValue(TextProperty);
- }
- set
- {
- SetValue(TextProperty, value);
- ShaderViewerInstance?.Text = value;
- }
- }
-}
\ No newline at end of file
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Resources/Colors.axaml b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Resources/Colors.axaml
deleted file mode 100644
index c92ed81..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Resources/Colors.axaml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
- #2B2B2B
- #D9DDDC
- #888A89
- #A3A5A4
-
- #D9DDDC
- #2B2B2B
-
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/RisGameFramework.ShaderToolkit.Client.csproj b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/RisGameFramework.ShaderToolkit.Client.csproj
deleted file mode 100644
index d465818..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/RisGameFramework.ShaderToolkit.Client.csproj
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
- net8.0
- enable
- latest
- true
- RisGameFramework.ShaderToolkit
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/UserControls/TargetWidget.axaml b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/UserControls/TargetWidget.axaml
deleted file mode 100644
index e5ed837..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/UserControls/TargetWidget.axaml
+++ /dev/null
@@ -1,39 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/UserControls/TargetWidget.axaml.cs b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/UserControls/TargetWidget.axaml.cs
deleted file mode 100644
index 83790f2..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/UserControls/TargetWidget.axaml.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using Avalonia;
-using Avalonia.Controls;
-using Avalonia.Controls.Platform;
-using Avalonia.Markup.Xaml;
-
-namespace RisGameFramework.ShaderToolkit.UserControls;
-
-public partial class TargetWidget : UserControl
-{
- public TargetWidget()
- {
- InitializeComponent();
- }
-}
\ No newline at end of file
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/ViewModels/EditorViewModel.cs b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/ViewModels/EditorViewModel.cs
deleted file mode 100644
index 8a18337..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/ViewModels/EditorViewModel.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using CommunityToolkit.Mvvm.ComponentModel;
-
-namespace RisGameFramework.ShaderToolkit.Client.ViewModels;
-
-///
-/// The editor view model.
-///
-public partial class EditorViewModel : ObservableObject
-{
-
-}
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/ViewModels/MainViewModel.cs b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/ViewModels/MainViewModel.cs
deleted file mode 100644
index b23371a..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/ViewModels/MainViewModel.cs
+++ /dev/null
@@ -1,81 +0,0 @@
-using CommunityToolkit.Mvvm.ComponentModel;
-using RisShaderToolkit;
-using System.Collections.Generic;
-
-namespace RisGameFramework.ShaderToolkit.Client.ViewModels;
-
-public partial class MainViewModel : ViewModelBase
-{
- private readonly ShaderCompiler _compiler = new ShaderCompiler();
-
- [ObservableProperty]
- private string _sourceShaderCode = @"
- void main()
- {
- gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
- }";
-
- [ObservableProperty]
- private string _targetShaderCode = "";
-
- internal List ProfileTypes { get; } = [
- ProfileType.GLSL,
- ProfileType.SLANG,
- ProfileType.HLSL
- ];
-
- internal List GlslProfiles { get; } = [
- GlslProfile.GLSL_330,
- GlslProfile.GLSL_400,
- GlslProfile.GLSL_410,
- GlslProfile.GLSL_420,
- GlslProfile.GLSL_430,
- GlslProfile.GLSL_450,
- GlslProfile.GLSL_460,
- GlslProfile.GLES_300,
- GlslProfile.GLES_310,
- GlslProfile.GLES_320,
- ];
-
- internal List ShaderStages { get; } = [
- ShaderStage.VERTEX,
- ShaderStage.FRAGMENT,
- ShaderStage.COMPUTE,
- ];
-
- [ObservableProperty]
- private ProfileType _sourceProfileType = ProfileType.SLANG;
-
- [ObservableProperty]
- private ProfileType _targetProfileType = ProfileType.GLSL;
-
- [ObservableProperty]
- private GlslProfile _targetGlslProfile = GlslProfile.GLES_300;
-
- [ObservableProperty]
- private ShaderStage _targetShaderStage = ShaderStage.VERTEX;
-
- public MainViewModel()
- {
-
- }
-
- public void Build()
- {
- CompileResult? compileResult = null;
- if(SourceProfileType == ProfileType.SLANG && TargetProfileType == ProfileType.GLSL)
- {
- compileResult = _compiler.CompileSlangSourceCodeToGlsl(SourceShaderCode, TargetGlslProfile, ShaderStage.VERTEX, "main_vs");
- }
-
- if (compileResult?.Success == true)
- {
- TargetShaderCode = compileResult.SourceCode!;
- }
- }
-
- partial void OnSourceShaderCodeChanged(string value)
- {
- Build();
- }
-}
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/ViewModels/ViewModelBase.cs b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/ViewModels/ViewModelBase.cs
deleted file mode 100644
index 5705bcc..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/ViewModels/ViewModelBase.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-using CommunityToolkit.Mvvm.ComponentModel;
-
-namespace RisGameFramework.ShaderToolkit.Client.ViewModels;
-
-public class ViewModelBase : ObservableObject
-{
-}
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Views/MainView.axaml b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Views/MainView.axaml
deleted file mode 100644
index 5db0c67..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Views/MainView.axaml
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Views/MainView.axaml.cs b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Views/MainView.axaml.cs
deleted file mode 100644
index 72b4af3..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Views/MainView.axaml.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using Avalonia.Controls;
-using AvaloniaEdit.TextMate;
-using TextMateSharp.Grammars;
-
-namespace RisGameFramework.ShaderToolkit.Client.Views;
-
-public partial class MainView : UserControl
-{
- private TextMate.Installation _textMateInstallation;
-
- public MainView()
- {
- InitializeComponent();
-
-
- }
-}
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Views/MainWindow.axaml b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Views/MainWindow.axaml
deleted file mode 100644
index 9a86df1..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Views/MainWindow.axaml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
diff --git a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Views/MainWindow.axaml.cs b/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Views/MainWindow.axaml.cs
deleted file mode 100644
index 06bbe0b..0000000
--- a/RisShaderToolkit/RisGameFramework.ShaderToolkit.Client/Views/MainWindow.axaml.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using Avalonia.Controls;
-
-namespace RisGameFramework.ShaderToolkit.Client.Views;
-
-public partial class MainWindow : Window
-{
- public MainWindow()
- {
- InitializeComponent();
- }
-}
diff --git a/RisShaderToolkit/RisShaderToolkit.Tests/Data/compile.json b/RisShaderToolkit/RisShaderToolkit.Tests/Data/compile.json
index a4e3c7d..02eaffd 100644
--- a/RisShaderToolkit/RisShaderToolkit.Tests/Data/compile.json
+++ b/RisShaderToolkit/RisShaderToolkit.Tests/Data/compile.json
@@ -1,5 +1,4 @@
{
- "compiler_verson": "0.0.1",
"shaders": [
{
"name": "sprite.slang",
@@ -7,15 +6,6 @@
"source_profile": "slang",
"stage": "vertex",
"profile": "gles_300",
- "rules": {
- "input_name_rule": {
- "prefix": "in_"
- },
- "output_name_rule": {
- "prefix": "out_",
- "trim_entry_point_name": true
- }
- }
},
{
"name": "sprite.slang",
@@ -23,15 +13,6 @@
"source_profile": "slang",
"stage": "fragment",
"profile": "gles_300",
- "rules": {
- "input_name_rule": {
- "prefix": "in_"
- },
- "output_name_rule": {
- "prefix": "out_",
- "trim_entry_point_name": true
- }
- }
}
]
}
\ No newline at end of file
diff --git a/RisShaderToolkit/RisShaderToolkit.Tests/Data/compile_slang_to_glsl.json b/RisShaderToolkit/RisShaderToolkit.Tests/Data/compile_slang_to_glsl.json
new file mode 100644
index 0000000..5b66010
--- /dev/null
+++ b/RisShaderToolkit/RisShaderToolkit.Tests/Data/compile_slang_to_glsl.json
@@ -0,0 +1,16 @@
+{
+ "shaders": [
+ {
+ "name": "sprite.slang",
+ "profile": "glsl_450",
+ "stages": [ "vertex", "fragment" ],
+ "output_file": "sprite.glsl"
+ },
+ {
+ "name": "sprite.slang",
+ "profile": "gles_300",
+ "stages": [ "vertex", "fragment" ],
+ "output_file": "sprite_300es.glsl"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/RisShaderToolkit/RisShaderToolkit.Tests/Data/compile_slang_to_spirv.json b/RisShaderToolkit/RisShaderToolkit.Tests/Data/compile_slang_to_spirv.json
index 189bbbb..e5b7156 100644
--- a/RisShaderToolkit/RisShaderToolkit.Tests/Data/compile_slang_to_spirv.json
+++ b/RisShaderToolkit/RisShaderToolkit.Tests/Data/compile_slang_to_spirv.json
@@ -1,9 +1,9 @@
{
- "compiler_verson": "0.0.1",
"shaders": [
{
"name": "sprite.slang",
"profile": "spirv_1_2",
+ "stages": [ "vertex", "fragment" ],
"output_file": "sprite.spv"
}
]
diff --git a/RisShaderToolkit/RisShaderToolkit.Tests/Data/compile_slang_to_wgsl.json b/RisShaderToolkit/RisShaderToolkit.Tests/Data/compile_slang_to_wgsl.json
index 1ec2afd..dc654c5 100644
--- a/RisShaderToolkit/RisShaderToolkit.Tests/Data/compile_slang_to_wgsl.json
+++ b/RisShaderToolkit/RisShaderToolkit.Tests/Data/compile_slang_to_wgsl.json
@@ -4,6 +4,7 @@
{
"name": "sprite.slang",
"profile": "wgsl",
+ "stages": [ "vertex", "fragment" ],
"output_file": "sprite.wgsl"
}
]
diff --git a/RisShaderToolkit/RisShaderToolkit.Tests/RisShaderToolkit.Tests.csproj b/RisShaderToolkit/RisShaderToolkit.Tests/RisShaderToolkit.Tests.csproj
index 927499b..e4dbc9a 100644
--- a/RisShaderToolkit/RisShaderToolkit.Tests/RisShaderToolkit.Tests.csproj
+++ b/RisShaderToolkit/RisShaderToolkit.Tests/RisShaderToolkit.Tests.csproj
@@ -1,7 +1,7 @@
- net10.0
+ net8.0
enable
enable
@@ -30,6 +30,9 @@
PreserveNewest
+
+ PreserveNewest
+
PreserveNewest
diff --git a/RisShaderToolkit/RisShaderToolkit.Tests/SlangToGlslTests.cs b/RisShaderToolkit/RisShaderToolkit.Tests/SlangToGlslTests.cs
new file mode 100644
index 0000000..bc7288e
--- /dev/null
+++ b/RisShaderToolkit/RisShaderToolkit.Tests/SlangToGlslTests.cs
@@ -0,0 +1,150 @@
+namespace RisShaderToolkit.Tests;
+
+///
+/// Tests for compiling Slang shaders to GLSL.
+///
+public class SlangToGlslTests
+{
+ ///
+ /// Test compiling a Slang shader source code to GLSL.
+ ///
+ [Fact]
+ public void TestCompileSlangToGlsl()
+ {
+ // Arrange
+ ShaderCompiler compiler = new ShaderCompiler();
+ string slangSourceCode = File.ReadAllText("Data/sprite.slang");
+ // Act
+ CompileResult vertexResult = compiler.CompileSlangToGlsl(slangSourceCode,
+ ShaderStage.VERTEX,
+ GlslProfile.GLSL_450,
+ "main_vs");
+
+ Assert.True(vertexResult.Success);
+ Assert.NotNull(vertexResult.SourceCode);
+ Assert.True(vertexResult.SourceCode.Length > 0);
+ Assert.Contains("main()", vertexResult.SourceCode);
+
+ // Act
+ CompileResult fragmentResult = compiler.CompileSlangToGlsl(slangSourceCode,
+ ShaderStage.FRAGMENT,
+ GlslProfile.GLSL_450,
+ "main_fs");
+
+ Assert.True(fragmentResult.Success);
+ Assert.NotNull(fragmentResult.SourceCode);
+ Assert.True(fragmentResult.SourceCode.Length > 0);
+ Assert.Contains("main()", fragmentResult.SourceCode);
+ }
+
+ ///
+ /// Test compiling a Slang shader source code to SPIR-V.
+ ///
+ [Fact]
+ public void TestCompileSlangToGlsl2()
+ {
+ // Arrange
+ ShaderCompiler compiler = new ShaderCompiler();
+ string slangSourceCode = File.ReadAllText("Data/sprite.slang");
+ // Act
+ CompileResult vertexResult = compiler.CompileSlangToGlsl(slangSourceCode,
+ ShaderStage.VERTEX);
+
+ Assert.True(vertexResult.Success);
+ Assert.NotNull(vertexResult.SourceCode);
+ Assert.True(vertexResult.SourceCode.Length > 0);
+ Assert.Contains("main()", vertexResult.SourceCode);
+
+ // Act
+ CompileResult fragmentResult = compiler.CompileSlangToGlsl(slangSourceCode,
+ ShaderStage.FRAGMENT);
+
+ Assert.True(fragmentResult.Success);
+ Assert.NotNull(fragmentResult.SourceCode);
+ Assert.True(fragmentResult.SourceCode.Length > 0);
+ Assert.Contains("main()", fragmentResult.SourceCode);
+ }
+
+ ///
+ /// Test compiling a Slang shader source code to GLSL.
+ ///
+ [Fact]
+ public void TestCompileSlangToGlsl300es()
+ {
+ // Arrange
+ ShaderCompiler compiler = new ShaderCompiler();
+ string slangSourceCode = File.ReadAllText("Data/sprite.slang");
+ // Act
+ CompileResult vertexResult = compiler.CompileSlangToGlsl(slangSourceCode,
+ ShaderStage.VERTEX,
+ GlslProfile.GLES_300,
+ "main_vs");
+
+ Assert.True(vertexResult.Success);
+ Assert.NotNull(vertexResult.SourceCode);
+ Assert.True(vertexResult.SourceCode.Length > 0);
+ Assert.Contains("main()", vertexResult.SourceCode);
+
+ // Act
+ CompileResult fragmentResult = compiler.CompileSlangToGlsl(slangSourceCode,
+ ShaderStage.FRAGMENT,
+ GlslProfile.GLES_300,
+ "main_fs");
+
+ Assert.True(fragmentResult.Success);
+ Assert.NotNull(fragmentResult.SourceCode);
+ Assert.True(fragmentResult.SourceCode.Length > 0);
+ Assert.Contains("main()", fragmentResult.SourceCode);
+ }
+
+
+ ///
+ /// Test compiling a Slang shader source code to GLSL.
+ ///
+ [Fact]
+ public void TestCompileSlangToGlsl300Es2()
+ {
+ // Arrange
+ ShaderCompiler compiler = new ShaderCompiler();
+ string slangSourceCode = File.ReadAllText("Data/sprite.slang");
+ // Act
+ CompileResult vertexResult = compiler.CompileSlangToGlsl(slangSourceCode,
+ ShaderStage.VERTEX,
+ GlslProfile.GLES_300);
+
+ Assert.True(vertexResult.Success);
+ Assert.NotNull(vertexResult.SourceCode);
+ Assert.True(vertexResult.SourceCode.Length > 0);
+ Assert.Contains("main()", vertexResult.SourceCode);
+
+ // Act
+ CompileResult fragmentResult = compiler.CompileSlangToGlsl(slangSourceCode,
+ ShaderStage.FRAGMENT,
+ GlslProfile.GLES_300);
+
+ Assert.True(fragmentResult.Success);
+ Assert.NotNull(fragmentResult.SourceCode);
+ Assert.True(fragmentResult.SourceCode.Length > 0);
+ Assert.Contains("main()", fragmentResult.SourceCode);
+ }
+
+ ///
+ /// Compiles shaders from a JSON file.
+ /// Tests Slang to SpirV JSON compilation.
+ ///
+ [Fact]
+ public void TestCompileGlslJson()
+ {
+ // Arrange
+ ShaderCompiler compiler = new ShaderCompiler();
+ string jsonFilePath = "Data/compile_slang_to_glsl.json";
+ // Act
+ compiler.CompileFromJson(jsonFilePath);
+ // If we reach this point, the compilation was successful.
+ Assert.True(true);
+ foreach (var result in compiler.CompileFromJson(jsonFilePath).Results)
+ {
+ Assert.True(result.Success);
+ }
+ }
+}
diff --git a/RisShaderToolkit/RisShaderToolkit.Tests/SlangToSpirVTests.cs b/RisShaderToolkit/RisShaderToolkit.Tests/SlangToSpirVTests.cs
index c9a8c5e..23d936e 100644
--- a/RisShaderToolkit/RisShaderToolkit.Tests/SlangToSpirVTests.cs
+++ b/RisShaderToolkit/RisShaderToolkit.Tests/SlangToSpirVTests.cs
@@ -15,14 +15,24 @@ public void TestCompileSlangToSpirV()
ShaderCompiler compiler = new ShaderCompiler();
string slangSourceCode = File.ReadAllText("Data/sprite.slang");
// Act
- CompileResult result = compiler.CompileSlangToSpirV(slangSourceCode,
- [ShaderStage.VERTEX, ShaderStage.FRAGMENT],
+ CompileResult vertexResult = compiler.CompileSlangToSpirV(slangSourceCode,
+ [ShaderStage.VERTEX],
SpirVProfile.SPIRV_1_2,
- ["main_vs", "main_fs"]);
+ "main_vs");
- Assert.True(result.Success);
- Assert.NotNull(result.BinarySourceCode);
- Assert.True(result.BinarySourceCode.Length > 0);
+ Assert.True(vertexResult.Success);
+ Assert.NotNull(vertexResult.BinarySourceCode);
+ Assert.True(vertexResult.BinarySourceCode.Length > 0);
+
+ // Act
+ CompileResult fragmentResult = compiler.CompileSlangToSpirV(slangSourceCode,
+ [ShaderStage.FRAGMENT],
+ SpirVProfile.SPIRV_1_2,
+ "main_fs");
+
+ Assert.True(fragmentResult.Success);
+ Assert.NotNull(fragmentResult.BinarySourceCode);
+ Assert.True(fragmentResult.BinarySourceCode.Length > 0);
}
///
@@ -35,10 +45,15 @@ public void TestCompileSlangToSpirV2()
ShaderCompiler compiler = new ShaderCompiler();
string slangSourceCode = File.ReadAllText("Data/sprite.slang");
// Act
- CompileResult result = compiler.CompileSlangToSpirV(slangSourceCode, [ShaderStage.VERTEX, ShaderStage.FRAGMENT], entryPoints: []);
- Assert.True(result.Success);
- Assert.NotNull(result.BinarySourceCode);
- Assert.True(result.BinarySourceCode.Length > 0);
+ CompileResult vertexResult = compiler.CompileSlangToSpirV(slangSourceCode, [ShaderStage.VERTEX]);
+ Assert.True(vertexResult.Success);
+ Assert.NotNull(vertexResult.BinarySourceCode);
+ Assert.True(vertexResult.BinarySourceCode.Length > 0);
+
+ CompileResult fragmentResult = compiler.CompileSlangToSpirV(slangSourceCode, [ShaderStage.FRAGMENT]);
+ Assert.True(fragmentResult.Success);
+ Assert.NotNull(fragmentResult.BinarySourceCode);
+ Assert.True(fragmentResult.BinarySourceCode.Length > 0);
}
///
@@ -46,8 +61,10 @@ public void TestCompileSlangToSpirV2()
/// Tests Slang to SpirV JSON compilation.
///
[Fact]
- public void TestCompilSpirVJson()
+ public void TestCompileSpirVJson()
{
+ // TODO: fix when removing automapper.
+
// Arrange
ShaderCompiler compiler = new ShaderCompiler();
string jsonFilePath = "Data/compile_slang_to_spirv.json";
diff --git a/RisShaderToolkit/RisShaderToolkit/AutoMapperProfile.cs b/RisShaderToolkit/RisShaderToolkit/AutoMapperProfile.cs
deleted file mode 100644
index ff7bd25..0000000
--- a/RisShaderToolkit/RisShaderToolkit/AutoMapperProfile.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using AutoMapper;
-using RisShaderToolkit.Dto;
-using RisShaderToolkit.Json;
-using RisShaderToolkit.Rules;
-using System;
-
-namespace RisShaderToolkit
-{
- internal class AutoMapperProfile : Profile
- {
- private static AnyProfile? ResolveProfile(string? profileStr)
- {
- if (String.IsNullOrEmpty(profileStr))
- {
- return null;
- }
-
- if (Enum.TryParse(profileStr, ignoreCase: true, out AnyProfile value))
- {
- return value;
- }
-
- throw new InvalidOperationException($"Unsupported profile type: {profileStr}.");
- }
-
- public AutoMapperProfile()
- {
- CreateMap();
- CreateMap();
- CreateMap()
- .ForMember(dest => dest.OutputFilePath, opt => opt.MapFrom(src => src.OutputFile))
- .ForMember(dest => dest.InputNameRule, opt => opt.MapFrom(src => src.Rules != null ? src.Rules.InputNameRule : null))
- .ForMember(dest => dest.OutputNameRule, opt => opt.MapFrom(src => src.Rules != null ? src.Rules.OutputNameRule : null))
- .ForMember(dest => dest.Profile, opt => opt.MapFrom(src => ResolveProfile(src.Profile)))
- .ForMember(dest => dest.SourceProfile, opt => opt.MapFrom(src => ResolveProfile(src.SourceProfile)));
-
-
-
- }
- }
-}
diff --git a/RisShaderToolkit/RisShaderToolkit/Dto/ShaderCompileTaskDto.cs b/RisShaderToolkit/RisShaderToolkit/Dto/ShaderCompileTaskDto.cs
index 140977a..adbda50 100644
--- a/RisShaderToolkit/RisShaderToolkit/Dto/ShaderCompileTaskDto.cs
+++ b/RisShaderToolkit/RisShaderToolkit/Dto/ShaderCompileTaskDto.cs
@@ -1,6 +1,4 @@
-using RisShaderToolkit.Rules;
-
-namespace RisShaderToolkit.Dto;
+namespace RisShaderToolkit.Dto;
///
/// The shader to compile.
@@ -25,7 +23,7 @@ internal record ShaderCompileTaskDto
///
/// The stage of the shader to compile.
///
- public ShaderStage[]? Stages { get; set; }
+ public List Stages { get; set; } = new();
///
/// The target profile for the shader.
@@ -36,14 +34,4 @@ internal record ShaderCompileTaskDto
/// The source profile of the shader.
///
public AnyProfile? SourceProfile { get; set; }
-
- ///
- /// The input name rule to apply to the shader.
- ///
- public ReplaceStageInputNameRule? InputNameRule { get; set; }
-
- ///
- /// The output name rule to apply to the shader.
- ///
- public ReplaceStageOutputNameRule? OutputNameRule { get; set; }
}
diff --git a/RisShaderToolkit/RisShaderToolkit/Json/ReplaceStageInputNameRuleJson.cs b/RisShaderToolkit/RisShaderToolkit/Json/ReplaceStageInputNameRuleJson.cs
deleted file mode 100644
index 28b2468..0000000
--- a/RisShaderToolkit/RisShaderToolkit/Json/ReplaceStageInputNameRuleJson.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-namespace RisShaderToolkit.Json;
-
-///
-/// The input name rule JSON representation.
-///
-public class ReplaceStageInputNameRuleJson
-{
- ///
- /// The prefix to add to input names.
- ///
- public string Prefix { get; set; } = string.Empty;
-}
diff --git a/RisShaderToolkit/RisShaderToolkit/Json/ReplaceStageOutputNameRuleJson.cs b/RisShaderToolkit/RisShaderToolkit/Json/ReplaceStageOutputNameRuleJson.cs
deleted file mode 100644
index 5e0ae88..0000000
--- a/RisShaderToolkit/RisShaderToolkit/Json/ReplaceStageOutputNameRuleJson.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-namespace RisShaderToolkit.Json;
-
-///
-/// The output name rule JSON representation.
-///
-public class ReplaceStageOutputNameRuleJson
-{
- ///
- /// The prefix to add to the stage output names.
- ///
- public string? Prefix { get; set; }
-
- ///
- /// Sets whether to trim the entry point name from output variable names.
- ///
- public bool TrimEntryPointName { get; set; }
-}
diff --git a/RisShaderToolkit/RisShaderToolkit/Json/RulesJson.cs b/RisShaderToolkit/RisShaderToolkit/Json/RulesJson.cs
deleted file mode 100644
index 3c21c6e..0000000
--- a/RisShaderToolkit/RisShaderToolkit/Json/RulesJson.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-namespace RisShaderToolkit.Json;
-
-///
-/// The rules JSON representation.
-///
-public class RulesJson
-{
- ///
- /// The input name rule.
- ///
- public ReplaceStageInputNameRuleJson? InputNameRule { get; set; }
-
- ///
- /// The output name rule.
- ///
- public ReplaceStageOutputNameRuleJson? OutputNameRule { get; set; }
-}
diff --git a/RisShaderToolkit/RisShaderToolkit/Json/ShaderJson.cs b/RisShaderToolkit/RisShaderToolkit/Json/ShaderJson.cs
index 92895e4..f33fb45 100644
--- a/RisShaderToolkit/RisShaderToolkit/Json/ShaderJson.cs
+++ b/RisShaderToolkit/RisShaderToolkit/Json/ShaderJson.cs
@@ -20,6 +20,12 @@ public class ShaderJson
///
public string[]? EntryPoints { get; set; }
+ ///
+ /// The stage of the shader to compile.
+ /// This is used if the shader only has one stage, and is mutually exclusive with the `stages` property, which is used if the shader has multiple stages.
+ ///
+ public ShaderStage? Stage { get; set; }
+
///
/// The stage of the shader to compile.
///
@@ -34,9 +40,4 @@ public class ShaderJson
/// The source profile of the shader.
///
public string? SourceProfile { get; set; } = string.Empty;
-
- ///
- /// The rules to apply to the shader.
- ///
- public RulesJson? Rules { get; set; }
}
diff --git a/RisShaderToolkit/RisShaderToolkit/JsonReader.cs b/RisShaderToolkit/RisShaderToolkit/JsonReader.cs
index f104de9..4a0d844 100644
--- a/RisShaderToolkit/RisShaderToolkit/JsonReader.cs
+++ b/RisShaderToolkit/RisShaderToolkit/JsonReader.cs
@@ -1,23 +1,28 @@
-using AutoMapper;
-using Microsoft.Extensions.Logging.Abstractions;
-using RisShaderToolkit.Dto;
+using RisShaderToolkit.Dto;
using RisShaderToolkit.Json;
using System.Text.Json;
namespace RisShaderToolkit
{
+ ///
+ /// This class is responsible for reading a JSON file that describes shader compilation tasks and
+ /// converting it into a list of `ShaderCompileTaskDto` objects that can be used by the rest of the application.
+ ///
internal class JsonReader
{
- private readonly IMapper _mapper;
-
- internal JsonReader()
+ private static AnyProfile? ResolveProfile(string? profileStr)
{
- MapperConfiguration config = new (cfg =>
+ if (String.IsNullOrEmpty(profileStr))
+ {
+ return null;
+ }
+
+ if (Enum.TryParse(profileStr, ignoreCase: true, out AnyProfile value))
{
- cfg.AddProfile();
- }, new NullLoggerFactory());
+ return value;
+ }
- _mapper = config.CreateMapper();
+ throw new InvalidOperationException($"Unsupported profile type: {profileStr}.");
}
///
@@ -42,17 +47,35 @@ public IReadOnlyList LoadJson(string jsonFilePath)
throw new InvalidOperationException("Failed to deserialize compile JSON.");
}
- List results = new ();
+ List results = new();
- foreach (ShaderJson shader in compileJson.Shaders)
+ foreach (ShaderJson shaderJson in compileJson.Shaders)
{
// Create a task for each shader
- string inputFilePath = Path.IsPathRooted(shader.Name)
- ? shader.Name
- : Path.Combine(directory, shader.Name);
+ string inputFilePath = Path.IsPathRooted(shaderJson.Name)
+ ? shaderJson.Name
+ : Path.Combine(directory, shaderJson.Name);
+
+ ShaderCompileTaskDto compileTask = new()
+ {
+ OutputFilePath = shaderJson.OutputFile,
+ EntryPoints = shaderJson.EntryPoints,
+
+ };
+
+ if(shaderJson.Stage.HasValue)
+ {
+ compileTask.Stages.Add(shaderJson.Stage.Value);
+ }
+
+ if(shaderJson.Stages != null)
+ {
+ compileTask.Stages.AddRange(shaderJson.Stages);
+ }
- ShaderCompileTaskDto compileTask = _mapper.Map(shader);
compileTask.InputFilePath = inputFilePath.Replace("\\", "/");
+ compileTask.SourceProfile = ResolveProfile(shaderJson.SourceProfile);
+ compileTask.Profile = ResolveProfile(shaderJson.Profile) ?? throw new InvalidOperationException("JSON entry in 'shaders' is missing 'profile' property.");
results.Add(compileTask);
}
diff --git a/RisShaderToolkit/RisShaderToolkit/RisShaderToolkit.csproj b/RisShaderToolkit/RisShaderToolkit/RisShaderToolkit.csproj
index 63806ba..a4fcaad 100644
--- a/RisShaderToolkit/RisShaderToolkit/RisShaderToolkit.csproj
+++ b/RisShaderToolkit/RisShaderToolkit/RisShaderToolkit.csproj
@@ -7,17 +7,24 @@
true
RisShaderToolkit
True
- 0.0.1-preview.5
+ 0.2.0
-
-
-
-
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
\ No newline at end of file
diff --git a/RisShaderToolkit/RisShaderToolkit/Rules/ReplaceStageInputNameRule.cs b/RisShaderToolkit/RisShaderToolkit/Rules/ReplaceStageInputNameRule.cs
deleted file mode 100644
index 8a48270..0000000
--- a/RisShaderToolkit/RisShaderToolkit/Rules/ReplaceStageInputNameRule.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-namespace RisShaderToolkit.Rules;
-
-///
-/// The rule to replace stage input names.
-///
-public class ReplaceStageInputNameRule
-{
- ///
- /// The prefix to add to the stage input names.
- ///
- public string? Prefix { get; set; }
-}
diff --git a/RisShaderToolkit/RisShaderToolkit/Rules/ReplaceStageOutputNameRule.cs b/RisShaderToolkit/RisShaderToolkit/Rules/ReplaceStageOutputNameRule.cs
deleted file mode 100644
index cdf8a2e..0000000
--- a/RisShaderToolkit/RisShaderToolkit/Rules/ReplaceStageOutputNameRule.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-namespace RisShaderToolkit.Rules;
-
-///
-/// The rule to replace stage output names.
-///
-public class ReplaceStageOutputNameRule
-{
- ///
- /// The prefix to add to the stage output names.
- ///
- public string? Prefix { get; set; }
-
- ///
- /// Sets whether to trim the entry point name from output variable names.
- ///
- public bool TrimEntryPointName { get; set; }
-}
diff --git a/RisShaderToolkit/RisShaderToolkit/ShaderCompiler.cs b/RisShaderToolkit/RisShaderToolkit/ShaderCompiler.cs
index 374a265..92863d6 100644
--- a/RisShaderToolkit/RisShaderToolkit/ShaderCompiler.cs
+++ b/RisShaderToolkit/RisShaderToolkit/ShaderCompiler.cs
@@ -2,7 +2,6 @@
using RisShaderToolkit.CObjects;
using RisShaderToolkit.Dto;
-using RisShaderToolkit.Rules;
using System.Runtime.InteropServices;
namespace RisShaderToolkit;
@@ -20,28 +19,8 @@ public class ShaderCompiler : IDisposable
[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
static extern void free_compiler(IntPtr compiler);
- //[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
- //static unsafe extern IntPtr compile_slang_to_glsl(
- // IntPtr compilerPtr,
- // IntPtr inputFilePath,
- // GlslProfile glslProfile,
- // ShaderStage shaderStage,
- // IntPtr entryPoint,
- // IntPtr inputRule,
- // IntPtr outputRule);
-
- //[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
- //static unsafe extern IntPtr compile_slang_source_code_to_glsl(
- // IntPtr compilerPtr,
- // IntPtr slangSourceCode,
- // GlslProfile glslProfile,
- // ShaderStage shaderStage,
- // IntPtr entryPoint,
- // IntPtr inputRule,
- // IntPtr outputRule);
-
[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
- static unsafe extern IntPtr compile_slang_to_wgsl(
+ static unsafe extern IntPtr compile_slang_to_wgsl_ext(
IntPtr compilerPtr,
IntPtr sourceCode,
ShaderStage* shaderStages,
@@ -50,7 +29,14 @@ static unsafe extern IntPtr compile_slang_to_wgsl(
uint entryPointsCount);
[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
- static unsafe extern IntPtr compile_slang_to_spirv(
+ static unsafe extern IntPtr compile_slang_to_wgsl(
+ IntPtr compilerPtr,
+ IntPtr sourceCode,
+ ShaderStage* shaderStages,
+ uint shaderStagesCount);
+
+ [DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
+ static unsafe extern IntPtr compile_slang_to_spirv_ext(
IntPtr compilerPtr,
IntPtr sourceCode,
ShaderStage* shaderStages,
@@ -60,6 +46,32 @@ static unsafe extern IntPtr compile_slang_to_spirv(
SpirVProfile spirVProfile
);
+ [DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
+ static unsafe extern IntPtr compile_slang_to_spirv(
+ IntPtr compilerPtr,
+ IntPtr sourceCode,
+ ShaderStage* shaderStages,
+ uint shaderStagesCount,
+ SpirVProfile spirVProfile
+ );
+
+ [DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
+ static unsafe extern IntPtr compile_slang_to_glsl_ext(
+ IntPtr compilerPtr,
+ IntPtr sourceCode,
+ ShaderStage shaderStage,
+ IntPtr entryPoint,
+ GlslProfile glslProfile
+ );
+
+ [DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
+ static unsafe extern IntPtr compile_slang_to_glsl(
+ IntPtr compilerPtr,
+ IntPtr sourceCode,
+ ShaderStage shaderStage,
+ GlslProfile glslProfile
+ );
+
private readonly IntPtr NativePtr;
private readonly JsonReader _jsonReader = new();
@@ -84,29 +96,27 @@ public ShaderCompiler()
}
}
- private void WriteGlslShaderToFile(ShaderCompileTaskDto task, CompileResult result, GlslProfile glslProfile)
+ private void WriteGlslShaderToFile(ShaderCompileTaskDto task, CompileResult result, GlslProfile glslProfile, ShaderStage stage)
{
- throw new InvalidOperationException("hello");
-
- //if (!result.Success)
- //{
- // return;
- //}
-
- //string? outputFilePath = task.OutputFilePath;
- //if (string.IsNullOrEmpty(outputFilePath))
- //{
- // string[] split = task.InputFilePath.Split('.');
- // split = split[..^1]; // Remove extension
-
- // string name = String.Join("", split);
- // outputFilePath = $"{name}_{_shortStageName[task.Stage.Value]}_{glslProfile.ToString().ToLower()}.glsl";
- //}
-
- //if (result.Success && result.SourceCode != null)
- //{
- // File.WriteAllText(outputFilePath, result.SourceCode);
- //}
+ if (!result.Success)
+ {
+ return;
+ }
+
+ string? outputFilePath = task.OutputFilePath;
+ if (string.IsNullOrEmpty(outputFilePath))
+ {
+ string[] split = task.InputFilePath.Split('.');
+ split = split[..^1]; // Remove extension
+
+ string name = String.Join("", split);
+ outputFilePath = $"{name}_{_shortStageName[stage]}_{glslProfile.ToString().ToLower()}.glsl";
+ }
+
+ if (result.Success && result.SourceCode != null)
+ {
+ File.WriteAllText(outputFilePath, result.SourceCode);
+ }
}
private void WriteWgslShaderToFile(ShaderCompileTaskDto task, CompileResult result)
@@ -156,11 +166,11 @@ private bool HandleSpirVProfile(List results, ShaderCompileTaskDt
{
string sourceCode = File.ReadAllText(compileTask.InputFilePath);
- CompileResult result = CompileSlangToSpirV(
+ var result = CompileSlangToSpirV(
sourceCode,
- compileTask.Stages ?? [ShaderStage.VERTEX, ShaderStage.FRAGMENT],
+ compileTask.Stages.ToArray(),
spirVProfile,
- compileTask.EntryPoints ?? []
+ compileTask?.EntryPoints
);
results.Add(result);
@@ -172,6 +182,27 @@ private bool HandleSpirVProfile(List results, ShaderCompileTaskDt
return false;
}
+ private bool HandleGlslProfile(List results, ShaderCompileTaskDto compileTask)
+ {
+ if (ProfileResolver.IsGlslProfile(compileTask.Profile, out GlslProfile glslProfile))
+ {
+ string sourceCode = File.ReadAllText(compileTask.InputFilePath);
+ foreach (ShaderStage shaderStage in compileTask.Stages)
+ {
+ var result = CompileSlangToGlsl(
+ sourceCode,
+ shaderStage,
+ glslProfile,
+ compileTask?.EntryPoints != null && compileTask.EntryPoints.Length > 0 ? compileTask.EntryPoints[0] : null
+ );
+ results.Add(result);
+ WriteGlslShaderToFile(compileTask, result, glslProfile, shaderStage);
+ }
+ return true;
+ }
+ return false;
+ }
+
///
/// Compiles shaders based on the given JSON file.
///
@@ -190,28 +221,19 @@ public AggregatedCompileResult CompileFromJson(string jsonFilePath)
CompileResult result = CompileSlangToWgsl(
sourceCode,
- compileTask.Stages ?? [ShaderStage.VERTEX, ShaderStage.FRAGMENT],
+ compileTask.Stages.ToArray(),
compileTask.EntryPoints ?? []);
results.Add(result);
WriteWgslShaderToFile(compileTask, result);
}
- else if(HandleSpirVProfile(results, compileTask))
+ else if (HandleSpirVProfile(results, compileTask))
{
continue;
}
- else if (compileTask.SourceProfile == AnyProfile.SLANG && ProfileResolver.IsGlslProfile(compileTask.Profile, out GlslProfile glslProfile))
+ else if (HandleGlslProfile(results, compileTask))
{
- //CompileResult result = CompileSlangToGlsl(
- // compileTask.InputFilePath,
- // glslProfile,
- // compileTask.Stage.Value,
- // compileTask.EntryPoint,
- // compileTask.InputNameRule,
- // compileTask.OutputNameRule);
-
- //results.Add(result);
- //WriteGlslShaderToFile(compileTask, result, glslProfile);
+ continue;
}
else
{
@@ -223,145 +245,6 @@ public AggregatedCompileResult CompileFromJson(string jsonFilePath)
return new(results);
}
- ///
- /// Transpiles the given Slang shader to GLSL.
- ///
- /// The input file path.
- /// The .
- /// The .
- /// The entry point.
- /// The optional .
- /// The optional .
- ///
- ///
- //public CompileResult CompileSlangToGlsl(
- // string inputFilePath,
- // GlslProfile glslProfile,
- // ShaderStage shaderStage,
- // string entryPoint = "main",
- // ReplaceStageInputNameRule? inputNameRule = null,
- // ReplaceStageOutputNameRule? outputNameRule = null
- // )
- //{
- // IntPtr inputFilePathPtr = Marshal.StringToHGlobalAnsi(inputFilePath);
- // IntPtr entryPointPtr = Marshal.StringToHGlobalAnsi(entryPoint);
- // IntPtr inputRulePtr = CReplaceStageInputNameRule.AllocNative(inputNameRule);
- // IntPtr outputRulePtr = CReplaceStageOutputNameRule.AllocNative(outputNameRule);
- // try
- // {
- // IntPtr resultPtr = compile_slang_to_glsl(
- // NativePtr,
- // inputFilePathPtr,
- // glslProfile,
- // shaderStage,
- // entryPointPtr,
- // inputRulePtr,
- // outputRulePtr);
-
- // if (resultPtr == IntPtr.Zero)
- // {
- // throw new InvalidOperationException("Compilation failed: No result returned.");
- // }
-
- // CCompileResult cCompileResult = Marshal.PtrToStructure(resultPtr);
-
- // CompileResult result = new CompileResult
- // {
- // Success = cCompileResult.Success,
- // SourceCode = cCompileResult.Success
- // ? Marshal.PtrToStringAnsi(cCompileResult.SourceCode) ?? string.Empty
- // : null,
- // ErrorMessage = cCompileResult.Success
- // ? null
- // : Marshal.PtrToStringAnsi(cCompileResult.ErrorMessage) ?? "Unknown error.",
- // EntryPoints = [entryPoint],
- // InputFilePath = inputFilePath,
- // GlslProfile = glslProfile,
- // ShaderStages = [shaderStage]
- // };
- // cCompileResult.Dispose();
- // return result;
-
- // }
- // finally
- // {
- // Marshal.FreeHGlobal(inputFilePathPtr);
- // Marshal.FreeHGlobal(entryPointPtr);
- // CReplaceStageInputNameRule.FreeNative(inputRulePtr);
- // CReplaceStageOutputNameRule.FreeNative(outputRulePtr);
- // }
- //}
-
- ///
- /// Transpiles the given Slang shader to GLSL.
- ///
- /// The Slang source code.
- /// The .
- /// The .
- /// The entry point.
- /// The optional .
- /// The optional .
- ///
- ///
- //public CompileResult CompileSlangSourceCodeToGlsl(
- // string slangSourceCode,
- // GlslProfile glslProfile,
- // ShaderStage shaderStage,
- // string entryPoint = "main",
- // ReplaceStageInputNameRule? inputNameRule = null,
- // ReplaceStageOutputNameRule? outputNameRule = null
- // )
- //{
- // IntPtr slangSourceCodePtr = Marshal.StringToHGlobalAnsi(slangSourceCode);
- // IntPtr entryPointPtr = Marshal.StringToHGlobalAnsi(entryPoint);
- // IntPtr inputRulePtr = CReplaceStageInputNameRule.AllocNative(inputNameRule);
- // IntPtr outputRulePtr = CReplaceStageOutputNameRule.AllocNative(outputNameRule);
- // try
- // {
- // IntPtr resultPtr = compile_slang_source_code_to_glsl(
- // NativePtr,
- // slangSourceCodePtr,
- // glslProfile,
- // shaderStage,
- // entryPointPtr,
- // inputRulePtr,
- // outputRulePtr);
-
- // if (resultPtr == IntPtr.Zero)
- // {
- // throw new InvalidOperationException("Compilation failed: No result returned.");
- // }
-
- // CCompileResult cCompileResult = Marshal.PtrToStructure(resultPtr);
-
- // CompileResult result = new CompileResult
- // {
- // Success = cCompileResult.Success,
- // SourceCode = cCompileResult.Success
- // ? Marshal.PtrToStringAnsi(cCompileResult.SourceCode) ?? string.Empty
- // : null,
- // ErrorMessage = cCompileResult.Success
- // ? null
- // : Marshal.PtrToStringAnsi(cCompileResult.ErrorMessage) ?? "Unknown error.",
- // EntryPoints = [entryPoint],
- // InputFilePath = slangSourceCode,
- // GlslProfile = glslProfile,
- // ShaderStages = [shaderStage]
- // };
- // cCompileResult.Dispose();
- // return result;
-
- // }
- // finally
- // {
- // Marshal.FreeHGlobal(slangSourceCodePtr);
- // Marshal.FreeHGlobal(entryPointPtr);
- // CReplaceStageInputNameRule.FreeNative(inputRulePtr);
- // CReplaceStageOutputNameRule.FreeNative(outputRulePtr);
- // }
- // }
-
-
///
/// Compiles the given Slang shader to WGSL.
///
@@ -386,19 +269,36 @@ params string[] entryPoints
shaderStagesPtr[i] = shaderStages[i];
}
- IntPtr* entryPointsPtr = stackalloc IntPtr[entryPoints.Length];
- for (int i = 0; i < entryPoints.Length; i++)
+ // Generate default entry points if not provided
+ if (entryPoints == null || entryPoints.Length == 0)
{
- entryPointsPtr[i] = Marshal.StringToHGlobalAnsi(entryPoints[i]);
+ entryPoints = new string[shaderStages.Length];
+ for (int i = 0; i < shaderStages.Length; i++)
+ {
+ entryPoints[i] = $"main_{_shortStageName[shaderStages[i]]}";
+ }
}
try
{
- IntPtr resultPtr = compile_slang_to_wgsl(
- NativePtr,
- slangSourceCodePtr,
- shaderStagesPtr, (uint)shaderStages.Length,
- entryPointsPtr, (uint)entryPoints.Length);
+ IntPtr resultPtr = IntPtr.Zero;
+ var entryPointsCount = entryPoints.Length;
+ IntPtr* entryPointsPtr = stackalloc IntPtr[entryPointsCount];
+ for (int i = 0; i < entryPointsCount; i++)
+ {
+ entryPointsPtr[i] = Marshal.StringToHGlobalAnsi(entryPoints[i]);
+ }
+
+ resultPtr = compile_slang_to_wgsl_ext(
+ NativePtr,
+ slangSourceCodePtr,
+ shaderStagesPtr, (uint)shaderStages.Length,
+ entryPointsPtr, (uint)entryPointsCount);
+
+ for (int i = 0; i < entryPointsCount; i++)
+ {
+ Marshal.FreeHGlobal(entryPointsPtr[i]);
+ }
if (resultPtr == IntPtr.Zero)
{
@@ -423,13 +323,20 @@ params string[] entryPoints
return result;
}
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message);
+ return new CompileResult
+ {
+ Success = false,
+ ErrorMessage = $"An error occurred during compilation: {ex.Message}",
+ EntryPoints = entryPoints.ToArray(),
+ ShaderStages = shaderStages
+ };
+ }
finally
{
Marshal.FreeHGlobal(slangSourceCodePtr);
- for (int i = 0; i < entryPoints.Length; i++)
- {
- Marshal.FreeHGlobal(entryPointsPtr[i]);
- }
}
}
}
@@ -438,7 +345,7 @@ params string[] entryPoints
/// Compiles the given Slang shader to WGSL.
///
/// The slang source code.
- /// The 's to compile.
+ /// The s to compile.
/// The optional . Default is SPIRV_1_2.
/// The optional entry points.
/// The .
@@ -449,6 +356,8 @@ public CompileResult CompileSlangToSpirV(
params string[] entryPoints
)
{
+ entryPoints = entryPoints ?? Array.Empty();
+
IntPtr slangSourceCodePtr = Marshal.StringToHGlobalAnsi(slangSourceCode);
CCompileResult compileResult = default;
@@ -460,20 +369,43 @@ params string[] entryPoints
shaderStagesPtr[i] = shaderStages[i];
}
- IntPtr* entryPointsPtr = stackalloc IntPtr[entryPoints.Length];
- for (int i = 0; i < entryPoints.Length; i++)
- {
- entryPointsPtr[i] = Marshal.StringToHGlobalAnsi(entryPoints[i]);
- }
-
try
{
- IntPtr resultPtr = compile_slang_to_spirv(
- NativePtr,
- slangSourceCodePtr,
- shaderStagesPtr, (uint)shaderStages.Length,
- entryPointsPtr, (uint)entryPoints.Length,
- spirVProfile);
+ IntPtr resultPtr;
+
+ if (entryPoints.Length > 0)
+ {
+ int entryPointsCount = entryPoints.Length;
+ IntPtr* entryPointsPtr = stackalloc IntPtr[entryPointsCount];
+ for (int i = 0; i < entryPointsCount; i++)
+ {
+ entryPointsPtr[i] = Marshal.StringToHGlobalAnsi(entryPoints[i]);
+ }
+
+ resultPtr = compile_slang_to_spirv_ext(
+ NativePtr,
+ slangSourceCodePtr,
+ shaderStagesPtr,
+ (uint)shaderStages.Length,
+ entryPointsPtr,
+ (uint)entryPoints.Length,
+ spirVProfile);
+
+ for (int i = 0; i < entryPoints.Length; i++)
+ {
+ Marshal.FreeHGlobal(entryPointsPtr[i]);
+ }
+ }
+ else
+ {
+ // If no entry points are provided, pass null pointers and zero count
+ resultPtr = compile_slang_to_spirv(
+ NativePtr,
+ slangSourceCodePtr,
+ shaderStagesPtr,
+ (uint)shaderStages.Length,
+ spirVProfile);
+ }
if (resultPtr == IntPtr.Zero)
{
@@ -509,10 +441,96 @@ params string[] entryPoints
finally
{
Marshal.FreeHGlobal(slangSourceCodePtr);
- for (int i = 0; i < entryPoints.Length; i++)
+
+ }
+ }
+ }
+
+ ///
+ /// Compiles the given Slang shader to GLSL.
+ ///
+ /// The slang source code.
+ /// The to compile.
+ /// The optional . Default is GLSL_450.
+ /// The optional entry point.
+ /// The .
+ ///
+ public CompileResult CompileSlangToGlsl(
+ string slangSourceCode,
+ ShaderStage shaderStage,
+ GlslProfile glslProfile = GlslProfile.GLSL_450,
+ string? entryPoint = null
+ )
+ {
+ IntPtr slangSourceCodePtr = Marshal.StringToHGlobalAnsi(slangSourceCode);
+
+ CCompileResult compileResult = default;
+ unsafe
+ {
+ try
+ {
+ IntPtr resultPtr;
+ if (!String.IsNullOrEmpty(entryPoint))
{
- Marshal.FreeHGlobal(entryPointsPtr[i]);
+ var entryPointPtr = Marshal.StringToHGlobalAnsi(entryPoint);
+
+ resultPtr = compile_slang_to_glsl_ext(
+ NativePtr,
+ slangSourceCodePtr,
+ shaderStage,
+ entryPointPtr,
+ glslProfile);
+
+ Marshal.FreeHGlobal(entryPointPtr);
+ }
+ else
+ {
+ resultPtr = compile_slang_to_glsl(
+ NativePtr,
+ slangSourceCodePtr,
+ shaderStage,
+ glslProfile);
}
+
+ if (resultPtr == IntPtr.Zero)
+ {
+ throw new InvalidOperationException("Compilation failed: No result returned.");
+ }
+
+ compileResult = Marshal.PtrToStructure(resultPtr);
+
+ CompileResult result = new CompileResult
+ {
+ Success = compileResult.Success,
+ SourceCode = compileResult.Success
+ ? Marshal.PtrToStringAnsi(compileResult.SourceCode) ?? string.Empty
+ : null,
+ ErrorMessage = compileResult.Success
+ ? null
+ : Marshal.PtrToStringAnsi(compileResult.ErrorMessage) ?? "Unknown error.",
+ EntryPoints = !string.IsNullOrEmpty(entryPoint) ? [entryPoint] : Array.Empty(),
+ ShaderStages = [shaderStage],
+ };
+
+ result.SourceCode = Marshal.PtrToStringAnsi(compileResult.SourceCode);
+
+ compileResult.Dispose();
+ return result;
+
+ }
+ catch (Exception ex)
+ {
+ return new CompileResult
+ {
+ Success = false,
+ ErrorMessage = $"An error occurred during compilation: {ex.Message}",
+ EntryPoints = !string.IsNullOrEmpty(entryPoint) ? [entryPoint] : Array.Empty(),
+ ShaderStages = [shaderStage],
+ };
+ }
+ finally
+ {
+ Marshal.FreeHGlobal(slangSourceCodePtr);
}
}
}
diff --git a/RisShaderToolkit/RisShaderToolkit/Slang/SlangGlobalSession.cs b/RisShaderToolkit/RisShaderToolkit/Slang/SlangGlobalSession.cs
index 3a18bae..bc0bbf0 100644
--- a/RisShaderToolkit/RisShaderToolkit/Slang/SlangGlobalSession.cs
+++ b/RisShaderToolkit/RisShaderToolkit/Slang/SlangGlobalSession.cs
@@ -78,6 +78,11 @@ public SlangProfileID FindProfile(string profileName)
}
}
+ ///
+ /// Creates a new Slang session.
+ ///
+ /// The .
+ /// The .
public SlangSession CreateSession(SlangSessionDescription sessionDescription)
{
unsafe
diff --git a/RisShaderToolkit/RisShaderToolkit/runtimes/linux-x64/native/libshader_toolkit_c.so b/RisShaderToolkit/RisShaderToolkit/runtimes/linux-x64/native/libshader_toolkit_c.so
old mode 100644
new mode 100755
index 8186c74..8ab092a
Binary files a/RisShaderToolkit/RisShaderToolkit/runtimes/linux-x64/native/libshader_toolkit_c.so and b/RisShaderToolkit/RisShaderToolkit/runtimes/linux-x64/native/libshader_toolkit_c.so differ
diff --git a/RisShaderToolkit/RisShaderToolkit/runtimes/osx-arm64/native/libshader_toolkit_c.dylib b/RisShaderToolkit/RisShaderToolkit/runtimes/osx-arm64/native/libshader_toolkit_c.dylib
index 2659136..44429a7 100644
Binary files a/RisShaderToolkit/RisShaderToolkit/runtimes/osx-arm64/native/libshader_toolkit_c.dylib and b/RisShaderToolkit/RisShaderToolkit/runtimes/osx-arm64/native/libshader_toolkit_c.dylib differ
diff --git a/RisShaderToolkit/RisShaderToolkit/runtimes/win-x64/native/shader_toolkit_c.dll b/RisShaderToolkit/RisShaderToolkit/runtimes/win-x64/native/shader_toolkit_c.dll
index 204f205..30b7988 100644
Binary files a/RisShaderToolkit/RisShaderToolkit/runtimes/win-x64/native/shader_toolkit_c.dll and b/RisShaderToolkit/RisShaderToolkit/runtimes/win-x64/native/shader_toolkit_c.dll differ
diff --git a/RisShaderToolkit/RisShaderToolkit/runtimes/win-x64/native/slang.dll b/RisShaderToolkit/RisShaderToolkit/runtimes/win-x64/native/slang.dll
index f467a48..3b12b67 100644
Binary files a/RisShaderToolkit/RisShaderToolkit/runtimes/win-x64/native/slang.dll and b/RisShaderToolkit/RisShaderToolkit/runtimes/win-x64/native/slang.dll differ
diff --git a/ShaderToolkitC/README.md b/ShaderToolkitC/README.md
index 05b31b0..757696e 100644
--- a/ShaderToolkitC/README.md
+++ b/ShaderToolkitC/README.md
@@ -71,7 +71,6 @@ The Windows script installs dependencies with vcpkg and configures CMake.
.\scripts\build_windows.ps1
```
-
Build output: `cmake-build-debugvisualstudio/`
Notes:
diff --git a/ShaderToolkitC/include/compiler/c_compiler.hpp b/ShaderToolkitC/include/compiler/c_compiler.hpp
index 95f73d5..bd9416a 100644
--- a/ShaderToolkitC/include/compiler/c_compiler.hpp
+++ b/ShaderToolkitC/include/compiler/c_compiler.hpp
@@ -18,33 +18,19 @@ extern "C" {
API_EXPORT
char* get_last_error_message();
- // API_EXPORT
- //void* compile_slang_to_glsl(
- // void* compilerPtr,
- // const char* inputFilePath,
- // int profile, // GlslProfile as int
- // int shaderStage, // ShaderStage as int
- // const char* entryPoint,
- // c_ReplaceStageInputNameRule* inputRule,
- // c_ReplaceStageOutputNameRule* outputRule
- //);
-
- //API_EXPORT
- //void* compile_slang_source_code_to_glsl(
- //void* compilerPtr,
- //const char* slangSourceCode,
- //int profile, // GlslProfile as int
- //int shaderStage, // ShaderStage as int
- //const char* entryPoint,
- //c_ReplaceStageInputNameRule* inputRule,
- //c_ReplaceStageOutputNameRule* outputRule
- //);
-
API_EXPORT
void* compile_slang_to_wgsl(
void* compilerPtr,
const char* slangSourceCode,
- int32_t* shaderStages,
+ int32_t* shaderStages,
+ uint32_t shaderStagesCount
+ );
+
+ API_EXPORT
+ void* compile_slang_to_wgsl_ext(
+ void* compilerPtr,
+ const char* slangSourceCode,
+ int32_t* shaderStages,
uint32_t shaderStagesCount,
const char** entryPoints,
uint32_t entryPointsCount
@@ -52,6 +38,15 @@ extern "C" {
API_EXPORT
void* compile_slang_to_spirv(
+ void* compilerPtr,
+ const char* slangSourceCode,
+ int32_t* shaderStages,
+ uint32_t shaderStagesCount,
+ ris_shader_toolkit::SpirVProfile profile
+ );
+
+ API_EXPORT
+ void* compile_slang_to_spirv_ext(
void* compilerPtr,
const char* slangSourceCode,
int32_t* shaderStages,
@@ -59,7 +54,26 @@ extern "C" {
const char** entryPoints,
uint32_t entryPointsCount,
ris_shader_toolkit::SpirVProfile profile
- );
+ );
+
+ API_EXPORT
+ void* compile_slang_to_glsl(
+ void* compilerPtr,
+ const char* slangSourceCode,
+ int32_t shaderStage,
+ ris_shader_toolkit::GlslProfile profile
+ );
+
+ API_EXPORT
+ void* compile_slang_to_glsl_ext(
+ void* compilerPtr,
+ const char* slangSourceCode,
+ int32_t shaderStage,
+ const char* entryPoint,
+ ris_shader_toolkit::GlslProfile profile
+ );
+
+
//! Frees the Compiler instance.
//! @param compilerPtr A pointer to the Compiler instance to free.
diff --git a/ShaderToolkitC/include/compiler/compile_result.hpp b/ShaderToolkitC/include/compiler/compile_result.hpp
index 39de46f..cf5dfe5 100644
--- a/ShaderToolkitC/include/compiler/compile_result.hpp
+++ b/ShaderToolkitC/include/compiler/compile_result.hpp
@@ -26,12 +26,12 @@ namespace ris_shader_toolkit {
//! @param success True if the compilation was successful, false otherwise.
//! @param sourceCode The compiled source code in binary format if the compilation was successful.
//! @param error The error message if the compilation failed.
- CompileResult(bool success, const std::vector& sourceCode, const std::string& error = "");
+ CompileResult(bool success, const std::vector& sourceCode, const std::string& error = "");
//! Constructs a CompileResult object with reflection data.
//! @param sourceCode The compiled source code in binary format if the compilation was successful.
//! @param reflectionData The reflection data from the compilation.
- CompileResult(const std::vector& sourceCode, ShaderReflection reflectionData);
+ CompileResult(const std::vector& sourceCode, ShaderReflection reflectionData);
//! Returns true if the compilation was successful, false otherwise.
//! @return True if the compilation was successful, false otherwise.
@@ -43,7 +43,7 @@ namespace ris_shader_toolkit {
//! Returns the compiled source code in binary format if the compilation was successful.
//! @return The compiled source code in binary format if the compilation was successful or an empty string otherwise.
- const std::vector& getBinaryCode() const { return _binarySourceCode; }
+ const std::vector& getBinaryCode() const { return _binarySourceCode; }
//! Returns the compiled source code if the compilation was successful.
//! @return The compiled source code if the compilation was successful or an empty string otherwise.
@@ -63,7 +63,7 @@ namespace ris_shader_toolkit {
//! @param binaryCode The compiled source code in binary format.
//! @param reflectionData The reflection data from the compilation.
//! @return A successful CompileResult object.
- static CompileResult successResult(const std::vector& binaryCode, ShaderReflection reflectionData);
+ static CompileResult successResult(const std::vector& binaryCode, ShaderReflection reflectionData);
//! Creates a failed CompileResult object.
//! @param errorMessage The error message.
@@ -73,7 +73,7 @@ namespace ris_shader_toolkit {
private:
bool _success;
std::string _sourceCode;
- std::vector _binarySourceCode;
+ std::vector _binarySourceCode;
std::string _errorMessage;
ShaderReflection _reflectionData;
};
diff --git a/ShaderToolkitC/include/compiler/compiler.hpp b/ShaderToolkitC/include/compiler/compiler.hpp
index 374ff3e..ecbf05f 100644
--- a/ShaderToolkitC/include/compiler/compiler.hpp
+++ b/ShaderToolkitC/include/compiler/compiler.hpp
@@ -6,6 +6,8 @@
#include "compiler/compile_result.hpp"
#include "rules.hpp"
#include