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

[OPT] Zero-extend unsigned 16-bit integers when bitcasting #5590

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cassiebeckley
Copy link
Contributor

The folding rule BitCastScalarOrVector was incorrectly handling bitcasting to unsigned 16-bit integers. It was simply copying the entire 32-bit word containing the 16-bit integer. This conflicts with the requirement in section 2.2.1 of the SPIR-V spec which states that unsigned numeric types with a bit width less than 32-bits must have the high-order bits set to 0.

Fixes microsoft/DirectXShaderCompiler#6319.

The folding rule `BitCastScalarOrVector` was incorrectly handling
bitcasting to unsigned 16-bit integers. It was simply copying the entire
32-bit word containing the 16-bit integer. This conflicts with the
requirement in section 2.2.1 of the SPIR-V spec which states that
unsigned numeric types with a bit width less than 32-bits must have the
high-order bits set to 0.

Fixes microsoft/DirectXShaderCompiler#6319.
return const_mgr->GetConstant(type, words);
const spvtools::opt::analysis::Integer* int_type = type->AsInteger();

if (int_type && int_type->width() < 32 && !int_type->IsSigned()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I recently added some utility functions you can use. See constant folding rules for SConvert.

Also you might need to handle 8bit integers as well. They are allowed in Spirv.

If we are casting from unsigned to signed, do we need to sign extend?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we are casting from unsigned to signed, do we need to sign extend?

Ah yes we do, thanks for catching that.

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.

[SPIR-V] Casting 16bit integral data types
2 participants