-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[naga spv-out] Add f16 io polyfill #7884
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
Open
cryvosh
wants to merge
24
commits into
gfx-rs:trunk
Choose a base branch
from
cryvosh:fix_shader16_vulkan
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,121
−19
Open
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
1e59af1
Fix shaderf16 support on vulkan/nvidia
cryvosh 3e0ee6c
fmt
cryvosh 053bb09
Merge remote-tracking branch 'origin/trunk' into fix_shader16_vulkan
cryvosh 888c461
F16 polyfill
cryvosh 5694706
Cleanup
cryvosh 8592c29
Merge branch 'trunk' into fix_shader16_vulkan
cryvosh 1fc98ff
Rename file
cryvosh 5201714
fmt
cryvosh 44c88df
Changelog entry
cryvosh 2151560
[naga spv-out] Add f16 io polyfill
cryvosh e9d75c3
fixup! [naga spv-out] Add f16 io polyfill
ErichDonGubler a8cddd9
fixup! [naga spv-out] Add f16 io polyfill
ErichDonGubler affce18
Merge remote-tracking branch 'upstream/trunk' into fix_shader16_vulkan
cryvosh 8f2143e
Merge branch 'fix_shader16_vulkan' of https://github.com/cryvosh/wgpu…
cryvosh c5e2ad3
Fix merge oops
cryvosh 0389c1b
Feedback
cryvosh 7642b64
fmt
cryvosh 8f13d22
Cleanup
cryvosh 6efd4ba
Cleanup comments
cryvosh 7098938
Cleanup capability check
cryvosh c2eb34c
fmt
cryvosh bd259cd
Changelog
cryvosh e17112b
Changelog
cryvosh 520f987
Add test
cryvosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/*! | ||
This module provides functionality polyfills f16 input/output variables | ||
when the StorageInputOutput16 capability is not available or disabled. | ||
|
||
It works by: | ||
1. Declaring f16 I/O variables as f32 in SPIR-V | ||
2. Converting between f16 and f32 at runtime using OpFConvert | ||
3. Maintaining mappings to track which variables need conversion | ||
*/ | ||
|
||
use crate::back::spv::{Instruction, LocalType, NumericType, Word}; | ||
use alloc::vec::Vec; | ||
|
||
/// Manages f16 I/O polyfill state and operations. | ||
#[derive(Default)] | ||
pub(super) struct F16IoPolyfill { | ||
use_native: bool, | ||
variable_map: crate::FastHashMap<Word, (Word, Word)>, | ||
} | ||
|
||
impl F16IoPolyfill { | ||
pub fn new(use_storage_input_output_16: bool) -> Self { | ||
Self { | ||
use_native: use_storage_input_output_16, | ||
variable_map: crate::FastHashMap::default(), | ||
} | ||
} | ||
|
||
pub fn needs_polyfill(&self, ty_inner: &crate::TypeInner) -> bool { | ||
use crate::{ScalarKind as Sk, TypeInner}; | ||
|
||
!self.use_native | ||
&& match *ty_inner { | ||
TypeInner::Scalar(ref s) if s.kind == Sk::Float && s.width == 2 => true, | ||
TypeInner::Vector { scalar, .. } | ||
if scalar.kind == Sk::Float && scalar.width == 2 => | ||
{ | ||
true | ||
} | ||
_ => false, | ||
} | ||
} | ||
|
||
pub fn register_variable(&mut self, variable_id: Word, f32_type_id: Word, f16_type_id: Word) { | ||
self.variable_map | ||
.insert(variable_id, (f32_type_id, f16_type_id)); | ||
} | ||
|
||
pub fn get_polyfill_info(&self, variable_id: Word) -> Option<(Word, Word)> { | ||
self.variable_map.get(&variable_id).copied() | ||
} | ||
|
||
pub fn emit_f16_to_f32_conversion( | ||
f16_value_id: Word, | ||
f32_type_id: Word, | ||
converted_id: Word, | ||
body: &mut Vec<Instruction>, | ||
) { | ||
body.push(Instruction::unary( | ||
spirv::Op::FConvert, | ||
f32_type_id, | ||
converted_id, | ||
f16_value_id, | ||
)); | ||
} | ||
|
||
pub fn emit_f32_to_f16_conversion( | ||
f32_value_id: Word, | ||
f16_type_id: Word, | ||
converted_id: Word, | ||
body: &mut Vec<Instruction>, | ||
) { | ||
body.push(Instruction::unary( | ||
spirv::Op::FConvert, | ||
f16_type_id, | ||
converted_id, | ||
f32_value_id, | ||
)); | ||
} | ||
|
||
pub fn create_polyfill_type(ty_inner: &crate::TypeInner) -> Option<LocalType> { | ||
use crate::{ScalarKind as Sk, TypeInner}; | ||
|
||
match *ty_inner { | ||
TypeInner::Scalar(ref s) if s.kind == Sk::Float && s.width == 2 => { | ||
Some(LocalType::Numeric(NumericType::Scalar(crate::Scalar::F32))) | ||
} | ||
TypeInner::Vector { size, scalar } if scalar.kind == Sk::Float && scalar.width == 2 => { | ||
Some(LocalType::Numeric(NumericType::Vector { | ||
size, | ||
scalar: crate::Scalar::F32, | ||
})) | ||
} | ||
_ => None, | ||
} | ||
} | ||
} | ||
|
||
impl crate::back::spv::recyclable::Recyclable for F16IoPolyfill { | ||
fn recycle(mut self) -> Self { | ||
self.variable_map = self.variable_map.recycle(); | ||
self | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: I noticed that
f16_type_id
is never used when recalled viaget_polyfill_info
. Is this a bug, or just some data that can be eliminated?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I've cleaned up the redundant data