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"
31 #include "vkPrograms.hpp"
32 #include "vktTestCase.hpp"
33 #include "vktTestGroupUtil.hpp"
34 #include "vkTypeUtil.hpp"
35 #include "vkBuilderUtil.hpp"
36 #include "vkCmdUtil.hpp"
38 #include "vktProtectedMemContext.hpp"
39 #include "vktProtectedMemUtils.hpp"
40 #include "vktProtectedMemImageValidator.hpp"
44 namespace ProtectedMem
55 class ClearColorImageTestInstance : public ProtectedTestInstance
58 ClearColorImageTestInstance (Context& ctx,
59 const vk::VkClearColorValue& clearColorValue,
60 const ValidationData& refData,
61 const ImageValidator& validator,
62 const CmdBufferType cmdBufferType);
63 virtual tcu::TestStatus iterate (void);
66 const vk::VkFormat m_imageFormat;
67 const vk::VkClearColorValue& m_clearColorValue;
68 const ValidationData& m_refData;
69 const ImageValidator& m_validator;
70 const CmdBufferType m_cmdBufferType;
73 class ClearColorImageTestCase : public TestCase
76 ClearColorImageTestCase (tcu::TestContext& testCtx,
77 const std::string& name,
78 vk::VkClearColorValue clearColorValue,
80 CmdBufferType cmdBufferType)
81 : TestCase (testCtx, name, "Clear color image.")
82 , m_clearColorValue (clearColorValue)
84 , m_cmdBufferType (cmdBufferType)
88 virtual ~ClearColorImageTestCase (void) {}
89 virtual TestInstance* createInstance (Context& ctx) const
91 return new ClearColorImageTestInstance(ctx, m_clearColorValue, m_refData, m_validator, m_cmdBufferType);
93 virtual void initPrograms (vk::SourceCollections& programCollection) const
95 m_validator.initPrograms(programCollection);
98 vk::VkClearColorValue m_clearColorValue;
99 ValidationData m_refData;
100 ImageValidator m_validator;
101 CmdBufferType m_cmdBufferType;
104 ClearColorImageTestInstance::ClearColorImageTestInstance (Context& ctx,
105 const vk::VkClearColorValue& clearColorValue,
106 const ValidationData& refData,
107 const ImageValidator& validator,
108 const CmdBufferType cmdBufferType)
109 : ProtectedTestInstance (ctx)
110 , m_imageFormat (vk::VK_FORMAT_R8G8B8A8_UNORM)
111 , m_clearColorValue (clearColorValue)
112 , m_refData (refData)
113 , m_validator (validator)
114 , m_cmdBufferType (cmdBufferType)
118 tcu::TestStatus ClearColorImageTestInstance::iterate()
120 ProtectedContext& ctx (m_protectedContext);
121 const vk::DeviceInterface& vk = ctx.getDeviceInterface();
122 const vk::VkDevice device = ctx.getDevice();
123 const vk::VkQueue queue = ctx.getQueue();
124 const deUint32 queueFamilyIndex = ctx.getQueueFamilyIndex();
126 // Create output image
127 de::MovePtr<vk::ImageWithMemory> colorImage = createImage2D(ctx, PROTECTION_ENABLED, queueFamilyIndex,
128 RENDER_WIDTH, RENDER_HEIGHT,
129 vk::VK_FORMAT_R8G8B8A8_UNORM,
130 vk::VK_IMAGE_USAGE_TRANSFER_DST_BIT|vk::VK_IMAGE_USAGE_SAMPLED_BIT);
132 vk::Unique<vk::VkPipelineLayout> pipelineLayout (createPipelineLayout(ctx, 0u, DE_NULL));
134 vk::Unique<vk::VkCommandPool> cmdPool (makeCommandPool(vk, device, PROTECTION_ENABLED, queueFamilyIndex));
135 vk::Unique<vk::VkCommandBuffer> cmdBuffer (vk::allocateCommandBuffer(vk, device, *cmdPool, vk::VK_COMMAND_BUFFER_LEVEL_PRIMARY));
136 vk::Unique<vk::VkCommandBuffer> secondaryCmdBuffer (vk::allocateCommandBuffer(vk, device, *cmdPool, vk::VK_COMMAND_BUFFER_LEVEL_SECONDARY));
137 vk::VkCommandBuffer targetCmdBuffer = (m_cmdBufferType == CMD_BUFFER_SECONDARY) ? *secondaryCmdBuffer : *cmdBuffer;
139 const vk::VkImageSubresourceRange subresourceRange =
141 vk::VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask
142 0u, // uint32_t baseMipLevel
143 1u, // uint32_t levelCount
144 0u, // uint32_t baseArrayLayer
145 1u, // uint32_t layerCount
148 beginCommandBuffer(vk, *cmdBuffer);
150 if (m_cmdBufferType == CMD_BUFFER_SECONDARY)
152 // Begin secondary command buffer
153 const vk::VkCommandBufferInheritanceInfo bufferInheritanceInfo =
155 vk::VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, // sType
157 DE_NULL, // renderPass
159 DE_NULL, // framebuffer
160 VK_FALSE, // occlusionQueryEnable
161 (vk::VkQueryControlFlags)0u, // queryFlags
162 (vk::VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
164 beginSecondaryCommandBuffer(vk, *secondaryCmdBuffer, bufferInheritanceInfo);
167 // Start image barrier
169 const vk::VkImageMemoryBarrier initializeBarrier =
171 vk::VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
174 vk::VK_ACCESS_TRANSFER_WRITE_BIT, // dstAccessMask
175 vk::VK_IMAGE_LAYOUT_UNDEFINED, // oldLayout
176 vk::VK_IMAGE_LAYOUT_GENERAL, // newLayout
177 queueFamilyIndex, // srcQueueFamilyIndex
178 queueFamilyIndex, // dstQueueFamilyIndex
179 **colorImage, // image
180 subresourceRange, // subresourceRange
183 vk.cmdPipelineBarrier(targetCmdBuffer,
184 vk::VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
185 vk::VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,
186 (vk::VkDependencyFlags)0,
187 0, (const vk::VkMemoryBarrier*)DE_NULL,
188 0, (const vk::VkBufferMemoryBarrier*)DE_NULL,
189 1, &initializeBarrier);
193 vk.cmdClearColorImage(targetCmdBuffer, **colorImage, vk::VK_IMAGE_LAYOUT_GENERAL, &m_clearColorValue, 1, &subresourceRange);
196 const vk::VkImageMemoryBarrier initializeBarrier =
198 vk::VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
200 vk::VK_ACCESS_TRANSFER_WRITE_BIT, // srcAccessMask
201 vk::VK_ACCESS_SHADER_READ_BIT, // dstAccessMask
202 vk::VK_IMAGE_LAYOUT_GENERAL, // oldLayout
203 vk::VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, // newLayout
204 queueFamilyIndex, // srcQueueFamilyIndex
205 queueFamilyIndex, // dstQueueFamilyIndex
206 **colorImage, // image
207 subresourceRange // subresourceRange
209 vk.cmdPipelineBarrier(targetCmdBuffer,
210 vk::VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
211 vk::VK_PIPELINE_STAGE_TRANSFER_BIT,
212 (vk::VkDependencyFlags)0,
213 0, (const vk::VkMemoryBarrier*)DE_NULL,
214 0, (const vk::VkBufferMemoryBarrier*)DE_NULL,
215 1, &initializeBarrier);
218 if (m_cmdBufferType == CMD_BUFFER_SECONDARY)
220 endCommandBuffer(vk, *secondaryCmdBuffer);
221 vk.cmdExecuteCommands(*cmdBuffer, 1u, &secondaryCmdBuffer.get());
224 endCommandBuffer(vk, *cmdBuffer);
226 // Submit command buffer
227 const vk::Unique<vk::VkFence> fence (vk::createFence(vk, device));
228 VK_CHECK(queueSubmit(ctx, PROTECTION_ENABLED, queue, *cmdBuffer, *fence, ~0ull));
231 ctx.getTestContext().getLog()
232 << tcu::TestLog::Message << "Color clear value: " << tcu::Vec4(m_clearColorValue.float32) << tcu::TestLog::EndMessage;
234 // Validate resulting image
235 if (m_validator.validateImage(ctx, m_refData, **colorImage, m_imageFormat))
236 return tcu::TestStatus::pass("Everything went OK");
238 return tcu::TestStatus::fail("Something went really wrong");
241 tcu::TestCaseGroup* createClearColorImageTests (tcu::TestContext& testCtx, CmdBufferType cmdBufferType)
244 vk::VkClearColorValue clearColorValue;
247 { { { 1.0f, 0.0f, 0.0f, 1.0f } },
249 { tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 0.0f, 0.0f),
250 tcu::Vec4(0.1f, 0.1f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.0f, 0.0f), },
251 { tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f),
252 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), }
255 { { { 0.0f, 1.0f, 0.0f, 1.0f } },
257 { tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 0.0f, 0.0f),
258 tcu::Vec4(0.1f, 0.1f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.0f, 0.0f), },
259 { tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f),
260 tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), }
263 { { { 0.0f, 0.0f, 1.0f, 1.0f } },
265 { tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 0.0f, 0.0f),
266 tcu::Vec4(0.1f, 0.1f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.0f, 0.0f), },
267 { tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f),
268 tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), }
271 { { { 0.0f, 0.0f, 0.0f, 1.0f } },
273 { tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 0.0f, 0.0f),
274 tcu::Vec4(0.1f, 0.1f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.0f, 0.0f), },
275 { tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f),
276 tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), }
279 { { { 1.0f, 0.0f, 0.0f, 1.0f } },
281 { tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 0.0f, 0.0f),
282 tcu::Vec4(0.1f, 0.1f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.0f, 0.0f), },
283 { tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f),
284 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), }
287 { { { 1.0f, 0.0f, 0.0f, 0.0f } },
289 { tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 0.0f, 0.0f),
290 tcu::Vec4(0.1f, 0.1f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.0f, 0.0f), },
291 { tcu::Vec4(1.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 0.0f, 0.0f, 0.0f),
292 tcu::Vec4(1.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 0.0f, 0.0f, 0.0f), }
295 { { { 0.1f, 0.2f, 0.3f, 0.0f } },
297 { tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 0.0f, 0.0f),
298 tcu::Vec4(0.1f, 0.1f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.0f, 0.0f), },
299 { tcu::Vec4(0.1f, 0.2f, 0.3f, 0.0f), tcu::Vec4(0.1f, 0.2f, 0.3f, 0.0f),
300 tcu::Vec4(0.1f, 0.2f, 0.3f, 0.0f), tcu::Vec4(0.1f, 0.2f, 0.3f, 0.0f), }
305 de::MovePtr<tcu::TestCaseGroup> clearStaticTests (new tcu::TestCaseGroup(testCtx, "static", "Clear Color Image Tests with static input"));
307 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(testData); ++ndx)
309 const std::string name = "clear_" + de::toString(ndx + 1);
310 clearStaticTests->addChild(new ClearColorImageTestCase(testCtx, name.c_str(), testData[ndx].clearColorValue, testData[ndx].data, cmdBufferType));
313 /* Add a few randomized tests */
314 de::MovePtr<tcu::TestCaseGroup> clearRandomTests (new tcu::TestCaseGroup(testCtx, "random", "Clear Color Image Tests with random input"));
315 const int testCount = 10;
316 de::Random rnd (testCtx.getCommandLine().getBaseSeed());
317 for (int ndx = 0; ndx < testCount; ++ndx)
319 const std::string name = "clear_" + de::toString(ndx + 1);
320 vk::VkClearValue clearValue = vk::makeClearValueColorF32(
321 rnd.getFloat(0.0, 1.0f),
322 rnd.getFloat(0.0, 1.0f),
323 rnd.getFloat(0.0, 1.0f),
324 rnd.getFloat(0.0, 1.0f));
326 tcu::Vec4 refValue (clearValue.color.float32[0], clearValue.color.float32[1], clearValue.color.float32[2], clearValue.color.float32[3]);
327 ValidationData data =
329 { tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
330 tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
331 tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)),
332 tcu::Vec4(rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f), rnd.getFloat(0.0f, 1.0f)) },
333 { refValue, refValue, refValue, refValue }
335 clearRandomTests->addChild(new ClearColorImageTestCase(testCtx, name.c_str(), clearValue.color, data, cmdBufferType));
338 std::string groupName = getCmdBufferTypeStr(cmdBufferType);
339 std::string groupDesc = "Clear Color Image Tests with " + groupName + " command buffer";
340 de::MovePtr<tcu::TestCaseGroup> clearTests (new tcu::TestCaseGroup(testCtx, groupName.c_str(), groupDesc.c_str()));
341 clearTests->addChild(clearStaticTests.release());
342 clearTests->addChild(clearRandomTests.release());
343 return clearTests.release();
348 tcu::TestCaseGroup* createClearColorImageTests (tcu::TestContext& testCtx)
350 de::MovePtr<tcu::TestCaseGroup> clearTests (new tcu::TestCaseGroup(testCtx, "clear_color", "Clear Color Image Tests"));
352 clearTests->addChild(createClearColorImageTests(testCtx, CMD_BUFFER_PRIMARY));
353 clearTests->addChild(createClearColorImageTests(testCtx, CMD_BUFFER_SECONDARY));
355 return clearTests.release();