From 1fef2326cdbca04c238962aea3000caea11d5216 Mon Sep 17 00:00:00 2001 From: Raphael Amorim Date: Thu, 3 Oct 2024 16:33:27 +0200 Subject: [PATCH] f16 wip --- Cargo.lock | 80 +++++++++++++------ Cargo.toml | 3 +- .../src/components/rich_text/rich_text.wgsl | 18 +++-- sugarloaf/src/context/mod.rs | 8 +- 4 files changed, 75 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a0469c5fd3..372449d671 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -137,6 +137,15 @@ dependencies = [ "num-traits", ] +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" +dependencies = [ + "derive_arbitrary", +] + [[package]] name = "arrayref" version = "0.3.9" @@ -372,7 +381,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" dependencies = [ "ciborium-io", - "half", + "half 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -807,9 +816,8 @@ checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991" [[package]] name = "d3d12" -version = "22.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdbd1f579714e3c809ebd822c81ef148b1ceaeb3d535352afc73fd0c4c6a0017" +version = "0.20.0" +source = "git+https://github.com/raphamorim/wgpu-simd#eebedb10a357fcaffab3ffb40416623efa3d2bd7" dependencies = [ "bitflags 2.6.0", "libloading", @@ -825,6 +833,17 @@ dependencies = [ "adler32", ] +[[package]] +name = "derive_arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] + [[package]] name = "dirs" version = "5.0.1" @@ -944,7 +963,7 @@ checksum = "887d93f60543e9a9362ef8a21beedd0a833c5d9610e18c67abe15a5963dcb1a4" dependencies = [ "bit_field", "flume", - "half", + "half 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "lebe", "miniz_oxide 0.7.4", "rayon-core", @@ -1335,6 +1354,17 @@ dependencies = [ "crunchy", ] +[[package]] +name = "half" +version = "2.4.1" +source = "git+https://github.com/FL33TW00D/half-rs.git?branch=feature/arbitrary#6bc4bea632269b53ccb6666a8508edc25fba9f3e" +dependencies = [ + "arbitrary", + "cfg-if 1.0.0", + "crunchy", + "num-traits", +] + [[package]] name = "hashbrown" version = "0.14.5" @@ -1599,6 +1629,12 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + [[package]] name = "libredox" version = "0.0.2" @@ -1708,9 +1744,9 @@ dependencies = [ [[package]] name = "metal" -version = "0.29.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ecfd3296f8c56b7c1f6fbac3c71cefa9d78ce009850c45000015f206dc7fa21" +checksum = "5637e166ea14be6063a3f8ba5ccb9a4159df7d8f6d61c02fc3d480b1f90dcfcb" dependencies = [ "bitflags 2.6.0", "block", @@ -1782,19 +1818,20 @@ dependencies = [ [[package]] name = "naga" -version = "22.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bd5a652b6faf21496f2cfd88fc49989c8db0825d1f6746b1a71a6ede24a63ad" +version = "0.20.0" +source = "git+https://github.com/raphamorim/wgpu-simd#eebedb10a357fcaffab3ffb40416623efa3d2bd7" dependencies = [ "arrayvec", "bit-set", "bitflags 2.6.0", - "cfg_aliases 0.1.1", "codespan-reporting", + "half 2.4.1 (git+https://github.com/FL33TW00D/half-rs.git?branch=feature/arbitrary)", "hexf-parse", "indexmap", "log 0.4.22", + "num-traits", "rustc-hash 1.1.0", + "smallvec", "spirv", "termcolor", "thiserror", @@ -1857,6 +1894,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -3536,9 +3574,8 @@ checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" [[package]] name = "wgpu" -version = "22.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d1c4ba43f80542cf63a0a6ed3134629ae73e8ab51e4b765a67f3aa062eb433" +version = "0.20.0" +source = "git+https://github.com/raphamorim/wgpu-simd#eebedb10a357fcaffab3ffb40416623efa3d2bd7" dependencies = [ "arrayvec", "cfg_aliases 0.1.1", @@ -3561,9 +3598,8 @@ dependencies = [ [[package]] name = "wgpu-core" -version = "22.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0348c840d1051b8e86c3bcd31206080c5e71e5933dabd79be1ce732b0b2f089a" +version = "0.20.0" +source = "git+https://github.com/raphamorim/wgpu-simd#eebedb10a357fcaffab3ffb40416623efa3d2bd7" dependencies = [ "arrayvec", "bit-vec", @@ -3586,9 +3622,8 @@ dependencies = [ [[package]] name = "wgpu-hal" -version = "22.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6bbf4b4de8b2a83c0401d9e5ae0080a2792055f25859a02bf9be97952bbed4f" +version = "0.20.0" +source = "git+https://github.com/raphamorim/wgpu-simd#eebedb10a357fcaffab3ffb40416623efa3d2bd7" dependencies = [ "android_system_properties", "arrayvec", @@ -3631,9 +3666,8 @@ dependencies = [ [[package]] name = "wgpu-types" -version = "22.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc9d91f0e2c4b51434dfa6db77846f2793149d8e73f800fa2e41f52b8eac3c5d" +version = "0.20.0" +source = "git+https://github.com/raphamorim/wgpu-simd#eebedb10a357fcaffab3ffb40416623efa3d2bd7" dependencies = [ "bitflags 2.6.0", "js-sys", diff --git a/Cargo.toml b/Cargo.toml index 28d61f5a38..7c69c1b0d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,7 +50,8 @@ regex = "1.10.6" bytemuck = { version = "1.17.0", features = [ "derive" ] } swash = "0.1.18" serde = { version = "1.0.208", features = ["derive"] } -wgpu = "22.1.0" +wgpu = { git = "https://github.com/raphamorim/wgpu-simd" } +# 22.1.0" libc = "0.2.158" smol_str = "0.3.1" futures = "0.3.30" diff --git a/sugarloaf/src/components/rich_text/rich_text.wgsl b/sugarloaf/src/components/rich_text/rich_text.wgsl index c06f07dccf..aa0a4439b2 100644 --- a/sugarloaf/src/components/rich_text/rich_text.wgsl +++ b/sugarloaf/src/components/rich_text/rich_text.wgsl @@ -1,3 +1,5 @@ +enable f16; + struct Globals { transform: mat4x4, } @@ -8,16 +10,16 @@ struct Globals { struct VertexInput { @builtin(vertex_index) vertex_index: u32, - @location(0) v_pos: vec4, - @location(1) v_color: vec4, - @location(2) v_uv: vec2, + @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, + @builtin(position) position: vec4, + @location(0) f_color: vec4, + @location(1) f_uv: vec2, @location(2) color_layer: i32, @location(3) mask_layer: i32, } @@ -36,14 +38,14 @@ fn vs_main(input: VertexInput) -> VertexOutput { @fragment fn fs_main(input: VertexOutput) -> @location(0) vec4 { - var out: vec4 = input.f_color; + 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); + out = vec4(out.xyz, textureSampleLevel(font_texture, font_sampler, input.f_uv, 0.0).x); } return out; diff --git a/sugarloaf/src/context/mod.rs b/sugarloaf/src/context/mod.rs index a15c4251b3..fc3476a27e 100644 --- a/sugarloaf/src/context/mod.rs +++ b/sugarloaf/src/context/mod.rs @@ -112,14 +112,18 @@ impl Context<'_> { let (device, queue) = { { if let Ok(result) = futures::executor::block_on( - adapter.request_device(&wgpu::DeviceDescriptor::default(), None), + adapter.request_device(&wgpu::DeviceDescriptor { + label: None, + required_features: wgpu::Features::SHADER_F16, + required_limits: wgpu::Limits::downlevel_defaults(), + }, None), ) { result } else { // These downlevel limits will allow the code to run on all possible hardware futures::executor::block_on(adapter.request_device( &wgpu::DeviceDescriptor { - memory_hints: wgpu::MemoryHints::Performance, + // memory_hints: wgpu::MemoryHints::Performance, label: None, required_features: wgpu::Features::empty(), required_limits: wgpu::Limits::downlevel_webgl2_defaults(),