Skip to content

Conversation

@ViTeXFTW
Copy link
Owner

@ViTeXFTW ViTeXFTW commented Jan 28, 2026

Summary

This PR refactors shader loading to embed compiled SPIR-V shaders directly into the application binary as C++ headers, eliminating the need to distribute and load shader files from disk at runtime.

Key Changes

  • New CMake shader embedding pipeline: Added cmake/EmbedShaders.cmake script that converts compiled SPIR-V binary files into C++ headers with inline constexpr arrays and a registry function for shader lookup by name
  • Updated CMakeLists.txt: Modified the compile_shaders() function to generate an embedded_shaders.hpp header after shader compilation, and removed the post-build copy step that distributed shader files
  • New shader loader utility: Created src/core/shader_loader.hpp with loadEmbeddedShader() function that retrieves shader bytecode from embedded data instead of reading from disk
  • Updated shader loading in Pipeline: Modified Pipeline::readFile() in src/core/pipeline.cpp to use the new embedded shader loader
  • Updated shader loading in SkeletonRenderer: Modified readShaderFile() in src/render/skeleton_renderer.cpp to use the new embedded shader loader

Implementation Details

  • The EmbedShaders.cmake script reads compiled SPIR-V files as hex and generates a C++ header with:
    • Individual constexpr uint8_t arrays for each shader
    • Inline accessor functions returning std::span<const uint8_t>
    • A getShader(std::string_view name) registry function for runtime lookup
  • Shader names are extracted from filenames (e.g., "basic.vert.spv") to support the registry lookup
  • The generated header is added to the target's include directories automatically
  • No external shader files need to be distributed with the application

Benefits

  • Simplified deployment (no separate shader files to manage)
  • Guaranteed shader availability at runtime
  • Potential for better optimization by the compiler
  • Reduced file I/O overhead

https://claude.ai/code/session_01UadMuMoxicsQ6dJ1vvEURj

Greptile Overview

Greptile Summary

This PR successfully refactors the shader loading system to embed compiled SPIR-V shaders directly into the application binary as C++ headers, eliminating runtime file I/O dependencies. The implementation is clean, well-structured, and maintains backward compatibility.

Key changes:

  • Created cmake/EmbedShaders.cmake script that converts SPIR-V binaries to C++ headers with constexpr arrays and a name-based lookup registry
  • Modified CMakeLists.txt to integrate shader embedding into the build pipeline and removed the post-build shader file copying
  • Added src/core/shader_loader.hpp utility that wraps the embedded shader access with error handling
  • Updated Pipeline::readFile() and readShaderFile() to use embedded shaders while maintaining API compatibility by extracting filenames from paths

Benefits:

  • Simplified deployment (no shader files to distribute)
  • Eliminated runtime file I/O overhead
  • Guaranteed shader availability at runtime
  • Clean separation between CMake generation and C++ consumption layers

Confidence Score: 5/5

  • This PR is safe to merge with no issues found
  • Clean refactoring with well-designed architecture, proper error handling, and no breaking changes
  • No files require special attention

Important Files Changed

Filename Overview
cmake/EmbedShaders.cmake New CMake script to convert SPIR-V binaries to C++ header with constexpr arrays and lookup registry
CMakeLists.txt Modified shader compilation to generate embedded header and removed post-build copy step
src/core/shader_loader.hpp New utility to load embedded shaders by name from generated header
src/core/pipeline.cpp Replaced file I/O with embedded shader loading, extracts filename from path for compatibility
src/render/skeleton_renderer.cpp Replaced file I/O with embedded shader loading in readShaderFile function

claude and others added 6 commits January 28, 2026 11:22
This change eliminates the runtime dependency on a shaders/ directory by
embedding SPIR-V shader bytecode directly into the executable.

Changes:
- Added cmake/EmbedShaders.cmake script to generate C++ header with embedded shader data
- Updated CMakeLists.txt to generate embedded_shaders.hpp during build
- Created src/core/shader_loader.hpp utility for loading embedded shaders
- Modified pipeline.cpp and skeleton_renderer.cpp to use embedded shaders
- Removed post-build shader directory copy step

The shaders are still compiled from GLSL to SPIR-V at build time, but are then
embedded as byte arrays in generated/embedded_shaders.hpp. This makes the
executable fully self-contained and portable.

https://claude.ai/code/session_01UadMuMoxicsQ6dJ1vvEURj
Fixed path quoting issues that could cause build failures on Windows or
when paths contain spaces:

- Added quotes around all file paths in CMakeLists.txt shader compilation
- Added quotes around all file paths in EmbedShaders.cmake
- Ensure output directory exists before generating embedded shader header
- Added debug message showing which shaders are being embedded

These changes ensure the build works correctly on Windows, Linux, and macOS
regardless of installation paths or special characters.

https://claude.ai/code/session_01UadMuMoxicsQ6dJ1vvEURj
Fixed build failure on Linux where semicolons in the shader file list
were being interpreted by the shell as command separators instead of
list delimiters. This caused cmake to try executing .spv files as
commands, resulting in "Permission denied" errors.

Solution: Use string(REPLACE) to escape semicolons before passing the
list to cmake -P, ensuring they're treated as list separators.

Error fixed:
/bin/sh: 1: /path/to/shaders/basic.vert.spv: Permission denied

https://claude.ai/code/session_01UadMuMoxicsQ6dJ1vvEURj
Cleaned up leftover file-based shader loading code:
- Removed unused #include <fstream> from pipeline.cpp and skeleton_renderer.cpp
- Reordered includes to follow project convention (local headers first)
- Improved comments to clarify that shaders are embedded and path extraction
  is for backward compatibility with existing call sites

No functional changes - shaders remain embedded in the executable.

https://claude.ai/code/session_01UadMuMoxicsQ6dJ1vvEURj
@ViTeXFTW ViTeXFTW marked this pull request as ready for review January 28, 2026 19:12
@ViTeXFTW ViTeXFTW merged commit a5bfa7f into dev Jan 28, 2026
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@ViTeXFTW ViTeXFTW deleted the claude/bake-shaders-executable-ROFjc branch January 28, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants