Skip to content

val: Validate consistent XfbStride for Vulkan output interfaces - #7057

Open
gryffxz wants to merge 1 commit into
KhronosGroup:mainfrom
gryffxz:xfb-stride-04693
Open

gryffxz wants to merge 1 commit into
KhronosGroup:mainfrom
gryffxz:xfb-stride-04693

Conversation

@gryffxz

@gryffxz gryffxz commented Nov 23, 2026 •

Copy link
Copy Markdown

Contributes to #6594

Adds the check for VUID-StandaloneSpirv-XfbBuffer-04693:

All variables or block members in the output interface of the entry point
being compiled decorated with a specific XfbBuffer value must all be
decorated with identical XfbStride values

Problem

spirv-val --target-env vulkan1.x accepts this interface today:

OpEntryPoint Vertex %main "main" %var1 %var2
OpExecutionMode %main Xfb
OpDecorate %var1 Location 0
OpDecorate %var1 XfbBuffer 0
OpDecorate %var1 XfbStride 16
OpDecorate %var2 Location 1
OpDecorate %var2 XfbBuffer 0
OpDecorate %var2 XfbStride 32

With this change:

error: line 19: [VUID-StandaloneSpirv-XfbBuffer-04693] Entry-point output interface variable '3[%3]' uses XfbBuffer 0 with XfbStride 32, but the same XfbBuffer is already used with XfbStride 16

Change

For each OpEntryPoint, in Vulkan environments only, collect XfbBuffer and
XfbStride from the Output interface variables and, looking through arrays,
from the members of their Block structs. Report the first stride that differs
from the one already seen for the same buffer.

Only objects that explicitly have both decorations are compared.

Not covered

  • The universal SPIR-V rule, see the question below.
  • A member that declares only one of the two decorations and would take the
    other from its block. 04697 says "declared or inherited" and 04716 describes
    inheriting from a block, but 04693 only says "decorated with", so I left that
    case alone.
  • An XfbBuffer without an XfbStride.
  • Members of nested structs, and of structs that are not Block.
  • The same decoration applied twice to one object, directly and through a
    decoration group. The existing duplicate check only looks at direct
    decorations.

Question

This PR does not implement or change the enforcement of the similar rule in the
universal validation rules (2.16.1), which is not limited to an entry point or
to Vulkan:

All XfbStride Decorations must be the same for all objects decorated with the
same XfbBuffer XFB Buffer Number.

I found no existing check for it in spirv-val. So a module where two entry
points use the same buffer with different strides, which breaks the universal
rule, is still accepted after this change.

I kept this PR to the VUID. Would you prefer the universal rule as a separate
validation in a follow-up PR?

Testing

  • 6 new tests in ValidateInterfacesTest, three valid and three invalid. Without
    the source change, the three invalid ones fail and the three valid ones pass.
    The invalid arrayed block test also fails if the check does not look through
    arrays.
  • All five test_val_* executables (69,121 tests) pass with GCC 15.2 on Ubuntu
    26.04 with SPIRV_WERROR=ON and no warnings, and with Clang 23 (llvm-mingw)
    on Windows with SPIRV_WERROR=OFF.
  • test_opt, test_opt_loops and test_spirv_unit_tests passed with Clang
    only, on an earlier revision with the same algorithm.
  • Not run locally: MSVC, sanitizers, the rest of ctest and the shaderc smoke
    test.

Implement VUID-StandaloneSpirv-XfbBuffer-04693: within the output interface
of an entry point, everything decorated with the same XfbBuffer must have
the same XfbStride.

Only objects that explicitly have both decorations are compared. The
universal rule, which is not limited to an entry point, is not checked.

Contributes to KhronosGroup#6594
@CLAassistant

CLAassistant commented Nov 23, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

// decorated with the same XfbBuffer is also decorated with the same XfbStride.
spv_result_t ValidateXfbStride(ValidationState_t& _,
const Instruction* entry_point) {
// Both XfbBuffer and XfbStride require this capability.

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.

this should say

// To reason to spend time validating if there is no possible transform feedback

return SPV_SUCCESS;
}

// Checks that, within the output interface of |entry_point|, everything

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.

remove this and all other comment that come off as AI generated... if the comment is not telling "why" and "what" it is not a good comment IMO

// Keyed by member index, with the variable itself as kInvalidMember. Direct
// duplicate decorations are rejected earlier, but not necessarily those
// introduced by a decoration group.
std::map<int, XfbInfo> infos;

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.

comment doesn't explain why this needs to be ordered and not used unordered_map

// duplicate decorations are rejected earlier, but not necessarily those
// introduced by a decoration group.
std::map<int, XfbInfo> infos;
auto collect = [&infos](const Decoration& dec) {

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.

do we really need a lambda for something only used twice, or could this just all be rewritten better to handle both block/non-block variables

like this is now doing two loops over _.id_decorations which I feel we do a better job in other functions of similar checks

// clear how a member that declares just one of the two decorations
// combines with what it inherits from the block, so don't check those.
const auto& info = entry.second;
if (!info.has_buffer || !info.has_stride) continue;

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.

if feel like before we get here, we could have returned early or filtered this already


for (uint32_t i = 3; i < entry_point->operands().size(); ++i) {
const auto variable = _.FindDef(entry_point->GetOperandAs<uint32_t>(i));
if (variable->opcode() != spv::Op::OpVariable ||

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.

maybe leave a comment that we just assume SPV_KHR_untyped_pointer and TransformFeedback are not supported here currently, since doubt anyone is going to use those two together, but its is a gap in validation so should be documented

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