Skip to content

Commit

Permalink
f16 wip
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Oct 3, 2024
1 parent ee5d956 commit 1fef232
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 34 deletions.
80 changes: 57 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 10 additions & 8 deletions sugarloaf/src/components/rich_text/rich_text.wgsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enable f16;

struct Globals {
transform: mat4x4<f32>,
}
Expand All @@ -8,16 +10,16 @@ struct Globals {

struct VertexInput {
@builtin(vertex_index) vertex_index: u32,
@location(0) v_pos: vec4<f32>,
@location(1) v_color: vec4<f32>,
@location(2) v_uv: vec2<f32>,
@location(0) v_pos: vec4<f16>,
@location(1) v_color: vec4<f16>,
@location(2) v_uv: vec2<f16>,
@location(3) layers: vec2<i32>,
}

struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(0) f_color: vec4<f32>,
@location(1) f_uv: vec2<f32>,
@builtin(position) position: vec4<f16>,
@location(0) f_color: vec4<f16>,
@location(1) f_uv: vec2<f16>,
@location(2) color_layer: i32,
@location(3) mask_layer: i32,
}
Expand All @@ -36,14 +38,14 @@ fn vs_main(input: VertexInput) -> VertexOutput {

@fragment
fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
var out: vec4<f32> = input.f_color;
var out: vec4<f16> = 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<f32>(out.xyz, textureSampleLevel(font_texture, font_sampler, input.f_uv, 0.0).x);
out = vec4<f16>(out.xyz, textureSampleLevel(font_texture, font_sampler, input.f_uv, 0.0).x);
}

return out;
Expand Down
8 changes: 6 additions & 2 deletions sugarloaf/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 1fef232

Please sign in to comment.