New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extension allows multiple same OpTypePointer types #783
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
#include "val/validation_state.h" | ||
|
||
#include <cassert> | ||
#include <map> | ||
|
||
#include "opcode.h" | ||
#include "val/basic_block.h" | ||
|
@@ -425,6 +426,22 @@ bool ValidationState_t::RegisterUniqueTypeDeclaration( | |
key.insert(key.end(), inst.words + words_begin, inst.words + words_end); | ||
} | ||
|
||
if (inst.opcode == SpvOpTypePointer && | ||
HasExtension(Extension::kSPV_KHR_variable_pointers)) { | ||
const std::vector<Decoration>& decorations = id_decorations(inst.result_id); | ||
std::map<SpvDecoration, const std::vector<uint32_t>*> decoration_params; | ||
for (const auto& decoration : decorations) { | ||
const auto result = decoration_params.emplace(decoration.dec_type(), | ||
&decoration.params()); | ||
(void)result; | ||
assert(result.second); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you should assert here? There's nothing wrong with redundant decorations, except that it wastes space. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's worth saying you're assuming that a single decoration enum can only be set once per target ID. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will assume that decorations are not unique, but only use the last one. |
||
} | ||
for (const auto& kv : decoration_params) { | ||
key.push_back(static_cast<uint32_t>(kv.first)); | ||
key.insert(key.end(), kv.second->begin(), kv.second->end()); | ||
} | ||
} | ||
|
||
return unique_type_declarations_.insert(std::move(key)).second; | ||
} | ||
} /// namespace libspirv |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ spv_result_t TypeUniquePass(ValidationState_t& _, | |
// return _.diag(SPV_ERROR_INVALID_DATA) | ||
return _.diag(SPV_SUCCESS) | ||
<< "Duplicate non-aggregate type declarations are not allowed." | ||
<< " Opcode: " << inst->opcode; | ||
<< " Opcode: " << spvOpcodeString(SpvOp(inst->opcode)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an improvement. But in actual practice I've found having the ID generated by this instruction is easier to work with. It pinpoints the exact instruction at fault. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ OpFunctionEnd | |
// declaration. | ||
string GetErrorString(SpvOp opcode) { | ||
return "Duplicate non-aggregate type declarations are not allowed. Opcode: " | ||
+ std::to_string(opcode); | ||
+ std::string(spvOpcodeString(opcode)); | ||
} | ||
|
||
TEST_F(ValidateTypeUnique, success) { | ||
|
@@ -238,4 +238,57 @@ OpMemoryModel Physical32 OpenCL | |
Not(HasSubstr(GetErrorString(SpvOpTypeVoid)))); | ||
} | ||
|
||
TEST_F(ValidateTypeUnique, PointerTypesSameArrayStrideNoExtension) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test name is misleading to me: The array strides here are different, but the test name is ....SameArrayStride... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CopyPaste |
||
string str = R"( | ||
OpCapability Shader | ||
OpCapability Linkage | ||
OpMemoryModel Logical GLSL450 | ||
OpDecorate %ptr1 ArrayStride 4 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe you just have a typo here? |
||
OpDecorate %ptr2 ArrayStride 8 | ||
%u32 = OpTypeInt 32 0 | ||
%ptr1 = OpTypePointer Input %u32 | ||
%ptr2 = OpTypePointer Input %u32 | ||
)"; | ||
CompileSuccessfully(str.c_str()); | ||
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); | ||
EXPECT_THAT(getDiagnosticString(), | ||
HasSubstr(GetErrorString(SpvOpTypePointer))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused. The validation succeeds, but generates an error string? Does this test even pass? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It logs a warning but returns SPV_SUCCESS. |
||
} | ||
|
||
TEST_F(ValidateTypeUnique, PointerTypesDifferentArrayStride) { | ||
string str = R"( | ||
OpCapability Shader | ||
OpCapability Linkage | ||
OpExtension "SPV_KHR_variable_pointers" | ||
OpMemoryModel Logical GLSL450 | ||
OpDecorate %ptr1 ArrayStride 4 | ||
OpDecorate %ptr2 ArrayStride 8 | ||
%u32 = OpTypeInt 32 0 | ||
%ptr1 = OpTypePointer Input %u32 | ||
%ptr2 = OpTypePointer Input %u32 | ||
)"; | ||
CompileSuccessfully(str.c_str()); | ||
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); | ||
EXPECT_THAT(getDiagnosticString(), | ||
Not(HasSubstr(GetErrorString(SpvOpTypePointer)))); | ||
} | ||
|
||
TEST_F(ValidateTypeUnique, PointerTypesSameArrayStride) { | ||
string str = R"( | ||
OpCapability Shader | ||
OpCapability Linkage | ||
OpExtension "SPV_KHR_variable_pointers" | ||
OpMemoryModel Logical GLSL450 | ||
OpDecorate %ptr1 ArrayStride 4 | ||
OpDecorate %ptr2 ArrayStride 4 | ||
%u32 = OpTypeInt 32 0 | ||
%ptr1 = OpTypePointer Input %u32 | ||
%ptr2 = OpTypePointer Input %u32 | ||
)"; | ||
CompileSuccessfully(str.c_str()); | ||
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); | ||
EXPECT_THAT(getDiagnosticString(), | ||
HasSubstr(GetErrorString(SpvOpTypePointer))); | ||
} | ||
|
||
} // anonymous namespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to have a comment describing the rule you're enforcing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.