Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement F16 support in shaders #5701

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

FL33TW00D
Copy link
Contributor

@FL33TW00D FL33TW00D commented May 13, 2024

Connections

Checklist for merge-ability

Additional context

F16 is available in >=SM6.2: https://github.com/microsoft/DirectXShaderCompiler/wiki/16-Bit-Scalar-Types

@FL33TW00D FL33TW00D mentioned this pull request May 14, 2024
@FL33TW00D FL33TW00D changed the title feature: Parse enable directives feature: Parse enable directives & SHADER-F16 support May 14, 2024
@FL33TW00D FL33TW00D marked this pull request as ready for review May 15, 2024 21:19
@FL33TW00D FL33TW00D requested a review from a team May 15, 2024 21:19
@FL33TW00D FL33TW00D requested a review from a team as a code owner May 15, 2024 21:19
@FL33TW00D
Copy link
Contributor Author

I've marked this as ready for review, as the wgpu specific logic is implemented and would be great to start iterating on it.

2 main blockers are:

  1. Merging of the PR on half-rs.
  2. hexf-parse improved implementation.

@FL33TW00D
Copy link
Contributor Author

FL33TW00D commented May 20, 2024

Dogfooding works! Fixed a few bugs in 30e12b5. Still waiting on upstream.

naga/src/proc/constant_evaluator.rs Outdated Show resolved Hide resolved
naga/src/proc/constant_evaluator.rs Outdated Show resolved Hide resolved
naga/src/proc/constant_evaluator.rs Outdated Show resolved Hide resolved
naga/src/proc/constant_evaluator.rs Outdated Show resolved Hide resolved
naga/src/proc/constant_evaluator.rs Outdated Show resolved Hide resolved
naga/src/front/wgsl/parse/lexer.rs Outdated Show resolved Hide resolved
naga/src/front/wgsl/parse/ast.rs Outdated Show resolved Hide resolved
naga/src/back/msl/writer.rs Outdated Show resolved Hide resolved
naga/src/back/msl/writer.rs Outdated Show resolved Hide resolved
naga/src/back/spv/writer.rs Show resolved Hide resolved
@teoxoy

This comment was marked as resolved.

@FL33TW00D

This comment was marked as resolved.

@teoxoy
Copy link
Member

teoxoy commented Jun 13, 2024

One thing I'm concerned is that the polyfills we have in some of the backends might not support f16. It would be worth adding more tests covering the built-in functions and operations that support f16. Execution tests would be great as well, they live in tests/tests/shader.

@teoxoy

This comment was marked as resolved.

@teoxoy teoxoy self-assigned this Jun 13, 2024
@FL33TW00D FL33TW00D force-pushed the feature/enable branch 2 times, most recently from 9c6a9b3 to 9f33e0e Compare June 14, 2024 14:20
@ErichDonGubler

This comment was marked as outdated.

@ErichDonGubler ErichDonGubler added type: enhancement New feature or request backend: webgpu Issues with direct interface with WebGPU labels Jun 14, 2024
Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make sure that we are properly validating As casts of matrices, because that code currently assumes that all matrices have the same kind (#6441).

@raphamorim
Copy link

Super awesome work folks, really appreciate it!! 👏 <3
@FL33TW00D please lemme know if I can help in anything 🙏

@wpmed92
Copy link

wpmed92 commented Dec 9, 2024

Is there an ETA for this to ship? We'd like to support f16 in tinygrad, we love wgpu, but are considering switching to dawn if it's not expected to ship in the near future.

@raphamorim
Copy link

Is there an ETA for this to ship? We'd like to support f16 in tinygrad, we love wgpu, but are considering switching to dawn if it's not expected to ship in the near future.

same, i love wgpu and use on rio terminal. Please lemme know if I can help any way to ship this feature. Maybe can split some work

@FL33TW00D
Copy link
Contributor Author

FL33TW00D commented Dec 9, 2024

@wpmed92 @raphamorim

If either of you are using Vulkan or Windows backend, feel free to start testing support for F16 using this branch.

I use the Metal backend, implemented enough support so that all my own tests pass.

@raphamorim
Copy link

Sounds good @FL33TW00D , i actually started testing this branch in Rio already.

Regarding starkat99/half-rs#111 I have been thinking in publish a fork to crates io and maintain until your PR get merged

@raphamorim
Copy link

Done: https://crates.io/crates/half-2
Hope unblock the CI issue for now, once your PR is merged then need to move back to half

@raphamorim
Copy link

@FL33TW00D created a PR raphamorim/rio#875 but having trouble with naga validation

    Finished `dev` profile [unoptimized + debuginfo] target(s) in 13.61s
     Running `target/debug/rio`
thread 'main' panicked at /Users/rapha/.cargo/git/checkouts/wgpu-48a004a2060e66f4/bfad205/wgpu/src/backend/wgpu_core.rs:3413:5:
wgpu error: Validation Error

Caused by:
  In Device::create_shader_module

Shader '' parsing error: expected global item ('struct', 'const', 'var', 'alias', ';', 'fn') or the end of the file, found 'enable'
  ┌─ wgsl:1:1
  │
1 │ enable f16;
  │ ^^^^^^ expected global item ('struct', 'const', 'var', 'alias', ';', 'fn') or the end of the file


      expected global item ('struct', 'const', 'var', 'alias', ';', 'fn') or the end of the file, found 'enable'

@FL33TW00D
Copy link
Contributor Author

@FL33TW00D created a PR raphamorim/rio#875 but having trouble with naga validation

    Finished `dev` profile [unoptimized + debuginfo] target(s) in 13.61s
     Running `target/debug/rio`
thread 'main' panicked at /Users/rapha/.cargo/git/checkouts/wgpu-48a004a2060e66f4/bfad205/wgpu/src/backend/wgpu_core.rs:3413:5:
wgpu error: Validation Error

Caused by:
  In Device::create_shader_module

Shader '' parsing error: expected global item ('struct', 'const', 'var', 'alias', ';', 'fn') or the end of the file, found 'enable'
  ┌─ wgsl:1:1
  │
1 │ enable f16;
  │ ^^^^^^ expected global item ('struct', 'const', 'var', 'alias', ';', 'fn') or the end of the file


      expected global item ('struct', 'const', 'var', 'alias', ';', 'fn') or the end of the file, found 'enable'

Just checked out 808db24 and ran:
RUST_LOG=shader_f16 cargo run --bin wgpu-examples shader-f16
It works correctly.

You forgot to specify the branch in the cargo git dep!

@raphamorim
Copy link

You forgot to specify the branch in the cargo git dep!

You are indeed correct, thank you!

@ErichDonGubler

This comment was marked as outdated.

@cwfitzgerald
Copy link
Member

Getting this over the line is on my list, will probably be next week.

@ErichDonGubler
Copy link
Member

I've resolved conflicts with the latest examples/ changes (I think, spot check me @cwfitzgerald), and added a fixup! that tentatively consumes @raphamorim's half-2 crate.

@cwfitzgerald cwfitzgerald force-pushed the feature/enable branch 2 times, most recently from 8192315 to d4909a2 Compare February 1, 2025 04:27
@cwfitzgerald
Copy link
Member

I have split the hex parsing task into a different work item to follow this. See #7046.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: cts Issues stemming from the WebGPU Conformance Test Suite area: naga back-end Outputs of naga shader conversion area: naga front-end area: naga processing Passes over IR in the middle backend: webgpu Issues with direct interface with WebGPU lang: WGSL WebGPU Shading Language naga Shader Translator type: enhancement New feature or request
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

[meta] f16 support WGSL: Support the enable directive
8 participants