Skip to content

spirv-opt: Don't fold to 8/16-bit constants without Int8/Int16 - #6990

Merged
s-perron merged 1 commit into
KhronosGroup:mainfrom
apollo-2006:fold-int8-without-capability
Nov 12, 2026
Merged

s-perron merged 1 commit into
KhronosGroup:mainfrom
apollo-2006:fold-int8-without-capability

Conversation

@apollo-2006

Copy link
Copy Markdown
Contributor

With only StorageBuffer8BitAccess (no Int8), constants of 8-bit types aren't allowed, but CCP and simplification were folding OpUConvert %uchar %uint_9 into OpConstant %uchar 9, which spirv-val rejects:

Cannot form constants of 8- or 16-bit types

glslang's spv.bufferhandle11.frag hits this under -O, -Os and --legalize-hlsl. This skips folding to a constant in those two passes when the module can't declare a constant of that type (same rule as the validator: 8/16-bit ints and fp16 without Int8/Int16/Float16).

Added tests to ccp_test.cpp and simplification_test.cpp. test_opt passes, and running glslang's tests through spirv-opt only changes spv.bufferhandle11.frag (invalid to valid). Let me know if you'd rather handle it somewhere else :)

@s-perron
s-perron enabled auto-merge (squash) October 30, 2026 15:53
@s-perron

Copy link
Copy Markdown
Collaborator

Please rebase your change on the latest main.

auto-merge was automatically disabled October 30, 2026 17:48

Head branch was pushed to by a user without write access

@apollo-2006
apollo-2006 force-pushed the fold-int8-without-capability branch from 31f4331 to 53ae00d Compare October 30, 2026 17:48
@s-perron
s-perron enabled auto-merge (squash) November 12, 2026 17:28
With only StorageBuffer8BitAccess (or the 16-bit storage
capabilities), constants of 8- or 16-bit types are not allowed, but
CCP and instruction simplification folded

    %c = OpUConvert %uchar %uint_9

into %uchar_9 = OpConstant %uchar 9, which spirv-val rejects with
"Cannot form constants of 8- or 16-bit types".

Skip folding to a constant in those passes when the module can't
declare a constant of the result type.
@s-perron
s-perron force-pushed the fold-int8-without-capability branch from 53ae00d to 58e4aee Compare November 12, 2026 18:47
@s-perron
s-perron merged commit ddf8cd4 into KhronosGroup:main Nov 12, 2026
25 of 26 checks passed
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.

3 participants