Support #include in runtime-compiled GLSL shaders #81
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Shader::compile(engine/src/vulkan/shader.cpp) compiles GLSL at runtime with shaderc but never sets an includer. shaderc accepts#includesyntax (GL_GOOGLE_include_directive) but has no way to resolve files, so any shader using#include "common.glsl"or#include <common.glsl>fails to compile.This blocks sharing code (structs, buffer_reference layouts, helpers) between shaders, e.g.
sandbox/shaders/common.glsl.Proposal
shaderc::CompileOptions::IncluderInterface(FileIncluder):shaderc_include_type_relative("..."): search the requesting file's directory first, then the include dirs.shaderc_include_type_standard(<...>): search the include dirs only.source_namewith the error message incontent(shaderc's convention).user_data; free them inReleaseInclude.CompileOptions::SetIncluderinShader::compile.Shader::Builder::addIncludeDir(path), and have the engine always add its own shader directory so shared engine headers are available to every app (sandbox, editor, testbed).Notes
#ifndef/#defineguards.Acceptance criteria
#include "common.glsl"resolves relative to the including shader.#include <x.glsl>resolves from the configured include dirs.