Skip to content

Fix shaderf16 support on vulkan/nvidia #7656

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

Closed
wants to merge 2 commits into from

Conversation

cryvosh
Copy link
Contributor

@cryvosh cryvosh commented May 1, 2025

Connections
N/A

Description
On my Laptop 4090, vulkaninfo reports:

VkPhysicalDeviceVulkan11Features:
---------------------------------
storageBuffer16BitAccess = true
uniformAndStorageBuffer16BitAccess = true
storagePushConstant16 = true
storageInputOutput16 = false

However the wgpu vulkan backend requires all four to be true for the SHADER_F16 feature to be supported.
This doesn't seem necessary, and as far as I can tell, storage_input_output16 isn't even read anywhere in wgpu.

This is also how dawn handles f16 support checking here.

Testing
My personal project using f16s (developed in chrome wasm which doesn't have this issue) was tested and works fine on Windows 11 native, Vulkan Backend.

Squash or Rebase?
Squash

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

@cryvosh cryvosh requested a review from a team as a code owner May 1, 2025 21:09
@cryvosh cryvosh marked this pull request as draft May 2, 2025 04:45
@cryvosh cryvosh marked this pull request as ready for review May 2, 2025 04:46
@sagudev
Copy link
Collaborator

sagudev commented May 2, 2025

storage_input_output16 is somehow implicitly used here:

.insert(spirv::Capability::StorageInputOutput16);

As for Dawn https://issues.chromium.org/issues/42251212:

Tint can now polyfill f16 shader IO by using f32 types, so we can
enable the F16 feature on Vulkan without this capability.

I think naga also does pollyfill somewhere.

@cryvosh cryvosh marked this pull request as draft May 3, 2025 10:15
@cryvosh
Copy link
Contributor Author

cryvosh commented May 3, 2025

Any idea where would be the best place to add the polyfill?

@LegNeato
Copy link
Contributor

Related: #7468

@tychedelia
Copy link
Collaborator

This fixes an issue I had when trying to profile code using f16 in Nsight.

@JMS55
Copy link
Collaborator

JMS55 commented Jul 1, 2025

@cryvosh can we take this PR out of draft, and leave pollyfilling to a followup?

@teoxoy
Copy link
Member

teoxoy commented Jul 1, 2025

All of the Vulkan features are required for the f16 feature. Dawn gets away with not requiring storageInputOutput16 since they polyfill the functionality, naga doesn't currently have this polyfill.

@teoxoy
Copy link
Member

teoxoy commented Jul 1, 2025

Landing this PR as is would make the functionality of the SHADER_F16 feature non-portable. If we want to not require storageInputOutput16 we can do so under a new feature SHADER_F16_WO_IO until naga can do the polyfill.

@cwfitzgerald
Copy link
Member

CI seems to correctly catch this as a vulkan validation error.

@cwfitzgerald
Copy link
Member

As this isn't actually allowed, I'm going to close this PR - we would accept a followup which adds the polyfill using f32.

@cryvosh
Copy link
Contributor Author

cryvosh commented Jul 1, 2025

For future reference, what's not allowed?

@cwfitzgerald
Copy link
Member

Basically, if you use f16 as part of the input or output of a shader (like Vertex input or Fragment shader input) you need the input/output capability. However you can polyfill it by using f32, we just have not implemented this.

@cryvosh
Copy link
Contributor Author

cryvosh commented Jul 1, 2025

Oh gotcha, I thought you meant I broke some rule

I'll look into adding the polyfill and open new PR when I get the chance

(in meantime any suggestions on where / at what stage in the pipeline to add this would be appreciated)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants