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

[hlsl-out] Insert padding between struct members #1786

Merged
merged 1 commit into from
Mar 21, 2022

Conversation

teoxoy
Copy link
Member

@teoxoy teoxoy commented Mar 20, 2022

fixes #1783

With this fix WGSL's align & size attributes and also spir-v's Offset decoration are respected since the offset in the IR is affected by those.

@teoxoy
Copy link
Member Author

teoxoy commented Mar 20, 2022

I noticed half is supported by the hlsl backend but the issue with using half as the padding type is that its size can be either 2 or 4 bytes. How should we deal with this?

@kvark
Copy link
Member

kvark commented Mar 20, 2022

but the issue with using half as the padding type is that its size can be either 2 or 4 bytes

Is that not defined in the spec? we shouldn't expose f16 (or half) until we figure out the details on how it maps to HLSL.
Note that fp16 extension has still not landed on WebGPU - gpuweb/gpuweb#2647

Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

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

Thank you for the PR!

src/back/hlsl/writer.rs Show resolved Hide resolved
@teoxoy
Copy link
Member Author

teoxoy commented Mar 20, 2022

half - 16-bit floating point value. This data type is provided only for language compatibility. Direct3D 10 shader targets map all half data types to float data types.

reference

DXC requires the -enable-16bit-types flag to be passed as described here in order for half to be a true 16bit type otherwise it's 32bit

Maybe a better way to do this would be to check if the struct contains a member with a half type and only then use half for padding since at this point it would be safe to assume that the half type is 16bit. Also the padding only needs to be as small as the smallest struct member.

What do you think?

@kvark
Copy link
Member

kvark commented Mar 21, 2022

@teoxoy sounds like a reasonable proposal!

@kvark kvark added the can backport PR that can be back-ported to a release branch label Mar 21, 2022
@kvark kvark merged commit 05f050f into gfx-rs:master Mar 21, 2022
@teoxoy
Copy link
Member Author

teoxoy commented Mar 21, 2022

Maybe a better way to do this would be to check if the struct contains a member with a half type and only then use half for padding since at this point it would be safe to assume that the half type is 16bit. Also the padding only needs to be as small as the smallest struct member.

sounds like a reasonable proposal!

so, should I open a new PR implementing that logic?

@kvark
Copy link
Member

kvark commented Mar 23, 2022

If you feel that the FP16 spec has issues with half, please open an issue. Suggesting or writing a PR with a solution is greatly appreciated, obviously!
I suspect we are the only ones detecting it because Google virtualized uniform buffers on DX12, so they aren't actually using half in them. So your worries are likely right.

@teoxoy teoxoy deleted the hlsl-out-insert-padding branch March 23, 2022 09:44
@teoxoy
Copy link
Member Author

teoxoy commented Mar 26, 2022

I looked into this some more and it looks like the WGSL FP16 extension will require generation of DXIL (comment, slide). So I guess when we start implementing the extension, we will just fail if we try to target the HLSL backend when the extension is required.

@kvark
Copy link
Member

kvark commented Mar 27, 2022

we'll just not expose it on DX12 until we are able to generate DXIL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can backport PR that can be back-ported to a release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[hlsl-out] account for "vector-relaxed" std140 layout for constant buffers
2 participants