Skip to content

Commit 1c74ae5

Browse files
spirv-val: Print SPIR-V version info in error message (KhronosGroup#6283)
* spirv-val: Print SPIR-V version info in error message * spirv-val: Fixed some version logic in messages
1 parent d85c6a6 commit 1c74ae5

11 files changed

+108
-55
lines changed

source/val/validate_barriers.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ spv_result_t BarriersPass(ValidationState_t& _, const Instruction* inst) {
4545
model != spv::ExecutionModel::MeshNV) {
4646
if (message) {
4747
*message =
48-
"OpControlBarrier requires one of the following "
49-
"Execution "
50-
"Models: TessellationControl, GLCompute, Kernel, "
51-
"MeshNV or TaskNV";
48+
"In SPIR-V 1.2 or earlier, OpControlBarrier requires "
49+
"one of the following "
50+
"Execution Models: TessellationControl, GLCompute, "
51+
"Kernel, MeshNV or TaskNV";
5252
}
5353
return false;
5454
}

source/val/validate_conversion.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,26 +572,38 @@ spv_result_t ConversionPass(ValidationState_t& _, const Instruction* inst) {
572572
if (result_is_pointer && !input_is_pointer && !input_is_int_scalar &&
573573
!(input_is_int_vector && input_has_int32))
574574
return _.diag(SPV_ERROR_INVALID_DATA, inst)
575-
<< "Expected input to be a pointer, int scalar or 32-bit int "
575+
<< "In SPIR-V 1.5 or later (or with "
576+
"SPV_KHR_physical_storage_buffer), expected input to be a "
577+
"pointer, "
578+
"int scalar or 32-bit int "
576579
"vector if Result Type is pointer: "
577580
<< spvOpcodeString(opcode);
578581

579582
if (input_is_pointer && !result_is_pointer && !result_is_int_scalar &&
580583
!(result_is_int_vector && result_has_int32))
581584
return _.diag(SPV_ERROR_INVALID_DATA, inst)
582-
<< "Pointer can only be converted to another pointer, int "
585+
<< "In SPIR-V 1.5 or later (or with "
586+
"SPV_KHR_physical_storage_buffer), pointer can only be "
587+
"converted to "
588+
"another pointer, int "
583589
"scalar or 32-bit int vector: "
584590
<< spvOpcodeString(opcode);
585591
} else {
586592
if (result_is_pointer && !input_is_pointer && !input_is_int_scalar)
587593
return _.diag(SPV_ERROR_INVALID_DATA, inst)
588-
<< "Expected input to be a pointer or int scalar if Result "
594+
<< "In SPIR-V 1.4 or earlier (and without "
595+
"SPV_KHR_physical_storage_buffer), expected input to be a "
596+
"pointer "
597+
"or int scalar if Result "
589598
"Type is pointer: "
590599
<< spvOpcodeString(opcode);
591600

592601
if (input_is_pointer && !result_is_pointer && !result_is_int_scalar)
593602
return _.diag(SPV_ERROR_INVALID_DATA, inst)
594-
<< "Pointer can only be converted to another pointer or int "
603+
<< "In SPIR-V 1.4 or earlier (and without "
604+
"SPV_KHR_physical_storage_buffer), pointer can only be "
605+
"converted "
606+
"to another pointer or int "
595607
"scalar: "
596608
<< spvOpcodeString(opcode);
597609
}

source/val/validate_decorations.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -848,32 +848,35 @@ spv_result_t CheckDecorationsOfEntryPoints(ValidationState_t& vstate) {
848848
if (storage_class == spv::StorageClass::TaskPayloadWorkgroupEXT) {
849849
if (has_task_payload) {
850850
return vstate.diag(SPV_ERROR_INVALID_ID, var_instr)
851-
<< "There can be at most one OpVariable with storage "
851+
<< "There can be at most one "
852+
"OpVariable with storage "
852853
"class TaskPayloadWorkgroupEXT associated with "
853854
"an OpEntryPoint";
854855
}
855856
has_task_payload = true;
856857
}
857-
}
858-
if (vstate.version() >= SPV_SPIRV_VERSION_WORD(1, 4)) {
858+
859859
// Starting in 1.4, OpEntryPoint must list all global variables
860860
// it statically uses and those interfaces must be unique.
861861
if (storage_class == spv::StorageClass::Function) {
862862
return vstate.diag(SPV_ERROR_INVALID_ID, var_instr)
863-
<< "OpEntryPoint interfaces should only list global "
863+
<< "In SPIR-V 1.4 or later, OpEntryPoint interfaces should "
864+
"only list global "
864865
"variables";
865866
}
866867

867868
if (!seen_vars.insert(var_instr).second) {
868869
return vstate.diag(SPV_ERROR_INVALID_ID, var_instr)
869-
<< "Non-unique OpEntryPoint interface "
870+
<< "In SPIR-V 1.4 or later, non-unique OpEntryPoint "
871+
"interface "
870872
<< vstate.getIdName(interface) << " is disallowed";
871873
}
872874
} else {
873875
if (storage_class != spv::StorageClass::Input &&
874876
storage_class != spv::StorageClass::Output) {
875877
return vstate.diag(SPV_ERROR_INVALID_ID, var_instr)
876-
<< "OpEntryPoint interfaces must be OpVariables with "
878+
<< "In SPIR-V 1.3 or earlier, OpEntryPoint interfaces must "
879+
"be OpVariables with "
877880
"Storage Class of Input(1) or Output(3). Found Storage "
878881
"Class "
879882
<< uint32_t(storage_class) << " for Entry Point id "

source/val/validate_extensions.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,8 +1085,10 @@ spv_result_t ValidateExtInstImport(ValidationState_t& _,
10851085
const std::string name = inst->GetOperandAs<std::string>(name_id);
10861086
if (name.find("NonSemantic.") == 0) {
10871087
return _.diag(SPV_ERROR_INVALID_DATA, inst)
1088-
<< "NonSemantic extended instruction sets cannot be declared "
1089-
"without SPV_KHR_non_semantic_info.";
1088+
<< "NonSemantic extended instruction "
1089+
"sets cannot be declared "
1090+
"without SPV_KHR_non_semantic_info. (This can also be fixed "
1091+
"having SPIR-V 1.6 or later)";
10901092
}
10911093
}
10921094

source/val/validate_non_uniform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ spv_result_t ValidateGroupNonUniformBroadcastShuffle(ValidationState_t& _,
130130
if (!spvOpcodeIsConstant(id_op)) {
131131
std::string operand = GetOperandName(inst->opcode());
132132
return _.diag(SPV_ERROR_INVALID_DATA, inst)
133-
<< "Before SPIR-V 1.5, " << operand
133+
<< "In SPIR-V 1.4 or earlier, " << operand
134134
<< " must be a constant instruction";
135135
}
136136
}

source/val/validate_scopes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ spv_result_t ValidateExecutionScope(ValidationState_t& _,
9494

9595
// Vulkan specific rules
9696
if (spvIsVulkanEnv(_.context()->target_env)) {
97-
// Vulkan 1.1 specific rules
97+
// Subgroups were not added until 1.1
9898
if (_.context()->target_env != SPV_ENV_VULKAN_1_0) {
9999
// Scope for Non Uniform Group Operations must be limited to Subgroup
100100
if ((spvOpcodeIsNonUniformGroupOperation(opcode) &&

test/val/val_conversion_test.cpp

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,9 +1515,12 @@ TEST_F(ValidateConversion, BitcastPtrWrongInputType) {
15151515

15161516
CompileSuccessfully(GenerateKernelCode(body).c_str());
15171517
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1518-
EXPECT_THAT(getDiagnosticString(),
1519-
HasSubstr("Expected input to be a pointer or int scalar if "
1520-
"Result Type is pointer: Bitcast"));
1518+
EXPECT_THAT(
1519+
getDiagnosticString(),
1520+
HasSubstr("In SPIR-V 1.4 or earlier (and without "
1521+
"SPV_KHR_physical_storage_buffer), expected input to be a "
1522+
"pointer or int scalar if "
1523+
"Result Type is pointer: Bitcast"));
15211524
}
15221525

15231526
TEST_F(ValidateConversion, BitcastPtrWrongInputTypeSPV1p5) {
@@ -1528,9 +1531,12 @@ TEST_F(ValidateConversion, BitcastPtrWrongInputTypeSPV1p5) {
15281531
CompileSuccessfully(GenerateKernelCode(body).c_str(), SPV_ENV_UNIVERSAL_1_5);
15291532
ASSERT_EQ(SPV_ERROR_INVALID_DATA,
15301533
ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
1531-
EXPECT_THAT(getDiagnosticString(),
1532-
HasSubstr("Expected input to be a pointer, int scalar or 32-bit "
1533-
"int vector if Result Type is pointer: Bitcast"));
1534+
EXPECT_THAT(
1535+
getDiagnosticString(),
1536+
HasSubstr("In SPIR-V 1.5 or later (or with "
1537+
"SPV_KHR_physical_storage_buffer), expected input to be a "
1538+
"pointer, int scalar or 32-bit "
1539+
"int vector if Result Type is pointer: Bitcast"));
15341540
}
15351541

15361542
TEST_F(ValidateConversion, BitcastPtrWrongInputTypePhysicalStorageBufferKHR) {
@@ -1543,9 +1549,12 @@ TEST_F(ValidateConversion, BitcastPtrWrongInputTypePhysicalStorageBufferKHR) {
15431549
"\nOpExtension \"SPV_KHR_physical_storage_buffer\"")
15441550
.c_str());
15451551
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1546-
EXPECT_THAT(getDiagnosticString(),
1547-
HasSubstr("Expected input to be a pointer, int scalar or 32-bit "
1548-
"int vector if Result Type is pointer: Bitcast"));
1552+
EXPECT_THAT(
1553+
getDiagnosticString(),
1554+
HasSubstr("In SPIR-V 1.5 or later (or with "
1555+
"SPV_KHR_physical_storage_buffer), expected input to be a "
1556+
"pointer, int scalar or 32-bit "
1557+
"int vector if Result Type is pointer: Bitcast"));
15491558
}
15501559

15511560
TEST_F(ValidateConversion, BitcastPtrWrongInputTypeIntVectorSPV1p5) {
@@ -1556,9 +1565,12 @@ TEST_F(ValidateConversion, BitcastPtrWrongInputTypeIntVectorSPV1p5) {
15561565
CompileSuccessfully(GenerateKernelCode(body).c_str(), SPV_ENV_UNIVERSAL_1_5);
15571566
ASSERT_EQ(SPV_ERROR_INVALID_DATA,
15581567
ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
1559-
EXPECT_THAT(getDiagnosticString(),
1560-
HasSubstr("Expected input to be a pointer, int scalar or 32-bit "
1561-
"int vector if Result Type is pointer: Bitcast"));
1568+
EXPECT_THAT(
1569+
getDiagnosticString(),
1570+
HasSubstr("In SPIR-V 1.5 or later (or with "
1571+
"SPV_KHR_physical_storage_buffer), expected input to be a "
1572+
"pointer, int scalar or 32-bit "
1573+
"int vector if Result Type is pointer: Bitcast"));
15621574
}
15631575

15641576
TEST_F(ValidateConversion,
@@ -1572,9 +1584,12 @@ TEST_F(ValidateConversion,
15721584
"\nOpExtension \"SPV_KHR_physical_storage_buffer\"")
15731585
.c_str());
15741586
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1575-
EXPECT_THAT(getDiagnosticString(),
1576-
HasSubstr("Expected input to be a pointer, int scalar or 32-bit "
1577-
"int vector if Result Type is pointer: Bitcast"));
1587+
EXPECT_THAT(
1588+
getDiagnosticString(),
1589+
HasSubstr("In SPIR-V 1.5 or later (or with "
1590+
"SPV_KHR_physical_storage_buffer), expected input to be a "
1591+
"pointer, int scalar or 32-bit "
1592+
"int vector if Result Type is pointer: Bitcast"));
15781593
}
15791594

15801595
TEST_F(ValidateConversion, BitcastPtrWrongResultType) {
@@ -1585,7 +1600,9 @@ TEST_F(ValidateConversion, BitcastPtrWrongResultType) {
15851600
CompileSuccessfully(GenerateKernelCode(body).c_str());
15861601
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
15871602
EXPECT_THAT(getDiagnosticString(),
1588-
HasSubstr("Pointer can only be converted to another pointer or "
1603+
HasSubstr("In SPIR-V 1.4 or earlier (and without "
1604+
"SPV_KHR_physical_storage_buffer), pointer can only be "
1605+
"converted to another pointer or "
15891606
"int scalar: Bitcast"));
15901607
}
15911608

@@ -1597,9 +1614,13 @@ TEST_F(ValidateConversion, BitcastPtrWrongResultTypeSPV1p5) {
15971614
CompileSuccessfully(GenerateKernelCode(body).c_str(), SPV_ENV_UNIVERSAL_1_5);
15981615
ASSERT_EQ(SPV_ERROR_INVALID_DATA,
15991616
ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
1600-
EXPECT_THAT(getDiagnosticString(),
1601-
HasSubstr("Pointer can only be converted to another pointer, int "
1602-
"scalar or 32-bit int vector: Bitcast"));
1617+
EXPECT_THAT(
1618+
getDiagnosticString(),
1619+
HasSubstr(
1620+
"In SPIR-V 1.5 or later (or with SPV_KHR_physical_storage_buffer), "
1621+
"pointer can only be converted "
1622+
"to another pointer, int "
1623+
"scalar or 32-bit int vector: Bitcast"));
16031624
}
16041625

16051626
TEST_F(ValidateConversion, BitcastPtrWrongResultTypePhysicalStorageBufferKHR) {
@@ -1612,9 +1633,13 @@ TEST_F(ValidateConversion, BitcastPtrWrongResultTypePhysicalStorageBufferKHR) {
16121633
"\nOpExtension \"SPV_KHR_physical_storage_buffer\"")
16131634
.c_str());
16141635
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1615-
EXPECT_THAT(getDiagnosticString(),
1616-
HasSubstr("Pointer can only be converted to another pointer, int "
1617-
"scalar or 32-bit int vector: Bitcast"));
1636+
EXPECT_THAT(
1637+
getDiagnosticString(),
1638+
HasSubstr(
1639+
"In SPIR-V 1.5 or later (or with SPV_KHR_physical_storage_buffer), "
1640+
"pointer can only be converted "
1641+
"to another pointer, int "
1642+
"scalar or 32-bit int vector: Bitcast"));
16181643
}
16191644

16201645
TEST_F(ValidateConversion, BitcastPtrWrongResultTypeIntVectorSPV1p5) {
@@ -1625,9 +1650,13 @@ TEST_F(ValidateConversion, BitcastPtrWrongResultTypeIntVectorSPV1p5) {
16251650
CompileSuccessfully(GenerateKernelCode(body).c_str(), SPV_ENV_UNIVERSAL_1_5);
16261651
ASSERT_EQ(SPV_ERROR_INVALID_DATA,
16271652
ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
1628-
EXPECT_THAT(getDiagnosticString(),
1629-
HasSubstr("Pointer can only be converted to another pointer, int "
1630-
"scalar or 32-bit int vector: Bitcast"));
1653+
EXPECT_THAT(
1654+
getDiagnosticString(),
1655+
HasSubstr(
1656+
"In SPIR-V 1.5 or later (or with SPV_KHR_physical_storage_buffer), "
1657+
"pointer can only be converted "
1658+
"to another pointer, int "
1659+
"scalar or 32-bit int vector: Bitcast"));
16311660
}
16321661

16331662
TEST_F(ValidateConversion,
@@ -1641,9 +1670,13 @@ TEST_F(ValidateConversion,
16411670
"\nOpExtension \"SPV_KHR_physical_storage_buffer\"")
16421671
.c_str());
16431672
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1644-
EXPECT_THAT(getDiagnosticString(),
1645-
HasSubstr("Pointer can only be converted to another pointer, int "
1646-
"scalar or 32-bit int vector: Bitcast"));
1673+
EXPECT_THAT(
1674+
getDiagnosticString(),
1675+
HasSubstr(
1676+
"In SPIR-V 1.5 or later (or with SPV_KHR_physical_storage_buffer), "
1677+
"pointer can only be converted "
1678+
"to another pointer, int "
1679+
"scalar or 32-bit int vector: Bitcast"));
16471680
}
16481681

16491682
TEST_F(ValidateConversion, BitcastDifferentTotalBitWidth) {

test/val/val_decoration_test.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "gmock/gmock.h"
2323
#include "source/val/decoration.h"
24+
#include "spirv-tools/libspirv.h"
2425
#include "test/unit_spirv.h"
2526
#include "test/val/val_code_generator.h"
2627
#include "test/val/val_fixtures.h"
@@ -9538,9 +9539,9 @@ OpFunctionEnd
95389539

95399540
CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_4);
95409541
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
9541-
EXPECT_THAT(
9542-
getDiagnosticString(),
9543-
HasSubstr("Non-unique OpEntryPoint interface '2[%var]' is disallowed"));
9542+
EXPECT_THAT(getDiagnosticString(),
9543+
HasSubstr("In SPIR-V 1.4 or later, non-unique OpEntryPoint "
9544+
"interface '2[%var]' is disallowed"));
95449545
}
95459546

95469547
TEST_F(ValidateDecorations, PhysicalStorageBufferMissingOffset) {

test/val/val_interfaces_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ OpFunctionEnd
215215

216216
CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
217217
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
218-
EXPECT_THAT(
219-
getDiagnosticString(),
220-
HasSubstr("Non-unique OpEntryPoint interface '2[%var]' is disallowed"));
218+
EXPECT_THAT(getDiagnosticString(),
219+
HasSubstr("In SPIR-V 1.4 or later, non-unique OpEntryPoint "
220+
"interface '2[%var]' is disallowed"));
221221
}
222222

223223
TEST_F(ValidateInterfacesTest, MissingGlobalVarSPV1p3) {

test/val/val_mesh_shading_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,8 @@ TEST_F(ValidateMeshShading, BadMultipleTaskPayloadWorkgroupEXT) {
488488
CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
489489
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
490490
EXPECT_THAT(getDiagnosticString(),
491-
HasSubstr("There can be at most one OpVariable with storage "
491+
HasSubstr("There can be at most one "
492+
"OpVariable with storage "
492493
"class TaskPayloadWorkgroupEXT associated with "
493494
"an OpEntryPoint"));
494495
}

0 commit comments

Comments
 (0)