ShaderCompilerTool at build time #24

Open
UnflavoredMeson/Primal_Plus_Plus
opened 2026-11-24 20:15:55 +00:00 by UnflavoredMeson · 0 comments
Owner

Why

Engine shaders are compiled at run time by EngineDLL today. Compiling at build time catches errors in the build, and one HLSL source can make both DXIL and SPIR-V.

Decided

  • HLSL compiled with DXC for both backends (DXIL and SPIR-V). Slang was tested side by side and rejected (UnflavoredMeson/Primal#45: same output quality, about 6x slower, no DXIL on Linux).
  • The shared HLSL lives in Engine/Graphics/Shaders/.
  • ShaderCompilerTool runs as a build step on both build systems and writes x64/<Config>/shaders/{d3d12,vulkan}/shaders.bin (a PSHB layout read by content::get_engine_shaders()).
  • shaders.bin.key holds a hash of the format version, the DXC version and all arguments; shaders recompile only when it changes.
  • The distro DXC on Linux can't make DXIL: Linux builds SPIR-V only.

Read first

  • LinuxVulkanPort, "Phase 5 – Shader pipeline".
  • EngineDLL/ShaderCompilation.cpp on master.

Steps

  • 1. Move the HLSL to Engine/Graphics/Shaders/ and update both builds.
  • 2. Write the tool with DXC's API; add PSHB read/write tests in UnitTests.
  • 3. Add the build step and the up-to-date key; check that a second build compiles nothing.
  • 4. Make the engine load shaders.bin instead of compiling.

Done when

  • Both builds make shaders.bin; EngineTest's renderer runs on D3D12 with it; 0 warnings; tidy 0.

Claude can help with

  • DXC's command-line options for SPIR-V (-spirv, -fvk-*-shift).

Learn

  • What DXIL and SPIR-V are and why one HLSL source can target both.
## Why Engine shaders are compiled at run time by EngineDLL today. Compiling at build time catches errors in the build, and one HLSL source can make both DXIL and SPIR-V. ## Decided - HLSL compiled with DXC for both backends (DXIL and SPIR-V). Slang was tested side by side and rejected (`UnflavoredMeson/Primal#45`: same output quality, about 6x slower, no DXIL on Linux). - The shared HLSL lives in `Engine/Graphics/Shaders/`. - `ShaderCompilerTool` runs as a build step on both build systems and writes `x64/<Config>/shaders/{d3d12,vulkan}/shaders.bin` (a `PSHB` layout read by `content::get_engine_shaders()`). - `shaders.bin.key` holds a hash of the format version, the DXC version and all arguments; shaders recompile only when it changes. - The distro DXC on Linux can't make DXIL: Linux builds SPIR-V only. ## Read first - [LinuxVulkanPort](https://forgejo.unflavoredmeson.com/UnflavoredMeson/Primal_Plus_Plus/wiki/LinuxVulkanPort), "Phase 5 – Shader pipeline". - `EngineDLL/ShaderCompilation.cpp` on `master`. ## Steps - [ ] 1. Move the HLSL to `Engine/Graphics/Shaders/` and update both builds. - [ ] 2. Write the tool with DXC's API; add `PSHB` read/write tests in UnitTests. - [ ] 3. Add the build step and the up-to-date key; check that a second build compiles nothing. - [ ] 4. Make the engine load `shaders.bin` instead of compiling. ## Done when - [ ] Both builds make `shaders.bin`; EngineTest's renderer runs on D3D12 with it; 0 warnings; tidy 0. ## Claude can help with - DXC's command-line options for SPIR-V (`-spirv`, `-fvk-*-shift`). ## Learn - What DXIL and SPIR-V are and why one HLSL source can target both.
Sign in to join this conversation.
No assignees
No project
No milestone
Blocks
#28 ContentTools on both OSes
UnflavoredMeson/Primal_Plus_Plus
Depends on
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
UnflavoredMeson/Primal_Plus_Plus#24
No description provided.