Skip to content

Commit

Permalink
tests: Add test file for BP and move 1 test
Browse files Browse the repository at this point in the history
Fix formatting issue

Change-Id: I40d125805b7d41da7a4715e194dbe945e4f91591
  • Loading branch information
camden-lunarg committed Nov 8, 2019
1 parent ca8f9cb commit 29b16be
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
5 changes: 3 additions & 2 deletions layers/best_practices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,12 +812,13 @@ void BestPractices::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindIn
}

bool BestPractices::PreCallValidateCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
const VkClearAttachment* pAttachments, uint32_t rectCount, const VkClearRect* pRects) {
const VkClearAttachment* pAttachments, uint32_t rectCount,
const VkClearRect* pRects) const {
bool skip = false;
const CMD_BUFFER_STATE* cb_node = GetCBState(commandBuffer);
if (!cb_node) return skip;

// Warn if this is issued prior to Draw Cmd and clearing the entire attachment
// Warn if this is issued prior to Draw Cmd and clearing the entire attachment
if (!cb_node->hasDrawCmd && (cb_node->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
(cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
// There are times where app needs to use ClearAttachments (generally when reusing a buffer inside of a render pass)
Expand Down
51 changes: 51 additions & 0 deletions tests/vklayertests_best_practices.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2015-2019 The Khronos Group Inc.
* Copyright (c) 2015-2019 Valve Corporation
* Copyright (c) 2015-2019 LunarG, Inc.
* Copyright (c) 2015-2019 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Author: Camden Stocker <[email protected]>
*/

#include "cast_utils.h"
#include "layer_validation_tests.h"

TEST_F(VkLayerTest, CmdClearAttachmentTest) {
TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");

VkValidationFeatureEnableEXT enables[] = {VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT};
VkValidationFeaturesEXT features = {};
features.sType = VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT;
features.enabledValidationFeatureCount = 1;
features.pEnabledValidationFeatures = enables;
InitFramework(myDbgFunc, m_errorMonitor, &features);
InitState();
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());

m_commandBuffer->begin();
m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);

// Main thing we care about for this test is that the VkImage obj we're
// clearing matches Color Attachment of FB
// Also pass down other dummy params to keep driver and paramchecker happy
VkClearAttachment color_attachment;
color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
color_attachment.clearValue.color.float32[0] = 1.0;
color_attachment.clearValue.color.float32[1] = 1.0;
color_attachment.clearValue.color.float32[2] = 1.0;
color_attachment.clearValue.color.float32[3] = 1.0;
color_attachment.colorAttachment = 0;
VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}, 0, 1};

// Call for full-sized FB Color attachment prior to issuing a Draw
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
"UNASSIGNED-CoreValidation-DrawState-ClearCmdBeforeDraw");
vk::CmdClearAttachments(m_commandBuffer->handle(), 1, &color_attachment, 1, &clear_rect);
m_errorMonitor->VerifyFound();
}
6 changes: 0 additions & 6 deletions tests/vklayertests_pipeline_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2564,12 +2564,6 @@ TEST_F(VkLayerTest, CmdClearAttachmentTests) {
color_attachment.colorAttachment = 0;
VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}, 0, 1};

// Call for full-sized FB Color attachment prior to issuing a Draw
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
"UNASSIGNED-CoreValidation-DrawState-ClearCmdBeforeDraw");
vk::CmdClearAttachments(m_commandBuffer->handle(), 1, &color_attachment, 1, &clear_rect);
m_errorMonitor->VerifyFound();

clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearAttachments-pRects-00016");
Expand Down

0 comments on commit 29b16be

Please sign in to comment.