# Embeds the native renderer HLSL sources (src/native/shaders/*.hlsl) into a # generated C++ header so the exe stays self-contained. Run as a script: # cmake -DSHADER_DIR= -DOUT=
-P EmbedShaders.cmake # Each shader becomes `inline constexpr char [] = R"__hlsl__(...)__hlsl__";` # with a leading newline, matching the original in-cpp raw string literals # (consumers use sizeof(kX) - 1). set(SHADER_VARS kShaderSource kShadowBlurSource kResolveShaderSource kBlurShaderSource kOutlineShaderSource kShader2dSource kShaderSplineSource kPhotoFxShaderSource kSsaoShaderSource kHdrShaderSource kSsrShaderSource ) set(SHADER_FILES scene.hlsl shadow_blur.hlsl resolve.hlsl blur.hlsl outline.hlsl overlay2d.hlsl spline.hlsl photo_fx.hlsl ssao.hlsl hdr.hlsl ssr.hlsl ) set(content "// Generated by cmake/EmbedShaders.cmake from src/native/shaders/*.hlsl.\n") string(APPEND content "// DO NOT EDIT - edit the .hlsl files instead.\n") string(APPEND content "#pragma once\n\n") foreach(var file IN ZIP_LISTS SHADER_VARS SHADER_FILES) file(READ "${SHADER_DIR}/${file}" src) # Inline `#include "x.hlsli"` directives so every embedded shader stays a # single self-contained string: the D3D12 backend hands the text to # D3DCompile without an include handler, and the shader bytecode cache # hashes the full text; pre-expanding means an include edit changes the # embedded source and invalidates cached bytecode naturally. The loop # rescans after each replacement, so nested includes expand too; the # iteration guard catches cycles. set(guard 0) while(src MATCHES "#include \"([^\"]+)\"") set(inc "${CMAKE_MATCH_1}") if(NOT EXISTS "${SHADER_DIR}/${inc}") message(FATAL_ERROR "${file}: include not found: ${inc}") endif() file(READ "${SHADER_DIR}/${inc}" inc_src) string(REPLACE "#include \"${inc}\"" "${inc_src}" src "${src}") math(EXPR guard "${guard} + 1") if(guard GREATER 32) message(FATAL_ERROR "${file}: include expansion did not converge (cycle?)") endif() endwhile() string(FIND "${src}" ")__hlsl__" collision) if(NOT collision EQUAL -1) message(FATAL_ERROR "${file} contains the raw-string delimiter )__hlsl__") endif() string(APPEND content "// ${file}\n") string(APPEND content "inline constexpr char ${var}[] = R\"__hlsl__(\n${src})__hlsl__\";\n\n") endforeach() file(WRITE "${OUT}" "${content}")