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

Store floats as bits #237

Merged
merged 1 commit into from
Oct 6, 2022
Merged

Store floats as bits #237

merged 1 commit into from
Oct 6, 2022

Conversation

wackbyte
Copy link
Contributor

@wackbyte wackbyte commented Oct 3, 2022

Closes #16, should help with #189

Copy link
Collaborator

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

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

Thanks! Can we possibly solve all the clippy lints for the base repo in a separate PR to make this one a bit easier to read?

/// Appends an OpConstant instruction with the given 32-bit integer `value`.
/// or the module if no block is under construction.
pub fn constant_u32(&mut self, result_type: spirv::Word, value: u32) -> spirv::Word {
pub fn constant_int32(&mut self, result_type: spirv::Word, value: u32) -> spirv::Word {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpicking: could we also name these constant_32bit and constant_64bit? Same for the other types, so that it's a bit more clear that it's a generic "array of bytes" rather than a (float interpreted as) integer.

That also matches the updated doc-comment on this function (and we could have a similar doc-comment on the dr::Operand enum variant).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Decided to go with bit32 and bit64 instead to avoid any names starting with numbers.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks! I didn't expect it to be such an intrusive change, but worth it IMO. Will now have to wait for a maintainer to say the same :)

@wackbyte
Copy link
Contributor Author

wackbyte commented Oct 4, 2022

I removed the clippy commit 👍

@wackbyte wackbyte force-pushed the no-more-float branch 2 times, most recently from 8d9475e to 4a66893 Compare October 4, 2022 04:29
@wackbyte
Copy link
Contributor Author

wackbyte commented Oct 4, 2022

Sorry about that, just had some trouble with git while trying to rebase.

@@ -197,10 +197,10 @@ fn disas_constant(inst: &dr::Instruction, type_tracker: &tracker::TypeTracker) -
debug_assert_eq!(inst.operands.len(), 1);
let literal_type = type_tracker.resolve(inst.result_type.unwrap());
match inst.operands[0] {
LiteralInt32(value) => disas_instruction(inst, " ", |_| {
Copy link
Contributor

Choose a reason for hiding this comment

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

the operand won't be disassembled correctly in case of a floating point literal type due to the underlying disas_literal_int code which does some type checking. Should be extended to support Float types as well otherwise we print an empty string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, my mistake. nice catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm, i looked into it and it looks like this might require something similar to this module in spirv-tools in order to properly deal with NaNs, infinity, 16-bit floats, etc. i think this is outside the scope of this PR, though, so I left a TODO comment and decided to just rely on the Display impls of f32 and f64 to handle most usages, as i believe this is what the behavior was before anyway.

@wackbyte
Copy link
Contributor Author

wackbyte commented Oct 5, 2022

Okay, finally rebased properly.

Copy link
Contributor

@msiglreith msiglreith left a comment

Choose a reason for hiding this comment

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

lgtm, thanks for adding a testcase for the float disassembling!
clippy nags about the chosen 3.14 constants tho :)

@wackbyte
Copy link
Contributor Author

wackbyte commented Oct 5, 2022

Alright, changed it to something else

@msiglreith msiglreith merged commit c7305b8 into gfx-rs:master Oct 6, 2022
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.

Instruction: Derive Eq and Hash
3 participants