layers: Require every input attachment used by FS to be present.
authorChris Forbes <chrisforbes@google.com>
Mon, 22 Aug 2016 03:20:11 +0000 (15:20 +1200)
committerChris Forbes <chrisforbes@google.com>
Tue, 23 Aug 2016 01:12:40 +0000 (13:12 +1200)
Signed-off-by: Chris Forbes <chrisforbes@google.com>
layers/core_validation.cpp
layers/core_validation_error_enums.h

index aa305d0..cf772cf 100644 (file)
@@ -2780,6 +2780,32 @@ static bool validate_pipeline_shader_stage(debug_report_data *report_data,
         }
     }
 
+    /* validate use of input attachments against subpass structure */
+    if (pStage->stage == VK_SHADER_STAGE_FRAGMENT_BIT) {
+        std::vector<std::pair<uint32_t, interface_var>> input_attachment_uses;
+        collect_interface_by_input_attachment_index(report_data, module, accessible_ids, input_attachment_uses);
+
+        auto rpci = pipeline->render_pass_ci.ptr();
+        auto subpass = pipeline->graphicsPipelineCI.subpass;
+
+        for (auto use : input_attachment_uses) {
+            auto input_attachments = rpci->pSubpasses[subpass].pInputAttachments;
+            auto index = (input_attachments && use.first < rpci->pSubpasses[subpass].inputAttachmentCount) ?
+                    input_attachments[use.first].attachment : VK_ATTACHMENT_UNUSED;
+
+            if (index == VK_ATTACHMENT_UNUSED) {
+                if (log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VkDebugReportObjectTypeEXT(0), 0, __LINE__,
+                            SHADER_CHECKER_MISSING_INPUT_ATTACHMENT, "SC",
+                            "Shader consumes input attachment index %d but not provided in subpass",
+                            use.first)) {
+                    pass = false;
+                }
+            }
+
+            /* TODO: type match, etc */
+        }
+    }
+
     return pass;
 }
 
index 56a8b2c..2ee0420 100644 (file)
@@ -243,6 +243,7 @@ enum SHADER_CHECKER_ERROR {
     SHADER_CHECKER_DESCRIPTOR_NOT_ACCESSIBLE_FROM_STAGE,    // Descriptor used by shader, but not accessible from stage
     SHADER_CHECKER_FEATURE_NOT_ENABLED,                     // Shader uses capability requiring a feature not enabled on device
     SHADER_CHECKER_BAD_CAPABILITY,                          // Shader uses capability not supported by Vulkan (OpenCL features)
+    SHADER_CHECKER_MISSING_INPUT_ATTACHMENT,   // Shader uses an input attachment but not declared in subpass
 };
 
 // Device Limits ERROR codes