Skip to content

[val] Explicit layout refactor - #6792

Merged
alan-baker merged 7 commits into
KhronosGroup:mainfrom
alan-baker:explicit-layout-refactor
Jul 28, 2026
Merged

alan-baker merged 7 commits into
KhronosGroup:mainfrom
alan-baker:explicit-layout-refactor

Conversation

@alan-baker

@alan-baker alan-baker commented Jul 13, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #6780

  • Combine layout checks into a single pass to share logic
    • checks both required explicit layouts and invalid layouts
    • remove checks from validate_decorations.cpp
  • Introduce enums for layout modes and requirements
  • Centralize which instructions are examined for layouts
  • Add options to specify descriptor sizes to the validator (buffer, sampler, image, and tensor)

* Combine layout checks into a single pass to share logic
  * checks both required explicit layouts and invalid layouts
  * remove checks from validate_decorations.cpp
* Introduce enums for layout modes and requirements
* Centralize which instructions are examined for layouts
* Add options to specify descriptor sizes to the validator (buffer, sampler, image, and tensor)
* Fix handling of OpBufferPointerEXT
* Add tests for missing coverage
Comment thread source/val/validate_memory.cpp Resolved
Comment thread source/val/validation_state.cpp Resolved
Comment thread source/val/validate_decorations.cpp Resolved
@alan-baker

Copy link
Copy Markdown
Collaborator Author

I should mention as well, I tested this against vk-gl-cts main branch and the only validation problems looked real and related workgroup memory explicit layout. See vk-gl-cts tracker issue 6736.

Comment thread test/val/val_decoration_test.cpp Resolved
Comment thread test/val/val_explicit_layout_test.cpp Resolved
Comment thread source/val/validate_explicit_layout.cpp Resolved
Comment thread source/val/validate_explicit_layout.cpp Resolved

@spencer-lunarg spencer-lunarg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I tested with VVL and CTS, it looks good will likely need some VUID churn... but honestly that is a followup level PR

overall this REALLY helps with untyped pointers to enforce people from setting offset/arrayStride to crazy non-sense values that will just lead to a nightmare for the average dev to debug

@spencer-lunarg

Copy link
Copy Markdown
Contributor

fyi, this is going to miss this SDK cycle now, which I think it is fine, gives more time to test this over time, but still happy to make this the new baseline

@dneto0 dneto0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM except that it looks like theres one function that should be deleted.

Comment thread include/spirv-tools/libspirv.h Resolved
Comment thread source/val/validate_decorations.cpp Resolved
Comment thread source/val/validate_explicit_layout.cpp Resolved
Comment thread source/val/validate_explicit_layout.cpp Resolved
* Remove dead code for invalid layout checks (old)
* Improve comments
@alan-baker
alan-baker requested a review from dneto0 July 28, 2026 18:47

@dneto0 dneto0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

@dneto0
dneto0 enabled auto-merge (squash) July 28, 2026 19:13
@alan-baker
alan-baker disabled auto-merge July 28, 2026 19:14
@alan-baker
alan-baker enabled auto-merge (squash) July 28, 2026 19:14
@alan-baker
alan-baker merged commit 4d6dad6 into KhronosGroup:main Jul 28, 2026
4 checks passed
@alan-baker
alan-baker deleted the explicit-layout-refactor branch July 28, 2026 20:47
@spencer-lunarg

spencer-lunarg commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Just wanted to point out VVL change is KhronosGroup/Vulkan-ValidationLayers#12788

really nice to just pass in the properties and catch real issues faster

vkCreateShaderModule(): pCreateInfo->pCode (spirv-val produced an error):
Structure member 0 at offset 32 is not aligned to 64. Instantiated via '26[%26]' in the UniformConstant storage class using standard layout rules.
  %_struct_4 = OpTypeStruct %20 %21

Command to reproduce:
	spirv-val <input.spv> --relax-block-layout --buffer-descriptor-layout 64:64 --image-descriptor-layout 64:64 --sampler-descriptor-layout 32:32 --target-env vulkan1.3

