aboutsummaryrefslogtreecommitdiff
path: root/source/val/validate_decorations.cpp
diff options
context:
space:
mode:
authorAlan Baker <alanbaker@google.com>2018-07-25 14:00:04 -0400
committerDavid Neto <dneto@google.com>2018-09-21 21:55:01 -0400
commit90a12b3d4d1d589b3d61c194f983eb9c22459226 (patch)
treeb283dcb682ec069a3e5e5b45a080616e4fceb423 /source/val/validate_decorations.cpp
parent1492111332bae7fd2e60e8678fab48eb81962fd4 (diff)
downloadSPIRV-Tools-90a12b3d4d1d589b3d61c194f983eb9c22459226.tar.gz
Decoration validation for Vulkan memory model
* Adds a check that using Coherent or Volatile decorations with the Vulkan memory model is a validation error * Adds tests
Diffstat (limited to 'source/val/validate_decorations.cpp')
-rw-r--r--source/val/validate_decorations.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/source/val/validate_decorations.cpp b/source/val/validate_decorations.cpp
index ed312f73..cfb38ef7 100644
--- a/source/val/validate_decorations.cpp
+++ b/source/val/validate_decorations.cpp
@@ -840,6 +840,34 @@ spv_result_t CheckDecorationsOfBuffers(ValidationState_t& vstate) {
return SPV_SUCCESS;
}
+spv_result_t CheckVulkanMemoryModelDeprecatedDecorations(
+ ValidationState_t& vstate) {
+ if (vstate.memory_model() != SpvMemoryModelVulkanKHR) return SPV_SUCCESS;
+
+ std::string msg;
+ std::ostringstream str(msg);
+ for (const auto& def : vstate.all_definitions()) {
+ const auto inst = def.second;
+ const auto id = inst->id();
+ for (const auto& dec : vstate.id_decorations(id)) {
+ const auto member = dec.struct_member_index();
+ if (dec.dec_type() == SpvDecorationCoherent ||
+ dec.dec_type() == SpvDecorationVolatile) {
+ str << (dec.dec_type() == SpvDecorationCoherent ? "Coherent"
+ : "Volatile");
+ str << " decoration targeting " << vstate.getIdName(id);
+ if (member != Decoration::kInvalidMember) {
+ str << " (member index " << member << ")";
+ }
+ str << " is banned when using the Vulkan memory model.";
+ return vstate.diag(SPV_ERROR_INVALID_ID, inst) << str.str();
+ }
+ }
+ }
+
+ return SPV_SUCCESS;
+}
+
} // namespace
// Validates that decorations have been applied properly.
@@ -849,6 +877,8 @@ spv_result_t ValidateDecorations(ValidationState_t& vstate) {
if (auto error = CheckDecorationsOfBuffers(vstate)) return error;
if (auto error = CheckLinkageAttrOfFunctions(vstate)) return error;
if (auto error = CheckDescriptorSetArrayOfArrays(vstate)) return error;
+ if (auto error = CheckVulkanMemoryModelDeprecatedDecorations(vstate))
+ return error;
return SPV_SUCCESS;
}