Skip to content

spirv-opt: Adding deduplication of NonWritable OpLoads#6413

Open
alister-chowdhury wants to merge 9 commits intoKhronosGroup:mainfrom
alister-chowdhury:deduplicating_loads
Open

spirv-opt: Adding deduplication of NonWritable OpLoads#6413
alister-chowdhury wants to merge 9 commits intoKhronosGroup:mainfrom
alister-chowdhury:deduplicating_loads

Conversation

@alister-chowdhury
Copy link
Copy Markdown
Contributor

The current logic would only mark a load as read-only if either the OpVariable had NonWritable or a Uniform was not a storage buffer.

This adds IsVulkanReadOnlyStorageBuffer, which does mostly the same stuff as IsVulkanStorageBuffer, with the addition of testing for NonWritable.

When used as part of IsReadOnlyLoad for assigning value numbers, prevents it from being forced a unique value.

Fixes #6412

@alister-chowdhury alister-chowdhury changed the title Adding deduplication of NonWritable OpLoads spirv-opt: Adding deduplication of NonWritable OpLoads Nov 16, 2025
Comment thread source/opt/instruction.cpp Outdated
Comment thread source/opt/instruction.cpp Outdated
Copy link
Copy Markdown
Collaborator

@dneto0 dneto0 left a comment

Choose a reason for hiding this comment

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

The tests look wrong. NonWritable is not put onto the struct type.
It's put on the OpVariable or the member of the struct.

Comment thread source/opt/instruction.h
Comment thread test/opt/instruction_test.cpp Outdated
Comment thread test/opt/instruction_test.cpp Outdated
Comment thread source/opt/instruction.cpp Outdated
Copy link
Copy Markdown
Collaborator

@dneto0 dneto0 left a comment

Choose a reason for hiding this comment

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

The implementation and testing look wrong. See above.

Comment thread source/opt/instruction.cpp Outdated
@s-perron s-perron requested a review from dneto0 December 16, 2025 19:23
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 13, 2026

CLA assistant check
All committers have signed the CLA.

@s-perron s-perron enabled auto-merge (squash) March 27, 2026 16:21
alister-chowdhury and others added 9 commits March 27, 2026 13:37
The current logic would only mark a load as read-only if either the
OpVariable had NonWritable or a Uniform was not a storage buffer.

This adds `IsVulkanReadOnlyStorageBuffer`, which does mostly the same
stuff as `IsVulkanStorageBuffer`, with the addition of testing for
NonWritable.

When used as part of `IsReadOnlyLoad` for assigning value numbers,
prevents it from being forced a unique value.

Fixes KhronosGroup#6412
* Renaming `IsVulkanReadOnlyStorageBuffer` to
  `IsVulkanStorageBufferNonWriteable`
Mainly to not accidentally mislead someone who comes across it.

* Changed `IsReadOnlyPointerShaders` to return an enum, that can provide
  a hint that we may need to check other variables.

* Added `IsSetBindingUniformlyReadOnly` which is basically for said
  hint, to make sure nothing that isn't read-only is bound to the same
  address.
* Changed IsVulkanStorageBufferNonWritable to test members, for NonWritable.
* Specified IsSetBindingUniformlyReadOnly should be called after
  IsReadOnlyPointerShaders returns true.
* Updated tests to use OpMemberDecorate.
* Updated tests to include testing for having a NonWritable member.
@s-perron s-perron force-pushed the deduplicating_loads branch from a1ac686 to 2125eb5 Compare March 27, 2026 17:40
@s-perron
Copy link
Copy Markdown
Collaborator

I rebased on main, and fixed the formatting. See if that affects the tests.

@s-perron
Copy link
Copy Markdown
Collaborator

This seems to have caused a real problem for the fuzzer test. @alister-chowdhury Let me know if you need help with 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.

[spirv-opt] OpLoads are not de-duplicated for NonWritable buffers

5 participants