Skip to content

Commit

Permalink
Consider 0xffffffff offset as missing (KhronosGroup#4564)
Browse files Browse the repository at this point in the history
Fixes KhronosGroup#4561

* When checking for offsets, don't accept 0xffffffff
  • Loading branch information
alan-baker authored Oct 15, 2021
1 parent 06ebc48 commit 35fd0e1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions source/val/validate_decorations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ bool isMissingOffsetInStruct(uint32_t struct_id, ValidationState_t& vstate) {
for (auto& decoration : vstate.id_decorations(struct_id)) {
if (SpvDecorationOffset == decoration.dec_type() &&
Decoration::kInvalidMember != decoration.struct_member_index()) {
// Offset 0xffffffff is not valid so ignore it for simplicity's sake.
if (decoration.params()[0] == 0xffffffff) return true;
hasOffset[decoration.struct_member_index()] = true;
}
}
Expand Down
30 changes: 30 additions & 0 deletions test/val/val_decoration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7825,6 +7825,36 @@ OpFunctionEnd
"laid out with Offset decorations"));
}

TEST_F(ValidateDecorations, AllOnesOffset) {
const std::string spirv = R"(
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpDecorate %var DescriptorSet 0
OpDecorate %var Binding 0
OpDecorate %outer Block
OpMemberDecorate %outer 0 Offset 0
OpMemberDecorate %struct 0 Offset 4294967295
%void = OpTypeVoid
%int = OpTypeInt 32 0
%struct = OpTypeStruct %int
%outer = OpTypeStruct %struct
%ptr = OpTypePointer Uniform %outer
%var = OpVariable %ptr Uniform
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
%entry = OpLabel
OpReturn
OpFunctionEnd
)";

CompileSuccessfully(spirv);
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
EXPECT_THAT(getDiagnosticString(),
HasSubstr("decorated as Block must be explicitly laid out with "
"Offset decorations"));
}

} // namespace
} // namespace val
} // namespace spvtools

0 comments on commit 35fd0e1

Please sign in to comment.