The only thing I will follow up with adding VUID so it points to things like VUID-RuntimeSpirv-imageDescriptorAlignment-11477

damyanp added a commit to damyanp/DirectXShaderCompiler that referenced this pull request Aug 6, 2026
The validator now requires explicit layout for UniformConstant when
SPV_EXT_descriptor_heap is used (KhronosGroup/SPIRV-Tools#6792), which
DXC's descriptor heap codegen does not yet do. Exposed by the
SPIRV-Tools update in 8725f5c.

Assisted-by: copilot
Co-authored-by: Copilot <[email protected]>
Copilot-Session: b04b21af-2d8b-4af5-b9ad-1b84073588f5
damyanp added a commit to microsoft/DirectXShaderCompiler that referenced this pull request Aug 6, 2026
Fixes two SPIR-V validation failures under -O3:

- #8609: loop unrolling duplicated RelaxedPrecision decorations
  (KhronosGroup/SPIRV-Tools#6690)
- #8603: MergeBinaryOpSelect produced an OpSelect with a vector result
  type and a scalar condition, only legal in SPIR-V 1.4+
  (KhronosGroup/SPIRV-Tools#6827)

SPIRV-Headers moves to 29981f65 to match; SPIRV-Tools 1c336172 does not
build against the older headers.

XFAIL resource-heap-ext-texture: the validator now requires explicit
layout for UniformConstant when SPV_EXT_descriptor_heap is used
(KhronosGroup/SPIRV-Tools#6792).

Assisted-by: copilot
Co-authored-by: Copilot <[email protected]>
Copilot-Session: b04b21af-2d8b-4af5-b9ad-1b84073588f5

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b04b21af-2d8b-4af5-b9ad-1b84073588f5
@Jamaika1

Copy link
Copy Markdown
In file included from C:/gcc1520/include/c++/15.2.0/x86_64-w64-mingw32/bits/c++allocator.h:33,
                 from C:/gcc1520/include/c++/15.2.0/bits/allocator.h:46,
                 from C:/gcc1520/include/c++/15.2.0/string:45,
                 from validate_decorations.cpp:17:
In member function 'void std::__new_allocator<_Tp>::deallocate(_Tp*, size_type) [with _Tp = unsigned int]',
    inlined from 'static void std::allocator_traits<std::allocator<_CharT> >::deallocate(allocator_type&, pointer, size_type) [with _Tp = unsigned int]' at C:/gcc1520/include/c++/15.2.0/bits/alloc_traits.h:649:23,
    inlined from 'void std::_Vector_base<_Tp, _Alloc>::_M_deallocate(pointer, std::size_t) [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>]' at C:/gcc1520/include/c++/15.2.0/bits/stl_vector.h:396:19,
    inlined from 'std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>]' at C:/gcc1520/include/c++/15.2.0/bits/stl_vector.h:375:15,
    inlined from 'std::vector<_Tp, _Alloc>::~vector() [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>]' at C:/gcc1520/include/c++/15.2.0/bits/stl_vector.h:805:7,
    inlined from 'std::vector<unsigned int> spvtools::val::{anonymous}::getStructMembers(uint32_t, spv::Op, spvtools::val::ValidationState_t&)' at validate_decorations.cpp:69:52,
    inlined from 'bool spvtools::val::{anonymous}::hasDecoration(uint32_t, spv::Decoration, spvtools::val::ValidationState_t&)' at validate_decorations.cpp:87:75:
C:/gcc1520/include/c++/15.2.0/bits/new_allocator.h:172:66: warning: 'void operator delete(void*, std::size_t)' called on pointer '<unknown>' with nonzero offset [1, 9223372036854775804] [-Wfree-nonheap-object]
  172 |         _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n));
      |                                                                  ^

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.

Add missing explicit layout check for OpBufferPointerEXT with typed result

4 participants