---
title: "oneshader cookbook"
url: https://recursiveai.org/oneshader/cookbook/
description: "Short recipes for common OneShader tasks, each with complete code you can copy."
version: "1.2.0"
---

# oneshader cookbook

Short recipes for common OneShader tasks, each with complete code you can copy.

## Recipes

- [Compile HLSL to SPIR-V for Vulkan](https://recursiveai.org/oneshader/cookbook/hlsl-to-spirv/index.md): Compile an HLSL vertex or pixel shader to SPIR-V for Vulkan with the oneshader command and its DXC-style flags, or from C# with ShaderCompiler, and check…
- [Compile HLSL in a C# project with dotnet build](https://recursiveai.org/oneshader/cookbook/compile-hlsl-csharp/index.md): Compile HLSL shaders as part of dotnet build in a C# project, with shader errors reported as build errors on the HLSL line, shared include files, defines…
- [Match HLSL constant buffers with C# structs](https://recursiveai.org/oneshader/cookbook/cbuffer-packing-csharp-structs/index.md): Get a C# struct whose field offsets equal an HLSL constant buffer’s packing, 16-byte rows, arrays and matrices included, so you can upload its bytes…
- [Push constants on Vulkan, Metal and WebGPU](https://recursiveai.org/oneshader/cookbook/push-constants/index.md): Declare an HLSL push-constant block once and get the C# struct plus where each API takes its bytes: a Vulkan push-constant range, a Metal setVertexBytes…
- [Shader variants with Axes in dotnet build](https://recursiveai.org/oneshader/cookbook/shader-variants-axes/index.md): Compile every combination of an HLSL shader’s keywords during dotnet build with Axes, or hand-picked define sets with OneShaderVariant, and pick a variant…
- [Specialization constants on Vulkan, Metal and WebGPU](https://recursiveai.org/oneshader/cookbook/specialization-constants/index.md): Declare HLSL specialization constants once with [[vk::constant_id]] and set them when the pipeline is created: VkSpecializationInfo on Vulkan, function…
- [16-bit and 64-bit types: half, int16_t, double and uint64_t](https://recursiveai.org/oneshader/cookbook/hlsl-16-bit-64-bit-types/index.md): Use native 16-bit half and int16_t and 64-bit double and uint64_t in HLSL with OneShader 1.2.0, get the matching C# structs, and see which device features…
- [Read shader reflection in C#: bindings, buffer layouts and vertex inputs](https://recursiveai.org/oneshader/cookbook/spirv-reflection-csharp/index.md): Read what a compiled HLSL shader binds, where, in which stages, its buffer layouts and its vertex inputs, from C# or as JSON, and turn it into Vulkan…
- [Reload shaders while the app runs](https://recursiveai.org/oneshader/cookbook/hot-reload-shaders/index.md): Recompile an HLSL shader when its file changes, swap in the new code while the app keeps running, and find out when an edit changed the interface the…
- [Shader variants with defines and includes](https://recursiveai.org/oneshader/cookbook/shader-variants-defines-includes/index.md): Compile several variants of one HLSL source at run time with preprocessor defines, and resolve #include from memory instead of the file system, with an…
- [Cache shader compiles at run time](https://recursiveai.org/oneshader/cookbook/shader-compile-cache/index.md): Keep compiled HLSL variants in memory with ShaderCompileCache, so a material system or editor that asks for the same shader again gets it without…
- [Write an HLSL compute shader for Vulkan and WebGPU](https://recursiveai.org/oneshader/cookbook/hlsl-compute-shader/index.md): Write one HLSL compute shader, compile it to SPIR-V and WGSL with dotnet build, and get the thread-group size for the dispatch and the descriptor and bind…
- [InterlockedAdd in HLSL, and what to do for floats](https://recursiveai.org/oneshader/cookbook/hlsl-interlockedadd/index.md): Count with InterlockedAdd in an HLSL compute shader on Vulkan, Metal and WebGPU, and add floats atomically with a compare-exchange loop, since there is no…
- [HLSL wave intrinsics on Vulkan, Metal and WebGPU](https://recursiveai.org/oneshader/cookbook/hlsl-wave-intrinsics/index.md): Use HLSL wave (subgroup) intrinsics such as WavePrefixCountBits, WaveActiveSum and WaveReadLaneFirst in one shader compiled to Vulkan, Metal and WebGPU…
- [The HLSL precise keyword on Vulkan, Metal and WebGPU](https://recursiveai.org/oneshader/cookbook/hlsl-precise-keyword/index.md): What HLSL’s precise keyword does when one shader is compiled to SPIR-V, Metal Shading Language and WGSL with OneShader: NoContraction on Vulkan, fast-math…
- [Convert HLSL to WGSL for WebGPU](https://recursiveai.org/oneshader/cookbook/hlsl-to-wgsl/index.md): Compile an HLSL vertex, pixel or compute shader to WGSL for WebGPU with OneShader, from the command line, from C# or during dotnet build, check it with…
- [Compile HLSL to Metal Shading Language](https://recursiveai.org/oneshader/cookbook/hlsl-to-metal/index.md): Compile HLSL vertex, pixel and compute shaders to Metal Shading Language with OneShader, and get from C# the function names, the buffer, texture and…
- [Switch from the DXC command line](https://recursiveai.org/oneshader/cookbook/migrate-from-dxc/index.md): Replace dxc -spirv with oneshader in a Makefile, CMake or script build: which DXC flags it takes unchanged, what it adds (MSL and WGSL targets, reflection…
