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

feature: Parse enable directives & SHADER-F16 support #5701

Open
wants to merge 12 commits into
base: trunk
Choose a base branch
from

Conversation

FL33TW00D
Copy link
Contributor

@FL33TW00D FL33TW00D commented May 13, 2024

Resolves #5476.
Resolves #4384.

References:
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 review from a team as code owners 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 Show resolved Hide resolved
use std::hash::Hash;

#[derive(Debug, Default)]
pub struct TranslationUnit<'a> {
pub directives: Arena<GlobalDirective>,
Copy link
Member

Choose a reason for hiding this comment

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

We don't use this field at all, we might in the future but I think it will end up looking differently. Extensions and language extensions can be bitflags, and global diagnostic modifiers will have their own shapes.

I think we should either remove this field or replace it with an extensions bitflags.

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
Copy link
Member

teoxoy commented Jun 13, 2024

Could you squash all the existing commits into 1? It will make it easier to look at the PR once the feedback is addressed.

@FL33TW00D
Copy link
Contributor Author

FL33TW00D commented Jun 13, 2024

Could you squash all the existing commits into 1? It will make it easier to look at the PR once the feedback is addressed.

@teoxoy 100% - thanks for the review let me address and squash!

@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
Copy link
Member

teoxoy commented Jun 13, 2024

It would be best for review to squash first so that the commits addressing various parts are by themselves.

@ErichDonGubler
Copy link
Member

I have not reviewed this PR in-depth as @teoxoy has, but the broad strokes of the const. eval code look correct to me, FWIW. 🫡

@ErichDonGubler ErichDonGubler added type: enhancement New feature or request api: webgpu Issues with direct interface with WebGPU area: cts Issues stemming from the WebGPU Conformance Test Suite area: naga back-end Outputs of naga shader conversion naga Shader Translator area: naga front-end lang: WGSL WebGPU Shading Language area: naga processing Passes over IR in the middle labels Jun 14, 2024
self.capabilities_used
.insert(spirv::Capability::StorageBuffer16BitAccess);
self.capabilities_used
.insert(spirv::Capability::UniformAndStorageBuffer16BitAccess);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@teoxoy not actually sure about this now.
gpuweb/gpuweb#2512 (comment)
Seems some of these are optional. If you enable them all you lose most devices on Vulkan.

Copy link
Member

Choose a reason for hiding this comment

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

What ended up in the spec requires all of the Vulkan features. Some more context from the follow-up meetings:
gpuweb/gpuweb#2512 (comment)
gpuweb/gpuweb#2512 (comment)

@teoxoy
Copy link
Member

teoxoy commented Jun 27, 2024

@FL33TW00D please request a re-review once ready.

@FL33TW00D
Copy link
Contributor Author

@FL33TW00D please request a re-review once ready.

@teoxoy will do apologies this got deprioritised.

@teoxoy
Copy link
Member

teoxoy commented Jun 27, 2024

No worries, I just want to make sure to get back to it.

@tgross35
Copy link

tgross35 commented Jul 1, 2024

Would it be feasible, either here or in a followup, to support the builtin f16 as an alternative to half? It is still unstable so needs to be behind a feature gate, but it would be great to start working it into the ecosystem and help us find more bugs.

Bytemuck just needs its nightly_float feature enabled to support it.

@teoxoy
Copy link
Member

teoxoy commented Jul 2, 2024

The buffers are all just a bunch of bytes, so you can use whichever type you want then put it in the buffer. The usage of half is internal to naga.

@FL33TW00D
Copy link
Contributor Author

FL33TW00D commented Aug 1, 2024

Taking a look at this again @teoxoy on a rented EC2 machine to check Vulkan.
Seems like the NVDA Vulkan driver doesn't seem to allow F16 (which seems off):

HAS SHADER FLOAT16: Some((PhysicalDeviceShaderFloat16Int8Features { s_type: PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES, p_next: 0x7ffdc4f00a68, shader_float16: 1, shader_int8: 1, _marker: PhantomData<&()> }, PhysicalDevice16BitStorageFeatures { s_type: PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES, p_next: 0x7ffdc4f00af8, storage_buffer16_bit_access: 1, uniform_and_storage_buffer16_bit_access: 1, storage_push_constant16: 1, storage_input_output16: 0, _marker: PhantomData<&()> }))

This is because the storage_input_output16 is 0.

https://forums.developer.nvidia.com/t/nvidia-driver-should-enable-the-storageinputoutput16-feature/275835

Any ideas here? I'd expect a T4 to offer this?

EDIT:
wow turns out Turing didn't even support f16 and it isn't a bug.

Nvidia Turing-based hardware currently [reports support](https://vulkan.gpuinfo.org/displayreport.php?id=6907#extended) for shaderFloat16, shaderInt8, storageBuffer16BitAccess, uniformAndStorageBuffer16BitAccess, and storagePushConstant16, but not storageInputOutput16

@teoxoy
Copy link
Member

teoxoy commented Aug 9, 2024

It is possible to use FP16 in user-defined pipeline input/output variables. However some Vulkan devices, which support other usages in this extension like FP16 built-in function and storage buffer, don’t support this usage. For capabilities reasons, we may suggest not enabling using FP16 as pipeline input or output with this extension. However, this usage can also be emulated on Vulkan devices with no native support for this usage (storageInputOutput16).

from gpuweb/gpuweb#2512

I think we have to do the casting ourselves. Dawn also seems to do this. We can do it in a different PR though.

What I find interesting is that the proposal talked about SM6.2 & Native16BitShaderOpsSupported enabling support for f16 IO, I guess the Nvidia compiler that ingests DXIL will do the casting. It probably does the casting regardless of frontend and that's why people report this working on Vulkan as well despite storageInputOutput16 not being supported. While it's unlikely this will change we shouldn't rely on this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: webgpu Issues with direct interface with WebGPU 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 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.

naga: Support the enable directive [meta] f16 support
4 participants