commit 2a1c509d9496a979b543f60636d2efe38407f106 Author: Molive Date: Mon Sep 28 00:32:27 2026 +0100 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6b007f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/target +pipeline_cache.bin +log.log +*.out.spv +*.spv-dis +shaders_out diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..257829b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + "configurations": [ + { + "name": "Debug example 'pica_pica'", + "type": "lldb", + "request": "launch", + "cargo": { + "args": [ + "run", + "--example=pica_pica" + ] + }, + "args": [] + } + ] +} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..aa2ea18 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7210 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "ab_glyph" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01c0457472c38ea5bd1c3b5ada5e368271cb550be7a4ca4a0b4634e9913f6cc2" +dependencies = [ + "ab_glyph_rasterizer", + "owned_ttf_parser", +] + +[[package]] +name = "ab_glyph_rasterizer" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "366ffbaa4442f4684d91e2cd7c5ea7c4ed8add41959a31447066e279e432b618" + +[[package]] +name = "accesskit" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad442f58ee04714aaa0ba0a2768c1ea1935b29507bb22ddece8cbbc76db02932" +dependencies = [ + "uuid", +] + +[[package]] +name = "accesskit_consumer" +version = "0.39.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a45e2bb300bea6d5f33a82c3e051c3ddc6f41c209750f68a0acbe991a284344" +dependencies = [ + "accesskit", + "hashbrown 0.17.1", +] + +[[package]] +name = "accesskit_ios" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28e539d64b27fd4c14de8f78ada8f7c944c092f52f7e49fb63316507a57f6937" +dependencies = [ + "accesskit", + "accesskit_consumer", + "hashbrown 0.17.1", + "objc2 0.5.2", + "objc2-foundation 0.2.2", + "objc2-ui-kit", +] + +[[package]] +name = "accesskit_macos" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5701624bf6a11efb6d4c8e922bf44126ed96250e5faa9a7a0468c979635839a4" +dependencies = [ + "accesskit", + "accesskit_consumer", + "hashbrown 0.17.1", + "objc2 0.5.2", + "objc2-app-kit 0.2.2", + "objc2-foundation 0.2.2", +] + +[[package]] +name = "accesskit_windows" +version = "0.35.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce63f35d6bdcf59f26b76b3379063f738e6412cef46999cc772d46aa3de35adb" +dependencies = [ + "accesskit", + "accesskit_consumer", + "hashbrown 0.17.1", + "static_assertions", + "windows", + "windows-core", +] + +[[package]] +name = "accesskit_winit" +version = "0.34.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee96dd150375c05912d8a473f98c2fb155fb3234fac88292d396548a2460fa77" +dependencies = [ + "accesskit", + "accesskit_ios", + "accesskit_macos", + "accesskit_windows", + "raw-window-handle", + "winit", +] + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "ahash" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" +dependencies = [ + "cfg-if", + "getrandom 0.3.4", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba" +dependencies = [ + "memchr", +] + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + +[[package]] +name = "alsa" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812947049edcd670a82cd5c73c3661d2e58468577ba8489de58e1a73c04cbd5d" +dependencies = [ + "alsa-sys", + "bitflags 2.13.2", + "cfg-if", + "libc", +] + +[[package]] +name = "alsa-sys" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad7569085a265dd3f607ebecce7458eaab2132a84393534c95b18dcbc3f31e04" +dependencies = [ + "libc", + "pkg-config", +] + +[[package]] +name = "android-activity" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f2a1bb052857d5dd49572219344a7332b31b76405648eabac5bc68978251bcd" +dependencies = [ + "android-properties", + "bitflags 2.13.2", + "cc", + "jni 0.22.4", + "libc", + "log", + "ndk", + "ndk-context", + "ndk-sys", + "num_enum", + "thiserror 2.0.21", +] + +[[package]] +name = "android-properties" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" + +[[package]] +name = "android_log-sys" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d" + +[[package]] +name = "android_system_properties" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc" +dependencies = [ + "libc", +] + +[[package]] +name = "annotate-snippets" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f211a51805bc641f3ad5b7664c77d2547af685cc33b4cd8d31964027a46f13f1" +dependencies = [ + "anstyle", + "memchr", + "unicode-width", +] + +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.61.2", +] + +[[package]] +name = "approx" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" +dependencies = [ + "num-traits", +] + +[[package]] +name = "arboard" +version = "3.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0348a1c054491f4bfe6ab86a7b6ab1e44e45d899005de92f58b3df180b36ddaf" +dependencies = [ + "clipboard-win", + "log", + "objc2 0.6.4", + "objc2-app-kit 0.3.2", + "objc2-foundation 0.3.2", + "parking_lot", + "percent-encoding", + "windows-sys 0.59.0", + "wl-clipboard-rs", + "x11rb", +] + +[[package]] +name = "argh" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "211818e820cda9ca6f167a64a5c808837366a6dfd807157c64c1304c486cd033" +dependencies = [ + "argh_derive", + "argh_shared", +] + +[[package]] +name = "argh_derive" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c442a9d18cef5dde467405d27d461d080d68972d6d0dfd0408265b6749ec427d" +dependencies = [ + "argh_shared", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "argh_shared" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5ade012bac4db278517a0132c8c10c6427025868dca16c801087c28d5a411f1" +dependencies = [ + "serde", +] + +[[package]] +name = "arrayref" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" + +[[package]] +name = "arrayvec" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56" + +[[package]] +name = "as-raw-xcb-connection" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb44936d800fea8f016d7f2311c6a4f97aebd5dc86f09906139ec848cf3a46f" +dependencies = [ + "libloading", +] + +[[package]] +name = "assert_type_match" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f548ad2c4031f2902e3edc1f29c29e835829437de49562d8eb5dc5584d3a1043" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "async-broadcast" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532" +dependencies = [ + "event-listener", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-channel" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "924ed96dd52d1b75e9c1a3e6275715fd320f5f9439fb5a4a11fa51f4221158d2" +dependencies = [ + "concurrent-queue", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-executor" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c96bf972d85afc50bf5ab8fe2d54d1586b4e0b46c97c50a0c9e71e2f7bcd812a" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "pin-project-lite", + "slab", +] + +[[package]] +name = "async-fs" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8034a681df4aed8b8edbd7fbe472401ecf009251c8b40556b304567052e294c5" +dependencies = [ + "async-lock", + "blocking", + "futures-lite", +] + +[[package]] +name = "async-io" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456b8a8feb6f42d237746d4b3e9a178494627745c3c56c6ea55d92ba50d026fc" +dependencies = [ + "autocfg", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite", + "parking", + "polling", + "rustix 1.1.5", + "slab", + "windows-sys 0.61.2", +] + +[[package]] +name = "async-lock" +version = "3.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f7f2596bd5b78a9fec8088ccd89180d7f9f55b94b0576823bbbdc72ee8311" +dependencies = [ + "event-listener", + "event-listener-strategy", + "pin-project-lite", +] + +[[package]] +name = "async-task" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" +dependencies = [ + "portable-atomic", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" +dependencies = [ + "portable-atomic", +] + +[[package]] +name = "atomicow" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301801c08259e328a1c7da556608c0c22687708831b22024dbd3a57ea741e6de" +dependencies = [ + "portable-atomic", + "portable-atomic-util", +] + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "base64" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" + +[[package]] +name = "bevy" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_internal", +] + +[[package]] +name = "bevy_a11y" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "accesskit", + "bevy_app", + "bevy_derive", + "bevy_ecs", + "bevy_reflect", +] + +[[package]] +name = "bevy_android" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "android-activity", +] + +[[package]] +name = "bevy_animation" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_animation_macros", + "bevy_app", + "bevy_asset", + "bevy_color", + "bevy_curve", + "bevy_derive", + "bevy_ecs", + "bevy_math", + "bevy_mesh", + "bevy_platform", + "bevy_reflect", + "bevy_time", + "bevy_transform", + "bevy_utils", + "bitvec", + "blake3", + "derive_more", + "downcast-rs 2.0.2", + "either", + "petgraph", + "ron", + "serde", + "smallvec", + "thiserror 2.0.21", + "thread_local", + "tracing", + "uuid", +] + +[[package]] +name = "bevy_animation_macros" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_macro_utils", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "bevy_anti_alias" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_camera", + "bevy_core_pipeline", + "bevy_derive", + "bevy_diagnostic", + "bevy_ecs", + "bevy_extract", + "bevy_image", + "bevy_math", + "bevy_reflect", + "bevy_render", + "bevy_shader", + "bevy_utils", + "dlss_wgpu", + "tracing", + "uuid", +] + +[[package]] +name = "bevy_app" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_derive", + "bevy_ecs", + "bevy_platform", + "bevy_reflect", + "bevy_tasks", + "bevy_utils", + "console_error_panic_hook", + "ctrlc", + "downcast-rs 2.0.2", + "log", + "thiserror 2.0.21", + "variadics_please", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "bevy_asset" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "async-broadcast", + "async-channel", + "async-fs", + "async-io", + "async-lock", + "atomicow", + "bevy_android", + "bevy_app", + "bevy_asset_macros", + "bevy_diagnostic", + "bevy_ecs", + "bevy_platform", + "bevy_reflect", + "bevy_tasks", + "bevy_utils", + "bitflags 2.13.2", + "blake3", + "blocking", + "crossbeam-channel", + "derive_more", + "disqualified", + "downcast-rs 2.0.2", + "either", + "futures-io", + "futures-lite", + "futures-util", + "js-sys", + "notify-debouncer-full", + "ron", + "serde", + "stackfuture", + "thiserror 2.0.21", + "tracing", + "ureq", + "uuid", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "bevy_asset_macros" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_macro_utils", + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "bevy_audio" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_ecs", + "bevy_math", + "bevy_reflect", + "bevy_transform", + "rodio", + "tracing", +] + +[[package]] +name = "bevy_camera" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_color", + "bevy_derive", + "bevy_ecs", + "bevy_image", + "bevy_math", + "bevy_mesh", + "bevy_reflect", + "bevy_shape", + "bevy_transform", + "bevy_utils", + "bevy_window", + "derive_more", + "downcast-rs 2.0.2", + "serde", + "smallvec", + "thiserror 2.0.21", + "wgpu-types", +] + +[[package]] +name = "bevy_camera_controller" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_camera", + "bevy_color", + "bevy_curve", + "bevy_derive", + "bevy_ecs", + "bevy_image", + "bevy_input", + "bevy_log", + "bevy_math", + "bevy_picking", + "bevy_platform", + "bevy_render", + "bevy_time", + "bevy_transform", + "bevy_window", +] + +[[package]] +name = "bevy_clipboard" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "arboard", + "bevy_app", + "bevy_ecs", + "bevy_log", + "bevy_platform", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "bevy_color" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_curve", + "bevy_math", + "bevy_reflect", + "bytemuck", + "derive_more", + "encase", + "serde", + "thiserror 2.0.21", + "wgpu-types", +] + +[[package]] +name = "bevy_core_pipeline" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_camera", + "bevy_color", + "bevy_derive", + "bevy_diagnostic", + "bevy_ecs", + "bevy_extract", + "bevy_image", + "bevy_light", + "bevy_log", + "bevy_math", + "bevy_platform", + "bevy_reflect", + "bevy_render", + "bevy_shader", + "bevy_transform", + "bevy_utils", + "bevy_window", + "bitflags 2.13.2", + "indexmap", + "nonmax", +] + +[[package]] +name = "bevy_curve" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "approx", + "bevy_math", + "bevy_reflect", + "itertools 0.14.0", + "serde", + "thiserror 2.0.21", + "variadics_please", +] + +[[package]] +name = "bevy_derive" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_macro_utils", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "bevy_dev_tools" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_animation", + "bevy_app", + "bevy_asset", + "bevy_audio", + "bevy_camera", + "bevy_color", + "bevy_core_pipeline", + "bevy_diagnostic", + "bevy_ecs", + "bevy_extract", + "bevy_image", + "bevy_input", + "bevy_light", + "bevy_log", + "bevy_math", + "bevy_mesh", + "bevy_pbr", + "bevy_picking", + "bevy_platform", + "bevy_reflect", + "bevy_render", + "bevy_shader", + "bevy_sprite", + "bevy_state", + "bevy_text", + "bevy_time", + "bevy_transform", + "bevy_ui", + "bevy_ui_render", + "bevy_ui_widgets", + "bevy_utils", + "bevy_window", + "bevy_world_serialization", + "tracing", +] + +[[package]] +name = "bevy_diagnostic" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "atomic-waker", + "bevy_app", + "bevy_ecs", + "bevy_platform", + "bevy_tasks", + "bevy_time", + "const-fnv1a-hash", + "log", + "serde", + "sysinfo", +] + +[[package]] +name = "bevy_ecs" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "arrayvec", + "bevy_ecs_macros", + "bevy_platform", + "bevy_ptr", + "bevy_reflect", + "bevy_tasks", + "bevy_utils", + "bitflags 2.13.2", + "bumpalo", + "concurrent-queue", + "derive_more", + "fixedbitset", + "indexmap", + "log", + "nonmax", + "rand", + "serde", + "slotmap", + "smallvec", + "thiserror 2.0.21", + "variadics_please", +] + +[[package]] +name = "bevy_ecs_macro_logic" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_macro_utils", + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "bevy_ecs_macros" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_ecs_macro_logic", + "bevy_macro_utils", + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "bevy_encase_derive" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_macro_utils", + "encase_derive_impl", +] + +[[package]] +name = "bevy_extract" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_camera", + "bevy_derive", + "bevy_ecs", + "bevy_extract_macros", + "bevy_log", + "bevy_platform", + "bevy_reflect", + "bevy_time", + "bevy_utils", +] + +[[package]] +name = "bevy_extract_macros" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_macro_utils", + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "bevy_feathers" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "accesskit", + "bevy_a11y", + "bevy_app", + "bevy_asset", + "bevy_camera", + "bevy_color", + "bevy_derive", + "bevy_ecs", + "bevy_input", + "bevy_input_focus", + "bevy_log", + "bevy_math", + "bevy_picking", + "bevy_platform", + "bevy_reflect", + "bevy_render", + "bevy_scene", + "bevy_shader", + "bevy_text", + "bevy_ui", + "bevy_ui_render", + "bevy_ui_widgets", + "bevy_window", + "smol_str", +] + +[[package]] +name = "bevy_gilrs" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_ecs", + "bevy_input", + "bevy_platform", + "bevy_time", + "gilrs", + "thiserror 2.0.21", + "tracing", +] + +[[package]] +name = "bevy_gizmos" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_camera", + "bevy_color", + "bevy_curve", + "bevy_ecs", + "bevy_gizmos_macros", + "bevy_input", + "bevy_log", + "bevy_math", + "bevy_mesh", + "bevy_reflect", + "bevy_shape", + "bevy_time", + "bevy_transform", + "bevy_utils", + "bevy_window", +] + +[[package]] +name = "bevy_gizmos_macros" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_macro_utils", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "bevy_gizmos_render" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_camera", + "bevy_color", + "bevy_core_pipeline", + "bevy_ecs", + "bevy_extract", + "bevy_gizmos", + "bevy_image", + "bevy_log", + "bevy_material", + "bevy_math", + "bevy_mesh", + "bevy_pbr", + "bevy_reflect", + "bevy_render", + "bevy_shader", + "bevy_shape", + "bevy_sprite_render", + "bevy_transform", + "bevy_utils", + "bytemuck", + "tracing", +] + +[[package]] +name = "bevy_gltf" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "async-lock", + "base64", + "bevy_animation", + "bevy_app", + "bevy_asset", + "bevy_camera", + "bevy_color", + "bevy_curve", + "bevy_ecs", + "bevy_image", + "bevy_light", + "bevy_material", + "bevy_math", + "bevy_mesh", + "bevy_platform", + "bevy_reflect", + "bevy_tasks", + "bevy_transform", + "bevy_world_serialization", + "fixedbitset", + "gltf", + "itertools 0.14.0", + "percent-encoding", + "serde", + "serde_json", + "smallvec", + "thiserror 2.0.21", + "tracing", + "wgpu-types", +] + +[[package]] +name = "bevy_image" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_color", + "bevy_ecs", + "bevy_math", + "bevy_platform", + "bevy_reflect", + "bevy_utils", + "bitflags 2.13.2", + "bytemuck", + "futures-lite", + "guillotiere", + "half", + "image", + "ktx2", + "rectangle-pack", + "ruzstd", + "serde", + "thiserror 2.0.21", + "tracing", + "wgpu-types", +] + +[[package]] +name = "bevy_input" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_ecs", + "bevy_math", + "bevy_platform", + "bevy_reflect", + "derive_more", + "log", + "smol_str", + "thiserror 2.0.21", +] + +[[package]] +name = "bevy_input_focus" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_camera", + "bevy_ecs", + "bevy_input", + "bevy_math", + "bevy_picking", + "bevy_reflect", + "bevy_window", + "log", + "thiserror 2.0.21", +] + +[[package]] +name = "bevy_internal" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_a11y", + "bevy_android", + "bevy_animation", + "bevy_anti_alias", + "bevy_app", + "bevy_asset", + "bevy_audio", + "bevy_camera", + "bevy_camera_controller", + "bevy_clipboard", + "bevy_color", + "bevy_core_pipeline", + "bevy_curve", + "bevy_derive", + "bevy_dev_tools", + "bevy_diagnostic", + "bevy_ecs", + "bevy_extract", + "bevy_feathers", + "bevy_gilrs", + "bevy_gizmos", + "bevy_gizmos_render", + "bevy_gltf", + "bevy_image", + "bevy_input", + "bevy_input_focus", + "bevy_light", + "bevy_log", + "bevy_material", + "bevy_math", + "bevy_mesh", + "bevy_pbr", + "bevy_picking", + "bevy_platform", + "bevy_post_process", + "bevy_ptr", + "bevy_reflect", + "bevy_render", + "bevy_scene", + "bevy_shader", + "bevy_shape", + "bevy_sprite", + "bevy_sprite_render", + "bevy_state", + "bevy_tasks", + "bevy_text", + "bevy_time", + "bevy_transform", + "bevy_ui", + "bevy_ui_render", + "bevy_ui_widgets", + "bevy_utils", + "bevy_window", + "bevy_winit", + "bevy_world_serialization", +] + +[[package]] +name = "bevy_light" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_camera", + "bevy_color", + "bevy_curve", + "bevy_ecs", + "bevy_gizmos", + "bevy_image", + "bevy_log", + "bevy_math", + "bevy_mesh", + "bevy_platform", + "bevy_reflect", + "bevy_shape", + "bevy_transform", + "bevy_utils", + "half", + "smallvec", + "tracing", + "wgpu-types", +] + +[[package]] +name = "bevy_log" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "android_log-sys", + "bevy_app", + "bevy_ecs", + "bevy_platform", + "bevy_utils", + "tracing", + "tracing-log", + "tracing-oslog", + "tracing-subscriber", + "tracing-wasm", +] + +[[package]] +name = "bevy_macro_utils" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", + "toml_edit", +] + +[[package]] +name = "bevy_material" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_asset", + "bevy_derive", + "bevy_ecs", + "bevy_material_macros", + "bevy_mesh", + "bevy_platform", + "bevy_reflect", + "bevy_shader", + "bevy_utils", + "encase", + "smallvec", + "thiserror 2.0.21", + "tracing", + "variadics_please", + "wgpu-types", +] + +[[package]] +name = "bevy_material_macros" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_macro_utils", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "bevy_math" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "approx", + "bevy_reflect", + "derive_more", + "glam 0.33.11", + "libm", + "rand", + "serde", + "thiserror 2.0.21", + "variadics_please", +] + +[[package]] +name = "bevy_mesh" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_derive", + "bevy_ecs", + "bevy_math", + "bevy_mikktspace", + "bevy_platform", + "bevy_reflect", + "bevy_shape", + "bevy_transform", + "bitflags 2.13.2", + "bytemuck", + "derive_more", + "encase", + "glam 0.33.11", + "half", + "hexasphere", + "serde", + "thiserror 2.0.21", + "tracing", + "wgpu-types", +] + +[[package]] +name = "bevy_mikktspace" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff34eb29ff4b8a8688bc7299f14fb6b597461ca80fec03ed7d22939ab33e48f" + +[[package]] +name = "bevy_pbr" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "arrayvec", + "bevy_app", + "bevy_asset", + "bevy_camera", + "bevy_color", + "bevy_core_pipeline", + "bevy_derive", + "bevy_diagnostic", + "bevy_ecs", + "bevy_extract", + "bevy_gltf", + "bevy_image", + "bevy_light", + "bevy_log", + "bevy_material", + "bevy_math", + "bevy_mesh", + "bevy_platform", + "bevy_reflect", + "bevy_render", + "bevy_shader", + "bevy_shape", + "bevy_tasks", + "bevy_transform", + "bevy_utils", + "bitflags 2.13.2", + "bytemuck", + "derive_more", + "fixedbitset", + "indexmap", + "nonmax", + "offset-allocator", + "smallvec", + "static_assertions", + "thiserror 2.0.21", + "tracing", + "wgpu-types", +] + +[[package]] +name = "bevy_picking" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_camera", + "bevy_derive", + "bevy_ecs", + "bevy_input", + "bevy_math", + "bevy_mesh", + "bevy_platform", + "bevy_reflect", + "bevy_shape", + "bevy_time", + "bevy_transform", + "bevy_window", + "crossbeam-channel", + "tracing", + "uuid", +] + +[[package]] +name = "bevy_platform" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bytemuck", + "critical-section", + "foldhash 0.2.0", + "futures-channel", + "futures-lite", + "hashbrown 0.17.1", + "js-sys", + "portable-atomic", + "portable-atomic-util", + "serde", + "spin", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-time", + "windows-sys 0.61.2", +] + +[[package]] +name = "bevy_post_process" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_camera", + "bevy_color", + "bevy_core_pipeline", + "bevy_curve", + "bevy_derive", + "bevy_ecs", + "bevy_extract", + "bevy_image", + "bevy_math", + "bevy_platform", + "bevy_reflect", + "bevy_render", + "bevy_shader", + "bevy_utils", + "smallvec", + "thiserror 2.0.21", + "tracing", +] + +[[package]] +name = "bevy_ptr" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" + +[[package]] +name = "bevy_reflect" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "assert_type_match", + "bevy_platform", + "bevy_ptr", + "bevy_reflect_derive", + "bevy_utils", + "derive_more", + "disqualified", + "downcast-rs 2.0.2", + "erased-serde", + "foldhash 0.2.0", + "glam 0.33.11", + "indexmap", + "inventory", + "petgraph", + "serde", + "smallvec", + "smol_str", + "thiserror 2.0.21", + "uuid", + "variadics_please", + "wgpu-types", +] + +[[package]] +name = "bevy_reflect_derive" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_macro_utils", + "indexmap", + "proc-macro2", + "quote", + "syn 3.0.6", + "uuid", +] + +[[package]] +name = "bevy_render" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "async-channel", + "bevy_app", + "bevy_asset", + "bevy_camera", + "bevy_color", + "bevy_derive", + "bevy_diagnostic", + "bevy_ecs", + "bevy_encase_derive", + "bevy_extract", + "bevy_extract_macros", + "bevy_image", + "bevy_log", + "bevy_material", + "bevy_material_macros", + "bevy_math", + "bevy_mesh", + "bevy_platform", + "bevy_reflect", + "bevy_render_macros", + "bevy_shader", + "bevy_shape", + "bevy_tasks", + "bevy_time", + "bevy_transform", + "bevy_utils", + "bevy_window", + "bitflags 2.13.2", + "bytemuck", + "derive_more", + "downcast-rs 2.0.2", + "encase", + "glam 0.33.11", + "image", + "indexmap", + "itertools 0.14.0", + "js-sys", + "nonmax", + "offset-allocator", + "send_wrapper", + "smallvec", + "static_assertions", + "thiserror 2.0.21", + "tracing", + "variadics_please", + "wasm-bindgen", + "weak-table", + "web-sys", + "wgpu", + "wgpu-types", +] + +[[package]] +name = "bevy_render_macros" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_extract_macros", + "bevy_macro_utils", + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "bevy_scene" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_derive", + "bevy_ecs", + "bevy_platform", + "bevy_reflect", + "bevy_scene_macros", + "bevy_utils", + "smallvec", + "thiserror 2.0.21", + "tracing", + "variadics_please", +] + +[[package]] +name = "bevy_scene_macros" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_ecs_macro_logic", + "bevy_macro_utils", + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "bevy_shader" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_asset", + "bevy_platform", + "bevy_reflect", + "bevy_utils", + "serde", + "thiserror 2.0.21", + "tracing", + "wesl", + "wgpu-types", +] + +[[package]] +name = "bevy_shape" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "arrayvec", + "bevy_math", + "bevy_reflect", + "derive_more", + "rand", + "rand_distr", + "serde", + "thiserror 2.0.21", +] + +[[package]] +name = "bevy_sprite" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_camera", + "bevy_color", + "bevy_derive", + "bevy_ecs", + "bevy_image", + "bevy_log", + "bevy_math", + "bevy_mesh", + "bevy_picking", + "bevy_reflect", + "bevy_text", + "bevy_transform", + "bevy_window", + "radsort", + "tracing", + "wgpu-types", +] + +[[package]] +name = "bevy_sprite_render" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_camera", + "bevy_color", + "bevy_core_pipeline", + "bevy_derive", + "bevy_ecs", + "bevy_extract", + "bevy_image", + "bevy_material", + "bevy_math", + "bevy_mesh", + "bevy_platform", + "bevy_reflect", + "bevy_render", + "bevy_shader", + "bevy_shape", + "bevy_sprite", + "bevy_text", + "bevy_transform", + "bevy_utils", + "bitflags 2.13.2", + "bytemuck", + "derive_more", + "fixedbitset", + "nonmax", + "smallvec", + "static_assertions", + "tracing", +] + +[[package]] +name = "bevy_state" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_ecs", + "bevy_platform", + "bevy_reflect", + "bevy_state_macros", + "bevy_utils", + "log", + "variadics_please", +] + +[[package]] +name = "bevy_state_macros" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_macro_utils", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "bevy_tape_drive" +version = "0.20.0-dev" +dependencies = [ + "argh", + "bevy", + "bevy_anti_alias", + "bevy_app", + "bevy_asset", + "bevy_camera", + "bevy_color", + "bevy_core_pipeline", + "bevy_derive", + "bevy_diagnostic", + "bevy_ecs", + "bevy_image", + "bevy_light", + "bevy_log", + "bevy_math", + "bevy_mesh", + "bevy_pbr", + "bevy_platform", + "bevy_reflect", + "bevy_render", + "bevy_shader", + "bevy_shape", + "bevy_transform", + "bevy_utils", + "bytemuck", + "chacha20", + "derive_more", + "rand", + "tape-load", + "tracing", + "wgpu", +] + +[[package]] +name = "bevy_tasks" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "async-channel", + "async-executor", + "async-task", + "atomic-waker", + "bevy_platform", + "concurrent-queue", + "crossbeam-queue", + "derive_more", + "futures-lite", + "heapless", + "web-task", +] + +[[package]] +name = "bevy_text" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_clipboard", + "bevy_color", + "bevy_derive", + "bevy_ecs", + "bevy_image", + "bevy_log", + "bevy_math", + "bevy_platform", + "bevy_reflect", + "bevy_utils", + "parley", + "serde", + "smallvec", + "smol_str", + "swash", + "thiserror 2.0.21", + "tracing", + "wgpu-types", +] + +[[package]] +name = "bevy_time" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_ecs", + "bevy_platform", + "bevy_reflect", + "crossbeam-channel", + "log", + "serde", +] + +[[package]] +name = "bevy_transform" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_ecs", + "bevy_math", + "bevy_reflect", + "bevy_tasks", + "bevy_utils", + "derive_more", + "serde", + "thiserror 2.0.21", +] + +[[package]] +name = "bevy_ui" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "accesskit", + "bevy_a11y", + "bevy_app", + "bevy_asset", + "bevy_camera", + "bevy_color", + "bevy_derive", + "bevy_ecs", + "bevy_image", + "bevy_input", + "bevy_input_focus", + "bevy_log", + "bevy_math", + "bevy_picking", + "bevy_platform", + "bevy_reflect", + "bevy_sprite", + "bevy_text", + "bevy_time", + "bevy_transform", + "bevy_utils", + "bevy_window", + "derive_more", + "parley", + "smallvec", + "swash", + "taffy", + "thiserror 2.0.21", + "tracing", + "uuid", +] + +[[package]] +name = "bevy_ui_render" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_a11y", + "bevy_app", + "bevy_asset", + "bevy_camera", + "bevy_color", + "bevy_core_pipeline", + "bevy_derive", + "bevy_ecs", + "bevy_extract", + "bevy_image", + "bevy_input_focus", + "bevy_math", + "bevy_mesh", + "bevy_platform", + "bevy_reflect", + "bevy_render", + "bevy_shader", + "bevy_sprite", + "bevy_sprite_render", + "bevy_text", + "bevy_transform", + "bevy_ui", + "bevy_utils", + "bytemuck", + "derive_more", + "indexmap", + "smallvec", + "tracing", +] + +[[package]] +name = "bevy_ui_widgets" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "accesskit", + "bevy_a11y", + "bevy_app", + "bevy_camera", + "bevy_ecs", + "bevy_input", + "bevy_input_focus", + "bevy_log", + "bevy_math", + "bevy_picking", + "bevy_platform", + "bevy_reflect", + "bevy_text", + "bevy_time", + "bevy_ui", + "bevy_window", + "parley", + "smol_str", + "web-sys", +] + +[[package]] +name = "bevy_utils" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "async-channel", + "bevy_platform", + "disqualified", + "indexmap", + "thread_local", +] + +[[package]] +name = "bevy_window" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_ecs", + "bevy_image", + "bevy_input", + "bevy_math", + "bevy_platform", + "bevy_reflect", + "log", + "raw-window-handle", + "serde", +] + +[[package]] +name = "bevy_winit" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "accesskit", + "accesskit_winit", + "approx", + "bevy_a11y", + "bevy_android", + "bevy_app", + "bevy_asset", + "bevy_derive", + "bevy_ecs", + "bevy_image", + "bevy_input", + "bevy_input_focus", + "bevy_log", + "bevy_math", + "bevy_platform", + "bevy_reflect", + "bevy_tasks", + "bevy_window", + "bytemuck", + "js-sys", + "tracing", + "wasm-bindgen", + "web-sys", + "wgpu-types", + "winit", +] + +[[package]] +name = "bevy_world_serialization" +version = "0.20.0-dev" +source = "git+https://github.com/bevyengine/bevy.git?rev=0f38358f573a7dc6ea961076f6151be662142010#0f38358f573a7dc6ea961076f6151be662142010" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_camera", + "bevy_derive", + "bevy_ecs", + "bevy_platform", + "bevy_reflect", + "bevy_transform", + "bevy_utils", + "derive_more", + "ron", + "serde", + "thiserror 2.0.21", + "uuid", +] + +[[package]] +name = "bindgen" +version = "0.73.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "787ef8ef523575546b106a58213d6e6b06198a05c2f757258c68a74273670cfa" +dependencies = [ + "bitflags 2.13.2", + "cexpr", + "clang-sys", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash 2.1.3", + "shlex", + "syn 3.0.6", +] + +[[package]] +name = "bit-set" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34ddef2995421ab6a5c779542c81ee77c115206f4ad9d5a8e05f4ff49716a3dd" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-set" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2f926cc3060f09db9ebc5b52823d85268d24bb917e472c0c4bea35780a7d" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b71798fca2c1fe1086445a7258a4bc81e6e49dcd24c8d0dd9a1e57395b603f51" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" +dependencies = [ + "bytemuck", + "serde_core", +] + +[[package]] +name = "bitvec" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddcec3d12c579d40898fe0a9a358a803c23e9c52ca3c425707f81c9436211837" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "blake3" +version = "1.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d9e454fc11f76977dc803893aff6304ed33d6a26efae8696573bea74baa27ae" +dependencies = [ + "arrayvec", + "cc", + "cfg-if", + "constant_time_eq", + "cpufeatures 0.3.1", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block2" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c132eebf10f5cad5289222520a4a058514204aed6d791f1cf4fe8088b82d15f" +dependencies = [ + "objc2 0.5.2", +] + +[[package]] +name = "block2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5" +dependencies = [ + "objc2 0.6.4", +] + +[[package]] +name = "blocking" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a70e4329df6cb94385eed412ec92375c3cdd8a6e502493d1229b6414e4036dfa" +dependencies = [ + "async-channel", + "async-task", + "futures-io", + "futures-lite", + "piper", +] + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "bytemuck" +version = "1.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95832e849adfb21180ccb6826a99da14e5d266ae5c2e668e1602cf234f153797" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a1f896587b6f2c069c73d2f0913e2d590c3990285cd2f0b6aa02b786b4c679c" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "byteorder-lite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + +[[package]] +name = "calloop" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b99da2f8558ca23c71f4fd15dc57c906239752dd27ff3c00a1d56b685b7cbfec" +dependencies = [ + "bitflags 2.13.2", + "log", + "polling", + "rustix 0.38.44", + "slab", + "thiserror 1.0.69", +] + +[[package]] +name = "calloop-wayland-source" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95a66a987056935f7efce4ab5668920b5d0dac4a7c99991a67395f13702ddd20" +dependencies = [ + "calloop", + "rustix 0.38.44", + "wayland-backend", + "wayland-client", +] + +[[package]] +name = "cc" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f360145194ee8e21db5ee7f3fcd4fe52210864c75c985dae33218202c8bbe040" +dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom 7.1.3", +] + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + +[[package]] +name = "chacha20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.1", + "rand_core", +] + +[[package]] +name = "clang-sys" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "157a8ba7b480713b56f4c09fd13fc3e0a22a5dfab8097ba61cbc5feef950788a" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "clipboard-win" +version = "5.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bde03770d3df201d4fb868f2c9c59e66a3e4e2bd06692a0fe701e7103c7e84d4" +dependencies = [ + "error-code", +] + +[[package]] +name = "codespan-reporting" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af491d569909a7e4dee0ad7db7f5341fef5c614d5b8ec8cf765732aba3cff681" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + +[[package]] +name = "combine" +version = "4.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfc320937d09e6de266b31b9afb480f197d7a861be86be7cb2ea7e5d1bfffc5e" +dependencies = [ + "bytes", + "memchr", +] + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", + "portable-atomic", +] + +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + +[[package]] +name = "const-fnv1a-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b13ea120a812beba79e34316b3942a857c86ec1593cb34f27bb28272ce2cca" + +[[package]] +name = "const_panic" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9603f79528ece8163c496f8932121cb36cfe46259e9c907bb3d8205139d7caa3" +dependencies = [ + "typewit", +] + +[[package]] +name = "const_soft_float" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ca1caa64ef4ed453e68bb3db612e51cf1b2f5b871337f0fcab1c8f87cc3dff" + +[[package]] +name = "constant_time_eq" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b" + +[[package]] +name = "constgebra" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1aaf9b65849a68662ac6c0810c8893a765c960b907dd7cfab9c4a50bf764fbc" +dependencies = [ + "const_soft_float", +] + +[[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 = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "core-graphics" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" +dependencies = [ + "bitflags 1.3.2", + "core-foundation 0.9.4", + "core-graphics-types", + "foreign-types", + "libc", +] + +[[package]] +name = "core-graphics-types" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" +dependencies = [ + "bitflags 1.3.2", + "core-foundation 0.9.4", + "libc", +] + +[[package]] +name = "coreaudio-rs" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5d7dca3ebcf65a035582c9ad4385371a9d9ee6537474d2a278f4e1e475bb58" +dependencies = [ + "bitflags 2.13.2", + "libc", + "objc2-audio-toolbox", + "objc2-core-audio", + "objc2-core-audio-types", + "objc2-core-foundation", +] + +[[package]] +name = "cpal" +version = "0.17.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8942da362c0f0d895d7cac616263f2f9424edc5687364dfd1d25ef7eba506d7" +dependencies = [ + "alsa", + "coreaudio-rs", + "dasp_sample", + "jni 0.21.1", + "js-sys", + "libc", + "mach2", + "ndk", + "ndk-context", + "num-derive", + "num-traits", + "objc2 0.6.4", + "objc2-audio-toolbox", + "objc2-avf-audio", + "objc2-core-audio", + "objc2-core-audio-types", + "objc2-core-foundation", + "objc2-foundation 0.3.2", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows", +] + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "cpufeatures" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01a7799fd6b852db0e61728dde9a204c423b44d689dbd432522543614b490e78" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "critical-section" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" + +[[package]] +name = "crossbeam-channel" +version = "0.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98b0cc327b5bc766e7fda9c9260cc0fa81b43a8e240440422dff70788e3f9ef1" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-queue" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03e8bd762f7479489c70ed6c768ddca99d7296857de437a68dcb2a94365b3fae" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6" + +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "ctrlc" +version = "3.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0b1fab2ae45819af2d0731d60f2afe17227ebb1a1538a236da84c93e9a60162" +dependencies = [ + "dispatch2", + "nix", + "windows-sys 0.61.2", +] + +[[package]] +name = "cursor-icon" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f27ae1dd37df86211c42e150270f82743308803d90a6f6e6651cd730d5e1732f" + +[[package]] +name = "dasp_sample" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c87e182de0887fd5361989c677c4e8f5000cd9491d6d563161a8f3a5519fc7f" + +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "dispatch" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" + +[[package]] +name = "dispatch2" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0e367e4e7da84520dedcac1901e4da967309406d1e51017ae1abfb97adbd38" +dependencies = [ + "bitflags 2.13.2", + "block2 0.6.2", + "libc", + "objc2 0.6.4", +] + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "disqualified" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e90a5dd66beeca277ae954f8055b02a712792b6b6b43f2bc2f92b0b7d8291614" + +[[package]] +name = "dlib" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab8ecd87370524b461f8557c119c405552c396ed91fc0a8eec68679eab26f94a" +dependencies = [ + "libloading", +] + +[[package]] +name = "dlss_wgpu" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6d49749f048ae6512153417e1ca603417620f6024132a4bb6d7a52f138a8bea" +dependencies = [ + "ash", + "bindgen", + "bitflags 2.13.2", + "cc", + "thiserror 2.0.21", + "uuid", + "wgpu", +] + +[[package]] +name = "document-features" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4b8a88685455ed29a21542a33abd9cb6510b6b129abadabdcef0f4c55bc8f61" +dependencies = [ + "litrs", +] + +[[package]] +name = "downcast-rs" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" + +[[package]] +name = "downcast-rs" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "117240f60069e65410b3ae1bb213295bd828f707b5bec6596a1afc8793ce0cbc" + +[[package]] +name = "dpi" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76" + +[[package]] +name = "either" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "252afb9ae5eaa683babdc6a068b3f5726eb19e05070c731f9b2a23a7c3e8ed34" + +[[package]] +name = "ena" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabffdaee24bd1bf95c5ef7cec31260444317e72ea56c4c91750e8b7ee58d5f1" +dependencies = [ + "log", +] + +[[package]] +name = "encase" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdf6312703f02e0625e1750eadf556054b6da5e44960a3a771e9127cb357dbd8" +dependencies = [ + "const_panic", + "encase_derive", + "thiserror 2.0.21", +] + +[[package]] +name = "encase_derive" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8429e24f02acf09b0fb3c4560c329a1a79fab14bbb9c2d632c073d0a61b0816a" +dependencies = [ + "encase_derive_impl", +] + +[[package]] +name = "encase_derive_impl" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ac3bf06563c72a9b64bc4d8da00ebcabd1d776ea4526c3b1461697142fe340f" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "erased-serde" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2add8a07dd6a8d93ff627029c51de145e12686fbc36ecb298ac22e74cf02dec" +dependencies = [ + "serde", + "serde_core", + "typeid", +] + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "error-code" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5343afd4a8365a643ac588dab4cf234a190c7f6c88c9f6dd6ffe00837661b7" + +[[package]] +name = "euclid" +version = "0.22.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1a05365e3b1c6d1650318537c7460c6923f1abdd272ad6842baa2b509957a06" +dependencies = [ + "num-traits", +] + +[[package]] +name = "event-listener" +version = "5.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a23add41df1562121a9393cb065eab5146a1242410f23a644851e90cfd669d2" +dependencies = [ + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" +dependencies = [ + "event-listener", + "pin-project-lite", +] + +[[package]] +name = "fastrand" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" + +[[package]] +name = "fdeflate" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c" +dependencies = [ + "simd-adler32", +] + +[[package]] +name = "file-id" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1fc6a637b6dc58414714eddd9170ff187ecb0933d4c7024d1abbd23a3cc26e9" +dependencies = [ + "windows-sys 0.60.2", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedcfb3409746eddb02b9e19ebda1c3394f759a152e48ee875a0844d1b955484" + +[[package]] +name = "fixedbitset" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" + +[[package]] +name = "flate2" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e634e2e0ebac1ee034020da1ca582e17ffe4e0f5e985823721e168928136dcb" +dependencies = [ + "crc32fast", + "miniz_oxide 0.9.1", + "zlib-rs", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + +[[package]] +name = "font-types" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8eb065f3251655b3c90e22e5e363f310fc5332fb3402e37bbc94752283248f6" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "fontique" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6688bc1294fe7117d788937b6c53480169b29c566954af490830d4c09da9516a" +dependencies = [ + "hashbrown 0.17.1", + "linebender_resource_handle", + "memmap2", + "parlance", + "read-fonts", + "smallvec", +] + +[[package]] +name = "foreign-types" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" +dependencies = [ + "foreign-types-macros", + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-macros" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea5190182e6915eb873ddbc16e23b711b6eb1f9c00a0d0a3a91b5f6228475225" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "foreign-types-shared" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" + +[[package]] +name = "fsevent-sys" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" +dependencies = [ + "libc", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + +[[package]] +name = "futures-lite" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", +] + +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-macro", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "gethostname" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8" +dependencies = [ + "rustix 1.1.5", + "windows-link", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "libc", + "r-efi 5.3.0", + "wasip2", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi 6.0.0", + "rand_core", +] + +[[package]] +name = "gilrs" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "902fb00d3f6398e635be22e5c837b303c501835cca7ac11a47bba138f7aafdd8" +dependencies = [ + "fnv", + "gilrs-core", + "log", + "uuid", + "vec_map", +] + +[[package]] +name = "gilrs-core" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc7f0ce6237abcc0523f2a5502b1e3fe5802daaae47ac14e166fe49551301ea9" +dependencies = [ + "inotify", + "js-sys", + "libc", + "libudev-sys", + "log", + "nix", + "objc2-core-foundation", + "objc2-io-kit", + "uuid", + "vec_map", + "wasm-bindgen", + "web-sys", + "windows", +] + +[[package]] +name = "gl_generator" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" +dependencies = [ + "khronos_api", + "log", + "xml-rs", +] + +[[package]] +name = "glam" +version = "0.30.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19fc433e8437a212d1b6f1e68c7824af3aed907da60afa994e7f542d18d12aa9" + +[[package]] +name = "glam" +version = "0.33.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35b4e837a1d133645d1dcf283e146a4b9901e390a1c13545f959cfed3a72f24f" +dependencies = [ + "approx", + "bytemuck", + "encase", + "libm", + "rand", + "serde_core", +] + +[[package]] +name = "glob" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b" + +[[package]] +name = "glow" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29038e1c483364cc6bb3cf78feee1816002e127c331a1eec55a4d202b9e1adb5" +dependencies = [ + "js-sys", + "slotmap", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "gltf" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ce1918195723ce6ac74e80542c5a96a40c2b26162c1957a5cd70799b8cacf7" +dependencies = [ + "byteorder", + "gltf-json", + "lazy_static", + "serde_json", +] + +[[package]] +name = "gltf-derive" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14070e711538afba5d6c807edb74bcb84e5dbb9211a3bf5dea0dfab5b24f4c51" +dependencies = [ + "inflections", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "gltf-json" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6176f9d60a7eab0a877e8e96548605dedbde9190a7ae1e80bbcc1c9af03ab14" +dependencies = [ + "gltf-derive", + "serde", + "serde_derive", + "serde_json", +] + +[[package]] +name = "glutin_wgl_sys" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c4ee00b289aba7a9e5306d57c2d05499b2e5dc427f84ac708bd2c090212cf3e" +dependencies = [ + "gl_generator", +] + +[[package]] +name = "gpu-allocator" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51255ea7cfaadb6c5f1528d43e92a82acb2b96c43365989a28b2d44ee38f8795" +dependencies = [ + "ash", + "hashbrown 0.16.1", + "log", + "presser", + "thiserror 2.0.21", + "windows", +] + +[[package]] +name = "guillotiere" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b17e70c989c36bad147b27a58d148c0741c51448aa5653436547323e524d0ab" +dependencies = [ + "euclid", +] + +[[package]] +name = "half" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b" +dependencies = [ + "bytemuck", + "cfg-if", + "crunchy", + "num-traits", + "serde", + "zerocopy", +] + +[[package]] +name = "harfrust" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c03d949a14aa089bbb282f7dd76a498a7f684428e4257202efc119ec010376f9" +dependencies = [ + "bitflags 2.13.2", + "bytemuck", + "read-fonts", + "smallvec", +] + +[[package]] +name = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +dependencies = [ + "byteorder", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash 0.1.5", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash 0.2.0", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" +dependencies = [ + "equivalent", + "foldhash 0.2.0", + "serde", + "serde_core", +] + +[[package]] +name = "heapless" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25ba4bd83f9415b58b4ed8dc5714c76e626a105be4646c02630ad730ad3b5aa4" +dependencies = [ + "hash32", + "portable-atomic", + "stable_deref_trait", +] + +[[package]] +name = "hermit-abi" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e17592d60ebacc7d5e169f4663c5f84f9161cc90328abcfe8456f41e4dfcb284" + +[[package]] +name = "hexasphere" +version = "19.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "163385eff5a0cf606ebe2c10b3a44ab02f4306e83fbd068a64f5e1d72a3049ac" +dependencies = [ + "constgebra", + "glam 0.33.11", + "tinyvec", +] + +[[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "humantime" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15cdd26707701c53297e2fa6afb323d55fbc1d0810c3aec078ae3ef0424c3c15" + +[[package]] +name = "icu_collections" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb" +dependencies = [ + "displaydoc", + "litemap", + "serde", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locale_fallback" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "251af8e57c9400e3eb58242fe5b8b1152b2a64fdf4cf632f923c38ccee6f2fa9" +dependencies = [ + "icu_locale_core", + "icu_locale_fallback_data", + "icu_provider", + "potential_utf", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locale_fallback_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "decf2a22ec8fa68f1a0c1129a3f8583f8f8bc24e8b9ccbe98ead99f62a4dc3a8" + +[[package]] +name = "icu_normalizer" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0" + +[[package]] +name = "icu_properties" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa" + +[[package]] +name = "icu_provider" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d27bbb9d3abbefac45d55f647c9de1d44aafcd1186eb91879afef17c396c3e73" +dependencies = [ + "displaydoc", + "icu_locale_core", + "serde", + "stable_deref_trait", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_segmenter" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82d07aafccd67af15d02512a6adf5896fbc5ed00f2e99b471d2efa14016db3db" +dependencies = [ + "icu_collections", + "icu_locale_fallback", + "icu_provider", + "icu_segmenter_data", + "potential_utf", + "smallvec", + "utf8_iter", + "zerovec", +] + +[[package]] +name = "icu_segmenter_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae293c039020f9ec10710af98d29ce6aa2051486638b49c9a6409f3b4a9e98ad" + +[[package]] +name = "image" +version = "0.25.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85ab80394333c02fe689eaf900ab500fbd0c2213da414687ebf995a65d5a6104" +dependencies = [ + "bytemuck", + "byteorder-lite", + "moxcms", + "num-traits", + "png", +] + +[[package]] +name = "indexmap" +version = "2.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" +dependencies = [ + "equivalent", + "hashbrown 0.17.1", + "serde", + "serde_core", +] + +[[package]] +name = "inflections" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a257582fdcde896fd96463bf2d40eefea0580021c0712a0e2b028b60b47a837a" + +[[package]] +name = "inotify" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cc00ea907cab49550b7da656f80ebb97be1b997d931fbcd28d39734e17ce592" +dependencies = [ + "bitflags 2.13.2", + "inotify-sys", + "libc", +] + +[[package]] +name = "inotify-sys" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c033f80b2c113cdf91ab7a33faa9cbc014726dcad99880c8609af2a370edf37d" +dependencies = [ + "libc", +] + +[[package]] +name = "inventory" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4f0c30c76f2f4ccee3fe55a2435f691ca00c0e4bd87abe4f4a851b1d4dac39b" +dependencies = [ + "rustversion", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + +[[package]] +name = "itertools" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b4baf93f58d4425749ca49a51c50ebab072c5df6994d08fed93541c331481dc" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys 0.3.1", + "log", + "thiserror 1.0.69", + "walkdir", + "windows-sys 0.45.0", +] + +[[package]] +name = "jni" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5efd9a482cf3a427f00d6b35f14332adc7902ce91efb778580e180ff90fa3498" +dependencies = [ + "cfg-if", + "combine", + "jni-macros", + "jni-sys 0.4.1", + "log", + "simd_cesu8", + "thiserror 2.0.21", + "walkdir", + "windows-link", +] + +[[package]] +name = "jni-macros" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00109accc170f0bdb141fed3e393c565b6f5e072365c3bd58f5b062591560a3" +dependencies = [ + "proc-macro2", + "quote", + "rustc_version", + "simd_cesu8", + "syn 2.0.119", +] + +[[package]] +name = "jni-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41a652e1f9b6e0275df1f15b32661cf0d4b78d4d87ddec5e0c3c20f097433258" +dependencies = [ + "jni-sys 0.4.1", +] + +[[package]] +name = "jni-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6377a88cb3910bee9b0fa88d4f42e1d2da8e79915598f65fb0c7ee14c878af2" +dependencies = [ + "jni-sys-macros", +] + +[[package]] +name = "jni-sys-macros" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264" +dependencies = [ + "quote", + "syn 2.0.119", +] + +[[package]] +name = "jobserver" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" +dependencies = [ + "getrandom 0.4.3", + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7883d941dae510fb2d978fc3fe018c71c9e2892fd38854de3e8b92c2e5ad9cc5" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "keccak" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb26cec98cce3a3d96cbb7bced3c4b16e3d13f27ec56dbd62cbc8f39cfb9d653" +dependencies = [ + "cpufeatures 0.2.17", +] + +[[package]] +name = "khronos-egl" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aae1df220ece3c0ada96b8153459b67eebe9ae9212258bb0134ae60416fdf76" +dependencies = [ + "libc", + "libloading", + "pkg-config", +] + +[[package]] +name = "khronos_api" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" + +[[package]] +name = "kqueue" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d763e5b24120b4ddf50de6c92308156765aabfbbccebf401da7cff2d70a41ea" +dependencies = [ + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07293a4e297ac234359b510362495713f75ea345d5307140414f20c69ffeb087" +dependencies = [ + "bitflags 2.13.2", + "libc", +] + +[[package]] +name = "ktx2" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d50be8a24c37debdf3170be6ca396d5b5b165f37f94837891adac735ca416b8" +dependencies = [ + "bitflags 2.13.2", +] + +[[package]] +name = "lalrpop" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98a80a963123205c7157323c99611bc4abb65dcbd62ef46dc4bac74a3941bc75" +dependencies = [ + "ascii-canvas", + "bit-set 0.9.1", + "ena", + "itertools 0.14.0", + "lalrpop-util", + "petgraph", + "regex", + "regex-syntax", + "sha3", + "string_cache", + "term", + "unicode-xid", + "walkdir", +] + +[[package]] +name = "lalrpop-util" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884f3e747ed2dcee867cda1b0c31a048f9e20de2d916a248949319921a2e666e" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "lewton" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "777b48df9aaab155475a83a7df3070395ea1ac6902f5cd062b8f2b028075c030" +dependencies = [ + "byteorder", + "ogg", + "tinyvec", +] + +[[package]] +name = "lexical" +version = "7.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc8a009b2ff1f419ccc62706f04fe0ca6e67b37460513964a3dfdb919bb37d6" +dependencies = [ + "lexical-core", +] + +[[package]] +name = "lexical-core" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d8d125a277f807e55a77304455eb7b1cb52f2b18c143b60e766c120bd64a594" +dependencies = [ + "lexical-parse-float", + "lexical-parse-integer", + "lexical-util", + "lexical-write-float", + "lexical-write-integer", +] + +[[package]] +name = "lexical-parse-float" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52a9f232fbd6f550bc0137dcb5f99ab674071ac2d690ac69704593cb4abbea56" +dependencies = [ + "lexical-parse-integer", + "lexical-util", +] + +[[package]] +name = "lexical-parse-integer" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a7a039f8fb9c19c996cd7b2fcce303c1b2874fe1aca544edc85c4a5f8489b34" +dependencies = [ + "lexical-util", +] + +[[package]] +name = "lexical-util" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2604dd126bb14f13fb5d1bd6a66155079cb9fa655b37f875b3a742c705dbed17" + +[[package]] +name = "lexical-write-float" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50c438c87c013188d415fbabbb1dceb44249ab81664efbd31b14ae55dabb6361" +dependencies = [ + "lexical-util", + "lexical-write-integer", +] + +[[package]] +name = "lexical-write-integer" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "409851a618475d2d5796377cad353802345cba92c867d9fbcde9cf4eac4e14df" +dependencies = [ + "lexical-util", +] + +[[package]] +name = "libc" +version = "0.2.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" + +[[package]] +name = "libloading" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" +dependencies = [ + "cfg-if", + "windows-link", +] + +[[package]] +name = "libm" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" + +[[package]] +name = "libredox" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61ff90caf6077a803a240f62fdbe88645a890bbca49ef8174c3cb0404362171d" +dependencies = [ + "bitflags 2.13.2", + "libc", + "plain", + "redox_syscall 0.9.4", +] + +[[package]] +name = "libudev-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c8469b4a23b962c1396b9b451dda50ef5b283e8dd309d69033475fa9b334324" +dependencies = [ + "libc", + "pkg-config", +] + +[[package]] +name = "linebender_resource_handle" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4a5ff6bcca6c4867b1c4fd4ef63e4db7436ef363e0ad7531d1558856bae64f4" + +[[package]] +name = "linux-raw-sys" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + +[[package]] +name = "litrs" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" + +[[package]] +name = "logos" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb2c55a318a87600ea870ff8c2012148b44bf18b74fad48d0f835c38c7d07c5f" +dependencies = [ + "logos-derive", +] + +[[package]] +name = "logos-codegen" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58b3ffaa284e1350d017a57d04ada118c4583cf260c8fb01e0fe28a2e9cf8970" +dependencies = [ + "fnv", + "proc-macro2", + "quote", + "regex-automata", + "regex-syntax", + "syn 2.0.119", +] + +[[package]] +name = "logos-derive" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52d3a9855747c17eaf4383823f135220716ab49bea5fbea7dd42cc9a92f8aa31" +dependencies = [ + "logos-codegen", +] + +[[package]] +name = "mach2" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a1b95cd5421ec55b445b5ae102f5ea0e768de1f82bd3001e11f426c269c3aea" +dependencies = [ + "libc", +] + +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "memmap2" +version = "0.9.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1219ed1b7f229ee7104d281dd01d6802fe28bb6e95d292942c4daacdeb798c0" +dependencies = [ + "libc", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "miniz_oxide" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "mio" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18443e9c262bfe8fa82f51666e2642c53393f7e5c27b3e1aeab922cff5b9d8" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "moxcms" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb85c154ba489f01b25c0d36ae69a87e4a1c73a72631fc6c0eb6dde34a73e44b" +dependencies = [ + "num-traits", + "pxfm", +] + +[[package]] +name = "mutants" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc0287524726960e07b119cebd01678f852f147742ae0d925e6a520dca956126" + +[[package]] +name = "naga" +version = "30.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a616d2fb8c89516ac2723a581f69d6c18576046bed761bd6b305e5618e6ae130" +dependencies = [ + "arrayvec", + "bit-set 0.10.0", + "bitflags 2.13.2", + "cfg-if", + "cfg_aliases", + "codespan-reporting", + "half", + "hashbrown 0.17.1", + "indexmap", + "libm", + "log", + "naga-types", + "num-traits", + "once_cell", + "rustc-hash 1.1.0", + "spirv 0.4.0+sdk-1.4.341.0", + "thiserror 2.0.21", + "unicode-ident", +] + +[[package]] +name = "naga-types" +version = "30.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "590afbf58a6f4f62873cd5cff4468061844bafa1cdf399cc954537c22d768d49" +dependencies = [ + "hashbrown 0.17.1", + "indexmap", + "rustc-hash 1.1.0", + "serde", + "thiserror 2.0.21", +] + +[[package]] +name = "ndk" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3f42e7bbe13d351b6bead8286a43aac9534b82bd3cc43e47037f012ebfd62d4" +dependencies = [ + "bitflags 2.13.2", + "jni-sys 0.3.1", + "log", + "ndk-sys", + "num_enum", + "raw-window-handle", + "thiserror 1.0.69", +] + +[[package]] +name = "ndk-context" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" + +[[package]] +name = "ndk-sys" +version = "0.6.0+11769913" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee6cda3051665f1fb8d9e08fc35c96d5a244fb1be711a03b71118828afc9a873" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d" +dependencies = [ + "bitflags 2.13.2", + "cfg-if", + "cfg_aliases", + "libc", +] + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "nom" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405" +dependencies = [ + "memchr", +] + +[[package]] +name = "nonmax" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "610a5acd306ec67f907abe5567859a3c693fb9886eb1f012ab8f2a47bef3db51" + +[[package]] +name = "notify" +version = "8.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d3d07927151ff8575b7087f245456e549fea62edf0ec4e565a5ee50c8402bc3" +dependencies = [ + "bitflags 2.13.2", + "fsevent-sys", + "inotify", + "kqueue", + "libc", + "log", + "mio", + "notify-types", + "walkdir", + "windows-sys 0.60.2", +] + +[[package]] +name = "notify-debouncer-full" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c02b49179cfebc9932238d04d6079912d26de0379328872846118a0fa0dbb302" +dependencies = [ + "file-id", + "log", + "notify", + "notify-types", + "walkdir", +] + +[[package]] +name = "notify-types" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42b8cfee0e339a0337359f3c88165702ac6e600dc01c0cc9579a92d62b08477a" +dependencies = [ + "bitflags 2.13.2", +] + +[[package]] +name = "ntapi" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3b335231dfd352ffb0f8017f3b6027a4917f7df785ea2143d8af2adc66980ae" +dependencies = [ + "winapi", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "num-bigint" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c89e69e7e0f03bea5ef08013795c25018e101932225a656383bd384495ecc367" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "num-integer" +version = "0.1.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ce2d95d4b3734dc35aa2f45e1aa22cd416814592a4f9d9205e11affd5b8e10b" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "num_enum" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0bca838442ec211fa11de3a8b0e0e8f3a4522575b5c4c06ed722e005036f26" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "680998035259dcfcafe653688bf2aa6d3e2dc05e98be6ab46afb089dc84f1df8" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "objc-sys" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb91bdd390c7ce1a8607f35f3ca7151b65afc0ff5ff3b34fa350f7d7c7e4310" + +[[package]] +name = "objc2" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46a785d4eeff09c14c487497c162e92766fbb3e4059a71840cecc03d9a50b804" +dependencies = [ + "objc-sys", + "objc2-encode", +] + +[[package]] +name = "objc2" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a12a8ed07aefc768292f076dc3ac8c48f3781c8f2d5851dd3d98950e8c5a89f" +dependencies = [ + "objc2-encode", +] + +[[package]] +name = "objc2-app-kit" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4e89ad9e3d7d297152b17d39ed92cd50ca8063a89a9fa569046d41568891eff" +dependencies = [ + "bitflags 2.13.2", + "block2 0.5.1", + "libc", + "objc2 0.5.2", + "objc2-core-data", + "objc2-core-image", + "objc2-foundation 0.2.2", + "objc2-quartz-core 0.2.2", +] + +[[package]] +name = "objc2-app-kit" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d49e936b501e5c5bf01fda3a9452ff86dc3ea98ad5f283e1455153142d97518c" +dependencies = [ + "bitflags 2.13.2", + "objc2 0.6.4", + "objc2-core-graphics", + "objc2-foundation 0.3.2", +] + +[[package]] +name = "objc2-audio-toolbox" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6948501a91121d6399b79abaa33a8aa4ea7857fe019f341b8c23ad6e81b79b08" +dependencies = [ + "bitflags 2.13.2", + "libc", + "objc2 0.6.4", + "objc2-core-audio", + "objc2-core-audio-types", + "objc2-core-foundation", + "objc2-foundation 0.3.2", +] + +[[package]] +name = "objc2-avf-audio" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13a380031deed8e99db00065c45937da434ca987c034e13b87e4441f9e4090be" +dependencies = [ + "objc2 0.6.4", + "objc2-foundation 0.3.2", +] + +[[package]] +name = "objc2-cloud-kit" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74dd3b56391c7a0596a295029734d3c1c5e7e510a4cb30245f8221ccea96b009" +dependencies = [ + "bitflags 2.13.2", + "block2 0.5.1", + "objc2 0.5.2", + "objc2-core-location", + "objc2-foundation 0.2.2", +] + +[[package]] +name = "objc2-contacts" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5ff520e9c33812fd374d8deecef01d4a840e7b41862d849513de77e44aa4889" +dependencies = [ + "block2 0.5.1", + "objc2 0.5.2", + "objc2-foundation 0.2.2", +] + +[[package]] +name = "objc2-core-audio" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1eebcea8b0dbff5f7c8504f3107c68fc061a3eb44932051c8cf8a68d969c3b2" +dependencies = [ + "dispatch2", + "objc2 0.6.4", + "objc2-core-audio-types", + "objc2-core-foundation", + "objc2-foundation 0.3.2", +] + +[[package]] +name = "objc2-core-audio-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a89f2ec274a0cf4a32642b2991e8b351a404d290da87bb6a9a9d8632490bd1c" +dependencies = [ + "bitflags 2.13.2", + "objc2 0.6.4", +] + +[[package]] +name = "objc2-core-data" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "617fbf49e071c178c0b24c080767db52958f716d9eabdf0890523aeae54773ef" +dependencies = [ + "bitflags 2.13.2", + "block2 0.5.1", + "objc2 0.5.2", + "objc2-foundation 0.2.2", +] + +[[package]] +name = "objc2-core-foundation" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536" +dependencies = [ + "bitflags 2.13.2", + "block2 0.6.2", + "dispatch2", + "libc", + "objc2 0.6.4", +] + +[[package]] +name = "objc2-core-graphics" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e022c9d066895efa1345f8e33e584b9f958da2fd4cd116792e15e07e4720a807" +dependencies = [ + "bitflags 2.13.2", + "dispatch2", + "objc2 0.6.4", + "objc2-core-foundation", + "objc2-io-surface", +] + +[[package]] +name = "objc2-core-image" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55260963a527c99f1819c4f8e3b47fe04f9650694ef348ffd2227e8196d34c80" +dependencies = [ + "block2 0.5.1", + "objc2 0.5.2", + "objc2-foundation 0.2.2", + "objc2-metal 0.2.2", +] + +[[package]] +name = "objc2-core-location" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "000cfee34e683244f284252ee206a27953279d370e309649dc3ee317b37e5781" +dependencies = [ + "block2 0.5.1", + "objc2 0.5.2", + "objc2-contacts", + "objc2-foundation 0.2.2", +] + +[[package]] +name = "objc2-encode" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33" + +[[package]] +name = "objc2-foundation" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8" +dependencies = [ + "bitflags 2.13.2", + "block2 0.5.1", + "dispatch", + "libc", + "objc2 0.5.2", +] + +[[package]] +name = "objc2-foundation" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272" +dependencies = [ + "bitflags 2.13.2", + "block2 0.6.2", + "libc", + "objc2 0.6.4", + "objc2-core-foundation", +] + +[[package]] +name = "objc2-io-kit" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33fafba39597d6dc1fb709123dfa8289d39406734be322956a69f0931c73bb15" +dependencies = [ + "bitflags 2.13.2", + "libc", + "objc2-core-foundation", +] + +[[package]] +name = "objc2-io-surface" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180788110936d59bab6bd83b6060ffdfffb3b922ba1396b312ae795e1de9d81d" +dependencies = [ + "bitflags 2.13.2", + "objc2 0.6.4", + "objc2-core-foundation", +] + +[[package]] +name = "objc2-link-presentation" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1a1ae721c5e35be65f01a03b6d2ac13a54cb4fa70d8a5da293d7b0020261398" +dependencies = [ + "block2 0.5.1", + "objc2 0.5.2", + "objc2-app-kit 0.2.2", + "objc2-foundation 0.2.2", +] + +[[package]] +name = "objc2-metal" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0cba1276f6023976a406a14ffa85e1fdd19df6b0f737b063b95f6c8c7aadd6" +dependencies = [ + "bitflags 2.13.2", + "block2 0.5.1", + "objc2 0.5.2", + "objc2-foundation 0.2.2", +] + +[[package]] +name = "objc2-metal" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0125f776a10d00af4152d74616409f0d4a2053a6f57fa5b7d6aa2854ac04794" +dependencies = [ + "bitflags 2.13.2", + "block2 0.6.2", + "objc2 0.6.4", + "objc2-foundation 0.3.2", +] + +[[package]] +name = "objc2-quartz-core" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e42bee7bff906b14b167da2bac5efe6b6a07e6f7c0a21a7308d40c960242dc7a" +dependencies = [ + "bitflags 2.13.2", + "block2 0.5.1", + "objc2 0.5.2", + "objc2-foundation 0.2.2", + "objc2-metal 0.2.2", +] + +[[package]] +name = "objc2-quartz-core" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c1358452b371bf9f104e21ec536d37a650eb10f7ee379fff67d2e08d537f1f" +dependencies = [ + "bitflags 2.13.2", + "objc2 0.6.4", + "objc2-core-foundation", + "objc2-core-graphics", + "objc2-foundation 0.3.2", + "objc2-metal 0.3.2", +] + +[[package]] +name = "objc2-symbols" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a684efe3dec1b305badae1a28f6555f6ddd3bb2c2267896782858d5a78404dc" +dependencies = [ + "objc2 0.5.2", + "objc2-foundation 0.2.2", +] + +[[package]] +name = "objc2-ui-kit" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8bb46798b20cd6b91cbd113524c490f1686f4c4e8f49502431415f3512e2b6f" +dependencies = [ + "bitflags 2.13.2", + "block2 0.5.1", + "objc2 0.5.2", + "objc2-cloud-kit", + "objc2-core-data", + "objc2-core-image", + "objc2-core-location", + "objc2-foundation 0.2.2", + "objc2-link-presentation", + "objc2-quartz-core 0.2.2", + "objc2-symbols", + "objc2-uniform-type-identifiers", + "objc2-user-notifications", +] + +[[package]] +name = "objc2-uniform-type-identifiers" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44fa5f9748dbfe1ca6c0b79ad20725a11eca7c2218bceb4b005cb1be26273bfe" +dependencies = [ + "block2 0.5.1", + "objc2 0.5.2", + "objc2-foundation 0.2.2", +] + +[[package]] +name = "objc2-user-notifications" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76cfcbf642358e8689af64cee815d139339f3ed8ad05103ed5eaf73db8d84cb3" +dependencies = [ + "bitflags 2.13.2", + "block2 0.5.1", + "objc2 0.5.2", + "objc2-core-location", + "objc2-foundation 0.2.2", +] + +[[package]] +name = "offset-allocator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e234d535da3521eb95106f40f0b73483d80bfb3aacf27c40d7e2b72f1a3e00a2" +dependencies = [ + "log", + "nonmax", +] + +[[package]] +name = "ogg" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6951b4e8bf21c8193da321bcce9c9dd2e13c858fe078bf9054a288b419ae5d6e" +dependencies = [ + "byteorder", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + +[[package]] +name = "orbclient" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5df339f526ea9a60e371768d50efc2f2508c7203290731565d1f7a6f71d21747" +dependencies = [ + "libc", + "libredox", +] + +[[package]] +name = "ordered-float" +version = "5.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c9e0d9b23589f26070720bac724174bfec1083e82f7854cdd0267518343c0" +dependencies = [ + "num-traits", +] + +[[package]] +name = "os_pipe" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "owned_ttf_parser" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36820e9051aca1014ddc75770aab4d68bc1e9e632f0f5627c4086bc216fb583b" +dependencies = [ + "ttf-parser", +] + +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.5.18", + "smallvec", + "windows-link", +] + +[[package]] +name = "parlance" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b6937eda350acc1a5d05872c3cbf99fe78619c269096e2be3d4a350058639d5" + +[[package]] +name = "parley" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22d2ff88bd3f7d68d1d9b09c7e6209f9a8e8c05088295140a2bcf2e9b17038c5" +dependencies = [ + "fontique", + "harfrust", + "hashbrown 0.17.1", + "icu_normalizer", + "icu_properties", + "icu_segmenter", + "linebender_resource_handle", + "parlance", + "parley_data", + "skrifa", +] + +[[package]] +name = "parley_data" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1567535334d6ba2d3cde19221ba9a7bd0fabb3cbd99046ddfb10ae061cfcc889" +dependencies = [ + "icu_properties", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "petgraph" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8701b58ea97060d5e5b155d383a69952a60943f0e6dfe30b04c287beb0b27455" +dependencies = [ + "fixedbitset", + "hashbrown 0.15.5", + "indexmap", + "serde", + "serde_derive", +] + +[[package]] +name = "phf_shared" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2466b2336ed02bcdca6b294417127b90ec92038d1d5c4fbeac971a922e0e0924" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c96395f0a926bc13b1c17622aaddda1ecb55d49c8f1bf9777e4d877800a43f8b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "piper" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c835479a4443ded371d6c535cbfd8d31ad92c5d23ae9770a61bc155e4992a3c1" +dependencies = [ + "atomic-waker", + "fastrand", + "futures-io", +] + +[[package]] +name = "pkg-config" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" + +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + +[[package]] +name = "png" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60769b8b31b2a9f263dae2776c37b1b28ae246943cf719eb6946a1db05128a61" +dependencies = [ + "bitflags 2.13.2", + "crc32fast", + "fdeflate", + "flate2", + "miniz_oxide 0.8.9", +] + +[[package]] +name = "polling" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi", + "pin-project-lite", + "rustix 1.1.5", + "windows-sys 0.61.2", +] + +[[package]] +name = "portable-atomic" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" + +[[package]] +name = "portable-atomic-util" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10ab3eb7f3becc3a1cbc4f2c6f20267996cfc1a6467a873763411b136a122715" +dependencies = [ + "portable-atomic", +] + +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "serde_core", + "writeable", + "zerovec", +] + +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa" + +[[package]] +name = "prettyplease" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bfe0f4c752e450fc2faf62654f1c134747922825d5b04ca717b8874f41a40c0" +dependencies = [ + "proc-macro2", + "syn 3.0.6", +] + +[[package]] +name = "proc-macro-crate" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "profiling" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d595e54a326bc53c1c197b32d295e14b169e3cfeaa8dc82b529f947fba6bcf5" + +[[package]] +name = "pxfm" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d55d956fa96f5ec02be2e13af0e20391a5aa83d6a074e3ad368959d0fab299ea" + +[[package]] +name = "quick-xml" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e660451e55124f798a69a5af3f49ccfbefbd41910eefd25caf2393e1f3473ec1" +dependencies = [ + "memchr", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "radsort" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "019b4b213425016d7d84a153c4c73afb0946fbb4840e4eece7ba8848b9d6da22" + +[[package]] +name = "rand" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af" +dependencies = [ + "chacha20", + "getrandom 0.4.3", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + +[[package]] +name = "rand_distr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d431c2703ccf129de4d45253c03f49ebb22b97d6ad79ee3ecfc7e3f4862c1d8" +dependencies = [ + "num-traits", + "rand", +] + +[[package]] +name = "range-alloc" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca45419789ae5a7899559e9512e58ca889e41f04f1f2445e9f4b290ceccd1d08" + +[[package]] +name = "raw-window-handle" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20675572f6f24e9e76ef639bc5552774ed45f1c30e2951e1e99c59888861c539" + +[[package]] +name = "raw-window-metal" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40d213455a5f1dc59214213c7330e074ddf8114c9a42411eb890c767357ce135" +dependencies = [ + "objc2 0.6.4", + "objc2-core-foundation", + "objc2-foundation 0.3.2", + "objc2-quartz-core 0.3.2", +] + +[[package]] +name = "read-fonts" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "046a7d674daf459825b32f5062056d6882db0d2f5a479fbd76ccfc870ac18709" +dependencies = [ + "bytemuck", + "font-types", + "once_cell", +] + +[[package]] +name = "rectangle-pack" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0d463f2884048e7153449a55166f91028d5b0ea53c79377099ce4e8cf0cf9bb" + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags 2.13.2", +] + +[[package]] +name = "redox_syscall" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "737970939a87c6fa31e7acad13307bccbb017a073b695b6089a2c484f929e20e" +dependencies = [ + "bitflags 2.13.2", +] + +[[package]] +name = "regex" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" + +[[package]] +name = "renderdoc-sys" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832" + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rodio" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a536bb79db59098ef71a4dd4246c02eb87b316deceb1b68e0cde7167ec01eb" +dependencies = [ + "cpal", + "dasp_sample", + "lewton", + "num-rational", + "thiserror 2.0.21", + "tracing", +] + +[[package]] +name = "ron" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81116b9531d61eabc41aeb228e4b6b2435bcca3233b98cf3b3077d4e6e9debb3" +dependencies = [ + "bitflags 2.13.2", + "once_cell", + "serde", + "serde_derive", + "typeid", + "unicode-ident", +] + +[[package]] +name = "rspirv" +version = "0.12.0+sdk-1.3.268.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cf3a93856b6e5946537278df0d3075596371b1950ccff012f02b0f7eafec8d" +dependencies = [ + "rustc-hash 1.1.0", + "spirv 0.3.0+sdk-1.3.268.0", +] + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" +dependencies = [ + "bitflags 2.13.2", + "errno", + "libc", + "linux-raw-sys 0.4.15", + "windows-sys 0.59.0", +] + +[[package]] +name = "rustix" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891efababe418670775f199f0d233d84843c227a0949a883ce15b37c78d6629d" +dependencies = [ + "bitflags 2.13.2", + "errno", + "libc", + "linux-raw-sys 0.12.1", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.23.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d41d731c7d2f962d1ccc364cec258de3c0e93b38c2fb3ba97ac74513048d634" +dependencies = [ + "log", + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-native-certs" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dab5152771c58876a2146916e53e35057e1a4dfa2b9df0f0305b07f611fdea4d" +dependencies = [ + "openssl-probe", + "rustls-pki-types", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" +dependencies = [ + "zeroize", +] + +[[package]] +name = "rustls-platform-verifier" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1167586491e2b18b8bfbb293e8180ec17c201c4f076d7cb3070ca964e7598f98" +dependencies = [ + "core-foundation 0.10.1", + "core-foundation-sys", + "jni 0.22.4", + "log", + "once_cell", + "rustls", + "rustls-native-certs", + "rustls-platform-verifier-android", + "rustls-webpki", + "security-framework", + "security-framework-sys", + "webpki-root-certs", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls-platform-verifier-android" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eec689c0bc40ff2458a5977b6619cb718087084a18e02a131c599b62d05e1a5f" + +[[package]] +name = "rustls-webpki" +version = "0.103.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "ruzstd" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7c1c839d570d835527c9a5e4db7cb2198683a988cb9d7293fc8674e6bd58fc8" +dependencies = [ + "twox-hash", +] + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91c1b7e4904c873ef0710c1f407dde2e6287de2bebc1bbbf7d430bb7cbffd939" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "sctk-adwaita" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6277f0217056f77f1d8f49f2950ac6c278c0d607c45f5ee99328d792ede24ec" +dependencies = [ + "ab_glyph", + "log", + "memmap2", + "smithay-client-toolkit", + "tiny-skia", +] + +[[package]] +name = "security-framework" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" +dependencies = [ + "bitflags 2.13.2", + "core-foundation 0.10.1", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + +[[package]] +name = "send_wrapper" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "serde_json" +version = "1.0.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "sha3" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77fd7028345d415a4034cf8777cd4f8ab1851274233b45f84e3d955502d93874" +dependencies = [ + "digest", + "keccak", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "simd-adler32" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" + +[[package]] +name = "simd_cesu8" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11031e251abf8611c80f460e19dbdeb54a66db918e49c65a7065b46ac7aec520" +dependencies = [ + "rustc_version", + "simdutf8", +] + +[[package]] +name = "simdutf8" +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 = "skrifa" +version = "0.44.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819ab7d62b1d3e72d9d9dea5650bac30424f9111364bb94928dbf5ecad1baa68" +dependencies = [ + "bytemuck", + "read-fonts", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "slotmap" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdd58c3c93c3d278ca835519292445cb4b0d4dc59ccfdf7ceadaab3f8aeb4038" +dependencies = [ + "version_check", +] + +[[package]] +name = "smallvec" +version = "1.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9395f0f0eee849a9b707b2f06bb92a6a422090e2123bb2ef8e87a0e61892a8e" + +[[package]] +name = "smithay-client-toolkit" +version = "0.19.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3457dea1f0eb631b4034d61d4d8c32074caa6cd1ab2d59f2327bd8461e2c0016" +dependencies = [ + "bitflags 2.13.2", + "calloop", + "calloop-wayland-source", + "cursor-icon", + "libc", + "log", + "memmap2", + "rustix 0.38.44", + "thiserror 1.0.69", + "wayland-backend", + "wayland-client", + "wayland-csd-frame", + "wayland-cursor", + "wayland-protocols", + "wayland-protocols-wlr", + "wayland-scanner", + "xkeysym", +] + +[[package]] +name = "smol_str" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd538fb6910ac1099850255cf94a94df6551fbdd602454387d0adb2d1ca6dead" +dependencies = [ + "serde", +] + +[[package]] +name = "spin" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0134f9043ed38b087ac4f7d4af44c79e2c9e5094421fe3164f435ce585953b10" +dependencies = [ + "portable-atomic", +] + +[[package]] +name = "spirv" +version = "0.3.0+sdk-1.3.268.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eda41003dc44290527a59b13432d4a0379379fa074b70174882adfbdfd917844" +dependencies = [ + "bitflags 2.13.2", +] + +[[package]] +name = "spirv" +version = "0.4.0+sdk-1.4.341.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9571ea910ebd84c86af4b3ed27f9dbdc6ad06f17c5f96146b2b671e2976744f" +dependencies = [ + "bitflags 2.13.2", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "stackfuture" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115beb9c69db2393ff10b75a1b8587a51716e5551d015001e55320ed279d32f9" +dependencies = [ + "const_panic", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strict-num" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" + +[[package]] +name = "string_cache" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a18596f8c785a729f2819c0f6a7eae6ebeebdfffbfe4214ae6b087f690e31901" +dependencies = [ + "new_debug_unreachable", + "parking_lot", + "phf_shared", + "precomputed-hash", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "swash" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c2499c2d826531388872b2268718aed907a39bd785ab0dcfe57fab26283f92e" +dependencies = [ + "skrifa", + "yazi", + "zeno", +] + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "sysinfo" +version = "0.39.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2071df9448915b71c4fe6d25deaf1c22f12bd234f01540b77312bb8e41361e6" +dependencies = [ + "libc", + "memchr", + "ntapi", + "objc2-core-foundation", + "objc2-io-kit", + "windows", +] + +[[package]] +name = "taffy" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "639627c87f43b9181c811f40a6296409e093a17bc761214cba3c15df74f86b99" +dependencies = [ + "arrayvec", + "serde", + "slotmap", + "smallvec", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "tape-load" +version = "0.1.0" +source = "git+https://git.stargaze.group/molive/tape-drive.git?rev=45762855bca8772798242a545cdee21afbec2828#45762855bca8772798242a545cdee21afbec2828" +dependencies = [ + "foldhash 0.1.5", + "glam 0.30.10", + "humantime", + "rspirv", +] + +[[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 = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e" +dependencies = [ + "thiserror-impl 2.0.21", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "thread_local" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad99c4c6d32803332c548b1af0540b357b3f5fc0be8f6c6bfe8b2e6ae784070" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "tiny-skia" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83d13394d44dae3207b52a326c0c85a8bf87f1541f23b0d143811088497b09ab" +dependencies = [ + "arrayref", + "arrayvec", + "bytemuck", + "cfg-if", + "log", + "tiny-skia-path", +] + +[[package]] +name = "tiny-skia-path" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c9e7fc0c2e86a30b117d0462aa261b72b7a99b7ebd7deb3a14ceda95c5bdc93" +dependencies = [ + "arrayref", + "bytemuck", + "strict-num", +] + +[[package]] +name = "tinystr" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643" +dependencies = [ + "displaydoc", + "serde_core", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee" + +[[package]] +name = "tokio" +version = "1.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" +dependencies = [ + "pin-project-lite", +] + +[[package]] +name = "toml_datetime" +version = "1.1.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_edit" +version = "0.25.15+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1340ea94a5856333492c9064b02c778b191dd2c853778d9609debdcdfea3a614" +dependencies = [ + "indexmap", + "toml_datetime", + "toml_parser", + "winnow", +] + +[[package]] +name = "toml_parser" +version = "1.1.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d38ac1cf9b95face32296c0a3ede1fdc270627c9d9c02a7274dd6d960dc4d56" +dependencies = [ + "winnow", +] + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-oslog" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76902d2a8d5f9f55a81155c08971734071968c90f2d9bfe645fe700579b2950" +dependencies = [ + "cc", + "cfg-if", + "tracing-core", + "tracing-subscriber", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "tracing-wasm" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4575c663a174420fa2d78f4108ff68f65bf2fbb7dd89f33749b6e826b3626e07" +dependencies = [ + "tracing", + "tracing-subscriber", + "wasm-bindgen", +] + +[[package]] +name = "tree_magic_mini" +version = "3.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8765b90061cba6c22b5831f675da109ae5561588290f9fa2317adab2714d5a6" +dependencies = [ + "memchr", + "nom 8.0.0", + "petgraph", +] + +[[package]] +name = "ttf-parser" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31" + +[[package]] +name = "twox-hash" +version = "2.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5283634e518fe9e82c7b20520bb4bc209009fd16c82077c802f8111ecbb0117a" + +[[package]] +name = "typeid" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c" + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + +[[package]] +name = "typewit" +version = "1.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "214ca0b2191785cbc06209b9ca1861e048e39b5ba33574b3cedd58363d5bb5f6" + +[[package]] +name = "unicode-ident" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954" + +[[package]] +name = "unicode-segmentation" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8" + +[[package]] +name = "unicode-width" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "unsynn" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501a7adf1a4bd9951501e5c66621e972ef8874d787628b7f90e64f936ef7ec0a" +dependencies = [ + "mutants", + "proc-macro2", + "rustc-hash 2.1.3", +] + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "ureq" +version = "3.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a7ac20be9b7726e0bbdbf974c059676d9acb1cd414961f570a4e8231cacd7fc" +dependencies = [ + "base64", + "log", + "percent-encoding", + "rustls", + "rustls-pki-types", + "rustls-platform-verifier", + "ureq-proto", + "utf8-zero", + "webpki-roots", +] + +[[package]] +name = "ureq-proto" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f86fd172ccca569e458f61b6bdd6220965a9ef36e672a6852953b51a0e1583be" +dependencies = [ + "base64", + "http", + "httparse", + "log", +] + +[[package]] +name = "utf8-zero" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8c0a043c9540bae7c578c88f91dda8bd82e59ae27c21baca69c8b191aaf5a6e" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "uuid" +version = "1.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ef6dac1e96601b4fb3acccccff2139741fcb757cb9a36089bf5be91cfb285ce" +dependencies = [ + "getrandom 0.4.3", + "js-sys", + "serde_core", + "wasm-bindgen", +] + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "variadics_please" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b53d0f7f2d0182759a549f1f313ce16b07d8f9ba93098157b5fa10ee3e61117f" +dependencies = [ + "quote", + "unsynn", +] + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.4+wasi-0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.129" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb54f33acc68fd454578d9820b0bde1a1a3d17aa17bb7b6595806d02886d409" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cbab34de2d982e9b48e18d216d04c4a6f641066ff19ffb699980f591ee3610e" +dependencies = [ + "js-sys", + "tokio", + "wasm-bindgen", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.129" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e29d0c35b16e224a7eeb5cd2d25e3e1968fbd65604117b44d3b789d00ee8535" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.129" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f501a8bc3719dba86ef8ae4728879c08001bea749eb1333ac5b91e040e2a6b7" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 3.0.6", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.129" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23f0c9c52aa7cd7d77769a4cfe2a9adb1b331f489a41d912ce14513d5ab995c6" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wayland-backend" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38a91b4eaddff87b1cd1074985e3713da4af2c49742d1b356b2c01670a67a078" +dependencies = [ + "cc", + "downcast-rs 1.2.1", + "rustix 1.1.5", + "scoped-tls", + "smallvec", + "wayland-sys", +] + +[[package]] +name = "wayland-client" +version = "0.31.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c36a0f861ad76d0901f2800b46321410d9f73f2ea88aac0650d86c32688073" +dependencies = [ + "bitflags 2.13.2", + "rustix 1.1.5", + "wayland-backend", + "wayland-scanner", +] + +[[package]] +name = "wayland-csd-frame" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625c5029dbd43d25e6aa9615e88b829a5cad13b2819c4ae129fdbb7c31ab4c7e" +dependencies = [ + "bitflags 2.13.2", + "cursor-icon", + "wayland-backend", +] + +[[package]] +name = "wayland-cursor" +version = "0.31.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a52d18780be9b1314328a3de5f930b73d2200112e3849ca6cb11822793fb34d" +dependencies = [ + "rustix 1.1.5", + "wayland-client", + "xcursor", +] + +[[package]] +name = "wayland-protocols" +version = "0.32.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d0c813de3daa2ed6520af85a3bd49b0e722a3078506899aa9686fea58dc4b6" +dependencies = [ + "bitflags 2.13.2", + "wayland-backend", + "wayland-client", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols-plasma" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b6d8cf1eb2c1c31ed1f5643c88a6e53538129d4af80030c8cabd1f9fa884d91" +dependencies = [ + "bitflags 2.13.2", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols-wlr" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb04e52f7836d7c7976c78ca0250d61e33873c34156a2a1fc9474828ec268234" +dependencies = [ + "bitflags 2.13.2", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-scanner", +] + +[[package]] +name = "wayland-scanner" +version = "0.31.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "338e30461b3a2b67d70eb30a6d89f8e0c93a833e07d2ae89085cd070c4a00ac0" +dependencies = [ + "proc-macro2", + "quick-xml", + "quote", +] + +[[package]] +name = "wayland-sys" +version = "0.31.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8eab23fefc9e41f8e841df4a9c707e8a8c4ed26e944ef69297184de2785e3be" +dependencies = [ + "dlib", + "log", + "once_cell", + "pkg-config", +] + +[[package]] +name = "weak-table" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eba2ec791141b0bf4db542f6b038a8f9310cee33e076cb181245780b09a24ff" +dependencies = [ + "cfg-if", + "hashbrown 0.16.1", +] + +[[package]] +name = "web-sys" +version = "0.3.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88261b9deccee56594c11a3460c462c41f58d148598fe70ad77070126a68aba4" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-task" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cdc136a53ccd64a1211f107ccc34404769fbcc0f165f1afa065f5d88ab93538" +dependencies = [ + "async-task", + "cfg-if", + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-root-certs" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b96554aa2acc8ccdb7e1c9a58a7a68dd5d13bccc69cd124cb09406db612a1c9b" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "webpki-roots" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "wesl" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb84b87be534d24ac15773f8942ce90a00afe06093025d014c8cfa5277afa25b" +dependencies = [ + "annotate-snippets", + "anstream", + "derive_more", + "half", + "itertools 0.15.0", + "num-traits", + "thiserror 2.0.21", + "wesl-macros", + "wgsl-parse", + "wgsl-types", +] + +[[package]] +name = "wesl-macros" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0de205d9eec254c378fa9ab1fd01e84537b6e330063d85fbf9245f65731aced" +dependencies = [ + "itertools 0.15.0", + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "wgpu" +version = "30.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "527ccdf43dd5b2e8676eed9984ce00e2bbb0a1b85b70c1969dcb6cd2eb55ab9e" +dependencies = [ + "arrayvec", + "bitflags 2.13.2", + "bytemuck", + "cfg-if", + "cfg_aliases", + "document-features", + "hashbrown 0.17.1", + "js-sys", + "log", + "portable-atomic", + "profiling", + "raw-window-handle", + "smallvec", + "static_assertions", + "wasm-bindgen", + "web-sys", + "wgpu-core", + "wgpu-hal", + "wgpu-types", +] + +[[package]] +name = "wgpu-core" +version = "30.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c018fce9b6270aa203c2fdd56f3cce996713534bd757e4ea58c8560b121f14" +dependencies = [ + "arrayvec", + "bit-set 0.10.0", + "bit-vec", + "bitflags 2.13.2", + "bytemuck", + "cfg_aliases", + "document-features", + "hashbrown 0.17.1", + "indexmap", + "log", + "naga", + "naga-types", + "once_cell", + "parking_lot", + "portable-atomic", + "profiling", + "raw-window-handle", + "rustc-hash 1.1.0", + "smallvec", + "thiserror 2.0.21", + "wgpu-core-deps-apple", + "wgpu-core-deps-wasm", + "wgpu-core-deps-windows-linux-android", + "wgpu-hal", + "wgpu-naga-bridge", + "wgpu-types", +] + +[[package]] +name = "wgpu-core-deps-apple" +version = "30.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "061f3d319a40d39d00b1ecc2c33b89fe21d4e6fe01859df3500a3a8ecccd6b68" +dependencies = [ + "wgpu-hal", +] + +[[package]] +name = "wgpu-core-deps-wasm" +version = "30.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d260ca2ca8adc654f513a869bf3cac0b47f5b8d3f87803d6942015f8de597aae" +dependencies = [ + "wgpu-hal", +] + +[[package]] +name = "wgpu-core-deps-windows-linux-android" +version = "30.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7586165fd5f6d881cb9ce4bb71f40d6caab2c0f1837e3fc1d9788a197fb6004f" +dependencies = [ + "wgpu-hal", +] + +[[package]] +name = "wgpu-hal" +version = "30.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6b7fb58561a792bc237628ba0792e332de418fefe145f13b5ed8201e6d52f58" +dependencies = [ + "android_system_properties", + "arrayvec", + "ash", + "bit-set 0.10.0", + "bitflags 2.13.2", + "block2 0.6.2", + "bytemuck", + "cfg-if", + "cfg_aliases", + "glow", + "glutin_wgl_sys", + "gpu-allocator", + "hashbrown 0.17.1", + "js-sys", + "khronos-egl", + "libc", + "libloading", + "log", + "naga", + "naga-types", + "ndk-sys", + "objc2 0.6.4", + "objc2-core-foundation", + "objc2-core-graphics", + "objc2-foundation 0.3.2", + "objc2-metal 0.3.2", + "objc2-quartz-core 0.3.2", + "once_cell", + "ordered-float", + "parking_lot", + "portable-atomic", + "portable-atomic-util", + "profiling", + "range-alloc", + "raw-window-handle", + "raw-window-metal", + "renderdoc-sys", + "smallvec", + "static_assertions", + "thiserror 2.0.21", + "wasm-bindgen", + "wayland-sys", + "web-sys", + "wgpu-naga-bridge", + "wgpu-types", + "windows", + "windows-core", + "windows-result", +] + +[[package]] +name = "wgpu-naga-bridge" +version = "30.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f62e73117bb7a62bfd9c5a5841438a823f6566c6442a808ee269d2d055c081" +dependencies = [ + "naga", + "wgpu-types", +] + +[[package]] +name = "wgpu-types" +version = "30.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99dad6f1fbdbbdb4c278a6508b059d44688f5cebddf78d005a46a31340269286" +dependencies = [ + "bitflags 2.13.2", + "bytemuck", + "js-sys", + "log", + "naga-types", + "raw-window-handle", + "serde", + "static_assertions", + "web-sys", +] + +[[package]] +name = "wgsl-parse" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c0588236e8f7cd43cd1d88322095d971fba842c7d985f484453461a376a1ce6" +dependencies = [ + "annotate-snippets", + "derive_more", + "itertools 0.15.0", + "lalrpop", + "lalrpop-util", + "lexical", + "logos", + "thiserror 2.0.21", + "wgsl-types", +] + +[[package]] +name = "wgsl-types" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfc32acf991054fb0290c5fb03d9dae60be8cbc9245c9c26e4420e11e8c0045" +dependencies = [ + "half", + "itertools 0.15.0", + "num-traits", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580" +dependencies = [ + "windows-collections", + "windows-core", + "windows-future", + "windows-numerics", +] + +[[package]] +name = "windows-collections" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610" +dependencies = [ + "windows-core", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-future" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb" +dependencies = [ + "windows-core", + "windows-link", + "windows-threading", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-numerics" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26" +dependencies = [ + "windows-core", + "windows-link", +] + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[package]] +name = "windows-threading" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "winit" +version = "0.30.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6755fa58a9f8350bd1e472d4c3fcc25f824ec358933bba33306d0b63df5978d" +dependencies = [ + "ahash", + "android-activity", + "atomic-waker", + "bitflags 2.13.2", + "block2 0.5.1", + "bytemuck", + "calloop", + "cfg_aliases", + "concurrent-queue", + "core-foundation 0.9.4", + "core-graphics", + "cursor-icon", + "dpi", + "js-sys", + "libc", + "memmap2", + "ndk", + "objc2 0.5.2", + "objc2-app-kit 0.2.2", + "objc2-foundation 0.2.2", + "objc2-ui-kit", + "orbclient", + "percent-encoding", + "pin-project", + "raw-window-handle", + "redox_syscall 0.4.1", + "rustix 0.38.44", + "sctk-adwaita", + "smithay-client-toolkit", + "smol_str", + "tracing", + "unicode-segmentation", + "wasm-bindgen", + "wasm-bindgen-futures", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-protocols-plasma", + "web-sys", + "web-time", + "windows-sys 0.52.0", + "x11-dl", + "x11rb", + "xkbcommon-dl", +] + +[[package]] +name = "winnow" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81" +dependencies = [ + "memchr", +] + +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + +[[package]] +name = "wl-clipboard-rs" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9651471a32e87d96ef3a127715382b2d11cc7c8bb9822ded8a7cc94072eb0a3" +dependencies = [ + "libc", + "log", + "os_pipe", + "rustix 1.1.5", + "thiserror 2.0.21", + "tree_magic_mini", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-protocols-wlr", +] + +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "x11-dl" +version = "2.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38735924fedd5314a6e548792904ed8c6de6636285cb9fec04d5b1db85c1516f" +dependencies = [ + "libc", + "once_cell", + "pkg-config", +] + +[[package]] +name = "x11rb" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9993aa5be5a26815fe2c3eacfc1fde061fc1a1f094bf1ad2a18bf9c495dd7414" +dependencies = [ + "as-raw-xcb-connection", + "gethostname", + "libc", + "libloading", + "once_cell", + "rustix 1.1.5", + "x11rb-protocol", +] + +[[package]] +name = "x11rb-protocol" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6fc2961e4ef194dcbfe56bb845534d0dc8098940c7e5c012a258bfec6701bd" + +[[package]] +name = "xcursor" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "163b33ed8786455e2fa5d72f554057ce3f3182425434f756cd39c99839d88e23" + +[[package]] +name = "xkbcommon-dl" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d039de8032a9a8856a6be89cea3e5d12fdd82306ab7c94d74e6deab2460651c5" +dependencies = [ + "bitflags 2.13.2", + "dlib", + "log", + "once_cell", + "xkeysym", +] + +[[package]] +name = "xkeysym" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56" + +[[package]] +name = "xml-rs" +version = "0.8.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e450f9b2ed1dff33c94c12589a87338689467b9c4f5d8a5710bd09a847d2c8a7" + +[[package]] +name = "yazi" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01738255b5a16e78bbb83e7fbba0a1e7dd506905cfc53f4622d89015a03fbb5" + +[[package]] +name = "yoke" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33811428bee40dbceb6d545e95754741d17a6aef9a4849f0fd62e2ba4f412a78" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", + "synstructure", +] + +[[package]] +name = "zeno" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6df3dc4292935e51816d896edcd52aa30bc297907c26167fec31e2b0c6a32524" + +[[package]] +name = "zerocopy" +version = "0.8.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6df92bf3d9227be3d53173901ddbffac2babc27ae50f397776ffd6dc33f800cb" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac4f328cf2f05d084e496c3e9c3f33ed0a183656a16e1fcec4d464d8373aec82" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" + +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "zerovec" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0464e17806c1d976d5cba29399c7f08e516e279e2ba493f63123b5fca67dd8" +dependencies = [ + "serde", + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34df6fc39dbd26ddc9c10e6a2984476e13acce22e64e4487636ef494369225da" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "zlib-rs" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112" + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..cc93f31 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,76 @@ +[package] +name = "bevy_tape_drive" +version = "0.20.0-dev" +edition = "2024" +description = "Provides raytraced lighting for Bevy Engine" +homepage = "https://bevy.org" +repository = "https://github.com/bevyengine/bevy" +license = "MIT OR Apache-2.0" +keywords = ["bevy"] + +[dependencies] +# bevy +bevy_anti_alias = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_app = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_asset = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_camera = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_color = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_core_pipeline = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_derive = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_diagnostic = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_ecs = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_light = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_log = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_shader = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_math = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_mesh = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_pbr = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010", features = [ + "dfg_lut", +] } +bevy_platform = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010", default-features = false, features = [ + "std", +] } +bevy_reflect = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_render = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_shape = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_image = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010", features = [ + "zstd_rust", +] } +bevy_utils = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } +bevy_transform = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010" } + +# tape drive +tape-load = { git = "https://git.stargaze.group/molive/tape-drive.git", rev = "45762855bca8772798242a545cdee21afbec2828" } + +# other +bytemuck = { version = "1" } +derive_more = { version = "2", default-features = false, features = ["from"] } +tracing = { version = "0.1", default-features = false, features = ["std"] } +wgpu = { version = "30", default-features = false } + +[features] +dlss = ["bevy_anti_alias/dlss"] +force_disable_dlss = ["bevy_anti_alias/force_disable_dlss"] + +[package.metadata.docs.rs] +rustdoc-args = [ + "-Zunstable-options", + "--generate-link-to-definition", + "--generate-macro-expansion", +] +all-features = true + +[dev-dependencies] +rand = "0.10.0" +chacha20 = { version = "0.10.0", default-features = false, features = ["rng"] } +bevy = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010", features = [ + "default_font", + "https", + "free_camera", + "dev" +] } +argh = "0.1.12" + +[[example]] +name = "pica_pica" +path = "examples/pica_pica.rs" diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..f49a4e1 --- /dev/null +++ b/LICENCE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..dfe8424 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Bevy Tape Drive + +`cargo run --example="pica_pica"` diff --git a/examples/pica_pica.rs b/examples/pica_pica.rs new file mode 100644 index 0000000..bf93472 --- /dev/null +++ b/examples/pica_pica.rs @@ -0,0 +1,683 @@ +//! Demonstrates realtime dynamic raytraced lighting using Bevy Solari. + +use std::f32::consts::PI; + +use argh::FromArgs; +#[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] +use bevy::{ + anti_alias::dlss::{ + Dlss, DlssProjectId, DlssRayReconstructionFeature, DlssRayReconstructionSupported, + }, + render::camera::{MipBias, TemporalJitter}, +}; +use bevy::{ + camera::CameraMainTextureUsages, + camera_controller::free_camera::{FreeCamera, FreeCameraPlugin}, + diagnostic::{Diagnostic, DiagnosticPath, DiagnosticsStore}, + gltf::GltfMaterialName, + image::{ImageAddressMode, ImageLoaderSettings}, + mesh::{Indices, VertexAttributeValues}, + post_process::bloom::Bloom, + prelude::*, + render::{diagnostic::RenderDiagnosticsPlugin, render_resource::TextureUsages}, + world_serialization::WorldInstanceReady, +}; +use bevy_tape_drive::{ + pathtracer::{Pathtracer, PathtracingPlugin}, + prelude::{RaytracingMesh3d, SolariLighting, SolariPlugins}, +}; +use chacha20::ChaCha8Rng; +use rand::{RngExt, SeedableRng}; + +/// `bevy_solari` demo. +#[derive(FromArgs, Resource, Clone, Copy)] +struct Args { + /// use the reference pathtracer instead of the realtime lighting system. + #[argh(switch)] + pathtracer: Option, + /// stress test a scene with many lights. + #[argh(switch)] + many_lights: Option, +} + +fn main() { + let args: Args = argh::from_env(); + + let mut app = App::new(); + + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + app.insert_resource(DlssProjectId(bevy_asset::uuid::uuid!( + "5417916c-0291-4e3f-8f65-326c1858ab96" // Don't copy paste this - generate your own UUID! + ))); + + app.add_plugins(( + DefaultPlugins, + SolariPlugins, + FreeCameraPlugin, + RenderDiagnosticsPlugin, + )) + .insert_resource(args); + + if args.many_lights == Some(true) { + app.add_systems(Startup, setup_many_lights); + } else { + app.add_systems(Startup, setup_pica_pica); + } + + if args.pathtracer == Some(true) { + app.add_plugins(PathtracingPlugin); + } else { + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + app.add_systems(Update, toggle_dlss_rr); + + app.add_systems(Update, toggle_restir); + + if args.many_lights != Some(true) { + app.add_systems(Update, (pause_scene, toggle_lights, patrol_path)); + } + app.add_systems(PostUpdate, (update_control_text, update_performance_text)); + } + + app.run(); +} + +fn setup_pica_pica( + mut commands: Commands, + asset_server: Res, + args: Res, + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] dlss_rr_supported: Option< + Res, + >, +) { + commands + .spawn(( + WorldAssetRoot( + asset_server.load( + GltfAssetLabel::Scene(0) + .from_asset("https://github.com/bevyengine/bevy_asset_files/raw/2a5950295a8b6d9d051d59c0df69e87abcda58c3/pica_pica/mini_diorama_01.glb") + ), + ), + Transform::from_scale(Vec3::splat(10.0)), + )) + .observe(add_raytracing_meshes_on_scene_load); + + commands + .spawn(( + WorldAssetRoot(asset_server.load( + GltfAssetLabel::Scene(0).from_asset("https://github.com/bevyengine/bevy_asset_files/raw/2a5950295a8b6d9d051d59c0df69e87abcda58c3/pica_pica/robot_01.glb") + )), + Transform::from_scale(Vec3::splat(2.0)) + .with_translation(Vec3::new(-2.0, 0.05, -2.1)) + .with_rotation(Quat::from_rotation_y(PI / 2.0)), + PatrolPath { + path: vec![ + (Vec3::new(-2.0, 0.05, -2.1), Quat::from_rotation_y(PI / 2.0)), + (Vec3::new(2.2, 0.05, -2.1), Quat::from_rotation_y(0.0)), + ( + Vec3::new(2.2, 0.05, 2.1), + Quat::from_rotation_y(3.0 * PI / 2.0), + ), + (Vec3::new(-2.0, 0.05, 2.1), Quat::from_rotation_y(PI)), + ], + i: 0, + }, + )) + .observe(add_raytracing_meshes_on_scene_load); + + commands.spawn(( + DirectionalLight { + illuminance: light_consts::lux::FULL_DAYLIGHT, + shadow_maps_enabled: false, // Solari replaces shadow mapping + ..default() + }, + Transform::from_rotation(Quat::from_xyzw( + -0.13334629, + -0.86597735, + -0.3586996, + 0.3219264, + )), + )); + + let mut camera = commands.spawn(( + Camera3d::default(), + Camera { + clear_color: ClearColorConfig::Custom(Color::BLACK), + ..default() + }, + FreeCamera { + walk_speed: 3.0, + run_speed: 10.0, + ..Default::default() + }, + Transform::from_translation(Vec3::new(0.219417, 2.5764852, 6.9718704)).with_rotation( + Quat::from_xyzw(-0.1466768, 0.013738206, 0.002037309, 0.989087), + ), + // Msaa::Off and CameraMainTextureUsages with STORAGE_BINDING are required for Solari + CameraMainTextureUsages::default().with(TextureUsages::STORAGE_BINDING), + Msaa::Off, + )); + + if args.pathtracer == Some(true) { + camera.insert(Pathtracer::default()); + } else { + camera.insert(SolariLighting::default()); + } + + // Using DLSS Ray Reconstruction for denoising (and cheaper rendering via + // upscaling) is _highly_ recommended when using Solari + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + if dlss_rr_supported.is_some() { + camera.insert(Dlss::::default()); + } + + commands.spawn(( + ControlText, + Text::default(), + Node { + position_type: PositionType::Absolute, + bottom: px(12.0), + left: px(12.0), + ..default() + }, + )); + + commands.spawn(( + Node { + position_type: PositionType::Absolute, + right: px(0.0), + padding: px(4.0).all(), + border_radius: BorderRadius::bottom_left(px(4.0)), + ..default() + }, + BackgroundColor(Color::srgba(0.10, 0.10, 0.10, 0.8)), + children![( + PerformanceText, + Text::default(), + TextFont { + font_size: FontSize::Px(8.0), + ..default() + }, + )], + )); +} + +fn setup_many_lights( + mut commands: Commands, + asset_server: Res, + mut meshes: ResMut>, + mut materials: ResMut>, + args: Res, + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] dlss_rr_supported: Option< + Res, + >, +) { + let mut rng = ChaCha8Rng::seed_from_u64(42); + + let mut plane_mesh = Plane3d::default() + .mesh() + .size(400.0, 400.0) + .build() + .with_generated_tangents() + .unwrap(); + match plane_mesh.attribute_mut(Mesh::ATTRIBUTE_UV_0).unwrap() { + VertexAttributeValues::Float32x2(items) => { + items.iter_mut().flatten().for_each(|x| *x *= 3.0); + }, + _ => unreachable!(), + } + let plane_mesh = meshes.add(plane_mesh); + let cube_mesh = meshes.add( + Cuboid::default() + .mesh() + .build() + .with_generated_tangents() + .unwrap(), + ); + let sphere_mesh = meshes.add( + Sphere::new(1.0) + .mesh() + .build() + .with_generated_tangents() + .unwrap(), + ); + + commands + .spawn(( + RaytracingMesh3d(plane_mesh.clone()), + MeshMaterial3d( + materials.add(StandardMaterial { + base_color_texture: Some( + asset_server + .load_builder() + .with_settings::(|settings| { + settings + .sampler + .get_or_init_descriptor() + .set_address_mode(ImageAddressMode::Repeat); + }) + .load("textures/uv_checker_bw.png"), + ), + perceptual_roughness: 0.0, + ..default() + }), + ), + )) + .insert_if(Mesh3d(plane_mesh), || args.pathtracer != Some(true)); + + for _ in 0..8000 { + commands + .spawn(( + RaytracingMesh3d(cube_mesh.clone()), + MeshMaterial3d(materials.add(StandardMaterial { + base_color: Color::srgb(rng.random(), rng.random(), rng.random()), + perceptual_roughness: rng.random(), + ..default() + })), + Transform::default() + .with_scale(Vec3 { + x: rng.random_range(0.2..=2.0), + y: rng.random_range(0.2..=2.0), + z: rng.random_range(0.2..=2.0), + }) + .with_translation(Vec3::new( + rng.random_range(-180.0..=180.0), + 0.2, + rng.random_range(-180.0..=180.0), + )), + )) + .insert_if(Mesh3d(cube_mesh.clone()), || args.pathtracer != Some(true)); + } + + for x in -10..=10 { + for y in -10..=10 { + commands + .spawn(( + RaytracingMesh3d(sphere_mesh.clone()), + MeshMaterial3d( + materials.add(StandardMaterial { + emissive: Color::linear_rgb( + rng.random::() * 60000.0, + rng.random::() * 60000.0, + rng.random::() * 60000.0, + ) + .into(), + ..default() + }), + ), + Transform::default().with_translation(Vec3::new( + (x * 20) as f32, + 7.0, + (y * 20) as f32, + )), + )) + .insert_if(Mesh3d(sphere_mesh.clone()), || { + args.pathtracer != Some(true) + }); + } + } + + let mut camera = commands.spawn(( + Camera3d::default(), + Camera { + clear_color: ClearColorConfig::Custom(Color::BLACK), + ..default() + }, + FreeCamera { + walk_speed: 3.0, + run_speed: 10.0, + ..Default::default() + }, + Transform::from_translation(Vec3::new(6.11329, 166.74896, 451.8226)).with_rotation( + Quat::from_xyzw(-0.183938, 0.009093744, 0.0017017953, 0.9828943), + ), + // Msaa::Off and CameraMainTextureUsages with STORAGE_BINDING are required for Solari + CameraMainTextureUsages::default().with(TextureUsages::STORAGE_BINDING), + Msaa::Off, + Bloom { + intensity: 0.1, + ..Bloom::NATURAL + }, + )); + + if args.pathtracer == Some(true) { + camera.insert(Pathtracer::default()); + } else { + camera.insert(SolariLighting::default()); + } + + // Using DLSS Ray Reconstruction for denoising (and cheaper rendering via + // upscaling) is _highly_ recommended when using Solari + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + if dlss_rr_supported.is_some() { + camera.insert(Dlss::::default()); + } + + commands.spawn(( + ControlText, + Text::default(), + Node { + position_type: PositionType::Absolute, + bottom: px(12.0), + left: px(12.0), + ..default() + }, + )); + + commands.spawn(( + Node { + position_type: PositionType::Absolute, + right: px(0.0), + padding: px(4.0).all(), + border_radius: BorderRadius::bottom_left(px(4.0)), + ..default() + }, + BackgroundColor(Color::srgba(0.10, 0.10, 0.10, 0.8)), + children![( + PerformanceText, + Text::default(), + TextFont { + font_size: FontSize::Px(8.0), + ..default() + }, + )], + )); +} + +fn add_raytracing_meshes_on_scene_load( + scene_ready: On, + children: Query<&Children>, + mesh_query: Query<( + &Mesh3d, + &MeshMaterial3d, + Option<&GltfMaterialName>, + )>, + mut meshes: ResMut>, + mut materials: ResMut>, + mut commands: Commands, + args: Res, +) { + for descendant in children.iter_descendants(scene_ready.entity) { + if let Ok((Mesh3d(mesh_handle), MeshMaterial3d(material_handle), material_name)) = + mesh_query.get(descendant) + { + // Add raytracing mesh component + commands + .entity(descendant) + .insert(RaytracingMesh3d(mesh_handle.clone())); + + // Ensure meshes are Solari compatible + let mut mesh = meshes.get_mut(mesh_handle).unwrap(); + if !mesh.contains_attribute(Mesh::ATTRIBUTE_UV_0) { + let vertex_count = mesh.count_vertices(); + mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, vec![[0.0, 0.0]; vertex_count]); + mesh.insert_attribute( + Mesh::ATTRIBUTE_TANGENT, + vec![[0.0, 0.0, 0.0, 0.0]; vertex_count], + ); + } + if !mesh.contains_attribute(Mesh::ATTRIBUTE_TANGENT) { + mesh.generate_tangents().unwrap(); + } + if mesh.contains_attribute(Mesh::ATTRIBUTE_UV_1) { + mesh.remove_attribute(Mesh::ATTRIBUTE_UV_1); + } + if let Some(indices) = mesh.indices_mut() + && let Indices::U16(_) = indices + { + *indices = Indices::U32(indices.iter().map(|i| i as u32).collect()); + } + + // Prevent rasterization if using pathtracer + if args.pathtracer == Some(true) { + commands.entity(descendant).remove::(); + } + + // Adjust scene materials to better demo Solari features + if material_name.map(|s| s.0.as_str()) == Some("material") { + let mut material = materials.get_mut(material_handle).unwrap(); + material.emissive = LinearRgba::BLACK; + } + if material_name.map(|s| s.0.as_str()) == Some("Lights") { + let mut material = materials.get_mut(material_handle).unwrap(); + material.emissive = + LinearRgba::from(Color::srgb(0.941, 0.714, 0.043)) * 1_000_000.0; + material.alpha_mode = AlphaMode::Opaque; + material.specular_transmission = 0.0; + + commands.insert_resource(RobotLightMaterial(material_handle.clone())); + } + if material_name.map(|s| s.0.as_str()) == Some("Glass_Dark_01") { + let mut material = materials.get_mut(material_handle).unwrap(); + material.alpha_mode = AlphaMode::Opaque; + material.specular_transmission = 0.0; + } + } + } +} + +#[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] +fn toggle_dlss_rr( + key_input: Res>, + camera: Single<(Entity, Has>), With>, + dlss_rr_supported: Option>, + mut commands: Commands, +) { + if key_input.just_pressed(KeyCode::Digit3) && dlss_rr_supported.is_some() { + let (entity, dlss) = *camera; + if dlss { + commands + .entity(entity) + .remove::<(Dlss, TemporalJitter, MipBias)>(); + } else { + commands + .entity(entity) + .insert(Dlss::::default()); + } + } +} + +fn toggle_restir( + key_input: Res>, + mut solari_lighting: Single<&mut SolariLighting>, +) { + if key_input.just_pressed(KeyCode::KeyR) { + solari_lighting.restir = !solari_lighting.restir; + } +} + +fn pause_scene(mut time: ResMut>, key_input: Res>) { + if key_input.just_pressed(KeyCode::Space) { + time.toggle(); + } +} + +#[derive(Resource)] +struct RobotLightMaterial(Handle); + +fn toggle_lights( + key_input: Res>, + robot_light_material: Option>, + mut materials: ResMut>, + directional_light: Query>, + mut commands: Commands, +) { + if key_input.just_pressed(KeyCode::Digit1) { + if let Ok(directional_light) = directional_light.single() { + commands.entity(directional_light).despawn(); + } else { + commands.spawn(( + DirectionalLight { + illuminance: light_consts::lux::FULL_DAYLIGHT, + shadow_maps_enabled: false, // Solari replaces shadow mapping + ..default() + }, + Transform::from_rotation(Quat::from_xyzw( + -0.13334629, + -0.86597735, + -0.3586996, + 0.3219264, + )), + )); + } + } + + if key_input.just_pressed(KeyCode::Digit2) + && let Some(robot_light_material) = robot_light_material + { + let mut material = materials.get_mut(&robot_light_material.0).unwrap(); + if material.emissive == LinearRgba::BLACK { + material.emissive = LinearRgba::from(Color::srgb(0.941, 0.714, 0.043)) * 1_000_000.0; + } else { + material.emissive = LinearRgba::BLACK; + } + } +} + +#[derive(Component)] +struct PatrolPath { + path: Vec<(Vec3, Quat)>, + i: usize, +} + +fn patrol_path(mut query: Query<(&mut PatrolPath, &mut Transform)>, time: Res>) { + for (mut path, mut transform) in query.iter_mut() { + let (mut target_position, mut target_rotation) = path.path[path.i]; + let mut distance_to_target = transform.translation.distance(target_position); + if distance_to_target < 0.01 { + transform.translation = target_position; + transform.rotation = target_rotation; + + path.i = (path.i + 1) % path.path.len(); + (target_position, target_rotation) = path.path[path.i]; + distance_to_target = transform.translation.distance(target_position); + } + + let direction = (target_position - transform.translation).normalize(); + let movement = direction * time.delta_secs(); + + if movement.length() > distance_to_target { + transform.translation = target_position; + transform.rotation = target_rotation; + } else { + transform.translation += movement; + } + } +} + +#[derive(Component)] +struct ControlText; + +fn update_control_text( + mut text: Single<&mut Text, With>, + solari_lighting: Single<&SolariLighting>, + robot_light_material: Option>, + materials: Res>, + directional_light: Query>, + time: Res>, + args: Res, + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] dlss_rr_supported: Option< + Res, + >, + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] dlss_camera: Query< + Has>, + With, + >, +) { + text.0.clear(); + + if args.many_lights != Some(true) { + if time.is_paused() { + text.0.push_str("(Space): Resume"); + } else { + text.0.push_str("(Space): Pause"); + } + + if directional_light.single().is_ok() { + text.0.push_str("\n(1): Disable directional light"); + } else { + text.0.push_str("\n(1): Enable directional light"); + } + + match robot_light_material.and_then(|m| materials.get(&m.0)) { + Some(robot_light_material) if robot_light_material.emissive != LinearRgba::BLACK => { + text.0.push_str("\n(2): Disable robot emissive light"); + }, + _ => { + text.0.push_str("\n(2): Enable robot emissive light"); + }, + } + } + + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + if dlss_rr_supported.is_some() { + if matches!(dlss_camera.single(), Ok(true)) { + text.0.push_str("\n(3): Disable DLSS Ray Reconstruction"); + } else { + text.0.push_str("\n(3): Enable DLSS Ray Reconstruction"); + } + } else { + text.0 + .push_str("\nDenoising: DLSS Ray Reconstruction not supported"); + } + + #[cfg(any(not(feature = "dlss"), feature = "force_disable_dlss"))] + text.0 + .push_str("\nDenoising: App not compiled with DLSS support"); + + if solari_lighting.restir { + text.0.push_str("\n(R): Disable ReSTIR"); + } else { + text.0.push_str("\n(R): Enable ReSTIR"); + } +} + +#[derive(Component)] +struct PerformanceText; + +fn update_performance_text( + mut text: Single<&mut Text, With>, + diagnostics: Res, + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] dlss_camera: Query< + Has>, + With, + >, +) { + text.0.clear(); + + let mut total = 0.0; + let mut add_diagnostic = |name: &str, path: &'static str| { + let path = DiagnosticPath::new(path); + if let Some(value) = diagnostics.get(&path).and_then(Diagnostic::smoothed) { + text.push_str(&format!("{name:17} {value:.2} ms\n")); + total += value; + } + }; + + (add_diagnostic)( + "Light tiles", + "render/solari_lighting/presample_light_tiles/elapsed_gpu", + ); + (add_diagnostic)( + "World cache", + "render/solari_lighting/world_cache/elapsed_gpu", + ); + (add_diagnostic)("Lighting", "render/solari_lighting/lighting/elapsed_gpu"); + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + if matches!(dlss_camera.single(), Ok(true)) { + (add_diagnostic)("DLSS-RR", "render/dlss_ray_reconstruction/elapsed_gpu"); + } + text.push_str(&format!("{:17} {total:.2} ms\n", "Total")); + + if let Some(world_cache_active_cells_count) = diagnostics + .get(&DiagnosticPath::new( + "render/solari_lighting/world_cache_active_cells_count", + )) + .and_then(Diagnostic::smoothed) + { + text.push_str(&format!( + "\nWorld cache cells {} ({:.0}%)", + world_cache_active_cells_count as u32, + (world_cache_active_cells_count * 100.0) / (2u64.pow(20) as f64) + )); + } +} diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 0000000..07ade69 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..8266ced --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,68 @@ +#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")] +#![feature(portable_simd)] + +//! Provides raytraced lighting. +//! +//! See [`SolariPlugins`] for more info. +//! +//! ![`bevy_solari` logo](https://raw.githubusercontent.com/bevyengine/bevy/refs/heads/main/assets/branding/bevy_solari.svg) + +extern crate alloc; + +pub mod pathtracer; +pub mod realtime; +pub mod scene; + +/// The solari prelude. +/// +/// This includes the most common types in this crate, re-exported for your +/// convenience. +pub mod prelude { + pub use super::SolariPlugins; + pub use crate::{realtime::SolariLighting, scene::RaytracingMesh3d}; +} + +use bevy_app::{PluginGroup, PluginGroupBuilder}; +use bevy_render::settings::WgpuFeatures; + +use crate::{ + realtime::SolariLightingPlugin, + scene::{RaytracingScenePlugin, TapeAllocatorPlugin, TapePlugin, TapeRenderAssetPlugin}, +}; + +/// An experimental set of plugins for raytraced lighting. +/// +/// This plugin group provides: +/// * [`SolariLightingPlugin`] - Raytraced direct and indirect lighting. +/// * [`RaytracingScenePlugin`] - BLAS building, resource and lighting binding. +/// * [`TapeAllocatorPlugin`] - Handles Tape3d objects GPU side. +/// +/// There's also: +/// * [`pathtracer::PathtracingPlugin`] - A non-realtime pathtracer for +/// validation purposes (not added by default). +/// +/// To get started, add this plugin to your app, and then add `RaytracingMesh3d` +/// and `MeshMaterial3d::` to your entities. +pub struct SolariPlugins; + +impl PluginGroup for SolariPlugins { + fn build(self) -> PluginGroupBuilder { + PluginGroupBuilder::start::() + .add(TapePlugin) + .add(TapeRenderAssetPlugin::default()) + .add(TapeAllocatorPlugin) + .add(RaytracingScenePlugin) + .add(SolariLightingPlugin) + } +} + +impl SolariPlugins { + /// [`WgpuFeatures`] required for these plugins to function. + pub fn required_wgpu_features() -> WgpuFeatures { + WgpuFeatures::EXPERIMENTAL_RAY_QUERY + | WgpuFeatures::BUFFER_BINDING_ARRAY + | WgpuFeatures::TEXTURE_BINDING_ARRAY + | WgpuFeatures::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING + | WgpuFeatures::PARTIALLY_BOUND_BINDING_ARRAY + } +} diff --git a/src/pathtracer/extract.rs b/src/pathtracer/extract.rs new file mode 100644 index 0000000..19db4f3 --- /dev/null +++ b/src/pathtracer/extract.rs @@ -0,0 +1,36 @@ +use super::{prepare::PathtracerAccumulationTexture, Pathtracer}; +use bevy_camera::Camera; +use bevy_ecs::{ + change_detection::DetectChanges, + system::{Commands, Query}, + world::Ref, +}; +use bevy_render::{sync_world::RenderEntity, Extract}; +use bevy_transform::components::GlobalTransform; + +pub fn extract_pathtracer( + cameras_3d: Extract< + Query<( + RenderEntity, + &Camera, + Ref, + Option<&Pathtracer>, + )>, + >, + mut commands: Commands, +) { + for (entity, camera, global_transform, pathtracer) in &cameras_3d { + let mut entity_commands = commands + .get_entity(entity) + .expect("Camera entity wasn't synced."); + if let Some(pathtracer) = pathtracer + && camera.is_active + { + let mut pathtracer = pathtracer.clone(); + pathtracer.reset |= global_transform.is_changed(); + entity_commands.insert(pathtracer); + } else { + entity_commands.remove::<(Pathtracer, PathtracerAccumulationTexture)>(); + } + } +} diff --git a/src/pathtracer/mod.rs b/src/pathtracer/mod.rs new file mode 100644 index 0000000..7402135 --- /dev/null +++ b/src/pathtracer/mod.rs @@ -0,0 +1,72 @@ +mod extract; +mod node; +mod prepare; + +use crate::{scene::RaytracingSceneBindings, SolariPlugins}; +use bevy_app::{App, Plugin}; +use bevy_asset::embedded_asset; +use bevy_camera::Hdr; +use bevy_core_pipeline::{ + schedule::{Core3d, Core3dSystems}, + tonemapping::tonemapping, +}; +use bevy_ecs::{component::Component, reflect::ReflectComponent, schedule::IntoScheduleConfigs}; +use bevy_reflect::{std_traits::ReflectDefault, Reflect}; +use bevy_render::{ + init_gpu_resource, renderer::RenderDevice, ExtractSchedule, Render, RenderApp, RenderStartup, + RenderSystems, +}; +use extract::extract_pathtracer; +use node::{init_pathtracer_pipelines, pathtracer}; +use prepare::prepare_pathtracer_accumulation_texture; +use tracing::warn; + +/// Non-realtime pathtracing. +/// +/// This plugin is meant to generate reference screenshots to compare against, +/// and is not intended to be used by games. +pub struct PathtracingPlugin; + +impl Plugin for PathtracingPlugin { + fn build(&self, app: &mut App) { + embedded_asset!(app, "pathtracer.wesl"); + } + + fn finish(&self, app: &mut App) { + let render_app = app.sub_app_mut(RenderApp); + + let render_device = render_app.world().resource::(); + let features = render_device.features(); + if !features.contains(SolariPlugins::required_wgpu_features()) { + warn!( + "PathtracingPlugin not loaded. GPU lacks support for required features: {:?}.", + SolariPlugins::required_wgpu_features().difference(features) + ); + return; + } + + render_app + .add_systems( + RenderStartup, + init_pathtracer_pipelines.after(init_gpu_resource::), + ) + .add_systems(ExtractSchedule, extract_pathtracer) + .add_systems( + Render, + prepare_pathtracer_accumulation_texture.in_set(RenderSystems::PrepareResources), + ) + .add_systems( + Core3d, + pathtracer + .after(Core3dSystems::MainPass) + .before(tonemapping), + ); + } +} + +#[derive(Component, Reflect, Default, Clone)] +#[reflect(Component, Default, Clone)] +#[require(Hdr)] +pub struct Pathtracer { + pub reset: bool, +} diff --git a/src/pathtracer/node.rs b/src/pathtracer/node.rs new file mode 100644 index 0000000..be638b0 --- /dev/null +++ b/src/pathtracer/node.rs @@ -0,0 +1,118 @@ +use super::{prepare::PathtracerAccumulationTexture, Pathtracer}; +use crate::scene::RaytracingSceneBindings; +use bevy_asset::{load_embedded_asset, AssetServer}; +use bevy_ecs::{prelude::*, resource::Resource, system::Commands}; +use bevy_render::{ + camera::ExtractedCamera, + render_resource::{ + binding_types::{texture_storage_2d, uniform_buffer}, + BindGroupEntries, BindGroupLayoutDescriptor, BindGroupLayoutEntries, + CachedComputePipelineId, ComputePassDescriptor, ComputePipelineDescriptor, + ImageSubresourceRange, PipelineCache, ShaderStages, StorageTextureAccess, TextureFormat, + }, + renderer::{RenderContext, RenderDevice, ViewQuery}, + view::{ViewTarget, ViewUniform, ViewUniformOffset, ViewUniforms}, +}; +use bevy_utils::default; + +/// Resource holding the pathtracer pipeline configuration. +#[derive(Resource)] +pub struct PathtracerPipelines { + bind_group_layout: BindGroupLayoutDescriptor, + pipeline: CachedComputePipelineId, +} + +/// Initializes the pathtracer pipelines at render startup. +pub fn init_pathtracer_pipelines( + mut commands: Commands, + pipeline_cache: Res, + scene_bindings: Res, + asset_server: Res, +) { + let bind_group_layout = BindGroupLayoutDescriptor::new( + "pathtracer_bind_group_layout", + &BindGroupLayoutEntries::sequential( + ShaderStages::COMPUTE, + ( + texture_storage_2d(TextureFormat::Rgba32Float, StorageTextureAccess::ReadWrite), + texture_storage_2d(TextureFormat::Rgba16Float, StorageTextureAccess::WriteOnly), + uniform_buffer::(true), + ), + ), + ); + + let pipeline = pipeline_cache.queue_compute_pipeline(ComputePipelineDescriptor { + label: Some("pathtracer_pipeline".into()), + layout: vec![ + scene_bindings.bind_group_layout.clone(), + bind_group_layout.clone(), + ], + shader: load_embedded_asset!(asset_server.as_ref(), "pathtracer.wesl"), + ..default() + }); + + commands.insert_resource(PathtracerPipelines { + bind_group_layout, + pipeline, + }); +} + +pub fn pathtracer( + view: ViewQuery<( + &Pathtracer, + &PathtracerAccumulationTexture, + &ExtractedCamera, + &ViewTarget, + &ViewUniformOffset, + )>, + pathtracer_pipelines: Option>, + pipeline_cache: Res, + scene_bindings: Res, + view_uniforms: Res, + render_device: Res, + mut ctx: RenderContext, +) { + let (pathtracer_settings, accumulation_texture, camera, view_target, view_uniform_offset) = + view.into_inner(); + + let Some(pathtracer_pipelines) = pathtracer_pipelines else { + return; + }; + + let (Some(pipeline), Some(scene_bind_group), Some(viewport), Some(view_uniforms_binding)) = ( + pipeline_cache.get_compute_pipeline(pathtracer_pipelines.pipeline), + &scene_bindings.bind_group, + camera.physical_viewport_size, + view_uniforms.uniforms.binding(), + ) else { + return; + }; + + let bind_group = render_device.create_bind_group( + "pathtracer_bind_group", + &pipeline_cache.get_bind_group_layout(&pathtracer_pipelines.bind_group_layout), + &BindGroupEntries::sequential(( + &accumulation_texture.0.default_view, + view_target.get_unsampled_color_attachment().view, + view_uniforms_binding, + )), + ); + + let command_encoder = ctx.command_encoder(); + + if pathtracer_settings.reset { + command_encoder.clear_texture( + &accumulation_texture.0.texture, + &ImageSubresourceRange::default(), + ); + } + + let mut pass = command_encoder.begin_compute_pass(&ComputePassDescriptor { + label: Some("pathtracer"), + timestamp_writes: None, + }); + pass.set_pipeline(pipeline); + pass.set_bind_group(0, scene_bind_group, &[]); + pass.set_bind_group(1, &bind_group, &[view_uniform_offset.offset]); + pass.dispatch_workgroups(viewport.x.div_ceil(8), viewport.y.div_ceil(8), 1); +} diff --git a/src/pathtracer/pathtracer.wesl b/src/pathtracer/pathtracer.wesl new file mode 100644 index 0000000..c41d6ef --- /dev/null +++ b/src/pathtracer/pathtracer.wesl @@ -0,0 +1,100 @@ +import bevy_core_pipeline::tonemapping::tonemapping_luminance as luminance; +import bevy_pbr::render::utils::{rand_f, rand_vec2f}; +import bevy_render::view::View; +import package::scene::brdf::{evaluate_brdf, evaluate_and_sample_brdf, brdf_pdf, F_AB}; +import package::scene::sampling::{sample_random_light, random_emissive_light_pdf, power_heuristic, sample_environment_map_light}; +import package::scene::bindings::{trace_ray, resolve_ray_hit_full, RAY_T_MIN, RAY_T_MAX, MIRROR_ROUGHNESS_THRESHOLD}; + +enable wgpu_ray_query; + +@group(1) @binding(0) var accumulation_texture: texture_storage_2d; +@group(1) @binding(1) var view_output: texture_storage_2d; +@group(1) @binding(2) var view: View; + +@compute @workgroup_size(8, 8, 1) +fn pathtrace(@builtin(global_invocation_id) global_id: vec3) { + if any(global_id.xy >= vec2u(view.viewport.zw)) { + return; + } + + let old_color = textureLoad(accumulation_texture, global_id.xy); + + // Setup RNG + let pixel_index = global_id.x + global_id.y * u32(view.viewport.z); + let frame_index = u32(old_color.a) * 5782582u; + var rng = pixel_index + frame_index; + + // Shoot the first ray from the camera + let pixel_center = vec2(global_id.xy) + 0.5; + let jitter = rand_vec2f(&rng) - 0.5; + let pixel_uv = (pixel_center + jitter) / view.viewport.zw; + let pixel_ndc = (pixel_uv * 2.0) - 1.0; + let primary_ray_target = view.world_from_clip * vec4(pixel_ndc.x, -pixel_ndc.y, 1.0, 1.0); + var ray_origin = view.world_position; + var ray_direction = normalize((primary_ray_target.xyz / primary_ray_target.w) - ray_origin); + var ray_t_min = 0.0; + + // Path trace + var radiance = vec3(0.0); + var throughput = vec3(1.0); + var p_bounce = 0.0; + loop { + let ray = trace_ray(ray_origin, ray_direction, ray_t_min, RAY_T_MAX, RAY_FLAG_NONE); + if ray.kind != RAY_QUERY_INTERSECTION_NONE { + let ray_hit = resolve_ray_hit_full(ray); + let wo = -ray_direction; + let NdotV = max(dot(ray_hit.world_normal, wo), 0.0001); + let F_ab = F_AB(ray_hit.material.perceptual_roughness, NdotV); + + // Emissive contribution + var mis_weight = 1.0; + if p_bounce != 0.0 { // Not first bounce + let p_light = random_emissive_light_pdf(ray_hit, ray.t, NdotV); + mis_weight = power_heuristic(p_bounce, p_light); + } + if dot(ray_hit.world_normal, wo) > 0.0 { + radiance += mis_weight * throughput * ray_hit.material.emissive; + } + + // Sample direct lighting, but only if the surface is not mirror-like + let is_perfectly_specular = ray_hit.material.roughness <= MIRROR_ROUGHNESS_THRESHOLD && ray_hit.material.metallic > 0.9999; + if !is_perfectly_specular { + let direct_lighting = sample_random_light(ray_hit.world_position, ray_hit.world_normal, &rng); + + mis_weight = 1.0; + if direct_lighting.brdf_rays_can_hit { + let pdf_of_bounce = brdf_pdf(wo, direct_lighting.wi, ray_hit.world_normal, ray_hit.material, F_ab); + mis_weight = power_heuristic(1.0 / direct_lighting.inverse_solid_angle_pdf, pdf_of_bounce); + } + + let direct_lighting_brdf = evaluate_brdf(wo, direct_lighting.wi, ray_hit.world_normal, ray_hit.material, F_ab); + radiance += mis_weight * throughput * direct_lighting.radiance * direct_lighting.inverse_pdf * direct_lighting_brdf; + } + + // Sample new ray direction from the material BRDF for next bounce and apply BRDF + let next_bounce = evaluate_and_sample_brdf(wo, ray_hit.world_normal, ray_hit.material, F_ab, &rng); + if next_bounce.pdf == 0.0 { break; } + ray_direction = next_bounce.wi; + ray_origin = ray_hit.world_position + (ray_hit.geometric_world_normal * RAY_T_MIN); + ray_t_min = RAY_T_MIN; + p_bounce = next_bounce.pdf; + throughput *= next_bounce.throughput; + + // Russian roulette for early termination + let rr = saturate(luminance(throughput)); + if rand_f(&rng) >= rr { break; } + throughput /= rr; + } else { + radiance += throughput * sample_environment_map_light(ray_direction); + break; + } + } + + // Camera exposure + radiance *= view.exposure; + + // Accumulation over time via running average + let new_color = mix(old_color.rgb, radiance, 1.0 / (old_color.a + 1.0)); + textureStore(accumulation_texture, global_id.xy, vec4(new_color, old_color.a + 1.0)); + textureStore(view_output, global_id.xy, vec4(new_color, 1.0)); +} diff --git a/src/pathtracer/prepare.rs b/src/pathtracer/prepare.rs new file mode 100644 index 0000000..ddef965 --- /dev/null +++ b/src/pathtracer/prepare.rs @@ -0,0 +1,47 @@ +use super::Pathtracer; +use bevy_ecs::{ + component::Component, + entity::Entity, + query::With, + system::{Commands, Query, Res, ResMut}, +}; +use bevy_image::ToExtents; +use bevy_render::{ + camera::ExtractedCamera, + render_resource::{TextureDescriptor, TextureDimension, TextureFormat, TextureUsages}, + renderer::RenderDevice, + texture::{CachedTexture, TextureCache}, +}; + +#[derive(Component)] +pub struct PathtracerAccumulationTexture(pub CachedTexture); + +pub fn prepare_pathtracer_accumulation_texture( + query: Query<(Entity, &ExtractedCamera), With>, + mut texture_cache: ResMut, + render_device: Res, + mut commands: Commands, +) { + for (entity, camera) in &query { + let Some(viewport) = camera.physical_viewport_size else { + continue; + }; + + let descriptor = TextureDescriptor { + label: Some("pathtracer_accumulation_texture"), + size: viewport.to_extents(), + mip_level_count: 1, + sample_count: 1, + dimension: TextureDimension::D2, + format: TextureFormat::Rgba32Float, + usage: TextureUsages::STORAGE_BINDING, + view_formats: &[], + }; + + commands + .entity(entity) + .insert(PathtracerAccumulationTexture( + texture_cache.get(&render_device, descriptor), + )); + } +} diff --git a/src/realtime/bindings.wesl b/src/realtime/bindings.wesl new file mode 100644 index 0000000..86e83e8 --- /dev/null +++ b/src/realtime/bindings.wesl @@ -0,0 +1,113 @@ +import bevy_render::view::View; +import bevy_pbr::prepass::bindings::PreviousViewUniforms; +import package::scene::sampling::{LightSample, NULL_LIGHT_ID}; + +enable wgpu_ray_query; + +@group(1) @binding(0) var view_output: texture_storage_2d; +@group(1) @binding(1) var light_tile_samples: array; +@group(1) @binding(2) var light_tile_resolved_samples: array; +@group(1) @binding(3) var gbuffer: texture_2d; +@group(1) @binding(4) var depth_buffer: texture_depth_2d; +@if(MOTION_VECTORS_READ_WRITE) +@group(1) @binding(5) var motion_vectors: texture_storage_2d; +@if(!MOTION_VECTORS_READ_WRITE) +@group(1) @binding(5) var motion_vectors: texture_2d; +@group(1) @binding(6) var view: View; +@group(1) @binding(7) var previous_view: PreviousViewUniforms; +@group(1) @binding(8) var world_cache: WorldCache; +@group(1) @binding(9) var constants: SolariLightingSettings; + +@if(RESTIR) { +@group(1) @binding(10) var previous_gbuffer: texture_2d; +@group(1) @binding(11) var previous_depth_buffer: texture_depth_2d; +@group(1) @binding(12) var reservoirs_a: array; +@group(1) @binding(13) var reservoirs_b: array; +} + +@if(DLSS_RR_GUIDE_BUFFERS) { +@group(2) @binding(0) var diffuse_albedo: texture_storage_2d; +@group(2) @binding(1) var specular_albedo: texture_storage_2d; +@group(2) @binding(2) var normal_roughness: texture_storage_2d; +@group(2) @binding(3) var dlss_rr_depth: texture_storage_2d; +@group(2) @binding(4) var specular_motion_vectors: texture_storage_2d; +} + +fn load_motion_vector(pixel_id: vec2) -> vec2 { + @if(MOTION_VECTORS_READ_WRITE) + return textureLoad(motion_vectors, pixel_id).xy; + @if(!MOTION_VECTORS_READ_WRITE) + return textureLoad(motion_vectors, pixel_id, 0).xy; +} + +/// User-configurable settings from the `SolariLighting` component, plus per-frame +/// state. Field order and types must match `SolariLightingUniforms` in `prepare.rs`. +struct SolariLightingSettings { + confidence_weight_cap: f32, + primary_di_samples: u32, + secondary_di_samples: u32, + max_bounces: u32, + world_cache_max_temporal_samples: f32, + world_cache_direct_light_sample_count: u32, + world_cache_max_gi_ray_distance: f32, + world_cache_cell_updates_soft_target: u32, + world_cache_position_base_cell_size: f32, + world_cache_position_lod_scale: f32, + frame_rng: u32, + reset: u32, +} + +/// Don't adjust the size of this struct without also adjusting `prepare::RESOLVED_LIGHT_SAMPLE_STRUCT_SIZE`. +struct ResolvedLightSamplePacked { + world_position_x: f32, + world_position_y: f32, + world_position_z: f32, + world_normal: u32, + radiance: u32, + inverse_pdf: f32, +} + +/// Don't adjust the size of this struct without also adjusting `prepare::RESERVOIR_STRUCT_SIZE`. +struct Reservoir { + sample_point_world_position: vec3, + unbiased_contribution_weight: f32, + radiance: vec3, + confidence_weight: f32, + sample_point_world_normal: vec2, + light_sample: LightSample, +} + +fn empty_reservoir() -> Reservoir { + return Reservoir( + vec3(0.0), + 0.0, + vec3(0.0), + 0.0, + vec2(0.0), + LightSample(NULL_LIGHT_ID, 0u), + ); +} + +struct WorldCacheGeometryData { + world_position: vec3, + padding_a: u32, + world_normal: vec3, + padding_b: u32, +} + +/// Keep in sync with the packed world-cache layout constants in `prepare.rs`. +struct WorldCache { + checksums: array, constants::WORLD_CACHE_SIZE>, + @if(WORLD_CACHE_NON_ATOMIC_LIFE_BUFFER) + life: array, + @if(!WORLD_CACHE_NON_ATOMIC_LIFE_BUFFER) + life: array, constants::WORLD_CACHE_SIZE>, + radiance: array, constants::WORLD_CACHE_SIZE>, + geometry_data: array, + luminance_deltas: array, + active_cells_new_radiance: array, constants::WORLD_CACHE_SIZE>, + a: array, + b: array, + active_cell_indices: array, + active_cells_count: u32, +} diff --git a/src/realtime/extract.rs b/src/realtime/extract.rs new file mode 100644 index 0000000..d2c1212 --- /dev/null +++ b/src/realtime/extract.rs @@ -0,0 +1,27 @@ +use super::{prepare::SolariLightingResources, SolariLighting}; +use bevy_camera::Camera; +use bevy_ecs::system::{Commands, ResMut}; +use bevy_pbr::deferred::SkipDeferredLighting; +use bevy_render::{sync_world::RenderEntity, MainWorld}; + +pub fn extract_solari_lighting(mut main_world: ResMut, mut commands: Commands) { + let mut cameras_3d = main_world.query::<(RenderEntity, &Camera, Option<&mut SolariLighting>)>(); + + for (entity, camera, solari_lighting) in cameras_3d.iter_mut(&mut main_world) { + let mut entity_commands = commands + .get_entity(entity) + .expect("Camera entity wasn't synced."); + if let Some(mut solari_lighting) = solari_lighting + && camera.is_active + { + entity_commands.insert((solari_lighting.clone(), SkipDeferredLighting)); + solari_lighting.reset = false; + } else { + entity_commands.remove::<( + SolariLighting, + SolariLightingResources, + SkipDeferredLighting, + )>(); + } + } +} diff --git a/src/realtime/gbuffer_utils.wesl b/src/realtime/gbuffer_utils.wesl new file mode 100644 index 0000000..b6dceba --- /dev/null +++ b/src/realtime/gbuffer_utils.wesl @@ -0,0 +1,56 @@ +import bevy_pbr::deferred::types::unpack_24bit_normal; +import bevy_pbr::render::rgb9e5::rgb9e5_to_vec3_; +import bevy_render::utils::octahedral_decode; +import bevy_render::view::{View, depth_ndc_to_view_z}; +import package::scene::bindings::ResolvedMaterial; + +struct ResolvedGPixel { + world_position: vec3, + world_normal: vec3, + material: ResolvedMaterial, +} + +fn gpixel_resolve(gpixel: vec4, depth: f32, pixel_id: vec2, view_size: vec2, world_from_clip: mat4x4) -> ResolvedGPixel { + let world_position = reconstruct_world_position(pixel_id, depth, view_size, world_from_clip); + let world_normal = octahedral_decode(unpack_24bit_normal(gpixel.a)); + + let base_rough = unpack4x8unorm(gpixel.r); + let base_color = pow(base_rough.rgb, vec3(2.2)); + let perceptual_roughness = base_rough.a; + let roughness = perceptual_roughness * perceptual_roughness; + let props = unpack4x8unorm(gpixel.b); + let reflectance = props.r; + let metallic = props.g; + let emissive = rgb9e5_to_vec3_(gpixel.g); + let material = ResolvedMaterial(base_color, emissive, reflectance, perceptual_roughness, roughness, metallic); + + return ResolvedGPixel(world_position, world_normal, material); +} + +fn reconstruct_world_position(pixel_id: vec2, depth: f32, view_size: vec2, world_from_clip: mat4x4) -> vec3 { + let uv = (vec2(pixel_id) + 0.5) / view_size; + let xy_ndc = (uv - vec2(0.5)) * vec2(2.0, -2.0); + let world_pos = world_from_clip * vec4(xy_ndc, depth, 1.0); + return world_pos.xyz / world_pos.w; +} + +/// Reject if tangent plane differs more than 0.3% or angle between normals more than 90 degrees +fn pixel_dissimilar(depth: f32, world_position: vec3, other_world_position: vec3, normal: vec3, other_normal: vec3, view: View) -> bool { + // https://developer.download.nvidia.com/video/gputechconf/gtc/2020/presentations/s22699-fast-denoising-with-self-stabilizing-recurrent-blurs.pdf#page=45 + let tangent_plane_distance = abs(dot(normal, other_world_position - world_position)); + let view_z = -depth_ndc_to_view_z(depth, view.clip_from_view, view.view_from_clip); + + return tangent_plane_distance / view_z > 0.003 || dot(normal, other_normal) < 0.0; +} + +fn permute_pixel(pixel_id: vec2, frame_index: u32, view_size: vec2) -> vec2 { + let r = frame_index; + let offset = vec2(i32(r & 3u), i32((r >> 2u) & 3u)); + var shifted_pixel_id = vec2(pixel_id) + offset; + shifted_pixel_id ^= vec2(3); + shifted_pixel_id -= offset; + if any(shifted_pixel_id < vec2(0)) || any(shifted_pixel_id >= vec2(view_size)) { + return pixel_id; + } + return vec2(shifted_pixel_id); +} diff --git a/src/realtime/initial_path.wesl b/src/realtime/initial_path.wesl new file mode 100644 index 0000000..ee204a7 --- /dev/null +++ b/src/realtime/initial_path.wesl @@ -0,0 +1,492 @@ +import bevy_core_pipeline::tonemapping::tonemapping_luminance as luminance; +import bevy_pbr::render::utils::{rand_f, rand_range_u}; +import bevy_render::maths::PI; +import bevy_render::utils::octahedral_encode; +import package::scene::brdf::{brdf_pdf, evaluate_and_sample_brdf, evaluate_brdf, EvaluateAndSampleBrdfResult, F_AB}; +import package::realtime::presample_light_tiles::unpack_resolved_light_sample; +import package::realtime::bindings::{empty_reservoir, light_tile_resolved_samples, light_tile_samples, Reservoir, constants, view}; +import package::scene::sampling::{calculate_resolved_light_contribution, isinf, LightSample, NULL_LIGHT_ID, power_heuristic, trace_visibility, sample_environment_map_light}; +import package::scene::bindings::{light_sources, RAY_T_MAX, RAY_T_MIN, resolve_ray_hit_full, ResolvedMaterial, ResolvedRayHitFull, trace_ray}; +import package::realtime::world_cache_query::{get_cell_size, query_world_cache, WORLD_CACHE_CELL_LIFETIME}; + +@if(DLSS_RR_GUIDE_BUFFERS) +import package::realtime::resolve_dlss_rr_textures::{is_delta_mirror, primary_surface_glossy, psr_bounce_reflectance, psr_chain_mirror, psr_environment_miss, psr_init, replace_primary_surface}; + +enable wgpu_ray_query; + +const RECONNECTION_FOOTPRINT_KAPPA = 0.02; +const RECONNECTION_ROUGHNESS_MIN = 0.6; +const RECONNECTION_RELAX_DISTANCE = 1.0; + +const CACHE_TERMINATION_MIN_SOLID_ANGLE = PI; + +/// What tracing one path produced. +/// +/// `radiance` is shaded straight into the pixel. With ReSTIR the reservoir additionally carries the +/// candidate chosen for reuse, and `radiance` holds the radiance that can not be reused. +/// Without ReSTIR there is no reservoir and `radiance` is the entire estimate. +struct InitialSamplingResult { + @if(RESTIR) reservoir: Reservoir, + radiance: vec3, +} + +/// Path vertices use the following convention: x0 = camera, x1 = primary ray hit (the G-buffer +/// surface), x2 = first BRDF-sampled hit (the reconnection vertex). +struct PathState { + ray_origin: vec3, + normal: vec3, + wo: vec3, + material: ResolvedMaterial, + /// Throughput past x1. With ReSTIR the brdf*cos at x1 is factored out of it, see x1_brdf. + throughput_past_first_hit: vec3, + /// Reconnection vertex x2, the first BRDF-sampled hit shared by every length >= 2 candidate + @if(RESTIR) x2_position: vec3, + @if(RESTIR) x2_normal: vec3, + /// If false, candidates built on x2 are shaded directly into radiance instead of + /// published to the reservoir + @if(RESTIR) x2_reusable: bool, + /// brdf*cos at x1 for the direction toward x2, applied at shade time + @if(RESTIR) x1_brdf: vec3, + /// Radiance shaded directly at this pixel + radiance: vec3, + @if(RESTIR) reservoir: Reservoir, + @if(RESTIR) weight_sum: f32, + @if(RESTIR) selected_target_function: f32, +} + +fn new_path_state(world_position: vec3, world_normal: vec3, wo: vec3, material: ResolvedMaterial) -> PathState { + var path: PathState; + path.ray_origin = world_position + (world_normal * RAY_T_MIN); + path.normal = world_normal; + path.wo = wo; + path.material = material; + path.throughput_past_first_hit = vec3(1.0); + path.radiance = vec3(0.0); + @if(RESTIR) { + path.x1_brdf = vec3(0.0); + path.x2_position = vec3(0.0); + path.x2_normal = vec3(0.0); + path.x2_reusable = false; + path.reservoir = empty_reservoir(); + path.reservoir.confidence_weight = 1.0; + path.weight_sum = 0.0; + path.selected_target_function = 0.0; + } + return path; +} + +fn generate_initial_path(world_position: vec3, world_normal: vec3, material: ResolvedMaterial, workgroup_id: vec2, pixel_id: vec2, rng: ptr) -> InitialSamplingResult { + let wo = normalize(view.world_position - world_position); + let primary_NdotV = max(dot(world_normal, wo), 0.0001); + let primary_F_ab = F_AB(material.perceptual_roughness, primary_NdotV); + + var path = new_path_state(world_position, world_normal, wo, material); + + @if(DLSS_RR_GUIDE_BUFFERS) + var psr = psr_init(world_normal, material); + + for (var bounce = 0u; bounce < constants.max_bounces; bounce++) { + let NdotV = max(dot(path.normal, path.wo), 0.0001); + let F_ab = F_AB(path.material.perceptual_roughness, NdotV); + + // Stochastic NEE, with probability proportional to how diffuse the vertex is. Mirror-like + // metals have too narrow a lobe for NEE to help, so mostly skip it there and let + // BRDF-sampled emissive do the work. Pure dielectrics always run NEE. + let p_nee = mix(1.0, path.material.perceptual_roughness, path.material.metallic); + let di_samples = select(constants.secondary_di_samples, constants.primary_di_samples, bounce == 0u); + generate_nee_candidate(&path, F_ab, p_nee, di_samples, workgroup_id, bounce, rng); + + // Sample the BRDF and trace the next ray + let next_bounce = evaluate_and_sample_brdf(path.wo, path.normal, path.material, F_ab, rng); + if next_bounce.pdf == 0.0 { break; } + let ray = trace_ray(path.ray_origin, next_bounce.wi, RAY_T_MIN, RAY_T_MAX, RAY_FLAG_NONE); + + if ray.kind == RAY_QUERY_INTERSECTION_NONE { + @if(DLSS_RR_GUIDE_BUFFERS) + if !psr.finished && !next_bounce.diffuse_selected { + psr_environment_miss(pixel_id, wo); + } + + let environment_map_light_radiance = sample_environment_map_light(next_bounce.wi); + @if(RESTIR) { + generate_environment_map_light_candidate(&path, next_bounce, environment_map_light_radiance, primary_F_ab, bounce, rng); + } @else { + path.radiance += path.throughput_past_first_hit * next_bounce.throughput * environment_map_light_radiance; + } + + break; + } + + let ray_hit = resolve_ray_hit_full(ray); + let p_brdf = next_bounce.pdf; + + @if(DLSS_RR_GUIDE_BUFFERS) + if !psr.finished { + if next_bounce.diffuse_selected { + // Took the non-specular lobe, so not a mirror reflection. Keep the guide-buffer defaults. + psr.finished = true; + } else { + psr.throughput *= psr_bounce_reflectance(path.wo, next_bounce.wi, path.normal, path.material, F_ab, isinf(p_brdf)); + psr.reflection_length += ray.t; + + if !primary_surface_glossy(material) && is_delta_mirror(ray_hit.material) { + // Still in the mirror chain, fold this mirror's reflection into the chain. + psr = psr_chain_mirror(psr, ray_hit.world_normal); + } else { + psr.finished = true; + replace_primary_surface(pixel_id, psr, ray_hit, material, world_position, world_normal, wo, primary_F_ab); + } + } + } + + // Capture x2, the first BRDF-sampled hit + if bounce == 0u { + @if(RESTIR) { + path.x2_position = ray_hit.world_position; + path.x2_normal = ray_hit.world_normal; + + path.x1_brdf = evaluate_brdf(wo, next_bounce.wi, world_normal, material, primary_F_ab); + + path.x2_reusable = reconnection_reusable(ray.t, p_brdf, next_bounce.wi, next_bounce.diffuse_selected, ray_hit, world_position, material.perceptual_roughness, primary_NdotV); + + // The primary brdf*cos is applied at shade time, so divide it out of next_bounce.throughput + // to leave 1/pdf (or 1/specular_weight for mirrors, avoiding the 1/INF = 0 that would kill + // mirror GI). + path.throughput_past_first_hit *= next_bounce.throughput / max(path.x1_brdf, vec3(0.0001)); + } @else { + // Nothing is reused, so there is no shade-time reconnection to factor the primary + // brdf*cos out for. + path.throughput_past_first_hit *= next_bounce.throughput; + } + } else { + // Later bounces keep the full brdf*cos/pdf for L_at_reconnection. + path.throughput_past_first_hit *= next_bounce.throughput; + } + + // Resample emissive hits + if any(ray_hit.material.emissive > vec3(0.0)) && dot(ray_hit.world_normal, -next_bounce.wi) > 0.0 { + generate_emissive_candidate(&path, ray_hit, next_bounce.wi, p_brdf, ray.t, p_nee, di_samples, bounce, rng); + } + + // Try terminating into the world cache + if terminate_into_cache(&path, ray_hit, ray.t, p_brdf, bounce, rng) { + break; + } + + // Advance to the next vertex + path.ray_origin = ray_hit.world_position + (ray_hit.geometric_world_normal * RAY_T_MIN); + path.normal = ray_hit.world_normal; + path.wo = -next_bounce.wi; + path.material = ray_hit.material; + + // Russian roulette for early termination + if bounce > 0u { + // With ReSTIR, throughput_past_first_hit has the primary brdf*cos divided out (so it can be + // re-applied at shade time), which inflates it. Multiply x1_brdf back in to get the true + // energy-bounded path throughput, which is the correct quantity for the RR survival + // probability. Without ReSTIR it already is that quantity. + var full_throughput = path.throughput_past_first_hit; + @if(RESTIR) + full_throughput *= max(path.x1_brdf, vec3(0.0001)); + let rr = saturate(luminance(full_throughput)); + if rand_f(rng) >= rr { break; } + path.throughput_past_first_hit /= rr; + } + } + + var result: InitialSamplingResult; + result.radiance = path.radiance; + @if(RESTIR) { + if path.selected_target_function > 0.0 { + path.reservoir.unbiased_contribution_weight = path.weight_sum / path.selected_target_function; + } + result.reservoir = path.reservoir; + } + return result; +} + +fn generate_nee_candidate( + path: ptr, + F_ab: vec2, + p_nee: f32, + di_samples: u32, + workgroup_id: vec2, + bounce: u32, + rng: ptr, +) { + if rand_f(rng) >= p_nee { return; } + + let di = sample_light_ris((*path).ray_origin, (*path).normal, (*path).wo, (*path).material, F_ab, di_samples, workgroup_id, bounce, rng); + let di_target_function = luminance(di.brdf_radiance); + if di_target_function <= 0.0 { return; } + + // MIS against the BRDF strategy. RIS over N candidates makes the effective NEE pdf at the + // winner roughly N * light_pdf(winner), so scale by p_nee for the stochastic gate. + var nee_mis_weight = 1.0; + if di.brdf_rays_can_hit && di.inverse_solid_angle_pdf > 0.0 { + let p_nee_strategy = f32(di_samples) * (1.0 / di.inverse_solid_angle_pdf) * p_nee; + let p_brdf_at_nee = brdf_pdf((*path).wo, di.wi, (*path).normal, (*path).material, F_ab); + nee_mis_weight = power_heuristic(p_nee_strategy, p_brdf_at_nee); + } + + if bounce == 0u { + @if(RESTIR) { + // Bounce 0: Candidate is the light sample, stored by reference and re-resolved each frame + // nee_mis_weight goes into the target function since it gets recomputed per-pixel during reuse + let target_function = di_target_function * nee_mis_weight; + let resampling_weight = target_function * di.unbiased_contribution_weight / p_nee; + + (*path).weight_sum += resampling_weight; + if rand_f(rng) * (*path).weight_sum < resampling_weight { + (*path).reservoir.light_sample = di.light_sample; + (*path).selected_target_function = target_function; + } + } @else { + (*path).radiance += di.brdf_radiance * di.unbiased_contribution_weight * nee_mis_weight / p_nee; + } + } else { + // Deeper bounces: Candidate is the reconnection radiance at x2 + let L_at_reconnection = (*path).throughput_past_first_hit * di.brdf_radiance * di.unbiased_contribution_weight * nee_mis_weight / p_nee; + + @if(RESTIR) { + resample_reconnection_candidate(path, L_at_reconnection, rng); + } @else { + (*path).radiance += L_at_reconnection; + } + } +} + +struct DiSample { + unbiased_contribution_weight: f32, + light_sample: LightSample, + wi: vec3, + brdf_radiance: vec3, + inverse_solid_angle_pdf: f32, + brdf_rays_can_hit: bool, +} + +fn sample_light_ris(ray_origin: vec3, normal: vec3, wo: vec3, material: ResolvedMaterial, F_ab: vec2, di_samples: u32, workgroup_id: vec2, bounce: u32, rng: ptr) -> DiSample { + var workgroup_rng = (workgroup_id.x * 5782582u) + workgroup_id.y + bounce; + let light_tile_start = rand_range_u(128u, &workgroup_rng) * 1024u; + + var weight_sum = 0.0; + var selected_target_function = 0.0; + var selected_tile_sample = 0u; + var selected_world_position = vec4(0.0); + var selected_wi = vec3(0.0); + var selected_brdf_radiance = vec3(0.0); + var selected_inverse_solid_angle_pdf = 0.0; + var selected_brdf_rays_can_hit = false; + let mis_weight = 1.0 / f32(di_samples); + for (var i = 0u; i < di_samples; i++) { + let tile_sample = light_tile_start + rand_range_u(1024u, rng); + let resolved_light_sample = unpack_resolved_light_sample(light_tile_resolved_samples[tile_sample], view.exposure); + let light_contribution = calculate_resolved_light_contribution(resolved_light_sample, ray_origin, normal); + let brdf_current = evaluate_brdf(wo, light_contribution.wi, normal, material, F_ab); + let brdf_radiance = brdf_current * light_contribution.radiance; + + let target_function = luminance(brdf_radiance); + let resampling_weight = mis_weight * (target_function * light_contribution.inverse_pdf); + + weight_sum += resampling_weight; + + if rand_f(rng) * weight_sum < resampling_weight { + selected_target_function = target_function; + selected_tile_sample = tile_sample; + selected_world_position = resolved_light_sample.world_position; + selected_wi = light_contribution.wi; + selected_inverse_solid_angle_pdf = light_contribution.inverse_solid_angle_pdf; + selected_brdf_rays_can_hit = light_contribution.brdf_rays_can_hit; + selected_brdf_radiance = brdf_radiance; + } + } + + var unbiased_contribution_weight = 0.0; + if selected_target_function > 0.0 { + unbiased_contribution_weight = weight_sum / selected_target_function; + unbiased_contribution_weight *= trace_visibility(ray_origin, selected_world_position); + } + + return DiSample(unbiased_contribution_weight, light_tile_samples[selected_tile_sample], selected_wi, selected_brdf_radiance, selected_inverse_solid_angle_pdf, selected_brdf_rays_can_hit); +} + +fn generate_emissive_candidate( + path: ptr, + ray_hit: ResolvedRayHitFull, + wi: vec3, + p_brdf: f32, + ray_t: f32, + p_nee: f32, + di_samples: u32, + bounce: u32, + rng: ptr, +) { + let NdotV_hit = max(dot(ray_hit.world_normal, -wi), 0.0001); + let light_count = arrayLength(&light_sources); + let area_pdf = 1.0 / (f32(light_count) * f32(ray_hit.triangle_count) * ray_hit.triangle_area); + let p_light = area_pdf * ray_t * ray_t / NdotV_hit; + let emissive_mis_weight = power_heuristic(p_brdf, p_light * p_nee * f32(di_samples)); + + @if(RESTIR) { + if !(*path).x2_reusable { + // x1 -> x2 not reuse-safe (mirror/sharp lobe or failed gate): shade directly at this pixel + // instead of publishing, since a reuse shift would waste it or make a firefly. Mirror lobes + // always land here (p_brdf = INF, footprint 0), where emissive_mis_weight is 1. + (*path).radiance += (*path).x1_brdf * (*path).throughput_past_first_hit * ray_hit.material.emissive * emissive_mis_weight; + } else if bounce == 0u { + // Bounce 0: Candidate is the emissive hit + let target_function = luminance((*path).x1_brdf * ray_hit.material.emissive) * emissive_mis_weight; + let resampling_weight = luminance((*path).x1_brdf * (*path).throughput_past_first_hit * ray_hit.material.emissive) * emissive_mis_weight; + + (*path).weight_sum += resampling_weight; + if rand_f(rng) * (*path).weight_sum < resampling_weight { + (*path).reservoir.light_sample = LightSample(NULL_LIGHT_ID, bitcast(area_pdf)); + (*path).reservoir.sample_point_world_position = (*path).x2_position; + (*path).reservoir.sample_point_world_normal = octahedral_encode((*path).x2_normal); + (*path).reservoir.radiance = ray_hit.material.emissive; + (*path).selected_target_function = target_function; + } + } else { + // Deeper bounces: Candidate is the reconnection radiance at x2 + let emissive_L_at_reconnection = (*path).throughput_past_first_hit * ray_hit.material.emissive * emissive_mis_weight; + resample_reconnection_candidate(path, emissive_L_at_reconnection, rng); + } + } @else { + (*path).radiance += (*path).throughput_past_first_hit * ray_hit.material.emissive * emissive_mis_weight; + } +} + +@if(RESTIR) +fn generate_environment_map_light_candidate( + path: ptr, + next_bounce: EvaluateAndSampleBrdfResult, + environment_map_light_radiance: vec3, + primary_F_ab: vec2, + bounce: u32, + rng: ptr, +) { + if all(environment_map_light_radiance == vec3(0.0)) { return; } + + if bounce == 0u { + // Bounce 0: Candidate is the sky direction + if !x1_lobe_reusable(next_bounce.pdf, next_bounce.diffuse_selected, (*path).material.perceptual_roughness) { + (*path).radiance += next_bounce.throughput * environment_map_light_radiance; + return; + } + + // Publish the candidate as a point RAY_T_MAX along wi. + // Neighbors see almost the same direction, and the reconnection jacobian evaluates to ~1. + // + // TODO: Once the environment map light is a proper LightSource that we sample during NEE, + // store this as a LightSample instead. + let x1_brdf = evaluate_brdf((*path).wo, next_bounce.wi, (*path).normal, (*path).material, primary_F_ab); + let target_function = luminance(x1_brdf * environment_map_light_radiance); + let resampling_weight = luminance(next_bounce.throughput * environment_map_light_radiance); + + (*path).weight_sum += resampling_weight; + if rand_f(rng) * (*path).weight_sum < resampling_weight { + (*path).reservoir.light_sample = LightSample(NULL_LIGHT_ID, 0u); + (*path).reservoir.sample_point_world_position = (*path).ray_origin + next_bounce.wi * RAY_T_MAX; + (*path).reservoir.sample_point_world_normal = octahedral_encode(-next_bounce.wi); + (*path).reservoir.radiance = environment_map_light_radiance; + (*path).selected_target_function = target_function; + } + } else { + // Deeper bounces: Candidate is the reconnection radiance at x2 + let L_at_reconnection = (*path).throughput_past_first_hit * next_bounce.throughput * environment_map_light_radiance; + resample_reconnection_candidate(path, L_at_reconnection, rng); + } +} + +fn terminate_into_cache( + path: ptr, + ray_hit: ResolvedRayHitFull, + ray_t: f32, + p_brdf: f32, + bounce: u32, + rng: ptr, +) -> bool { + // Only terminate into the world cache when the bounce was from a wide-enough BRDF sample + // because the cache is less noisy than continuing the path for rough surfaces, + // but less accurate for smooth surfaces + let lobe_solid_angle = 1.0 / p_brdf; + let broad_enough_to_terminate = lobe_solid_angle >= CACHE_TERMINATION_MIN_SOLID_ANGLE; + let forced_terminate = bounce == constants.max_bounces - 1u; + if !(broad_enough_to_terminate || forced_terminate) { return false; } + + // Only use the cache when the ray cleared the cache cell (diagonal = sqrt(3) * cell_size). Short + // rays land in a cell that may straddle occluders and leak light through corners. + var rng_copy = *rng; + let world_cache_cell_size = get_cell_size(ray_hit.world_position, view.world_position, ray_t, &rng_copy); + if ray_t <= sqrt(3.0) * world_cache_cell_size { return false; } + + let cached_radiance = query_world_cache(ray_hit.world_position, ray_hit.geometric_world_normal, view.world_position, ray_t, WORLD_CACHE_CELL_LIFETIME, rng); + + let cache_outgoing = (ray_hit.material.base_color / PI) * cached_radiance; + let cache_L_at_reconnection = (*path).throughput_past_first_hit * cache_outgoing; + + @if(RESTIR) { + resample_reconnection_candidate(path, cache_L_at_reconnection, rng); + } @else { + (*path).radiance += cache_L_at_reconnection; + } + + return true; +} + +/// Resample radiance arriving at x1 through the reconnection vertex x2. `L_at_reconnection` excludes the +/// brdf*cos at x1, which is re-applied at shade time from whichever pixel ends up reusing the candidate. +@if(RESTIR) +fn resample_reconnection_candidate(path: ptr, L_at_reconnection: vec3, rng: ptr) { + if !(*path).x2_reusable { + // x1 -> x2 not reuse-safe: shade directly at this pixel instead of publishing. + (*path).radiance += (*path).x1_brdf * L_at_reconnection; + return; + } + + let target_function = luminance((*path).x1_brdf * L_at_reconnection); + let resampling_weight = target_function; + + (*path).weight_sum += resampling_weight; + if rand_f(rng) * (*path).weight_sum < resampling_weight { + (*path).reservoir.light_sample = LightSample(NULL_LIGHT_ID, 0u); + (*path).reservoir.sample_point_world_position = (*path).x2_position; + (*path).reservoir.sample_point_world_normal = octahedral_encode((*path).x2_normal); + (*path).reservoir.radiance = L_at_reconnection; + (*path).selected_target_function = target_function; + } +} + +/// ReSTIR PT Enhanced: Algorithmic Advances for Faster and More Robust ReSTIR Path Tracing +/// Section 4 (sorta) +/// https://research.nvidia.com/labs/rtr/publication/lin2026restirptenhanced/lin2026restirptenhanced.pdf +@if(RESTIR) +fn reconnection_reusable(ray_t: f32, p_brdf: f32, wi: vec3, diffuse_selected: bool, ray_hit: ResolvedRayHitFull, world_position: vec3, x1_perceptual_roughness: f32, primary_NdotV: f32) -> bool { + // ray_footprint = t^2 / (p_brdf * cos_x2) is the area a sample represents at x2. It goes to 0 for + // mirror lobes (p_brdf = INF) and shrinks for sharp lobes or short segments. Compared against a + // uniform 1/(4*PI) primary footprint, so the test trades roughness against distance. + let cos_x2 = max(dot(ray_hit.world_normal, -wi), 0.0001); + let ray_footprint = (ray_t * ray_t) / (p_brdf * cos_x2); + let primary_dist = length(view.world_position - world_position); + let primary_footprint = 4.0 * PI * primary_dist * primary_dist / primary_NdotV; + let footprint_ok = ray_footprint >= (RECONNECTION_FOOTPRINT_KAPPA / 100.0) * primary_footprint; + + let x1_lobe_ok = x1_lobe_reusable(p_brdf, diffuse_selected, x1_perceptual_roughness); + + // Guard at x2. A sharp reflector there makes the stored radiance view-dependent and wrong to + // reuse from a neighbor's direction. The roughness floor relaxes with segment length: a distant + // glossy x2 is seen by neighbors from nearly the same direction, so the view-dependence washes out. + // Diffuse, rough, and emissive vertices are always reuse-safe. + let x2_is_light = any(ray_hit.material.emissive > vec3(0.0)); + let x2_roughness = mix(1.0, ray_hit.material.perceptual_roughness, ray_hit.material.metallic); + let x2_roughness_floor = RECONNECTION_ROUGHNESS_MIN * saturate(RECONNECTION_RELAX_DISTANCE / ray_t); + let x2_end_ok = x2_is_light || x2_roughness >= x2_roughness_floor; + + return footprint_ok && x1_lobe_ok && x2_end_ok; +} + +/// Whether the lobe sampled at x1 is wide enough for its candidates to be reused by neighbors. +@if(RESTIR) +fn x1_lobe_reusable(p_brdf: f32, diffuse_selected: bool, x1_perceptual_roughness: f32) -> bool { + return !isinf(p_brdf) && (diffuse_selected || x1_perceptual_roughness >= RECONNECTION_ROUGHNESS_MIN); +} diff --git a/src/realtime/mod.rs b/src/realtime/mod.rs new file mode 100644 index 0000000..7300f81 --- /dev/null +++ b/src/realtime/mod.rs @@ -0,0 +1,267 @@ +mod extract; +mod node; +mod prepare; + +use crate::{ + scene::{prepare_raytracing_scene_resources, RaytracingSceneBindings}, + SolariPlugins, +}; +use bevy_app::{App, Plugin, PostUpdate}; +use bevy_asset::embedded_asset; +use bevy_camera::Hdr; +use bevy_core_pipeline::{ + core_3d::main_opaque_pass_3d, + prepass::{ + DeferredPrepass, DeferredPrepassDoubleBuffer, DepthPrepass, DepthPrepassDoubleBuffer, + MotionVectorPrepass, + }, + schedule::{Core3d, Core3dSystems}, +}; +use bevy_ecs::{ + component::Component, + entity::Entity, + query::Has, + reflect::ReflectComponent, + schedule::IntoScheduleConfigs, + system::{Commands, Query}, +}; +use bevy_pbr::DefaultOpaqueRendererMethod; +use bevy_reflect::{std_traits::ReflectDefault, Reflect}; +use bevy_render::{ + init_gpu_resource, renderer::RenderDevice, ExtractSchedule, Render, RenderApp, RenderStartup, + RenderSystems, +}; +use bevy_shader::load_shader_library; +use extract::extract_solari_lighting; +use node::{init_solari_lighting_pipelines, solari_lighting}; +use prepare::{ + prepare_solari_lighting_resources, setup_raytracing_scene_needs_previous_frame_data, +}; +use tracing::warn; + +/// Raytraced direct and indirect lighting. +/// +/// When using this plugin, it's highly recommended to set `shadow_maps_enabled: false` on all lights, as Solari replaces +/// traditional shadow mapping. +pub struct SolariLightingPlugin; + +impl Plugin for SolariLightingPlugin { + fn build(&self, app: &mut App) { + load_shader_library!(app, "gbuffer_utils.wesl"); + load_shader_library!(app, "bindings.wesl"); + load_shader_library!(app, "presample_light_tiles.wesl"); + load_shader_library!(app, "initial_path.wesl"); + embedded_asset!(app, "restir.wesl"); + embedded_asset!(app, "no_restir.wesl"); + load_shader_library!(app, "world_cache_query.wesl"); + embedded_asset!(app, "world_cache_compact.wesl"); + embedded_asset!(app, "world_cache_update.wesl"); + + load_shader_library!(app, "resolve_dlss_rr_textures.wesl"); + + app.insert_resource(DefaultOpaqueRendererMethod::deferred()); + } + + fn finish(&self, app: &mut App) { + let features = app + .sub_app(RenderApp) + .world() + .resource::() + .features(); + if !features.contains(SolariPlugins::required_wgpu_features()) { + warn!( + "SolariLightingPlugin not loaded. GPU lacks support for required features: {:?}.", + SolariPlugins::required_wgpu_features().difference(features) + ); + return; + } + + app.add_systems(PostUpdate, manage_prepass_double_buffers); + + app.sub_app_mut(RenderApp) + .add_systems( + RenderStartup, + init_solari_lighting_pipelines.after(init_gpu_resource::), + ) + .add_systems(ExtractSchedule, extract_solari_lighting) + .add_systems( + Render, + ( + prepare_solari_lighting_resources, + setup_raytracing_scene_needs_previous_frame_data + .before(prepare_raytracing_scene_resources), + ) + .in_set(RenderSystems::PrepareResources), + ) + .add_systems( + Core3d, + solari_lighting + .before(main_opaque_pass_3d) + .in_set(Core3dSystems::MainPass), + ); + } +} + +/// A component for a 3d camera entity to enable the Solari raytraced lighting system. +/// +/// Must be used with `CameraMainTextureUsages::default().with(TextureUsages::STORAGE_BINDING)`, and +/// `Msaa::Off`. +#[derive(Component, Reflect, Clone)] +#[reflect(Component, Default, Clone)] +#[require(Hdr, DeferredPrepass, DepthPrepass, MotionVectorPrepass)] +pub struct SolariLighting { + /// [ReSTIR](https://en.wikipedia.org/wiki/Spatiotemporal_reservoir_resampling) is a technique to reuse path samples + /// between pixels and frames. This dramatically reduces noise, at the cost of a few extra rays per pixel. + /// + /// However, modern denoisers cope well with very noisy input. In many cases, turning this on + /// won't dramatically improve quality after denoising. + /// + /// If you want more fine shadow detail, or have scenes with more difficult lighting conditions, + /// turning this on may improve quality and stability, at the cost of a decent chunk of performance. + /// + /// Whether to enable this setting or not will be very scene dependent. + /// + /// Defaults to `false`. + pub restir: bool, + + /// Maximum confidence weight (effective temporal history length) a pixel + /// can accumulate during temporal resampling. + /// + /// Has no effect when [`SolariLighting::restir`] is `false`. + /// + /// Higher values are more stable but slower to react to lighting changes + /// and will lead to increased artifacts. + pub confidence_weight_cap: f32, + + /// Number of direct light samples taken for the camera's primary hit during + /// initial sampling. + /// + /// Higher values reduce noise in directly-lit areas at the cost of more work + /// per frame. Lower values are faster but noisier. + pub primary_di_samples: u32, + + /// Number of direct light samples taken at each indirect bounce during + /// initial sampling. + /// + /// Higher values reduce noise in indirect lighting at the cost of more work + /// per frame. Lower values are faster but noisier. + pub secondary_di_samples: u32, + + /// Maximum number of bounces traced when generating an initial path. + /// + /// Higher values capture more detail in nested reflections and more indirect lighting, + /// at the cost of more rays traced per frame. Lower values are faster but lose + /// multi-bounce lighting for specular paths. + pub max_bounces: u32, + + /// How responsive the world cache is to changes in lighting. + /// + /// Higher values accumulate more temporal history, giving more stable but + /// less responsive (slower to update) lighting. Lower values react faster + /// but are noisier and less stable. + pub world_cache_max_temporal_samples: f32, + + /// How many direct light samples each world cache cell takes when updating + /// each frame. + /// + /// Higher values reduce noise in cached lighting at the cost of more work + /// per frame. Lower values are faster but noisier. + pub world_cache_direct_light_sample_count: u32, + + /// Maximum distance to trace GI rays between two world cache cells. + /// + /// Higher values capture indirect light from farther away for more accurate + /// GI at the cost of longer (more expensive) ray traversal and increased noise. + /// Lower values are faster and less noisy but may miss distant lighting or leak sky lighting. + /// + /// Rays that miss within this distance are treated as reaching the environment + /// map light, and leak sky lighting into the cache. + pub world_cache_max_gi_ray_distance: f32, + + /// Soft upper limit on the number of world cache cells to update each frame. + /// + /// Higher values let the cache converge faster after lighting changes at the + /// cost of more work per frame. Lower values are cheaper but make the cache + /// slower to update. + /// + /// This is a stochastic target that only takes effect when the number of + /// active cells exceeds it: each active cell is then updated with + /// probability `target / active_cells`, so on average this many cells + /// update, though individual frames may update more or fewer. When there + /// are fewer active cells than the target, all of them update every frame. + pub world_cache_cell_updates_soft_target: u32, + + /// Size of a world cache cell at the lowest LOD, in meters. + /// + /// Smaller values give finer spatial resolution and more detailed indirect + /// lighting at the cost of more cells to fill and update. Larger values are + /// cheaper but coarser, which can cause light leaking. + pub world_cache_position_base_cell_size: f32, + + /// How fast the world cache transitions between LODs as a function of + /// distance to the camera. + /// + /// Higher values keep cells small (high detail) out to greater distances for + /// better quality at the cost of more cells to fill. Lower values transition + /// to larger cells sooner, which is cheaper but coarser farther from the + /// camera. + pub world_cache_position_lod_scale: f32, + + /// Set to true to delete the saved temporal history (past frames). + /// + /// Useful for preventing ghosting when the history is no longer + /// representative of the current frame, such as in sudden camera cuts. + /// + /// After setting this to true, it will automatically be toggled + /// back to false at the end of the frame. + pub reset: bool, +} + +impl Default for SolariLighting { + fn default() -> Self { + Self { + restir: false, + confidence_weight_cap: 8.0, + primary_di_samples: 8, + secondary_di_samples: 4, + max_bounces: 3, + world_cache_max_temporal_samples: 32.0, + world_cache_direct_light_sample_count: 32, + world_cache_max_gi_ray_distance: 50.0, + world_cache_cell_updates_soft_target: 40000, + world_cache_position_base_cell_size: 0.15, + world_cache_position_lod_scale: 15.0, + reset: true, // No temporal history on the first frame + } + } +} + +/// Adds or removes the prepass double-buffer components according to [`SolariLighting::restir`]. +fn manage_prepass_double_buffers( + views: Query<( + Entity, + &SolariLighting, + Has, + Has, + )>, + mut commands: Commands, +) { + for (entity, solari_lighting, deferred_double_buffered, depth_double_buffered) in &views { + let mut entity = commands.entity(entity); + if solari_lighting.restir { + if !deferred_double_buffered { + entity.insert(DeferredPrepassDoubleBuffer); + } + if !depth_double_buffered { + entity.insert(DepthPrepassDoubleBuffer); + } + } else { + if deferred_double_buffered { + entity.remove::(); + } + if depth_double_buffered { + entity.remove::(); + } + } + } +} diff --git a/src/realtime/no_restir.wesl b/src/realtime/no_restir.wesl new file mode 100644 index 0000000..f15fcd0 --- /dev/null +++ b/src/realtime/no_restir.wesl @@ -0,0 +1,30 @@ +import package::realtime::gbuffer_utils::gpixel_resolve; +import package::realtime::initial_path::generate_initial_path; +import package::realtime::bindings::{constants, depth_buffer, gbuffer, view, view_output}; +import package::scene::bindings::RAY_T_MAX; +import package::realtime::world_cache_query::{query_world_cache, WORLD_CACHE_CELL_LIFETIME}; + +enable wgpu_ray_query; + +@compute @workgroup_size(8, 8, 1) +fn initial_and_shade(@builtin(workgroup_id) workgroup_id: vec3, @builtin(global_invocation_id) global_id: vec3) { + if any(global_id.xy >= vec2u(view.main_pass_viewport.zw)) { return; } + + let pixel_index = global_id.x + global_id.y * u32(view.main_pass_viewport.z); + var rng = pixel_index + constants.frame_rng; + + let depth = textureLoad(depth_buffer, global_id.xy, 0); + if depth == 0.0 { return; } + + let surface = gpixel_resolve(textureLoad(gbuffer, global_id.xy, 0), depth, global_id.xy, view.main_pass_viewport.zw, view.world_from_clip); + + let path = generate_initial_path(surface.world_position, surface.world_normal, surface.material, workgroup_id.xy, global_id.xy, &rng); + + var pixel_color = path.radiance; + pixel_color += surface.material.emissive; + pixel_color *= view.exposure; + textureStore(view_output, global_id.xy, vec4(pixel_color, 1.0)); + + @if(VISUALIZE_WORLD_CACHE) + textureStore(view_output, global_id.xy, vec4(query_world_cache(surface.world_position, surface.world_normal, view.world_position, RAY_T_MAX, WORLD_CACHE_CELL_LIFETIME, &rng) * view.exposure, 1.0)); +} diff --git a/src/realtime/node.rs b/src/realtime/node.rs new file mode 100644 index 0000000..7c2ee5e --- /dev/null +++ b/src/realtime/node.rs @@ -0,0 +1,670 @@ +use super::prepare::{ + SolariLightingResources, LIGHT_TILE_BLOCKS, WORLD_CACHE_ACTIVE_CELLS_COUNT_OFFSET, + WORLD_CACHE_SIZE, +}; +use crate::scene::RaytracingSceneBindings; +#[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] +use bevy_anti_alias::dlss::ViewDlssRayReconstructionTextures; +use bevy_asset::{load_embedded_asset, AssetServer, Handle}; +use bevy_core_pipeline::prepass::{ + PreviousViewData, PreviousViewUniformOffset, PreviousViewUniforms, ViewPrepassTextures, + MOTION_VECTOR_PREPASS_FORMAT, +}; +use bevy_ecs::{prelude::*, resource::Resource, system::Commands}; +use bevy_render::{ + diagnostic::RecordDiagnostics as _, + render_resource::{ + binding_types::{ + storage_buffer_sized, texture_2d, texture_depth_2d, texture_storage_2d, uniform_buffer, + uniform_buffer_sized, + }, + BindGroupEntries, BindGroupLayoutDescriptor, BindGroupLayoutEntries, + CachedComputePipelineId, ComputePassDescriptor, ComputePipelineDescriptor, LoadOp, + PipelineCache, RenderPassDescriptor, ShaderStages, StorageTextureAccess, TextureFormat, + TextureFormatFeatureFlags, TextureSampleType, + }, + renderer::{RenderAdapter, RenderContext, RenderDevice, ViewQuery}, + view::{ViewTarget, ViewUniform, ViewUniformOffset, ViewUniforms}, +}; +use bevy_shader::{Shader, ShaderDefVal}; +use bevy_utils::default; + +/// Resource holding the Solari lighting pipeline configuration. +#[derive(Resource)] +pub struct SolariLightingPipelines { + bind_group_layout: BindGroupLayoutDescriptor, + bind_group_layout_restir: BindGroupLayoutDescriptor, + bind_group_layout_world_cache_active_cells_dispatch: BindGroupLayoutDescriptor, + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + bind_group_layout_resolve_dlss_rr_textures: BindGroupLayoutDescriptor, + decay_world_cache_pipeline: CachedComputePipelineId, + compact_world_cache_single_block_pipeline: CachedComputePipelineId, + compact_world_cache_blocks_pipeline: CachedComputePipelineId, + compact_world_cache_write_active_cells_pipeline: CachedComputePipelineId, + sample_di_for_world_cache_pipeline: CachedComputePipelineId, + sample_gi_for_world_cache_pipeline: CachedComputePipelineId, + blend_new_world_cache_samples_pipeline: CachedComputePipelineId, + presample_light_tiles_pipeline: CachedComputePipelineId, + restir: RestirPipelines, + no_restir: NoRestirPipelines, + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + resolve_dlss_rr_textures_pipeline: CachedComputePipelineId, +} + +struct RestirPipelines { + initial_and_temporal: CachedComputePipelineId, + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + initial_and_temporal_with_psr: CachedComputePipelineId, + spatial_and_shade: CachedComputePipelineId, +} + +struct NoRestirPipelines { + initial_and_shade: CachedComputePipelineId, + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + initial_and_shade_with_psr: CachedComputePipelineId, +} + +#[cfg(any(not(feature = "dlss"), feature = "force_disable_dlss"))] +type SolariLightingViewQuery = ( + &'static SolariLightingResources, + &'static ViewTarget, + &'static ViewPrepassTextures, + &'static ViewUniformOffset, + &'static PreviousViewUniformOffset, +); + +#[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] +type SolariLightingViewQuery = ( + &'static SolariLightingResources, + &'static ViewTarget, + &'static ViewPrepassTextures, + &'static ViewUniformOffset, + &'static PreviousViewUniformOffset, + Option<&'static ViewDlssRayReconstructionTextures>, +); + +pub fn solari_lighting( + view: ViewQuery, + solari_pipelines: Option>, + pipeline_cache: Res, + scene_bindings: Res, + view_uniforms: Res, + previous_view_uniforms: Res, + render_device: Res, + mut ctx: RenderContext, +) { + #[cfg(any(not(feature = "dlss"), feature = "force_disable_dlss"))] + let ( + solari_lighting_resources, + view_target, + view_prepass_textures, + view_uniform_offset, + previous_view_uniform_offset, + ) = view.into_inner(); + + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + let ( + solari_lighting_resources, + view_target, + view_prepass_textures, + view_uniform_offset, + previous_view_uniform_offset, + view_dlss_rr_textures, + ) = view.into_inner(); + + let Some(pipelines) = solari_pipelines else { + return; + }; + + let restir = solari_lighting_resources.reservoirs.as_ref().zip( + view_prepass_textures + .previous_deferred_view() + .zip(view_prepass_textures.previous_depth_only_view()), + ); + + #[cfg(any(not(feature = "dlss"), feature = "force_disable_dlss"))] + let (initial_pipeline_id, spatial_pipeline_id) = if restir.is_some() { + ( + pipelines.restir.initial_and_temporal, + Some(pipelines.restir.spatial_and_shade), + ) + } else { + (pipelines.no_restir.initial_and_shade, None) + }; + + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + let (initial_pipeline_id, spatial_pipeline_id) = + match (restir.is_some(), view_dlss_rr_textures.is_some()) { + (true, true) => ( + pipelines.restir.initial_and_temporal_with_psr, + Some(pipelines.restir.spatial_and_shade), + ), + (true, false) => ( + pipelines.restir.initial_and_temporal, + Some(pipelines.restir.spatial_and_shade), + ), + (false, true) => (pipelines.no_restir.initial_and_shade_with_psr, None), + (false, false) => (pipelines.no_restir.initial_and_shade, None), + }; + + let ( + Some(decay_world_cache_pipeline), + Some(compact_world_cache_single_block_pipeline), + Some(compact_world_cache_blocks_pipeline), + Some(compact_world_cache_write_active_cells_pipeline), + Some(sample_di_for_world_cache_pipeline), + Some(sample_gi_for_world_cache_pipeline), + Some(blend_new_world_cache_samples_pipeline), + Some(presample_light_tiles_pipeline), + Some(initial_pipeline), + Some(scene_bind_group), + Some(gbuffer), + Some(depth_buffer), + Some(motion_vectors), + Some(view_uniforms_binding), + Some(previous_view_uniforms_binding), + ) = ( + pipeline_cache.get_compute_pipeline(pipelines.decay_world_cache_pipeline), + pipeline_cache.get_compute_pipeline(pipelines.compact_world_cache_single_block_pipeline), + pipeline_cache.get_compute_pipeline(pipelines.compact_world_cache_blocks_pipeline), + pipeline_cache + .get_compute_pipeline(pipelines.compact_world_cache_write_active_cells_pipeline), + pipeline_cache.get_compute_pipeline(pipelines.sample_di_for_world_cache_pipeline), + pipeline_cache.get_compute_pipeline(pipelines.sample_gi_for_world_cache_pipeline), + pipeline_cache.get_compute_pipeline(pipelines.blend_new_world_cache_samples_pipeline), + pipeline_cache.get_compute_pipeline(pipelines.presample_light_tiles_pipeline), + pipeline_cache.get_compute_pipeline(initial_pipeline_id), + &scene_bindings.bind_group, + view_prepass_textures.deferred_view(), + view_prepass_textures.depth_only_view(), + view_prepass_textures.motion_vectors_view(), + view_uniforms.uniforms.binding(), + previous_view_uniforms.uniforms.binding(), + ) + else { + return; + }; + + let spatial_and_shade_pipeline = match spatial_pipeline_id { + Some(id) => match pipeline_cache.get_compute_pipeline(id) { + None => return, + pipeline => pipeline, + }, + None => None, + }; + + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + let Some(resolve_dlss_rr_textures_pipeline) = + pipeline_cache.get_compute_pipeline(pipelines.resolve_dlss_rr_textures_pipeline) + else { + return; + }; + + // Past every bail-out, so this view's reservoirs will be brought up to this frame's light ids + if restir.is_some() { + scene_bindings.note_light_translations_consumed(); + } + + let view_target_attachment = view_target.get_unsampled_color_attachment(); + + let s = solari_lighting_resources; + let bind_group = render_device.create_bind_group( + "solari_lighting_bind_group", + &pipeline_cache.get_bind_group_layout(&pipelines.bind_group_layout), + &BindGroupEntries::sequential(( + view_target_attachment.view, + s.light_tile_samples.as_entire_binding(), + s.light_tile_resolved_samples.as_entire_binding(), + gbuffer, + depth_buffer, + motion_vectors, + view_uniforms_binding.clone(), + previous_view_uniforms_binding.clone(), + s.world_cache.as_entire_binding(), + s.constants.as_entire_binding(), + )), + ); + + let bind_group_restir = + restir.map(|(reservoirs, (previous_gbuffer, previous_depth_buffer))| { + render_device.create_bind_group( + "solari_lighting_bind_group_restir", + &pipeline_cache.get_bind_group_layout(&pipelines.bind_group_layout_restir), + &BindGroupEntries::sequential(( + view_target_attachment.view, + s.light_tile_samples.as_entire_binding(), + s.light_tile_resolved_samples.as_entire_binding(), + gbuffer, + depth_buffer, + motion_vectors, + view_uniforms_binding, + previous_view_uniforms_binding, + s.world_cache.as_entire_binding(), + s.constants.as_entire_binding(), + previous_gbuffer, + previous_depth_buffer, + reservoirs.a.as_entire_binding(), + reservoirs.b.as_entire_binding(), + )), + ) + }); + + let bind_group_world_cache_active_cells_dispatch = render_device.create_bind_group( + "solari_lighting_bind_group_world_cache_active_cells_dispatch", + &pipeline_cache + .get_bind_group_layout(&pipelines.bind_group_layout_world_cache_active_cells_dispatch), + &BindGroupEntries::single(s.world_cache_active_cells_dispatch.as_entire_binding()), + ); + + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + let bind_group_resolve_dlss_rr_textures = view_dlss_rr_textures.map(|d| { + render_device.create_bind_group( + "solari_lighting_bind_group_resolve_dlss_rr_textures", + &pipeline_cache + .get_bind_group_layout(&pipelines.bind_group_layout_resolve_dlss_rr_textures), + &BindGroupEntries::sequential(( + &d.diffuse_albedo.default_view, + &d.specular_albedo.default_view, + &d.normal_roughness.default_view, + &d.depth.default_view, + &d.specular_motion_vectors.default_view, + )), + ) + }); + + let diagnostics = ctx.diagnostic_recorder(); + let diagnostics = diagnostics.as_deref(); + + let command_encoder = ctx.command_encoder(); + + // Clear the view target if we're the first node to write to it + if matches!(view_target_attachment.ops.load, LoadOp::Clear(_)) { + command_encoder.begin_render_pass(&RenderPassDescriptor { + label: Some("solari_lighting_clear"), + color_attachments: &[Some(view_target_attachment)], + depth_stencil_attachment: None, + timestamp_writes: None, + occlusion_query_set: None, + multiview_mask: None, + }); + } + + let mut pass = command_encoder.begin_compute_pass(&ComputePassDescriptor { + label: Some("solari_lighting"), + timestamp_writes: None, + }); + + let dx = solari_lighting_resources.view_size.x.div_ceil(8); + let dy = solari_lighting_resources.view_size.y.div_ceil(8); + + pass.set_bind_group(0, scene_bind_group, &[]); + pass.set_bind_group( + 1, + &bind_group, + &[ + view_uniform_offset.offset, + previous_view_uniform_offset.offset, + ], + ); + + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + if let Some(bind_group_resolve_dlss_rr_textures) = &bind_group_resolve_dlss_rr_textures { + pass.set_bind_group(2, bind_group_resolve_dlss_rr_textures, &[]); + pass.set_pipeline(resolve_dlss_rr_textures_pipeline); + pass.dispatch_workgroups(dx, dy, 1); + } + + let d = diagnostics.time_span(&mut pass, "solari_lighting/presample_light_tiles"); + pass.set_pipeline(presample_light_tiles_pipeline); + pass.dispatch_workgroups(LIGHT_TILE_BLOCKS as u32, 1, 1); + d.end(&mut pass); + + let d = diagnostics.time_span(&mut pass, "solari_lighting/world_cache"); + + pass.set_bind_group(2, &bind_group_world_cache_active_cells_dispatch, &[]); + + pass.set_pipeline(decay_world_cache_pipeline); + pass.dispatch_workgroups((WORLD_CACHE_SIZE / 1024) as u32, 1, 1); + + pass.set_pipeline(compact_world_cache_single_block_pipeline); + pass.dispatch_workgroups((WORLD_CACHE_SIZE / 1024) as u32, 1, 1); + + pass.set_pipeline(compact_world_cache_blocks_pipeline); + pass.dispatch_workgroups(1, 1, 1); + + pass.set_pipeline(compact_world_cache_write_active_cells_pipeline); + pass.dispatch_workgroups((WORLD_CACHE_SIZE / 1024) as u32, 1, 1); + + pass.set_bind_group(2, None, &[]); + + pass.set_pipeline(sample_di_for_world_cache_pipeline); + pass.dispatch_workgroups_indirect( + &solari_lighting_resources.world_cache_active_cells_dispatch, + 0, + ); + + pass.set_pipeline(sample_gi_for_world_cache_pipeline); + pass.dispatch_workgroups_indirect( + &solari_lighting_resources.world_cache_active_cells_dispatch, + 0, + ); + + pass.set_pipeline(blend_new_world_cache_samples_pipeline); + pass.dispatch_workgroups_indirect( + &solari_lighting_resources.world_cache_active_cells_dispatch, + 0, + ); + + d.end(&mut pass); + + let d = diagnostics.time_span(&mut pass, "solari_lighting/lighting"); + + if let Some(bind_group_restir) = &bind_group_restir { + pass.set_bind_group( + 1, + bind_group_restir, + &[ + view_uniform_offset.offset, + previous_view_uniform_offset.offset, + ], + ); + } + + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + if let Some(bind_group_resolve_dlss_rr_textures) = &bind_group_resolve_dlss_rr_textures { + pass.set_bind_group(2, bind_group_resolve_dlss_rr_textures, &[]); + } + pass.set_pipeline(initial_pipeline); + pass.dispatch_workgroups(dx, dy, 1); + + if let Some(spatial_and_shade_pipeline) = spatial_and_shade_pipeline { + pass.set_pipeline(spatial_and_shade_pipeline); + pass.dispatch_workgroups(dx, dy, 1); + } + + d.end(&mut pass); + + drop(pass); + + // Active cell count readback. + diagnostics.record_u32( + ctx.command_encoder(), + &s.world_cache.slice( + WORLD_CACHE_ACTIVE_CELLS_COUNT_OFFSET + ..WORLD_CACHE_ACTIVE_CELLS_COUNT_OFFSET + size_of::() as u64, + ), + "solari_lighting/world_cache_active_cells_count", + ); +} + +/// Initializes the Solari lighting pipelines at render startup. +pub fn init_solari_lighting_pipelines( + mut commands: Commands, + pipeline_cache: Res, + scene_bindings: Res, + asset_server: Res, + render_adapter: Res, +) { + let motion_vectors_storage_read_write = render_adapter + .get_texture_format_features(MOTION_VECTOR_PREPASS_FORMAT) + .flags + .contains(TextureFormatFeatureFlags::STORAGE_READ_WRITE); + let motion_vectors_binding = if motion_vectors_storage_read_write { + texture_storage_2d(TextureFormat::Rg16Float, StorageTextureAccess::ReadWrite) + } else { + texture_2d(TextureSampleType::Float { filterable: false }) + }; + + let bind_group_layout = BindGroupLayoutDescriptor::new( + "solari_lighting_bind_group_layout", + &BindGroupLayoutEntries::sequential( + ShaderStages::COMPUTE, + ( + texture_storage_2d(TextureFormat::Rgba16Float, StorageTextureAccess::ReadWrite), + storage_buffer_sized(false, None), + storage_buffer_sized(false, None), + texture_2d(TextureSampleType::Uint), + texture_depth_2d(), + motion_vectors_binding, + uniform_buffer::(true), + uniform_buffer::(true), + storage_buffer_sized(false, None), + uniform_buffer_sized(false, None), + ), + ), + ); + + let bind_group_layout_restir = BindGroupLayoutDescriptor::new( + "solari_lighting_bind_group_layout_restir", + &BindGroupLayoutEntries::sequential( + ShaderStages::COMPUTE, + ( + texture_storage_2d(TextureFormat::Rgba16Float, StorageTextureAccess::ReadWrite), + storage_buffer_sized(false, None), + storage_buffer_sized(false, None), + texture_2d(TextureSampleType::Uint), + texture_depth_2d(), + motion_vectors_binding, + uniform_buffer::(true), + uniform_buffer::(true), + storage_buffer_sized(false, None), + uniform_buffer_sized(false, None), + texture_2d(TextureSampleType::Uint), + texture_depth_2d(), + storage_buffer_sized(false, None), + storage_buffer_sized(false, None), + ), + ), + ); + + let bind_group_layout_world_cache_active_cells_dispatch = BindGroupLayoutDescriptor::new( + "solari_lighting_bind_group_layout_world_cache_active_cells_dispatch", + &BindGroupLayoutEntries::single(ShaderStages::COMPUTE, storage_buffer_sized(false, None)), + ); + + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + let bind_group_layout_resolve_dlss_rr_textures = BindGroupLayoutDescriptor::new( + "solari_lighting_bind_group_layout_resolve_dlss_rr_textures", + &BindGroupLayoutEntries::sequential( + ShaderStages::COMPUTE, + ( + texture_storage_2d(TextureFormat::Rgba8Unorm, StorageTextureAccess::WriteOnly), + texture_storage_2d(TextureFormat::Rgba8Unorm, StorageTextureAccess::WriteOnly), + texture_storage_2d(TextureFormat::Rgba16Float, StorageTextureAccess::WriteOnly), + texture_storage_2d(TextureFormat::R32Float, StorageTextureAccess::WriteOnly), + texture_storage_2d(TextureFormat::Rg16Float, StorageTextureAccess::WriteOnly), + ), + ), + ); + + let create_pipeline = |label: &'static str, + entry_point: &'static str, + shader: Handle, + restir: bool, + extra_bind_group: ExtraBindGroup, + extra_shader_defs: Vec| { + let group_1 = if restir { + &bind_group_layout_restir + } else { + &bind_group_layout + }; + let mut layout = vec![scene_bindings.bind_group_layout.clone(), group_1.clone()]; + match extra_bind_group { + ExtraBindGroup::None => {} + ExtraBindGroup::WorldCacheDispatch => { + layout.push(bind_group_layout_world_cache_active_cells_dispatch.clone()); + } + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + ExtraBindGroup::DlssRrGuideBuffers => { + layout.push(bind_group_layout_resolve_dlss_rr_textures.clone()); + } + } + + let mut shader_defs = vec![ShaderDefVal::UInt( + "WORLD_CACHE_SIZE".into(), + WORLD_CACHE_SIZE as u32, + )]; + if motion_vectors_storage_read_write { + shader_defs.push("MOTION_VECTORS_READ_WRITE".into()); + } + if restir { + shader_defs.push("RESTIR".into()); + } + match extra_bind_group { + ExtraBindGroup::None => {} + ExtraBindGroup::WorldCacheDispatch => { + shader_defs.push("WORLD_CACHE_NON_ATOMIC_LIFE_BUFFER".into()); + } + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + ExtraBindGroup::DlssRrGuideBuffers => { + shader_defs.push("DLSS_RR_GUIDE_BUFFERS".into()); + } + } + shader_defs.extend_from_slice(&extra_shader_defs); + + pipeline_cache.queue_compute_pipeline(ComputePipelineDescriptor { + label: Some(label.into()), + layout, + shader, + shader_defs, + entry_point: Some(entry_point.into()), + ..default() + }) + }; + + commands.insert_resource(SolariLightingPipelines { + bind_group_layout: bind_group_layout.clone(), + bind_group_layout_restir: bind_group_layout_restir.clone(), + bind_group_layout_world_cache_active_cells_dispatch: + bind_group_layout_world_cache_active_cells_dispatch.clone(), + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + bind_group_layout_resolve_dlss_rr_textures: bind_group_layout_resolve_dlss_rr_textures + .clone(), + decay_world_cache_pipeline: create_pipeline( + "solari_lighting_decay_world_cache_pipeline", + "decay_world_cache", + load_embedded_asset!(asset_server.as_ref(), "world_cache_compact.wesl"), + false, + ExtraBindGroup::WorldCacheDispatch, + vec![], + ), + compact_world_cache_single_block_pipeline: create_pipeline( + "solari_lighting_compact_world_cache_single_block_pipeline", + "compact_world_cache_single_block", + load_embedded_asset!(asset_server.as_ref(), "world_cache_compact.wesl"), + false, + ExtraBindGroup::WorldCacheDispatch, + vec![], + ), + compact_world_cache_blocks_pipeline: create_pipeline( + "solari_lighting_compact_world_cache_blocks_pipeline", + "compact_world_cache_blocks", + load_embedded_asset!(asset_server.as_ref(), "world_cache_compact.wesl"), + false, + ExtraBindGroup::WorldCacheDispatch, + vec![], + ), + compact_world_cache_write_active_cells_pipeline: create_pipeline( + "solari_lighting_compact_world_cache_write_active_cells_pipeline", + "compact_world_cache_write_active_cells", + load_embedded_asset!(asset_server.as_ref(), "world_cache_compact.wesl"), + false, + ExtraBindGroup::WorldCacheDispatch, + vec![], + ), + sample_di_for_world_cache_pipeline: create_pipeline( + "solari_lighting_sample_di_for_world_cache_pipeline", + "sample_di", + load_embedded_asset!(asset_server.as_ref(), "world_cache_update.wesl"), + false, + ExtraBindGroup::None, + vec![], + ), + sample_gi_for_world_cache_pipeline: create_pipeline( + "solari_lighting_sample_gi_for_world_cache_pipeline", + "sample_gi", + load_embedded_asset!(asset_server.as_ref(), "world_cache_update.wesl"), + false, + ExtraBindGroup::None, + vec!["WORLD_CACHE_QUERY_ATOMIC_MAX_LIFETIME".into()], + ), + blend_new_world_cache_samples_pipeline: create_pipeline( + "solari_lighting_blend_new_world_cache_samples_pipeline", + "blend_new_samples", + load_embedded_asset!(asset_server.as_ref(), "world_cache_update.wesl"), + false, + ExtraBindGroup::None, + vec![], + ), + presample_light_tiles_pipeline: create_pipeline( + "solari_lighting_presample_light_tiles_pipeline", + "presample_light_tiles", + load_embedded_asset!(asset_server.as_ref(), "presample_light_tiles.wesl"), + false, + ExtraBindGroup::None, + vec![], + ), + restir: RestirPipelines { + initial_and_temporal: create_pipeline( + "solari_lighting_initial_and_temporal_pipeline", + "initial_and_temporal", + load_embedded_asset!(asset_server.as_ref(), "restir.wesl"), + true, + ExtraBindGroup::None, + vec![], + ), + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + initial_and_temporal_with_psr: create_pipeline( + "solari_lighting_initial_and_temporal_with_psr_pipeline", + "initial_and_temporal", + load_embedded_asset!(asset_server.as_ref(), "restir.wesl"), + true, + ExtraBindGroup::DlssRrGuideBuffers, + vec![], + ), + spatial_and_shade: create_pipeline( + "solari_lighting_spatial_and_shade_pipeline", + "spatial_and_shade", + load_embedded_asset!(asset_server.as_ref(), "restir.wesl"), + true, + ExtraBindGroup::None, + vec!["SPATIAL_MERGE".into()], + ), + }, + no_restir: NoRestirPipelines { + initial_and_shade: create_pipeline( + "solari_lighting_initial_and_shade_pipeline", + "initial_and_shade", + load_embedded_asset!(asset_server.as_ref(), "no_restir.wesl"), + false, + ExtraBindGroup::None, + vec![], + ), + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + initial_and_shade_with_psr: create_pipeline( + "solari_lighting_initial_and_shade_with_psr_pipeline", + "initial_and_shade", + load_embedded_asset!(asset_server.as_ref(), "no_restir.wesl"), + false, + ExtraBindGroup::DlssRrGuideBuffers, + vec![], + ), + }, + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + resolve_dlss_rr_textures_pipeline: create_pipeline( + "solari_lighting_resolve_dlss_rr_textures_pipeline", + "resolve_dlss_rr_textures", + load_embedded_asset!(asset_server.as_ref(), "resolve_dlss_rr_textures.wesl"), + false, + ExtraBindGroup::DlssRrGuideBuffers, + vec![], + ), + }); +} + +enum ExtraBindGroup { + None, + WorldCacheDispatch, + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + DlssRrGuideBuffers, +} diff --git a/src/realtime/prepare.rs b/src/realtime/prepare.rs new file mode 100644 index 0000000..95f52f6 --- /dev/null +++ b/src/realtime/prepare.rs @@ -0,0 +1,340 @@ +use super::SolariLighting; +use crate::scene::RaytracingSceneNeedsPreviousFrameData; +#[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] +use bevy_anti_alias::dlss::{ + Dlss, DlssRayReconstructionFeature, ViewDlssRayReconstructionTextures, +}; +use bevy_camera::MainPassResolutionOverride; +use bevy_diagnostic::FrameCount; +#[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] +use bevy_ecs::query::Has; +use bevy_ecs::{ + component::Component, + entity::Entity, + system::{Commands, Query, Res}, +}; +#[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] +use bevy_image::ToExtents; +use bevy_math::UVec2; +use bevy_render::{ + camera::ExtractedCamera, + render_resource::{Buffer, BufferDescriptor, BufferInitDescriptor, BufferUsages}, + renderer::{RenderDevice, RenderQueue}, +}; +#[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] +use bevy_render::{ + render_resource::{ + TextureDescriptor, TextureDimension, TextureFormat, TextureUsages, TextureViewDescriptor, + }, + texture::CachedTexture, +}; +use bytemuck::{Pod, Zeroable}; + +/// Size of the `LightSample` shader struct in bytes. +const LIGHT_SAMPLE_STRUCT_SIZE: u64 = 8; + +/// Size of the `ResolvedLightSamplePacked` shader struct in bytes. +const RESOLVED_LIGHT_SAMPLE_STRUCT_SIZE: u64 = 24; + +/// Size of the `Reservoir` shader struct in bytes. +const RESERVOIR_STRUCT_SIZE: u64 = 48; + +pub const LIGHT_TILE_BLOCKS: u64 = 128; +pub const LIGHT_TILE_SAMPLES_PER_BLOCK: u64 = 1024; + +/// Amount of entries in the world cache (must be a power of 2, and >= 2^10) +pub const WORLD_CACHE_SIZE: u64 = 2u64.pow(20); +/// Sum of per-cell field sizes in `WorldCache`. Keep in sync with `realtime_bindings.wgsl`. +const WORLD_CACHE_ENTRY_SIZE: u64 = 84; +/// Size of the fixed `b` array (`array`). +const WORLD_CACHE_B_SIZE: u64 = (WORLD_CACHE_SIZE / 1024) * size_of::() as u64; +/// Offset of `active_cells_count`. +pub const WORLD_CACHE_ACTIVE_CELLS_COUNT_OFFSET: u64 = + WORLD_CACHE_SIZE * WORLD_CACHE_ENTRY_SIZE + WORLD_CACHE_B_SIZE; +/// Must stay under wgpu's default `max_storage_buffer_binding_size` (128 MiB or 2^27 bytes). +pub const WORLD_CACHE_BUFFER_SIZE: u64 = + (WORLD_CACHE_ACTIVE_CELLS_COUNT_OFFSET + size_of::() as u64).next_multiple_of(16); + +/// GPU representation of the user-configurable [`SolariLighting`] settings, plus +/// per-frame state. +/// +/// Field order and types must match the `SolariLightingSettings` struct in +/// `realtime_bindings.wgsl`. +#[repr(C)] +#[derive(Clone, Copy, Pod, Zeroable)] +struct SolariLightingUniforms { + confidence_weight_cap: f32, + primary_di_samples: u32, + secondary_di_samples: u32, + max_bounces: u32, + world_cache_max_temporal_samples: f32, + world_cache_direct_light_sample_count: u32, + world_cache_max_gi_ray_distance: f32, + world_cache_cell_updates_soft_target: u32, + world_cache_position_base_cell_size: f32, + world_cache_position_lod_scale: f32, + frame_rng: u32, + reset: u32, +} + +impl SolariLightingUniforms { + fn new(settings: &SolariLighting, frame_count: u32, force_reset: bool) -> Self { + Self { + confidence_weight_cap: settings.confidence_weight_cap, + primary_di_samples: settings.primary_di_samples, + secondary_di_samples: settings.secondary_di_samples, + max_bounces: settings.max_bounces, + world_cache_max_temporal_samples: settings.world_cache_max_temporal_samples, + world_cache_direct_light_sample_count: settings.world_cache_direct_light_sample_count, + world_cache_max_gi_ray_distance: settings.world_cache_max_gi_ray_distance, + world_cache_cell_updates_soft_target: settings.world_cache_cell_updates_soft_target, + world_cache_position_base_cell_size: settings.world_cache_position_base_cell_size, + world_cache_position_lod_scale: settings.world_cache_position_lod_scale, + frame_rng: frame_count.wrapping_mul(5782582), + reset: (settings.reset || force_reset) as u32, + } + } +} + +/// Declares to the raytracing scene whether any view needs last frame's TLAS and light ids. +pub fn setup_raytracing_scene_needs_previous_frame_data( + views: Query<&SolariLighting>, + needs_previous_frame_data: Option>, + mut commands: Commands, +) { + let restir_used = views.iter().any(|solari_lighting| solari_lighting.restir); + match (restir_used, needs_previous_frame_data.is_some()) { + (true, false) => commands.insert_resource(RaytracingSceneNeedsPreviousFrameData), + (false, true) => commands.remove_resource::(), + _ => {} + } +} + +/// Internal rendering resources used for Solari lighting. +#[derive(Component)] +pub struct SolariLightingResources { + pub constants: Buffer, + pub light_tile_samples: Buffer, + pub light_tile_resolved_samples: Buffer, + pub reservoirs: Option, + pub world_cache: Buffer, + pub world_cache_active_cells_dispatch: Buffer, + pub view_size: UVec2, +} + +pub struct SolariReservoirBuffers { + pub a: Buffer, + pub b: Buffer, +} + +pub fn prepare_solari_lighting_resources( + #[cfg(any(not(feature = "dlss"), feature = "force_disable_dlss"))] query: Query<( + Entity, + &ExtractedCamera, + &SolariLighting, + Option<&SolariLightingResources>, + Option<&MainPassResolutionOverride>, + )>, + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] query: Query<( + Entity, + &ExtractedCamera, + &SolariLighting, + Option<&SolariLightingResources>, + Option<&MainPassResolutionOverride>, + Has>, + )>, + render_device: Res, + render_queue: Res, + frame_count: Res, + mut commands: Commands, +) { + for query_item in &query { + #[cfg(any(not(feature = "dlss"), feature = "force_disable_dlss"))] + let (entity, camera, solari_lighting, solari_lighting_resources, resolution_override) = + query_item; + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + let ( + entity, + camera, + solari_lighting, + solari_lighting_resources, + resolution_override, + has_dlss_rr, + ) = query_item; + + let Some(mut view_size) = camera.physical_viewport_size else { + continue; + }; + if let Some(MainPassResolutionOverride(resolution_override)) = resolution_override { + view_size = *resolution_override; + } + + let reusable = solari_lighting_resources.filter(|r| { + r.view_size == view_size && r.reservoirs.is_some() == solari_lighting.restir + }); + let uniforms = + SolariLightingUniforms::new(solari_lighting, frame_count.0, reusable.is_none()); + + if let Some(solari_lighting_resources) = reusable { + // The constants uniform can change every frame, so always upload it. + render_queue.write_buffer( + &solari_lighting_resources.constants, + 0, + bytemuck::bytes_of(&uniforms), + ); + continue; + } + + let constants = render_device.create_buffer_with_data(&BufferInitDescriptor { + label: Some("solari_lighting_constants"), + contents: bytemuck::bytes_of(&uniforms), + usage: BufferUsages::UNIFORM | BufferUsages::COPY_DST, + }); + + let light_tile_samples = render_device.create_buffer(&BufferDescriptor { + label: Some("solari_lighting_light_tile_samples"), + size: LIGHT_TILE_BLOCKS * LIGHT_TILE_SAMPLES_PER_BLOCK * LIGHT_SAMPLE_STRUCT_SIZE, + usage: BufferUsages::STORAGE, + mapped_at_creation: false, + }); + + let light_tile_resolved_samples = render_device.create_buffer(&BufferDescriptor { + label: Some("solari_lighting_light_tile_resolved_samples"), + size: LIGHT_TILE_BLOCKS + * LIGHT_TILE_SAMPLES_PER_BLOCK + * RESOLVED_LIGHT_SAMPLE_STRUCT_SIZE, + usage: BufferUsages::STORAGE, + mapped_at_creation: false, + }); + + let reservoirs = solari_lighting.restir.then(|| { + let reservoirs_buffer = |name| { + render_device.create_buffer(&BufferDescriptor { + label: Some(name), + size: (view_size.x * view_size.y) as u64 * RESERVOIR_STRUCT_SIZE, + usage: BufferUsages::STORAGE, + mapped_at_creation: false, + }) + }; + SolariReservoirBuffers { + a: reservoirs_buffer("solari_lighting_reservoirs_a"), + b: reservoirs_buffer("solari_lighting_reservoirs_b"), + } + }); + + let world_cache = render_device.create_buffer(&BufferDescriptor { + label: Some("solari_lighting_world_cache"), + size: WORLD_CACHE_BUFFER_SIZE, + usage: BufferUsages::STORAGE | BufferUsages::COPY_SRC, + mapped_at_creation: false, + }); + + let world_cache_active_cells_dispatch = render_device.create_buffer(&BufferDescriptor { + label: Some("solari_lighting_world_cache_active_cells_dispatch"), + size: size_of::<[u32; 3]>() as u64, + usage: BufferUsages::INDIRECT | BufferUsages::STORAGE, + mapped_at_creation: false, + }); + + commands.entity(entity).insert(SolariLightingResources { + constants, + light_tile_samples, + light_tile_resolved_samples, + reservoirs, + world_cache, + world_cache_active_cells_dispatch, + view_size, + }); + + #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] + if has_dlss_rr { + let diffuse_albedo = render_device.create_texture(&TextureDescriptor { + label: Some("solari_lighting_diffuse_albedo"), + size: view_size.to_extents(), + mip_level_count: 1, + sample_count: 1, + dimension: TextureDimension::D2, + format: TextureFormat::Rgba8Unorm, + usage: TextureUsages::TEXTURE_BINDING | TextureUsages::STORAGE_BINDING, + view_formats: &[], + }); + let diffuse_albedo_view = diffuse_albedo.create_view(&TextureViewDescriptor::default()); + + let specular_albedo = render_device.create_texture(&TextureDescriptor { + label: Some("solari_lighting_specular_albedo"), + size: view_size.to_extents(), + mip_level_count: 1, + sample_count: 1, + dimension: TextureDimension::D2, + format: TextureFormat::Rgba8Unorm, + usage: TextureUsages::TEXTURE_BINDING | TextureUsages::STORAGE_BINDING, + view_formats: &[], + }); + let specular_albedo_view = + specular_albedo.create_view(&TextureViewDescriptor::default()); + + let normal_roughness = render_device.create_texture(&TextureDescriptor { + label: Some("solari_lighting_normal_roughness"), + size: view_size.to_extents(), + mip_level_count: 1, + sample_count: 1, + dimension: TextureDimension::D2, + format: TextureFormat::Rgba16Float, + usage: TextureUsages::TEXTURE_BINDING | TextureUsages::STORAGE_BINDING, + view_formats: &[], + }); + let normal_roughness_view = + normal_roughness.create_view(&TextureViewDescriptor::default()); + + let dlss_rr_depth = render_device.create_texture(&TextureDescriptor { + label: Some("solari_lighting_dlss_rr_depth"), + size: view_size.to_extents(), + mip_level_count: 1, + sample_count: 1, + dimension: TextureDimension::D2, + format: TextureFormat::R32Float, + usage: TextureUsages::TEXTURE_BINDING | TextureUsages::STORAGE_BINDING, + view_formats: &[], + }); + let dlss_rr_depth_view = dlss_rr_depth.create_view(&TextureViewDescriptor::default()); + + let specular_motion_vectors = render_device.create_texture(&TextureDescriptor { + label: Some("solari_lighting_specular_motion_vectors"), + size: view_size.to_extents(), + mip_level_count: 1, + sample_count: 1, + dimension: TextureDimension::D2, + format: TextureFormat::Rg16Float, + usage: TextureUsages::TEXTURE_BINDING | TextureUsages::STORAGE_BINDING, + view_formats: &[], + }); + let specular_motion_vectors_view = + specular_motion_vectors.create_view(&TextureViewDescriptor::default()); + + commands + .entity(entity) + .insert(ViewDlssRayReconstructionTextures { + diffuse_albedo: CachedTexture { + texture: diffuse_albedo, + default_view: diffuse_albedo_view, + }, + specular_albedo: CachedTexture { + texture: specular_albedo, + default_view: specular_albedo_view, + }, + normal_roughness: CachedTexture { + texture: normal_roughness, + default_view: normal_roughness_view, + }, + depth: CachedTexture { + texture: dlss_rr_depth, + default_view: dlss_rr_depth_view, + }, + specular_motion_vectors: CachedTexture { + texture: specular_motion_vectors, + default_view: specular_motion_vectors_view, + }, + }); + } + } +} diff --git a/src/realtime/presample_light_tiles.wesl b/src/realtime/presample_light_tiles.wesl new file mode 100644 index 0000000..be26d89 --- /dev/null +++ b/src/realtime/presample_light_tiles.wesl @@ -0,0 +1,40 @@ +// https://cwyman.org/papers/hpg21_rearchitectingReSTIR.pdf + +import bevy_pbr::render::rgb9e5::{vec3_to_rgb9e5_, rgb9e5_to_vec3_}; +import bevy_render::utils::{octahedral_encode, octahedral_decode}; +import package::scene::sampling::{generate_random_light_sample, ResolvedLightSample}; +import package::realtime::bindings::{light_tile_samples, light_tile_resolved_samples, view, constants, ResolvedLightSamplePacked}; + +enable wgpu_ray_query; + +@compute @workgroup_size(1024, 1, 1) +fn presample_light_tiles(@builtin(workgroup_id) workgroup_id: vec3, @builtin(local_invocation_index) sample_index: u32) { + let tile_id = workgroup_id.x; + var rng = (tile_id * 0x9E3779B9u) + sample_index + constants.frame_rng; + + let sample = generate_random_light_sample(&rng); + + let i = (tile_id * 1024u) + sample_index; + light_tile_samples[i] = sample.light_sample; + light_tile_resolved_samples[i] = pack_resolved_light_sample(sample.resolved_light_sample); +} + +fn pack_resolved_light_sample(sample: ResolvedLightSample) -> ResolvedLightSamplePacked { + return ResolvedLightSamplePacked( + sample.world_position.x, + sample.world_position.y, + sample.world_position.z, + pack2x16unorm(octahedral_encode(sample.world_normal)), + vec3_to_rgb9e5_(log2(sample.radiance * view.exposure + 1.0)), + sample.inverse_pdf * select(1.0, -1.0, sample.world_position.w == 0.0), + ); +} + +fn unpack_resolved_light_sample(packed: ResolvedLightSamplePacked, exposure: f32) -> ResolvedLightSample { + return ResolvedLightSample( + vec4(packed.world_position_x, packed.world_position_y, packed.world_position_z, select(1.0, 0.0, packed.inverse_pdf < 0.0)), + octahedral_decode(unpack2x16unorm(packed.world_normal)), + (exp2(rgb9e5_to_vec3_(packed.radiance)) - 1.0) / exposure, + abs(packed.inverse_pdf), + ); +} diff --git a/src/realtime/resolve_dlss_rr_textures.wesl b/src/realtime/resolve_dlss_rr_textures.wesl new file mode 100644 index 0000000..906096f --- /dev/null +++ b/src/realtime/resolve_dlss_rr_textures.wesl @@ -0,0 +1,269 @@ +import bevy_core_pipeline::tonemapping::tonemapping_luminance as luminance; +import bevy_pbr::deferred::types::unpack_24bit_normal; +import bevy_pbr::render::pbr_functions::{calculate_diffuse_color, calculate_F0, calculate_F0_dielectric}; +import bevy_render::utils::octahedral_decode; +import package::realtime::gbuffer_utils::gpixel_resolve; +import package::realtime::bindings::{gbuffer, depth_buffer, load_motion_vector, motion_vectors, previous_view, view, diffuse_albedo, specular_albedo, normal_roughness, dlss_rr_depth, specular_motion_vectors}; +import package::scene::brdf::{evaluate_specular_brdf, F_AB, lobe_reflectances}; +import package::scene::bindings::{MIRROR_ROUGHNESS_THRESHOLD, ResolvedMaterial, ResolvedRayHitFull}; + +enable wgpu_ray_query; + +/// A surface is replaced outright only when nearly all of its reflectance leaves through the delta +/// lobe. +const FULL_REPLACEMENT_FRACTION = 0.9; + +/// How far a reflector's virtual image may shift between neighboring pixels, as a fraction of the +/// virtual distance itself, before the surface is treated as too curved to replace. +const MAX_VIRTUAL_DEPTH_JITTER = 0.002; + +/// Even a perfectly flat surface measures a small nonzero normal change, because G-buffer normals are +/// 24-bit octahedral and neighboring texels round differently. +const NORMAL_QUANTIZATION_FLOOR = 0.002; + +/// Distance, in meters, standing in for "infinitely far" when a mirror ray finds nothing. +const ENVIRONMENT_VIRTUAL_DISTANCE = 10000.0; + +@compute @workgroup_size(8, 8, 1) +fn resolve_dlss_rr_textures(@builtin(global_invocation_id) global_id: vec3) { + let pixel_id = global_id.xy; + if any(pixel_id >= vec2u(view.main_pass_viewport.zw)) { return; } + + let depth = textureLoad(depth_buffer, global_id.xy, 0); + let surface_motion_vector = load_motion_vector(pixel_id); + + textureStore(dlss_rr_depth, pixel_id, vec4(depth)); + + if depth == 0.0 { + textureStore(specular_motion_vectors, pixel_id, vec4(surface_motion_vector, vec2(0.0))); + textureStore(diffuse_albedo, pixel_id, vec4(0.0)); + textureStore(specular_albedo, pixel_id, vec4(0.5)); + textureStore(normal_roughness, pixel_id, vec4(0.0, 0.0, 1.0, 0.0)); + return; + } + + let surface = gpixel_resolve(textureLoad(gbuffer, pixel_id, 0), depth, pixel_id, view.main_pass_viewport.zw, view.world_from_clip); + let F0 = calculate_F0(surface.material.base_color, surface.material.metallic, vec3(surface.material.reflectance)); + let wo = normalize(view.world_position - surface.world_position); + + textureStore(diffuse_albedo, pixel_id, vec4(calculate_diffuse_color(surface.material.base_color, surface.material.metallic, 0.0, 0.0), 0.0)); + textureStore(specular_albedo, pixel_id, vec4(env_brdf_approx2(F0, surface.material.roughness, surface.world_normal, wo), 0.0)); + textureStore(normal_roughness, pixel_id, vec4(surface.world_normal, surface.material.perceptual_roughness)); + + // Resetting to the specular motion vector on the frames we draw a diffuse lobe means we + // wouldn't be writing the motion vectors that frame, so it would alternate the guide between + // to values, and the denoiser blurs the reflection rather than reprojecting it. + if !needs_specular_motion_vector(surface.material.roughness) { + textureStore(specular_motion_vectors, pixel_id, vec4(surface_motion_vector, vec2(0.0))); + } +} + +fn needs_specular_motion_vector(roughness: f32) -> bool { + return roughness <= 0.0625; +} + +/// Carried across every bounce of the path walk, so anything derivable from a value the walk already +/// holds is derived at the end instead of stored. What is left is only what the walk itself produces. +struct PsrState { + finished: bool, + /// Whether this pixel's surface is being swapped out for the reflected one, or is only having its + /// reflection's motion described. Keyed on the primary surface only, and false for anything glossy. + replace_fully: bool, + /// The chain's cumulative transform - the product of one Householder reflection per mirror, in + /// chain order - stored as a rotor plus the parity of the reflection count rather than as the 3x3 + /// matrix it denotes. + mirror_rotor: vec4, + mirror_parity_odd: bool, + /// Distance traveled since the primary surface, camera through every mirror. Not the total path + /// length: keeping the reflection's own share means the primary distance is only ever added, never + /// subtracted back out, so it can be recovered at the end without the two disagreeing. + reflection_length: f32, + /// Product of the Fresnel term at each mirror in the chain: what the reflected surface's color is + /// multiplied by on its way back to the eye. + throughput: vec3, +} + +fn psr_init(world_normal: vec3, material: ResolvedMaterial) -> PsrState { + var psr: PsrState; + psr.finished = !needs_specular_motion_vector(material.roughness); + psr.replace_fully = is_delta_mirror(material); + // The chain opens with the primary surface's own reflection, so parity starts odd. + psr.mirror_rotor = mirror_chain_rotor(world_normal, false); + psr.mirror_parity_odd = true; + psr.reflection_length = 0.0; + psr.throughput = vec3(1.0); + return psr; +} + +/// Fold one more mirror into the chain, equivalent to right-multiplying the chain's matrix by this +/// mirror's Householder reflection. +/// https://en.wikipedia.org/wiki/Householder_transformation +/// +/// A product of k Householder reflections is orthogonal with determinant (-1)^k, so it is a rotation +/// when k is even, and a rotation composed with any one fixed reflection when k is odd. +fn psr_chain_mirror(psr: PsrState, plane_normal: vec3) -> PsrState { + var chained = psr; + chained.mirror_rotor = quaternion_multiply(psr.mirror_rotor, mirror_chain_rotor(plane_normal, psr.mirror_parity_odd)); + chained.mirror_parity_odd = !psr.mirror_parity_odd; + return chained; +} + +fn psr_environment_miss(pixel_id: vec2, primary_wo: vec3) { + let far_position = view.world_position - (primary_wo * ENVIRONMENT_VIRTUAL_DISTANCE); + textureStore(specular_motion_vectors, pixel_id, vec4(calculate_motion_vector(far_position, far_position), vec2(0.0))); +} + +/// Primary surface replacement for perfect mirrors. The reflection chain has been followed to its +/// first non-mirror hit; write that surface's attributes, reflected into the mirror's virtual space, +/// to the DLSS RR guide buffers so the denoiser treats this pixel as directly seeing it. +/// https://developer.nvidia.com/blog/rendering-perfect-reflections-and-refractions-in-path-traced-games/#primary_surface_replacement +fn replace_primary_surface( + pixel_id: vec2, + psr: PsrState, + ray_hit: ResolvedRayHitFull, + primary_material: ResolvedMaterial, + primary_world_position: vec3, + primary_normal: vec3, + primary_wo: vec3, + primary_F_ab: vec2, +) { + let primary_distance = length(primary_world_position - view.world_position); + let path_length = primary_distance + psr.reflection_length; + + // Too curved to track the reflection; fall back to the surface's own motion so the guide is not stale + if psr.replace_fully && 2.0 * reflector_curvature(pixel_id, primary_normal) * psr.reflection_length > MAX_VIRTUAL_DEPTH_JITTER * path_length { + textureStore(specular_motion_vectors, pixel_id, vec4(load_motion_vector(pixel_id), vec2(0.0))); + return; + } + + let virtual_position = primary_world_position - (primary_wo * psr.reflection_length); + let world_motion = ray_hit.previous_frame_world_position - ray_hit.world_position; + let virtual_previous_position = virtual_position + apply_mirror_chain(psr, world_motion); + let specular_motion_vector = calculate_motion_vector(virtual_position, virtual_previous_position); + + textureStore(specular_motion_vectors, pixel_id, vec4(specular_motion_vector, vec2(0.0))); + + if !psr.replace_fully { + return; + } + + let wo = normalize(view.world_position - virtual_position); + let virtual_normal = normalize(apply_mirror_chain(psr, ray_hit.world_normal)); + + let primary_depth = textureLoad(depth_buffer, pixel_id, 0); + textureStore(dlss_rr_depth, pixel_id, vec4(primary_depth * primary_distance / path_length)); + @if(MOTION_VECTORS_READ_WRITE) + textureStore(motion_vectors, pixel_id, vec4(specular_motion_vector, vec2(0.0))); + + let reflected_diffuse = calculate_diffuse_color(ray_hit.material.base_color, ray_hit.material.metallic, 0.0, 0.0); + let reflected_F0 = calculate_F0(ray_hit.material.base_color, ray_hit.material.metallic, vec3(ray_hit.material.reflectance)); + let reflected_specular = env_brdf_approx2(reflected_F0, ray_hit.material.roughness, virtual_normal, wo); + + let own_diffuse = calculate_diffuse_color(primary_material.base_color, primary_material.metallic, 0.0, 0.0); + let own_F0 = calculate_F0(primary_material.base_color, primary_material.metallic, vec3(primary_material.reflectance)); + let own_specular = env_brdf_approx2(own_F0, primary_material.roughness, primary_normal, primary_wo); + + let specular_fraction = specular_fraction(primary_material, primary_F_ab); + + textureStore(diffuse_albedo, pixel_id, vec4(psr.throughput * reflected_diffuse + own_diffuse, 0.0)); + textureStore(specular_albedo, pixel_id, vec4(mix(own_specular, psr.throughput * reflected_specular, specular_fraction), 0.0)); + textureStore(normal_roughness, pixel_id, vec4(virtual_normal, ray_hit.material.perceptual_roughness)); +} + +fn primary_surface_glossy(material: ResolvedMaterial) -> bool { + return material.roughness > MIRROR_ROUGHNESS_THRESHOLD; +} + +fn is_delta_mirror(material: ResolvedMaterial) -> bool { + return material.roughness <= MIRROR_ROUGHNESS_THRESHOLD + && specular_fraction(material, F_AB(material.perceptual_roughness, 1.0)) >= FULL_REPLACEMENT_FRACTION; +} + +/// Share of a surface's total reflectance that leaves through the specular lobe, in 0..1. +fn specular_fraction(material: ResolvedMaterial, F_ab: vec2) -> f32 { + let rho = lobe_reflectances(material.base_color, calculate_F0_dielectric(vec3(material.reflectance)), material, F_ab); + let specular_luminance = luminance(rho.specular); + return specular_luminance / max(specular_luminance + luminance(rho.diffuse), 0.0001); +} + +fn psr_bounce_reflectance(wo: vec3, wi: vec3, normal: vec3, material: ResolvedMaterial, F_ab: vec2, delta: bool) -> vec3 { + if delta { + return evaluate_specular_brdf(wo, wi, normal, material, F_ab); + } + return lobe_reflectances(material.base_color, calculate_F0_dielectric(vec3(material.reflectance)), material, F_ab).specular; +} + +/// Angle, in radians, that the shading normal changes over one pixel in screen space. +fn reflector_curvature(pixel_id: vec2, normal: vec3) -> f32 { + let max_pixel_id = vec2(view.main_pass_viewport.zw) - vec2(1u); + let right = load_gbuffer_normal(min(pixel_id + vec2(1u, 0u), max_pixel_id)); + let down = load_gbuffer_normal(min(pixel_id + vec2(0u, 1u), max_pixel_id)); + let min_cos = min(dot(normal, right), dot(normal, down)); + let angle = sqrt(max(0.0, 2.0 * (1.0 - min_cos))); + return max(0.0, angle - NORMAL_QUANTIZATION_FLOOR); +} + +fn load_gbuffer_normal(pixel_id: vec2) -> vec3 { + return octahedral_decode(unpack_24bit_normal(textureLoad(gbuffer, pixel_id, 0).a)); +} + +fn apply_mirror_chain(psr: PsrState, v: vec3) -> vec3 { + var reflected = v; + if psr.mirror_parity_odd { + reflected.z = -reflected.z; + } + let t = 2.0 * cross(psr.mirror_rotor.xyz, reflected); + return reflected + psr.mirror_rotor.w * t + cross(psr.mirror_rotor.xyz, t); +} + +/// The rotation half of `H(n) * F` at even parity, or of `F * H(n)` at odd, where `H(n)` is the +/// Householder reflection about `plane_normal` and `F` the fixed z-axis one. +fn mirror_chain_rotor(plane_normal: vec3, parity_odd: bool) -> vec4 { + if parity_odd { + return vec4(plane_normal.y, -plane_normal.x, 0.0, plane_normal.z); + } + return vec4(-plane_normal.y, plane_normal.x, 0.0, plane_normal.z); +} + +fn quaternion_multiply(a: vec4, b: vec4) -> vec4 { + return vec4(a.w * b.xyz + b.w * a.xyz + cross(a.xyz, b.xyz), a.w * b.w - dot(a.xyz, b.xyz)); +} + +fn calculate_motion_vector(world_position: vec3, previous_world_position: vec3) -> vec2 { + let clip_position_t = view.unjittered_clip_from_world * vec4(world_position, 1.0); + let clip_position = clip_position_t.xy / clip_position_t.w; + let previous_clip_position_t = previous_view.unjittered_clip_from_world * vec4(previous_world_position, 1.0); + let previous_clip_position = previous_clip_position_t.xy / previous_clip_position_t.w; + // Motion vectors are UV-space offsets in [-1, 1], from one corner to the diagonally-opposite one. + // A clip-space diagonal difference is in [-2, 2], so scale by 0.5, and flip y since V goes down + // where clip-space y goes up. + return (clip_position - previous_clip_position) * vec2(0.5, -0.5); +} + +fn env_brdf_approx2(specular_color: vec3, alpha: f32, N: vec3, V: vec3) -> vec3 { + let NoV = abs(dot(N, V)); + + var X: vec4; + X.x = 1.0; + X.y = NoV; + X.z = NoV * NoV; + X.w = NoV * X.z; + + var Y: vec4; + Y.x = 1.0; + Y.y = alpha; + Y.z = alpha * alpha; + Y.w = alpha * Y.z; + + let M1 = mat2x2(0.99044, 1.29678, -1.28514, -0.755907); + let M2 = mat3x3(1.0, 20.3225, 121.563, 2.92338, -27.0302, 626.13, 59.4188, 222.592, 316.627); + let M3 = mat2x2(0.0365463, 9.0632, 3.32707, -9.04756); + let M4 = mat3x3(1.0, 9.04401, 5.56589, 3.59685, -16.3174, 19.7886, -1.36772, 9.22949, -20.2123); + + var bias = dot(M1 * X.xy, Y.xy) / dot(M2 * X.xyw, Y.xyw); + let scale = dot(M3 * X.xy, Y.xy) / dot(M4 * X.xzw, Y.xyw); + + bias *= saturate(specular_color.g * 50.0); + + return fma(specular_color, vec3(max(0.0, scale)), vec3(max(0.0, bias))); +} diff --git a/src/realtime/restir.wesl b/src/realtime/restir.wesl new file mode 100644 index 0000000..8211b29 --- /dev/null +++ b/src/realtime/restir.wesl @@ -0,0 +1,364 @@ +//! https://intro-to-restir.cwyman.org/presentations/2023ReSTIR_Course_Notes.pdf + +import bevy_core_pipeline::tonemapping::tonemapping_luminance as luminance; +import bevy_pbr::render::utils::{rand_f, rand_u, sample_disk}; +import bevy_render::utils::octahedral_decode; +import package::scene::brdf::{brdf_pdf, evaluate_brdf, F_AB}; +import package::realtime::gbuffer_utils::{gpixel_resolve, permute_pixel, pixel_dissimilar}; +import package::realtime::initial_path::{generate_initial_path, InitialSamplingResult}; +import package::realtime::bindings::{depth_buffer, empty_reservoir, gbuffer, load_motion_vector, previous_depth_buffer, previous_gbuffer, previous_view, reservoirs_a, reservoirs_b, Reservoir, constants, view, view_output}; +import package::scene::sampling::{balance_heuristic, calculate_resolved_light_contribution, isinf, isnan, LightSample, NULL_LIGHT_ID, power_heuristic, resolve_light_sample, ResolvedLightSample, trace_visibility, trace_visibility_previous_frame}; +import package::scene::bindings::{light_sources, LIGHT_NOT_PRESENT_THIS_FRAME, previous_frame_light_id_translations, RAY_T_MAX, RAY_T_MIN, ResolvedMaterial}; +import package::realtime::world_cache_query::{query_world_cache, WORLD_CACHE_CELL_LIFETIME}; + +enable wgpu_ray_query; + +const SPATIAL_REUSE_RADIUS_PIXELS = 30.0; + +@compute @workgroup_size(8, 8, 1) +fn initial_and_temporal(@builtin(workgroup_id) workgroup_id: vec3, @builtin(global_invocation_id) global_id: vec3) { + if any(global_id.xy >= vec2u(view.main_pass_viewport.zw)) { return; } + + let pixel_index = global_id.x + global_id.y * u32(view.main_pass_viewport.z); + var rng = pixel_index + constants.frame_rng; + + let depth = textureLoad(depth_buffer, global_id.xy, 0); + if depth == 0.0 { + reservoirs_b[pixel_index] = empty_reservoir(); + return; + } + let surface = gpixel_resolve(textureLoad(gbuffer, global_id.xy, 0), depth, global_id.xy, view.main_pass_viewport.zw, view.world_from_clip); + + let initial = generate_initial_path(surface.world_position, surface.world_normal, surface.material, workgroup_id.xy, global_id.xy, &rng); + textureStore(view_output, global_id.xy, vec4(initial.radiance, 0.0)); + + let temporal = load_temporal_reservoir(global_id.xy, depth, surface.world_position, surface.world_normal); + let previous_camera_homogeneous = previous_view.world_from_clip * (previous_view.clip_from_view * vec4(0.0, 0.0, 0.0, 1.0)); + let previous_camera_world_position = previous_camera_homogeneous.xyz / previous_camera_homogeneous.w; + let merge_result = merge_reservoirs(initial.reservoir, surface.world_position, surface.world_normal, surface.material, + temporal.reservoir, temporal.world_position, temporal.world_normal, temporal.material, previous_camera_world_position, &rng); + + reservoirs_b[pixel_index] = merge_result.merged_reservoir; +} + +@compute @workgroup_size(8, 8, 1) +fn spatial_and_shade(@builtin(global_invocation_id) global_id: vec3) { + if any(global_id.xy >= vec2u(view.main_pass_viewport.zw)) { return; } + + let pixel_index = global_id.x + global_id.y * u32(view.main_pass_viewport.z); + var rng = pixel_index + constants.frame_rng + 0x6A09E667u; + + let depth = textureLoad(depth_buffer, global_id.xy, 0); + if depth == 0.0 { + reservoirs_a[pixel_index] = empty_reservoir(); + return; + } + let surface = gpixel_resolve(textureLoad(gbuffer, global_id.xy, 0), depth, global_id.xy, view.main_pass_viewport.zw, view.world_from_clip); + + let input_reservoir = reservoirs_b[pixel_index]; + let spatial = load_spatial_reservoir(global_id.xy, depth, surface.world_position, surface.world_normal, &rng); + let merge_result = merge_reservoirs(input_reservoir, surface.world_position, surface.world_normal, surface.material, + spatial.reservoir, spatial.world_position, spatial.world_normal, spatial.material, view.world_position, &rng); + + reservoirs_a[pixel_index] = merge_result.merged_reservoir; + + var pixel_color = merge_result.selected_sample_brdf_radiance * merge_result.merged_reservoir.unbiased_contribution_weight; + pixel_color += surface.material.emissive; + pixel_color += textureLoad(view_output, global_id.xy).rgb; + pixel_color *= view.exposure; + textureStore(view_output, global_id.xy, vec4(pixel_color, 1.0)); + + @if(VISUALIZE_WORLD_CACHE) + textureStore(view_output, global_id.xy, vec4(query_world_cache(surface.world_position, surface.world_normal, view.world_position, RAY_T_MAX, WORLD_CACHE_CELL_LIFETIME, &rng) * view.exposure, 1.0)); +} + +fn load_temporal_reservoir(pixel_id: vec2, depth: f32, world_position: vec3, world_normal: vec3) -> NeighborInfo { + if bool(constants.reset) { + return NeighborInfo(empty_reservoir(), vec3(0.0), vec3(0.0), empty_material()); + } + + let motion_vector = load_motion_vector(pixel_id); + let temporal_pixel_id_float = round(vec2(pixel_id) - (motion_vector * view.main_pass_viewport.zw)); + + // If reprojection lands off-screen, fall back to this pixel's own previous reservoir rather than + // dropping history. The dissimilarity check below still validates the surface, and a same-pixel + // guess that passes it beats restarting from a confidence-1 reservoir at the screen edge. + var point_temporal_pixel_id = pixel_id; + if all(temporal_pixel_id_float >= vec2(0.0)) && all(temporal_pixel_id_float < view.main_pass_viewport.zw) { + point_temporal_pixel_id = vec2(temporal_pixel_id_float); + } + + var permute_rng = constants.frame_rng; + let permuted_temporal_pixel_id = permute_pixel(point_temporal_pixel_id, rand_u(&permute_rng), view.main_pass_viewport.zw); + + // Check if the pixel features have changed heavily between the current and previous frame + let temporal_depth = textureLoad(previous_depth_buffer, permuted_temporal_pixel_id, 0); + let temporal_surface = gpixel_resolve(textureLoad(previous_gbuffer, permuted_temporal_pixel_id, 0), temporal_depth, permuted_temporal_pixel_id, view.main_pass_viewport.zw, previous_view.world_from_clip); + if pixel_dissimilar(depth, world_position, temporal_surface.world_position, world_normal, temporal_surface.world_normal, view) { + return NeighborInfo(empty_reservoir(), vec3(0.0), vec3(0.0), empty_material()); + } + + let temporal_pixel_index = permuted_temporal_pixel_id.x + permuted_temporal_pixel_id.y * u32(view.main_pass_viewport.z); + var temporal = NeighborInfo(reservoirs_a[temporal_pixel_index], temporal_surface.world_position, temporal_surface.world_normal, temporal_surface.material); + + // Check if the light selected in the previous frame no longer exists in the current frame (e.g. entity despawned) + if temporal.reservoir.light_sample.light_id != NULL_LIGHT_ID { + let previous_light_id = temporal.reservoir.light_sample.light_id >> 16u; + let triangle_id = temporal.reservoir.light_sample.light_id & 0xFFFFu; + let light_id = previous_frame_light_id_translations[previous_light_id]; + if light_id == LIGHT_NOT_PRESENT_THIS_FRAME { + return NeighborInfo(empty_reservoir(), vec3(0.0), vec3(0.0), empty_material()); + } + temporal.reservoir.light_sample.light_id = (light_id << 16u) | triangle_id; + } + + temporal.reservoir.confidence_weight = min(temporal.reservoir.confidence_weight, constants.confidence_weight_cap); + + return temporal; +} + +fn load_spatial_reservoir(pixel_id: vec2, depth: f32, world_position: vec3, world_normal: vec3, rng: ptr) -> NeighborInfo { + for (var i = 0u; i < 5u; i++) { + let spatial_pixel_id = get_neighbor_pixel_id(pixel_id, SPATIAL_REUSE_RADIUS_PIXELS, rng); + + if all(spatial_pixel_id == pixel_id) { + continue; + } + + let spatial_depth = textureLoad(depth_buffer, spatial_pixel_id, 0); + let spatial_surface = gpixel_resolve(textureLoad(gbuffer, spatial_pixel_id, 0), spatial_depth, spatial_pixel_id, view.main_pass_viewport.zw, view.world_from_clip); + if pixel_dissimilar(depth, world_position, spatial_surface.world_position, world_normal, spatial_surface.world_normal, view) { + continue; + } + + let spatial_pixel_index = spatial_pixel_id.x + spatial_pixel_id.y * u32(view.main_pass_viewport.z); + return NeighborInfo(reservoirs_b[spatial_pixel_index], spatial_surface.world_position, spatial_surface.world_normal, spatial_surface.material); + } + + return NeighborInfo(empty_reservoir(), world_position, world_normal, empty_material()); +} + +fn get_neighbor_pixel_id(center_pixel_id: vec2, search_radius: f32, rng: ptr) -> vec2 { + var spatial_id = vec2(center_pixel_id) + sample_disk(search_radius, rng); + spatial_id = clamp(spatial_id, vec2(0.0), view.main_pass_viewport.zw - 1.0); + return vec2(spatial_id); +} + +struct NeighborInfo { + reservoir: Reservoir, + world_position: vec3, + world_normal: vec3, + material: ResolvedMaterial, +} + +fn empty_material() -> ResolvedMaterial { + return ResolvedMaterial(vec3(0.0), vec3(0.0), 0.0, 0.0, 0.0, 0.0); +} + +fn jacobian( + new_world_position: vec3, + original_world_position: vec3, + sample_point_world_position: vec3, + sample_point_world_normal: vec3, +) -> f32 { + let r = new_world_position - sample_point_world_position; + let q = original_world_position - sample_point_world_position; + let rl = length(r); + let ql = length(q); + let phi_r = saturate(dot(r / rl, sample_point_world_normal)); + let phi_q = saturate(dot(q / ql, sample_point_world_normal)); + let jacobian = (phi_r * ql * ql) / (phi_q * rl * rl); + return select(jacobian, 0.0, isinf(jacobian) || isnan(jacobian)); +} + +struct ReservoirMergeResult { + merged_reservoir: Reservoir, + selected_sample_brdf_radiance: vec3, +} + +fn merge_reservoirs( + canonical_reservoir: Reservoir, + canonical_world_position: vec3, + canonical_world_normal: vec3, + canonical_material: ResolvedMaterial, + other_reservoir: Reservoir, + other_world_position: vec3, + other_world_normal: vec3, + other_material: ResolvedMaterial, + other_view_position: vec3, + rng: ptr, +) -> ReservoirMergeResult { + var canonical_resolved: ResolvedLightSample; + if canonical_reservoir.light_sample.light_id != NULL_LIGHT_ID { + canonical_resolved = resolve_light_sample(canonical_reservoir.light_sample, light_sources[canonical_reservoir.light_sample.light_id >> 16u]); + } + + let canonical_wo = normalize(view.world_position - canonical_world_position); + let canonical_NdotV = max(dot(canonical_world_normal, canonical_wo), 0.0001); + let canonical_F_ab = F_AB(canonical_material.perceptual_roughness, canonical_NdotV); + let canonical_sample_at_canonical = reservoir_contribution(canonical_reservoir, canonical_resolved, canonical_world_position, canonical_world_normal, canonical_wo, canonical_material, canonical_F_ab); + + // Skip resampling empty reservoirs + if other_reservoir.confidence_weight == 0.0 { + return ReservoirMergeResult(canonical_reservoir, canonical_sample_at_canonical.brdf_radiance); + } + + var other_resolved: ResolvedLightSample; + if other_reservoir.light_sample.light_id != NULL_LIGHT_ID { + other_resolved = resolve_light_sample(other_reservoir.light_sample, light_sources[other_reservoir.light_sample.light_id >> 16u]); + } + let other_wo = normalize(other_view_position - other_world_position); + let other_NdotV = max(dot(other_world_normal, other_wo), 0.0001); + let other_F_ab = F_AB(other_material.perceptual_roughness, other_NdotV); + + // Contributions for resampling and MIS + var other_sample_at_canonical = reservoir_contribution(other_reservoir, other_resolved, canonical_world_position, canonical_world_normal, canonical_wo, canonical_material, canonical_F_ab); + var canonical_sample_at_other = reservoir_contribution(canonical_reservoir, canonical_resolved, other_world_position, other_world_normal, other_wo, other_material, other_F_ab); + let other_sample_at_other = reservoir_contribution(other_reservoir, other_resolved, other_world_position, other_world_normal, other_wo, other_material, other_F_ab); + + // Jacobians for resampling and MIS. Light samples don't need a reprojection jacobian, + // since calculate_resolved_light_contribution already accounts for the shading point's geometry. + var other_sample_at_canonical_jacobian = 1.0; + if other_reservoir.light_sample.light_id == NULL_LIGHT_ID { + other_sample_at_canonical_jacobian = jacobian( + canonical_world_position, + other_world_position, + other_reservoir.sample_point_world_position, + octahedral_decode(other_reservoir.sample_point_world_normal) + ); + } + var canonical_sample_at_other_jacobian = 1.0; + if canonical_reservoir.light_sample.light_id == NULL_LIGHT_ID { + canonical_sample_at_other_jacobian = jacobian( + other_world_position, + canonical_world_position, + canonical_reservoir.sample_point_world_position, + octahedral_decode(canonical_reservoir.sample_point_world_normal) + ); + } + + // Don't merge samples with huge jacobians, as it explodes the variance + if other_sample_at_canonical_jacobian < 0.125 || other_sample_at_canonical_jacobian > 8.0 { + other_sample_at_canonical_jacobian = 0.0; + } + if canonical_sample_at_other_jacobian < 0.125 || canonical_sample_at_other_jacobian > 8.0 { + canonical_sample_at_other_jacobian = 0.0; + } + + // Visibility for the cross-domain targets + if other_sample_at_canonical.target_function > 0.0 && other_sample_at_canonical_jacobian > 0.0 { + let visibility = trace_visibility(canonical_world_position + canonical_world_normal * RAY_T_MIN, other_sample_at_canonical.sample_world_position); + other_sample_at_canonical.target_function *= visibility; + } + if canonical_sample_at_other.target_function > 0.0 && canonical_sample_at_other_jacobian > 0.0 { + @if(SPATIAL_MERGE) + let visibility = trace_visibility(other_world_position + other_world_normal * RAY_T_MIN, canonical_sample_at_other.sample_world_position); + @else + let visibility = trace_visibility_previous_frame(other_world_position + other_world_normal * RAY_T_MIN, canonical_sample_at_other.sample_world_position); + canonical_sample_at_other.target_function *= visibility; + } + + // Defensive balance heuristic MIS (for spatial reuse only) + let total_confidence_weight = canonical_reservoir.confidence_weight + other_reservoir.confidence_weight; + var defensive_t_c = 0.0; + @if(SPATIAL_MERGE) + defensive_t_c = select(1.0, canonical_reservoir.confidence_weight / total_confidence_weight, total_confidence_weight > 0.0); + + // Resampling weight for canonical sample + let canonical_balance_mis_weight = balance_heuristic( + canonical_reservoir.confidence_weight * canonical_sample_at_canonical.target_function, + other_reservoir.confidence_weight * canonical_sample_at_other.target_function * canonical_sample_at_other_jacobian, + ); + let canonical_sample_mis_weight = mix(canonical_balance_mis_weight, 1.0, defensive_t_c); + let canonical_sample_resampling_weight = canonical_sample_mis_weight * canonical_sample_at_canonical.target_function * canonical_reservoir.unbiased_contribution_weight; + + // Resampling weight for other sample + let other_balance_mis_weight = balance_heuristic( + other_reservoir.confidence_weight * other_sample_at_other.target_function, + canonical_reservoir.confidence_weight * other_sample_at_canonical.target_function * other_sample_at_canonical_jacobian, + ); + let other_sample_mis_weight = mix(other_balance_mis_weight, 0.0, defensive_t_c); + let other_sample_resampling_weight = other_sample_mis_weight * other_sample_at_canonical.target_function * other_reservoir.unbiased_contribution_weight * other_sample_at_canonical_jacobian; + + // Perform resampling + var combined_reservoir = empty_reservoir(); + combined_reservoir.confidence_weight = canonical_reservoir.confidence_weight + other_reservoir.confidence_weight; + let weight_sum = canonical_sample_resampling_weight + other_sample_resampling_weight; + + if rand_f(rng) * weight_sum < other_sample_resampling_weight { + combined_reservoir.sample_point_world_position = other_reservoir.sample_point_world_position; + combined_reservoir.sample_point_world_normal = other_reservoir.sample_point_world_normal; + combined_reservoir.radiance = other_reservoir.radiance; + combined_reservoir.light_sample = other_reservoir.light_sample; + + let inverse_target_function = select(0.0, 1.0 / other_sample_at_canonical.target_function, other_sample_at_canonical.target_function > 0.0); + combined_reservoir.unbiased_contribution_weight = weight_sum * inverse_target_function; + + return ReservoirMergeResult(combined_reservoir, other_sample_at_canonical.brdf_radiance); + } else { + combined_reservoir.sample_point_world_position = canonical_reservoir.sample_point_world_position; + combined_reservoir.sample_point_world_normal = canonical_reservoir.sample_point_world_normal; + combined_reservoir.radiance = canonical_reservoir.radiance; + combined_reservoir.light_sample = canonical_reservoir.light_sample; + + let inverse_target_function = select(0.0, 1.0 / canonical_sample_at_canonical.target_function, canonical_sample_at_canonical.target_function > 0.0); + combined_reservoir.unbiased_contribution_weight = weight_sum * inverse_target_function; + + return ReservoirMergeResult(combined_reservoir, canonical_sample_at_canonical.brdf_radiance); + } +} + +struct ReservoirContribution { + brdf_radiance: vec3, + target_function: f32, + sample_world_position: vec4, +} + +fn reservoir_contribution(reservoir: Reservoir, resolved: ResolvedLightSample, world_position: vec3, world_normal: vec3, wo: vec3, material: ResolvedMaterial, F_ab: vec2) -> ReservoirContribution { + if reservoir.light_sample.light_id != NULL_LIGHT_ID { + let light_contribution = calculate_resolved_light_contribution(resolved, world_position, world_normal); + + // MIS weight against the bounce-0 BRDF-emissive strategy, recomputed from this surface's + // brdf and material rather than baked into the unbiased contribution weight at generation. Mirrors the bounce-0 + // nee_mis_weight in generate_nee_candidate and generate_emissive_candidate, which puts the same factor in the target. + var nee_mis_weight = 1.0; + if light_contribution.brdf_rays_can_hit && light_contribution.inverse_solid_angle_pdf > 0.0 { + let light_count = arrayLength(&light_sources); + let inverse_solid_angle_pdf = light_contribution.inverse_solid_angle_pdf * f32(light_count); + let p_nee = mix(1.0, material.perceptual_roughness, material.metallic); + let p_nee_strategy = f32(constants.primary_di_samples) * (1.0 / inverse_solid_angle_pdf) * p_nee; + let p_brdf_at_nee = brdf_pdf(wo, light_contribution.wi, world_normal, material, F_ab); + nee_mis_weight = power_heuristic(p_nee_strategy, p_brdf_at_nee); + } + + let brdf_radiance = light_contribution.radiance * evaluate_brdf(wo, light_contribution.wi, world_normal, material, F_ab) * nee_mis_weight; + return ReservoirContribution(brdf_radiance, luminance(brdf_radiance), resolved.world_position); + } else if any(reservoir.radiance != vec3(0.0)) { + let delta = reservoir.sample_point_world_position - (world_position + world_normal * RAY_T_MIN); + let sample_distance = length(delta); + let wi = delta / sample_distance; + var brdf_radiance = reservoir.radiance * evaluate_brdf(wo, wi, world_normal, material, F_ab); + + // Bounce-0 BRDF-emissive sample (directly-visible light). The seed field carries the light + // triangle's bitcast area pdf, and the stored radiance is the raw emission. Rebuild the MIS + // weight against this surface's NEE strategy, the dual of nee_mis_weight above and a mirror + // of the emissive candidate in generate_initial_path. + if reservoir.light_sample.seed != 0u { + let area_pdf = bitcast(reservoir.light_sample.seed); + let light_normal = octahedral_decode(reservoir.sample_point_world_normal); + let cos_theta_light = dot(-wi, light_normal); + if cos_theta_light <= 0.0 { + brdf_radiance = vec3(0.0); + } else { + let p_light = area_pdf * sample_distance * sample_distance / cos_theta_light; + let p_nee = mix(1.0, material.perceptual_roughness, material.metallic); + let p_brdf = brdf_pdf(wo, wi, world_normal, material, F_ab); + brdf_radiance *= power_heuristic(p_brdf, p_light * p_nee * f32(constants.primary_di_samples)); + } + } + + return ReservoirContribution(brdf_radiance, luminance(brdf_radiance), vec4(reservoir.sample_point_world_position, 1.0)); + } else { + return ReservoirContribution(vec3(0.0), 0.0, vec4(reservoir.sample_point_world_position, 1.0)); + } +} diff --git a/src/realtime/world_cache_compact.wesl b/src/realtime/world_cache_compact.wesl new file mode 100644 index 0000000..bdd4f80 --- /dev/null +++ b/src/realtime/world_cache_compact.wesl @@ -0,0 +1,79 @@ +import package::realtime::world_cache_query::WORLD_CACHE_EMPTY_CELL; +import package::realtime::bindings::{ + world_cache, +}; + +enable wgpu_ray_query; + +@group(2) @binding(0) var world_cache_active_cells_dispatch: vec3; + +var w1: array; +var w2: array; + +@compute @workgroup_size(1024, 1, 1) +fn decay_world_cache(@builtin(global_invocation_id) global_id: vec3) { + var life = world_cache.life[global_id.x]; + if life > 0u { + life -= 1u; + world_cache.life[global_id.x] = life; + + if life == 0u { + world_cache.checksums[global_id.x] = WORLD_CACHE_EMPTY_CELL; + world_cache.radiance[global_id.x] = vec4(0.0); + world_cache.luminance_deltas[global_id.x] = 0.0; + } + } +} + +@compute @workgroup_size(1024, 1, 1) +fn compact_world_cache_single_block( + @builtin(global_invocation_id) cell_id: vec3, + @builtin(local_invocation_index) t: u32, +) { + if t == 0u { w1[0u] = 0u; } else { w1[t] = u32(world_cache.life[cell_id.x - 1u] != 0u); }; workgroupBarrier(); + if t < 1u { w2[t] = w1[t]; } else { w2[t] = w1[t] + w1[t - 1u]; } workgroupBarrier(); + if t < 2u { w1[t] = w2[t]; } else { w1[t] = w2[t] + w2[t - 2u]; } workgroupBarrier(); + if t < 4u { w2[t] = w1[t]; } else { w2[t] = w1[t] + w1[t - 4u]; } workgroupBarrier(); + if t < 8u { w1[t] = w2[t]; } else { w1[t] = w2[t] + w2[t - 8u]; } workgroupBarrier(); + if t < 16u { w2[t] = w1[t]; } else { w2[t] = w1[t] + w1[t - 16u]; } workgroupBarrier(); + if t < 32u { w1[t] = w2[t]; } else { w1[t] = w2[t] + w2[t - 32u]; } workgroupBarrier(); + if t < 64u { w2[t] = w1[t]; } else { w2[t] = w1[t] + w1[t - 64u]; } workgroupBarrier(); + if t < 128u { w1[t] = w2[t]; } else { w1[t] = w2[t] + w2[t - 128u]; } workgroupBarrier(); + if t < 256u { w2[t] = w1[t]; } else { w2[t] = w1[t] + w1[t - 256u]; } workgroupBarrier(); + if t < 512u { world_cache.a[cell_id.x] = w2[t]; } else { world_cache.a[cell_id.x] = w2[t] + w2[t - 512u]; } +} + +@compute @workgroup_size(1024, 1, 1) +fn compact_world_cache_blocks(@builtin(local_invocation_index) t: u32) { + if t == 0u { w1[0u] = 0u; } else { w1[t] = world_cache.a[t * 1024u - 1u] + u32(world_cache.life[t * 1024u - 1u] != 0u); }; workgroupBarrier(); + if t < 1u { w2[t] = w1[t]; } else { w2[t] = w1[t] + w1[t - 1u]; } workgroupBarrier(); + if t < 2u { w1[t] = w2[t]; } else { w1[t] = w2[t] + w2[t - 2u]; } workgroupBarrier(); + if t < 4u { w2[t] = w1[t]; } else { w2[t] = w1[t] + w1[t - 4u]; } workgroupBarrier(); + if t < 8u { w1[t] = w2[t]; } else { w1[t] = w2[t] + w2[t - 8u]; } workgroupBarrier(); + if t < 16u { w2[t] = w1[t]; } else { w2[t] = w1[t] + w1[t - 16u]; } workgroupBarrier(); + if t < 32u { w1[t] = w2[t]; } else { w1[t] = w2[t] + w2[t - 32u]; } workgroupBarrier(); + if t < 64u { w2[t] = w1[t]; } else { w2[t] = w1[t] + w1[t - 64u]; } workgroupBarrier(); + if t < 128u { w1[t] = w2[t]; } else { w1[t] = w2[t] + w2[t - 128u]; } workgroupBarrier(); + if t < 256u { w2[t] = w1[t]; } else { w2[t] = w1[t] + w1[t - 256u]; } workgroupBarrier(); + if t < 512u { world_cache.b[t] = w2[t]; } else { world_cache.b[t] = w2[t] + w2[t - 512u]; } +} + +@compute @workgroup_size(1024, 1, 1) +fn compact_world_cache_write_active_cells( + @builtin(global_invocation_id) cell_id: vec3, + @builtin(workgroup_id) workgroup_id: vec3, + @builtin(local_invocation_index) thread_index: u32, +) { + let compacted_index = world_cache.a[cell_id.x] + world_cache.b[workgroup_id.x]; + let cell_active = world_cache.life[cell_id.x] != 0u; + + if cell_active { + world_cache.active_cell_indices[compacted_index] = cell_id.x; + } + + if thread_index == 1023u && workgroup_id.x == 1023u { + let active_cell_count = compacted_index + u32(cell_active); + world_cache.active_cells_count = active_cell_count; + world_cache_active_cells_dispatch = vec3((active_cell_count + 63u) / 64u, 1u, 1u); + } +} diff --git a/src/realtime/world_cache_query.wesl b/src/realtime/world_cache_query.wesl new file mode 100644 index 0000000..02a6b8c --- /dev/null +++ b/src/realtime/world_cache_query.wesl @@ -0,0 +1,116 @@ +import constants::WORLD_CACHE_SIZE; +import bevy_pbr::render::utils::{rand_f, rand_vec2f}; +import bevy_render::maths::orthonormalize; +import package::realtime::bindings::{ + world_cache, + constants, +}; + +enable wgpu_ray_query; + +/// Maximum amount of frames a cell can live for without being queried +const WORLD_CACHE_CELL_LIFETIME: u32 = 10u; +/// Maximum amount of attempts to find a cache entry after a hash collision +const WORLD_CACHE_MAX_SEARCH_STEPS: u32 = 3u; + +/// Marker value for an empty cell +const WORLD_CACHE_EMPTY_CELL: u32 = 0u; + +@if(!WORLD_CACHE_NON_ATOMIC_LIFE_BUFFER) +fn query_world_cache(world_position_in: vec3, world_normal: vec3, view_position: vec3, ray_t: f32, cell_lifetime: u32, rng: ptr) -> vec3 { + var world_position = world_position_in; + var cell_size = get_cell_size(world_position, view_position, ray_t, rng); + +@if(!NO_JITTER_WORLD_CACHE) { + // Jitter query point, which essentially blurs the cache a bit so it's not so grid-like + // https://tomclabault.github.io/blog/2025/regir, jitter_world_position_tangent_plane + let TBN = orthonormalize(world_normal); + let offset = (rand_vec2f(rng) * 2.0 - 1.0) * cell_size * 0.5; + world_position += offset.x * TBN[0] + offset.y * TBN[1]; + cell_size = get_cell_size(world_position, view_position, ray_t, rng); +} + + let world_position_quantized = bitcast>(quantize_position(world_position, cell_size)); + let world_normal_quantized = bitcast>(quantize_normal(world_normal)); + var key = compute_key(world_position_quantized, world_normal_quantized); + let checksum = compute_checksum(world_position_quantized, world_normal_quantized); + + for (var i = 0u; i < WORLD_CACHE_MAX_SEARCH_STEPS; i++) { + let cas = atomicCompareExchangeWeak(&world_cache.checksums[key], WORLD_CACHE_EMPTY_CELL, checksum); + let existing_checksum = cas.old_value; + + // Cell already exists or is empty - reset lifetime + if existing_checksum == checksum || existing_checksum == WORLD_CACHE_EMPTY_CELL { + @if(!WORLD_CACHE_QUERY_ATOMIC_MAX_LIFETIME) + atomicStore(&world_cache.life[key], cell_lifetime); + @else + atomicMax(&world_cache.life[key], cell_lifetime); + } + + if existing_checksum == checksum { + // Cache entry already exists - get radiance + return world_cache.radiance[key].rgb; + } else if existing_checksum == WORLD_CACHE_EMPTY_CELL && cas.exchanged { + // Cell is empty - initialize it + world_cache.geometry_data[key].world_position = world_position; + world_cache.geometry_data[key].world_normal = world_normal; + return vec3(0.0); + } else { + // Collision - linear probe to next entry + key += 1u; + } + } + + return vec3(0.0); +} + +fn get_cell_size(world_position: vec3, view_position: vec3, ray_t: f32, rng: ptr) -> f32 { + let camera_distance = distance(view_position, world_position) / constants.world_cache_position_lod_scale; + let lod_f = log2(1.0 + camera_distance); + let lod_fract = fract(lod_f); + let lod = floor(lod_f) + select(0.0, 1.0, rand_f(rng) < lod_fract * lod_fract * lod_fract); + return constants.world_cache_position_base_cell_size * exp2(lod); +} + +fn quantize_position(world_position: vec3, quantization_factor: f32) -> vec3 { + return floor(world_position / quantization_factor + 0.0001); +} + +fn quantize_normal(world_normal: vec3) -> vec3 { + return floor(world_normal + 0.0001); +} + +fn compute_key(world_position: vec3, world_normal: vec3) -> u32 { + var key = pcg_hash(world_position.x); + key = pcg_hash(key + world_position.y); + key = pcg_hash(key + world_position.z); + key = pcg_hash(key + world_normal.x); + key = pcg_hash(key + world_normal.y); + key = pcg_hash(key + world_normal.z); + return wrap_key(key); +} + +fn compute_checksum(world_position: vec3, world_normal: vec3) -> u32 { + var key = iqint_hash(world_position.x); + key = iqint_hash(key + world_position.y); + key = iqint_hash(key + world_position.z); + key = iqint_hash(key + world_normal.x); + key = iqint_hash(key + world_normal.y); + key = iqint_hash(key + world_normal.z); + return max(key, 1u); // 0u is reserved for WORLD_CACHE_EMPTY_CELL +} + +fn pcg_hash(input: u32) -> u32 { + let state = input * 747796405u + 2891336453u; + let word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u; + return (word >> 22u) ^ word; +} + +fn iqint_hash(input: u32) -> u32 { + let n = (input << 13u) ^ input; + return n * (n * n * 15731u + 789221u) + 1376312589u; +} + +fn wrap_key(key: u32) -> u32 { + return key & (u32(WORLD_CACHE_SIZE) - 1u); +} diff --git a/src/realtime/world_cache_update.wesl b/src/realtime/world_cache_update.wesl new file mode 100644 index 0000000..d04b07f --- /dev/null +++ b/src/realtime/world_cache_update.wesl @@ -0,0 +1,122 @@ +import bevy_core_pipeline::tonemapping::tonemapping_luminance as luminance; +import bevy_pbr::render::utils::{rand_f, rand_range_u, sample_cosine_hemisphere}; +import bevy_render::maths::PI; +import package::realtime::presample_light_tiles::unpack_resolved_light_sample; +import package::scene::sampling::{calculate_resolved_light_contribution, trace_visibility, sample_environment_map_light}; +import package::scene::bindings::{trace_ray, resolve_ray_hit_full, RAY_T_MIN}; +import package::realtime::world_cache_query::query_world_cache; +import package::realtime::bindings::{ + light_tile_resolved_samples, + view, + constants, + world_cache, +}; + +enable wgpu_ray_query; + +@compute @workgroup_size(64, 1, 1) +fn sample_di(@builtin(workgroup_id) workgroup_id: vec3, @builtin(global_invocation_id) active_cell_id: vec3) { + if active_cell_id.x >= world_cache.active_cells_count { return; } + + let cell_index = world_cache.active_cell_indices[active_cell_id.x]; + let geometry_data = world_cache.geometry_data[cell_index]; + var rng = cell_index + constants.frame_rng; + + if rand_f(&rng) >= f32(constants.world_cache_cell_updates_soft_target) / f32(world_cache.active_cells_count) { return; } + + let new_radiance = sample_random_light_ris(geometry_data.world_position, geometry_data.world_normal, workgroup_id.xy, &rng); + + world_cache.active_cells_new_radiance[active_cell_id.x] = new_radiance; +} + +@compute @workgroup_size(64, 1, 1) +fn sample_gi(@builtin(workgroup_id) workgroup_id: vec3, @builtin(global_invocation_id) active_cell_id: vec3) { + if active_cell_id.x >= world_cache.active_cells_count { return; } + + let cell_index = world_cache.active_cell_indices[active_cell_id.x]; + let geometry_data = world_cache.geometry_data[cell_index]; + var rng = cell_index + constants.frame_rng; + + if rand_f(&rng) >= f32(constants.world_cache_cell_updates_soft_target) / f32(world_cache.active_cells_count) { return; } + + let ray_direction = sample_cosine_hemisphere(geometry_data.world_normal, &rng); + let ray = trace_ray(geometry_data.world_position + (geometry_data.world_normal * RAY_T_MIN), ray_direction, RAY_T_MIN, constants.world_cache_max_gi_ray_distance, RAY_FLAG_NONE); + if ray.kind != RAY_QUERY_INTERSECTION_NONE { + let ray_hit = resolve_ray_hit_full(ray); + let cell_life = atomicLoad(&world_cache.life[cell_index]); + let radiance = query_world_cache(ray_hit.world_position, ray_hit.geometric_world_normal, view.world_position, ray.t, cell_life, &rng); + world_cache.active_cells_new_radiance[active_cell_id.x] += ray_hit.material.base_color * radiance; + } else { + // The ray is cut short at world_cache_max_gi_ray_distance to save on traversal costs. + // A miss here may actually have been a surface further away if we kept tracing, and not actually have been a miss. + // We could be leaking sky light due to this if world_cache_max_gi_ray_distance is too small. + world_cache.active_cells_new_radiance[active_cell_id.x] += PI * sample_environment_map_light(ray_direction); + } +} + +@compute @workgroup_size(64, 1, 1) +fn blend_new_samples(@builtin(global_invocation_id) active_cell_id: vec3) { + if active_cell_id.x >= world_cache.active_cells_count { return; } + + let cell_index = world_cache.active_cell_indices[active_cell_id.x]; + var rng = cell_index + constants.frame_rng; + + if rand_f(&rng) >= f32(constants.world_cache_cell_updates_soft_target) / f32(world_cache.active_cells_count) { return; } + + let old_radiance = world_cache.radiance[cell_index]; + let new_radiance = world_cache.active_cells_new_radiance[active_cell_id.x]; + let luminance_delta = world_cache.luminance_deltas[cell_index]; + + // https://bsky.app/profile/gboisse.bsky.social/post/3m5blga3ftk2a + let sample_count = min(old_radiance.a + 1.0, constants.world_cache_max_temporal_samples); + let alpha = abs(luminance_delta) / max(luminance(old_radiance.rgb), 0.001); + let max_sample_count = mix(constants.world_cache_max_temporal_samples, 1.0, pow(saturate(alpha), 1.0 / 8.0)); + var blend_amount = 1.0 / min(sample_count, max_sample_count); + if bool(constants.reset) { + blend_amount = 1.0; + } + + let blended_radiance = mix(old_radiance.rgb, new_radiance, blend_amount); + let blended_luminance_delta = select(mix(luminance_delta, luminance(blended_radiance) - luminance(old_radiance.rgb), 1.0 / 8.0), 0.0, bool(constants.reset)); + + world_cache.radiance[cell_index] = vec4(blended_radiance, sample_count); + world_cache.luminance_deltas[cell_index] = blended_luminance_delta; +} + +fn sample_random_light_ris(world_position: vec3, world_normal: vec3, workgroup_id: vec2, rng: ptr) -> vec3 { + var workgroup_rng = (workgroup_id.x * 5782582u) + workgroup_id.y; + let light_tile_start = rand_range_u(128u, &workgroup_rng) * 1024u; + + var weight_sum = 0.0; + var selected_sample_radiance = vec3(0.0); + var selected_sample_target_function = 0.0; + var selected_sample_world_position = vec4(0.0); + let mis_weight = 1.0 / f32(constants.world_cache_direct_light_sample_count); + for (var i = 0u; i < constants.world_cache_direct_light_sample_count; i++) { + let tile_sample = light_tile_start + rand_range_u(1024u, rng); + let resolved_light_sample = unpack_resolved_light_sample(light_tile_resolved_samples[tile_sample], view.exposure); + let light_contribution = calculate_resolved_light_contribution(resolved_light_sample, world_position, world_normal); + + let contribution = light_contribution.radiance * saturate(dot(light_contribution.wi, world_normal)); + let target_function = luminance(contribution); + let resampling_weight = mis_weight * (target_function * light_contribution.inverse_pdf); + + weight_sum += resampling_weight; + + if rand_f(rng) * weight_sum < resampling_weight { + selected_sample_radiance = contribution; + selected_sample_target_function = target_function; + selected_sample_world_position = resolved_light_sample.world_position; + } + } + + var unbiased_contribution_weight = 0.0; + if any(selected_sample_radiance != vec3(0.0)) { + let inverse_target_function = select(0.0, 1.0 / selected_sample_target_function, selected_sample_target_function > 0.0); + unbiased_contribution_weight = weight_sum * inverse_target_function; + + unbiased_contribution_weight *= trace_visibility(world_position + (world_normal * RAY_T_MIN), selected_sample_world_position); + } + + return selected_sample_radiance * unbiased_contribution_weight; +} diff --git a/src/scene/binder/allocator.rs b/src/scene/binder/allocator.rs new file mode 100644 index 0000000..e6476af --- /dev/null +++ b/src/scene/binder/allocator.rs @@ -0,0 +1,245 @@ +use bevy_platform::collections::HashMap; +use core::{hash::Hash, num::NonZeroU32}; + +/// A free-list allocator for `u32` array indices meant for GPU allocations. +pub struct IndexAllocator { + free: Vec, + high_water_mark: u32, +} + +impl IndexAllocator { + pub fn new() -> Self { + Self { + free: Vec::new(), + high_water_mark: 0, + } + } + + /// An exclusive upper bound on every index handed out, for sizing and dispatching over the data + /// they key. + /// + /// Not a live count: released indices leave holes below it, and it never shrinks. + pub fn high_water_mark(&self) -> u32 { + self.high_water_mark + } + + pub fn allocate(&mut self) -> u32 { + self.free.pop().unwrap_or_else(|| { + let index = self.high_water_mark; + self.high_water_mark += 1; + index + }) + } + + pub fn release(&mut self, index: u32) { + self.free.push(index); + } + + /// How many more indices can be handed out before running past `capacity`. + fn vacancies(&self, capacity: u32) -> u32 { + capacity.saturating_sub(self.high_water_mark) + self.free.len() as u32 + } +} + +/// Assigns each key an index that stays put for as long as the key is live. +pub struct SlotAllocator { + slots: HashMap, + indices: IndexAllocator, +} + +impl SlotAllocator { + pub fn new() -> Self { + Self { + slots: HashMap::default(), + indices: IndexAllocator::new(), + } + } + + pub fn get(&self, key: &K) -> Option { + self.slots.get(key).copied() + } + + pub fn contains(&self, key: &K) -> bool { + self.slots.contains_key(key) + } + + pub fn keys(&self) -> impl Iterator { + self.slots.keys() + } + + pub fn get_or_allocate(&mut self, key: K) -> u32 { + if let Some(&slot) = self.slots.get(&key) { + return slot; + } + + let slot = self.indices.allocate(); + self.slots.insert(key, slot); + slot + } + + pub fn remove(&mut self, key: &K) -> Option { + let slot = self.slots.remove(key)?; + self.indices.release(slot); + Some(slot) + } + + /// How many more distinct keys can be taken on before running past `capacity`. + fn vacancies(&self, capacity: u32) -> u32 { + self.indices.vacancies(capacity) + } +} + +/// One occupied slot of a [`RetainedBindingArray`]. +struct BindingSlot { + item: T, + /// Live references to this slot. An occupied slot always has at least one live reference. + references: NonZeroU32, +} + +/// A binding array whose indices are stable across frames. +/// +/// Slots are reference counted by whatever points at them (e.g. materials for textures, instances for +/// mesh slab buffers), and are reused once the last reference goes away. +/// +/// `dirty` marks that the contents have changed and the bind group has to be rebuilt. +pub struct RetainedBindingArray { + allocator: SlotAllocator, + slots: Vec>>, + pub dirty: bool, +} + +impl RetainedBindingArray { + pub fn new() -> Self { + Self { + allocator: SlotAllocator::new(), + slots: Vec::new(), + dirty: false, + } + } + + pub fn contains(&self, key: &K) -> bool { + self.allocator.contains(key) + } + + /// How many more distinct keys can be held before running past `capacity`. + pub fn vacancies(&self, capacity: u32) -> u32 { + self.allocator.vacancies(capacity) + } + + /// Whether [`Self::acquire`] would be able to hand out a reference to `key`. + /// + /// Callers that need more than one slot at once check this for all of them before acquiring + /// any, so that they never have to hand a slot straight back. + pub fn has_room(&self, key: &K, capacity: u32) -> bool { + self.contains(key) || self.vacancies(capacity) > 0 + } + + /// The array's contents in slot order, with `None` for slots that are currently free. + pub fn iter(&self) -> impl Iterator> { + self.slots + .iter() + .map(|slot| slot.as_ref().map(|slot| &slot.item)) + } + + /// Takes a reference to `key`'s slot, allocating and filling it if this is the first one. + /// + /// Returns `None` if `key` would need a new slot and every slot below `capacity` is taken. The + /// bind group layout declares these arrays with a fixed length, so running past it makes + /// `create_bind_group` fail outright, and callers have to drop whatever wanted the slot. + pub fn acquire(&mut self, key: K, capacity: u32, item: impl FnOnce() -> T) -> Option { + if !self.has_room(&key, capacity) { + return None; + } + + let slot = self.allocator.get_or_allocate(key); + let index = slot as usize; + + if self.slots.len() <= index { + self.slots.resize_with(index + 1, || None); + } + + if let Some(occupied) = self.slots[index].as_mut() { + occupied.references = occupied.references.saturating_add(1); + } else { + self.slots[index] = Some(BindingSlot { + item: item(), + references: NonZeroU32::MIN, + }); + self.dirty = true; + } + + Some(slot) + } + + /// Drops a reference to `key`'s slot, freeing it if that was the last one. + pub fn release(&mut self, key: &K) { + let Some(slot) = self.allocator.get(key) else { + return; + }; + let index = slot as usize; + let Some(occupied) = self.slots[index].as_mut() else { + return; + }; + + if let Some(remaining) = NonZeroU32::new(occupied.references.get() - 1) { + occupied.references = remaining; + return; + } + + self.slots[index] = None; + self.allocator.remove(key); + self.dirty = true; + } + + /// Repoints an already-allocated slot at a new value, leaving its index and refcount alone. + pub fn replace(&mut self, key: &K, item: T) { + if let Some(slot) = self.allocator.get(key) + && let Some(occupied) = self.slots[slot as usize].as_mut() + { + occupied.item = item; + self.dirty = true; + } + } +} + +#[cfg(test)] +mod tests { + use super::{IndexAllocator, RetainedBindingArray}; + + #[test] + fn index_allocator_reuses_released_slots_without_growing() { + let mut slots = IndexAllocator::new(); + + assert_eq!(slots.allocate(), 0); + assert_eq!(slots.allocate(), 1); + assert_eq!(slots.high_water_mark(), 2); + + slots.release(0); + assert_eq!(slots.allocate(), 0); + assert_eq!(slots.high_water_mark(), 2); + } + + #[test] + fn retained_binding_array_only_dirties_on_binding_changes() { + let mut bindings = RetainedBindingArray::new(); + + assert_eq!(bindings.acquire(7, 2, || 11), Some(0)); + assert!(bindings.dirty); + bindings.dirty = false; + + // Sharing the existing stable slot only changes its refcount + assert_eq!(bindings.acquire(7, 2, || 99), Some(0)); + assert!(!bindings.dirty); + assert_eq!(bindings.iter().next(), Some(Some(&11))); + + bindings.release(&7); + assert!(!bindings.dirty); + assert!(bindings.contains(&7)); + + // The final release changes the binding array and makes the slot reusable + bindings.release(&7); + assert!(bindings.dirty); + assert!(!bindings.contains(&7)); + assert_eq!(bindings.acquire(8, 2, || 22), Some(0)); + } +} diff --git a/src/scene/binder/assets.rs b/src/scene/binder/assets.rs new file mode 100644 index 0000000..0eff3dd --- /dev/null +++ b/src/scene/binder/assets.rs @@ -0,0 +1,265 @@ +use super::{ + allocator::{RetainedBindingArray, SlotAllocator}, + instances::InstanceState, + StandardMaterialAssets, +}; +use bevy_asset::AssetId; +use bevy_color::{ColorToComponents, LinearRgba}; +use bevy_image::Image; +use bevy_math::Vec3; +use bevy_pbr::StandardMaterial; +use bevy_platform::collections::{HashMap, HashSet}; +use bevy_render::{ + impl_atomic_pod, + render_asset::{ExtractedAssets, RenderAssets}, + render_resource::{AtomicPod, AtomicSparseBufferVec, BufferUsages, Sampler, TextureView}, + texture::GpuImage, +}; +use bevy_utils::once; +use bytemuck::{Pod, Zeroable}; +use core::num::NonZeroU32; +use tracing::{info_span, warn}; + +pub const MAX_TEXTURE_COUNT: NonZeroU32 = NonZeroU32::new(5_000).unwrap(); +const TEXTURE_MAP_NONE: u32 = u32::MAX; + +/// The four textures a [`StandardMaterial`] can reference, in [`GpuMaterial`] field order. +type MaterialTextures = [Option>; 4]; + +#[derive(Clone, Copy, Default, PartialEq, Pod, Zeroable)] +#[repr(C)] +pub struct GpuMaterial { + normal_map_texture_id: u32, + base_color_texture_id: u32, + emissive_texture_id: u32, + metallic_roughness_texture_id: u32, + + base_color: Vec3, + perceptual_roughness: f32, + emissive: Vec3, + metallic: f32, + _padding: Vec3, + reflectance: f32, +} + +impl_atomic_pod!(GpuMaterial, GpuMaterialBlob); + +/// Stable material and texture slots, plus the retry state for assets that aren't ready yet. +pub struct AssetState { + pub textures: RetainedBindingArray, (TextureView, Sampler)>, + pub materials: AtomicSparseBufferVec, + pub material_slots: SlotAllocator>, + material_textures: HashMap, MaterialTextures>, + pub emissive_materials: HashSet>, + /// Materials to retry because at least one required texture is not on the GPU yet. + unresolved_materials: HashSet>, + /// Bound images whose replacement GPU data has not landed yet. + pending_texture_updates: HashSet>, +} + +impl AssetState { + pub fn new() -> Self { + Self { + textures: RetainedBindingArray::new(), + materials: AtomicSparseBufferVec::new(BufferUsages::STORAGE, "solari_materials".into()), + material_slots: SlotAllocator::new(), + material_textures: HashMap::default(), + emissive_materials: HashSet::default(), + unresolved_materials: HashSet::default(), + pending_texture_updates: HashSet::default(), + } + } + + pub fn update_materials( + &mut self, + instances: &mut InstanceState, + material_assets: &StandardMaterialAssets, + texture_assets: &RenderAssets, + ) { + let _span = info_span!("update_materials").entered(); + + for material_id in &material_assets.removed { + self.remove_material(*material_id, instances); + } + for material_id in &material_assets.changed { + self.update_material(*material_id, instances, material_assets, texture_assets); + } + } + + /// Swaps in uploaded replacements and retries materials waiting on images. + pub fn update_textures( + &mut self, + instances: &mut InstanceState, + extracted_images: &ExtractedAssets, + texture_assets: &RenderAssets, + material_assets: &StandardMaterialAssets, + ) { + let _span = info_span!("update_textures").entered(); + + let mut pending = core::mem::take(&mut self.pending_texture_updates); + pending.extend(extracted_images.added.iter().copied()); + + for image_id in pending { + if !self.textures.contains(&image_id) { + continue; + } + + match texture_assets.get(image_id) { + Some(image) => self.textures.replace( + &image_id, + (image.texture_view.clone(), image.sampler.clone()), + ), + None => { + self.pending_texture_updates.insert(image_id); + } + } + } + + for material_id in core::mem::take(&mut self.unresolved_materials) { + self.update_material(material_id, instances, material_assets, texture_assets); + } + } + + /// Resolves a material's textures and writes it into its stable slot. + fn update_material( + &mut self, + material_id: AssetId, + instances: &mut InstanceState, + material_assets: &StandardMaterialAssets, + texture_assets: &RenderAssets, + ) { + let Some(material) = material_assets.get(&material_id) else { + self.remove_material(material_id, instances); + return; + }; + + let was_resolved = self.material_slots.contains(&material_id); + let handles = [ + &material.normal_map_texture, + &material.base_color_texture, + &material.emissive_texture, + &material.metallic_roughness_texture, + ]; + + // Resolve first so a missing texture leaves no partially acquired slots + let mut textures: MaterialTextures = [None; 4]; + for (slot, handle) in textures.iter_mut().zip(handles) { + let Some(handle) = handle else { continue }; + let image_id = handle.id(); + if texture_assets.get(image_id).is_none() { + self.defer_material(material_id, instances); + return; + } + *slot = Some(image_id); + } + + if self.new_texture_count(&textures) > self.textures.vacancies(MAX_TEXTURE_COUNT.get()) { + // At the limit, release the old set once so a replacement can reuse those slots + self.release_material_textures(material_id); + self.material_textures.remove(&material_id); + + if self.new_texture_count(&textures) > self.textures.vacancies(MAX_TEXTURE_COUNT.get()) + { + once!(warn!( + "Solari scene needs more than {} textures. Materials past that limit will not \ + be rendered.", + MAX_TEXTURE_COUNT.get() + )); + self.defer_material(material_id, instances); + return; + } + } + + let mut texture_ids = [TEXTURE_MAP_NONE; 4]; + for (texture_id, image_id) in texture_ids.iter_mut().zip(textures) { + let Some(image_id) = image_id else { continue }; + let image = texture_assets.get(image_id).unwrap(); + if let Some(slot) = self + .textures + .acquire(image_id, MAX_TEXTURE_COUNT.get(), || { + (image.texture_view.clone(), image.sampler.clone()) + }) + { + *texture_id = slot; + } + } + + self.release_material_textures(material_id); + self.material_textures.insert(material_id, textures); + self.unresolved_materials.remove(&material_id); + + let slot = self.material_slots.get_or_allocate(material_id); + let emissive = material.emissive.to_vec3(); + let is_emissive = emissive != Vec3::ZERO; + self.materials.grow_and_set( + slot, + GpuMaterial { + normal_map_texture_id: texture_ids[0], + base_color_texture_id: texture_ids[1], + emissive_texture_id: texture_ids[2], + metallic_roughness_texture_id: texture_ids[3], + base_color: LinearRgba::from(material.base_color).to_vec3(), + perceptual_roughness: material.perceptual_roughness.clamp(0.0, 1.0), + emissive, + metallic: material.metallic.clamp(0.0, 1.0), + reflectance: material.reflectance, + _padding: Vec3::ZERO, + }, + ); + + let was_emissive = if is_emissive { + !self.emissive_materials.insert(material_id) + } else { + self.emissive_materials.remove(&material_id) + }; + if !was_resolved || was_emissive != is_emissive { + instances.invalidate_material(material_id); + } + } + + fn new_texture_count(&self, textures: &MaterialTextures) -> u32 { + let mut count = 0; + for (index, image_id) in textures.iter().enumerate() { + let Some(image_id) = image_id else { continue }; + let counted_already = textures[..index].contains(&Some(*image_id)); + if !counted_already && !self.textures.contains(image_id) { + count += 1; + } + } + count + } + + fn defer_material( + &mut self, + material_id: AssetId, + instances: &mut InstanceState, + ) { + self.remove_material(material_id, instances); + self.unresolved_materials.insert(material_id); + } + + fn remove_material( + &mut self, + material_id: AssetId, + instances: &mut InstanceState, + ) { + self.unresolved_materials.remove(&material_id); + if self.material_slots.remove(&material_id).is_none() { + return; + } + + self.release_material_textures(material_id); + self.material_textures.remove(&material_id); + self.emissive_materials.remove(&material_id); + instances.invalidate_material(material_id); + } + + fn release_material_textures(&mut self, material_id: AssetId) { + let Some(textures) = self.material_textures.get(&material_id).copied() else { + return; + }; + for image_id in textures.into_iter().flatten() { + self.textures.release(&image_id); + } + } +} diff --git a/src/scene/binder/bind_group.rs b/src/scene/binder/bind_group.rs new file mode 100644 index 0000000..5efacbf --- /dev/null +++ b/src/scene/binder/bind_group.rs @@ -0,0 +1,460 @@ +use core::{mem::size_of, ops::Deref}; + +use bevy_ecs::system::{Res, ResMut}; +use bevy_math::Mat3; +use bevy_pbr::DfgLut; +use bevy_render::{ + render_asset::RenderAssets, + render_resource::{ + BindGroup, BindGroupEntries, BindGroupLayout, Buffer, BufferBinding, BufferDescriptor, + BufferId, BufferSize, BufferUsages, PipelineCache, Sampler, SamplerId, ShaderType, + SparseBufferUpdateBindGroups, SparseBufferUpdateJobs, SparseBufferUpdatePipelines, + StorageBuffer, TextureView, TextureViewId, + }, + renderer::{RenderDevice, RenderQueue}, + texture::{FallbackImage, GpuImage}, +}; +use tracing::info_span; + +use super::{ + RaytracingSceneBindings, TlasInstanceSetupPipeline, allocator::RetainedBindingArray, + lights::GpuLightSource, +}; +use crate::scene::extract::ExtractedEnvironmentMapLight; + +pub struct BindGroupCacheState { + cached: [Option; 2], + pub invalid: bool, + last_buffer_ids: [Option; 11], + last_light_count: u32, + last_dfg_ids: Option<(TextureViewId, SamplerId)>, + last_environment_map_light_id: Option, + pub dummy_buffer: Buffer, +} + +impl BindGroupCacheState { + pub fn new(render_device: &RenderDevice) -> Self { + // Binding arrays are dense, so freed slots still need something valid + // bound into them + let dummy_buffer = render_device.create_buffer(&BufferDescriptor { + label: Some("solari_dummy_binding_array_buffer"), + size: 48, + usage: BufferUsages::STORAGE, + mapped_at_creation: false, + }); + + Self { + cached: [None, None], + invalid: true, + last_buffer_ids: [None; 11], + last_light_count: 0, + last_dfg_ids: None, + last_environment_map_light_id: None, + dummy_buffer, + } + } +} + +fn buffer_bindings<'a>( + buffers: &'a RetainedBindingArray, + dummy: &'a Buffer, +) -> Vec> { + buffers + .iter() + .map(|buffer| buffer.unwrap_or(dummy).as_entire_buffer_binding()) + .collect() +} + +impl RaytracingSceneBindings { + /// Each sparse buffer's GPU buffer id, or `None` where it has not been + /// created yet. + fn buffer_ids(&self) -> [Option; 11] { + [ + self.assets.materials.buffer().map(Buffer::id), + self.instances.transforms.buffer().map(Buffer::id), + self.instances + .previous_frame_transforms + .buffer() + .map(Buffer::id), + self.instances.geometry_ids.buffer().map(Buffer::id), + self.instances.tape_ids.buffer().map(Buffer::id), + self.instances.material_ids.buffer().map(Buffer::id), + self.instances.blas_refs.buffer().map(Buffer::id), + self.lights.sources.buffer().map(Buffer::id), + self.lights.directional_lights.buffer().map(Buffer::id), + self.lights + .previous_frame_id_translations + .buffer() + .map(Buffer::id), + self.environment_map_light_buffer.buffer().map(Buffer::id), + ] + } + + fn take_bind_group_invalidation( + &mut self, + dfg_view: &TextureView, + dfg_sampler: &Sampler, + environment_map_light: &TextureView, + ) -> bool { + let mut invalid = self.bind_groups.invalid; + self.bind_groups.invalid = false; + + for dirty in [ + &mut self.instances.vertex_buffers.dirty, + &mut self.instances.index_buffers.dirty, + &mut self.instances.aabb_buffers.dirty, + &mut self.assets.textures.dirty, + ] { + invalid |= core::mem::replace(dirty, false); + } + + let buffer_ids = self.buffer_ids(); + if self.bind_groups.last_buffer_ids != buffer_ids { + self.bind_groups.last_buffer_ids = buffer_ids; + invalid = true; + } + + let light_count = self.lights.index.len() as u32; + if self.bind_groups.last_light_count != light_count { + self.bind_groups.last_light_count = light_count; + invalid = true; + } + + let dfg_ids = Some((dfg_view.id(), dfg_sampler.id())); + if self.bind_groups.last_dfg_ids != dfg_ids { + self.bind_groups.last_dfg_ids = dfg_ids; + invalid = true; + } + + let environment_map_light_id = Some(environment_map_light.id()); + if self.bind_groups.last_environment_map_light_id != environment_map_light_id { + self.bind_groups.last_environment_map_light_id = environment_map_light_id; + invalid = true; + } + + invalid + } + + fn create_bind_group( + &self, + current_index: usize, + render_device: &RenderDevice, + layout: &BindGroupLayout, + fallback_texture: &FallbackImage, + dfg_view: &TextureView, + dfg_sampler: &Sampler, + environment_map_light: &TextureView, + ) -> BindGroup { + let _span = info_span!("create_bind_group").entered(); + let dummy = &self.bind_groups.dummy_buffer; + let vertex_buffers = buffer_bindings(&self.instances.vertex_buffers, dummy); + let index_buffers = buffer_bindings(&self.instances.index_buffers, dummy); + let aabb_buffers = buffer_bindings(&self.instances.aabb_buffers, dummy); + + let (mut textures, mut samplers): (Vec<_>, Vec<_>) = self + .assets + .textures + .iter() + .map(|texture| match texture { + Some((view, sampler)) => (view.deref(), sampler.deref()), + None => ( + fallback_texture.d2.texture_view.deref(), + fallback_texture.d2.sampler.deref(), + ), + }) + .unzip(); + if textures.is_empty() { + textures.push(fallback_texture.d2.texture_view.deref()); + samplers.push(fallback_texture.d2.sampler.deref()); + } + + let light_sources = BufferBinding { + buffer: self.lights.sources.buffer().unwrap(), + offset: 0, + size: BufferSize::new( + self.lights.index.len() as u64 * size_of::() as u64, + ), + }; + + let materials = self + .assets + .materials + .buffer() + .unwrap() + .as_entire_buffer_binding(); + let transforms = self + .instances + .transforms + .buffer() + .unwrap() + .as_entire_buffer_binding(); + let previous_frame_transforms = self + .instances + .previous_frame_transforms + .buffer() + .unwrap() + .as_entire_buffer_binding(); + let geometry_ids = self + .instances + .geometry_ids + .buffer() + .unwrap() + .as_entire_buffer_binding(); + let tape_ids = self + .instances + .tape_ids + .buffer() + .unwrap() + .as_entire_buffer_binding(); + let material_ids = self + .instances + .material_ids + .buffer() + .unwrap() + .as_entire_buffer_binding(); + let directional_lights = self + .lights + .directional_lights + .buffer() + .unwrap() + .as_entire_buffer_binding(); + let translations = self + .lights + .previous_frame_id_translations + .buffer() + .unwrap() + .as_entire_buffer_binding(); + + let current = self.tlas.structures[current_index].as_ref().unwrap(); + let previous = self.tlas.structures[current_index ^ 1] + .as_ref() + .filter(|_| self.tlas.built[current_index ^ 1]) + .unwrap_or(current); + + render_device.create_bind_group( + "raytracing_scene_bind_group", + layout, + &BindGroupEntries::sequential(( + vertex_buffers.as_slice(), + index_buffers.as_slice(), + aabb_buffers.as_slice(), + textures.as_slice(), + samplers.as_slice(), + materials, + current.as_binding(), + previous.as_binding(), + transforms, + previous_frame_transforms, + geometry_ids, + tape_ids, + material_ids, + light_sources, + directional_lights, + translations, + dfg_view, + dfg_sampler, + environment_map_light, + &self.environment_map_light_sampler, + &self.environment_map_light_buffer, + )), + ) + } + + fn cache_bind_group( + &mut self, + current_index: usize, + render_device: &RenderDevice, + pipeline_cache: &PipelineCache, + fallback_texture: &FallbackImage, + dfg_view: &TextureView, + dfg_sampler: &Sampler, + environment_map_light: &TextureView, + ) -> BindGroup { + if let Some(bind_group) = &self.bind_groups.cached[current_index] { + return bind_group.clone(); + } + + // Only resolve the layout on a miss, as it locks and hashes the whole + // descriptor + let layout = pipeline_cache.get_bind_group_layout(&self.bind_group_layout); + let bind_group = self.create_bind_group( + current_index, + render_device, + &layout, + fallback_texture, + dfg_view, + dfg_sampler, + environment_map_light, + ); + if self.tlas.previous_binding_is_stable() { + self.bind_groups.cached[current_index] = Some(bind_group.clone()); + } + bind_group + } +} + +/// Finalizes sparse uploads and selects the cached bind group for this frame's +/// TLAS. +pub fn prepare_raytracing_scene_bind_group( + texture_assets: Res>, + fallback_texture: Res, + dfg_lut: Res, + extracted_environment_map_light: Res, + render_device: Res, + render_queue: Res, + pipeline_cache: Res, + sparse_buffer_update_pipelines: Res, + instance_setup_pipeline: Res, + mut sparse_buffer_update_jobs: ResMut, + mut sparse_buffer_update_bind_groups: ResMut, + mut bindings: ResMut, +) { + let bindings = &mut *bindings; + + prepare_sparse_uploads( + bindings, + &render_device, + &pipeline_cache, + &mut sparse_buffer_update_jobs, + &mut sparse_buffer_update_bind_groups, + &sparse_buffer_update_pipelines, + ); + + bindings.tlas.update_instance_setup_bind_group( + &bindings.instances, + &render_device, + &pipeline_cache, + &instance_setup_pipeline, + ); + bindings.bind_group = None; + + if bindings.instances.live_count == 0 || bindings.lights.index.is_empty() { + return; + } + if bindings.tlas.structures[bindings.tlas.current_index].is_none() { + return; + } + + let (dfg_view, dfg_sampler) = texture_assets + .get(&dfg_lut.texture) + .map(|image| (&image.texture_view, &image.sampler)) + .unwrap_or(( + &fallback_texture.d2.texture_view, + &fallback_texture.d2.sampler, + )); + + let environment_map_light = prepare_environment_map_light( + &extracted_environment_map_light, + &texture_assets, + &fallback_texture, + &mut bindings.environment_map_light_buffer, + &render_device, + &render_queue, + ); + + if bindings.take_bind_group_invalidation(dfg_view, dfg_sampler, environment_map_light) { + bindings.bind_groups.cached = [None, None]; + } + + let current_index = bindings.tlas.current_index; + bindings.bind_group = Some(bindings.cache_bind_group( + current_index, + &render_device, + &pipeline_cache, + &fallback_texture, + dfg_view, + dfg_sampler, + environment_map_light, + )); +} + +#[derive(ShaderType, Default)] +pub struct GpuEnvironmentMapLight { + pub light_from_world: Mat3, + pub intensity: f32, +} + +fn prepare_environment_map_light<'a>( + extracted_environment_map_light: &ExtractedEnvironmentMapLight, + texture_assets: &'a RenderAssets, + fallback_texture: &'a FallbackImage, + buffer: &mut StorageBuffer, + render_device: &RenderDevice, + render_queue: &RenderQueue, +) -> &'a TextureView { + let cubemap = extracted_environment_map_light + .cubemap + .as_ref() + .and_then(|cubemap| texture_assets.get(cubemap)); + + let (texture, uniform) = match cubemap { + Some(cubemap) => ( + &cubemap.texture_view, + GpuEnvironmentMapLight { + light_from_world: Mat3::from_quat( + extracted_environment_map_light.rotation.inverse(), + ), + intensity: extracted_environment_map_light.intensity, + }, + ), + None => ( + &fallback_texture.cube.texture_view, + GpuEnvironmentMapLight::default(), + ), + }; + + buffer.set(uniform); + buffer.write_buffer(render_device, render_queue); + texture +} + +/// Queues the compute jobs that scatter each buffer's staged elements into its +/// GPU buffer. +fn prepare_sparse_uploads( + bindings: &mut RaytracingSceneBindings, + device: &RenderDevice, + cache: &PipelineCache, + jobs: &mut SparseBufferUpdateJobs, + groups: &mut SparseBufferUpdateBindGroups, + pipelines: &SparseBufferUpdatePipelines, +) { + let _span = info_span!("prepare_sparse_uploads").entered(); + + bindings + .assets + .materials + .prepare_to_populate_buffers(device, cache, jobs, groups, pipelines); + + let instances = &mut bindings.instances; + instances + .transforms + .prepare_to_populate_buffers(device, cache, jobs, groups, pipelines); + instances + .previous_frame_transforms + .prepare_to_populate_buffers(device, cache, jobs, groups, pipelines); + instances + .geometry_ids + .prepare_to_populate_buffers(device, cache, jobs, groups, pipelines); + instances + .tape_ids + .prepare_to_populate_buffers(device, cache, jobs, groups, pipelines); + instances + .material_ids + .prepare_to_populate_buffers(device, cache, jobs, groups, pipelines); + if bindings.tlas.uses_raw_build() { + instances + .blas_refs + .prepare_to_populate_buffers(device, cache, jobs, groups, pipelines); + } + + let lights = &mut bindings.lights; + lights + .sources + .prepare_to_populate_buffers(device, cache, jobs, groups, pipelines); + lights + .directional_lights + .prepare_to_populate_buffers(device, cache, jobs, groups, pipelines); + lights + .previous_frame_id_translations + .prepare_to_populate_buffers(device, cache, jobs, groups, pipelines); +} diff --git a/src/scene/binder/instances.rs b/src/scene/binder/instances.rs new file mode 100644 index 0000000..30fafef --- /dev/null +++ b/src/scene/binder/instances.rs @@ -0,0 +1,615 @@ +use core::{hash::Hash, num::NonZeroU32}; + +use bevy_asset::AssetId; +use bevy_ecs::{ + entity::{Entity, EntityHashMap, EntityHashSet}, + query::{Changed, Or, With}, + system::Query, +}; +use bevy_math::{Affine3, Affine3Ext, Vec4}; +use bevy_mesh::Mesh; +use bevy_pbr::{MeshMaterial3d, PreviousGlobalTransform, StandardMaterial}; +use bevy_platform::collections::HashMap; +use bevy_render::{ + impl_atomic_pod, + mesh::allocator::MeshAllocator, + render_resource::{AtomicPod, AtomicSparseBufferVec, Buffer, BufferId, BufferUsages}, +}; +use bevy_transform::components::GlobalTransform; +use bevy_utils::once; +use bytemuck::{Pod, Zeroable}; +use tracing::{info_span, warn}; + +use super::{ + MeshBlasManager, RaytracingMesh3d, RaytracingSceneBindings, Tape3d, TapeBlasManager, + allocator::{IndexAllocator, RetainedBindingArray}, + assets::AssetState, + lights::{GpuLightSource, LightSourceId, LightState}, +}; +use crate::scene::tapes::{allocator::TapeAllocator, types::Tape}; + +pub const MAX_MESH_SLAB_COUNT: NonZeroU32 = NonZeroU32::new(500).unwrap(); + +#[derive(Clone, Copy, Default, PartialEq, Pod, Zeroable)] +#[repr(C)] +pub struct GpuInstanceGeometryIds { + vertex_buffer_id: u32, + vertex_buffer_offset: u32, + index_buffer_id: u32, + index_buffer_offset: u32, + triangle_count: u32, +} + +#[derive(Clone, Copy, Default, PartialEq, Pod, Zeroable)] +#[repr(C)] +pub struct GpuInstanceTapeIds { + aabb_buffer_id: u32, + aabb_buffer_offset: u32, + aabb_count: u32, +} + +/// A world-from-local affine transform, stored transposed as three rows. +#[derive(Clone, Copy, Default, PartialEq, Pod, Zeroable)] +#[repr(C)] +pub struct GpuTransform([Vec4; 3]); + +impl GpuTransform { + /// The three rows as the flat row-major 3x4 a [`TlasInstance`] wants. + /// + /// [`TlasInstance`]: bevy_render::render_resource::TlasInstance + fn rows(self) -> [f32; 12] { + bytemuck::cast(self) + } +} + +/// The device address of a slot's acceleration structure. Zero marks an +/// inactive slot. +#[derive(Clone, Copy, Default, PartialEq, Pod, Zeroable)] +#[repr(transparent)] +pub struct GpuBlasRef(u64); + +impl GpuBlasRef { + const NONE: Self = Self(0); +} + +impl_atomic_pod!(GpuInstanceGeometryIds, GpuInstanceGeometryIdsBlob); +impl_atomic_pod!(GpuInstanceTapeIds, GpuInstanceTapeIdsBlob); +impl_atomic_pod!(GpuTransform, GpuTransformBlob); +impl_atomic_pod!(GpuBlasRef, GpuBlasRefBlob); + +fn storage_buffer(label: &str) -> AtomicSparseBufferVec { + AtomicSparseBufferVec::new(BufferUsages::STORAGE, label.into()) +} + +#[derive(Clone, Copy, PartialEq, Eq, Hash)] +pub enum Object { + Mesh(AssetId), + Tape(AssetId), +} + +/// Everything tracked per raytracing mesh instance. +#[derive(Clone, Copy)] +struct Instance { + slot: u32, + object: Object, + material: AssetId, + buffers: Option<(BufferId, BufferId)>, +} + +/// Stable slots, reverse dependency indices and GPU data owned by raytracing +/// instances. +pub struct InstanceState { + pub vertex_buffers: RetainedBindingArray, + pub index_buffers: RetainedBindingArray, + pub aabb_buffers: RetainedBindingArray, + pub transforms: AtomicSparseBufferVec, + pub previous_frame_transforms: AtomicSparseBufferVec, + pub geometry_ids: AtomicSparseBufferVec, + pub tape_ids: AtomicSparseBufferVec, + pub material_ids: AtomicSparseBufferVec, + pub blas_refs: AtomicSparseBufferVec, + pub slots: IndexAllocator, + records: EntityHashMap, + pub live_count: u32, + pub pending_refresh: EntityHashSet, + object_instances: HashMap, + pub material_instances: HashMap, EntityHashSet>, +} + +impl InstanceState { + pub fn new() -> Self { + Self { + vertex_buffers: RetainedBindingArray::new(), + index_buffers: RetainedBindingArray::new(), + aabb_buffers: RetainedBindingArray::new(), + transforms: storage_buffer("solari_transforms"), + previous_frame_transforms: storage_buffer("solari_previous_frame_transforms"), + geometry_ids: storage_buffer("solari_geometry_ids"), + tape_ids: storage_buffer("solari_tape_ids"), + material_ids: storage_buffer("solari_material_ids"), + blas_refs: storage_buffer("solari_blas_refs"), + slots: IndexAllocator::new(), + records: EntityHashMap::default(), + live_count: 0, + pending_refresh: EntityHashSet::default(), + object_instances: HashMap::default(), + material_instances: HashMap::default(), + } + } + + /// Every drawable instance's slot, mesh and world-from-local transform. + /// + /// Only the `wgpu-core` TLAS build path needs this, to fill in the instance + /// descriptors that the raw path sets up on the GPU. Slots with a null + /// acceleration structure reference are not currently drawable, and are + /// left out. + pub fn drawable(&self) -> impl Iterator + '_ { + self.records.values().filter_map(|instance| { + let slot = instance.slot; + (self.blas_refs.get(slot) != GpuBlasRef::NONE) + .then(|| (slot, instance.object, self.transforms.get(slot).rows())) + }) + } + + /// Queues every instance using `material_id` to be re-resolved. + pub fn invalidate_material(&mut self, material_id: AssetId) { + if let Some(instances) = self.material_instances.get(&material_id) { + self.pending_refresh.extend(instances.iter().copied()); + } + } +} + +pub type MeshInstanceQueryData<'w> = ( + &'w RaytracingMesh3d, + &'w MeshMaterial3d, + &'w GlobalTransform, + &'w PreviousGlobalTransform, +); + +pub type TapeInstanceQueryData<'w> = ( + &'w Tape3d, + &'w MeshMaterial3d, + &'w GlobalTransform, + &'w PreviousGlobalTransform, +); + +pub enum InstanceQueryData<'w> { + Mesh(MeshInstanceQueryData<'w>), + Tape(TapeInstanceQueryData<'w>), +} + +pub type ChangedMeshInstanceFilter = ( + With, + Or<( + Changed, + Changed>, + )>, +); + +pub type ChangedTapeInstanceFilter = ( + With, + Or<(Changed, Changed>)>, +); + +/// The scene state an instance resolves its GPU data against. +pub struct InstanceInputs<'a> { + pub assets: &'a AssetState, + pub mesh_blas_manager: &'a MeshBlasManager, + pub mesh_allocator: &'a MeshAllocator, + pub tape_blas_manager: &'a TapeBlasManager, + pub tape_allocator: &'a TapeAllocator, +} + +fn unlink(map: &mut HashMap, key: &K, entity: Entity) { + let now_empty = map.get_mut(key).is_some_and(|instances| { + instances.remove(&entity); + instances.is_empty() + }); + if now_empty { + map.remove(key); + } +} + +fn relink( + map: &mut HashMap, + entity: Entity, + previous: Option, + key: K, +) { + if previous == Some(key) { + return; + } + if let Some(previous) = previous { + unlink(map, &previous, entity); + } + map.entry(key).or_default().insert(entity); +} + +impl InstanceState { + pub fn remove_instances( + &mut self, + lights: &mut LightState, + removed: impl IntoIterator, + ) { + let _span = info_span!("remove_instances").entered(); + for entity in removed { + self.remove_instance(lights, entity); + } + } + + pub fn refresh_instances( + &mut self, + inputs: &InstanceInputs, + lights: &mut LightState, + mesh_instances: &Query, + changed_mesh_instances: &Query, + tape_instances: &Query, + changed_tape_instances: &Query, + ) { + let _span = info_span!("refresh_instances").entered(); + + let mut refresh = core::mem::take(&mut self.pending_refresh); + refresh.extend(changed_mesh_instances.iter()); + refresh.extend(changed_tape_instances.iter()); + + let moved_meshes = inputs.mesh_allocator.meshes_displaced_by_slab_growth(); + for mesh_id in inputs + .mesh_blas_manager + .changed_meshes() + .iter() + .copied() + .chain(moved_meshes) + { + if let Some(mesh_instances) = self.object_instances.get(&Object::Mesh(mesh_id)) { + refresh.extend(mesh_instances.iter().copied()); + } + } + + let moved_tapes = inputs.tape_allocator.tapes_displaced_by_slab_growth(); + for tape_id in inputs + .tape_blas_manager + .changed_tapes() + .iter() + .copied() + .chain(moved_tapes) + { + if let Some(tape_instances) = self.object_instances.get(&Object::Tape(tape_id)) { + refresh.extend(tape_instances.iter().copied()); + } + } + + for entity in refresh { + match mesh_instances.get(entity) { + Ok(data) => { + self.refresh_instance(inputs, lights, entity, InstanceQueryData::Mesh(data)) + }, + Err(_) => match tape_instances.get(entity) { + Ok(data) => { + self.refresh_instance(inputs, lights, entity, InstanceQueryData::Tape(data)) + }, + Err(_) => self.remove_instance(lights, entity), + }, + } + } + } + + fn reserve_slot(&mut self, slot: u32) { + let len = slot + 1; + self.transforms.grow(len); + self.previous_frame_transforms.grow(len); + self.blas_refs.grow(len); + } + + fn refresh_instance( + &mut self, + inputs: &InstanceInputs, + lights: &mut LightState, + entity: Entity, + data: InstanceQueryData, + ) { + let previous = self.records.get(&entity).copied(); + + let (id, material, transform, previous_frame_transform) = match data { + InstanceQueryData::Mesh((mesh, material, transform, previous_frame_transform)) => ( + Object::Mesh(mesh.id()), + material, + transform, + previous_frame_transform, + ), + InstanceQueryData::Tape((tape, material, transform, previous_frame_transform)) => ( + Object::Tape(tape.id()), + material, + transform, + previous_frame_transform, + ), + }; + + let material_id = material.id(); + + relink( + &mut self.object_instances, + entity, + previous.map(|instance| instance.object), + id, + ); + relink( + &mut self.material_instances, + entity, + previous.map(|instance| instance.material), + material_id, + ); + + let slot = match previous { + Some(previous) => previous.slot, + None => self.slots.allocate(), + }; + self.reserve_slot(slot); + + // Seed only once. Later refreshes must not overwrite transforms written + // by extraction. + if previous.is_none() { + self.write_transforms(slot, transform, previous_frame_transform); + } + + let mut instance = Instance { + slot, + object: id, + material: material_id, + buffers: previous.and_then(|instance| instance.buffers), + }; + let resolved = self.resolve_instance(inputs, lights, entity, &mut instance); + + self.records.insert(entity, instance); + if !resolved { + self.pending_refresh.insert(entity); + } + } + + fn resolve_instance( + &mut self, + inputs: &InstanceInputs, + lights: &mut LightState, + entity: Entity, + instance: &mut Instance, + ) -> bool { + match instance.object { + Object::Mesh(asset_id) => { + self.resolve_mesh_instance(inputs, lights, entity, asset_id, instance) + }, + Object::Tape(asset_id) => { + self.resolve_tape_instance(inputs, lights, entity, asset_id, instance) + }, + } + } + + fn resolve_mesh_instance( + &mut self, + inputs: &InstanceInputs, + lights: &mut LightState, + entity: Entity, + mesh_id: AssetId, + instance: &mut Instance, + ) -> bool { + let slot = instance.slot; + let (Some(vertex_slice), Some(index_slice), Some(material_slot), Some(blas_address)) = ( + inputs.mesh_allocator.mesh_vertex_slice(&mesh_id), + inputs.mesh_allocator.mesh_index_slice(&mesh_id), + inputs.assets.material_slots.get(&instance.material), + inputs.mesh_blas_manager.device_address(&mesh_id), + ) else { + self.deactivate_instance(lights, entity, instance); + return false; + }; + + let vertex_buffer_key = vertex_slice.buffer.id(); + let index_buffer_key = index_slice.buffer.id(); + let capacity = MAX_MESH_SLAB_COUNT.get(); + if !self.vertex_buffers.has_room(&vertex_buffer_key, capacity) + || !self.index_buffers.has_room(&index_buffer_key, capacity) + { + once!(warn!( + "Solari scene needs more than {} mesh slabs. Instances past that limit will not \ + be rendered.", + MAX_MESH_SLAB_COUNT.get() + )); + self.deactivate_instance(lights, entity, instance); + return false; + } + + let previous_buffers = instance.buffers.take(); + let vertex_buffer_id = self + .vertex_buffers + .acquire(vertex_buffer_key, capacity, || vertex_slice.buffer.clone()) + .expect("vertex slab binding array had room but handed out no slot"); + let index_buffer_id = self + .index_buffers + .acquire(index_buffer_key, capacity, || index_slice.buffer.clone()) + .expect("index slab binding array had room but handed out no slot"); + instance.buffers = Some((vertex_buffer_key, index_buffer_key)); + self.release_mesh_buffers(previous_buffers); + + let triangle_count = (index_slice.range.len() / 3) as u32; + self.geometry_ids.grow_and_set( + slot, + GpuInstanceGeometryIds { + vertex_buffer_id, + vertex_buffer_offset: vertex_slice.range.start, + index_buffer_id, + index_buffer_offset: index_slice.range.start, + triangle_count, + }, + ); + self.material_ids.grow_and_set(slot, material_slot); + self.set_blas_ref(slot, GpuBlasRef(blas_address)); + + let is_emissive = inputs + .assets + .emissive_materials + .contains(&instance.material); + if is_emissive { + lights.add_light( + LightSourceId::EmissiveMesh(entity), + GpuLightSource::new_emissive_mesh_light(slot, triangle_count), + ); + } else { + lights.remove_light(LightSourceId::EmissiveMesh(entity)); + } + true + } + + fn resolve_tape_instance( + &mut self, + inputs: &InstanceInputs, + lights: &mut LightState, + entity: Entity, + tape_id: AssetId, + instance: &mut Instance, + ) -> bool { + let slot = instance.slot; + let (Some(aabb_slice), Some(material_slot), Some(blas_address)) = ( + inputs.tape_allocator.tape_aabb_slice(&tape_id), + inputs.assets.material_slots.get(&instance.material), + inputs.tape_blas_manager.device_address(&tape_id), + ) else { + self.deactivate_instance(lights, entity, instance); + return false; + }; + + let aabb_buffer_key = aabb_slice.buffer.id(); + let capacity = MAX_MESH_SLAB_COUNT.get(); + if !self.aabb_buffers.has_room(&aabb_buffer_key, capacity) { + once!(warn!( + "Solari scene needs more than {} mesh slabs. Instances past that limit will not \ + be rendered.", + MAX_MESH_SLAB_COUNT.get() + )); + self.deactivate_instance(lights, entity, instance); + return false; + } + + let previous_buffers = instance.buffers.take(); + let aabb_buffer_id = self + .aabb_buffers + .acquire(aabb_buffer_key, capacity, || aabb_slice.buffer.clone()) + .expect("aabb slab binding array had room but handed out no slot"); + instance.buffers = Some((aabb_buffer_key, aabb_buffer_key)); + self.release_tape_buffers(previous_buffers); + + let aabb_count = (aabb_slice.range.len()) as u32; + self.tape_ids.grow_and_set( + slot, + GpuInstanceTapeIds { + aabb_buffer_id, + aabb_buffer_offset: aabb_slice.range.start, + aabb_count, + }, + ); + self.material_ids.grow_and_set(slot, material_slot); + self.set_blas_ref(slot, GpuBlasRef(blas_address)); + + /* + let is_emissive = inputs + .assets + .emissive_materials + .contains(&instance.material); + if is_emissive { + lights.add_light( + LightSourceId::EmissiveMesh(entity), + GpuLightSource::new_emissive_mesh_light(slot, triangle_count), + ); + } else { + lights.remove_light(LightSourceId::EmissiveMesh(entity)); + } + */ + + true + } + + fn write_transforms( + &self, + slot: u32, + transform: &GlobalTransform, + previous_frame_transform: &PreviousGlobalTransform, + ) { + self.transforms.set_if_changed( + slot, + GpuTransform(Affine3::from(transform.affine()).to_transpose()), + ); + self.previous_frame_transforms.set_if_changed( + slot, + GpuTransform(Affine3::from(previous_frame_transform.0).to_transpose()), + ); + } + + /// Points a slot at an acceleration structure, or at nothing, keeping + /// `live_count` in step. + fn set_blas_ref(&mut self, slot: u32, reference: GpuBlasRef) { + self.blas_refs.grow(slot + 1); + let previous = self.blas_refs.get(slot); + if previous == reference { + return; + } + self.blas_refs.set(slot, reference); + + if previous == GpuBlasRef::NONE { + self.live_count += 1; + } else if reference == GpuBlasRef::NONE { + self.live_count -= 1; + } + } + + fn deactivate_instance( + &mut self, + lights: &mut LightState, + entity: Entity, + instance: &mut Instance, + ) { + self.set_blas_ref(instance.slot, GpuBlasRef::NONE); + lights.remove_light(LightSourceId::EmissiveMesh(entity)); + match instance.object { + Object::Mesh(_) => self.release_mesh_buffers(instance.buffers.take()), + Object::Tape(_) => self.release_tape_buffers(instance.buffers.take()), + } + } + + fn release_mesh_buffers(&mut self, buffers: Option<(BufferId, BufferId)>) { + if let Some((vertex_key, index_key)) = buffers { + self.vertex_buffers.release(&vertex_key); + self.index_buffers.release(&index_key); + } + } + + fn release_tape_buffers(&mut self, buffers: Option<(BufferId, BufferId)>) { + if let Some((aabb_key, _)) = buffers { + self.aabb_buffers.release(&aabb_key); + } + } + + fn remove_instance(&mut self, lights: &mut LightState, entity: Entity) { + let Some(mut instance) = self.records.remove(&entity) else { + return; + }; + + self.deactivate_instance(lights, entity, &mut instance); + self.slots.release(instance.slot); + self.pending_refresh.remove(&entity); + unlink(&mut self.object_instances, &instance.object, entity); + unlink(&mut self.material_instances, &instance.material, entity); + } +} + +impl RaytracingSceneBindings { + /// Parallel hot path: one entity lookup, then two allocation-free sparse + /// writes. + pub fn move_instance( + &self, + entity: Entity, + transform: &GlobalTransform, + previous_frame_transform: &PreviousGlobalTransform, + ) { + if let Some(instance) = self.instances.records.get(&entity) { + self.instances + .write_transforms(instance.slot, transform, previous_frame_transform); + } + } +} diff --git a/src/scene/binder/lights.rs b/src/scene/binder/lights.rs new file mode 100644 index 0000000..9c6bf72 --- /dev/null +++ b/src/scene/binder/lights.rs @@ -0,0 +1,310 @@ +use super::allocator::SlotAllocator; +use bevy_color::ColorToComponents; +use bevy_ecs::{ + entity::{Entity, EntityHashSet}, + system::Query, +}; +use bevy_math::{ops::cos, Vec3}; +use bevy_pbr::ExtractedDirectionalLight; +use bevy_platform::collections::{HashMap, HashSet}; +use bevy_render::render_resource::{AtomicSparseBufferVec, BufferUsages}; +use bevy_render::{impl_atomic_pod, render_resource::AtomicPod}; +use bytemuck::{Pod, Zeroable}; +use core::sync::atomic::{AtomicBool, Ordering}; +use core::{f32::consts::TAU, hash::Hash}; +use tracing::info_span; + +const LIGHT_NOT_PRESENT_THIS_FRAME: u32 = u32::MAX; + +#[derive(Clone, Copy, Default, PartialEq, Pod, Zeroable)] +#[repr(C)] +pub struct GpuLightSource { + kind: u32, + id: u32, +} + +/// Stable identity for one source in the light array. +/// +/// An entity can contribute both kinds at once, so the entity alone is not enough to identify a +/// source. +#[derive(Clone, Copy, Eq, Hash, PartialEq)] +pub enum LightSourceId { + EmissiveMesh(Entity), + Directional(Entity), +} + +#[derive(Default)] +pub struct LightIndex { + indices: HashMap, + ids: Vec, + changed: HashSet, +} + +impl LightIndex { + pub fn len(&self) -> usize { + self.ids.len() + } + + pub fn is_empty(&self) -> bool { + self.ids.is_empty() + } + + fn get(&self, id: &LightSourceId) -> Option { + self.indices.get(id).copied() + } + + fn insert(&mut self, id: LightSourceId) -> u32 { + if let Some(&index) = self.indices.get(&id) { + return index; + } + + let index = self.ids.len() as u32; + self.ids.push(id); + self.indices.insert(id, index); + self.changed.insert(id); + index + } + + /// Removes `id` and reports both its old index and the old final index. + /// + /// Only the ids tracked here are swapped down. When the two indices differ, the caller has to + /// mirror that swap in `sources`, copying the element at the old final index into the hole. + fn remove(&mut self, id: LightSourceId) -> Option<(u32, u32)> { + let index = self.indices.remove(&id)?; + self.changed.insert(id); + + let last = self.ids.len() as u32 - 1; + self.ids.swap_remove(index as usize); + + if index != last { + let moved = self.ids[index as usize]; + self.indices.insert(moved, index); + self.changed.insert(moved); + } + + Some((index, last)) + } +} + +impl GpuLightSource { + pub fn new_emissive_mesh_light(instance_id: u32, triangle_count: u32) -> GpuLightSource { + if triangle_count > u16::MAX as u32 { + panic!("Too many triangles ({triangle_count}) in an emissive mesh, maximum is 65535."); + } + + Self { + kind: triangle_count << 1, + id: instance_id, + } + } + + fn new_directional_light(directional_light_id: u32) -> GpuLightSource { + Self { + kind: 1, + id: directional_light_id, + } + } +} + +#[derive(Clone, Copy, Default, PartialEq, Pod, Zeroable)] +#[repr(C)] +pub struct GpuDirectionalLight { + direction_to_light: Vec3, + cos_theta_max: f32, + luminance: Vec3, + inverse_pdf: f32, +} + +impl_atomic_pod!(GpuLightSource, GpuLightSourceBlob); +impl_atomic_pod!(GpuDirectionalLight, GpuDirectionalLightBlob); + +impl GpuDirectionalLight { + fn new(directional_light: &ExtractedDirectionalLight) -> Self { + let cos_theta_max = cos(directional_light.sun_disk_angular_size / 2.0); + let solid_angle = TAU * (1.0 - cos_theta_max); + let luminance = + (directional_light.color.to_vec3() * directional_light.illuminance) / solid_angle; + + Self { + direction_to_light: directional_light.transform.back().into(), + cos_theta_max, + luminance, + inverse_pdf: solid_angle, + } + } +} + +/// Light slots and the incremental previous-frame id translation state. +pub struct LightState { + /// Kept gap-free because shaders derive the light count with `arrayLength`. + pub sources: AtomicSparseBufferVec, + pub directional_lights: AtomicSparseBufferVec, + pub previous_frame_id_translations: AtomicSparseBufferVec, + pub index: LightIndex, + /// Light ids as of the last frame whose translation table the lighting shader actually read. + previous_index: HashMap, + nonidentity_translations: Vec, + directional_slots: SlotAllocator, + /// Set by the lighting node once it has recorded work reading the translation table. + translations_consumed: AtomicBool, +} + +impl LightState { + pub fn new() -> Self { + Self { + sources: AtomicSparseBufferVec::new( + BufferUsages::STORAGE, + "solari_light_sources".into(), + ), + directional_lights: AtomicSparseBufferVec::new( + BufferUsages::STORAGE, + "solari_directional_lights".into(), + ), + previous_frame_id_translations: AtomicSparseBufferVec::new( + BufferUsages::STORAGE, + "solari_previous_frame_light_id_translations".into(), + ), + index: LightIndex::default(), + previous_index: HashMap::default(), + nonidentity_translations: Vec::new(), + directional_slots: SlotAllocator::new(), + translations_consumed: AtomicBool::new(false), + } + } + + pub fn update(&mut self, directional_lights: &Query<(Entity, &ExtractedDirectionalLight)>) { + // There are few enough directional lights to just walk them every frame + let _span = info_span!("update_lights").entered(); + + let mut live_directional_lights = EntityHashSet::default(); + for (entity, directional_light) in directional_lights { + live_directional_lights.insert(entity); + + let slot = self.directional_slots.get_or_allocate(entity); + self.directional_lights + .grow_and_set(slot, GpuDirectionalLight::new(directional_light)); + self.add_light( + LightSourceId::Directional(entity), + GpuLightSource::new_directional_light(slot), + ); + } + + let stale: Vec = self + .directional_slots + .keys() + .copied() + .filter(|entity| !live_directional_lights.contains(entity)) + .collect(); + for entity in stale { + self.directional_slots.remove(&entity); + self.remove_light(LightSourceId::Directional(entity)); + } + + self.write_light_id_translations(); + + if self.index.len() > u16::MAX as usize { + panic!("Too many light sources in the scene, maximum is 65535."); + } + } + + pub fn add_light(&mut self, id: LightSourceId, source: GpuLightSource) { + let index = self.index.insert(id); + self.sources.grow_and_set(index, source); + } + + /// Removes a light, moving the last one down into the hole so the array stays gap-free. + pub fn remove_light(&mut self, id: LightSourceId) { + let Some((index, last)) = self.index.remove(id) else { + return; + }; + + if index != last { + let source = self.sources.get(last); + self.sources.grow_and_set(index, source); + } + } + + /// Rolls the translation table over for a new frame. + /// + /// `previous_index` and `changed` only advance once the shader has read the table. The + /// lighting node bails out while its pipelines compile, and the reservoirs keep the older ids + /// across such a gap, so the next table has to translate from those instead. `has_consumers` + /// is false when no view runs Solari lighting, where deferring forever would grow both + /// without bound. + pub fn begin_frame(&mut self, has_consumers: bool) { + for index in core::mem::take(&mut self.nonidentity_translations) { + self.previous_frame_id_translations + .grow_and_set(index, index); + } + + if !has_consumers || self.translations_consumed.swap(false, Ordering::Relaxed) { + for id in core::mem::take(&mut self.index.changed) { + match self.index.get(&id) { + Some(index) => self.previous_index.insert(id, index), + None => self.previous_index.remove(&id), + }; + } + } + } + + /// Records that the lighting shader read this frame's translation table. + pub fn note_translations_consumed(&self) { + self.translations_consumed.store(true, Ordering::Relaxed); + } + + /// Records where each light that moved or disappeared this frame ended up, so that reservoirs + /// still carrying last frame's light ids can be remapped. + fn write_light_id_translations(&mut self) { + for id in &self.index.changed { + // Lights that first appeared since the last read table have no previous id + let Some(&previous) = self.previous_index.get(id) else { + continue; + }; + let current = self.index.get(id).unwrap_or(LIGHT_NOT_PRESENT_THIS_FRAME); + + if current != previous { + self.previous_frame_id_translations + .grow_and_set(previous, current); + self.nonidentity_translations.push(previous); + } + } + + // Every index the shader might read has to be backed by a real element + let light_count = self.index.len() as u32; + let translations = &mut self.previous_frame_id_translations; + if translations.len() < light_count { + let start = translations.len(); + translations.grow(light_count); + for index in start..light_count { + translations.set(index, index); + } + } + } +} + +#[cfg(test)] +mod tests { + use super::{LightIndex, LightSourceId}; + use bevy_ecs::entity::Entity; + + #[test] + fn light_index_keeps_sources_on_the_same_entity_independent() { + let entity = Entity::PLACEHOLDER; + let emissive = LightSourceId::EmissiveMesh(entity); + let directional = LightSourceId::Directional(entity); + let mut lights = LightIndex::default(); + + assert_eq!(lights.insert(emissive), 0); + assert_eq!(lights.insert(directional), 1); + assert_eq!(lights.insert(emissive), 0); + assert_eq!(lights.len(), 2); + + assert_eq!(lights.remove(emissive), Some((0, 1))); + assert_eq!(lights.get(&emissive), None); + assert_eq!(lights.get(&directional), Some(0)); + assert_eq!(lights.len(), 1); + + assert_eq!(lights.remove(directional), Some((0, 0))); + assert!(lights.is_empty()); + } +} diff --git a/src/scene/binder/mod.rs b/src/scene/binder/mod.rs new file mode 100644 index 0000000..bb4fc47 --- /dev/null +++ b/src/scene/binder/mod.rs @@ -0,0 +1,268 @@ +mod allocator; +mod assets; +mod bind_group; +mod instances; +mod lights; +mod tlas; +mod tlas_build; + +use bevy_ecs::{ + entity::Entity, + lifecycle::RemovedComponents, + resource::Resource, + system::{Query, Res, ResMut}, + world::{FromWorld, World}, +}; +use bevy_pbr::ExtractedDirectionalLight; +use bevy_render::{ + mesh::allocator::MeshAllocator, + render_asset::{ExtractedAssets, RenderAssets}, + render_resource::{binding_types::*, *}, + renderer::{RenderDevice, RenderQueue}, + texture::GpuImage, +}; +use tracing::info_span; + +use self::{ + assets::{AssetState, MAX_TEXTURE_COUNT}, + bind_group::{BindGroupCacheState, GpuEnvironmentMapLight}, + instances::{ + ChangedMeshInstanceFilter, ChangedTapeInstanceFilter, InstanceInputs, InstanceState, + MAX_MESH_SLAB_COUNT, MeshInstanceQueryData, TapeInstanceQueryData, + }, + lights::LightState, + tlas::TlasState, +}; +pub use self::{ + bind_group::prepare_raytracing_scene_bind_group, + tlas::{TlasInstanceSetupPipeline, build_raytracing_tlas}, +}; +use super::{ + RaytracingMesh3d, Tape3d, extract::StandardMaterialAssets, + meshes::blas::BlasManager as MeshBlasManager, tapes::blas::BlasManager as TapeBlasManager, +}; +use crate::scene::tapes::allocator::TapeAllocator; + +/// Insert this resource into the render world to make the raytracing scene +/// retain the previous frame's TLAS and the light id translation table that +/// maps into it. +/// +/// This is useful for temporal techniques that need last frame's data. +/// Retaining it costs a second TLAS allocation and rebuild, so the scene only +/// does so while something asks for it. +#[derive(Resource, Default)] +pub struct RaytracingSceneNeedsPreviousFrameData; + +#[derive(Resource)] +pub struct RaytracingSceneBindings { + pub bind_group: Option, + pub bind_group_layout: BindGroupLayoutDescriptor, + assets: AssetState, + instances: InstanceState, + lights: LightState, + tlas: TlasState, + bind_groups: BindGroupCacheState, + environment_map_light_sampler: Sampler, + environment_map_light_buffer: StorageBuffer, +} + +impl RaytracingSceneBindings { + /// Records that a lighting pass read + /// `previous_frame_light_id_translations`, so the next frame's table + /// translates from this frame's light ids rather than older ones. + pub fn note_light_translations_consumed(&self) { + self.lights.note_translations_consumed(); + } +} + +impl FromWorld for RaytracingSceneBindings { + fn from_world(world: &mut World) -> Self { + let render_device = world.resource::(); + + let bind_group_layout = BindGroupLayoutDescriptor::new( + "raytracing_scene_bind_group_layout", + &BindGroupLayoutEntries::sequential( + ShaderStages::COMPUTE, + ( + storage_buffer_read_only_sized(false, None).count(MAX_MESH_SLAB_COUNT), + storage_buffer_read_only_sized(false, None).count(MAX_MESH_SLAB_COUNT), + storage_buffer_read_only_sized(false, None).count(MAX_MESH_SLAB_COUNT), + texture_2d(TextureSampleType::Float { filterable: true }) + .count(MAX_TEXTURE_COUNT), + sampler(SamplerBindingType::Filtering).count(MAX_TEXTURE_COUNT), + storage_buffer_read_only_sized(false, None), + acceleration_structure(), + acceleration_structure(), + storage_buffer_read_only_sized(false, None), + storage_buffer_read_only_sized(false, None), + storage_buffer_read_only_sized(false, None), + storage_buffer_read_only_sized(false, None), + storage_buffer_read_only_sized(false, None), + storage_buffer_read_only_sized(false, None), + storage_buffer_read_only_sized(false, None), + storage_buffer_read_only_sized(false, None), + texture_2d(TextureSampleType::Float { filterable: true }), + sampler(SamplerBindingType::Filtering), + texture_cube(TextureSampleType::Float { filterable: true }), + sampler(SamplerBindingType::Filtering), + storage_buffer_read_only_sized(false, None), + ), + ), + ); + + let environment_map_light_sampler = render_device.create_sampler(&SamplerDescriptor { + label: Some("solari_environment_map_light_sampler"), + address_mode_u: AddressMode::ClampToEdge, + address_mode_v: AddressMode::ClampToEdge, + address_mode_w: AddressMode::ClampToEdge, + mag_filter: FilterMode::Linear, + min_filter: FilterMode::Linear, + mipmap_filter: MipmapFilterMode::Linear, + ..Default::default() + }); + + let mut environment_map_light_buffer = StorageBuffer::::default(); + environment_map_light_buffer.set_label(Some("solari_environment_map_light")); + + Self { + bind_group: None, + bind_group_layout, + assets: AssetState::new(), + instances: InstanceState::new(), + lights: LightState::new(), + tlas: TlasState::new(render_device), + bind_groups: BindGroupCacheState::new(render_device), + environment_map_light_sampler, + environment_map_light_buffer, + } + } +} + +/// Applies this frame's scene changes to the retained buffers, binding arrays +/// and TLAS. +pub fn prepare_raytracing_scene_resources( + (mesh_instances, tape_instances): (Query, Query), + (changed_mesh_instances, changed_tape_instances): ( + Query, + Query, + ), + (mut removed_mesh_instances, mut removed_tape_instances): ( + RemovedComponents, + RemovedComponents, + ), + directional_lights: Query<(Entity, &ExtractedDirectionalLight)>, + needs_previous_frame_data: Option>, + (mesh_allocator, tape_allocator): (Res, Res), + (mesh_blas_manager, tape_blas_manager): (Res, Res), + material_assets: Res, + texture_assets: Res>, + extracted_images: Res>, + render_device: Res, + render_queue: Res, + pipeline_cache: Res, + instance_setup_pipeline: Res, + mut bindings: ResMut, +) { + let bindings = &mut *bindings; + let needs_previous_frame_data = needs_previous_frame_data.is_some(); + + // Roll light ids over before any removal or compaction writes this frame's + // translations + bindings.lights.begin_frame(needs_previous_frame_data); + + // Update material and texture assets + bindings + .assets + .update_materials(&mut bindings.instances, &material_assets, &texture_assets); + bindings.assets.update_textures( + &mut bindings.instances, + &extracted_images, + &texture_assets, + &material_assets, + ); + + // Apply structural instance changes, now that asset slots are current + bindings + .instances + .remove_instances(&mut bindings.lights, removed_mesh_instances.read()); + bindings + .instances + .remove_instances(&mut bindings.lights, removed_tape_instances.read()); + let inputs = InstanceInputs { + assets: &bindings.assets, + mesh_blas_manager: &mesh_blas_manager, + mesh_allocator: &mesh_allocator, + tape_blas_manager: &tape_blas_manager, + tape_allocator: &tape_allocator, + }; + bindings.instances.refresh_instances( + &inputs, + &mut bindings.lights, + &mesh_instances, + &changed_mesh_instances, + &tape_instances, + &changed_tape_instances, + ); + + // Update the light set, now that emissive instances are resolved + bindings.lights.update(&directional_lights); + + // Upload the above writes + write_sparse_buffers(bindings, &render_device, &render_queue); + + // Prepare the next TLAS + let build_ready = !bindings.tlas.uses_raw_build() + || instance_setup_pipeline + .id + .and_then(|id| pipeline_cache.get_compute_pipeline(id)) + .is_some(); + bindings.tlas.advance( + &bindings.instances, + &mut bindings.bind_groups, + &render_device, + build_ready, + needs_previous_frame_data, + ); +} + +/// Grows every sparse buffer to hold at least one element, then snapshots its +/// dirty set into either a staged sparse update or a full reupload. +fn write_sparse_buffers( + bindings: &mut RaytracingSceneBindings, + device: &RenderDevice, + queue: &RenderQueue, +) { + let _span = info_span!("write_buffers").entered(); + + let assets = &mut bindings.assets; + assets.materials.grow(1); + assets.materials.write_buffers(device, queue); + + let instances = &mut bindings.instances; + instances.transforms.grow(1); + instances.transforms.write_buffers(device, queue); + instances.previous_frame_transforms.grow(1); + instances + .previous_frame_transforms + .write_buffers(device, queue); + instances.geometry_ids.grow(1); + instances.geometry_ids.write_buffers(device, queue); + instances.tape_ids.grow(1); + instances.tape_ids.write_buffers(device, queue); + instances.material_ids.grow(1); + instances.material_ids.write_buffers(device, queue); + if bindings.tlas.uses_raw_build() { + instances.blas_refs.grow(1); + instances.blas_refs.write_buffers(device, queue); + } + + let lights = &mut bindings.lights; + lights.sources.grow(1); + lights.sources.write_buffers(device, queue); + lights.directional_lights.grow(1); + lights.directional_lights.write_buffers(device, queue); + lights.previous_frame_id_translations.grow(1); + lights + .previous_frame_id_translations + .write_buffers(device, queue); +} diff --git a/src/scene/binder/setup_tlas_instances.wesl b/src/scene/binder/setup_tlas_instances.wesl new file mode 100644 index 0000000..da9bbf6 --- /dev/null +++ b/src/scene/binder/setup_tlas_instances.wesl @@ -0,0 +1,25 @@ +@group(0) @binding(0) var transforms: array, 3>>; +@group(0) @binding(1) var blas_refs: array>; +@group(0) @binding(2) var instances: array; + +struct TlasInstance { + transform: array, 3>, + custom_data_and_mask: u32, + sbt_offset_and_flags: u32, + blas_ref: vec2, +} + +@compute @workgroup_size(64, 1, 1) +fn setup_tlas_instances(@builtin(global_invocation_id) global_id: vec3) { + let slot = global_id.x; + if slot >= arrayLength(&instances) || slot >= arrayLength(&blas_refs) || slot >= arrayLength(&transforms) { + return; + } + + instances[slot] = TlasInstance( + transforms[slot], + (slot & 0xFFFFFFu) | 0xFF000000u, + 0u, + blas_refs[slot], + ); +} diff --git a/src/scene/binder/tlas.rs b/src/scene/binder/tlas.rs new file mode 100644 index 0000000..64ad3af --- /dev/null +++ b/src/scene/binder/tlas.rs @@ -0,0 +1,570 @@ +use bevy_asset::load_embedded_asset; +use bevy_ecs::{ + resource::Resource, + system::{Res, ResMut}, + world::{FromWorld, World}, +}; +use bevy_render::{ + diagnostic::RecordDiagnostics, + render_resource::{ + AccelerationStructureFlags, AccelerationStructureUpdateMode, BindGroup, BindGroupEntries, + BindGroupLayoutDescriptor, BindGroupLayoutEntries, Buffer, BufferDescriptor, BufferId, + BufferUsages, CachedComputePipelineId, CommandEncoderDescriptor, ComputePassDescriptor, + ComputePipelineDescriptor, CreateTlasDescriptor, PipelineCache, ShaderStages, Tlas, + TlasInstance, + binding_types::{storage_buffer_read_only_sized, storage_buffer_sized}, + }, + renderer::{RenderContext, RenderDevice}, +}; +use bevy_utils::{default, once}; +use tracing::{info_span, warn}; +use wgpu::{BufferTransition, BufferUses}; + +use super::{ + MeshBlasManager, RaytracingSceneBindings, TapeBlasManager, bind_group::BindGroupCacheState, + instances::InstanceState, tlas_build, +}; +use crate::scene::binder::instances::Object; + +/// Compute pipeline that writes per-slot transforms and BLAS addresses into +/// TLAS descriptors. +#[derive(Resource)] +pub struct TlasInstanceSetupPipeline { + pub layout: BindGroupLayoutDescriptor, + pub id: Option, +} + +impl FromWorld for TlasInstanceSetupPipeline { + fn from_world(world: &mut World) -> Self { + let layout = BindGroupLayoutDescriptor::new( + "tlas_instance_setup_bind_group_layout", + &BindGroupLayoutEntries::sequential( + ShaderStages::COMPUTE, + ( + storage_buffer_read_only_sized(false, None), + storage_buffer_read_only_sized(false, None), + storage_buffer_sized(false, None), + ), + ), + ); + + if tlas_build::resolve(world.resource::()).is_none() { + return Self { layout, id: None }; + } + + let shader = load_embedded_asset!(world, "setup_tlas_instances.wesl"); + let id = + world + .resource::() + .queue_compute_pipeline(ComputePipelineDescriptor { + label: Some("tlas_instance_setup_pipeline".into()), + layout: vec![layout.clone()], + shader, + entry_point: Some("setup_tlas_instances".into()), + ..default() + }); + + Self { + layout, + id: Some(id), + } + } +} + +/// Smallest TLAS instance capacity handed out, and the floor +/// [`tlas_capacity_for`] grows from. +const TLAS_MIN_CAPACITY: u32 = 128; + +/// Width of a TLAS instance's custom data in both Vulkan +/// (`instanceCustomIndex`) and DXR (`InstanceID`). `setup_tlas_instances.wgsl` +/// writes instance slots into that field, so they have to fit. +const TLAS_CUSTOM_DATA_BITS: u32 = 24; + +/// Instance capacity to allocate to hold `instance_count` slots. +/// +/// Grows geometrically rather than by a fixed step, so reallocations over a +/// scene's lifetime are logarithmic in its size. Being a pure function of the +/// count keeps the descriptor buffer and both TLASes on the same capacity curve +/// without having to coordinate their previous sizes. +fn tlas_capacity_for(instance_count: u32) -> u32 { + let mut capacity = TLAS_MIN_CAPACITY; + while capacity < instance_count { + capacity = capacity.saturating_add(capacity.div_ceil(2)); + } + capacity +} + +/// The TLAS and its capacity state, double buffered only while something traces +/// last frame's. +/// +/// An acceleration structure is only bindable once it has been built. Nothing +/// here owns a BLAS: keeping the ones a built structure points at alive is +/// [`BlasManager`]'s job, which defers every retirement until +/// [`BlasManager::note_tlas_build`] has seen both structures rebuilt. +pub struct TlasState { + /// The backend to build through, or `None` to go through `wgpu-core`. + raw: Option<&'static dyn tlas_build::RawTlasBackend>, + /// Whether last frame's structure is being retained alongside this frame's. + double_buffered: bool, + /// Alternating current/previous acceleration structures. The second is + /// `None` while single buffered. + pub structures: [Option; 2], + capacity: [u32; 2], + /// Whether each structure has had a build recorded since its latest + /// allocation. + pub built: [bool; 2], + /// Which of [`Self::structures`] this frame builds into. The other holds + /// last frame's. + pub current_index: usize, + pub instance_descriptors: Option, + instance_descriptor_capacity: u32, + pub scratch: Option, + scratch_capacity: u64, + scratch_sized_for: u32, + pub instance_setup_bind_group: Option, + instance_setup_buffer_ids: Option<[BufferId; 3]>, +} + +impl TlasState { + pub fn new(render_device: &RenderDevice) -> Self { + Self { + raw: tlas_build::resolve(render_device), + double_buffered: false, + structures: [None, None], + capacity: [0, 0], + built: [false, false], + current_index: 0, + instance_descriptors: None, + instance_descriptor_capacity: 0, + scratch: None, + scratch_capacity: 0, + scratch_sized_for: 0, + instance_setup_bind_group: None, + instance_setup_buffer_ids: None, + } + } + + /// Whether builds go through [`tlas_build`]'s raw path rather than + /// `wgpu-core`. + pub fn uses_raw_build(&self) -> bool { + self.raw.is_some() + } + + /// Brings the acceleration structure up to date with this frame's changes. + /// + /// While `double_buffered`, the two structures alternate: this frame's is + /// rebuilt, and last frame's stays intact so the shaders can trace + /// against it. Otherwise the single structure is rebuilt in place, + /// which is safe because the build is recorded before any pass that traces + /// it and nothing reads last frame's contents. + /// + /// `build_ready` reports whether this frame will be able to record a build. + /// When false nothing is allocated or swapped, though an unused + /// structure is still released. + pub fn advance( + &mut self, + instances: &InstanceState, + bind_groups: &mut BindGroupCacheState, + render_device: &RenderDevice, + build_ready: bool, + double_buffered: bool, + ) { + let _span = info_span!("advance_tlas").entered(); + + // Free the retained structure as soon as nothing wants it + self.set_double_buffered(double_buffered, bind_groups); + + // An empty scene must not allocate an unbuilt TLAS that could resurface + // as a later previous-frame entry + if !build_ready || instances.slots.high_water_mark() == 0 { + return; + } + + debug_assert!( + instances.slots.high_water_mark() < 1 << TLAS_CUSTOM_DATA_BITS, + "instance slot count {} does not fit in a TLAS instance's custom data", + instances.slots.high_water_mark() + ); + + // Secure every build input before committing the swap. Neither buffer + // exists on the wgpu-core path, which builds from instances + // written into the TLAS itself. + let instance_count = instances.slots.high_water_mark(); + if self.raw.is_some() { + self.reserve_instance_descriptors(instance_count, render_device); + self.reserve_tlas_scratch(render_device); + if self.instance_descriptors.is_none() || self.scratch.is_none() { + return; + } + } + + if self.double_buffered { + self.current_index ^= 1; + } + let current_index = self.current_index; + self.reserve_tlas(current_index, instance_count, render_device, bind_groups); + } + + /// Switches between retaining last frame's structure and rebuilding a + /// single one in place, dropping the structure that is no longer + /// traced. + fn set_double_buffered( + &mut self, + double_buffered: bool, + bind_groups: &mut BindGroupCacheState, + ) { + if self.double_buffered != double_buffered { + self.double_buffered = double_buffered; + bind_groups.invalid = true; + } + if double_buffered { + return; + } + + // Keep building into whichever structure is already current, so the + // frame this turns off does not have to allocate + let previous_index = self.current_index ^ 1; + if self.structures[previous_index].take().is_some() { + self.capacity[previous_index] = 0; + self.built[previous_index] = false; + bind_groups.invalid = true; + } + } + + /// Whether the previous-frame slot's binding will still be correct next + /// frame, and so whether a bind group using it can be cached. + pub fn previous_binding_is_stable(&self) -> bool { + !self.double_buffered || self.built[self.current_index ^ 1] + } + + /// Rebuilds the setup shader's bind group only when one of its three + /// buffers moves. + pub fn update_instance_setup_bind_group( + &mut self, + instances: &InstanceState, + render_device: &RenderDevice, + pipeline_cache: &PipelineCache, + pipeline: &TlasInstanceSetupPipeline, + ) { + let (Some(transforms), Some(blas_refs), Some(instances)) = ( + instances.transforms.buffer(), + instances.blas_refs.buffer(), + self.instance_descriptors.as_ref(), + ) else { + self.instance_setup_bind_group = None; + return; + }; + + let ids = [transforms.id(), blas_refs.id(), instances.id()]; + if self.instance_setup_bind_group.is_some() && self.instance_setup_buffer_ids == Some(ids) { + return; + } + + let layout = pipeline_cache.get_bind_group_layout(&pipeline.layout); + self.instance_setup_bind_group = Some(render_device.create_bind_group( + "tlas_instance_setup_bind_group", + &layout, + &BindGroupEntries::sequential(( + transforms.as_entire_binding(), + blas_refs.as_entire_binding(), + instances.as_entire_binding(), + )), + )); + self.instance_setup_buffer_ids = Some(ids); + } + + /// Makes sure the instance descriptor buffer covers every stable slot. + fn reserve_instance_descriptors(&mut self, needed: u32, render_device: &RenderDevice) { + if self.instance_descriptors.is_some() && needed <= self.instance_descriptor_capacity { + return; + } + + let capacity = tlas_capacity_for(needed); + self.instance_descriptors = Some(render_device.create_buffer(&BufferDescriptor { + label: Some("solari_tlas_instance_descriptors"), + size: u64::from(capacity) * tlas_build::INSTANCE_DESCRIPTOR_SIZE, + usage: BufferUsages::STORAGE | BufferUsages::TLAS_INPUT, + mapped_at_creation: false, + })); + self.instance_descriptor_capacity = capacity; + self.instance_setup_bind_group = None; + } + + /// Makes sure the build scratch buffer is big enough for this frame's + /// descriptor capacity. + fn reserve_tlas_scratch(&mut self, render_device: &RenderDevice) { + let capacity = self.instance_descriptor_capacity; + if self.scratch.is_some() && capacity <= self.scratch_sized_for { + return; + } + + let (Some(backend), Some(instances)) = (self.raw, self.instance_descriptors.as_ref()) + else { + return; + }; + let Some(needed) = backend.scratch_size(render_device, instances, capacity) else { + return; + }; + self.scratch_sized_for = capacity; + + if self.scratch.is_some() && needed <= self.scratch_capacity { + return; + } + + // The setup transition lets wgpu retain an outgrown scratch buffer + // until in-flight work releases it + self.scratch = backend.create_scratch_buffer(render_device, needed); + self.scratch_capacity = if self.scratch.is_some() { needed } else { 0 }; + } + + /// Makes sure one of the two structures can hold every instance slot, + /// leaving the other alone. + fn reserve_tlas( + &mut self, + current_index: usize, + needed: u32, + render_device: &RenderDevice, + bind_groups: &mut BindGroupCacheState, + ) { + if self.structures[current_index].is_some() && needed <= self.capacity[current_index] { + return; + } + + let capacity = tlas_capacity_for(needed); + self.structures[current_index] = Some(render_device.wgpu_device().create_tlas( + &CreateTlasDescriptor { + label: Some("tlas"), + flags: AccelerationStructureFlags::PREFER_FAST_TRACE, + update_mode: AccelerationStructureUpdateMode::Build, + max_instances: capacity, + }, + )); + self.capacity[current_index] = capacity; + self.built[current_index] = false; + bind_groups.invalid = true; + } +} + +/// Records this frame's TLAS build into the render graph's command encoder. +pub fn build_raytracing_tlas( + mut bindings: ResMut, + mut mesh_blas_manager: ResMut, + mut tape_blas_manager: ResMut, + pipeline_cache: Res, + pipeline: Res, + mut render_context: RenderContext, +) { + let bindings = &mut *bindings; + let current_index = bindings.tlas.current_index; + + let built = match bindings.tlas.raw { + Some(backend) => { + setup_tlas_instances(bindings, &pipeline_cache, &pipeline, &mut render_context) + && build_tlas_raw(bindings, backend, &mut render_context) + }, + None => build_tlas_through_wgpu_core( + bindings, + &mesh_blas_manager, + &tape_blas_manager, + &mut render_context, + ), + }; + + if built { + bindings.tlas.built[current_index] = true; + // This structure no longer points at whatever was retired before it, + // which is what lets the oldest retirements go + mesh_blas_manager.note_tlas_build(); + tape_blas_manager.note_tlas_build(); + } +} + +/// Writes this frame's TLAS instance descriptors on the GPU, ready for +/// [`build_tlas_raw`]. +/// +/// Returns whether the pass was recorded. The build has nothing to read when it +/// wasn't. +fn setup_tlas_instances( + bindings: &mut RaytracingSceneBindings, + pipeline_cache: &PipelineCache, + pipeline: &TlasInstanceSetupPipeline, + render_context: &mut RenderContext, +) -> bool { + if bindings.tlas.structures[bindings.tlas.current_index].is_none() { + return false; + } + + let (Some(bind_group), Some(compute_pipeline), Some(instances), Some(scratch)) = ( + bindings.tlas.instance_setup_bind_group.as_ref(), + pipeline + .id + .and_then(|id| pipeline_cache.get_compute_pipeline(id)), + bindings.tlas.instance_descriptors.as_ref(), + bindings.tlas.scratch.as_ref(), + ) else { + // `advance` secures all of these before it allocates the TLAS this is + // setting up for + once!(warn!( + "TLAS allocated but its instance setup pass could not be recorded: bind group={}, \ + descriptors={}, scratch={}", + bindings.tlas.instance_setup_bind_group.is_some(), + bindings.tlas.instance_descriptors.is_some(), + bindings.tlas.scratch.is_some(), + )); + return false; + }; + + let slot_count = bindings.instances.slots.high_water_mark(); + if slot_count == 0 { + return false; + } + + let diagnostics = render_context.diagnostic_recorder(); + let diagnostics = diagnostics.as_deref(); + let command_encoder = render_context.command_encoder(); + let time_span = diagnostics.time_span(command_encoder, "setup_tlas_instances"); + { + let mut pass = command_encoder.begin_compute_pass(&ComputePassDescriptor { + label: Some("setup_tlas_instances"), + timestamp_writes: None, + }); + pass.set_pipeline(compute_pipeline); + pass.set_bind_group(0, bind_group, &[]); + pass.dispatch_workgroups(slot_count.div_ceil(64), 1, 1); + } + time_span.end(command_encoder); + + command_encoder.transition_resources( + [ + BufferTransition { + buffer: &**instances, + state: BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + }, + BufferTransition { + buffer: &**scratch, + state: BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + }, + ] + .into_iter(), + core::iter::empty(), + ); + + true +} + +/// Builds from the descriptors [`setup_tlas_instances`] wrote, straight through +/// `wgpu_hal`. +fn build_tlas_raw( + bindings: &mut RaytracingSceneBindings, + backend: &dyn tlas_build::RawTlasBackend, + render_context: &mut RenderContext, +) -> bool { + let current_index = bindings.tlas.current_index; + let (Some(tlas), Some(instances), Some(scratch)) = ( + bindings.tlas.structures[current_index].as_mut(), + bindings.tlas.instance_descriptors.as_ref(), + bindings.tlas.scratch.as_ref(), + ) else { + once!(warn!( + "TLAS instances were set up but not built: structure={}, descriptors={}, scratch={}", + bindings.tlas.structures[current_index].is_some(), + bindings.tlas.instance_descriptors.is_some(), + bindings.tlas.scratch.is_some(), + )); + return false; + }; + + let render_device = render_context.render_device().clone(); + let diagnostics = render_context.diagnostic_recorder(); + let diagnostics = diagnostics.as_deref(); + let time_span = diagnostics.time_span(render_context.command_encoder(), "tlas_build"); + + let mut command_encoder = render_device.create_command_encoder(&CommandEncoderDescriptor { + label: Some("tlas_build_command_encoder"), + }); + let built = backend.build_tlas( + &mut command_encoder, + tlas, + instances, + bindings.instances.slots.high_water_mark(), + scratch, + ); + render_context.add_command_buffer(command_encoder.finish()); + + time_span.end(render_context.command_encoder()); + if !built { + once!(warn!( + "TLAS build recorded nothing; the resolved backend does not own the build resources." + )); + } + built +} + +/// Builds from instance descriptors filled in on the CPU, through `wgpu-core`. +/// +/// The portable path, and the only one Metal can use. It costs work per +/// instance every frame rather than only for the ones that moved, and +/// `wgpu-core` then re-derives the whole build from what it is handed here, +/// which is the cost [`tlas_build`] exists to avoid. +fn build_tlas_through_wgpu_core( + bindings: &mut RaytracingSceneBindings, + mesh_blas_manager: &MeshBlasManager, + tape_blas_manager: &TapeBlasManager, + render_context: &mut RenderContext, +) -> bool { + // An empty scene leaves the index unswapped, so whatever is here belongs to + // an earlier frame and is still being traced as the previous one + if bindings.instances.slots.high_water_mark() == 0 { + return false; + } + let current_index = bindings.tlas.current_index; + let Some(tlas) = bindings.tlas.structures[current_index].as_mut() else { + return false; + }; + + { + let _span = info_span!("fill_tlas_instances").entered(); + + // The TLAS outlives the frame, so a slot freed or deactivated since its + // last build still holds that build's instance and has to be + // cleared before this frame's are written + let capacity = tlas.get().len(); + tlas[0..capacity].iter_mut().for_each(|entry| *entry = None); + + for (slot, object, transform) in bindings.instances.drawable() { + // A mesh can lose its acceleration structure after the instance + // resolved against it, which leaves the slot with + // nothing to point at for a frame + let Some(blas) = (match object { + Object::Mesh(mesh) => mesh_blas_manager.get(&mesh), + Object::Tape(tape) => tape_blas_manager.get(&tape), + }) else { + continue; + }; + tlas[slot as usize] = Some(TlasInstance::new(blas, transform, slot, 0xFF)); + } + } + + let diagnostics = render_context.diagnostic_recorder(); + let diagnostics = diagnostics.as_deref(); + let command_encoder = render_context.command_encoder(); + let time_span = diagnostics.time_span(command_encoder, "tlas_build"); + command_encoder.build_acceleration_structures(&[], [&*tlas]); + time_span.end(command_encoder); + + true +} + +#[cfg(test)] +mod tests { + use super::{TLAS_MIN_CAPACITY, tlas_capacity_for}; + + #[test] + fn tlas_capacity_grows_geometrically_at_boundaries() { + assert_eq!(tlas_capacity_for(0), TLAS_MIN_CAPACITY); + assert_eq!(tlas_capacity_for(TLAS_MIN_CAPACITY), TLAS_MIN_CAPACITY); + assert_eq!(tlas_capacity_for(TLAS_MIN_CAPACITY + 1), 192); + assert_eq!(tlas_capacity_for(192), 192); + assert_eq!(tlas_capacity_for(193), 288); + } +} diff --git a/src/scene/binder/tlas_build.rs b/src/scene/binder/tlas_build.rs new file mode 100644 index 0000000..0cb6d3f --- /dev/null +++ b/src/scene/binder/tlas_build.rs @@ -0,0 +1,299 @@ +//! Building the binder's TLAS through `wgpu_hal` directly, bypassing `wgpu-core` and using +//! an indirect acceleration structure build. +//! +//! Vulkan and DX12 only, as their instance descriptors are byte-identical. Metal cannot work this +//! way: `wgpu-core` makes a TLAS's BLASes resident from its dependency list, and +//! `mark_acceleration_structures_built` clears that list, so traversal would read memory Metal is +//! free to have evicted. Every other backend falls back to the `wgpu-core` build in [`super::tlas`]. +//! +//! Every operation has to be instantiated per backend, as `as_hal` is generic over the hal type and +//! wgpu exposes no dynamic equivalent. [`resolve`] does that once, by trying each compiled-in +//! backend and relying on `as_hal` returning `None` for a device that isn't its own, which can't +//! disagree with the adapter actually in use. + +#![expect( + unsafe_code, + reason = "Building the TLAS without wgpu-core's per-instance cost requires wgpu_hal." +)] +// With neither backend compiled in every arm is cfg'd away, so nothing here is instantiated. It +// still has to exist, because Solari compiles everywhere and only declines to load at runtime. +#![cfg_attr( + not(any( + windows, + target_os = "linux", + target_os = "android", + target_os = "freebsd" + )), + expect( + dead_code, + unused_variables, + reason = "no backend with a raw TLAS build path is compiled in for this target" + ) +)] + +use bevy_render::{ + render_resource::{Blas, Buffer, BufferDescriptor, BufferUsages, CommandEncoder, Tlas}, + renderer::RenderDevice, +}; +use core::marker::PhantomData; +use wgpu::{hal, BufferUses}; + +/// Size of one TLAS instance descriptor, on both Vulkan and DXR. +pub const INSTANCE_DESCRIPTOR_SIZE: u64 = 64; + +/// Flags the TLAS is created with, which its build has to be given again. +const TLAS_BUILD_FLAGS: wgpu::AccelerationStructureFlags = + wgpu::AccelerationStructureFlags::PREFER_FAST_TRACE; + +/// The `wgpu_hal` operations a raw TLAS build needs, bound to one backend by [`resolve`]. +pub trait RawTlasBackend: Send + Sync { + /// Scratch space a TLAS build over `instance_count` instances of `instances` needs. + fn scratch_size( + &self, + render_device: &RenderDevice, + instances: &Buffer, + instance_count: u32, + ) -> Option; + + /// Allocates a buffer usable as acceleration structure build scratch. + /// + /// There is no [`BufferUsages`] for scratch and `STORAGE` won't do, as Vulkan only adds + /// `SHADER_DEVICE_ADDRESS` for acceleration structure usages. So it is created through hal and + /// handed to `wgpu-core` to own. `wgpu-core` only defers freeing what a submission's tracker + /// references, so the caller transitioning it each frame is what makes replacing it safe. + fn create_scratch_buffer(&self, render_device: &RenderDevice, size: u64) -> Option; + + /// Records a TLAS build reading instance descriptors straight out of `instances`. + /// + /// The caller must already have transitioned `instances` to + /// `BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT` and `scratch` to + /// `BufferUses::ACCELERATION_STRUCTURE_SCRATCH`, on an earlier command buffer in the same + /// submission. The scratch transition is not optional even when its state is unchanged: scratch + /// is an exclusive usage, so the redundant-looking transition is what keeps consecutive frames' + /// builds from overlapping in it. + /// + /// `encoder` must have no wgpu command recorded into it, including timestamp writes, as + /// `wgpu-core` panics if an encoder mixes the wgpu and raw encoding APIs. + /// + /// Marking the build clears the TLAS's dependency list, which is what otherwise keeps the + /// BLASes it points at alive. The caller has to retain them past every submission that might + /// still trace it. + fn build_tlas( + &self, + encoder: &mut CommandEncoder, + tlas: &mut Tlas, + instances: &Buffer, + instance_count: u32, + scratch: &Buffer, + ) -> bool; +} + +/// The backend to build through, or `None` where this device has no raw path. +pub fn resolve(render_device: &RenderDevice) -> Option<&'static dyn RawTlasBackend> { + let device = render_device.wgpu_device(); + + #[cfg(any( + windows, + target_os = "linux", + target_os = "android", + target_os = "freebsd" + ))] + // SAFETY: the handle is only read, and is dropped with the guard + if unsafe { device.as_hal::() }.is_some() { + return Some(&Hal::::NEW); + } + + #[cfg(windows)] + // SAFETY: the handle is only read, and is dropped with the guard + if unsafe { device.as_hal::() }.is_some() { + return Some(&Hal::::NEW); + } + + None +} + +/// [`RawTlasBackend`] for one hal backend. +/// +/// `fn() -> A` rather than `A`, so the marker is [`Send`] and [`Sync`] whatever `A` is. +struct Hal(PhantomData A>); + +impl Hal { + const NEW: Self = Self(PhantomData); + + /// Records the build itself, leaving [`RawTlasBackend::build_tlas`] to mark it. + fn record_build( + &self, + encoder: &mut CommandEncoder, + tlas: &mut Tlas, + instances: &Buffer, + instance_count: u32, + scratch: &Buffer, + ) -> Option<()> { + use hal::CommandEncoder as _; + + // Workaround for https://github.com/gfx-rs/wgpu/issues/10191 + let buffer_address = |buffer: &Buffer| { + // SAFETY: the handle is only read, and the buffer is not destroyed here + let guard = unsafe { buffer.as_hal::() }?; + Some(core::ptr::from_ref::(&*guard)) + }; + let hal_instances = buffer_address(instances)?; + let hal_scratch = buffer_address(scratch)?; + // SAFETY: the handle is only read, and the TLAS is not destroyed here + let hal_tlas = unsafe { tlas.as_hal::() }?; + + // SAFETY: both buffers outlive this call through the caller's borrows, and neither is + // destroyed between reading its address and the build recording + let (hal_instances, hal_scratch) = unsafe { (&*hal_instances, &*hal_scratch) }; + + let entries = + hal::AccelerationStructureEntries::Instances(hal::AccelerationStructureInstances { + buffer: Some(hal_instances), + offset: 0, + count: instance_count, + }); + + let descriptor = hal::BuildAccelerationStructureDescriptor { + entries: &entries, + mode: hal::AccelerationStructureBuildMode::Build, + flags: TLAS_BUILD_FLAGS, + source_acceleration_structure: None, + destination_acceleration_structure: &*hal_tlas, + scratch_buffer: hal_scratch, + scratch_buffer_offset: 0, + }; + + // The caller transitioned both buffers, so the only barriers left are the acceleration + // structure's own, which have no public spelling. + // + // SAFETY: every resource in `descriptor` belongs to backend `A` and to this device, the + // scratch buffer is sized by `scratch_size` and used by no other build in this submission, + // and the encoder is neither ended nor its raw handle destroyed here + unsafe { + encoder.as_hal_mut::(|encoder| { + let encoder = encoder?; + + // Write-after-read against submissions still tracing this TLAS as their previous + // frame, and against a BLAS compaction copy submitted ahead of this build. A + // barrier's first scope covers everything already submitted, which covers both. + encoder.place_acceleration_structure_barrier(hal::AccelerationStructureBarrier { + usage: hal::StateTransition { + from: hal::AccelerationStructureUses::SHADER_INPUT + | hal::AccelerationStructureUses::COPY_DST, + to: hal::AccelerationStructureUses::BUILD_OUTPUT + | hal::AccelerationStructureUses::BUILD_INPUT, + }, + }); + + encoder.build_acceleration_structures(1, [descriptor]); + + // And read-after-write, for the passes later this frame that trace the result + encoder.place_acceleration_structure_barrier(hal::AccelerationStructureBarrier { + usage: hal::StateTransition { + from: hal::AccelerationStructureUses::BUILD_OUTPUT, + to: hal::AccelerationStructureUses::SHADER_INPUT, + }, + }); + + Some(()) + }) + } + } +} + +impl RawTlasBackend for Hal { + fn scratch_size( + &self, + render_device: &RenderDevice, + instances: &Buffer, + instance_count: u32, + ) -> Option { + use hal::Device as _; + + // SAFETY: the handle is only read, and is dropped with the guard + let hal_device = unsafe { render_device.wgpu_device().as_hal::() }?; + // SAFETY: the handle is only read, and is dropped with the guard + let hal_instances = unsafe { instances.as_hal::() }?; + + // Sizing ignores the buffer itself, but `wgpu_hal`'s Metal path unwraps it unconditionally, + // so a real one has to be handed over + let entries = + hal::AccelerationStructureEntries::Instances(hal::AccelerationStructureInstances { + buffer: Some(&*hal_instances), + offset: 0, + count: instance_count, + }); + + // SAFETY: `entries` describes a buffer belonging to backend `A`, and the query records + // nothing and reads no memory through it + let sizes = unsafe { + hal_device.get_acceleration_structure_build_sizes( + &hal::GetAccelerationStructureBuildSizesDescriptor { + entries: &entries, + flags: TLAS_BUILD_FLAGS, + }, + ) + }; + + Some(sizes.build_scratch_size) + } + + fn create_scratch_buffer(&self, render_device: &RenderDevice, size: u64) -> Option { + use hal::Device as _; + + let device = render_device.wgpu_device(); + let hal_buffer = { + // SAFETY: the handle is only read, and is dropped with the guard + let hal_device = unsafe { device.as_hal::() }?; + // SAFETY: the descriptor is valid and the buffer is handed to `wgpu-core` below, which + // takes over destroying it + unsafe { + hal_device.create_buffer(&hal::BufferDescriptor { + label: Some("solari_tlas_scratch"), + size, + usage: BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + memory_flags: hal::MemoryFlags::empty(), + }) + } + .ok()? + }; + + // `usage` is only consulted for wgpu-level validation, which this buffer never sees + let descriptor = BufferDescriptor { + label: Some("solari_tlas_scratch"), + size, + usage: BufferUsages::STORAGE, + mapped_at_creation: false, + }; + + // SAFETY: `hal_buffer` was created from this device, matches `descriptor`, and has nonzero + // size + Some(unsafe { device.create_buffer_from_hal::(hal_buffer, &descriptor) }.into()) + } + + fn build_tlas( + &self, + encoder: &mut CommandEncoder, + tlas: &mut Tlas, + instances: &Buffer, + instance_count: u32, + scratch: &Buffer, + ) -> bool { + if self + .record_build(encoder, tlas, instances, instance_count, scratch) + .is_none() + { + return false; + } + + // Without this the build is invisible to `wgpu-core` and it rejects the TLAS when bound + // + // SAFETY: the TLAS was just built into this encoder, and every BLAS its instances point at + // was built and submitted earlier in the frame by `prepare_raytracing_blas` + unsafe { + encoder.mark_acceleration_structures_built(core::iter::empty::<&Blas>(), [&*tlas]); + } + + true + } +} diff --git a/src/scene/bindings.wesl b/src/scene/bindings.wesl new file mode 100644 index 0000000..684d55c --- /dev/null +++ b/src/scene/bindings.wesl @@ -0,0 +1,275 @@ +import bevy_pbr::render::pbr_functions::calculate_tbn_mikktspace; +import bevy_render::maths::affine3_to_square; + +enable wgpu_ray_query; +enable wgpu_binding_array; + +struct InstanceGeometryIds { + vertex_buffer_id: u32, + vertex_buffer_offset: u32, + index_buffer_id: u32, + index_buffer_offset: u32, + triangle_count: u32, +} + +struct InstanceTapeIds { + aabb_buffer_id: u32, + aabb_buffer_offset: u32, + aabb_count: u32, +} + +struct VertexBuffer { vertices: array } + +struct IndexBuffer { indices: array } + +struct AabbBuffer { indices: array } + +struct PackedVertex { + a: vec4, + b: vec4, + tangent: vec4, +} + +struct PackedAabb { + min: vec3, + max: vec3, +} + +struct Vertex { + position: vec3, + normal: vec3, + uv: vec2, + tangent: vec4, +} + +fn unpack_vertex(packed: PackedVertex) -> Vertex { + var vertex: Vertex; + vertex.position = packed.a.xyz; + vertex.normal = vec3(packed.a.w, packed.b.xy); + vertex.uv = packed.b.zw; + vertex.tangent = packed.tangent; + return vertex; +} + +struct Material { + normal_map_texture_id: u32, + base_color_texture_id: u32, + emissive_texture_id: u32, + metallic_roughness_texture_id: u32, + + base_color: vec3, + perceptual_roughness: f32, + emissive: vec3, + metallic: f32, + _padding: vec3, + reflectance: f32, +} + +const TEXTURE_MAP_NONE = 0xFFFFFFFFu; + +const MIRROR_ROUGHNESS_THRESHOLD = 0.001f; + +struct LightSource { + kind: u32, // 1 bit for kind, 31 bits for extra data + id: u32, +} + +const LIGHT_SOURCE_KIND_EMISSIVE_MESH = 0u; +const LIGHT_SOURCE_KIND_DIRECTIONAL = 1u; + +struct DirectionalLight { + direction_to_light: vec3, + cos_theta_max: f32, + luminance: vec3, + inverse_pdf: f32, +} + +struct EnvironmentMapLight { + light_from_world: mat3x3, + intensity: f32, +} + +const LIGHT_NOT_PRESENT_THIS_FRAME = 0xFFFFFFFFu; + +@group(0) @binding(0) var vertex_buffers: binding_array; +@group(0) @binding(1) var index_buffers: binding_array; +@group(0) @binding(2) var aabb_buffers: binding_array; +@group(0) @binding(3) var textures: binding_array>; +@group(0) @binding(4) var samplers: binding_array; +@group(0) @binding(5) var materials: array; +@group(0) @binding(6) var tlas: acceleration_structure; +@group(0) @binding(7) var previous_frame_tlas: acceleration_structure; +@group(0) @binding(8) var transforms: array>; +@group(0) @binding(9) var previous_frame_transforms: array>; +@group(0) @binding(10) var geometry_ids: array; +@group(0) @binding(11) var tape_ids: array; +@group(0) @binding(12) var material_ids: array; +@group(0) @binding(13) var light_sources: array; +@group(0) @binding(14) var directional_lights: array; +@group(0) @binding(15) var previous_frame_light_id_translations: array; +@group(0) @binding(16) var brdf_dfg_lut: texture_2d; +@group(0) @binding(17) var brdf_dfg_lut_sampler: sampler; +@group(0) @binding(18) var environment_map: texture_cube; +@group(0) @binding(19) var environment_map_sampler: sampler; +@group(0) @binding(20) var environment_map_light: EnvironmentMapLight; + +const RAY_T_MIN = 0.001f; +const RAY_T_MAX = 100000.0f; + +const RAY_NO_CULL = 0xFFu; + +fn trace_ray(ray_origin: vec3, ray_direction: vec3, ray_t_min: f32, ray_t_max: f32, ray_flag: u32) -> RayIntersection { + let ray = RayDesc(ray_flag, RAY_NO_CULL, ray_t_min, ray_t_max, ray_origin, ray_direction); + var rq: ray_query; + rayQueryInitialize(&rq, tlas, ray); + rayQueryProceed(&rq); + return rayQueryGetCommittedIntersection(&rq); +} + +fn trace_ray_previous_frame(ray_origin: vec3, ray_direction: vec3, ray_t_min: f32, ray_t_max: f32, ray_flag: u32) -> RayIntersection { + let ray = RayDesc(ray_flag, RAY_NO_CULL, ray_t_min, ray_t_max, ray_origin, ray_direction); + var rq: ray_query; + rayQueryInitialize(&rq, previous_frame_tlas, ray); + rayQueryProceed(&rq); + return rayQueryGetCommittedIntersection(&rq); +} + +fn sample_texture(id: u32, uv: vec2) -> vec3 { + return textureSampleLevel(textures[id], samplers[id], uv, 0.0).rgb; // TODO: Mipmap +} + +struct ResolvedMaterial { + base_color: vec3, + emissive: vec3, + reflectance: f32, + perceptual_roughness: f32, + roughness: f32, + metallic: f32, +} + +struct ResolvedRayHitFull { + world_position: vec3, + previous_frame_world_position: vec3, + world_normal: vec3, + geometric_world_normal: vec3, + world_tangent: vec4, + uv: vec2, + triangle_area: f32, + triangle_count: u32, + material: ResolvedMaterial, +} + +fn resolve_material(material: Material, uv: vec2) -> ResolvedMaterial { + var m: ResolvedMaterial; + + m.base_color = material.base_color.rgb; + if material.base_color_texture_id != TEXTURE_MAP_NONE { + m.base_color *= sample_texture(material.base_color_texture_id, uv); + } + + m.emissive = material.emissive.rgb; + if material.emissive_texture_id != TEXTURE_MAP_NONE { + m.emissive *= sample_texture(material.emissive_texture_id, uv); + } + + m.reflectance = material.reflectance; + + m.perceptual_roughness = material.perceptual_roughness; + m.metallic = material.metallic; + if material.metallic_roughness_texture_id != TEXTURE_MAP_NONE { + let metallic_roughness = sample_texture(material.metallic_roughness_texture_id, uv); + m.perceptual_roughness *= metallic_roughness.g; + m.metallic *= metallic_roughness.b; + } + + m.roughness = m.perceptual_roughness * m.perceptual_roughness; + + return m; +} + +fn resolve_ray_hit_full(ray_hit: RayIntersection) -> ResolvedRayHitFull { + let barycentrics = vec3(1.0 - ray_hit.barycentrics.x - ray_hit.barycentrics.y, ray_hit.barycentrics); + return resolve_triangle_data_full(ray_hit.instance_custom_data, ray_hit.primitive_index, barycentrics); +} + +fn load_vertices(instance_geometry_ids: InstanceGeometryIds, triangle_id: u32) -> array { + let index_buffer = &index_buffers[instance_geometry_ids.index_buffer_id].indices; + let vertex_buffer = &vertex_buffers[instance_geometry_ids.vertex_buffer_id].vertices; + + let indices_i = (triangle_id * 3u) + vec3(0u, 1u, 2u) + instance_geometry_ids.index_buffer_offset; + let indices = vec3((*index_buffer)[indices_i.x], (*index_buffer)[indices_i.y], (*index_buffer)[indices_i.z]) + instance_geometry_ids.vertex_buffer_offset; + + return array( + unpack_vertex((*vertex_buffer)[indices.x]), + unpack_vertex((*vertex_buffer)[indices.y]), + unpack_vertex((*vertex_buffer)[indices.z]) + ); +} + +fn transform_positions(transform: mat4x4, vertices: array) -> array, 3> { + return array, 3>( + (transform * vec4(vertices[0].position, 1.0)).xyz, + (transform * vec4(vertices[1].position, 1.0)).xyz, + (transform * vec4(vertices[2].position, 1.0)).xyz + ); +} + +fn resolve_triangle_data_full(instance_id: u32, triangle_id: u32, barycentrics: vec3) -> ResolvedRayHitFull { + let material_id = material_ids[instance_id]; + let material = materials[material_id]; + + let transform = affine3_to_square(transforms[instance_id]); + let previous_frame_transform = affine3_to_square(previous_frame_transforms[instance_id]); + + let instance_geometry_ids = geometry_ids[instance_id]; + let vertices = load_vertices(instance_geometry_ids, triangle_id); + + let world_vertices = transform_positions(transform, vertices); + let world_position = mat3x3(world_vertices[0], world_vertices[1], world_vertices[2]) * barycentrics; + + let previous_frame_world_vertices = transform_positions(previous_frame_transform, vertices); + let previous_frame_world_position = mat3x3(previous_frame_world_vertices[0], previous_frame_world_vertices[1], previous_frame_world_vertices[2]) * barycentrics; + + let uv = mat3x2(vertices[0].uv, vertices[1].uv, vertices[2].uv) * barycentrics; + + let transform_3x3 = mat3x3(transform[0].xyz, transform[1].xyz, transform[2].xyz); + + let cofactor = mat3x3(cross(transform_3x3[1], transform_3x3[2]), cross(transform_3x3[2], transform_3x3[0]), cross(transform_3x3[0], transform_3x3[1])); + let determinant = dot(transform_3x3[0], cofactor[0]); + let determinant_sign = select(sign(determinant), 1.0, determinant == 0.0); + + let local_tangent = mat3x3(vertices[0].tangent.xyz, vertices[1].tangent.xyz, vertices[2].tangent.xyz) * barycentrics; + let world_tangent = vec4(normalize(transform_3x3 * local_tangent), vertices[0].tangent.w * determinant_sign); + + let local_normal = mat3x3(vertices[0].normal, vertices[1].normal, vertices[2].normal) * barycentrics; // TODO: Use barycentric lerp, ray_hit.object_to_world, cross product geo normal + var world_normal = normalize(determinant_sign * (cofactor * local_normal)); + + let geometric_world_normal = world_normal; + if material.normal_map_texture_id != TEXTURE_MAP_NONE { + let TBN = calculate_tbn_mikktspace(world_normal, world_tangent); + let T = TBN[0]; + let B = TBN[1]; + let N = TBN[2]; + var Nt = sample_texture(material.normal_map_texture_id, uv) * 2.0 - 1.0; + Nt.z = sqrt(max(1.0 - dot(Nt.xy, Nt.xy), 0.0)); // Reconstruct Z to support two-channel normal maps + world_normal = normalize(Nt.x * T + Nt.y * B + Nt.z * N); + } + + let triangle_edge0 = world_vertices[0] - world_vertices[1]; + let triangle_edge1 = world_vertices[0] - world_vertices[2]; + let triangle_area = length(cross(triangle_edge0, triangle_edge1)) / 2.0; + + let resolved_material = resolve_material(material, uv); + + return ResolvedRayHitFull( + world_position, + previous_frame_world_position, + world_normal, + geometric_world_normal, + world_tangent, + uv, + triangle_area, + instance_geometry_ids.triangle_count, + resolved_material, + ); +} diff --git a/src/scene/brdf.wesl b/src/scene/brdf.wesl new file mode 100644 index 0000000..e4fe4fa --- /dev/null +++ b/src/scene/brdf.wesl @@ -0,0 +1,176 @@ +import bevy_core_pipeline::tonemapping::tonemapping_luminance as luminance; +import bevy_pbr::render::pbr_lighting::{D_GGX, V_SmithGGXCorrelated, specular_multiscatter}; +import bevy_pbr::render::pbr_functions::calculate_F0_dielectric; +import bevy_pbr::render::utils::{rand_f, sample_cosine_hemisphere}; +import bevy_render::maths::{PI, orthonormalize}; +import package::scene::sampling::{sample_ggx_vndf, ggx_vndf_pdf, ggx_vndf_sample_invalid}; +import package::scene::bindings::{ResolvedMaterial, MIRROR_ROUGHNESS_THRESHOLD, brdf_dfg_lut, brdf_dfg_lut_sampler}; + +enable wgpu_ray_query; + +struct EvaluateAndSampleBrdfResult { + wi: vec3, + throughput: vec3, + pdf: f32, + diffuse_selected: bool, +} + +struct LobeReflectances { + specular: vec3, + diffuse: vec3, +} + +/// Hemispherical reflectance of each lobe +fn lobe_reflectances(F0_metal: vec3, F0_dielectric: vec3, material: ResolvedMaterial, F_ab: vec2) -> LobeReflectances { + let multiscattering_factor = 1.0 / (F_ab.x + F_ab.y) - 1.0; + let rho_specular_metallic = (F0_metal * F_ab.x + F_ab.y) * (1.0 + F0_metal * multiscattering_factor); + let rho_specular_dielectric = (F0_dielectric * F_ab.x + F_ab.y) * (1.0 + F0_dielectric * multiscattering_factor); + return LobeReflectances( + mix(rho_specular_dielectric, rho_specular_metallic, material.metallic), + (1.0 - material.metallic) * (1.0 - rho_specular_dielectric) * material.base_color, + ); +} + +fn specular_lobe_sampling_probability(rho: LobeReflectances, perceptual_roughness: f32) -> f32 { + let specular_luminance = luminance(rho.specular); + let total_luminance = specular_luminance + luminance(rho.diffuse); + let energy_probability = specular_luminance / max(total_luminance, 0.0001); + + // Give smooth dielectric reflections more specular samples to prevent undersampling + let roughness_biased_probability = mix(0.5, energy_probability, perceptual_roughness); + return max(energy_probability, roughness_biased_probability); +} + +fn evaluate_and_sample_brdf( + wo: vec3, + world_normal: vec3, + material: ResolvedMaterial, + F_ab: vec2, + rng: ptr, +) -> EvaluateAndSampleBrdfResult { + let NdotV = dot(world_normal, wo); + if NdotV < 0.0001 { return EvaluateAndSampleBrdfResult(vec3(0.0), vec3(0.0), 0.0, false); } + let F0_metal = material.base_color; + let F0_dielectric = calculate_F0_dielectric(vec3(material.reflectance)); + let rho = lobe_reflectances(F0_metal, F0_dielectric, material, F_ab); + let specular_weight = specular_lobe_sampling_probability(rho, material.perceptual_roughness); + let diffuse_weight = 1.0 - specular_weight; + + let TBN = orthonormalize(world_normal); + let T = TBN[0]; + let B = TBN[1]; + let N = TBN[2]; + + let wo_tangent = vec3(dot(wo, T), dot(wo, B), dot(wo, N)); + + var wi: vec3; + var wi_tangent: vec3; + let diffuse_selected = rand_f(rng) < diffuse_weight; + if diffuse_selected { + wi = sample_cosine_hemisphere(world_normal, rng); + wi_tangent = vec3(dot(wi, T), dot(wi, B), dot(wi, N)); + } else { + wi_tangent = sample_ggx_vndf(wo_tangent, material.roughness, rng); + if ggx_vndf_sample_invalid(wi_tangent) { + return EvaluateAndSampleBrdfResult(vec3(0.0), vec3(0.0), 0.0, false); + } + wi = wi_tangent.x * T + wi_tangent.y * B + wi_tangent.z * N; + + // Mirror specular is a delta function + if material.roughness <= MIRROR_ROUGHNESS_THRESHOLD { + return EvaluateAndSampleBrdfResult( + wi, + evaluate_specular_brdf(wo, wi, world_normal, material, F_ab) / specular_weight, + bitcast(0x7F800000u), // INF + false, + ); + } + } + + let diffuse_pdf = wi_tangent.z / PI; + let specular_pdf = ggx_vndf_pdf(wo_tangent, wi_tangent, material.roughness); + let pdf = (diffuse_weight * diffuse_pdf) + (specular_weight * specular_pdf); + let throughput = evaluate_brdf(wo, wi, world_normal, material, F_ab) / pdf; + return EvaluateAndSampleBrdfResult(wi, throughput, pdf, diffuse_selected); +} + +fn evaluate_brdf( + wo: vec3, + wi: vec3, + world_normal: vec3, + material: ResolvedMaterial, + F_ab: vec2, +) -> vec3 { + return evaluate_diffuse_brdf(wo, wi, world_normal, material, F_ab) + evaluate_specular_brdf(wo, wi, world_normal, material, F_ab); +} + +fn evaluate_diffuse_brdf(wo: vec3, wi: vec3, world_normal: vec3, material: ResolvedMaterial, F_ab: vec2) -> vec3 { + let NdotL = dot(world_normal, wi); + let NdotV = dot(world_normal, wo); + if NdotL < 0.0001 || NdotV < 0.0001 { return vec3(0.0); } + let F0_metal = material.base_color; + let F0_dielectric = calculate_F0_dielectric(vec3(material.reflectance)); + let rho = lobe_reflectances(F0_metal, F0_dielectric, material, F_ab); + return rho.diffuse / PI * NdotL; +} + +fn evaluate_specular_brdf(wo: vec3, wi: vec3, world_normal: vec3, material: ResolvedMaterial, F_ab: vec2) -> vec3 { + let H = normalize(wi + wo); + let NdotL = dot(world_normal, wi); + let NdotH = min(dot(world_normal, H), 1.0); + let LdotH = dot(wi, H); + let NdotV = dot(world_normal, wo); + if NdotL < 0.0001 || NdotH < 0.0001 || LdotH < 0.0001 || NdotV < 0.0001 { return vec3(0.0); } + + let F0_metal = material.base_color; + let F0_dielectric = calculate_F0_dielectric(vec3(material.reflectance)); + + if material.roughness <= MIRROR_ROUGHNESS_THRESHOLD { + let mirror_wi = 2.0 * NdotV * world_normal - wo; + if distance(mirror_wi, wi) < 0.0001 { + let F_metal = fresnel(F0_metal, LdotH); + let F_dielectric = fresnel(F0_dielectric, LdotH); + return mix(F_dielectric, F_metal, material.metallic); + } else { + return vec3(0.0); + } + } + + let D = D_GGX(material.roughness, NdotH); + let Vs = V_SmithGGXCorrelated(material.roughness, NdotV, NdotL); + let F_metal = fresnel(F0_metal, LdotH); + let F_dielectric = fresnel(F0_dielectric, LdotH); + return mix(specular_multiscatter(D, Vs, F_dielectric, F0_dielectric, F_ab, 1.0), + specular_multiscatter(D, Vs, F_metal, F0_metal, F_ab, 1.0), + material.metallic) * NdotL; +} + +fn brdf_pdf(wo: vec3, wi: vec3, world_normal: vec3, material: ResolvedMaterial, F_ab: vec2) -> f32 { + let NdotV = max(dot(world_normal, wo), 0.0001); + let F0_metal = material.base_color; + let F0_dielectric = calculate_F0_dielectric(vec3(material.reflectance)); + let rho = lobe_reflectances(F0_metal, F0_dielectric, material, F_ab); + let specular_weight = specular_lobe_sampling_probability(rho, material.perceptual_roughness); + let diffuse_weight = 1.0 - specular_weight; + + let TBN = orthonormalize(world_normal); + let T = TBN[0]; + let B = TBN[1]; + let N = TBN[2]; + + let wo_tangent = vec3(dot(wo, T), dot(wo, B), dot(wo, N)); + let wi_tangent = vec3(dot(wi, T), dot(wi, B), dot(wi, N)); + + let diffuse_pdf = wi_tangent.z / PI; + let specular_pdf = ggx_vndf_pdf(wo_tangent, wi_tangent, material.roughness); + return (diffuse_weight * diffuse_pdf) + (specular_weight * specular_pdf); +} + +fn fresnel(f0: vec3, LdotH: f32) -> vec3 { + return f0 + (1.0 - f0) * pow(saturate(1.0 - LdotH), 5.0); +} + +/// Scale/bias approximation +fn F_AB(perceptual_roughness: f32, NdotV: f32) -> vec2 { + return textureSampleLevel(brdf_dfg_lut, brdf_dfg_lut_sampler, vec2(NdotV, perceptual_roughness), 0.0).rg; +} diff --git a/src/scene/extract.rs b/src/scene/extract.rs new file mode 100644 index 0000000..aa6e81f --- /dev/null +++ b/src/scene/extract.rs @@ -0,0 +1,270 @@ +use bevy_asset::{AssetEvent, AssetId, Assets, Handle}; +use bevy_camera::Camera; +use bevy_ecs::{ + lifecycle::RemovedComponents, + message::MessageReader, + query::{Added, Changed, Or, With}, + resource::Resource, + system::{Commands, Query, Res, ResMut}, +}; +use bevy_image::Image; +use bevy_light::{EnvironmentMapLight, GeneratedEnvironmentMapLight}; +use bevy_math::Quat; +use bevy_pbr::{MeshMaterial3d, PreviousGlobalTransform, StandardMaterial}; +use bevy_platform::collections::HashMap; +use bevy_render::{Extract, sync_world::RenderEntity}; +use bevy_transform::components::GlobalTransform; +use bevy_utils::once; +use tracing::warn; + +use super::{RaytracingMesh3d, RaytracingSceneBindings}; +use crate::scene::Tape3d; + +/// Creates or removes components in the render world related to raytracing +/// mesh instances. +pub fn extract_raytracing_scene_meshes_structural( + new_instances: Extract< + Query< + ( + RenderEntity, + &RaytracingMesh3d, + &MeshMaterial3d, + &GlobalTransform, + Option<&PreviousGlobalTransform>, + ), + Added, + >, + >, + mut removed_raytracing_meshes: Extract>, + render_entities: Extract>, + mut commands: Commands, +) { + // Process removed components before additions, that way it properly handles + // same-frame removal->insertion + for main_entity in removed_raytracing_meshes.read() { + if let Ok(render_entity) = render_entities.get(main_entity) { + commands.entity(render_entity).remove::(); + } + } + + for (render_entity, mesh, material, transform, previous_frame_transform) in &new_instances { + commands.entity(render_entity).insert(( + mesh.clone(), + material.clone(), + *transform, + previous_frame_transform + .cloned() + .unwrap_or(PreviousGlobalTransform(transform.affine())), + )); + } +} + +/// Creates or removes components in the render world related to raytracing +/// tape instances. +pub fn extract_raytracing_scene_tapes_structural( + new_instances: Extract< + Query< + ( + RenderEntity, + &Tape3d, + &MeshMaterial3d, + &GlobalTransform, + Option<&PreviousGlobalTransform>, + ), + Added, + >, + >, + mut removed_raytracing_tapes: Extract>, + render_entities: Extract>, + mut commands: Commands, +) { + // Process removed components before additions, that way it properly handles + // same-frame removal->insertion + for main_entity in removed_raytracing_tapes.read() { + if let Ok(render_entity) = render_entities.get(main_entity) { + commands.entity(render_entity).remove::(); + } + } + + for (render_entity, tape, material, transform, previous_frame_transform) in &new_instances { + commands.entity(render_entity).insert(( + tape.clone(), + material.clone(), + *transform, + previous_frame_transform + .cloned() + .unwrap_or(PreviousGlobalTransform(transform.affine())), + )); + } +} + +/// Copies the transforms of moved raytracing instances from the main world +/// straight into their GPU buffers. +pub fn extract_raytracing_scene_transforms( + main_instances: Extract< + Query< + ( + RenderEntity, + &GlobalTransform, + Option<&PreviousGlobalTransform>, + ), + ( + Or<(Changed, Changed)>, + Or<(With, With)>, + ), + >, + >, + bindings: Res, +) { + main_instances + .par_iter() + .for_each(|(render_entity, transform, previous_frame_transform)| { + let previous_frame_transform = previous_frame_transform + .cloned() + .unwrap_or(PreviousGlobalTransform(transform.affine())); + + bindings.move_instance(render_entity, transform, &previous_frame_transform); + }); +} + +/// Updates the mesh and material of existing raytracing instances in the render +/// world. +pub fn extract_raytracing_scene_meshes_and_materials( + main_instances: Extract< + Query< + ( + RenderEntity, + &RaytracingMesh3d, + &MeshMaterial3d, + ), + Or<( + Changed, + Changed>, + )>, + >, + >, + mut render_instances: Query<(&mut RaytracingMesh3d, &mut MeshMaterial3d)>, +) { + for (render_entity, new_mesh, new_material) in &main_instances { + if let Ok((mut mesh, mut material)) = render_instances.get_mut(render_entity) { + *mesh = new_mesh.clone(); + *material = new_material.clone(); + } + } +} + +/// Updates the tape and material of existing raytracing instances in the render +/// world. +pub fn extract_raytracing_scene_tapes_and_materials( + main_instances: Extract< + Query< + (RenderEntity, &Tape3d, &MeshMaterial3d), + Or<(Changed, Changed>)>, + >, + >, + mut render_instances: Query<(&mut Tape3d, &mut MeshMaterial3d)>, +) { + for (render_entity, new_tape, new_material) in &main_instances { + if let Ok((mut tape, mut material)) = render_instances.get_mut(render_entity) { + *tape = new_tape.clone(); + *material = new_material.clone(); + } + } +} + +/// The set of [`StandardMaterial`] in the scene, mirrored into the render +/// world. +#[derive(Resource, Default)] +pub struct StandardMaterialAssets { + materials: HashMap, StandardMaterial>, + /// Materials added or modified this frame. + pub changed: Vec>, + /// Materials removed this frame. + pub removed: Vec>, +} + +impl StandardMaterialAssets { + pub fn get(&self, id: &AssetId) -> Option<&StandardMaterial> { + self.materials.get(id) + } +} + +/// Keeps [`StandardMaterialAssets`] up to date in the render world. +pub fn extract_raytracing_material_assets( + main_materials: Extract>>, + mut render_materials: ResMut, + mut events: Extract>>, +) { + let render_materials = &mut *render_materials; + + render_materials.changed.clear(); + render_materials.removed.clear(); + + for event in events.read() { + match event { + AssetEvent::Added { id } | AssetEvent::Modified { id } => { + if let Some(material) = main_materials.get(*id) { + render_materials.materials.insert(*id, material.clone()); + render_materials.changed.push(*id); + } + }, + AssetEvent::Removed { id } => { + render_materials.materials.remove(id); + render_materials.removed.push(*id); + }, + AssetEvent::Unused { .. } | AssetEvent::LoadedWithDependencies { .. } => {}, + } + } +} + +#[derive(Resource, Default, Clone, PartialEq)] +pub struct ExtractedEnvironmentMapLight { + pub cubemap: Option>, + pub intensity: f32, + pub rotation: Quat, +} + +/// Finds the environment map light to use for the raytraced scene, if any. +pub fn extract_raytracing_environment_map_light( + cameras: Extract< + Query<( + &Camera, + Option<&GeneratedEnvironmentMapLight>, + Option<&EnvironmentMapLight>, + )>, + >, + mut environment_map_light: ResMut, +) { + let mut extracted_env_map_light = ExtractedEnvironmentMapLight::default(); + + for (camera, generated, pregenerated) in &cameras { + if !camera.is_active { + continue; + } + + let env_map_light = match (generated, pregenerated) { + (Some(generated), _) => ExtractedEnvironmentMapLight { + cubemap: Some(generated.environment_map.clone()), + intensity: generated.intensity, + rotation: generated.rotation, + }, + (None, Some(pregenerated)) => ExtractedEnvironmentMapLight { + cubemap: Some(pregenerated.specular_map.clone()), + intensity: pregenerated.intensity, + rotation: pregenerated.rotation, + }, + (None, None) => continue, + }; + + if extracted_env_map_light.cubemap.is_none() { + extracted_env_map_light = env_map_light; + } else if extracted_env_map_light != env_map_light { + once!(warn!( + "bevy_solari only supports a single environment light for the whole scene, but \ + multiple cameras have differing environment lights. Using the first one found." + )); + } + } + + *environment_map_light = extracted_env_map_light; +} diff --git a/src/scene/meshes/blas.rs b/src/scene/meshes/blas.rs new file mode 100644 index 0000000..0bf5fcc --- /dev/null +++ b/src/scene/meshes/blas.rs @@ -0,0 +1,262 @@ +use alloc::collections::VecDeque; +use bevy_asset::AssetId; +use bevy_ecs::{ + resource::Resource, + system::{Res, ResMut}, +}; +use bevy_mesh::{Indices, Mesh}; +use bevy_platform::collections::HashMap; +use bevy_render::{ + diagnostic::{DiagnosticsRecorder, RecordDiagnostics}, + mesh::{ + allocator::{MeshAllocator, MeshBufferSlice}, + RenderMesh, + }, + render_asset::ExtractedAssets, + render_resource::*, + renderer::{RenderDevice, RenderQueue}, +}; + +/// After compacting this many vertices worth of meshes per frame, no further BLAS will be compacted. +/// Lower this number to distribute the work across more frames. +const MAX_COMPACTION_VERTICES_PER_FRAME: u32 = 400_000; + +/// Under the `wgpu_hal` build path, we need to manage BLAS lifetimes ourselves. +/// Since solari keeps both current and previous frame TLAS's around, only after +/// two TLAS builds since we marked it for deletion is it safe to delete a BLAS. +const TLAS_BUILDS_BEFORE_DELETION_ALLOWED: usize = 2; + +#[derive(Resource, Default)] +pub struct BlasManager { + blas: HashMap, Blas>, + compaction_queue: VecDeque<(AssetId, u32, bool)>, + changed: Vec>, + /// BLAS that are pending deletion, one batch per TLAS build. The back batch collects + /// retirements since the last build, and every batch ahead of it has one more build to wait + /// out. + pending_deletions: VecDeque>, +} + +impl BlasManager { + pub fn get(&self, mesh: &AssetId) -> Option<&Blas> { + self.blas.get(mesh) + } + + pub fn device_address(&self, mesh: &AssetId) -> Option { + self.blas.get(mesh)?.handle() + } + + pub fn changed_meshes(&self) -> &[AssetId] { + &self.changed + } + + pub fn note_tlas_build(&mut self) { + if !self.pending_deletions.is_empty() { + self.pending_deletions.push_back(Vec::new()); + } + } + + fn insert(&mut self, mesh: AssetId, blas: Blas) { + if let Some(old) = self.blas.insert(mesh, blas) { + self.retire(old); + } + + self.changed.push(mesh); + } + + fn remove(&mut self, mesh: AssetId) { + self.changed.push(mesh); + + if let Some(removed) = self.blas.remove(&mesh) { + self.retire(removed); + } + } + + fn retire(&mut self, blas: Blas) { + match self.pending_deletions.back_mut() { + Some(batch) => batch.push(blas), + None => self.pending_deletions.push_back(vec![blas]), + } + } +} + +pub fn prepare_raytracing_blas( + mut blas_manager: ResMut, + extracted_meshes: Res>, + mesh_allocator: Res, + render_device: Res, + render_queue: Res, + mut diagnostics: Option>, +) { + blas_manager.changed.clear(); + + // Delete BLAS for deleted or modified meshes + for asset_id in extracted_meshes + .removed + .iter() + .chain(extracted_meshes.modified.iter()) + { + blas_manager.remove(*asset_id); + } + + if extracted_meshes.extracted.is_empty() { + return; + } + + // Create new BLAS for added or changed meshes + let blas_resources = extracted_meshes + .extracted + .iter() + .filter(|(_, mesh)| is_mesh_raytracing_compatible(mesh)) + .map(|(asset_id, _)| { + let vertex_slice = mesh_allocator.mesh_vertex_slice(asset_id).unwrap(); + let index_slice = mesh_allocator.mesh_index_slice(asset_id).unwrap(); + + let (blas, blas_size) = + allocate_blas(&vertex_slice, &index_slice, asset_id, &render_device); + + blas_manager.insert(*asset_id, blas); + blas_manager + .compaction_queue + .push_back((*asset_id, blas_size.vertex_count, false)); + + (*asset_id, vertex_slice, index_slice, blas_size) + }) + .collect::>(); + + // Build geometry into each BLAS + let build_entries = blas_resources + .iter() + .map(|(asset_id, vertex_slice, index_slice, blas_size)| { + let geometry = BlasTriangleGeometry { + size: blas_size, + vertex_buffer: vertex_slice.buffer, + first_vertex: vertex_slice.range.start, + vertex_stride: 48, + index_buffer: Some(index_slice.buffer), + first_index: Some(index_slice.range.start), + transform_buffer: None, + transform_buffer_offset: None, + }; + BlasBuildEntry { + blas: &blas_manager.blas[asset_id], + geometry: BlasGeometries::TriangleGeometries(vec![geometry]), + } + }) + .collect::>(); + + let mut command_encoder = render_device.create_command_encoder(&CommandEncoderDescriptor { + label: Some("blas_build_command_encoder"), + }); + let time_span = diagnostics + .as_mut() + .map(|diagnostics| diagnostics.time_span(&mut command_encoder, "blas_build")); + command_encoder.build_acceleration_structures(&build_entries, &[]); + if let Some(time_span) = time_span { + time_span.end(&mut command_encoder); + } + render_queue.submit([command_encoder.finish()]); +} + +pub fn compact_raytracing_blas( + mut blas_manager: ResMut, + render_queue: Res, +) { + let queue_size = blas_manager.compaction_queue.len(); + let mut meshes_processed = 0; + let mut vertices_compacted = 0; + + while !blas_manager.compaction_queue.is_empty() + && vertices_compacted < MAX_COMPACTION_VERTICES_PER_FRAME + && meshes_processed < queue_size + { + meshes_processed += 1; + + let (mesh, vertex_count, compaction_started) = + blas_manager.compaction_queue.pop_front().unwrap(); + + let Some(blas) = blas_manager.get(&mesh) else { + continue; + }; + + if !compaction_started { + blas.prepare_compaction_async(|_| {}); + } + + if blas.ready_for_compaction() { + let compacted_blas = render_queue.compact_blas(blas); + blas_manager.insert(mesh, compacted_blas); + + vertices_compacted += vertex_count; + continue; + } + + // BLAS not ready for compaction, put back in queue + blas_manager + .compaction_queue + .push_back((mesh, vertex_count, true)); + } +} + +pub fn delete_raytracing_blas( + mut blas_manager: ResMut, + render_queue: Res, +) { + if blas_manager.pending_deletions.len() <= TLAS_BUILDS_BEFORE_DELETION_ALLOWED { + return; + } + + if let Some(deletable) = blas_manager + .pending_deletions + .pop_front() + .filter(|b| !b.is_empty()) + { + render_queue.on_submitted_work_done(move || drop(deletable)); + } +} + +fn allocate_blas( + vertex_slice: &MeshBufferSlice, + index_slice: &MeshBufferSlice, + asset_id: &AssetId, + render_device: &RenderDevice, +) -> (Blas, BlasTriangleGeometrySizeDescriptor) { + let blas_size = BlasTriangleGeometrySizeDescriptor { + vertex_format: Mesh::ATTRIBUTE_POSITION.format, + vertex_count: vertex_slice.range.len() as u32, + index_format: Some(IndexFormat::Uint32), + index_count: Some(index_slice.range.len() as u32), + flags: AccelerationStructureGeometryFlags::OPAQUE, + }; + + // TODO: If we ever introduce BLAS refits, we need to be aware of the TLAS double-buffer + // to avoid invalidating the previous frame TLAS + let blas = render_device.wgpu_device().create_blas( + &CreateBlasDescriptor { + label: Some(&asset_id.to_string()), + flags: AccelerationStructureFlags::PREFER_FAST_TRACE + | AccelerationStructureFlags::ALLOW_COMPACTION, + update_mode: AccelerationStructureUpdateMode::Build, + }, + BlasGeometrySizeDescriptors::Triangles { + descriptors: vec![blas_size.clone()], + }, + ); + + (blas, blas_size) +} + +fn is_mesh_raytracing_compatible(mesh: &Mesh) -> bool { + let triangle_list = mesh.primitive_topology() == PrimitiveTopology::TriangleList; + let vertex_attributes = mesh + .attributes() + .map(|(attribute, _)| (attribute.id, attribute.format)) + .eq([ + (Mesh::ATTRIBUTE_POSITION.id, Mesh::ATTRIBUTE_POSITION.format), + (Mesh::ATTRIBUTE_NORMAL.id, Mesh::ATTRIBUTE_NORMAL.format), + (Mesh::ATTRIBUTE_UV_0.id, Mesh::ATTRIBUTE_UV_0.format), + (Mesh::ATTRIBUTE_TANGENT.id, Mesh::ATTRIBUTE_TANGENT.format), + ]); + let indexed_32 = matches!(mesh.indices(), Some(Indices::U32(..))); + mesh.enable_raytracing && triangle_list && vertex_attributes && indexed_32 +} diff --git a/src/scene/meshes/mod.rs b/src/scene/meshes/mod.rs new file mode 100644 index 0000000..f78e126 --- /dev/null +++ b/src/scene/meshes/mod.rs @@ -0,0 +1,2 @@ +pub mod blas; +pub mod types; diff --git a/src/scene/meshes/types.rs b/src/scene/meshes/types.rs new file mode 100644 index 0000000..e11da91 --- /dev/null +++ b/src/scene/meshes/types.rs @@ -0,0 +1,25 @@ +use bevy_asset::Handle; +use bevy_derive::{Deref, DerefMut}; +use bevy_ecs::{component::Component, prelude::ReflectComponent, template::FromTemplate}; +use bevy_mesh::Mesh; +use bevy_pbr::{MeshMaterial3d, StandardMaterial}; +use bevy_reflect::{Reflect, prelude::ReflectDefault}; +use bevy_render::sync_world::SyncToRenderWorld; +use bevy_transform::components::Transform; +use derive_more::derive::From; + +/// A mesh component used for raytracing. +/// +/// The mesh used in this component must have [`Mesh::enable_raytracing`] set to +/// true, use the following set of vertex attributes: `{POSITION, NORMAL, UV_0, +/// TANGENT}`, use [`bevy_mesh::PrimitiveTopology::TriangleList`], +/// and use [`bevy_mesh::Indices::U32`]. +/// +/// The material used for this entity must be +/// [`MeshMaterial3d`]. +#[derive( + Component, FromTemplate, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From, +)] +#[reflect(Component, Default, Clone, PartialEq)] +#[require(MeshMaterial3d, Transform, SyncToRenderWorld)] +pub struct RaytracingMesh3d(pub Handle); diff --git a/src/scene/mod.rs b/src/scene/mod.rs new file mode 100644 index 0000000..0aa50c4 --- /dev/null +++ b/src/scene/mod.rs @@ -0,0 +1,128 @@ +mod binder; +mod extract; +mod meshes; + +mod tapes; + +use bevy_app::{App, Plugin}; +use bevy_asset::embedded_asset; +use bevy_ecs::schedule::IntoScheduleConfigs; +use bevy_render::{ + ExtractSchedule, GpuResourceAppExt, Render, RenderApp, RenderSystems, + mesh::{ + RenderMesh, + allocator::{MeshAllocatorSettings, allocate_and_free_meshes}, + }, + render_asset::prepare_assets, + render_resource::{BufferUsages, update_sparse_buffers}, + renderer::{RenderDevice, RenderGraph, RenderGraphSystems}, +}; +use bevy_shader::load_shader_library; +pub use binder::{ + RaytracingSceneBindings, RaytracingSceneNeedsPreviousFrameData, + prepare_raytracing_scene_resources, +}; +use binder::{ + TlasInstanceSetupPipeline, build_raytracing_tlas, prepare_raytracing_scene_bind_group, +}; +use extract::{ + ExtractedEnvironmentMapLight, StandardMaterialAssets, extract_raytracing_environment_map_light, + extract_raytracing_material_assets, extract_raytracing_scene_meshes_and_materials, + extract_raytracing_scene_transforms, +}; +pub use meshes::types::RaytracingMesh3d; +pub use tapes::{ + allocator::{TapeAllocatorPlugin, TapeRenderAssetPlugin}, + plugin::TapePlugin, + types::Tape3d, +}; +use tracing::warn; + +use crate::{ + SolariPlugins, + scene::{ + extract::{ + extract_raytracing_scene_meshes_structural, + extract_raytracing_scene_tapes_and_materials, + extract_raytracing_scene_tapes_structural, + }, + tapes::allocator::allocate_and_free_tapes, + }, +}; + +/// Creates acceleration structures and binding arrays of resources for +/// raytracing. +pub struct RaytracingScenePlugin; + +impl Plugin for RaytracingScenePlugin { + fn build(&self, app: &mut App) { + load_shader_library!(app, "brdf.wesl"); + load_shader_library!(app, "bindings.wesl"); + load_shader_library!(app, "sampling.wesl"); + embedded_asset!(app, "binder/setup_tlas_instances.wesl"); + } + + fn finish(&self, app: &mut App) { + let render_app = app.sub_app_mut(RenderApp); + + let render_device = render_app.world().resource::(); + let features = render_device.features(); + if !features.contains(SolariPlugins::required_wgpu_features()) { + warn!( + "RaytracingScenePlugin not loaded. GPU lacks support for required features: {:?}.", + SolariPlugins::required_wgpu_features().difference(features) + ); + return; + } + + render_app + .world_mut() + .resource_mut::() + .extra_buffer_usages |= BufferUsages::BLAS_INPUT | BufferUsages::STORAGE; + + render_app + .init_resource::() + .init_gpu_resource::() + .init_gpu_resource::() + .init_gpu_resource::() + .init_gpu_resource::() + .init_gpu_resource::() + .add_systems( + ExtractSchedule, + ( + extract_raytracing_scene_meshes_structural, + extract_raytracing_scene_tapes_structural, + extract_raytracing_scene_transforms, + extract_raytracing_scene_meshes_and_materials, + extract_raytracing_scene_tapes_and_materials, + extract_raytracing_material_assets, + extract_raytracing_environment_map_light, + ), + ) + .add_systems( + Render, + ( + meshes::blas::prepare_raytracing_blas + .in_set(RenderSystems::PrepareAssets) + .before(prepare_assets::) + .after(allocate_and_free_meshes) + .after(allocate_and_free_tapes), + meshes::blas::compact_raytracing_blas + .in_set(RenderSystems::PrepareAssets) + .after(meshes::blas::prepare_raytracing_blas), + prepare_raytracing_scene_resources.in_set(RenderSystems::PrepareResources), + prepare_raytracing_scene_bind_group.in_set(RenderSystems::PrepareBindGroups), + ), + ) + .add_systems( + RenderGraph, + ( + build_raytracing_tlas + .after(update_sparse_buffers) + .in_set(RenderGraphSystems::Begin), + meshes::blas::delete_raytracing_blas.in_set(RenderGraphSystems::Finish), + tapes::blas::delete_raytracing_blas.in_set(RenderGraphSystems::Finish), + ), + ); + } +} diff --git a/src/scene/sampling.wesl b/src/scene/sampling.wesl new file mode 100644 index 0000000..df78d55 --- /dev/null +++ b/src/scene/sampling.wesl @@ -0,0 +1,267 @@ +import bevy_pbr::render::pbr_lighting::D_GGX; +import bevy_pbr::render::utils::{rand_vec2f, rand_u, rand_range_u}; +import bevy_render::maths::{PI_2, orthonormalize}; +import package::scene::bindings::{trace_ray, trace_ray_previous_frame, RAY_T_MIN, RAY_T_MAX, light_sources, directional_lights, environment_map, environment_map_sampler, environment_map_light, LightSource, LIGHT_SOURCE_KIND_DIRECTIONAL, resolve_triangle_data_full, ResolvedRayHitFull, MIRROR_ROUGHNESS_THRESHOLD}; + +enable wgpu_ray_query; + +fn power_heuristic(f: f32, g: f32) -> f32 { + return balance_heuristic(f * f, g * g); +} + +fn balance_heuristic(f: f32, g: f32) -> f32 { + // Need to guard against NaNs since ReSTIR reservoirs can have UCW=0 + if f == 0.0 { + return 0.0; + } + // When NaN, fall back to even weights of 0.5 : 0.5 + let weight = 1.0 / (1.0 + (g / f)); + return select(weight, 0.5, isnan(weight)); +} + +/// https://gpuopen.com/download/Bounded_VNDF_Sampling_for_Smith-GGX_Reflections.pdf (Listing 1) +/// Result is invalid when output.z <= 0.0, and must be discarded +fn sample_ggx_vndf(wi_tangent: vec3, roughness: f32, rng: ptr) -> vec3 { + // Mirror BRDF case + if roughness <= MIRROR_ROUGHNESS_THRESHOLD { + return vec3(-wi_tangent.xy, wi_tangent.z); + } + + let i = wi_tangent; + let rand = rand_vec2f(rng); + let i_std = normalize(vec3(i.xy * roughness, i.z)); + let phi = PI_2 * rand.x; + let a = roughness; + let s = 1.0 + length(vec2(i.xy)); + let a2 = a * a; + let s2 = s * s; + let k = (1.0 - a2) * s2 / (s2 + a2 * i.z * i.z); + let b = select(i_std.z, k * i_std.z, i.z > 0.0); + let z = fma(1.0 - rand.y, 1.0 + b, -b); + let sin_theta = sqrt(saturate(1.0 - z * z)); + let o_std = vec3(sin_theta * cos(phi), sin_theta * sin(phi), z); + let m_std = i_std + o_std; + let m = normalize(vec3(m_std.xy * roughness, m_std.z)); + return 2.0 * dot(i, m) * m - i; +} + +fn ggx_vndf_sample_invalid(ray_tangent: vec3) -> bool { + return !(ray_tangent.z > 0.0); +} + +/// https://gpuopen.com/download/Bounded_VNDF_Sampling_for_Smith-GGX_Reflections.pdf (Listing 2) +fn ggx_vndf_pdf(wi_tangent: vec3, wo_tangent: vec3, roughness: f32) -> f32 { + // Mirror BRDF case + if roughness <= MIRROR_ROUGHNESS_THRESHOLD { + let mirror_wo = vec3(-wi_tangent.xy, wi_tangent.z); + if distance(mirror_wo, wo_tangent) < 0.0001 { + return bitcast(0x7F800000u); // INF + } else { + return 0.0; + } + } + + let i = wi_tangent; + let o = wo_tangent; + let m = normalize(i + o); + let ndf = D_GGX(roughness, saturate(m.z)); + let ai = roughness * i.xy; + let len2 = dot(ai, ai); + let t = sqrt(len2 + i.z * i.z); + var pdf: f32; + if i.z >= 0.0 { + let a = roughness; + let s = 1.0 + length(i.xy); + let a2 = a * a; + let s2 = s * s; + let k = (1.0 - a2) * s2 / (s2 + a2 * i.z * i.z); + pdf = ndf / (2.0 * (k * i.z + t)); + } else { + pdf = ndf * (t - i.z) / (2.0 * len2); + } + + return select(pdf, 0.0, isnan(pdf)); +} + +fn isinf(x: f32) -> bool { + return (bitcast(x) & 0x7fffffffu) == 0x7f800000u; +} + +fn isnan(x: f32) -> bool { + return (bitcast(x) & 0x7fffffffu) > 0x7f800000u; +} + +const NULL_LIGHT_ID = 0xFFFFFFFFu; + +struct LightSample { + light_id: u32, + seed: u32, +} + +struct ResolvedLightSample { + world_position: vec4, + world_normal: vec3, + radiance: vec3, + inverse_pdf: f32, +} + +struct LightContribution { + radiance: vec3, + inverse_pdf: f32, + /// inverse_pdf may not be in solid angle measure (e.g. area measure) + /// but inverse_solid_angle_pdf is always in solid angle measure + /// for cases where it's required, e.g. MIS between light sampling techniques + inverse_solid_angle_pdf: f32, + wi: vec3, + brdf_rays_can_hit: bool, +} + +struct GenerateRandomLightSampleResult { + light_sample: LightSample, + resolved_light_sample: ResolvedLightSample, +} + +fn sample_random_light(ray_origin: vec3, origin_world_normal: vec3, rng: ptr) -> LightContribution { + let sample = generate_random_light_sample(rng); + var light_contribution = calculate_resolved_light_contribution(sample.resolved_light_sample, ray_origin, origin_world_normal); + light_contribution.radiance *= trace_visibility(ray_origin, sample.resolved_light_sample.world_position); + return light_contribution; +} + +fn random_emissive_light_pdf(hit: ResolvedRayHitFull, ray_distance: f32, NdotV: f32) -> f32 { + let light_count = arrayLength(&light_sources); + let area_pdf = 1.0 / (f32(light_count) * f32(hit.triangle_count) * hit.triangle_area); + return area_pdf * (ray_distance * ray_distance) / NdotV; +} + +fn sample_environment_map_light(world_direction: vec3) -> vec3 { + if environment_map_light.intensity == 0.0 { return vec3(0.0); } + + var sample_direction = environment_map_light.light_from_world * world_direction; + sample_direction.z = -sample_direction.z; + + // Hardcoded to sample mip 0 (unfiltered radiance) + return textureSampleLevel(environment_map, environment_map_sampler, sample_direction, 0.0).rgb * environment_map_light.intensity; +} + +fn generate_random_light_sample(rng: ptr) -> GenerateRandomLightSampleResult { + let light_count = arrayLength(&light_sources); + let light_id = rand_range_u(light_count, rng); + + let light_source = light_sources[light_id]; + + var triangle_id = 0u; + if light_source.kind != LIGHT_SOURCE_KIND_DIRECTIONAL { + let triangle_count = light_source.kind >> 1u; + triangle_id = rand_range_u(triangle_count, rng); + } + + let seed = rand_u(rng); + let light_sample = LightSample((light_id << 16u) | triangle_id, seed); + + var resolved_light_sample = resolve_light_sample(light_sample, light_source); + resolved_light_sample.inverse_pdf *= f32(light_count); + + return GenerateRandomLightSampleResult(light_sample, resolved_light_sample); +} + +fn resolve_light_sample(light_sample: LightSample, light_source: LightSource) -> ResolvedLightSample { + if light_source.kind == LIGHT_SOURCE_KIND_DIRECTIONAL { + let directional_light = directional_lights[light_source.id]; + + var direction_to_light: vec3; +@if(!NO_DIRECTIONAL_LIGHT_SOFT_SHADOWS) { + // Sample a random direction within a cone whose base is the sun approximated as a disk + // https://www.realtimerendering.com/raytracinggems/unofficial_RayTracingGems_v1.9.pdf#0004286901.INDD%3ASec30%3A305 + var rng = light_sample.seed; + let random = rand_vec2f(&rng); + let cos_theta = (1.0 - random.x) + random.x * directional_light.cos_theta_max; + let sin_theta = sqrt(1.0 - cos_theta * cos_theta); + let phi = random.y * PI_2; + let x = cos(phi) * sin_theta; + let y = sin(phi) * sin_theta; + direction_to_light = vec3(x, y, cos_theta); + + // Rotate the ray so that the cone it was sampled from is aligned with the light direction + direction_to_light = orthonormalize(directional_light.direction_to_light) * direction_to_light; +} @else { + direction_to_light = directional_light.direction_to_light; +} + + return ResolvedLightSample( + vec4(direction_to_light, 0.0), + -direction_to_light, + directional_light.luminance, + directional_light.inverse_pdf, + ); +} else { + let triangle_count = light_source.kind >> 1u; + let triangle_id = light_sample.light_id & 0xFFFFu; + let barycentrics = triangle_barycentrics(light_sample.seed); + let triangle_data = resolve_triangle_data_full(light_source.id, triangle_id, barycentrics); + + return ResolvedLightSample( + vec4(triangle_data.world_position, 1.0), + triangle_data.world_normal, + triangle_data.material.emissive.rgb, + f32(triangle_count) * triangle_data.triangle_area, + ); + } +} + +fn calculate_resolved_light_contribution(resolved_light_sample: ResolvedLightSample, ray_origin: vec3, origin_world_normal: vec3) -> LightContribution { + let ray = resolved_light_sample.world_position.xyz - (resolved_light_sample.world_position.w * ray_origin); + let light_distance = length(ray); + let wi = ray / light_distance; + + let cos_theta_light = saturate(dot(-wi, resolved_light_sample.world_normal)); + let light_distance_squared = light_distance * light_distance; + let denominator = cos_theta_light / light_distance_squared; + + let radiance = resolved_light_sample.radiance * denominator; + let inverse_solid_angle_pdf = resolved_light_sample.inverse_pdf * denominator; + + return LightContribution(radiance, resolved_light_sample.inverse_pdf, inverse_solid_angle_pdf, wi, resolved_light_sample.world_position.w == 1.0); +} + +fn trace_visibility(ray_origin: vec3, point: vec4) -> f32 { + var ray_direction = point.xyz; + var ray_t_max = RAY_T_MAX; + + if point.w == 1.0 { + let ray = ray_direction - ray_origin; + let dist = length(ray); + ray_direction = ray / dist; + ray_t_max = dist - RAY_T_MIN; + } + + if ray_t_max < RAY_T_MIN { return 0.0; } + + let ray_hit = trace_ray(ray_origin, ray_direction, RAY_T_MIN, ray_t_max, RAY_FLAG_TERMINATE_ON_FIRST_HIT); + return f32(ray_hit.kind == RAY_QUERY_INTERSECTION_NONE); +} + +fn trace_visibility_previous_frame(ray_origin: vec3, point: vec4) -> f32 { + var ray_direction = point.xyz; + var ray_t_max = RAY_T_MAX; + + if point.w == 1.0 { + let ray = ray_direction - ray_origin; + let dist = length(ray); + ray_direction = ray / dist; + ray_t_max = dist - RAY_T_MIN; + } + + if ray_t_max < RAY_T_MIN { return 0.0; } + + let ray_hit = trace_ray_previous_frame(ray_origin, ray_direction, RAY_T_MIN, ray_t_max, RAY_FLAG_TERMINATE_ON_FIRST_HIT); + return f32(ray_hit.kind == RAY_QUERY_INTERSECTION_NONE); +} + +/// https://www.realtimerendering.com/raytracinggems/unofficial_RayTracingGems_v1.9.pdf#0004286901.INDD%3ASec22%3A297 +fn triangle_barycentrics(seed: u32) -> vec3 { + var rng = seed; + var barycentrics = rand_vec2f(&rng); + if barycentrics.x + barycentrics.y > 1.0 { barycentrics = 1.0 - barycentrics; } + return vec3(1.0 - barycentrics.x - barycentrics.y, barycentrics); +} diff --git a/src/scene/tapes/allocator.rs b/src/scene/tapes/allocator.rs new file mode 100644 index 0000000..f434e65 --- /dev/null +++ b/src/scene/tapes/allocator.rs @@ -0,0 +1,486 @@ +//! Manages tape aabb buffers. + +use alloc::borrow::Cow; + +use bevy_app::{App, Plugin}; +use bevy_asset::AssetId; +use bevy_derive::{Deref, DerefMut}; +use bevy_ecs::{ + resource::Resource, + schedule::IntoScheduleConfigs as _, + system::{Res, ResMut}, + world::{FromWorld, World}, +}; +use bevy_log::warn; +use bevy_render::{ + GpuResourceAppExt, Render, RenderApp, RenderSystems, + render_asset::{ExtractedAssets, RenderAssetPlugin, prepare_assets}, + renderer::{RenderDevice, RenderQueue}, + slab_allocator::{ + Slab, SlabAllocationBufferSlice, SlabAllocator, SlabAllocatorSettings, SlabId, SlabItem, + SlabItemLayout, + }, +}; +use bevy_shape::BoundingVolume; +use wgpu::{BufferUsages, COPY_BUFFER_ALIGNMENT}; + +use crate::scene::tapes::types::{Aabb, RenderTape, Tape, TapeMetadata}; + +/// A plugin that manages GPU memory for tape data. +pub struct TapeAllocatorPlugin; + +pub type TapeRenderAssetPlugin = RenderAssetPlugin; + +/// Manages the assignment of tape data to GPU buffers. +/// +/// The Bevy renderer tries to pack vertex and index data for multiple tapes +/// together so that multiple tapes can be drawn back-to-back without any +/// rebinding. This resource manages these buffers. +/// +/// The [`TapeAllocatorSettings`] allows you to tune the behavior of the +/// allocator for better performance with your use case. Most applications won't +/// need to change the settings from their default values. +#[derive(Resource, Deref, DerefMut)] +pub struct TapeAllocator { + /// Holds all buffers and offset allocators. + #[deref] + slab_allocator: SlabAllocator, +} + +/// Tunable parameters that customize the behavior of the allocator. +/// +/// Generally, these parameters adjust the tradeoff between memory fragmentation +/// and speed. You can adjust them as desired for your application. Most +/// applications can stick with the default values. +#[derive(Resource, Deref, DerefMut)] +pub struct TapeAllocatorSettings { + #[deref] + pub slab_allocator_settings: SlabAllocatorSettings, + + /// Additional buffer usages to add to any vertex or index buffers created. + pub extra_buffer_usages: BufferUsages, +} + +impl Default for TapeAllocatorSettings { + fn default() -> TapeAllocatorSettings { + TapeAllocatorSettings { + slab_allocator_settings: SlabAllocatorSettings::default(), + extra_buffer_usages: BufferUsages::empty(), + } + } +} + +/// The ID of a single slab. +pub type TapeSlabId = SlabId; + +/// The slab buffer and location within that slab in which each tape is +/// allocated. +pub type TapeBufferSlice<'a> = SlabAllocationBufferSlice<'a, TapeSlabItem>; + +/// The [`SlabItem`] implementation that describes the information needed to +/// allocate and free tapes. +pub struct TapeSlabItem; + +impl SlabItem for TapeSlabItem { + type Key = TapeAllocationKey; + type Layout = ElementLayout; + + fn label() -> Cow<'static, str> { + "tape".into() + } +} + +/// IDs of the slabs associated with a single tape. +#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +pub struct TapeSlabs { + /// The slab storing the tape's aabb data. + pub aabb_slab_id: TapeSlabId, + /// The slab storing the tape's metadata. + pub metadata_slab_id: Option, +} + +/// Returns the type of buffer that this is: vertex, index, metadata. +fn element_class(slab: &Slab) -> ElementClass { + slab.element_layout().class +} + +/// The handle used to retrieve a single tape allocation. +#[derive(Clone, Copy, PartialEq, Eq, Hash)] +pub struct TapeAllocationKey { + /// The ID of the tape asset. + pub tape_id: AssetId, + /// The type of data: vertex data, index data + pub class: ElementClass, +} + +impl TapeAllocationKey { + /// Creates a new [`TapeAllocationKey`] for the given tape asset ID and + /// class. + pub fn new(tape_id: AssetId, class: ElementClass) -> Self { + Self { tape_id, class } + } +} + +/// The type of element that a tape slab can store. +#[derive(Clone, Copy, PartialEq, Eq, Hash)] +pub enum ElementClass { + /// Per-tape metadata + Metadata, + /// Data for the aabbs. + Aabb, +} + +/// Information about the size of individual elements within a slab. +/// +/// Slab objects are allocated in units of *slots*. Usually, each element takes +/// up one slot, and so elements and slots are equivalent. Occasionally, +/// however, a slot may consist of 2 or even 4 elements. This occurs when the +/// size of an element isn't divisible by [`COPY_BUFFER_ALIGNMENT`]. When we +/// resize buffers, we perform GPU-to-GPU copies to shuffle the existing +/// elements into their new positions, and such copies must be on +/// [`COPY_BUFFER_ALIGNMENT`] boundaries. Slots solve this problem by +/// guaranteeing that the size of an allocation quantum is divisible by both the +/// size of an element and [`COPY_BUFFER_ALIGNMENT`], so we can relocate it +/// freely. +#[derive(Clone, Copy, PartialEq, Eq, Hash)] +pub struct ElementLayout { + class: ElementClass, + + /// The size in bytes of a single element. + size: u64, + + /// The number of elements that make up a single slot. + /// + /// Usually, this is 1, but it can be different if [`ElementLayout::size`] + /// isn't divisible by 4. See the comment in [`ElementLayout`] for more + /// details. + elements_per_slot: u32, + + buffer_usages: BufferUsages, +} + +impl Plugin for TapeAllocatorPlugin { + fn build(&self, app: &mut App) { + let Some(render_app) = app.get_sub_app_mut(RenderApp) else { + return; + }; + + render_app + .init_resource::() + .add_systems( + Render, + allocate_and_free_tapes + .in_set(RenderSystems::PrepareAssets) + .before(prepare_assets::), + ); + } + + fn finish(&self, app: &mut App) { + let Some(render_app) = app.get_sub_app_mut(RenderApp) else { + return; + }; + + // The `RenderAdapter` isn't available until now, so we can't do this in + // [`Plugin::build`]. + render_app.init_gpu_resource::(); + } +} + +impl FromWorld for TapeAllocator { + fn from_world(world: &mut World) -> Self { + // Take the `extra_buffer_usages` from the tape allocator settings into + // account. + let tape_allocator_settings = world.resource::(); + let mut slab_allocator = SlabAllocator::new(); + slab_allocator.extra_buffer_usages |= tape_allocator_settings.extra_buffer_usages; + + Self { slab_allocator } + } +} + +/// A system that processes newly-extracted or newly-removed tapes and writes +/// their data into buffers or frees their data as appropriate. +pub fn allocate_and_free_tapes( + mut tape_allocator: ResMut, + tape_allocator_settings: Res, + extracted_tapes: Res>, + render_device: Res, + render_queue: Res, +) { + // Clear the list of tapes displaced by last frame's slab growth. + tape_allocator.clear_displaced_keys(); + + // Process removed or modified tapes. + tape_allocator.free_tapes(&extracted_tapes); + + // Process newly-added or modified tapes. + tape_allocator.allocate_tapes( + &tape_allocator_settings, + &extracted_tapes, + &render_device, + &render_queue, + ); +} + +impl TapeAllocator { + /// Returns the buffer and range within that buffer of the metadata for + /// the tape with the given ID. + /// + /// If the tape wasn't allocated, returns None. + pub fn tape_metadata_slice(&self, tape_id: &AssetId) -> Option> { + self.slab_allocation_slice( + &TapeAllocationKey::new(*tape_id, ElementClass::Metadata), + *self.tape_id_to_metadata_slab(tape_id)?, + ) + } + + /// Tapes that had the buffer under their aabb data replaced + /// this frame by a slab they were already resident in growing, so that + /// anything caching those buffers can rebuild just the affected + /// entries. + /// + /// **It is not the full set of tapes whose buffers changed this frame, and + /// is not meant to be.** Callers must handle [`ExtractedAssets`] + /// themselves if they want the full set of changed buffers. + /// + /// See [`SlabAllocator::keys_displaced_by_slab_growth`], which this wraps. + pub fn tapes_displaced_by_slab_growth(&self) -> impl Iterator> { + self.keys_displaced_by_slab_growth() + .iter() + .filter(|key| matches!(key.class, ElementClass::Aabb)) + .map(|key| key.tape_id) + } + + /// Returns the buffer and range within that buffer of the aabb data for + /// the tape with the given ID. + /// + /// If the tape wasn't allocated, returns None. + pub fn tape_aabb_slice(&self, tape_id: &AssetId) -> Option> { + self.slab_allocation_slice( + &TapeAllocationKey::new(*tape_id, ElementClass::Aabb), + *self.tape_id_to_aabb_slab(tape_id)?, + ) + } + + /// Returns the IDs of the vertex buffer and index buffer respectively for + /// the tape with the given ID. + /// + /// If the tape wasn't allocated, or has no index data in the case of the + /// index buffer, the corresponding element in the returned tuple will be + /// None. + pub fn tape_slabs(&self, tape_id: &AssetId) -> Option { + Some(TapeSlabs { + aabb_slab_id: self.tape_id_to_aabb_slab(tape_id).cloned()?, + metadata_slab_id: self.tape_id_to_metadata_slab(tape_id).cloned(), + }) + } + + /// Returns the number of aabb allocations that this tape allocator + /// manages. + pub fn aabb_allocation_count(&self) -> usize { + self.key_to_slab + .keys() + .filter(|key| key.class == ElementClass::Aabb) + .count() + } + + /// Given the ID of a tape, returns the ID of the slab that contains the + /// metadata for that tape, if it exists. + fn tape_id_to_metadata_slab(&self, tape_id: &AssetId) -> Option<&SlabId> { + self.key_to_slab + .get(&TapeAllocationKey::new(*tape_id, ElementClass::Metadata)) + } + + /// Given the ID of a tape, returns the ID of the slab that contains the + /// aabb data for that tape, if it exists. + fn tape_id_to_aabb_slab(&self, tape_id: &AssetId) -> Option<&SlabId> { + self.key_to_slab + .get(&TapeAllocationKey::new(*tape_id, ElementClass::Aabb)) + } + + pub fn metadata_slabs(&self) -> impl Iterator { + self.slabs.iter().filter_map(|(slab_id, slab)| { + if matches!(element_class(slab), ElementClass::Metadata) { + Some(*slab_id) + } else { + None + } + }) + } + + /// Processes newly-loaded tapes, allocating room in the slabs for their + /// tape data and performing upload operations as appropriate. + fn allocate_tapes( + &mut self, + tape_allocator_settings: &TapeAllocatorSettings, + extracted_tapes: &ExtractedAssets, + render_device: &RenderDevice, + render_queue: &RenderQueue, + ) { + let mut allocation_stage = self.slab_allocator.stage_allocation(); + + // Loop over each tape that was extracted this frame. + for (tape_id, tape) in &extracted_tapes.extracted { + let aabb_buffer_size = tape.get_aabb_buffer_size() as u64; + if aabb_buffer_size == 0 { + warn!("Tape {:?} contains no aabbs.", tape_id); + continue; + } + + // Allocate metadata. + if let Some(metadata_element_layout) = ElementLayout::metadata(tape) { + allocation_stage.allocate( + &TapeAllocationKey::new(*tape_id, ElementClass::Metadata), + size_of::() as u64, + metadata_element_layout, + tape_allocator_settings, + ); + } + + // Allocate aabb data. + if let Some(aabb_element_layout) = ElementLayout::aabb(tape) { + allocation_stage.allocate( + &TapeAllocationKey::new(*tape_id, ElementClass::Aabb), + aabb_buffer_size, + aabb_element_layout, + tape_allocator_settings, + ); + } + } + + // Perform growth. + allocation_stage.commit(render_device, render_queue); + + // Copy new tape data in. + for (tape_id, tape) in &extracted_tapes.extracted { + let aabb_buffer_size = tape.get_aabb_buffer_size() as u64; + if aabb_buffer_size == 0 { + continue; + } + self.copy_tape_metadata(tape_id, tape, render_device, render_queue); + } + } + + /// Copies metadata from a tape into the appropriate spot in the slab. + fn copy_tape_metadata( + &mut self, + tape_id: &AssetId, + tape: &Tape, + render_device: &RenderDevice, + render_queue: &RenderQueue, + ) { + let metadata = { + let aabb = tape.get_aabb(0.0); + let aabb_center = aabb.center().into(); + let aabb_half_extents = aabb.half_size().into(); + TapeMetadata { + aabb_center, + aabb_half_extents, + ..Default::default() + } + }; + // Call the generic function. + self.copy_element_data( + &TapeAllocationKey::new(*tape_id, ElementClass::Metadata), + size_of::(), + |mut slice| slice.copy_from_slice(bytemuck::cast_slice(&[metadata])), + render_device, + render_queue, + ); + } + + /// Frees allocations for tapes that were removed, modified, or + /// re-extracted this frame. + fn free_tapes(&mut self, extracted_tapes: &ExtractedAssets) { + let mut deallocation_stage = self.slab_allocator.stage_deallocation(); + + // TODO: Consider explicitly reusing allocations for changed tapes of + // the same size + + // Free every tape that `allocate_tapes` is about to reallocate. + // Despite its name, `added` holds every tape extracted this + // frame rather than only the new ones, so it's exactly that + // set. This catches a tape removed from `Assets` and reinserted + // under the same ID, which arrives as `Removed` then `Added` + // and so never appears in `modified`. + let tapes_to_free = extracted_tapes + .removed + .iter() + .chain(extracted_tapes.modified.iter()) + .chain(extracted_tapes.added.iter()); + + for tape_id in tapes_to_free { + deallocation_stage.free(&TapeAllocationKey::new(*tape_id, ElementClass::Metadata)); + deallocation_stage.free(&TapeAllocationKey::new(*tape_id, ElementClass::Aabb)); + } + + deallocation_stage.commit(); + } +} + +impl ElementLayout { + /// Creates an [`ElementLayout`] for tape data of the given class (vertex or + /// index) with the given byte size. + fn new(class: ElementClass, size: u64) -> ElementLayout { + const { + assert!(4 == COPY_BUFFER_ALIGNMENT); + } + + // this is equivalent to `4 / gcd(4,size)` but lets us not implement + // gcd. ping @atlv if above assert ever fails (likely never) + let elements_per_slot = [1, 4, 2, 4][size as usize & 3]; + ElementLayout { + class, + size, + // Make sure that slot boundaries begin and end on + // `COPY_BUFFER_ALIGNMENT`-byte (4-byte) boundaries. + elements_per_slot, + buffer_usages: class.buffer_usages(), + } + } + + /// Creates the appropriate [`ElementLayout`] for the given tape's metadata + /// data. + fn metadata(_tape: &Tape) -> Option { + Some(ElementLayout::new( + ElementClass::Metadata, + size_of::() as u64, + )) + } + + /// Creates the appropriate [`ElementLayout`] for the given tape's aabb + /// data. + fn aabb(_tape: &Tape) -> Option { + Some(ElementLayout::new( + ElementClass::Aabb, + size_of::() as u64, + )) + } +} + +impl SlabItemLayout for ElementLayout { + fn size(&self) -> u64 { + self.size + } + + fn elements_per_slot(&self) -> u32 { + self.elements_per_slot + } + + fn buffer_usages(&self) -> BufferUsages { + self.buffer_usages + } +} + +impl ElementClass { + /// Returns the `wgpu` [`BufferUsages`] appropriate for a buffer of this + /// class. + const fn buffer_usages(&self) -> BufferUsages { + match *self { + ElementClass::Metadata => BufferUsages::STORAGE, + ElementClass::Aabb => { + BufferUsages::union(BufferUsages::STORAGE, BufferUsages::BLAS_INPUT) + }, + } + } +} diff --git a/src/scene/tapes/blas.rs b/src/scene/tapes/blas.rs new file mode 100644 index 0000000..cfc1236 --- /dev/null +++ b/src/scene/tapes/blas.rs @@ -0,0 +1,191 @@ +use alloc::collections::VecDeque; + +use bevy_asset::AssetId; +use bevy_ecs::{ + resource::Resource, + system::{Res, ResMut}, +}; +use bevy_platform::collections::HashMap; +use bevy_render::{ + diagnostic::{DiagnosticsRecorder, RecordDiagnostics}, + render_asset::ExtractedAssets, + render_resource::*, + renderer::{RenderDevice, RenderQueue}, +}; +use wgpu::{BlasAabbGeometry, wgt::BlasAABBGeometrySizeDescriptor}; + +use crate::scene::tapes::{ + self, + allocator::{TapeAllocator, TapeBufferSlice}, + types::{RenderTape, Tape}, +}; + +/// Under the `wgpu_hal` build path, we need to manage BLAS lifetimes ourselves. +/// Since solari keeps both current and previous frame TLAS's around, only after +/// two TLAS builds since we marked it for deletion is it safe to delete a BLAS. +const TLAS_BUILDS_BEFORE_DELETION_ALLOWED: usize = 2; + +#[derive(Resource, Default)] +pub struct BlasManager { + blas: HashMap, Blas>, + changed: Vec>, + /// BLAS that are pending deletion, one batch per TLAS build. The back batch + /// collects retirements since the last build, and every batch ahead of + /// it has one more build to wait out. + pending_deletions: VecDeque>, +} + +impl BlasManager { + pub fn get(&self, tape: &AssetId) -> Option<&Blas> { + self.blas.get(tape) + } + + pub fn device_address(&self, tape: &AssetId) -> Option { + self.blas.get(tape)?.handle() + } + + pub fn changed_tapes(&self) -> &[AssetId] { + &self.changed + } + + pub fn note_tlas_build(&mut self) { + if !self.pending_deletions.is_empty() { + self.pending_deletions.push_back(Vec::new()); + } + } + + fn insert(&mut self, tape: AssetId, blas: Blas) { + if let Some(old) = self.blas.insert(tape, blas) { + self.retire(old); + } + + self.changed.push(tape); + } + + fn remove(&mut self, tape: AssetId) { + self.changed.push(tape); + + if let Some(removed) = self.blas.remove(&tape) { + self.retire(removed); + } + } + + fn retire(&mut self, blas: Blas) { + match self.pending_deletions.back_mut() { + Some(batch) => batch.push(blas), + None => self.pending_deletions.push_back(vec![blas]), + } + } +} + +pub fn prepare_raytracing_blas( + mut blas_manager: ResMut, + extracted_tapes: Res>, + tape_allocator: Res, + render_device: Res, + render_queue: Res, + mut diagnostics: Option>, +) { + blas_manager.changed.clear(); + + // Delete BLAS for deleted or modified tapes + for asset_id in extracted_tapes + .removed + .iter() + .chain(extracted_tapes.modified.iter()) + { + blas_manager.remove(*asset_id); + } + + if extracted_tapes.extracted.is_empty() { + return; + } + + // Create new BLAS for added or changed tapes + let blas_resources = extracted_tapes + .extracted + .iter() + .map(|(asset_id, _)| { + let aabbs_slice = tape_allocator.tape_aabb_slice(asset_id).unwrap(); + + let (blas, blas_size) = allocate_blas(&aabbs_slice, asset_id, &render_device); + + blas_manager.insert(*asset_id, blas); + + (*asset_id, aabbs_slice, blas_size) + }) + .collect::>(); + + // Build geometry into each BLAS + let build_entries = blas_resources + .iter() + .map(|(asset_id, aabbs_slice, blas_size)| { + let geometry = BlasAabbGeometry { + size: blas_size, + stride: size_of::() as u64, + aabb_buffer: aabbs_slice.buffer, + primitive_offset: aabbs_slice.range.start, + }; + BlasBuildEntry { + blas: &blas_manager.blas[asset_id], + geometry: BlasGeometries::AabbGeometries(vec![geometry]), + } + }) + .collect::>(); + + let mut command_encoder = render_device.create_command_encoder(&CommandEncoderDescriptor { + label: Some("blas_build_command_encoder"), + }); + let time_span = diagnostics + .as_mut() + .map(|diagnostics| diagnostics.time_span(&mut command_encoder, "tape_blas_build")); + command_encoder.build_acceleration_structures(&build_entries, &[]); + if let Some(time_span) = time_span { + time_span.end(&mut command_encoder); + } + render_queue.submit([command_encoder.finish()]); +} + +pub fn delete_raytracing_blas( + mut blas_manager: ResMut, + render_queue: Res, +) { + if blas_manager.pending_deletions.len() <= TLAS_BUILDS_BEFORE_DELETION_ALLOWED { + return; + } + + if let Some(deletable) = blas_manager + .pending_deletions + .pop_front() + .filter(|b| !b.is_empty()) + { + render_queue.on_submitted_work_done(move || drop(deletable)); + } +} + +fn allocate_blas( + aabbs_slice: &TapeBufferSlice, + asset_id: &AssetId, + render_device: &RenderDevice, +) -> (Blas, BlasAABBGeometrySizeDescriptor) { + let blas_size = BlasAABBGeometrySizeDescriptor { + primitive_count: aabbs_slice.range.len() as u32, + flags: AccelerationStructureGeometryFlags::OPAQUE, + }; + + // TODO: If we ever introduce BLAS refits, we need to be aware of the TLAS + // double-buffer to avoid invalidating the previous frame TLAS + let blas = render_device.wgpu_device().create_blas( + &CreateBlasDescriptor { + label: Some(&asset_id.to_string()), + flags: AccelerationStructureFlags::PREFER_FAST_TRACE + | AccelerationStructureFlags::ALLOW_COMPACTION, + update_mode: AccelerationStructureUpdateMode::Build, + }, + BlasGeometrySizeDescriptors::AABBs { + descriptors: vec![blas_size.clone()], + }, + ); + + (blas, blas_size) +} diff --git a/src/scene/tapes/mod.rs b/src/scene/tapes/mod.rs new file mode 100644 index 0000000..ea468f0 --- /dev/null +++ b/src/scene/tapes/mod.rs @@ -0,0 +1,4 @@ +pub mod allocator; +pub mod blas; +pub mod plugin; +pub mod types; diff --git a/src/scene/tapes/plugin.rs b/src/scene/tapes/plugin.rs new file mode 100644 index 0000000..8442a1e --- /dev/null +++ b/src/scene/tapes/plugin.rs @@ -0,0 +1,48 @@ +use bevy_app::{App, Plugin, PostUpdate}; +use bevy_asset::{AssetApp as _, AssetEvent, AssetEventSystems, AssetId}; +use bevy_ecs::{ + change_detection::DetectChangesMut as _, message::MessageReader, + schedule::IntoScheduleConfigs as _, system::Query, +}; +use bevy_platform::{collections::HashSet, hash::FixedHasher}; + +use crate::scene::{Tape3d, tapes::types::Tape}; + +/// A system that marks a [`Tape3d`] as changed if the associated [`Tape`] asset +/// has changed. +pub fn mark_tapes_as_changed_if_their_assets_changed( + mut tapes: Query<&mut Tape3d>, + mut tape_asset_events: MessageReader>, +) { + let mut changed_tapes: HashSet, FixedHasher> = HashSet::default(); + for tape_asset_event in tape_asset_events.read() { + if let AssetEvent::Modified { id } = tape_asset_event { + changed_tapes.insert(*id); + } + } + + if changed_tapes.is_empty() { + return; + } + + tapes.par_iter_mut().for_each(|mut tape| { + if changed_tapes.contains(&tape.0.id()) { + tape.set_changed(); + } + }); +} + +/// Adds [`Tape`] as an asset. +#[derive(Default)] +pub struct TapePlugin; + +impl Plugin for TapePlugin { + fn build(&self, app: &mut App) { + app.init_asset::() + .register_asset_reflect::() + .add_systems( + PostUpdate, + mark_tapes_as_changed_if_their_assets_changed.after(AssetEventSystems), + ); + } +} diff --git a/src/scene/tapes/types.rs b/src/scene/tapes/types.rs new file mode 100644 index 0000000..55b20bb --- /dev/null +++ b/src/scene/tapes/types.rs @@ -0,0 +1,232 @@ +use std::simd::StdFloat as _; + +use bevy_asset::{Asset, AssetId, Handle}; +use bevy_derive::{Deref, DerefMut}; +use bevy_ecs::{ + component::Component, + prelude::ReflectComponent, + system::{SystemParamItem, lifetimeless::SRes}, + template::FromTemplate, +}; +use bevy_math::Vec3; +use bevy_pbr::{MeshMaterial3d, StandardMaterial}; +use bevy_reflect::{Reflect, prelude::ReflectDefault}; +use bevy_render::{ + render_asset::{AssetExtractionError, PrepareAssetError, RenderAsset}, + render_resource::ShaderType, + renderer::{RenderDevice, RenderQueue}, + sync_world::SyncToRenderWorld, +}; +use bevy_shape::Aabb3d; +use bevy_transform::components::Transform; +use bytemuck::{Pod, Zeroable}; +use derive_more::derive::From; +use tape_load::interpreters::{self, point::PointInterpreter}; + +#[derive(Debug, PartialEq, Clone, Copy, Reflect)] +#[reflect(Debug, PartialEq, Clone)] +pub struct Aabb { + /// The minimum point of the box + pub min: Vec3, + /// The maximum point of the box + pub max: Vec3, +} + +#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Reflect)] +#[reflect(Clone)] +pub enum SSAOpcode { + SSAAdd, + SSASub, + SSAMul, + SSADiv, + SSAAtan2, + SSAMin, + SSAMax, + SSACompare, + SSAMod, + SSAAnd, + SSAOr, + + SSANegate, + SSAAbs, + SSARecip, + SSASqrt, + SSASquare, + SSAFloor, + SSACeil, + SSARound, + SSASin, + SSACos, + SSATan, + SSAAsin, + SSAAcos, + SSAAtan, + SSAExp, + SSALog, + SSANot, + + SSAFract, + SSACube, + SSASmoothMin, + SSASmoothMax, + SSAClamp, + SSAMix, + SSAFMA, + + SSADot, + SSALength, + SSADistance, + + #[default] + SSAStop, + SSAReturn, + SSAPosition, + SSAMinMaterial, + SSAMaxMaterial, + SSASmoothMinMaterial, + SSASmoothMaxMaterial, + SSASDFSphere, + SSASDFBox, + SSASDFTorus, +} + +#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Reflect)] +#[reflect(Clone)] +pub struct SSAOpcodeSized { + pub opcode: SSAOpcode, + pub size: u8, +} + +#[derive(Debug, PartialEq, Clone, Copy, Reflect)] +#[reflect(Clone)] +pub enum SSAInput { + Register(u32), + Constant(f32), +} + +#[derive(Debug, Default, PartialEq, Clone, Reflect)] +#[reflect(Clone)] +pub struct SSAInstruction { + pub opcode: SSAOpcodeSized, + pub inputs: Vec, + pub outputs: Vec, +} + +#[derive(Debug, Default, PartialEq, Clone, Reflect)] +#[reflect(Clone)] +pub struct SSATape { + pub last_output: u32, + pub tape: Vec, + constants: Vec, +} + +/// A tape drive tape. +#[derive(Asset, Clone, Debug, Reflect, PartialEq)] +#[reflect(Clone)] +pub struct Tape { + pub parts: SSATape, + pub _seed: u64, + pub subdivision: u32, +} + +impl Tape { + pub fn get_aabb(&self, time: f32) -> Aabb3d { + const INTERPRET_INPUT_X: interpreters::Value = + interpreters::Value::from_array([10000.0, 0.0, 0.0, -10000.0, 0.0, 0.0, 0.0, 0.0]); + const INTERPRET_INPUT_Y: interpreters::Value = + interpreters::Value::from_array([0.0, 10000.0, 0.0, 0.0, -10000.0, 0.0, 0.0, 0.0]); + const INTERPRET_INPUT_Z: interpreters::Value = + interpreters::Value::from_array([0.0, 0.0, 10000.0, 0.0, 0.0, -10000.0, 0.0, 0.0]); + const INTERPRET_MUL: interpreters::Value = + interpreters::Value::from_array([-1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 0.0, 0.0]); + const INTERPRET_ADD: interpreters::Value = interpreters::Value::from_array([ + 10000.0, 10000.0, 10000.0, -10000.0, -10000.0, -10000.0, 0.0, 0.0, + ]); + + // This can only go well + let parts = unsafe { core::mem::transmute(&self.parts) }; + + let mut interpreter = PointInterpreter::new(parts); + let interpreter_out = interpreter + .scene( + INTERPRET_INPUT_X, + INTERPRET_INPUT_Y, + INTERPRET_INPUT_Z, + interpreters::Value::splat(time), + ) + .mul_add(INTERPRET_MUL, INTERPRET_ADD) + .to_array(); + + const EPSILON: f32 = 0.1; + + let highest_corner = + Vec3::new(interpreter_out[0], interpreter_out[1], interpreter_out[2]) + EPSILON; + let lowest_corner = + Vec3::new(interpreter_out[3], interpreter_out[4], interpreter_out[5]) - EPSILON; + + Aabb3d::from_min_max(lowest_corner, highest_corner) + } + + pub fn get_aabb_buffer_size(&self) -> u64 { + (self.subdivision * self.subdivision * self.subdivision) as u64 + } +} + +/// Per-tape metadata, stored in [`crate::mesh::allocator::MeshAllocator`]. +/// Currently this is used to decompress vertex. +#[derive(Default, Pod, Zeroable, Clone, Copy, Debug, ShaderType)] +#[repr(C)] +pub struct TapeMetadata { + // AABB for decompressing positions. + pub aabb_center: Vec3, + pub pad1: u32, + // AABB for decompressing positions. + pub aabb_half_extents: Vec3, + pub pad2: u32, +} + +/// The render world representation of a [`Tape`]. +#[derive(Debug, Clone)] +pub struct RenderTape {} + +impl RenderAsset for RenderTape { + type Param = (SRes, SRes); + type SourceAsset = Tape; + + fn take_gpu_data( + source: &mut Self::SourceAsset, + _previous_gpu_asset: Option<&Self>, + ) -> Result { + Ok(source.clone()) + } + + fn byte_len(_tape: &Self::SourceAsset) -> Option { + // Some(0) // Is this really correct? + None + } + + /// Converts the extracted mesh into a [`RenderMesh`]. + fn prepare_asset( + _tape: Self::SourceAsset, + _tape_id: AssetId, + (_render_device, _render_queue): &mut SystemParamItem, + _: Option<&Self>, + ) -> Result> { + Ok(Self {}) + } + + fn unload_asset(_tape_id: AssetId, (..): &mut SystemParamItem) { + } +} + +/// A tape drive tape. +/// +/// The material used for this entity must be +/// [`MeshMaterial3d`]. +#[derive( + Component, FromTemplate, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From, +)] +#[reflect(Component, Default, Clone, PartialEq)] +#[require(MeshMaterial3d, Transform, SyncToRenderWorld)] +pub struct Tape3d(pub Handle); +