Skip to content

[val] Explicit layout refactor#6792

Open
alan-baker wants to merge 6 commits into
KhronosGroup:mainfrom
alan-baker:explicit-layout-refactor
Open

[val] Explicit layout refactor#6792
alan-baker wants to merge 6 commits into
KhronosGroup:mainfrom
alan-baker:explicit-layout-refactor

Conversation

@alan-baker

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

Copy link
Copy Markdown
Contributor

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 on lines +2833 to +2839
auto sc = storage_class_ptr->GetOperandAs<spv::StorageClass>(1u);
if (sc != spv::StorageClass::StorageBuffer &&
sc != spv::StorageClass::Uniform) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpBufferPointerEXT Result Type must be a pointer type "
<< "with a Storage Class of Uniform or StorageBuffer.";
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was previously in CheckDecorationsOfBuffers, but makes more sense here.


if (inst->opcode() == spv::Op::OpConstantNull) {
*val = 0;
} else if (inst->opcode() == spv::Op::OpConstantSizeOfEXT) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These allow validation to process OpConstantSizeOf without freezing the constants to some value.

return SPV_SUCCESS;
}

spv_result_t CheckDecorationsOfBuffers(ValidationState_t& vstate) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I left the block checks since I don't entirely count them as explicit layout.

@alan-baker

Copy link
Copy Markdown
Contributor 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.

@@ -1073,130 +1073,6 @@ TEST_F(ValidateDecorations, BlockDecoratingIntBad) {
EXPECT_THAT(getDiagnosticString(), HasSubstr("must be a structure type"));
}

TEST_F(ValidateDecorations, BlockMissingOffsetBad) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

All these tests were ported straight into the new file (modulo some message updates).

EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
}

TEST_F(ValidateExplicitLayout, BufferPointerEXTMissingOffsetBad) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These are new until the untyped layout tests.

Comment thread source/val/validate_explicit_layout.cpp
Comment thread source/val/validate_explicit_layout.cpp

@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

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

2 participants