horizon-shaderpack: translate Java shader pack programs to WGSL
The legaliser of docs/shader-packs.md step 1, on a syntax tree (glsl-lang) instead of the spike's tokens: attribute/varying to located in/out with matrix and array varyings split, loose uniforms in one std140 block that extends across a pass, combined samplers split into texture + sampler bindings (through function parameters, respecting locals that hide them), compatibility built-ins and Iris's core-profile names declared, legacy texture and shadow calls, hoisted global initialisers, sized unsized arrays, isnan/isinf/modf helpers, and dead code after a jump dropped (the spike's 'naga constructor bug' in BSL was code after discard). naga then parses, validates and writes WGSL. The programs of one pass share a Link so locations, bindings and the uniform layout agree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Generated
+378
-6
@@ -178,6 +178,15 @@ version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "175571dd1d178ced59193a6fc02dde1b972eb0bc56c892cde9beeceac5bf0f6b"
|
||||
|
||||
[[package]]
|
||||
name = "ascii-canvas"
|
||||
version = "4.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef1e3e699d84ab1b0911a1010c5c106aa34ae89aeac103be5ce0c3859db1e891"
|
||||
dependencies = [
|
||||
"term",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ash"
|
||||
version = "0.38.0+1.3.281"
|
||||
@@ -205,15 +214,30 @@ version = "0.22.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||
|
||||
[[package]]
|
||||
name = "bit-set"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3"
|
||||
dependencies = [
|
||||
"bit-vec 0.8.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit-set"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ec2f926cc3060f09db9ebc5b52823d85268d24bb917e472c0c4bea35780a7d"
|
||||
dependencies = [
|
||||
"bit-vec",
|
||||
"bit-vec 0.9.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit-vec"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7"
|
||||
|
||||
[[package]]
|
||||
name = "bit-vec"
|
||||
version = "0.9.1"
|
||||
@@ -259,6 +283,16 @@ dependencies = [
|
||||
"objc2 0.6.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "borsh"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "553c5d846a6ba5150c65e3b1b8ec073bcf1abc20f9b7220de384a4443ea4e20a"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"cfg_aliases",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.20.3"
|
||||
@@ -450,6 +484,15 @@ dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "convert_case"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "633458d4ef8c78b72454de2d54fd6ab2e60f9e02be22f3c6104cdc8a4e0fceb9"
|
||||
dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "coords-hud"
|
||||
version = "0.1.0"
|
||||
@@ -754,6 +797,41 @@ dependencies = [
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_core"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dasp_sample"
|
||||
version = "0.11.0"
|
||||
@@ -771,6 +849,29 @@ dependencies = [
|
||||
"syn 3.0.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_more"
|
||||
version = "2.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d751e9e49156b02b44f9c1815bcb94b984cdcc4396ecc32521c739452808b134"
|
||||
dependencies = [
|
||||
"derive_more-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_more-impl"
|
||||
version = "2.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb"
|
||||
dependencies = [
|
||||
"convert_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustc_version",
|
||||
"syn 2.0.119",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
@@ -857,6 +958,15 @@ version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d"
|
||||
|
||||
[[package]]
|
||||
name = "ena"
|
||||
version = "0.14.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eabffdaee24bd1bf95c5ef7cec31260444317e72ea56c4c91750e8b7ee58d5f1"
|
||||
dependencies = [
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
version = "0.8.42"
|
||||
@@ -1120,6 +1230,58 @@ version = "0.30.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19fc433e8437a212d1b6f1e68c7824af3aed907da60afa994e7f542d18d12aa9"
|
||||
|
||||
[[package]]
|
||||
name = "glsl-lang"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "983a18d0c2ecad18ac9ff3c94b069d6bd03b47405a200836d9d8d63def8e34de"
|
||||
dependencies = [
|
||||
"glsl-lang-lexer",
|
||||
"glsl-lang-types",
|
||||
"lalrpop",
|
||||
"lalrpop-util",
|
||||
"lang-util",
|
||||
"once_cell",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glsl-lang-lexer"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "abdbc0bdfbc81d557f4865e695457eb23d68031bfb061fda3444f56511b26eee"
|
||||
dependencies = [
|
||||
"glsl-lang-pp",
|
||||
"glsl-lang-types",
|
||||
"lalrpop-util",
|
||||
"lang-util",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glsl-lang-pp"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "88677876fb27f116015d0ecebda6d77bdf65f3a6fa3f5dfeed10b8c8f04cb2c5"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"derive_more",
|
||||
"lang-util",
|
||||
"string_cache",
|
||||
"string_cache_codegen",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glsl-lang-types"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd8b1532b424d40df634cf2dc2be56d59f994b9ac07fa7c1e3183fd33db9cb07"
|
||||
dependencies = [
|
||||
"lang-util",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gpu-allocator"
|
||||
version = "0.28.0"
|
||||
@@ -1368,6 +1530,8 @@ dependencies = [
|
||||
name = "horizon-shaderpack"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"glsl-lang",
|
||||
"naga",
|
||||
"pp-rs",
|
||||
"zip",
|
||||
]
|
||||
@@ -1512,6 +1676,12 @@ version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
|
||||
|
||||
[[package]]
|
||||
name = "ident_case"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "1.1.0"
|
||||
@@ -1694,6 +1864,73 @@ dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "keccak"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb26cec98cce3a3d96cbb7bced3c4b16e3d13f27ec56dbd62cbc8f39cfb9d653"
|
||||
dependencies = [
|
||||
"cpufeatures",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lalrpop"
|
||||
version = "0.22.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba4ebbd48ce411c1d10fb35185f5a51a7bfa3d8b24b4e330d30c9e3a34129501"
|
||||
dependencies = [
|
||||
"ascii-canvas",
|
||||
"bit-set 0.8.0",
|
||||
"ena",
|
||||
"itertools",
|
||||
"lalrpop-util",
|
||||
"petgraph 0.7.1",
|
||||
"pico-args",
|
||||
"regex",
|
||||
"regex-syntax",
|
||||
"sha3",
|
||||
"string_cache",
|
||||
"term",
|
||||
"unicode-xid",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lalrpop-util"
|
||||
version = "0.22.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5baa5e9ff84f1aefd264e6869907646538a52147a755d494517a8007fb48733"
|
||||
dependencies = [
|
||||
"regex-automata",
|
||||
"rustversion",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lang-util"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d1715a1e56998f119cd6d49ac8a69802dcbe4fca96d8291243d6dae87abeb913"
|
||||
dependencies = [
|
||||
"derive_more",
|
||||
"lalrpop-util",
|
||||
"lang-util-derive",
|
||||
"line-span",
|
||||
"smol_str 0.3.6",
|
||||
"text-size",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lang-util-derive"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f2acc66aedf0e445534e0a6b3f0f6ee20ef6ebb9647dbe10735e52ea8d6a096"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.1"
|
||||
@@ -1750,6 +1987,12 @@ dependencies = [
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "line-span"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29fc123b2f6600099ca18248f69e3ee02b09c4188c0d98e9a690d90dec3e408a"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.15"
|
||||
@@ -1861,7 +2104,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a616d2fb8c89516ac2723a581f69d6c18576046bed761bd6b305e5618e6ae130"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bit-set",
|
||||
"bit-set 0.10.0",
|
||||
"bitflags 2.13.2",
|
||||
"cfg-if",
|
||||
"cfg_aliases",
|
||||
@@ -1874,6 +2117,7 @@ dependencies = [
|
||||
"naga-types",
|
||||
"num-traits",
|
||||
"once_cell",
|
||||
"pp-rs",
|
||||
"rustc-hash 1.1.0",
|
||||
"spirv",
|
||||
"thiserror 2.0.21",
|
||||
@@ -1922,6 +2166,12 @@ dependencies = [
|
||||
"jni-sys 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "new_debug_unreachable"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086"
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.31.3"
|
||||
@@ -2421,6 +2671,16 @@ version = "2.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
|
||||
|
||||
[[package]]
|
||||
name = "petgraph"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3672b37090dbd86368a4145bc067582552b29c27377cad4e0a306c97f9bd7772"
|
||||
dependencies = [
|
||||
"fixedbitset",
|
||||
"indexmap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "petgraph"
|
||||
version = "0.8.3"
|
||||
@@ -2432,6 +2692,31 @@ dependencies = [
|
||||
"indexmap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_generator"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d"
|
||||
dependencies = [
|
||||
"phf_shared",
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_shared"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5"
|
||||
dependencies = [
|
||||
"siphasher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pico-args"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project"
|
||||
version = "1.1.13"
|
||||
@@ -2559,6 +2844,12 @@ dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "precomputed-hash"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
|
||||
|
||||
[[package]]
|
||||
name = "presser"
|
||||
version = "0.3.1"
|
||||
@@ -2652,6 +2943,15 @@ version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e058c7de0b26af77780c769414d6257830bb240f3c38477dbc2c16e5f54d6d4c"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
@@ -2984,6 +3284,16 @@ dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha3"
|
||||
version = "0.10.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77fd7028345d415a4034cf8777cd4f8ab1851274233b45f84e3d955502d93874"
|
||||
dependencies = [
|
||||
"digest",
|
||||
"keccak",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "2.0.1"
|
||||
@@ -3012,6 +3322,12 @@ version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33f4fe9184a62d842c9ef383018f3306d8ba224fd9d836f56d7288308847c256"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.12"
|
||||
@@ -3061,6 +3377,16 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smol_str"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4aaa7368fcf4852a4c2dd92df0cace6a71f2091ca0a23391ce7f3a31833f1523"
|
||||
dependencies = [
|
||||
"borsh",
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
version = "0.5.10"
|
||||
@@ -3110,6 +3436,37 @@ version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731"
|
||||
|
||||
[[package]]
|
||||
name = "string_cache"
|
||||
version = "0.8.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf776ba3fa74f83bf4b63c3dcbbf82173db2632ed8452cb2d891d33f459de70f"
|
||||
dependencies = [
|
||||
"new_debug_unreachable",
|
||||
"parking_lot",
|
||||
"phf_shared",
|
||||
"precomputed-hash",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "string_cache_codegen"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c711928715f1fe0fe509c53b43e993a9a557babc2d0a3567d0a3006f1ac931a0"
|
||||
dependencies = [
|
||||
"phf_generator",
|
||||
"phf_shared",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "2.6.1"
|
||||
@@ -3226,6 +3583,15 @@ version = "0.13.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
|
||||
|
||||
[[package]]
|
||||
name = "term"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8c27177b12a6399ffc08b98f76f7c9a1f4fe9fc967c784c5a071fa8d93cf7e1"
|
||||
dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.4.1"
|
||||
@@ -3235,6 +3601,12 @@ dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "text-size"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f18aa187839b2bdb1ad2fa35ead8c4c2976b64e4363c386d45ac0f7ee85c9233"
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.69"
|
||||
@@ -3394,7 +3766,7 @@ checksum = "b8765b90061cba6c22b5831f675da109ae5561588290f9fa2317adab2714d5a6"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"nom",
|
||||
"petgraph",
|
||||
"petgraph 0.8.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4115,8 +4487,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14c018fce9b6270aa203c2fdd56f3cce996713534bd757e4ea58c8560b121f14"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bit-set",
|
||||
"bit-vec",
|
||||
"bit-set 0.10.0",
|
||||
"bit-vec 0.9.1",
|
||||
"bitflags 2.13.2",
|
||||
"bytemuck",
|
||||
"cfg_aliases",
|
||||
@@ -4662,7 +5034,7 @@ dependencies = [
|
||||
"rustix 0.38.44",
|
||||
"sctk-adwaita",
|
||||
"smithay-client-toolkit",
|
||||
"smol_str",
|
||||
"smol_str 0.2.2",
|
||||
"tracing",
|
||||
"unicode-segmentation",
|
||||
"wasm-bindgen",
|
||||
|
||||
@@ -7,6 +7,8 @@ rust-version.workspace = true
|
||||
description = "Java (OptiFine/Iris) shader packs for Horizon: Iris's preprocessor and the GLSL to WGSL translation"
|
||||
|
||||
[dependencies]
|
||||
glsl-lang = "0.8.1"
|
||||
naga = { version = "30.0.1", features = ["glsl-in", "wgsl-in", "wgsl-out"] }
|
||||
# The C preprocessor naga's GLSL front end uses.
|
||||
pp-rs = "0.2.1"
|
||||
zip = { version = "2", default-features = false, features = ["deflate"] }
|
||||
|
||||
@@ -8,6 +8,7 @@ pub mod include;
|
||||
pub mod options;
|
||||
pub mod preprocess;
|
||||
pub mod source;
|
||||
pub mod translate;
|
||||
|
||||
use include::{IncludeGraph, Inlined};
|
||||
use options::{Annotated, OptionSet, OptionValues};
|
||||
@@ -17,6 +18,7 @@ use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
path::Path,
|
||||
};
|
||||
use translate::{Link, Translated};
|
||||
|
||||
/// A program's pipeline stage, from its file extension.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
@@ -119,4 +121,20 @@ impl JavaPack {
|
||||
) -> Result<Preprocessed, String> {
|
||||
preprocess::preprocess(&self.source(program, values)?, env)
|
||||
}
|
||||
|
||||
/// `program` translated to WGSL. The programs of one pass (its `.vsh`,
|
||||
/// then its `.fsh`) share `link`.
|
||||
pub fn translate(
|
||||
&self,
|
||||
program: &str,
|
||||
values: &OptionValues,
|
||||
env: &Environment,
|
||||
link: &mut Link,
|
||||
) -> Result<Translated, String> {
|
||||
let stage = Stage::of(program).ok_or_else(|| format!("{program}: not a program"))?;
|
||||
let source = self.source(program, values)?;
|
||||
let pre = preprocess::preprocess(&source, env)?;
|
||||
translate::translate(stage, &pre.text, link, &|line| source.locate(line))
|
||||
.map_err(|e| format!("{program}: {e}"))
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,352 @@
|
||||
//! The GLSL → WGSL translation on hand-written compatibility-profile
|
||||
//! programs, checked through naga's IR (locations, bindings, uniform block),
|
||||
//! and on real packs when `HORIZON_TEST_SHADERPACKS` names a folder of them.
|
||||
|
||||
use horizon_shaderpack::{
|
||||
JavaPack, Stage,
|
||||
include::Inlined,
|
||||
preprocess::{Environment, preprocess},
|
||||
translate::{Link, Translated, translate},
|
||||
};
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
fn env() -> Environment {
|
||||
Environment::iris("Apple", "Apple M4 Pro", 4)
|
||||
}
|
||||
|
||||
fn run(stage: Stage, source: &str, link: &mut Link) -> Result<Translated, String> {
|
||||
let inlined = Inlined {
|
||||
text: source.to_owned(),
|
||||
origin: Vec::new(),
|
||||
};
|
||||
let pre = preprocess(&inlined, &env())?;
|
||||
translate(stage, &pre.text, link, &|line| format!("line {line}"))
|
||||
}
|
||||
|
||||
/// `(name, location)` of an entry point's inputs (`result: false`) or outputs.
|
||||
fn io(t: &Translated, result: bool) -> BTreeMap<String, u32> {
|
||||
let f = &t.module.entry_points[0].function;
|
||||
let mut out = BTreeMap::new();
|
||||
let mut add =
|
||||
|name: Option<&String>, binding: &Option<naga::Binding>, ty: naga::Handle<naga::Type>| {
|
||||
match (binding, &t.module.types[ty].inner) {
|
||||
(Some(naga::Binding::Location { location, .. }), _) => {
|
||||
out.insert(name.cloned().unwrap_or_default(), *location);
|
||||
}
|
||||
(None, naga::TypeInner::Struct { members, .. }) => {
|
||||
for m in members {
|
||||
if let Some(naga::Binding::Location { location, .. }) = &m.binding {
|
||||
out.insert(m.name.clone().unwrap_or_default(), *location);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
};
|
||||
if result {
|
||||
if let Some(r) = &f.result {
|
||||
add(None, &r.binding, r.ty);
|
||||
}
|
||||
} else {
|
||||
for a in &f.arguments {
|
||||
add(a.name.as_ref(), &a.binding, a.ty);
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Group 0 bindings of the module's resources, by variable name.
|
||||
fn bindings(t: &Translated) -> BTreeMap<String, u32> {
|
||||
t.module
|
||||
.global_variables
|
||||
.iter()
|
||||
.filter_map(|(_, v)| Some((v.name.clone()?, v.binding.as_ref()?.binding)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The uniform block's member names, in order.
|
||||
fn block_members(t: &Translated) -> Vec<String> {
|
||||
t.module
|
||||
.global_variables
|
||||
.iter()
|
||||
.find(|(_, v)| v.space == naga::AddressSpace::Uniform)
|
||||
.map(|(_, v)| match &t.module.types[v.ty].inner {
|
||||
naga::TypeInner::Struct { members, .. } => {
|
||||
members.iter().filter_map(|m| m.name.clone()).collect()
|
||||
}
|
||||
_ => Vec::new(),
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
const VSH: &str = r#"
|
||||
#version 120
|
||||
attribute vec4 mc_Entity;
|
||||
uniform mat4 gbufferModelView;
|
||||
uniform bool hasSkylight;
|
||||
varying vec2 texcoord;
|
||||
varying vec4 color;
|
||||
varying mat3 tbn;
|
||||
varying float entity;
|
||||
void main() {
|
||||
gl_Position = ftransform();
|
||||
texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
|
||||
color = gl_Color;
|
||||
gl_FrontColor = gl_Color;
|
||||
tbn = mat3(gbufferModelView) * gl_NormalMatrix;
|
||||
entity = hasSkylight ? mc_Entity.x : 0.0;
|
||||
}
|
||||
"#;
|
||||
|
||||
const FSH: &str = r#"
|
||||
#version 120
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2DShadow shadowtex0;
|
||||
uniform float frameTimeCounter;
|
||||
varying vec2 texcoord;
|
||||
varying vec4 color;
|
||||
varying mat3 tbn;
|
||||
float phase = frameTimeCounter * 2.0;
|
||||
const float weights[] = float[](0.25, 0.5, 0.25);
|
||||
vec4 sampleTwice(sampler2D tex, vec2 uv) {
|
||||
return texture2D(tex, uv) + texture2D(tex, uv + vec2(phase));
|
||||
}
|
||||
float shade(vec3 p) {
|
||||
float texture = shadow2D(shadowtex0, p).x;
|
||||
return texture * weights[1];
|
||||
}
|
||||
void main() {
|
||||
vec4 albedo = sampleTwice(texture, texcoord) * color;
|
||||
if (isnan(albedo.r)) {
|
||||
discard;
|
||||
albedo = vec4(0.0);
|
||||
}
|
||||
gl_FragData[0] = albedo * shade(tbn[2]) * gl_Color;
|
||||
gl_FragData[1] = vec4(texture(shadowtex0, vec3(texcoord, 0.5)).x);
|
||||
}
|
||||
"#;
|
||||
|
||||
#[test]
|
||||
fn translates_a_compatibility_profile_pass() {
|
||||
let mut link = Link::default();
|
||||
let vs = run(Stage::Vertex, VSH, &mut link).unwrap();
|
||||
let fs = run(Stage::Fragment, FSH, &mut link).unwrap();
|
||||
|
||||
// The varyings meet at the same locations, the mat3 as three columns.
|
||||
let outs = io(&vs, true);
|
||||
let ins = io(&fs, false);
|
||||
for name in [
|
||||
"texcoord",
|
||||
"color",
|
||||
"tbn_iris0",
|
||||
"tbn_iris1",
|
||||
"tbn_iris2",
|
||||
"iris_FrontColor",
|
||||
] {
|
||||
assert_eq!(
|
||||
outs.get(name),
|
||||
ins.get(name),
|
||||
"{name}: vs {outs:?} fs {ins:?}"
|
||||
);
|
||||
assert!(outs.contains_key(name), "{name} in {outs:?}");
|
||||
}
|
||||
assert!(outs.contains_key("entity") && !ins.contains_key("entity"));
|
||||
// Attributes: the pack's, then the compatibility ones it reads.
|
||||
let attributes: Vec<String> = io(&vs, false).into_keys().collect();
|
||||
assert_eq!(
|
||||
attributes,
|
||||
[
|
||||
"iris_Color",
|
||||
"iris_MultiTexCoord0",
|
||||
"iris_Vertex",
|
||||
"mc_Entity"
|
||||
]
|
||||
);
|
||||
// gl_FragData[n] are the outputs at location n.
|
||||
assert_eq!(
|
||||
fs.interface.outputs.keys().copied().collect::<Vec<_>>(),
|
||||
[0, 1]
|
||||
);
|
||||
assert_eq!(
|
||||
io(&fs, true).values().copied().collect::<BTreeSet<_>>(),
|
||||
[0, 1].into()
|
||||
);
|
||||
|
||||
// One block whose members extend across the pass: the fragment program's
|
||||
// starts with the vertex program's, so offsets agree.
|
||||
let vs_block = block_members(&vs);
|
||||
let fs_block = block_members(&fs);
|
||||
assert_eq!(
|
||||
vs_block,
|
||||
[
|
||||
"gbufferModelView",
|
||||
"iris_bool_hasSkylight",
|
||||
"iris_ModelViewProjectionMatrix",
|
||||
"iris_TextureMatrix",
|
||||
"iris_NormalMatrix"
|
||||
]
|
||||
);
|
||||
assert_eq!(fs_block[..vs_block.len()], vs_block[..]);
|
||||
assert_eq!(fs_block[vs_block.len()..], ["frameTimeCounter"]);
|
||||
|
||||
// Samplers split into texture + sampler bindings, shared by the pass.
|
||||
let b = bindings(&fs);
|
||||
let block = fs
|
||||
.module
|
||||
.global_variables
|
||||
.iter()
|
||||
.find(|(_, v)| v.space == naga::AddressSpace::Uniform)
|
||||
.unwrap()
|
||||
.1;
|
||||
assert_eq!(
|
||||
block.binding.as_ref().map(|b| (b.group, b.binding)),
|
||||
Some((0, 0))
|
||||
);
|
||||
for name in ["texture_t", "texture_s", "shadowtex0_t", "shadowtex0_s"] {
|
||||
assert_eq!(b[name], link.bindings[name], "{name}");
|
||||
}
|
||||
assert_eq!(
|
||||
fs.interface.samplers,
|
||||
[
|
||||
("texture".into(), "sampler2D".into()),
|
||||
("shadowtex0".into(), "sampler2DShadow".into())
|
||||
]
|
||||
);
|
||||
// A local named `texture` hides the sampler; the sampler parameter is split.
|
||||
assert!(
|
||||
fs.glsl.contains(
|
||||
"float texture = vec4(texture(sampler2DShadow(shadowtex0_t, shadowtex0_s), p)).x;"
|
||||
),
|
||||
"{}",
|
||||
fs.glsl
|
||||
);
|
||||
assert!(
|
||||
fs.glsl
|
||||
.contains("vec4 sampleTwice(texture2D tex_t, sampler tex_s, vec2 uv)"),
|
||||
"{}",
|
||||
fs.glsl
|
||||
);
|
||||
assert!(
|
||||
fs.glsl
|
||||
.contains("sampleTwice(texture_t, texture_s, texcoord)"),
|
||||
"{}",
|
||||
fs.glsl
|
||||
);
|
||||
// Global initialisers run first; the unsized array is sized.
|
||||
assert!(
|
||||
fs.glsl.contains("phase = frameTimeCounter * 2.;"),
|
||||
"{}",
|
||||
fs.glsl
|
||||
);
|
||||
assert!(
|
||||
fs.glsl
|
||||
.contains("const float weights[3] = float[3](0.25, 0.5, 0.25);"),
|
||||
"{}",
|
||||
fs.glsl
|
||||
);
|
||||
// The code after `discard` is gone, isnan is a helper.
|
||||
assert!(!fs.glsl.contains("albedo = vec4(0.);"), "{}", fs.glsl);
|
||||
assert!(fs.glsl.contains("iris_isnan(albedo.r)"), "{}", fs.glsl);
|
||||
assert!(fs.wgsl.contains("@fragment"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reports_errors_with_their_place() {
|
||||
let mut link = Link::default();
|
||||
let err = run(
|
||||
Stage::Fragment,
|
||||
"void main() {\n float x = ;\n}\n",
|
||||
&mut link,
|
||||
)
|
||||
.err()
|
||||
.unwrap();
|
||||
assert!(err.starts_with("line 2:"), "{err}");
|
||||
let err = run(Stage::Geometry, "void main() {}", &mut link)
|
||||
.err()
|
||||
.unwrap();
|
||||
assert_eq!(err, "Geometry programs are not supported");
|
||||
let mut link = Link::default();
|
||||
run(
|
||||
Stage::Vertex,
|
||||
"uniform float a;\nvoid main() { gl_Position = vec4(a); }",
|
||||
&mut link,
|
||||
)
|
||||
.unwrap();
|
||||
let err = run(
|
||||
Stage::Fragment,
|
||||
"uniform int a;\nvoid main() { gl_FragColor = vec4(a); }",
|
||||
&mut link,
|
||||
)
|
||||
.err()
|
||||
.unwrap();
|
||||
assert_eq!(err, "uniform a is declared as both `float a` and `int a`");
|
||||
}
|
||||
|
||||
/// The written WGSL, read back and validated: what wgpu is given.
|
||||
fn reparse(wgsl: &str) -> Result<(), String> {
|
||||
let module = naga::front::wgsl::parse_str(wgsl).map_err(|e| e.emit_to_string(wgsl))?;
|
||||
naga::valid::Validator::new(
|
||||
naga::valid::ValidationFlags::all(),
|
||||
naga::valid::Capabilities::all(),
|
||||
)
|
||||
.validate(&module)
|
||||
.map(|_| ())
|
||||
.map_err(|e| e.emit_to_string(wgsl))
|
||||
}
|
||||
|
||||
/// Every program the packs in `HORIZON_TEST_SHADERPACKS` enable by default
|
||||
/// translates to WGSL that reads back (each pass's `.vsh` before its `.fsh`). Skipped when the
|
||||
/// variable isn't set. Distant Horizons, Colorwheel and Voxy programs are
|
||||
/// left out: Iris loads them only with those mods.
|
||||
#[test]
|
||||
fn real_packs_translate() {
|
||||
let Some(dir) = std::env::var_os("HORIZON_TEST_SHADERPACKS") else {
|
||||
return;
|
||||
};
|
||||
// Off by default (`program.*/shadowcomp.enabled` in shaders.properties).
|
||||
let disabled = ["shadowcomp.csh"];
|
||||
let mut failures = Vec::new();
|
||||
for entry in std::fs::read_dir(dir).unwrap().flatten() {
|
||||
let Ok(pack) = JavaPack::open(&entry.path()) else {
|
||||
continue;
|
||||
};
|
||||
let values = pack.values(&BTreeMap::new());
|
||||
let mut passes: BTreeMap<&str, Vec<&String>> = BTreeMap::new();
|
||||
for p in &pack.programs {
|
||||
let file = p.rsplit('/').next().unwrap();
|
||||
if ["dh_", "clrwl_", "voxy"]
|
||||
.iter()
|
||||
.any(|m| file.starts_with(m))
|
||||
|| disabled.contains(&file)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
passes
|
||||
.entry(p.rsplit_once('.').unwrap().0)
|
||||
.or_default()
|
||||
.push(p);
|
||||
}
|
||||
let (mut ok, mut total) = (0, 0);
|
||||
for programs in passes.values_mut() {
|
||||
programs.sort_by_key(|p| !p.ends_with(".vsh"));
|
||||
let mut link = Link::default();
|
||||
for p in programs.iter() {
|
||||
total += 1;
|
||||
match pack
|
||||
.translate(p, &values, &env(), &mut link)
|
||||
.and_then(|t| reparse(&t.wgsl))
|
||||
{
|
||||
Ok(()) => ok += 1,
|
||||
Err(e) => {
|
||||
failures.push(format!("{}: {e}", entry.file_name().to_string_lossy()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
println!(
|
||||
"{}: {ok}/{total} programs translated",
|
||||
entry.file_name().to_string_lossy()
|
||||
);
|
||||
}
|
||||
assert!(failures.is_empty(), "{}", failures.join("\n\n"));
|
||||
}
|
||||
@@ -17,6 +17,7 @@ Both are off by default. With no pack selected the renderer draws exactly what i
|
||||
| Horizon shader packs: `deferred`, `gbuffer`, `shadow` stages, custom textures | planned |
|
||||
| Java shader packs: preprocessing + GLSL parse coverage | spike done: 450 of 470 programs reach valid WGSL (below) |
|
||||
| Java shader packs: preprocessor (`crates/horizon-shaderpack`: includes, options, Iris's macros) | done: every program of the three test packs preprocesses |
|
||||
| Java shader packs: GLSL → WGSL (`horizon_shaderpack::translate`: syntax-tree legaliser, naga) | done: the 464 programs the three test packs enable by default translate (below) |
|
||||
| Java shader packs: Iris pipeline emulation | planned |
|
||||
|
||||
## How the renderer draws a frame today
|
||||
@@ -305,6 +306,12 @@ What is left, by cause:
|
||||
| 6 | `writeonly image2D` without a format (`shadowcomp.csh` in Complementary and BSL) | take the format from the pack's image declaration (`shaders.properties` / `const int` format) |
|
||||
| 5 | naga GLSL front-end bug: a call result inside a constructor (`vec3(TAAJitter(..), z)`) leaves an unvisited expression (BSL) | spill call results to temporaries; report to naga |
|
||||
|
||||
The translator in `crates/horizon-shaderpack` now passes all of them that the packs enable by default (464 of 464,
|
||||
the WGSL read back and validated): matrix varyings are split into columns; the five BSL failures were not a naga bug
|
||||
but dead code after a `discard;` (how BSL turns its clouds and weather off), which the legaliser drops; the six
|
||||
`shadowcomp.csh` are off by default (`program.*/shadowcomp.enabled` in `shaders.properties`) and use images and arrays
|
||||
that only exist with their options on, so they wait for `shaders.properties`.
|
||||
|
||||
So the GLSL side is feasible: naga's front end plus a legaliser reaches 96% on the three packs, and every remaining
|
||||
failure has a mechanical fix. Valid WGSL isn't a working pack yet: the output still has to be bound to Horizon's
|
||||
pipeline (render targets, the uniforms' values, vertex attributes for `gbuffers_*`), which is the emulation work.
|
||||
|
||||
Reference in New Issue
Block a user