Shader packs for material shaders and variants #26

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

Why

Material shaders come in variants (vertex formats, features) and both backends need their own byte code. A pack compiled at build time holds them all, so assets don't carry one backend's byte code only (the fork's editor stored DXIL only and Vulkan couldn't run its materials).

Decided

  • A manifest (*.shaders) lists groups (stage, file, entry point) and variants (key + -D defines). PrimalShaderCompiler --pack <manifest> <pack> compiles it at build time with the same up-to-date check.
  • Format: module primal.shader_pack (Engine/Content/ShaderPack.ixx); content::add_shader_pack(blob, size, platform, groups).
  • Variant keys mean one thing everywhere: content::shader_variant_key() (vertex shaders: the elements type; other stages: u32_invalid_id).
  • Debug builds: SPIR-V gets -Zi (source + lines for RenderDoc, not -fspv-debug=vulkan*, which crashes DXC 1.10); DXIL PDBs go to x64/Debug/shaders/d3d12/pdb/.

Read first

  • UnflavoredMeson/Primal#17 (items 5-7) and UnflavoredMeson/Primal#35.
  • EngineTest/TestShader.hlsl on master.

Steps

  • 1. Write the manifest format and its parser, with tests.
  • 2. Write the pack format (module) with read/write tests.
  • 3. Add --pack to the compiler and EngineTest's manifest to both builds.
  • 4. Load EngineTest's materials from the pack.

Done when

  • The renderer EngineTest draws with pack shaders; pack tests pass; 0 warnings; tidy 0.

Claude can help with

  • Writing the manifest parser's error messages.

Learn

  • Why shader permutations explode and how variant keys keep them countable.
## Why Material shaders come in variants (vertex formats, features) and both backends need their own byte code. A pack compiled at build time holds them all, so assets don't carry one backend's byte code only (the fork's editor stored DXIL only and Vulkan couldn't run its materials). ## Decided - A manifest (`*.shaders`) lists groups (stage, file, entry point) and variants (key + `-D` defines). `PrimalShaderCompiler --pack <manifest> <pack>` compiles it at build time with the same up-to-date check. - Format: module `primal.shader_pack` (`Engine/Content/ShaderPack.ixx`); `content::add_shader_pack(blob, size, platform, groups)`. - Variant keys mean one thing everywhere: `content::shader_variant_key()` (vertex shaders: the elements type; other stages: `u32_invalid_id`). - Debug builds: SPIR-V gets `-Zi` (source + lines for RenderDoc, not `-fspv-debug=vulkan*`, which crashes DXC 1.10); DXIL PDBs go to `x64/Debug/shaders/d3d12/pdb/`. ## Read first - `UnflavoredMeson/Primal#17` (items 5-7) and `UnflavoredMeson/Primal#35`. - `EngineTest/TestShader.hlsl` on `master`. ## Steps - [ ] 1. Write the manifest format and its parser, with tests. - [ ] 2. Write the pack format (module) with read/write tests. - [ ] 3. Add `--pack` to the compiler and EngineTest's manifest to both builds. - [ ] 4. Load EngineTest's materials from the pack. ## Done when - [ ] The renderer EngineTest draws with pack shaders; pack tests pass; 0 warnings; tidy 0. ## Claude can help with - Writing the manifest parser's error messages. ## Learn - Why shader permutations explode and how variant keys keep them countable.
Sign in to join this conversation.
No assignees
No project
No milestone
Blocks
#27 Shader hot reload
UnflavoredMeson/Primal_Plus_Plus
#32 Vulkan content, uploads and descriptors
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#26
No description provided.