Veldrid.SPIRV is an extension library for Veldrid that provides support for loading SPIR-V bytecode for all Veldrid backends.
This is a modernized fork based on ppy/veldrid-spirv (itself a fork of the original mellinoe/veldrid-spirv).
- Upgraded all projects from .NET 5/8 to .NET 10 (
net10.0) - Upgraded to latest C# language version with modern features:
- File-scoped namespaces
- Collection expressions (
[]syntax) - Switch expressions
- Primary constructors
- Source-generated regex (
[GeneratedRegex]) - Nullable reference types enabled across all projects
- Implicit usings enabled
- Updated Nerdbank.GitVersioning 3.4.255 → 3.9.50
- Updated xUnit to xunit.v3 3.2.2 (latest)
- Updated Microsoft.NET.Test.Sdk to 18.4.0
- Updated McMaster.Extensions.CommandLineUtils 4.0 → 5.1.0
- Replaced deprecated
PackageLicenseUrlwithPackageLicenseExpression - Removed deprecated
DotNetCliToolReferenceand unnecessarySystem.Runtime.CompilerServices.Unsafepackage - Removed deprecated test runner
Program.cs(xunit.v3 usesdotnet testdirectly)
Bug Fixes (from upstream veldrid/veldrid-spirv issues/PRs)
- Issue #32: Debug flag is now correctly propagated to cross-compiled shader descriptions in
ResourceFactoryExtensions - PR #34: Added
#include <cstdint>for GCC 10+ build compatibility in the native C++ library - PR #21:
SpirvCompilationExceptionnow includesLineNumberandShaderStagein itsDatadictionary for better error diagnostics - CompileCompute interop bug: Fixed incorrect use of
SpecializationConstant(managed struct) instead ofNativeSpecializationConstant(interop struct) when passing specialization constants to native code — this could cause memory corruption or crashes - Null safety improvements: Added null checks, removed unsafe null-forgiving operators, improved error handling in
VariantCompiler - Code quality: Extracted duplicate
JsonSerializersetup, fixed confusing flag logic, removed dead code
- Added
-Wl,-z,max-page-size=16384linker flag inCMakeLists.txtfor Android builds, required for Android 16 (API level 36+) which mandates 16KB page-aligned shared libraries. See the Android developer documentation for details.
- .NET SDK updated from 6.0 to 10.0
- Test execution modernized:
dotnet run -p→dotnet test - Added linux-arm64 to the test matrix
- Added
workflow_dispatchwithpublish_nugetboolean input for one-click NuGet publishing (just click "Run workflow" in the Actions tab and check "Publish NuGet package") - Added
--skip-duplicateto NuGet push to avoid failures on re-runs
The easiest way to use Veldrid.SPIRV is through the extension methods it provides for the ResourceFactory type.
byte[] vertexShaderSpirvBytes = File.ReadAllBytes("myshader.vert.spv");
byte[] fragmentShaderSpirvBytes = File.ReadAllBytes("myshader.frag.spv");
Shader[] shaders = factory.CreateFromSpirv(
new ShaderDescription(ShaderStages.Vertex, vertexShaderSpirvBytes, "main"),
new ShaderDescription(ShaderStages.Fragment, fragmentShaderSpirvBytes, "main"));
// Use "shaders" array to construct a PipelineYou can also directly load GLSL source code and do the same as above. Behind the scenes, Veldrid.SPIRV will compile the GLSL to SPIR-V and then perform the cross-compile to the target language.
Although HLSL and OpenGL-style GLSL do not support SPIR-V Specialization Constants, you can use Veldrid.SPIRV to "specialize" the shader before the target source code is actually emitted. Set CrossCompileOptions.Specializations with an array of SpecializationConstant values to accomplish this.
Veldrid.SPIRV is implemented primarily as a native library, interfacing with SPIRV-Cross and shaderc. There are build scripts in the root of the repository which can be used to automatically build the native library for your platform.
Native build requirements:
- CMake
- Python
Pre-built binaries are bundled in the NuGet package for the following platforms:
- Windows x64, x86, ARM64
- macOS universal (x64 + ARM64)
- Linux x64, ARM64
- iOS (device + simulator via XCFramework)
- Android arm64-v8a, armeabi-v7a, x86, x86_64
- Go to the Actions tab → CI workflow
- Click Run workflow
- Optionally check Publish NuGet package to nuget.org to push directly (requires
NUGET_API_KEYsecret) - Click Run workflow
The workflow builds native libraries for all platforms, runs tests, packs the NuGet package, and optionally publishes it.
# Build native libraries for your platform
./build-native.sh release linux-x64 # or osx, etc.
# Pack NuGet
dotnet pack src/Veldrid.SPIRV -c ReleasePush a git tag (e.g., v1.0.16) to automatically trigger a build and NuGet publish.