-
Notifications
You must be signed in to change notification settings - Fork 943
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
Add 1-component ({s,u}{int,norm}{8,16}
, float16
) and unorm8x4-bgra
vertex formats
#6632
Open
nolanderc
wants to merge
5
commits into
gfx-rs:trunk
Choose a base branch
from
nolanderc:vertex-format-1-component
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.
+439
−78
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f12a208
feat: add missing 8/16-bit vertex formats (and 8-bit bgra) #6614
nolanderc 0a953a7
add tests for 1-component vertex formats (and bgra)
nolanderc 14ea484
metal: unpacking function for 1-component vertex formats
nolanderc 0ef0529
test: use proper alignment for float16 vertex format
nolanderc 5b1e5d7
changelog: new vertex formats
nolanderc 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 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 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 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 |
---|---|---|
|
@@ -4010,6 +4010,13 @@ template <typename A> | |
) -> Result<(String, u32, u32), Error> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: @gfx-rs/naga: Why do we not re-use the output of |
||
use back::msl::VertexFormat::*; | ||
match format { | ||
Uint8 => { | ||
let name = self.namer.call("unpackUint8"); | ||
writeln!(self.out, "uint {name}(metal::uchar b0) {{")?; | ||
writeln!(self.out, "{}return uint(b0);", back::INDENT)?; | ||
writeln!(self.out, "}}")?; | ||
Ok((name, 1, 1)) | ||
} | ||
Uint8x2 => { | ||
let name = self.namer.call("unpackUint8x2"); | ||
writeln!( | ||
|
@@ -4038,6 +4045,13 @@ template <typename A> | |
writeln!(self.out, "}}")?; | ||
Ok((name, 4, 4)) | ||
} | ||
Sint8 => { | ||
let name = self.namer.call("unpackSint8"); | ||
writeln!(self.out, "int {name}(metal::uchar b0) {{")?; | ||
writeln!(self.out, "{}return int(as_type<char>(b0));", back::INDENT)?; | ||
writeln!(self.out, "}}")?; | ||
Ok((name, 1, 1)) | ||
} | ||
Sint8x2 => { | ||
let name = self.namer.call("unpackSint8x2"); | ||
writeln!( | ||
|
@@ -4074,6 +4088,17 @@ template <typename A> | |
writeln!(self.out, "}}")?; | ||
Ok((name, 4, 4)) | ||
} | ||
Unorm8 => { | ||
let name = self.namer.call("unpackUnorm8"); | ||
writeln!(self.out, "float {name}(metal::uchar b0) {{")?; | ||
writeln!( | ||
self.out, | ||
"{}return float(float(b0) / 255.0f);", | ||
back::INDENT | ||
)?; | ||
writeln!(self.out, "}}")?; | ||
Ok((name, 1, 1)) | ||
} | ||
Unorm8x2 => { | ||
let name = self.namer.call("unpackUnorm8x2"); | ||
writeln!( | ||
|
@@ -4110,6 +4135,17 @@ template <typename A> | |
writeln!(self.out, "}}")?; | ||
Ok((name, 4, 4)) | ||
} | ||
Snorm8 => { | ||
let name = self.namer.call("unpackSnorm8"); | ||
writeln!(self.out, "float {name}(metal::uchar b0) {{")?; | ||
writeln!( | ||
self.out, | ||
"{}return float(metal::max(-1.0f, as_type<char>(b0) / 127.0f));", | ||
back::INDENT | ||
)?; | ||
writeln!(self.out, "}}")?; | ||
Ok((name, 1, 1)) | ||
} | ||
Snorm8x2 => { | ||
let name = self.namer.call("unpackSnorm8x2"); | ||
writeln!( | ||
|
@@ -4146,6 +4182,21 @@ template <typename A> | |
writeln!(self.out, "}}")?; | ||
Ok((name, 4, 4)) | ||
} | ||
Uint16 => { | ||
let name = self.namer.call("unpackUint16"); | ||
writeln!( | ||
self.out, | ||
"metal::uint {name}(metal::uint b0, \ | ||
metal::uint b1) {{" | ||
)?; | ||
writeln!( | ||
self.out, | ||
"{}return metal::uint(b1 << 8 | b0);", | ||
back::INDENT | ||
)?; | ||
writeln!(self.out, "}}")?; | ||
Ok((name, 2, 1)) | ||
} | ||
Uint16x2 => { | ||
let name = self.namer.call("unpackUint16x2"); | ||
writeln!( | ||
|
@@ -4188,6 +4239,21 @@ template <typename A> | |
writeln!(self.out, "}}")?; | ||
Ok((name, 8, 4)) | ||
} | ||
Sint16 => { | ||
let name = self.namer.call("unpackSint16"); | ||
writeln!( | ||
self.out, | ||
"int {name}(metal::ushort b0, \ | ||
metal::ushort b1) {{" | ||
)?; | ||
writeln!( | ||
self.out, | ||
"{}return int(as_type<short>(metal::ushort(b1 << 8 | b0)));", | ||
back::INDENT | ||
)?; | ||
writeln!(self.out, "}}")?; | ||
Ok((name, 2, 1)) | ||
} | ||
Sint16x2 => { | ||
let name = self.namer.call("unpackSint16x2"); | ||
writeln!( | ||
|
@@ -4230,6 +4296,21 @@ template <typename A> | |
writeln!(self.out, "}}")?; | ||
Ok((name, 8, 4)) | ||
} | ||
Unorm16 => { | ||
let name = self.namer.call("unpackUnorm16"); | ||
writeln!( | ||
self.out, | ||
"float {name}(metal::ushort b0, \ | ||
metal::ushort b1) {{" | ||
)?; | ||
writeln!( | ||
self.out, | ||
"{}return float(float(b1 << 8 | b0) / 65535.0f);", | ||
back::INDENT | ||
)?; | ||
writeln!(self.out, "}}")?; | ||
Ok((name, 2, 1)) | ||
} | ||
Unorm16x2 => { | ||
let name = self.namer.call("unpackUnorm16x2"); | ||
writeln!( | ||
|
@@ -4272,6 +4353,21 @@ template <typename A> | |
writeln!(self.out, "}}")?; | ||
Ok((name, 8, 4)) | ||
} | ||
Snorm16 => { | ||
let name = self.namer.call("unpackSnorm16"); | ||
writeln!( | ||
self.out, | ||
"float {name}(metal::ushort b0, \ | ||
metal::ushort b1) {{" | ||
)?; | ||
writeln!( | ||
self.out, | ||
"{}return metal::unpack_snorm2x16_to_float(b1 << 8 | b0).x;", | ||
back::INDENT | ||
)?; | ||
writeln!(self.out, "}}")?; | ||
Ok((name, 2, 1)) | ||
} | ||
Snorm16x2 => { | ||
let name = self.namer.call("unpackSnorm16x2"); | ||
writeln!( | ||
|
@@ -4311,6 +4407,21 @@ template <typename A> | |
writeln!(self.out, "}}")?; | ||
Ok((name, 8, 4)) | ||
} | ||
Float16 => { | ||
let name = self.namer.call("unpackFloat16"); | ||
writeln!( | ||
self.out, | ||
"float {name}(metal::ushort b0, \ | ||
metal::ushort b1) {{" | ||
)?; | ||
writeln!( | ||
self.out, | ||
"{}return float(as_type<half>(metal::ushort(b1 << 8 | b0)));", | ||
back::INDENT | ||
)?; | ||
writeln!(self.out, "}}")?; | ||
Ok((name, 2, 1)) | ||
} | ||
Float16x2 => { | ||
let name = self.namer.call("unpackFloat16x2"); | ||
writeln!( | ||
|
@@ -4675,6 +4786,26 @@ template <typename A> | |
writeln!(self.out, "}}")?; | ||
Ok((name, 4, 4)) | ||
} | ||
Unorm8x4Bgra => { | ||
let name = self.namer.call("unpackUnorm8x4Bgra"); | ||
writeln!( | ||
self.out, | ||
"metal::float4 {name}(metal::uchar b0, \ | ||
metal::uchar b1, \ | ||
metal::uchar b2, \ | ||
metal::uchar b3) {{" | ||
)?; | ||
writeln!( | ||
self.out, | ||
"{}return metal::float4(float(b2) / 255.0f, \ | ||
float(b1) / 255.0f, \ | ||
float(b0) / 255.0f, \ | ||
float(b3) / 255.0f);", | ||
back::INDENT | ||
)?; | ||
writeln!(self.out, "}}")?; | ||
Ok((name, 4, 4)) | ||
} | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
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: @gfx-rs/naga: This code has a 5-slot gap for texture indices here. Is there a reason that this gap should continue to exist, given these changes?
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.
I noticed the gap in the previous code corresponded to the missing Float64 formats. I suppose having the enum discriminant values be a 1:1 mapping between those in wpgu_types and msl could be yield more efficient conversions between the two, or similar, so I just left it as is.