diff --git a/Cargo.lock b/Cargo.lock index 2a93243fd3..32e61991fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -303,7 +303,7 @@ checksum = "bcfcc3cd946cb52f0bbfdbbcfa2f4e24f75ebb6c0e1002f7c25904fada18b9ec" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -449,7 +449,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -520,6 +520,37 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" +[[package]] +name = "com" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e17887fd17353b65b1b2ef1c526c83e26cd72e74f598a8dc1bee13a48f3d9f6" +dependencies = [ + "com_macros", +] + +[[package]] +name = "com_macros" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d375883580a668c7481ea6631fc1a8863e33cc335bf56bfad8d7e6d4b04b13a5" +dependencies = [ + "com_macros_support", + "proc-macro2", + "syn 1.0.109", +] + +[[package]] +name = "com_macros_support" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad899a1087a9296d5644792d7cb72b8e34c1bec8e7d4fbc002230169a6e8710c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -829,6 +860,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991" +[[package]] +name = "d3d12" +version = "22.0.0" +source = "git+https://github.com/FL33TW00D/wgpu#bfad205cf55fc8e28098deb95529803da314ffcf" +dependencies = [ + "bitflags 2.6.0", + "libloading", + "winapi", +] + [[package]] name = "data-encoding" version = "2.6.0" @@ -906,7 +947,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -1093,7 +1134,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -1230,7 +1271,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -1383,6 +1424,7 @@ dependencies = [ "log 0.4.22", "presser", "thiserror 1.0.69", + "winapi", "windows 0.58.0", ] @@ -1426,6 +1468,16 @@ dependencies = [ "crunchy", ] +[[package]] +name = "half-2" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c36518ae13d88b7cbdc61401256df5d9fc27921ea66353a16660869b47af8864" +dependencies = [ + "cfg-if 1.0.0", + "crunchy", +] + [[package]] name = "halfbrown" version = "0.2.5" @@ -1457,6 +1509,21 @@ dependencies = [ "foldhash", ] +[[package]] +name = "hassle-rs" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af2a7e73e1f34c48da31fb668a907f250794837e08faa144fd24f0b8b741e890" +dependencies = [ + "bitflags 2.6.0", + "com", + "libc", + "libloading", + "thiserror 1.0.69", + "widestring", + "winapi", +] + [[package]] name = "heck" version = "0.5.0" @@ -1596,7 +1663,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -1910,7 +1977,7 @@ dependencies = [ "librashader-pack", "librashader-preprocess", "librashader-presets", - "naga", + "naga 23.0.0", "rspirv", "rustc-hash 2.1.0", "serde", @@ -2111,6 +2178,26 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "naga" +version = "22.0.0" +source = "git+https://github.com/FL33TW00D/wgpu#bfad205cf55fc8e28098deb95529803da314ffcf" +dependencies = [ + "arrayvec", + "bit-set", + "bitflags 2.6.0", + "cfg_aliases 0.1.1", + "codespan-reporting", + "hexf-parse", + "indexmap", + "log 0.4.22", + "rustc-hash 1.1.0", + "spirv", + "termcolor", + "thiserror 1.0.69", + "unicode-xid", +] + [[package]] name = "naga" version = "23.0.0" @@ -2122,7 +2209,6 @@ dependencies = [ "bitflags 2.6.0", "cfg_aliases 0.1.1", "codespan-reporting", - "hexf-parse", "indexmap", "log 0.4.22", "petgraph", @@ -2130,7 +2216,6 @@ dependencies = [ "spirv", "termcolor", "thiserror 1.0.69", - "unicode-xid", ] [[package]] @@ -2220,7 +2305,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -2490,7 +2575,7 @@ checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -3108,7 +3193,7 @@ checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -3339,7 +3424,7 @@ checksum = "18017a288e6ce64dd5d56510166baeabb01849483555c031f573c091b6934a64" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -3383,6 +3468,7 @@ dependencies = [ "fontconfig-parser", "futures", "guillotiere", + "half-2", "halfbrown", "image", "js-sys", @@ -3429,6 +3515,17 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce5d813d71d82c4cbc1742135004e4a79fd870214c155443451c139c9470a0aa" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.89" @@ -3448,7 +3545,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -3511,7 +3608,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -3522,7 +3619,7 @@ checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -3673,7 +3770,7 @@ checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -3889,7 +3986,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.89", "wasm-bindgen-shared", ] @@ -3923,7 +4020,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3957,7 +4054,7 @@ checksum = "c97b2ef2c8d627381e51c071c2ab328eac606d3f69dd82bcbca20a9e389d95f0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -4097,16 +4194,15 @@ checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" [[package]] name = "wgpu" -version = "23.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80f70000db37c469ea9d67defdc13024ddf9a5f1b89cb2941b812ad7cde1735a" +version = "22.0.0" +source = "git+https://github.com/FL33TW00D/wgpu#bfad205cf55fc8e28098deb95529803da314ffcf" dependencies = [ "arrayvec", "cfg_aliases 0.1.1", "document-features", "js-sys", "log 0.4.22", - "naga", + "naga 22.0.0", "parking_lot", "profiling", "raw-window-handle", @@ -4122,9 +4218,8 @@ dependencies = [ [[package]] name = "wgpu-core" -version = "23.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d63c3c478de8e7e01786479919c8769f62a22eec16788d8c2ac77ce2c132778a" +version = "22.0.0" +source = "git+https://github.com/FL33TW00D/wgpu#bfad205cf55fc8e28098deb95529803da314ffcf" dependencies = [ "arrayvec", "bit-vec", @@ -4133,7 +4228,7 @@ dependencies = [ "document-features", "indexmap", "log 0.4.22", - "naga", + "naga 22.0.0", "once_cell", "parking_lot", "profiling", @@ -4147,9 +4242,8 @@ dependencies = [ [[package]] name = "wgpu-hal" -version = "23.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89364b8a0b211adc7b16aeaf1bd5ad4a919c1154b44c9ce27838213ba05fd821" +version = "22.0.0" +source = "git+https://github.com/FL33TW00D/wgpu#bfad205cf55fc8e28098deb95529803da314ffcf" dependencies = [ "android_system_properties", "arrayvec", @@ -4157,21 +4251,22 @@ dependencies = [ "bit-set", "bitflags 2.6.0", "block", - "bytemuck", "cfg_aliases 0.1.1", "core-graphics-types 0.1.3", + "d3d12", "glow", "glutin_wgl_sys", "gpu-alloc", "gpu-allocator", "gpu-descriptor", + "hassle-rs", "js-sys", "khronos-egl", "libc", "libloading", "log 0.4.22", "metal", - "naga", + "naga 22.0.0", "ndk-sys", "objc", "once_cell", @@ -4186,21 +4281,26 @@ dependencies = [ "wasm-bindgen", "web-sys", "wgpu-types", + "winapi", "windows 0.58.0", - "windows-core", ] [[package]] name = "wgpu-types" -version = "23.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "610f6ff27778148c31093f3b03abc4840f9636d58d597ca2f5977433acfe0068" +version = "22.0.0" +source = "git+https://github.com/FL33TW00D/wgpu#bfad205cf55fc8e28098deb95529803da314ffcf" dependencies = [ "bitflags 2.6.0", "js-sys", "web-sys", ] +[[package]] +name = "widestring" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7219d36b6eac893fa81e84ebe06485e7dcbb616177469b142df14f1f4deb1311" + [[package]] name = "winapi" version = "0.3.9" @@ -4278,7 +4378,7 @@ checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -4289,7 +4389,7 @@ checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -4669,7 +4769,7 @@ checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", "synstructure", ] @@ -4697,7 +4797,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] @@ -4717,7 +4817,7 @@ checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", "synstructure", ] @@ -4740,7 +4840,7 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.89", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 4bf92fa56e..128a544366 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,8 @@ image_rs = { package = "image", version = "0.25.5", default-features = false, fe regex = "1.11.1" bytemuck = { version = "1.21.0", features = [ "derive" ] } serde = { version = "1.0.217", features = ["derive"] } -wgpu = "23.0.1" +# wgpu = "23.0.1" +wgpu = { git = "https://github.com/FL33TW00D/wgpu" } libc = "0.2.169" smol_str = "0.3.2" futures = "0.3.31" diff --git a/sugarloaf/Cargo.toml b/sugarloaf/Cargo.toml index 2996ea0866..a6f8e639a1 100644 --- a/sugarloaf/Cargo.toml +++ b/sugarloaf/Cargo.toml @@ -52,6 +52,7 @@ num-traits = "0.2.19" yazi = { version = "0.2.0", optional = true } zeno = { version = "0.2.3", optional = true, default-features = false } futures = "0.3.31" +half-2 = { version = "2.4.1" } librashader-common = "0.6.2" librashader-presets = "0.6.2" diff --git a/sugarloaf/src/components/rich_text/mod.rs b/sugarloaf/src/components/rich_text/mod.rs index 1705a96446..683181be5d 100644 --- a/sugarloaf/src/components/rich_text/mod.rs +++ b/sugarloaf/src/components/rich_text/mod.rs @@ -164,11 +164,15 @@ impl RichTextBrush { label: Some("rich_text::layout_bind_group"), }); + let shader_source = if context.f16_support { + include_str!("rich_text_f16.wgsl") + } else { + include_str!("rich_text.wgsl") + }; + let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, - source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!( - "rich_text.wgsl" - ))), + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(shader_source)), }); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { diff --git a/sugarloaf/src/components/rich_text/rich_text_f16.wgsl b/sugarloaf/src/components/rich_text/rich_text_f16.wgsl new file mode 100644 index 0000000000..aa0a4439b2 --- /dev/null +++ b/sugarloaf/src/components/rich_text/rich_text_f16.wgsl @@ -0,0 +1,52 @@ +enable f16; + +struct Globals { + transform: mat4x4, +} + +@group(0) @binding(0) var globals: Globals; +@group(0) @binding(1) var font_sampler: sampler; +@group(1) @binding(0) var font_texture: texture_2d; + +struct VertexInput { + @builtin(vertex_index) vertex_index: u32, + @location(0) v_pos: vec4, + @location(1) v_color: vec4, + @location(2) v_uv: vec2, + @location(3) layers: vec2, +} + +struct VertexOutput { + @builtin(position) position: vec4, + @location(0) f_color: vec4, + @location(1) f_uv: vec2, + @location(2) color_layer: i32, + @location(3) mask_layer: i32, +} + +@vertex +fn vs_main(input: VertexInput) -> VertexOutput { + var out: VertexOutput; + out.f_color = input.v_color; + out.f_uv = input.v_uv; + out.color_layer = input.layers.x; + out.mask_layer = input.layers.y; + + out.position = globals.transform * vec4(input.v_pos.xy, 0.0, 1.0); + return out; +} + +@fragment +fn fs_main(input: VertexOutput) -> @location(0) vec4 { + var out: vec4 = input.f_color; + + if input.color_layer > 0 { + out = textureSampleLevel(font_texture, font_sampler, input.f_uv, 0.0); + } + + if input.mask_layer > 0 { + out = vec4(out.xyz, textureSampleLevel(font_texture, font_sampler, input.f_uv, 0.0).x); + } + + return out; +} \ No newline at end of file diff --git a/sugarloaf/src/context/mod.rs b/sugarloaf/src/context/mod.rs index d02b927ba6..864b55c251 100644 --- a/sugarloaf/src/context/mod.rs +++ b/sugarloaf/src/context/mod.rs @@ -8,6 +8,7 @@ pub struct Context<'a> { pub format: wgpu::TextureFormat, pub size: SugarloafWindowSize, pub scale: f32, + pub f16_support: bool, alpha_mode: wgpu::CompositeAlphaMode, pub adapter_info: wgpu::AdapterInfo, surface_caps: wgpu::SurfaceCapabilities, @@ -110,8 +111,20 @@ impl Context<'_> { #[cfg(not(target_os = "macos"))] let format = find_best_texture_format(surface_caps.formats.as_slice()); + let mut f16_support = false; + let (device, queue) = { - { + // First try with f16 support + if let Ok(result) = futures::executor::block_on(adapter.request_device( + &wgpu::DeviceDescriptor { + label: None, + required_features: wgpu::Features::SHADER_F16, + ..Default::default() + }, None), + ) { + f16_support = true; + result + } else { if let Ok(result) = futures::executor::block_on(adapter.request_device( // ADDRESS_MODE_CLAMP_TO_BORDER is required for librashader &wgpu::DeviceDescriptor { @@ -167,6 +180,7 @@ impl Context<'_> { ); Context { + f16_support, device, queue, surface,