feat(render3d): every shader variant as Vulkan SPIR-V, built ahead of time

Vulkan cannot compile GLSL when the game starts, so the programs render3d builds are listed
(shaders/variants.list, 45 of them, collected with R3D_PROGRAMS_LOG across the self-tests, the
screens, the viewpoints and the debug switches) and `ludic-dev shaders` compiles each into
shaders/spv/<id>.vert.spv and .frag.spv with a manifest of what the backend needs: each
stage's uniform block and member offsets, the samplers' bindings, the vertex inputs.

The GLSL is the renderer's own, assembled as programs.ludic assembles it, through glslang's
relaxed Vulkan mode, so gpu_uniform / u_* can write the same uniforms into a block on Vulkan.
Bindings are assigned by the tool (glslang's own numbering put several samplers of one stage
on binding 0): the vertex block is 0, the fragment block 1, samplers from 2 in name order,
shared across both stages. Every stage passes spirv-val; `ludic-dev test` rebuilds and compares
wherever the Vulkan SDK is installed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-15 10:11:31 +03:00
parent bd79b276e9
commit 3fb1b7cd87
97 changed files with 2657 additions and 0 deletions

View file

@ -52,6 +52,7 @@ var ov_clip_w: int = 0
var ov_clip_h: int = 0
function overlay_init(font_dir: string) -> bool {
r3d_program_log("overlay.vert", "overlay.frag", "")
ov_prog = gl_program("#version 410 core\n" + r3d_shader_file("overlay.vert"), "#version 410 core\n" + r3d_shader_file("overlay.frag"))
if ov_prog == 0 { print("overlay: program failed"); return false }
ov_vao = gl_vao()

View file

@ -65,7 +65,22 @@ function r3d_program_tess(vs: string, tcs: string, tes: string, fs: string, defi
}
# Build a program from a vertex + fragment file pair (defines apply to both).
# R3D_PROGRAMS_LOG=<file>: append every program built (vertex, fragment, defines) - the list a
# backend that cannot compile shaders at run time (Vulkan: SPIR-V is built ahead) must cover
var r3d_prog_log: int = -1
function r3d_program_log(vs: string, fs: string, defines: string) -> void {
if r3d_prog_log < 0 { r3d_prog_log = 0; if Os.has_env("R3D_PROGRAMS_LOG") { r3d_prog_log = 1 } }
if r3d_prog_log == 0 { return }
let f = file_open(Os.env("R3D_PROGRAMS_LOG"), "ab")
if f == null { return }
# one line per program: the defines' newlines become ';' so a variant is one line
let defs = Text.replace(`{r3d_global_defs}{defines}`, "\n", ";")
let line = `{vs}|{fs}|{defs}\n`
file_write(f, line, len(line))
file_close(f)
}
function r3d_program(vs: string, fs: string, defines: string) -> int {
r3d_program_log(vs, fs, defines)
let p = gl_program(r3d_shader_src(vs, defines, false), r3d_shader_src(fs, defines, true))
if p == 0 { print(`r3d: program failed: {vs} + {fs}`) }
return p

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,49 @@
# variants.list - every program render3d builds: vertex|fragment|defines (one line; newlines
# in the defines are written as ";"). A backend that cannot compile shaders at run time
# (Vulkan: SPIR-V is built ahead) must cover all of them. Regenerate by running the game and
# its self-tests with R3D_PROGRAMS_LOG=<file> and sorting the result.
fullscreen.vert|adapt.frag|
fullscreen.vert|bloom_down.frag|
fullscreen.vert|bloom_up.frag|
fullscreen.vert|heightgen.frag|#define DEM;
fullscreen.vert|ibl_brdf.frag|
fullscreen.vert|ibl_irradiance.frag|
fullscreen.vert|ibl_prefilter.frag|
fullscreen.vert|sharpen.frag|
fullscreen.vert|sky.frag|
fullscreen.vert|ssao_blur.frag|
fullscreen.vert|ssgi.frag|
fullscreen.vert|ternormal.frag|
fullscreen.vert|tershadow.frag|#define NOISE_ONLY;
fullscreen.vert|tonemap.frag|
grass.vert|model.frag|#define FOLIAGE;#define BLADE;
impostor.vert|impostor.frag|
impostor.vert|impostor.frag|#define SHADOW_PASS;
model.vert|bake.frag|
model.vert|bake.frag|#define CARD;
model.vert|bake.frag|#define FLOWER;
model.vert|depth.frag|#define FOLIAGE;#define WIND;#define ALPHA_TEST;
model.vert|model.frag|
model.vert|model.frag|#define CARD;#define CHEAP;
model.vert|model.frag|#define FOLIAGE;#define WIND;#define ALPHA_TEST;
model.vert|model.frag|#define FOLIAGE;#define WIND;#define BLADE;
model.vert|model.frag|#define FOLIAGE;#define WIND;#define CARD;
model.vert|model.frag|#define FOLIAGE;#define WIND;#define EQ_PASS;
model.vert|model.frag|#define FOLIAGE;#define WIND;#define FLOWER;
model.vert|model.frag|#define SHADOW_PASS;#define WIND;#define CARD;
model.vert|model.frag|#define WIND;
model.vert|shadow.frag|#define SHADOW_PASS;
model.vert|shadow.frag|#define SHADOW_PASS;#define WIND;
model.vert|shadow.frag|#define SHADOW_PASS;#define WIND;#define ALPHA_TEST;
overlay.vert|overlay.frag|
skin.vert|model.frag|
skin.vert|model.frag|#define ALPHA_TEST;
skin.vert|outline.frag|#define OUTLINE;
skin.vert|outline.frag|#define OUTLINE;#define ALPHA_TEST;
skin.vert|shadow.frag|#define SHADOW_PASS;
skin.vert|shadow.frag|#define SHADOW_PASS;#define ALPHA_TEST;
terrain.vert|terrain.frag|
terrain.vert|terrain.frag|#define FAR_ONLY;
terrain.vert|terrain.frag|#define NEAR_ONLY;
terrain.vert|tersun.frag|
water.vert|water.frag|