1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2017 The Khronos Group Inc.
6 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 * \brief Protected content clear color image tests
23 *//*--------------------------------------------------------------------*/
25 #include "vktProtectedMemClearColorImageTests.hpp"
27 #include "deRandom.hpp"
28 #include "tcuTestLog.hpp"
29 #include "tcuVector.hpp"
30 #include "tcuVectorUtil.hpp"
32 #include "vkPrograms.hpp"
33 #include "vktTestCase.hpp"
34 #include "vktTestGroupUtil.hpp"
35 #include "vkTypeUtil.hpp"
36 #include "vkBuilderUtil.hpp"
37 #include "vkCmdUtil.hpp"
39 #include "vktProtectedMemContext.hpp"
40 #include "vktProtectedMemUtils.hpp"
41 #include "vktProtectedMemImageValidator.hpp"
45 namespace ProtectedMem
56 class ClearColorImageTestInstance : public ProtectedTestInstance
59 ClearColorImageTestInstance (Context& ctx,
60 const vk::VkClearColorValue& clearColorValue,
61 const ValidationData& refData,
62 const ImageValidator& validator,
63 const CmdBufferType cmdBufferType);
64 virtual tcu::TestStatus iterate (void);
67 const vk::VkFormat m_imageFormat;
68 const vk::VkClearColorValue& m_clearColorValue;
69 const ValidationData& m_refData;
70 const ImageValidator& m_validator;
71 const CmdBufferType m_cmdBufferType;
74 class ClearColorImageTestCase : public TestCase
77 ClearColorImageTestCase (tcu::TestContext& testCtx,
78 const std::string& name,
79 vk::VkClearColorValue clearColorValue,
81 CmdBufferType cmdBufferType)
82 : TestCase (testCtx, name, "Clear color image.")
83 , m_clearColorValue (clearColorValue)
85 , m_cmdBufferType (cmdBufferType)
89 virtual ~ClearColorImageTestCase (void) {}
90 virtual TestInstance* createInstance (Context& ctx) const
92 return new ClearColorImageTestInstance(ctx, m_clearColorValue, m_refData, m_validator, m_cmdBufferType);
94 virtual void initPrograms (vk::SourceCollections& programCollection) const
96 m_validator.initPrograms(programCollection);
99 vk::VkClearColorValue m_clearColorValue;
100 ValidationData m_refData;
101 ImageValidator m_validator;
102 CmdBufferType m_cmdBufferType;
105 ClearColorImageTestInstance::ClearColorImageTestInstance (Context& ctx,
106 const vk::VkClearColorValue& clearColorValue,
107 const ValidationData& refData,
108 const ImageValidator& validator,
109 const CmdBufferType cmdBufferType)
110 : ProtectedTestInstance (ctx)
111 , m_imageFormat (vk::VK_FORMAT_R8G8B8A8_UNORM)
112 , m_clearColorValue (clearColorValue)
113 , m_refData (refData)
114 , m_validator (validator)
115 , m_cmdBufferType (cmdBufferType)
119 tcu::TestStatus ClearColorImageTestInstance::iterate()
121 ProtectedContext& ctx (m_protectedContext);
122 const vk::DeviceInterface& vk = ctx.getDeviceInterface();
123 const vk::VkDevice device = ctx.getDevice();
124 const vk::VkQueue queue = ctx.getQueue();
125 const deUint32 queueFamilyIndex = ctx.getQueueFamilyIndex();
127 // Create output image
128 de::MovePtr<vk::ImageWithMemory> colorImage = createImage2D(ctx, PROTECTION_ENABLED, queueFamilyIndex,
129 RENDER_WIDTH, RENDER_HEIGHT,
130 vk::VK_FORMAT_R8G8B8A8_UNORM,
131 vk::VK_IMAGE_USAGE_TRANSFER_DST_BIT|vk::VK_IMAGE_USAGE_SAMPLED_BIT);
133 vk::Unique<vk::VkPipelineLayout> pipelineLayout (createPipelineLayout(ctx, 0u, DE_NULL));
135 vk::Unique<vk::VkCommandPool> cmdPool (makeCommandPool(vk, device, PROTECTION_ENABLED, queueFamilyIndex));
136 vk::Unique<vk::VkCommandBuffer> cmdBuffer (vk::allocateCommandBuffer(vk, device, *cmdPool, vk::VK_COMMAND_BUFFER_LEVEL_PRIMARY));
137 vk::Unique<vk::VkCommandBuffer> secondaryCmdBuffer (vk::allocateCommandBuffer(vk, device, *cmdPool, vk::VK_COMMAND_BUFFER_LEVEL_SECONDARY));
138 vk::VkCommandBuffer targetCmdBuffer = (m_cmdBufferType == CMD_BUFFER_SECONDARY) ? *secondaryCmdBuffer : *cmdBuffer;
140 const vk::VkImageSubresourceRange subresourceRange =
142 vk::VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask
143 0u, // uint32_t baseMipLevel
144 1u, // uint32_t levelCount
145 0u, // uint32_t baseArrayLayer
146 1u, // uint32_t layerCount
149 beginCommandBuffer(vk, *cmdBuffer);
151 if (m_cmdBufferType == CMD_BUFFER_SECONDARY)
153 // Begin secondary command buffer
154 const vk::VkCommandBufferInheritanceInfo bufferInheritanceInfo =
156 vk::VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, // sType
158 DE_NULL, // renderPass
160 DE_NULL, // framebuffer
161 VK_FALSE, // occlusionQueryEnable
162 (vk::VkQueryControlFlags)0u, // queryFlags
163 (vk::VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
165 beginSecondaryCommandBuffer(vk, *secondaryCmdBuffer, bufferInheritanceInfo);
168 // Start image barrier
170 const vk::VkImageMemoryBarrier initializeBarrier =
172 vk::VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
175 vk::VK_ACCESS_TRANSFER_WRITE_BIT, // dstAccessMask
176 vk::VK_IMAGE_LAYOUT_UNDEFINED, // oldLayout
177 vk::VK_IMAGE_LAYOUT_GENERAL, // newLayout
178 queueFamilyIndex, // srcQueueFamilyIndex
179 queueFamilyIndex, // dstQueueFamilyIndex
180 **colorImage, // image
181 subresourceRange, // subresourceRange
184 vk.cmdPipelineBarrier(targetCmdBuffer, // commandBuffer
185 vk::VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, // srcStageMask
186 vk::VK_PIPELINE_STAGE_TRANSFER_BIT, // dstStageMask
187 (vk::VkDependencyFlags)0, // dependencyFlags
188 0, (const vk::VkMemoryBarrier*)DE_NULL, // memoryBarrierCount, pMemoryBarriers
189 0, (const vk::VkBufferMemoryBarrier*)DE_NULL, // bufferMemoryBarrierCount, pBufferMemoryBarriers
190 1, &initializeBarrier); // imageMemoryBarrierCount, pImageMemoryBarriers
194 vk.cmdClearColorImage(targetCmdBuffer, **colorImage, vk::VK_IMAGE_LAYOUT_GENERAL, &m_clearColorValue, 1, &subresourceRange);
196 // Image barrier to change accessMask.
198 const vk::VkImageMemoryBarrier initializeBarrier =
200 vk::VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
202 vk::VK_ACCESS_TRANSFER_WRITE_BIT, // srcAccessMask
203 vk::VK_ACCESS_SHADER_READ_BIT, // dstAccessMask
204 vk::VK_IMAGE_LAYOUT_GENERAL, // oldLayout
205 vk::VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, // newLayout
206 queueFamilyIndex, // srcQueueFamilyIndex
207 queueFamilyIndex, // dstQueueFamilyIndex
208 **colorImage, // image
209 subresourceRange // subresourceRange
211 vk.cmdPipelineBarrier(targetCmdBuffer,
212 vk::VK_PIPELINE_STAGE_TRANSFER_BIT, // srcStageMask
213 vk::VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, // dstStageMask
214 (vk::VkDependencyFlags)0,
215 0, (const vk::VkMemoryBarrier*)DE_NULL,
216 0, (const vk::VkBufferMemoryBarrier*)DE_NULL,
217 1, &initializeBarrier);
220 if (m_cmdBufferType == CMD_BUFFER_SECONDARY)
222 endCommandBuffer(vk, *secondaryCmdBuffer);
223 vk.cmdExecuteCommands(*cmdBuffer, 1u, &secondaryCmdBuffer.get());
226 endCommandBuffer(vk, *cmdBuffer);
228 // Submit command buffer
229 const vk::Unique<vk::VkFence> fence (vk::createFence(vk, device));
230 VK_CHECK(queueSubmit(ctx, PROTECTION_ENABLED, queue, *cmdBuffer, *fence, ~0ull));
233 ctx.getTestContext().getLog()
234 << tcu::TestLog::Message << "Color clear value: " << tcu::Vec4(m_clearColorValue.float32) << tcu::TestLog::EndMessage;
236 // Validate resulting image
237 if (m_validator.validateImage(ctx, m_refData, **colorImage, m_imageFormat, vk::VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL))
238 return tcu::TestStatus::pass("Everything went OK");
240 return tcu::TestStatus::fail("Something went really wrong");
243 tcu::TestCaseGroup* createClearColorImageTests (tcu::TestContext& testCtx, CmdBufferType cmdBufferType)
246 vk::VkClearColorValue clearColorValue;
249 { { { 1.0f, 0.0f, 0.0f, 1.0f } },
251 { tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 0.0f, 0.0f),
252 tcu::Vec4(0.1f, 0.1f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.0f, 0.0f), },
253 { tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f),
254 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), }
257 { { { 0.0f, 1.0f, 0.0f, 1.0f } },
259 { tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 0.0f, 0.0f),
260 tcu::Vec4(0.1f, 0.1f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.0f, 0.0f), },
261 { tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f),
262 tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), }
265 { { { 0.0f, 0.0f, 1.0f, 1.0f } },
267 { tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 0.0f, 0.0f),
268 tcu::Vec4(0.1f, 0.1f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.0f, 0.0f), },
269 { tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f),
270 tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), }
273 { { { 0.0f, 0.0f, 0.0f, 1.0f } },
275 { tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 0.0f, 0.0f),
276 tcu::Vec4(0.1f, 0.1f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.0f, 0.0f), },
277 { tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f),
278 tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), }
281 { { { 1.0f, 0.0f, 0.0f, 1.0f } },
283 { tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 0.0f, 0.0f),
284 tcu::Vec4(0.1f, 0.1f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.0f, 0.0f), },
285 { tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f),
286 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), }
289 { { { 1.0f, 0.0f, 0.0f, 0.0f } },
291 { tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 0.0f, 0.0f),
292 tcu::Vec4(0.1f, 0.1f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.0f, 0.0f), },
293 { tcu::Vec4(1.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 0.0f, 0.0f, 0.0f),
294 tcu::Vec4(1.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 0.0f, 0.0f, 0.0f), }
297 { { { 0.1f, 0.2f, 0.3f, 0.0f } },
299 { tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 0.0f, 0.0f),
300 tcu::Vec4(0.1f, 0.1f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.0f, 0.0f), },
301 { tcu::Vec4(0.1f, 0.2f, 0.3f, 0.0f), tcu::Vec4(0.1f, 0.2f, 0.3f, 0.0f),
302 tcu::Vec4(0.1f, 0.2f, 0.3f, 0.0f), tcu::Vec4(0.1f, 0.2f, 0.3f, 0.0f), }
307 de::MovePtr<tcu::TestCaseGroup> clearStaticTests (new tcu::TestCaseGroup(testCtx, "static", "Clear Color Image Tests with static input"));
309 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(testData); ++ndx)
311 const std::string name = "clear_" + de::toString(ndx + 1);
312 clearStaticTests->addChild(new ClearColorImageTestCase(testCtx, name.c_str(), testData[ndx].clearColorValue, testData[ndx].data, cmdBufferType));
315 /* Add a few randomized tests */
316 de::MovePtr<tcu::TestCaseGroup> clearRandomTests (new tcu::TestCaseGroup(testCtx, "random", "Clear Color Image Tests with random input"));
317 const int testCount = 10;
318 de::Random rnd (testCtx.getCommandLine().getBaseSeed());
319 for (int ndx = 0; ndx < testCount; ++ndx)
321 const std::string name = "clear_" + de::toString(ndx + 1);
322 vk::VkClearValue clearValue = vk::makeClearValueColorVec4(tcu::randomVec4(rnd));
323 const tcu::Vec4 refValue (clearValue.color.float32[0], clearValue.color.float32[1], clearValue.color.float32[2], clearValue.color.float32[3]);
324 const tcu::Vec4 vec0 = tcu::randomVec4(rnd);
325 const tcu::Vec4 vec1 = tcu::randomVec4(rnd);
326 const tcu::Vec4 vec2 = tcu::randomVec4(rnd);
327 const tcu::Vec4 vec3 = tcu::randomVec4(rnd);
329 ValidationData data =
331 { vec0, vec1, vec2, vec3 },
332 { refValue, refValue, refValue, refValue }
334 clearRandomTests->addChild(new ClearColorImageTestCase(testCtx, name.c_str(), clearValue.color, data, cmdBufferType));
337 std::string groupName = getCmdBufferTypeStr(cmdBufferType);
338 std::string groupDesc = "Clear Color Image Tests with " + groupName + " command buffer";
339 de::MovePtr<tcu::TestCaseGroup> clearTests (new tcu::TestCaseGroup(testCtx, groupName.c_str(), groupDesc.c_str()));
340 clearTests->addChild(clearStaticTests.release());
341 clearTests->addChild(clearRandomTests.release());
342 return clearTests.release();
347 tcu::TestCaseGroup* createClearColorImageTests (tcu::TestContext& testCtx)
349 de::MovePtr<tcu::TestCaseGroup> clearTests (new tcu::TestCaseGroup(testCtx, "clear_color", "Clear Color Image Tests"));
351 clearTests->addChild(createClearColorImageTests(testCtx, CMD_BUFFER_PRIMARY));
352 clearTests->addChild(createClearColorImageTests(testCtx, CMD_BUFFER_SECONDARY));
354 return clearTests.release();