-
Notifications
You must be signed in to change notification settings - Fork 245
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 floating-point pack/unpack proposal #6191
Open
fairywreath
wants to merge
8
commits into
shader-slang:master
Choose a base branch
from
fairywreath:float-packed-proposal
base: master
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.
Open
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9bec1a8
add initial proposal
fairywreath 366020d
update proposal
fairywreath cb5c207
update proposal
fairywreath 7e42b3e
update proposal
fairywreath 1b59fd8
update proposal
fairywreath 1cc2159
Merge branch 'master' into float-packed-proposal
fairywreath b28a5a6
fix typo
fairywreath d2ad934
improve wording
fairywreath 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
83 changes: 83 additions & 0 deletions
83
docs/proposals/018-floating-point-packed-data-intrinsics.md
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
SP #018: Add floating-point pack/unpack intrinsics | ||
================= | ||
|
||
Adds intrinsics for converting vector floating-point data to and from packed unsigned integer values. | ||
|
||
## Status | ||
|
||
Status: Design Review. | ||
|
||
Implementation: N/A | ||
|
||
Author: Darren Wihandi and Slang community | ||
|
||
Reviewer: | ||
|
||
## Background | ||
|
||
Floating-point pack and unpack functions provide great utility and exist as built-in intrinsics on GLSL, SPIRV, Metal and WGSL but not on HLSL. | ||
Since Slang's core mudle is derived from HLSL, floating-point pack/unpack intrinsics are not defined and there is no way to access the intrinsics | ||
provided by the other shader language targets. | ||
|
||
## Proposed Approach | ||
|
||
Slang's core module, which derives from HLSL, already defines integer pack/unpack intrinsics which were introduced in SM 6.6. Some examples are | ||
``` | ||
uint32_t4 unpack_u8u32(uint8_t4_packed packedVal); | ||
uint8_t4_packed pack_u8(uint32_t4 unpackedVal); | ||
``` | ||
|
||
We propose to add more intrinsics, with similar syntax, to cover floating-points. Different variants exist to cover conversion between unorm, snorm, and | ||
unormalized/standard IEEE 754 floats and vectors of 16-bit and 32-bit floats. | ||
|
||
A set of unpack intrinsics are added to decompose a 32-bit integer of packed 8-bit or 16-bit float chunks and reinterprets them | ||
as a vector of unorm, snorm or standard floats and halfs. Each 8-bit or 16-bit chunk is converted to either a normalized float | ||
through a conversion rule or to a standard IEEE-754 floating-point. | ||
``` | ||
float4 unpack_unorm_f8f32(uint packedVal); | ||
half4 unpack_unorm_f8f16(uint packedVal); | ||
|
||
float4 unpack_snorm_f8f32(uint packedVal); | ||
half4 unpack_snorm_f8f16(uint packedVal); | ||
|
||
float2 unpack_unorm_f16f32(uint packedVal); | ||
half2 unpack_unorm_f16f16(uint packedVal); | ||
|
||
float2 unpack_snorm_f16f32(uint packedVal); | ||
half2 unpack_snorm_f16f16(uint packedVal); | ||
|
||
float2 unpack_half_f16f32(uint packedVal); | ||
half4 unpack_half_f16f16(uint packedVal); | ||
``` | ||
|
||
A set of pack intrinsics are added to pack a vector of unorm, snorm or standard floats and halfs to a 32-bit integer of packed 8-bit or 16-bit float chunks. | ||
Each vector element is converted to an 8-bit or 16-bit integer chunk through conversion rules, then packed into one 32-bit integer value. | ||
``` | ||
uint pack_unorm_f8(float4 unpackedVal); | ||
uint pack_unorm_f8(half4 unpackedVal); | ||
|
||
uint pack_snorm_f8(float4 unpackedVal); | ||
uint pack_snorm_f8(half4 unpackedVal); | ||
|
||
uint pack_unorm_f16(float2 unpackedVal); | ||
uint pack_unorm_f16(half2 unpackedVal); | ||
|
||
uint pack_snorm_f16(float2 unpackedVal); | ||
uint pack_snorm_f16(half2 unpackedVal); | ||
|
||
uint pack_half_f16(float2 unpackedVal); | ||
uint pack_half_f16(half2 unpackedVal); | ||
``` | ||
|
||
### Normalized float conversion rules | ||
Normalized float conversion rules are standard across GLSL/SPIRV, Metal and WGSL. Slang follows these standards. Details of the conversion rules for each target can be found in: | ||
- Section 8.4, `Floating-Point Pack and Unpack Functions`, of the GLSL language specification, which is also used by the SPIR-V extended instrucsion for GLSL. | ||
- Section 7.7.1, `Conversion Rules for Normalized Integer Pixel Data Types`, of the Metal Shading language specification. | ||
- Sections [16.9 Data Packing Built-in Functions](https://www.w3.org/TR/WGSL/#pack-builtin-functions) and [16.10 Data Unpacking Built-in Functions](https://www.w3.org/TR/WGSL/#unpack-builtin-functions) of the WebGPU Shading language specification. | ||
|
||
### Built-in packed Datatypes | ||
Unlike HLSL's implementation with introduces new packed datatypes, `uint8_t4_packed` and `int8_t4_packed`, unsigned 32-bit integers are used directly | ||
and no new pakced datatypes are introduced. | ||
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. I don't have a strong preference here and would really appreciate any suggestions or input. If new datatypes are to be introduced we would add something like |
||
|
||
### Targets without built-in intrinsics | ||
For targets without built-in intrinsics, the implementation is done manually through code with a combination of arithmetic and bitwise operations. |
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.
should be half2 here. this should be exactly the same as
bitcast<half2>
, right?