Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-baker committed Jul 16, 2024
1 parent c746442 commit 158c63c
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 41 deletions.
23 changes: 14 additions & 9 deletions source/val/validate_decorations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,14 +773,16 @@ spv_result_t CheckDecorationsOfEntryPoints(ValidationState_t& vstate) {
std::unordered_set<spv::BuiltIn> output_var_builtin;
for (auto interface : desc.interfaces) {
Instruction* var_instr = vstate.FindDef(interface);
if (!var_instr || (spv::Op::OpVariable != var_instr->opcode() &&
spv::Op::OpUntypedVariableKHR != var_instr->opcode())) {
if (!var_instr ||
(spv::Op::OpVariable != var_instr->opcode() &&
spv::Op::OpUntypedVariableKHR != var_instr->opcode())) {
return vstate.diag(SPV_ERROR_INVALID_ID, var_instr)
<< "Interfaces passed to OpEntryPoint must be variables. "
"Found Op"
<< spvOpcodeString(var_instr->opcode()) << ".";
}
const bool untyped_pointers = var_instr->opcode() == spv::Op::OpUntypedVariableKHR;
const bool untyped_pointers =
var_instr->opcode() == spv::Op::OpUntypedVariableKHR;
const auto sc_index = 2u;
const spv::StorageClass storage_class =
var_instr->GetOperandAs<spv::StorageClass>(sc_index);
Expand Down Expand Up @@ -891,9 +893,11 @@ spv_result_t CheckDecorationsOfEntryPoints(ValidationState_t& vstate) {
<< "Untyped workgroup variables in shaders must be "
"block decorated";
}
if (hasDecoration(var_instr->id(), spv::Decoration::Aliased, vstate))
if (hasDecoration(var_instr->id(), spv::Decoration::Aliased,
vstate))
++num_workgroup_variables_with_aliased;
} else if (untyped_pointers && vstate.HasCapability(spv::Capability::Shader)) {
} else if (untyped_pointers &&
vstate.HasCapability(spv::Capability::Shader)) {
return vstate.diag(SPV_ERROR_INVALID_ID, var_instr)
<< "Untyped workgroup variables in shaders must be block "
"decorated structs";
Expand Down Expand Up @@ -1114,7 +1118,8 @@ spv_result_t CheckDecorationsOfBuffers(ValidationState_t& vstate) {
MemberConstraints constraints;
if (spv::Op::OpVariable == inst.opcode() ||
spv::Op::OpUntypedVariableKHR == inst.opcode()) {
const bool untyped_pointer = inst.opcode() == spv::Op::OpUntypedVariableKHR;
const bool untyped_pointer =
inst.opcode() == spv::Op::OpUntypedVariableKHR;
const auto var_id = inst.id();
// For storage class / decoration combinations, see Vulkan 14.5.4 "Offset
// and Stride Assignment".
Expand Down Expand Up @@ -1386,9 +1391,9 @@ spv_result_t CheckDecorationsOfBuffers(ValidationState_t& vstate) {
ComputeMemberConstraintsForStruct(&constraints, pointee_type_id,
LayoutConstraints(), vstate);
}
if (auto res = checkLayout(pointee_type_id, "PhysicalStorageBuffer", "Block",
!buffer, scalar_block_layout, 0, constraints,
vstate)) {
if (auto res = checkLayout(pointee_type_id, "PhysicalStorageBuffer",
"Block", !buffer, scalar_block_layout, 0,
constraints, vstate)) {
return res;
}
} else if (vstate.HasCapability(spv::Capability::UntypedPointersKHR) &&
Expand Down
3 changes: 2 additions & 1 deletion source/val/validate_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ spv_result_t ValidateFunctionParameter(ValidationState_t& _,
_.FindDef(param_nonarray_type_id)->GetOperandAs<uint32_t>(1u);
}
if (_.GetIdOpcode(param_nonarray_type_id) == spv::Op::OpTypePointer ||
_.GetIdOpcode(param_nonarray_type_id) == spv::Op::OpTypeUntypedPointerKHR) {
_.GetIdOpcode(param_nonarray_type_id) ==
spv::Op::OpTypeUntypedPointerKHR) {
auto param_nonarray_type = _.FindDef(param_nonarray_type_id);
if (param_nonarray_type->GetOperandAs<spv::StorageClass>(1u) ==
spv::StorageClass::PhysicalStorageBuffer) {
Expand Down
3 changes: 2 additions & 1 deletion source/val/validate_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,8 @@ spv_result_t ValidateImageTexelPointer(ValidationState_t& _,
if (result_type->opcode() == spv::Op::OpTypePointer) {
ptr_type = result_type->GetOperandAs<uint32_t>(2);
const auto ptr_opcode = _.GetIdOpcode(ptr_type);
if (ptr_opcode != spv::Op::OpTypeInt && ptr_opcode != spv::Op::OpTypeFloat &&
if (ptr_opcode != spv::Op::OpTypeInt &&
ptr_opcode != spv::Op::OpTypeFloat &&
ptr_opcode != spv::Op::OpTypeVoid &&
!(ptr_opcode == spv::Op::OpTypeVector &&
_.HasCapability(spv::Capability::AtomicFloat16VectorNV) &&
Expand Down
3 changes: 2 additions & 1 deletion source/val/validate_logicals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ spv_result_t LogicalsPass(ValidationState_t& _, const Instruction* inst) {
case spv::Op::OpTypeUntypedPointerKHR:
case spv::Op::OpTypePointer: {
if (_.addressing_model() == spv::AddressingModel::Logical &&
!_.HasCapability(spv::Capability::VariablePointersStorageBuffer))
!_.HasCapability(
spv::Capability::VariablePointersStorageBuffer))
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Using pointers with OpSelect requires capability "
<< "VariablePointers or VariablePointersStorageBuffer";
Expand Down
28 changes: 18 additions & 10 deletions source/val/validate_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ spv_result_t ValidateVariable(ValidationState_t& _, const Instruction* inst) {

auto result_type = _.FindDef(inst->type_id());
if (untyped_pointer) {
if (!result_type || result_type->opcode() != spv::Op::OpTypeUntypedPointerKHR)
if (!result_type ||
result_type->opcode() != spv::Op::OpTypeUntypedPointerKHR)
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "Result type must be an untyped pointer";
} else {
Expand Down Expand Up @@ -975,8 +976,9 @@ spv_result_t ValidateLoad(ValidationState_t& _, const Instruction* inst) {
}

const auto pointer_type = _.FindDef(pointer->type_id());
if (!pointer_type || (pointer_type->opcode() != spv::Op::OpTypePointer &&
pointer_type->opcode() != spv::Op::OpTypeUntypedPointerKHR)) {
if (!pointer_type ||
(pointer_type->opcode() != spv::Op::OpTypePointer &&
pointer_type->opcode() != spv::Op::OpTypeUntypedPointerKHR)) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpLoad type for pointer <id> " << _.getIdName(pointer_id)
<< " is not a pointer type.";
Expand Down Expand Up @@ -1033,8 +1035,9 @@ spv_result_t ValidateStore(ValidationState_t& _, const Instruction* inst) {
<< " is not a logical pointer.";
}
const auto pointer_type = _.FindDef(pointer->type_id());
if (!pointer_type || (pointer_type->opcode() != spv::Op::OpTypePointer &&
pointer_type->opcode() != spv::Op::OpTypeUntypedPointerKHR)) {
if (!pointer_type ||
(pointer_type->opcode() != spv::Op::OpTypePointer &&
pointer_type->opcode() != spv::Op::OpTypeUntypedPointerKHR)) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpStore type for pointer <id> " << _.getIdName(pointer_id)
<< " is not a pointer type.";
Expand Down Expand Up @@ -1126,7 +1129,8 @@ spv_result_t ValidateStore(ValidationState_t& _, const Instruction* inst) {
}

if (type && (type->id() != object_type->id())) {
if (!_.options()->relax_struct_store || type->opcode() != spv::Op::OpTypeStruct ||
if (!_.options()->relax_struct_store ||
type->opcode() != spv::Op::OpTypeStruct ||
object_type->opcode() != spv::Op::OpTypeStruct) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpStore Pointer <id> " << _.getIdName(pointer_id)
Expand Down Expand Up @@ -1246,8 +1250,10 @@ spv_result_t ValidateCopyMemory(ValidationState_t& _, const Instruction* inst) {
}

if (inst->opcode() == spv::Op::OpCopyMemory) {
const bool target_typed = target_pointer_type->opcode() == spv::Op::OpTypePointer;
const bool source_typed = source_pointer_type->opcode() == spv::Op::OpTypePointer;
const bool target_typed =
target_pointer_type->opcode() == spv::Op::OpTypePointer;
const bool source_typed =
source_pointer_type->opcode() == spv::Op::OpTypePointer;
Instruction* target_type = nullptr;
Instruction* source_type = nullptr;
if (target_typed) {
Expand Down Expand Up @@ -1458,7 +1464,8 @@ spv_result_t ValidateAccessChain(ValidationState_t& _,
// OpTypeUntypedPointerKHR for untyped access chains.
auto result_type = _.FindDef(inst->type_id());
if (untyped_pointer) {
if (!result_type || spv::Op::OpTypeUntypedPointerKHR != result_type->opcode()) {
if (!result_type ||
spv::Op::OpTypeUntypedPointerKHR != result_type->opcode()) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "The Result Type of " << instr_name << " <id> "
<< _.getIdName(inst->id())
Expand Down Expand Up @@ -2077,7 +2084,8 @@ spv_result_t ValidateCooperativeMatrixLoadStoreKHR(ValidationState_t& _,
<< " is not a pointer type.";
}

const bool untyped = pointer_type->opcode() == spv::Op::OpTypeUntypedPointerKHR;
const bool untyped =
pointer_type->opcode() == spv::Op::OpTypeUntypedPointerKHR;
const auto storage_class_index = 1u;
const auto storage_class =
pointer_type->GetOperandAs<spv::StorageClass>(storage_class_index);
Expand Down
3 changes: 2 additions & 1 deletion source/val/validate_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,8 @@ spv_result_t ValidateTypeUntypedPointerKHR(ValidationState_t& _,
const auto sc = inst->GetOperandAs<spv::StorageClass>(1);
switch (sc) {
case spv::StorageClass::Workgroup:
if (!_.HasCapability(spv::Capability::WorkgroupMemoryExplicitLayoutKHR)) {
if (!_.HasCapability(
spv::Capability::WorkgroupMemoryExplicitLayoutKHR)) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "Workgroup storage class untyped pointers in Vulkan "
"require WorkgroupMemoryExplicitLayoutKHR be declared";
Expand Down
9 changes: 3 additions & 6 deletions source/val/validation_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1700,12 +1700,9 @@ bool ValidationState_t::ContainsRuntimeArray(uint32_t id) const {

bool ValidationState_t::ContainsUntypedPointer(uint32_t id) const {
const auto inst = FindDef(id);
if (!inst)
return false;
if (!spvOpcodeGeneratesType(inst->opcode()))
return false;
if (inst->opcode() == spv::Op::OpTypeUntypedPointerKHR)
return true;
if (!inst) return false;
if (!spvOpcodeGeneratesType(inst->opcode())) return false;
if (inst->opcode() == spv::Op::OpTypeUntypedPointerKHR) return true;

switch (inst->opcode()) {
case spv::Op::OpTypeArray:
Expand Down
6 changes: 4 additions & 2 deletions test/text_to_binary.extension_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1357,12 +1357,14 @@ INSTANTIATE_TEST_SUITE_P(
MakeInstruction(spv::Op::OpUntypedAccessChainKHR,
{1, 2, 3, 4, 5, 6, 7})},
{"%2 = OpUntypedInBoundsAccessChainKHR %1 %3 %4\n",
MakeInstruction(spv::Op::OpUntypedInBoundsAccessChainKHR, {1, 2, 3, 4})},
MakeInstruction(spv::Op::OpUntypedInBoundsAccessChainKHR,
{1, 2, 3, 4})},
{"%2 = OpUntypedInBoundsAccessChainKHR %1 %3 %4 %5 %6 %7\n",
MakeInstruction(spv::Op::OpUntypedInBoundsAccessChainKHR,
{1, 2, 3, 4, 5, 6, 7})},
{"%2 = OpUntypedPtrAccessChainKHR %1 %3 %4 %5\n",
MakeInstruction(spv::Op::OpUntypedPtrAccessChainKHR, {1, 2, 3, 4, 5})},
MakeInstruction(spv::Op::OpUntypedPtrAccessChainKHR,
{1, 2, 3, 4, 5})},
{"%2 = OpUntypedPtrAccessChainKHR %1 %3 %4 %5 %6 %7\n",
MakeInstruction(spv::Op::OpUntypedPtrAccessChainKHR,
{1, 2, 3, 4, 5, 6, 7})},
Expand Down
12 changes: 8 additions & 4 deletions test/val/val_decoration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10155,7 +10155,8 @@ OpDecorate %var Binding 0
%void = OpTypeVoid
%int = OpTypeInt 32 0
%struct = OpTypeStruct %int
%ptr = OpTypeUntypedPointerKHR )" + sc + R"(
%ptr = OpTypeUntypedPointerKHR )" +
sc + R"(
%var = OpUntypedVariableKHR %ptr )" + sc + R"( %struct
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
Expand Down Expand Up @@ -10188,7 +10189,8 @@ OpDecorate %var DescriptorSet 0
%void = OpTypeVoid
%int = OpTypeInt 32 0
%struct = OpTypeStruct %int
%ptr = OpTypeUntypedPointerKHR )" + sc + R"(
%ptr = OpTypeUntypedPointerKHR )" +
sc + R"(
%var = OpUntypedVariableKHR %ptr )" + sc + R"( %struct
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
Expand Down Expand Up @@ -10242,7 +10244,8 @@ OpMemberDecorate %test_type 1 Offset 1
%struct = OpTypeStruct %int %int
%test_type = OpTypeStruct %int %int
%test_val = OpConstantNull %test_type
%ptr = OpTypeUntypedPointerKHR )" + sc + R"(
%ptr = OpTypeUntypedPointerKHR )" +
sc + R"(
%var = OpUntypedVariableKHR %ptr )" + sc + R"( %struct
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
Expand Down Expand Up @@ -10294,7 +10297,8 @@ OpMemberDecorate %struct 1 Offset 4
%test_type = OpTypeArray %int4 %int_4
%test_val = OpConstantNull %test_type
%struct = OpTypeStruct %int %int
%ptr = OpTypeUntypedPointerKHR )" + sc + R"(
%ptr = OpTypeUntypedPointerKHR )" +
sc + R"(
%var = OpUntypedVariableKHR %ptr )" + sc + R"( %struct
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
Expand Down
4 changes: 1 addition & 3 deletions test/val/val_fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ class ValidateBase : public ::testing::Test,
diagnostic_ = nullptr;
}

void SetAssembleOptions(uint32_t options) {
assemble_options_ = options;
}
void SetAssembleOptions(uint32_t options) { assemble_options_ = options; }

std::string getDiagnosticString();
spv_position_t getErrorPosition();
Expand Down
6 changes: 4 additions & 2 deletions test/val/val_function_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,8 @@ OpFunctionEnd
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
}

TEST_F(ValidateFunctionCall, UntypedPointerParameterNotMemoryObjectDeclaration) {
TEST_F(ValidateFunctionCall,
UntypedPointerParameterNotMemoryObjectDeclaration) {
const std::string spirv = R"(
OpCapability Shader
OpCapability UntypedPointersKHR
Expand Down Expand Up @@ -938,7 +939,8 @@ OpFunctionEnd
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
EXPECT_THAT(
getDiagnosticString(),
HasSubstr("Pointer operand '3[%gep]' must be a memory object declaration"));
HasSubstr(
"Pointer operand '3[%gep]' must be a memory object declaration"));
}

INSTANTIATE_TEST_SUITE_P(StorageClass, ValidateFunctionCall,
Expand Down
3 changes: 2 additions & 1 deletion test/val/val_id_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,8 @@ OpMemoryModel Logical GLSL450
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
}

TEST_P(ValidateIdWithMessage, OpTypeUntypedPointerWorkgroupMissingExplicitLayout) {
TEST_P(ValidateIdWithMessage,
OpTypeUntypedPointerWorkgroupMissingExplicitLayout) {
const std::string spirv = R"(
OpCapability Shader
OpCapability UntypedPointersKHR
Expand Down

0 comments on commit 158c63c

Please sign in to comment.