Skip to content
SPIR-V shader translation for Veldrid, using SPIRV-Cross
C# C++ CMake GLSL PowerShell Python Other
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
ext
ios
src
.gitignore
.gitmodules
.travis.yml
CMakeLists.txt
Directory.Build.props
LICENSE
NuGet.Config
README.md
appveyor.yml
build-full-package.ps1
build-local-package.cmd
build-local-package.sh
build-native.cmd
build-native.sh
ci-build.cmd
ci-build.sh
version.json

README.md

Veldrid.SPIRV

NuGet

Veldrid.SPIRV is an extension library for Veldrid that provides support for loading SPIR-V bytecode for all Veldrid backends.

Usage

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.vert.spv");
Shader[] shaders = factory.CreateFromSpirv(
    new ShaderDescription(ShaderStages.Vertex, vertexShaderSpirvBytes, "main"),
    new ShaderDescription(ShaderStages.Fragment, vertexShaderSpirvBytes, "main"));
// Use "shaders" array to construct a Pipeline

You 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.

Specialization Constants

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.

libveldrid-spirv

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 operating systems:

  • Windows x64
  • Windows x86
  • macOS x64
  • Linux x64
  • iOS arm64
  • Android arm64-v8a
  • Android armeabi-v7a
You can’t perform that action at this time.