1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 ARM 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 Pipeline Cache Tests
23 *//*--------------------------------------------------------------------*/
25 #include "vktPipelineCacheTests.hpp"
26 #include "vktPipelineClearUtil.hpp"
27 #include "vktPipelineImageUtil.hpp"
28 #include "vktPipelineVertexUtil.hpp"
29 #include "vktTestCase.hpp"
30 #include "vktTestCaseUtil.hpp"
31 #include "vkImageUtil.hpp"
32 #include "vkMemUtil.hpp"
33 #include "vkPrograms.hpp"
34 #include "vkBuilderUtil.hpp"
35 #include "vkQueryUtil.hpp"
37 #include "vkRefUtil.hpp"
38 #include "vkTypeUtil.hpp"
39 #include "vkCmdUtil.hpp"
40 #include "vkObjUtil.hpp"
41 #include "tcuImageCompare.hpp"
42 #include "deUniquePtr.hpp"
44 #include "tcuTestLog.hpp"
60 VK_MAX_SHADER_STAGES = 6,
65 std::string getShaderFlagStr (const VkShaderStageFlagBits shader,
68 std::ostringstream desc;
71 case VK_SHADER_STAGE_VERTEX_BIT:
73 desc << ((isDescription) ? "vertex stage" : "vertex_stage");
76 case VK_SHADER_STAGE_FRAGMENT_BIT:
78 desc << ((isDescription) ? "fragment stage" : "fragment_stage");
81 case VK_SHADER_STAGE_GEOMETRY_BIT:
83 desc << ((isDescription) ? "geometry stage" : "geometry_stage");
86 case VK_SHADER_STAGE_COMPUTE_BIT:
88 desc << ((isDescription) ? "compute stage" : "compute_stage");
91 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
93 desc << ((isDescription) ? "tessellation control stage" : "tessellation_control_stage");
96 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
98 desc << ((isDescription) ? "tessellation evaluation stage" : "tessellation_evaluation_stage");
102 desc << "unknown shader stage!";
103 DE_FATAL("Unknown shader Stage!");
114 CacheTestParam (const VkShaderStageFlagBits* shaders,
116 bool compileCacheMissShaders);
117 virtual ~CacheTestParam (void);
118 virtual const std::string generateTestName (void) const;
119 virtual const std::string generateTestDescription (void) const;
120 VkShaderStageFlagBits getShaderFlag (deUint32 ndx) const { return m_shaders[ndx]; }
121 deUint32 getShaderCount (void) const { return (deUint32)m_shaderCount; }
122 bool getCompileMissShaders (void) const { return m_compileCacheMissShaders; }
124 VkShaderStageFlagBits m_shaders[VK_MAX_SHADER_STAGES];
125 size_t m_shaderCount;
126 bool m_compileCacheMissShaders;
129 CacheTestParam::CacheTestParam (const VkShaderStageFlagBits* shaders, deUint32 count, bool compileCacheMissShaders)
130 : m_compileCacheMissShaders (compileCacheMissShaders)
132 DE_ASSERT(count <= VK_MAX_SHADER_STAGES);
134 for (deUint32 ndx = 0; ndx < count; ndx++)
135 m_shaders[ndx] = shaders[ndx];
137 m_shaderCount = count;
140 CacheTestParam::~CacheTestParam (void)
144 const std::string CacheTestParam::generateTestName (void) const
146 std::string result(getShaderFlagStr(m_shaders[0], false));
148 for(deUint32 ndx = 1; ndx < m_shaderCount; ndx++)
149 result += '_' + getShaderFlagStr(m_shaders[ndx], false) ;
154 const std::string CacheTestParam::generateTestDescription (void) const
156 std::string result("Create pipeline cache with " + getShaderFlagStr(m_shaders[0], true));
158 for(deUint32 ndx = 1; ndx < m_shaderCount; ndx++)
159 result += ' ' + getShaderFlagStr(m_shaders[ndx], true);
164 class SimpleGraphicsPipelineBuilder
167 SimpleGraphicsPipelineBuilder (Context& context);
168 ~SimpleGraphicsPipelineBuilder (void) { }
169 void bindShaderStage (VkShaderStageFlagBits stage,
170 const char* sourceName,
171 const char* entryName);
172 void enableTessellationStage (deUint32 patchControlPoints);
173 Move<VkPipeline> buildPipeline (tcu::UVec2 renderSize,
174 VkRenderPass renderPass,
175 VkPipelineCache cache,
176 VkPipelineLayout pipelineLayout);
179 Move<VkShaderModule> m_shaderModules[VK_MAX_SHADER_STAGES];
180 deUint32 m_shaderStageCount;
181 VkPipelineShaderStageCreateInfo m_shaderStageInfo[VK_MAX_SHADER_STAGES];
182 deUint32 m_patchControlPoints;
185 SimpleGraphicsPipelineBuilder::SimpleGraphicsPipelineBuilder (Context& context)
188 m_patchControlPoints = 0;
189 m_shaderStageCount = 0;
192 void SimpleGraphicsPipelineBuilder::bindShaderStage (VkShaderStageFlagBits stage,
193 const char* sourceName,
194 const char* entryName)
196 const DeviceInterface& vk = m_context.getDeviceInterface();
197 const VkDevice vkDevice = m_context.getDevice();
199 // Create shader module
200 deUint32* code = (deUint32*)m_context.getBinaryCollection().get(sourceName).getBinary();
201 deUint32 codeSize = (deUint32)m_context.getBinaryCollection().get(sourceName).getSize();
203 const VkShaderModuleCreateInfo moduleCreateInfo =
205 VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, // VkStructureType sType;
206 DE_NULL, // const void* pNext;
207 0u, // VkShaderModuleCreateFlags flags;
208 codeSize, // deUintptr codeSize;
209 code, // const deUint32* pCode;
212 m_shaderModules[m_shaderStageCount] = createShaderModule(vk, vkDevice, &moduleCreateInfo);
214 // Prepare shader stage info
215 m_shaderStageInfo[m_shaderStageCount].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
216 m_shaderStageInfo[m_shaderStageCount].pNext = DE_NULL;
217 m_shaderStageInfo[m_shaderStageCount].flags = 0u;
218 m_shaderStageInfo[m_shaderStageCount].stage = stage;
219 m_shaderStageInfo[m_shaderStageCount].module = *m_shaderModules[m_shaderStageCount];
220 m_shaderStageInfo[m_shaderStageCount].pName = entryName;
221 m_shaderStageInfo[m_shaderStageCount].pSpecializationInfo = DE_NULL;
223 m_shaderStageCount++;
226 Move<VkPipeline> SimpleGraphicsPipelineBuilder::buildPipeline (tcu::UVec2 renderSize, VkRenderPass renderPass, VkPipelineCache cache, VkPipelineLayout pipelineLayout)
228 const DeviceInterface& vk = m_context.getDeviceInterface();
229 const VkDevice vkDevice = m_context.getDevice();
232 const VkVertexInputBindingDescription vertexInputBindingDescription =
234 0u, // deUint32 binding;
235 sizeof(Vertex4RGBA), // deUint32 strideInBytes;
236 VK_VERTEX_INPUT_RATE_VERTEX, // VkVertexInputRate inputRate;
239 const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[2] =
242 0u, // deUint32 location;
243 0u, // deUint32 binding;
244 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
245 0u // deUint32 offsetInBytes;
248 1u, // deUint32 location;
249 0u, // deUint32 binding;
250 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
251 DE_OFFSET_OF(Vertex4RGBA, color), // deUint32 offsetInBytes;
255 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
257 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
258 DE_NULL, // const void* pNext;
259 0u, // VkPipelineVertexInputStateCreateFlags flags;
260 1u, // deUint32 vertexBindingDescriptionCount;
261 &vertexInputBindingDescription, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
262 2u, // deUint32 vertexAttributeDescriptionCount;
263 vertexInputAttributeDescriptions, // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
266 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateParams =
268 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
269 DE_NULL, // const void* pNext;
270 0u, // VkPipelineInputAssemblyStateCreateFlags flags;
271 (m_patchControlPoints == 0 ? VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST
272 : VK_PRIMITIVE_TOPOLOGY_PATCH_LIST), // VkPrimitiveTopology topology;
273 VK_FALSE, // VkBool32 primitiveRestartEnable;
276 const VkViewport viewport = makeViewport(renderSize);
277 const VkRect2D scissor = makeRect2D(renderSize);
279 const VkPipelineViewportStateCreateInfo viewportStateParams =
281 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
282 DE_NULL, // const void* pNext;
283 0u, // VkPipelineViewportStateCreateFlags flags;
284 1u, // deUint32 viewportCount;
285 &viewport, // const VkViewport* pViewports;
286 1u, // deUint32 scissorCount;
287 &scissor // const VkRect2D* pScissors;
290 const VkPipelineRasterizationStateCreateInfo rasterStateParams =
292 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
293 DE_NULL, // const void* pNext;
294 0u, // VkPipelineRasterizationStateCreateFlags flags;
295 VK_FALSE, // VkBool32 depthClampEnable;
296 VK_FALSE, // VkBool32 rasterizerDiscardEnable;
297 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode;
298 VK_CULL_MODE_NONE, // VkCullModeFlags cullMode;
299 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
300 VK_FALSE, // VkBool32 depthBiasEnable;
301 0.0f, // float depthBiasConstantFactor;
302 0.0f, // float depthBiasClamp;
303 0.0f, // float depthBiasSlopeFactor;
304 1.0f, // float lineWidth;
307 const VkPipelineColorBlendAttachmentState colorBlendAttachmentState =
309 VK_FALSE, // VkBool32 blendEnable;
310 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcColorBlendFactor;
311 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstColorBlendFactor;
312 VK_BLEND_OP_ADD, // VkBlendOp colorBlendOp;
313 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcAlphaBlendFactor;
314 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstAlphaBlendFactor;
315 VK_BLEND_OP_ADD, // VkBlendOp alphaBlendOp;
316 VK_COLOR_COMPONENT_R_BIT |
317 VK_COLOR_COMPONENT_G_BIT |
318 VK_COLOR_COMPONENT_B_BIT |
319 VK_COLOR_COMPONENT_A_BIT // VkColorComponentFlags colorWriteMask;
322 const VkPipelineColorBlendStateCreateInfo colorBlendStateParams =
324 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
325 DE_NULL, // const void* pNext;
326 0u, // VkPipelineColorBlendStateCreateFlags flags;
327 VK_FALSE, // VkBool32 logicOpEnable;
328 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
329 1u, // deUint32 attachmentCount;
330 &colorBlendAttachmentState, // const VkPipelineColorBlendAttachmentState* pAttachments;
331 { 0.0f, 0.0f, 0.0f, 0.0f }, // float blendConst[4];
334 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
336 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
337 DE_NULL, // const void* pNext;
338 0u, // VkPipelineMultisampleStateCreateFlags flags;
339 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits rasterizationSamples;
340 VK_FALSE, // VkBool32 sampleShadingEnable;
341 0.0f, // float minSampleShading;
342 DE_NULL, // const VkSampleMask* pSampleMask;
343 VK_FALSE, // VkBool32 alphaToCoverageEnable;
344 VK_FALSE, // VkBool32 alphaToOneEnable;
347 VkPipelineDepthStencilStateCreateInfo depthStencilStateParams =
349 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // VkStructureType sType;
350 DE_NULL, // const void* pNext;
351 0u, // VkPipelineDepthStencilStateCreateFlags flags;
352 VK_TRUE, // VkBool32 depthTestEnable;
353 VK_TRUE, // VkBool32 depthWriteEnable;
354 VK_COMPARE_OP_LESS_OR_EQUAL, // VkCompareOp depthCompareOp;
355 VK_FALSE, // VkBool32 depthBoundsTestEnable;
356 VK_FALSE, // VkBool32 stencilTestEnable;
357 // VkStencilOpState front;
359 VK_STENCIL_OP_KEEP, // VkStencilOp failOp;
360 VK_STENCIL_OP_KEEP, // VkStencilOp passOp;
361 VK_STENCIL_OP_KEEP, // VkStencilOp depthFailOp;
362 VK_COMPARE_OP_NEVER, // VkCompareOp compareOp;
363 0u, // deUint32 compareMask;
364 0u, // deUint32 writeMask;
365 0u, // deUint32 reference;
367 // VkStencilOpState back;
369 VK_STENCIL_OP_KEEP, // VkStencilOp failOp;
370 VK_STENCIL_OP_KEEP, // VkStencilOp passOp;
371 VK_STENCIL_OP_KEEP, // VkStencilOp depthFailOp;
372 VK_COMPARE_OP_NEVER, // VkCompareOp compareOp;
373 0u, // deUint32 compareMask;
374 0u, // deUint32 writeMask;
375 0u, // deUint32 reference;
377 0.0f, // float minDepthBounds;
378 1.0f, // float maxDepthBounds;
381 const VkPipelineTessellationStateCreateInfo tessStateCreateInfo =
383 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, // VkStructureType sType;
384 DE_NULL, // const void* pNext;
385 0u, // VkPipelineTesselationStateCreateFlags flags;
386 m_patchControlPoints, // deUint32 patchControlPoints;
388 const VkPipelineTessellationStateCreateInfo* pTessCreateInfo = (m_patchControlPoints > 0)
389 ? &tessStateCreateInfo
392 const VkGraphicsPipelineCreateInfo graphicsPipelineParams =
394 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
395 DE_NULL, // const void* pNext;
396 0u, // VkPipelineCreateFlags flags;
397 m_shaderStageCount, // deUint32 stageCount;
398 m_shaderStageInfo, // const VkPipelineShaderStageCreateInfo* pStages;
399 &vertexInputStateParams, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
400 &inputAssemblyStateParams, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
401 pTessCreateInfo, // const VkPipelineTessellationStateCreateInfo* pTessellationState;
402 &viewportStateParams, // const VkPipelineViewportStateCreateInfo* pViewportState;
403 &rasterStateParams, // const VkPipelineRasterizationStateCreateInfo* pRasterState;
404 &multisampleStateParams, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
405 &depthStencilStateParams, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
406 &colorBlendStateParams, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
407 (const VkPipelineDynamicStateCreateInfo*)DE_NULL, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
408 pipelineLayout, // VkPipelineLayout layout;
409 renderPass, // VkRenderPass renderPass;
410 0u, // deUint32 subpass;
411 0u, // VkPipeline basePipelineHandle;
412 0, // deInt32 basePipelineIndex;
415 return createGraphicsPipeline(vk, vkDevice, cache, &graphicsPipelineParams);
418 void SimpleGraphicsPipelineBuilder::enableTessellationStage (deUint32 patchControlPoints)
420 m_patchControlPoints = patchControlPoints;
423 template <class Test>
424 vkt::TestCase* newTestCase (tcu::TestContext& testContext,
425 const CacheTestParam* testParam)
427 return new Test(testContext,
428 testParam->generateTestName().c_str(),
429 testParam->generateTestDescription().c_str(),
433 Move<VkBuffer> createBufferAndBindMemory (Context& context, VkDeviceSize size, VkBufferUsageFlags usage, de::MovePtr<Allocation>* pAlloc)
435 const DeviceInterface& vk = context.getDeviceInterface();
436 const VkDevice vkDevice = context.getDevice();
437 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
439 const VkBufferCreateInfo vertexBufferParams =
441 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
442 DE_NULL, // const void* pNext;
443 0u, // VkBufferCreateFlags flags;
444 size, // VkDeviceSize size;
445 usage, // VkBufferUsageFlags usage;
446 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
447 1u, // deUint32 queueFamilyCount;
448 &queueFamilyIndex // const deUint32* pQueueFamilyIndices;
451 Move<VkBuffer> vertexBuffer = createBuffer(vk, vkDevice, &vertexBufferParams);
453 *pAlloc = context.getDefaultAllocator().allocate(getBufferMemoryRequirements(vk, vkDevice, *vertexBuffer), MemoryRequirement::HostVisible);
454 VK_CHECK(vk.bindBufferMemory(vkDevice, *vertexBuffer, (*pAlloc)->getMemory(), (*pAlloc)->getOffset()));
459 Move<VkImage> createImage2DAndBindMemory (Context& context,
463 VkImageUsageFlags usage,
464 VkSampleCountFlagBits sampleCount,
465 de::details::MovePtr<Allocation>* pAlloc)
467 const DeviceInterface& vk = context.getDeviceInterface();
468 const VkDevice vkDevice = context.getDevice();
469 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
471 const VkImageCreateInfo colorImageParams =
473 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
474 DE_NULL, // const void* pNext;
475 0u, // VkImageCreateFlags flags;
476 VK_IMAGE_TYPE_2D, // VkImageType imageType;
477 format, // VkFormat format;
478 { width, height, 1u }, // VkExtent3D extent;
479 1u, // deUint32 mipLevels;
480 1u, // deUint32 arraySize;
481 sampleCount, // deUint32 samples;
482 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
483 usage, // VkImageUsageFlags usage;
484 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
485 1u, // deUint32 queueFamilyCount;
486 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
487 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
490 Move<VkImage> image = createImage(vk, vkDevice, &colorImageParams);
492 *pAlloc = context.getDefaultAllocator().allocate(getImageMemoryRequirements(vk, vkDevice, *image), MemoryRequirement::Any);
493 VK_CHECK(vk.bindImageMemory(vkDevice, *image, (*pAlloc)->getMemory(), (*pAlloc)->getOffset()));
499 class CacheTest : public vkt::TestCase
502 CacheTest (tcu::TestContext& testContext,
503 const std::string& name,
504 const std::string& description,
505 const CacheTestParam* param)
506 : vkt::TestCase (testContext, name, description)
509 virtual ~CacheTest (void) { }
511 const CacheTestParam m_param;
514 class CacheTestInstance : public vkt::TestInstance
519 PIPELINE_CACHE_NDX_NO_CACHE,
520 PIPELINE_CACHE_NDX_CACHED,
521 PIPELINE_CACHE_NDX_COUNT,
523 CacheTestInstance (Context& context,
524 const CacheTestParam* param);
525 virtual ~CacheTestInstance (void);
526 virtual tcu::TestStatus iterate (void);
528 virtual tcu::TestStatus verifyTestResult (void) = 0;
529 virtual void prepareCommandBuffer (void) = 0;
531 const CacheTestParam* m_param;
532 Move<VkCommandPool> m_cmdPool;
533 Move<VkCommandBuffer> m_cmdBuffer;
534 Move<VkPipelineCache> m_cache;
537 CacheTestInstance::CacheTestInstance (Context& context,
538 const CacheTestParam* param)
539 : TestInstance (context)
542 const DeviceInterface& vk = m_context.getDeviceInterface();
543 const VkDevice vkDevice = m_context.getDevice();
544 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
546 // Create command pool
547 m_cmdPool = createCommandPool(vk, vkDevice, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, queueFamilyIndex);
549 // Create command buffer
550 m_cmdBuffer = allocateCommandBuffer(vk, vkDevice, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
552 // Create the Pipeline Cache
554 const VkPipelineCacheCreateInfo pipelineCacheCreateInfo =
556 VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO, // VkStructureType sType;
557 DE_NULL, // const void* pNext;
558 0u, // VkPipelineCacheCreateFlags flags;
559 0u, // deUintptr initialDataSize;
560 DE_NULL, // const void* pInitialData;
563 m_cache = createPipelineCache(vk, vkDevice, &pipelineCacheCreateInfo);
567 CacheTestInstance::~CacheTestInstance (void)
571 tcu::TestStatus CacheTestInstance::iterate (void)
573 const DeviceInterface& vk = m_context.getDeviceInterface();
574 const VkDevice vkDevice = m_context.getDevice();
575 const VkQueue queue = m_context.getUniversalQueue();
577 prepareCommandBuffer();
579 submitCommandsAndWait(vk, vkDevice, queue, m_cmdBuffer.get());
581 return verifyTestResult();
584 class GraphicsCacheTest : public CacheTest
587 GraphicsCacheTest (tcu::TestContext& testContext,
588 const std::string& name,
589 const std::string& description,
590 const CacheTestParam* param)
591 : CacheTest (testContext, name, description, param)
593 virtual ~GraphicsCacheTest (void) { }
594 virtual void initPrograms (SourceCollections& programCollection) const;
595 virtual void checkSupport (Context& context) const;
596 virtual TestInstance* createInstance (Context& context) const;
599 class GraphicsCacheTestInstance : public CacheTestInstance
602 GraphicsCacheTestInstance (Context& context,
603 const CacheTestParam* param);
604 virtual ~GraphicsCacheTestInstance (void);
606 void prepareRenderPass (VkFramebuffer framebuffer, VkPipeline pipeline);
607 virtual void prepareCommandBuffer (void);
608 virtual tcu::TestStatus verifyTestResult (void);
611 const tcu::UVec2 m_renderSize;
612 const VkFormat m_colorFormat;
613 const VkFormat m_depthFormat;
614 Move<VkPipelineLayout> m_pipelineLayout;
616 Move<VkImage> m_depthImage;
617 de::MovePtr<Allocation> m_depthImageAlloc;
618 de::MovePtr<Allocation> m_colorImageAlloc[PIPELINE_CACHE_NDX_COUNT];
619 Move<VkImageView> m_depthAttachmentView;
620 VkImageMemoryBarrier m_imageLayoutBarriers[3];
622 Move<VkBuffer> m_vertexBuffer;
623 de::MovePtr<Allocation> m_vertexBufferMemory;
624 std::vector<Vertex4RGBA> m_vertices;
626 SimpleGraphicsPipelineBuilder m_pipelineBuilder;
627 SimpleGraphicsPipelineBuilder m_missPipelineBuilder;
628 Move<VkRenderPass> m_renderPass;
630 Move<VkImage> m_colorImage[PIPELINE_CACHE_NDX_COUNT];
631 Move<VkImageView> m_colorAttachmentView[PIPELINE_CACHE_NDX_COUNT];
632 Move<VkFramebuffer> m_framebuffer[PIPELINE_CACHE_NDX_COUNT];
633 Move<VkPipeline> m_pipeline[PIPELINE_CACHE_NDX_COUNT];
636 void GraphicsCacheTest::initPrograms (SourceCollections& programCollection) const
638 enum ShaderCacheOpType
640 SHADERS_CACHE_OP_HIT = 0,
641 SHADERS_CACHE_OP_MISS,
643 SHADERS_CACHE_OP_LAST
646 for (deUint32 shaderOpNdx = 0u; shaderOpNdx < SHADERS_CACHE_OP_LAST; shaderOpNdx++)
648 const ShaderCacheOpType shaderOp = (ShaderCacheOpType)shaderOpNdx;
650 if (shaderOp == SHADERS_CACHE_OP_MISS && !m_param.getCompileMissShaders())
653 const std::string missHitDiff = (shaderOp == SHADERS_CACHE_OP_HIT ? "" : " + 0.1");
654 const std::string missSuffix = (shaderOp == SHADERS_CACHE_OP_HIT ? "" : "_miss");
656 for (deUint32 shaderNdx = 0; shaderNdx < m_param.getShaderCount(); shaderNdx++)
658 switch(m_param.getShaderFlag(shaderNdx))
660 case VK_SHADER_STAGE_VERTEX_BIT:
661 programCollection.glslSources.add("color_vert" + missSuffix) << glu::VertexSource(
663 "layout(location = 0) in vec4 position;\n"
664 "layout(location = 1) in vec4 color;\n"
665 "layout(location = 0) out highp vec4 vtxColor;\n"
668 " gl_Position = position;\n"
669 " vtxColor = color" + missHitDiff + ";\n"
673 case VK_SHADER_STAGE_FRAGMENT_BIT:
674 programCollection.glslSources.add("color_frag" + missSuffix) << glu::FragmentSource(
676 "layout(location = 0) in highp vec4 vtxColor;\n"
677 "layout(location = 0) out highp vec4 fragColor;\n"
680 " fragColor = vtxColor" + missHitDiff + ";\n"
684 case VK_SHADER_STAGE_GEOMETRY_BIT:
685 programCollection.glslSources.add("unused_geo" + missSuffix) << glu::GeometrySource(
687 "layout(triangles) in;\n"
688 "layout(triangle_strip, max_vertices = 3) out;\n"
689 "layout(location = 0) in highp vec4 in_vtxColor[];\n"
690 "layout(location = 0) out highp vec4 vtxColor;\n"
691 "out gl_PerVertex { vec4 gl_Position; };\n"
692 "in gl_PerVertex { vec4 gl_Position; } gl_in[];\n"
695 " for(int ndx=0; ndx<3; ndx++)\n"
697 " gl_Position = gl_in[ndx].gl_Position;\n"
698 " vtxColor = in_vtxColor[ndx]" + missHitDiff + ";\n"
705 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
706 programCollection.glslSources.add("basic_tcs" + missSuffix) << glu::TessellationControlSource(
708 "layout(vertices = 3) out;\n"
709 "layout(location = 0) in highp vec4 color[];\n"
710 "layout(location = 0) out highp vec4 vtxColor[];\n"
711 "out gl_PerVertex { vec4 gl_Position; } gl_out[3];\n"
712 "in gl_PerVertex { vec4 gl_Position; } gl_in[gl_MaxPatchVertices];\n"
715 " gl_TessLevelOuter[0] = 4.0;\n"
716 " gl_TessLevelOuter[1] = 4.0;\n"
717 " gl_TessLevelOuter[2] = 4.0;\n"
718 " gl_TessLevelInner[0] = 4.0;\n"
719 " gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n"
720 " vtxColor[gl_InvocationID] = color[gl_InvocationID]" + missHitDiff + ";\n"
724 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
725 programCollection.glslSources.add("basic_tes" + missSuffix) << glu::TessellationEvaluationSource(
727 "layout(triangles, fractional_even_spacing, ccw) in;\n"
728 "layout(location = 0) in highp vec4 colors[];\n"
729 "layout(location = 0) out highp vec4 vtxColor;\n"
730 "out gl_PerVertex { vec4 gl_Position; };\n"
731 "in gl_PerVertex { vec4 gl_Position; } gl_in[gl_MaxPatchVertices];\n"
734 " float u = gl_TessCoord.x;\n"
735 " float v = gl_TessCoord.y;\n"
736 " float w = gl_TessCoord.z;\n"
737 " vec4 pos = vec4(0);\n"
738 " vec4 color = vec4(0)" + missHitDiff + ";\n"
739 " pos.xyz += u * gl_in[0].gl_Position.xyz;\n"
740 " color.xyz += u * colors[0].xyz;\n"
741 " pos.xyz += v * gl_in[1].gl_Position.xyz;\n"
742 " color.xyz += v * colors[1].xyz;\n"
743 " pos.xyz += w * gl_in[2].gl_Position.xyz;\n"
744 " color.xyz += w * colors[2].xyz;\n"
747 " gl_Position = pos;\n"
748 " vtxColor = color;\n"
753 DE_FATAL("Unknown Shader Stage!");
760 void GraphicsCacheTest::checkSupport (Context& context) const
762 for (deUint32 shaderNdx = 0; shaderNdx < m_param.getShaderCount(); shaderNdx++)
764 switch(m_param.getShaderFlag(shaderNdx))
766 case VK_SHADER_STAGE_GEOMETRY_BIT:
767 context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_GEOMETRY_SHADER);
769 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
770 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
771 context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_TESSELLATION_SHADER);
779 TestInstance* GraphicsCacheTest::createInstance (Context& context) const
781 return new GraphicsCacheTestInstance(context, &m_param);
784 GraphicsCacheTestInstance::GraphicsCacheTestInstance (Context& context,
785 const CacheTestParam* param)
786 : CacheTestInstance (context,param)
787 , m_renderSize (32u, 32u)
788 , m_colorFormat (VK_FORMAT_R8G8B8A8_UNORM)
789 , m_depthFormat (VK_FORMAT_D16_UNORM)
790 , m_pipelineBuilder (context)
791 , m_missPipelineBuilder (context)
793 const DeviceInterface& vk = m_context.getDeviceInterface();
794 const VkDevice vkDevice = m_context.getDevice();
796 // Create vertex buffer
798 m_vertexBuffer = createBufferAndBindMemory(m_context, 1024u, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, &m_vertexBufferMemory);
800 m_vertices = createOverlappingQuads();
801 // Load vertices into vertex buffer
802 deMemcpy(m_vertexBufferMemory->getHostPtr(), m_vertices.data(), m_vertices.size() * sizeof(Vertex4RGBA));
803 flushAlloc(vk, vkDevice, *m_vertexBufferMemory);
806 // Create render pass
807 m_renderPass = makeRenderPass(vk, vkDevice, m_colorFormat, m_depthFormat);
809 const VkComponentMapping ComponentMappingRGBA = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A};
810 // Create color image
812 m_colorImage[PIPELINE_CACHE_NDX_NO_CACHE] = createImage2DAndBindMemory(m_context,
816 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
817 VK_SAMPLE_COUNT_1_BIT,
818 &m_colorImageAlloc[PIPELINE_CACHE_NDX_NO_CACHE]);
819 m_colorImage[PIPELINE_CACHE_NDX_CACHED] = createImage2DAndBindMemory(m_context,
823 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
824 VK_SAMPLE_COUNT_1_BIT,
825 &m_colorImageAlloc[PIPELINE_CACHE_NDX_CACHED]);
828 // Create depth image
830 m_depthImage = createImage2DAndBindMemory(m_context,
834 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
835 VK_SAMPLE_COUNT_1_BIT,
839 // Set up image layout transition barriers
841 VkImageMemoryBarrier colorImageBarrier =
843 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
844 DE_NULL, // const void* pNext;
845 0u, // VkAccessFlags srcAccessMask;
846 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkAccessFlags dstAccessMask;
847 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
848 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout newLayout;
849 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
850 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
851 *m_colorImage[PIPELINE_CACHE_NDX_NO_CACHE], // VkImage image;
852 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u }, // VkImageSubresourceRange subresourceRange;
855 m_imageLayoutBarriers[0] = colorImageBarrier;
857 colorImageBarrier.image = *m_colorImage[PIPELINE_CACHE_NDX_CACHED];
858 m_imageLayoutBarriers[1] = colorImageBarrier;
860 const VkImageMemoryBarrier depthImageBarrier =
862 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
863 DE_NULL, // const void* pNext;
864 0u, // VkAccessFlags srcAccessMask;
865 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, // VkAccessFlags dstAccessMask;
866 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
867 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, // VkImageLayout newLayout;
868 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
869 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
870 *m_depthImage, // VkImage image;
871 { VK_IMAGE_ASPECT_DEPTH_BIT, 0u, 1u, 0u, 1u }, // VkImageSubresourceRange subresourceRange;
874 m_imageLayoutBarriers[2] = depthImageBarrier;
876 // Create color attachment view
878 VkImageViewCreateInfo colorAttachmentViewParams =
880 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
881 DE_NULL, // const void* pNext;
882 0u, // VkImageViewCreateFlags flags;
883 *m_colorImage[PIPELINE_CACHE_NDX_NO_CACHE], // VkImage image;
884 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
885 m_colorFormat, // VkFormat format;
886 ComponentMappingRGBA, // VkComponentMapping components;
887 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u }, // VkImageSubresourceRange subresourceRange;
890 m_colorAttachmentView[PIPELINE_CACHE_NDX_NO_CACHE] = createImageView(vk, vkDevice, &colorAttachmentViewParams);
892 colorAttachmentViewParams.image = *m_colorImage[PIPELINE_CACHE_NDX_CACHED];
893 m_colorAttachmentView[PIPELINE_CACHE_NDX_CACHED] = createImageView(vk, vkDevice, &colorAttachmentViewParams);
896 // Create depth attachment view
898 const VkImageViewCreateInfo depthAttachmentViewParams =
900 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
901 DE_NULL, // const void* pNext;
902 0u, // VkImageViewCreateFlags flags;
903 *m_depthImage, // VkImage image;
904 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
905 m_depthFormat, // VkFormat format;
906 ComponentMappingRGBA, // VkComponentMapping components;
907 { VK_IMAGE_ASPECT_DEPTH_BIT, 0u, 1u, 0u, 1u }, // VkImageSubresourceRange subresourceRange;
910 m_depthAttachmentView = createImageView(vk, vkDevice, &depthAttachmentViewParams);
913 // Create framebuffer
915 VkImageView attachmentBindInfos[2] =
917 *m_colorAttachmentView[PIPELINE_CACHE_NDX_NO_CACHE],
918 *m_depthAttachmentView,
921 const VkFramebufferCreateInfo framebufferParams =
923 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
924 DE_NULL, // const void* pNext;
925 0u, // VkFramebufferCreateFlags flags;
926 *m_renderPass, // VkRenderPass renderPass;
927 2u, // deUint32 attachmentCount;
928 attachmentBindInfos, // const VkImageView* pAttachments;
929 (deUint32)m_renderSize.x(), // deUint32 width;
930 (deUint32)m_renderSize.y(), // deUint32 height;
931 1u, // deUint32 layers;
934 m_framebuffer[PIPELINE_CACHE_NDX_NO_CACHE] = createFramebuffer(vk, vkDevice, &framebufferParams);
936 attachmentBindInfos[0] = *m_colorAttachmentView[PIPELINE_CACHE_NDX_CACHED];
937 m_framebuffer[PIPELINE_CACHE_NDX_CACHED] = createFramebuffer(vk, vkDevice, &framebufferParams);
940 // Bind shader stages
941 for (deUint32 shaderNdx = 0; shaderNdx < m_param->getShaderCount(); shaderNdx++)
943 switch(m_param->getShaderFlag(shaderNdx))
945 case VK_SHADER_STAGE_VERTEX_BIT:
946 m_pipelineBuilder.bindShaderStage(VK_SHADER_STAGE_VERTEX_BIT, "color_vert", "main");
947 if (m_param->getCompileMissShaders())
949 m_missPipelineBuilder.bindShaderStage(VK_SHADER_STAGE_VERTEX_BIT, "color_vert_miss", "main");
952 case VK_SHADER_STAGE_FRAGMENT_BIT:
953 m_pipelineBuilder.bindShaderStage(VK_SHADER_STAGE_FRAGMENT_BIT, "color_frag", "main");
954 if (m_param->getCompileMissShaders())
956 m_missPipelineBuilder.bindShaderStage(VK_SHADER_STAGE_FRAGMENT_BIT, "color_frag_miss", "main");
959 case VK_SHADER_STAGE_GEOMETRY_BIT:
960 m_pipelineBuilder.bindShaderStage(VK_SHADER_STAGE_GEOMETRY_BIT, "unused_geo", "main");
961 if (m_param->getCompileMissShaders())
963 m_missPipelineBuilder.bindShaderStage(VK_SHADER_STAGE_GEOMETRY_BIT, "unused_geo_miss", "main");
966 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
967 m_pipelineBuilder.bindShaderStage(VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, "basic_tcs", "main");
968 m_pipelineBuilder.enableTessellationStage(3);
969 if (m_param->getCompileMissShaders())
971 m_missPipelineBuilder.bindShaderStage(VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, "basic_tcs_miss", "main");
972 m_missPipelineBuilder.enableTessellationStage(3);
975 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
976 m_pipelineBuilder.bindShaderStage(VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, "basic_tes", "main");
977 m_pipelineBuilder.enableTessellationStage(3);
978 if (m_param->getCompileMissShaders())
980 m_missPipelineBuilder.bindShaderStage(VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, "basic_tes_miss", "main");
981 m_missPipelineBuilder.enableTessellationStage(3);
985 DE_FATAL("Unknown Shader Stage!");
990 // Create pipeline layout
992 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
994 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
995 DE_NULL, // const void* pNext;
996 0u, // VkPipelineLayoutCreateFlags flags;
997 0u, // deUint32 setLayoutCount;
998 DE_NULL, // const VkDescriptorSetLayout* pSetLayouts;
999 0u, // deUint32 pushConstantRangeCount;
1000 DE_NULL // const VkPushConstantRange* pPushConstantRanges;
1003 m_pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
1006 m_pipeline[PIPELINE_CACHE_NDX_NO_CACHE] = m_pipelineBuilder.buildPipeline(m_renderSize, *m_renderPass, *m_cache, *m_pipelineLayout);
1007 m_pipeline[PIPELINE_CACHE_NDX_CACHED] = m_pipelineBuilder.buildPipeline(m_renderSize, *m_renderPass, *m_cache, *m_pipelineLayout);
1010 GraphicsCacheTestInstance::~GraphicsCacheTestInstance (void)
1014 void GraphicsCacheTestInstance::prepareRenderPass (VkFramebuffer framebuffer, VkPipeline pipeline)
1016 const DeviceInterface& vk = m_context.getDeviceInterface();
1018 const VkClearValue attachmentClearValues[2] =
1020 defaultClearValue(m_colorFormat),
1021 defaultClearValue(m_depthFormat),
1024 beginRenderPass(vk, *m_cmdBuffer, *m_renderPass, framebuffer, makeRect2D(0, 0, m_renderSize.x(), m_renderSize.y()), 2u, attachmentClearValues);
1026 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1027 VkDeviceSize offsets = 0u;
1028 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0u, 1u, &m_vertexBuffer.get(), &offsets);
1029 vk.cmdDraw(*m_cmdBuffer, (deUint32)m_vertices.size(), 1u, 0u, 0u);
1031 endRenderPass(vk, *m_cmdBuffer);
1034 void GraphicsCacheTestInstance::prepareCommandBuffer (void)
1036 const DeviceInterface& vk = m_context.getDeviceInterface();
1038 beginCommandBuffer(vk, *m_cmdBuffer, 0u);
1040 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, (VkDependencyFlags)0,
1041 0u, DE_NULL, 0u, DE_NULL, DE_LENGTH_OF_ARRAY(m_imageLayoutBarriers), m_imageLayoutBarriers);
1043 prepareRenderPass(*m_framebuffer[PIPELINE_CACHE_NDX_NO_CACHE], *m_pipeline[PIPELINE_CACHE_NDX_NO_CACHE]);
1045 // After the first render pass, the images are in correct layouts
1047 prepareRenderPass(*m_framebuffer[PIPELINE_CACHE_NDX_CACHED], *m_pipeline[PIPELINE_CACHE_NDX_CACHED]);
1049 endCommandBuffer(vk, *m_cmdBuffer);
1052 tcu::TestStatus GraphicsCacheTestInstance::verifyTestResult (void)
1054 const DeviceInterface& vk = m_context.getDeviceInterface();
1055 const VkDevice vkDevice = m_context.getDevice();
1056 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
1058 const VkQueue queue = m_context.getUniversalQueue();
1059 de::MovePtr<tcu::TextureLevel> resultNoCache = readColorAttachment(vk,
1063 m_context.getDefaultAllocator(),
1064 *m_colorImage[PIPELINE_CACHE_NDX_NO_CACHE],
1067 de::MovePtr<tcu::TextureLevel> resultCache = readColorAttachment(vk,
1071 m_context.getDefaultAllocator(),
1072 *m_colorImage[PIPELINE_CACHE_NDX_CACHED],
1076 bool compareOk = tcu::intThresholdCompare(m_context.getTestContext().getLog(),
1079 resultNoCache->getAccess(),
1080 resultCache->getAccess(),
1081 tcu::UVec4(1, 1, 1, 1),
1082 tcu::COMPARE_LOG_RESULT);
1085 return tcu::TestStatus::pass("Render images w/o cached pipeline match.");
1087 return tcu::TestStatus::fail("Render Images mismatch.");
1090 class ComputeCacheTest : public CacheTest
1093 ComputeCacheTest (tcu::TestContext& testContext,
1094 const std::string& name,
1095 const std::string& description,
1096 const CacheTestParam* param)
1097 : CacheTest (testContext, name, description, param)
1099 virtual ~ComputeCacheTest (void) { }
1100 virtual void initPrograms (SourceCollections& programCollection) const;
1101 virtual TestInstance* createInstance (Context& context) const;
1104 class ComputeCacheTestInstance : public CacheTestInstance
1107 ComputeCacheTestInstance (Context& context,
1108 const CacheTestParam* param);
1109 virtual ~ComputeCacheTestInstance (void);
1110 virtual void prepareCommandBuffer (void);
1112 virtual tcu::TestStatus verifyTestResult (void);
1113 void buildBuffers (void);
1114 void buildDescriptorSets (deUint32 ndx);
1115 void buildShader (void);
1116 void buildPipeline (deUint32 ndx);
1118 Move<VkBuffer> m_inputBuf;
1119 de::MovePtr<Allocation> m_inputBufferAlloc;
1120 Move<VkShaderModule> m_computeShaderModule;
1122 Move<VkBuffer> m_outputBuf[PIPELINE_CACHE_NDX_COUNT];
1123 de::MovePtr<Allocation> m_outputBufferAlloc[PIPELINE_CACHE_NDX_COUNT];
1125 Move<VkDescriptorPool> m_descriptorPool[PIPELINE_CACHE_NDX_COUNT];
1126 Move<VkDescriptorSetLayout> m_descriptorSetLayout[PIPELINE_CACHE_NDX_COUNT];
1127 Move<VkDescriptorSet> m_descriptorSet[PIPELINE_CACHE_NDX_COUNT];
1129 Move<VkPipelineLayout> m_pipelineLayout[PIPELINE_CACHE_NDX_COUNT];
1130 Move<VkPipeline> m_pipeline[PIPELINE_CACHE_NDX_COUNT];
1133 void ComputeCacheTest::initPrograms (SourceCollections& programCollection) const
1135 programCollection.glslSources.add("basic_compute") << glu::ComputeSource(
1137 "layout(local_size_x = 1) in;\n"
1138 "layout(std430) buffer;\n"
1139 "layout(binding = 0) readonly buffer Input0\n"
1141 " vec4 elements[];\n"
1143 "layout(binding = 1) writeonly buffer Output\n"
1145 " vec4 elements[];\n"
1149 " uint ident = gl_GlobalInvocationID.x;\n"
1150 " output_data.elements[ident] = input_data0.elements[ident] * input_data0.elements[ident];\n"
1154 TestInstance* ComputeCacheTest::createInstance (Context& context) const
1156 return new ComputeCacheTestInstance(context, &m_param);
1159 void ComputeCacheTestInstance::buildBuffers (void)
1161 const DeviceInterface& vk = m_context.getDeviceInterface();
1162 const VkDevice vkDevice = m_context.getDevice();
1164 // Create buffer object, allocate storage, and generate input data
1165 const VkDeviceSize size = sizeof(tcu::Vec4) * 128u;
1166 m_inputBuf = createBufferAndBindMemory(m_context, size, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, &m_inputBufferAlloc);
1168 // Initialize input buffer
1169 tcu::Vec4* pVec = reinterpret_cast<tcu::Vec4*>(m_inputBufferAlloc->getHostPtr());
1170 for (deUint32 ndx = 0u; ndx < 128u; ndx++)
1172 for (deUint32 component = 0u; component < 4u; component++)
1173 pVec[ndx][component]= (float)(ndx * (component + 1u));
1175 flushAlloc(vk, vkDevice, *m_inputBufferAlloc);
1177 // Clear the output buffer
1178 for (deUint32 ndx = 0; ndx < PIPELINE_CACHE_NDX_COUNT; ndx++)
1180 m_outputBuf[ndx] = createBufferAndBindMemory(m_context, size, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, &m_outputBufferAlloc[ndx]);
1182 pVec = reinterpret_cast<tcu::Vec4*>(m_outputBufferAlloc[ndx]->getHostPtr());
1184 for (deUint32 i = 0; i < (size / sizeof(tcu::Vec4)); i++)
1185 pVec[i] = tcu::Vec4(0.0f);
1187 flushAlloc(vk, vkDevice, *m_outputBufferAlloc[ndx]);
1191 void ComputeCacheTestInstance::buildDescriptorSets (deUint32 ndx)
1193 const DeviceInterface& vk = m_context.getDeviceInterface();
1194 const VkDevice vkDevice = m_context.getDevice();
1196 // Create descriptor set layout
1197 DescriptorSetLayoutBuilder descLayoutBuilder;
1199 for (deUint32 bindingNdx = 0u; bindingNdx < 2u; bindingNdx++)
1200 descLayoutBuilder.addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_COMPUTE_BIT);
1202 m_descriptorSetLayout[ndx] = descLayoutBuilder.build(vk, vkDevice);
1204 std::vector<VkDescriptorBufferInfo> descriptorInfos;
1205 descriptorInfos.push_back(makeDescriptorBufferInfo(*m_inputBuf, 0u, sizeof(tcu::Vec4) * 128u));
1206 descriptorInfos.push_back(makeDescriptorBufferInfo(*m_outputBuf[ndx], 0u, sizeof(tcu::Vec4) * 128u));
1208 // Create descriptor pool
1209 m_descriptorPool[ndx] = DescriptorPoolBuilder().addType(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2u).build(vk,
1211 VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,
1214 // Create descriptor set
1215 const VkDescriptorSetAllocateInfo descriptorSetAllocInfo =
1217 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType;
1218 DE_NULL, // const void* pNext;
1219 *m_descriptorPool[ndx], // VkDescriptorPool descriptorPool;
1220 1u, // deUint32 setLayoutCount;
1221 &m_descriptorSetLayout[ndx].get(), // const VkDescriptorSetLayout* pSetLayouts;
1223 m_descriptorSet[ndx] = allocateDescriptorSet(vk, vkDevice, &descriptorSetAllocInfo);
1225 DescriptorSetUpdateBuilder builder;
1226 for (deUint32 descriptorNdx = 0u; descriptorNdx < 2u; descriptorNdx++)
1228 builder.writeSingle(*m_descriptorSet[ndx],
1229 DescriptorSetUpdateBuilder::Location::binding(descriptorNdx),
1230 VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1231 &descriptorInfos[descriptorNdx]);
1233 builder.update(vk, vkDevice);
1236 void ComputeCacheTestInstance::buildShader (void)
1238 const DeviceInterface& vk = m_context.getDeviceInterface();
1239 const VkDevice vkDevice = m_context.getDevice();
1241 // Create compute shader
1242 VkShaderModuleCreateInfo shaderModuleCreateInfo =
1244 VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, // VkStructureType sType;
1245 DE_NULL, // const void* pNext;
1246 0u, // VkShaderModuleCreateFlags flags;
1247 m_context.getBinaryCollection().get("basic_compute").getSize(), // deUintptr codeSize;
1248 (deUint32*)m_context.getBinaryCollection().get("basic_compute").getBinary(), // const deUint32* pCode;
1250 m_computeShaderModule = createShaderModule(vk, vkDevice, &shaderModuleCreateInfo);
1253 void ComputeCacheTestInstance::buildPipeline (deUint32 ndx)
1255 const DeviceInterface& vk = m_context.getDeviceInterface();
1256 const VkDevice vkDevice = m_context.getDevice();
1258 // Create compute pipeline layout
1259 const VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo =
1261 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
1262 DE_NULL, // const void* pNext;
1263 0u, // VkPipelineLayoutCreateFlags flags;
1264 1u, // deUint32 setLayoutCount;
1265 &m_descriptorSetLayout[ndx].get(), // const VkDescriptorSetLayout* pSetLayouts;
1266 0u, // deUint32 pushConstantRangeCount;
1267 DE_NULL, // const VkPushConstantRange* pPushConstantRanges;
1270 m_pipelineLayout[ndx] = createPipelineLayout(vk, vkDevice, &pipelineLayoutCreateInfo);
1272 const VkPipelineShaderStageCreateInfo stageCreateInfo =
1274 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
1275 DE_NULL, // const void* pNext;
1276 0u, // VkPipelineShaderStageCreateFlags flags;
1277 VK_SHADER_STAGE_COMPUTE_BIT, // VkShaderStageFlagBits stage;
1278 *m_computeShaderModule, // VkShaderModule module;
1279 "main", // const char* pName;
1280 DE_NULL, // const VkSpecializationInfo* pSpecializationInfo;
1283 const VkComputePipelineCreateInfo pipelineCreateInfo =
1285 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, // VkStructureType sType;
1286 DE_NULL, // const void* pNext;
1287 0u, // VkPipelineCreateFlags flags;
1288 stageCreateInfo, // VkPipelineShaderStageCreateInfo stage;
1289 *m_pipelineLayout[ndx], // VkPipelineLayout layout;
1290 (VkPipeline)0, // VkPipeline basePipelineHandle;
1291 0u, // deInt32 basePipelineIndex;
1294 m_pipeline[ndx] = createComputePipeline(vk, vkDevice, *m_cache, &pipelineCreateInfo);
1297 ComputeCacheTestInstance::ComputeCacheTestInstance (Context& context,
1298 const CacheTestParam* param)
1299 : CacheTestInstance (context, param)
1303 buildDescriptorSets(PIPELINE_CACHE_NDX_NO_CACHE);
1305 buildDescriptorSets(PIPELINE_CACHE_NDX_CACHED);
1309 buildPipeline(PIPELINE_CACHE_NDX_NO_CACHE);
1311 buildPipeline(PIPELINE_CACHE_NDX_CACHED);
1314 ComputeCacheTestInstance::~ComputeCacheTestInstance (void)
1318 void ComputeCacheTestInstance::prepareCommandBuffer (void)
1320 const DeviceInterface& vk = m_context.getDeviceInterface();
1322 beginCommandBuffer(vk, *m_cmdBuffer, 0u);
1324 for (deUint32 ndx = 0; ndx < PIPELINE_CACHE_NDX_COUNT; ndx++)
1326 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *m_pipeline[ndx]);
1327 vk.cmdBindDescriptorSets(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *m_pipelineLayout[ndx], 0u, 1u, &m_descriptorSet[ndx].get(), 0u, DE_NULL);
1328 vk.cmdDispatch(*m_cmdBuffer, 128u, 1u, 1u);
1331 endCommandBuffer(vk, *m_cmdBuffer);
1334 tcu::TestStatus ComputeCacheTestInstance::verifyTestResult (void)
1336 const DeviceInterface& vk = m_context.getDeviceInterface();
1337 const VkDevice vkDevice = m_context.getDevice();
1339 // Read the content of output buffers
1340 invalidateAlloc(vk, vkDevice, *m_outputBufferAlloc[PIPELINE_CACHE_NDX_NO_CACHE]);
1342 invalidateAlloc(vk, vkDevice, *m_outputBufferAlloc[PIPELINE_CACHE_NDX_CACHED]);
1343 // Compare the content
1344 deUint8* bufNoCache = reinterpret_cast<deUint8*>(m_outputBufferAlloc[PIPELINE_CACHE_NDX_NO_CACHE]->getHostPtr());
1345 deUint8* bufCached = reinterpret_cast<deUint8*>(m_outputBufferAlloc[PIPELINE_CACHE_NDX_CACHED]->getHostPtr());
1346 for (deUint32 ndx = 0u; ndx < sizeof(tcu::Vec4) * 128u; ndx++)
1348 if (bufNoCache[ndx] != bufCached[ndx])
1350 return tcu::TestStatus::fail("Output buffers w/o cached pipeline mismatch.");
1354 return tcu::TestStatus::pass("Output buffers w/o cached pipeline match.");
1357 class PipelineFromCacheTest : public GraphicsCacheTest
1360 PipelineFromCacheTest (tcu::TestContext& testContext, const std::string& name, const std::string& description, const CacheTestParam* param);
1361 virtual ~PipelineFromCacheTest (void) { }
1362 virtual TestInstance* createInstance (Context& context) const;
1365 PipelineFromCacheTest::PipelineFromCacheTest (tcu::TestContext& testContext, const std::string& name, const std::string& description, const CacheTestParam* param)
1366 : GraphicsCacheTest(testContext, name, description, param)
1370 class PipelineFromCacheTestInstance : public GraphicsCacheTestInstance
1373 PipelineFromCacheTestInstance (Context& context, const CacheTestParam* param);
1374 virtual ~PipelineFromCacheTestInstance (void);
1376 Move<VkPipelineCache> m_newCache;
1380 TestInstance* PipelineFromCacheTest::createInstance (Context& context) const
1382 return new PipelineFromCacheTestInstance(context, &m_param);
1385 PipelineFromCacheTestInstance::PipelineFromCacheTestInstance (Context& context, const CacheTestParam* param)
1386 : GraphicsCacheTestInstance (context, param)
1389 const DeviceInterface& vk = m_context.getDeviceInterface();
1390 const VkDevice vkDevice = m_context.getDevice();
1392 // Create more pipeline caches
1394 size_t dataSize = 0u;
1396 VK_CHECK(vk.getPipelineCacheData(vkDevice, *m_cache, (deUintptr*)&dataSize, DE_NULL));
1398 m_data = new deUint8[dataSize];
1400 VK_CHECK(vk.getPipelineCacheData(vkDevice, *m_cache, (deUintptr*)&dataSize, (void*)m_data));
1402 const VkPipelineCacheCreateInfo pipelineCacheCreateInfo =
1404 VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO, // VkStructureType sType;
1405 DE_NULL, // const void* pNext;
1406 0u, // VkPipelineCacheCreateFlags flags;
1407 dataSize, // deUintptr initialDataSize;
1408 m_data, // const void* pInitialData;
1410 m_newCache = createPipelineCache(vk, vkDevice, &pipelineCacheCreateInfo);
1412 m_pipeline[PIPELINE_CACHE_NDX_CACHED] = m_pipelineBuilder.buildPipeline(m_renderSize, *m_renderPass, *m_newCache, *m_pipelineLayout);
1415 PipelineFromCacheTestInstance::~PipelineFromCacheTestInstance (void)
1420 class PipelineFromIncompleteCacheTest : public GraphicsCacheTest
1423 PipelineFromIncompleteCacheTest (tcu::TestContext& testContext, const std::string& name, const std::string& description, const CacheTestParam* param);
1424 virtual ~PipelineFromIncompleteCacheTest (void) {}
1425 virtual TestInstance* createInstance (Context& context) const;
1428 PipelineFromIncompleteCacheTest::PipelineFromIncompleteCacheTest (tcu::TestContext& testContext, const std::string& name, const std::string& description, const CacheTestParam* param)
1429 : GraphicsCacheTest(testContext, name, description, param)
1433 class PipelineFromIncompleteCacheTestInstance : public GraphicsCacheTestInstance
1436 PipelineFromIncompleteCacheTestInstance(Context& context, const CacheTestParam* param);
1437 virtual ~PipelineFromIncompleteCacheTestInstance(void);
1440 Move<VkPipelineCache> m_newCache;
1444 TestInstance* PipelineFromIncompleteCacheTest::createInstance (Context& context) const
1446 return new PipelineFromIncompleteCacheTestInstance(context, &m_param);
1449 PipelineFromIncompleteCacheTestInstance::PipelineFromIncompleteCacheTestInstance (Context& context, const CacheTestParam* param)
1450 : GraphicsCacheTestInstance (context, param)
1453 const DeviceInterface& vk = m_context.getDeviceInterface();
1454 const VkDevice vkDevice = m_context.getDevice();
1456 // Create more pipeline caches
1458 size_t dataSize = 0u;
1459 VK_CHECK(vk.getPipelineCacheData(vkDevice, *m_cache, (deUintptr*)&dataSize, DE_NULL));
1462 TCU_THROW(NotSupportedError, "Empty pipeline cache - unable to test");
1466 m_data = new deUint8[dataSize];
1468 if (vk.getPipelineCacheData(vkDevice, *m_cache, (deUintptr*)&dataSize, (void*)m_data) != VK_INCOMPLETE)
1469 TCU_THROW(TestError, "GetPipelineCacheData should return VK_INCOMPLETE state!");
1471 const VkPipelineCacheCreateInfo pipelineCacheCreateInfo =
1473 VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO, // VkStructureType sType;
1474 DE_NULL, // const void* pNext;
1475 0u, // VkPipelineCacheCreateFlags flags;
1476 dataSize, // deUintptr initialDataSize;
1477 m_data, // const void* pInitialData;
1479 m_newCache = createPipelineCache(vk, vkDevice, &pipelineCacheCreateInfo);
1481 m_pipeline[PIPELINE_CACHE_NDX_CACHED] = m_pipelineBuilder.buildPipeline(m_renderSize, *m_renderPass, *m_newCache, *m_pipelineLayout);
1484 PipelineFromIncompleteCacheTestInstance::~PipelineFromIncompleteCacheTestInstance (void)
1491 MERGE_CACHE_EMPTY = 0,
1492 MERGE_CACHE_FROM_DATA,
1495 MERGE_CACHE_MISS_AND_HIT,
1498 MERGE_CACHE_TYPE_LAST = MERGE_CACHE_MERGED
1501 std::string getMergeCacheTypeStr (MergeCacheType type)
1505 case MERGE_CACHE_EMPTY:
1507 case MERGE_CACHE_FROM_DATA:
1509 case MERGE_CACHE_HIT:
1511 case MERGE_CACHE_MISS_AND_HIT:
1513 case MERGE_CACHE_MISS:
1515 case MERGE_CACHE_MERGED:
1518 TCU_FAIL("unhandled merge cache type");
1521 std::string getMergeCacheTypesStr (const std::vector<MergeCacheType>& types)
1524 for (size_t idx = 0; idx < types.size(); ++idx)
1528 ret += getMergeCacheTypeStr(types[idx]);
1534 class MergeCacheTestParam
1537 MergeCacheType destCacheType;
1538 std::vector<MergeCacheType> srcCacheTypes;
1541 class MergeCacheTest : public GraphicsCacheTest
1544 MergeCacheTest (tcu::TestContext& testContext,
1545 const std::string& name,
1546 const std::string& description,
1547 const CacheTestParam* param,
1548 const MergeCacheTestParam* mergeCacheParam)
1549 : GraphicsCacheTest (testContext, name, description, param)
1550 , m_mergeCacheParam (*mergeCacheParam)
1552 virtual ~MergeCacheTest (void) { }
1553 virtual TestInstance* createInstance (Context& context) const;
1555 const MergeCacheTestParam m_mergeCacheParam;
1558 class MergeCacheTestInstance : public GraphicsCacheTestInstance
1561 MergeCacheTestInstance (Context& context,
1562 const CacheTestParam* param,
1563 const MergeCacheTestParam* mergeCacheParam);
1565 Move<VkPipelineCache> createPipelineCache (const DeviceInterface& vk, VkDevice device, MergeCacheType type);
1568 Move<VkPipelineCache> m_cacheMerged;
1571 TestInstance* MergeCacheTest::createInstance (Context& context) const
1573 return new MergeCacheTestInstance(context, &m_param, &m_mergeCacheParam);
1576 MergeCacheTestInstance::MergeCacheTestInstance (Context& context, const CacheTestParam* param, const MergeCacheTestParam* mergeCacheParam)
1577 : GraphicsCacheTestInstance (context, param)
1579 const DeviceInterface& vk = m_context.getDeviceInterface();
1580 const VkDevice vkDevice = m_context.getDevice();
1582 // Create a merge destination cache
1583 m_cacheMerged = createPipelineCache(vk, vkDevice, mergeCacheParam->destCacheType);
1585 // Create more pipeline caches
1586 std::vector<VkPipelineCache> sourceCaches (mergeCacheParam->srcCacheTypes.size());
1587 typedef de::SharedPtr<Move<VkPipelineCache> > PipelineCachePtr;
1588 std::vector<PipelineCachePtr> sourceCachePtrs (sourceCaches.size());
1590 for (size_t sourceIdx = 0; sourceIdx < mergeCacheParam->srcCacheTypes.size(); sourceIdx++)
1592 // vk::Move is not copyable, so create it on heap and wrap into de::SharedPtr
1593 PipelineCachePtr pipelineCachePtr (new Move<VkPipelineCache>());
1594 *pipelineCachePtr = createPipelineCache(vk, vkDevice, mergeCacheParam->srcCacheTypes[sourceIdx]);
1596 sourceCachePtrs[sourceIdx] = pipelineCachePtr;
1597 sourceCaches[sourceIdx] = **pipelineCachePtr;
1602 VK_CHECK(vk.mergePipelineCaches(vkDevice, *m_cacheMerged, static_cast<deUint32>(sourceCaches.size()), &sourceCaches[0]));
1604 // Create pipeline from merged cache
1605 m_pipeline[PIPELINE_CACHE_NDX_CACHED] = m_pipelineBuilder.buildPipeline(m_renderSize, *m_renderPass, *m_cacheMerged, *m_pipelineLayout);
1608 Move<VkPipelineCache> MergeCacheTestInstance::createPipelineCache (const DeviceInterface& vk, VkDevice device, MergeCacheType type)
1610 VkPipelineCacheCreateInfo pipelineCacheCreateInfo =
1612 VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO, // VkStructureType sType;
1613 DE_NULL, // const void* pNext;
1614 0u, // VkPipelineCacheCreateFlags flags;
1615 0u, // deUintptr initialDataSize;
1616 DE_NULL, // const void* pInitialData;
1621 case MERGE_CACHE_EMPTY:
1623 return vk::createPipelineCache(vk, device, &pipelineCacheCreateInfo);
1625 case MERGE_CACHE_FROM_DATA:
1627 // Create a cache with init data from m_cache
1628 size_t dataSize = 0u;
1629 VK_CHECK(vk.getPipelineCacheData(device, *m_cache, (deUintptr*)&dataSize, DE_NULL));
1631 std::vector<deUint8> data(dataSize);
1632 VK_CHECK(vk.getPipelineCacheData(device, *m_cache, (deUintptr*)&dataSize, &data[0]));
1634 pipelineCacheCreateInfo.initialDataSize = data.size();
1635 pipelineCacheCreateInfo.pInitialData = &data[0];
1636 return vk::createPipelineCache(vk, device, &pipelineCacheCreateInfo);
1638 case MERGE_CACHE_HIT:
1640 Move<VkPipelineCache> ret = createPipelineCache(vk, device, MERGE_CACHE_EMPTY);
1642 m_pipelineBuilder.buildPipeline(m_renderSize, *m_renderPass, *ret, *m_pipelineLayout);
1646 case MERGE_CACHE_MISS:
1648 Move<VkPipelineCache> ret = createPipelineCache(vk, device, MERGE_CACHE_EMPTY);
1650 m_missPipelineBuilder.buildPipeline(m_renderSize, *m_renderPass, *ret, *m_pipelineLayout);
1654 case MERGE_CACHE_MISS_AND_HIT:
1656 Move<VkPipelineCache> ret = createPipelineCache(vk, device, MERGE_CACHE_EMPTY);
1658 m_pipelineBuilder.buildPipeline(m_renderSize, *m_renderPass, *ret, *m_pipelineLayout);
1659 m_missPipelineBuilder.buildPipeline(m_renderSize, *m_renderPass, *ret, *m_pipelineLayout);
1663 case MERGE_CACHE_MERGED:
1665 Move<VkPipelineCache> cache1 = createPipelineCache(vk, device, MERGE_CACHE_FROM_DATA);
1666 Move<VkPipelineCache> cache2 = createPipelineCache(vk, device, MERGE_CACHE_HIT);
1667 Move<VkPipelineCache> cache3 = createPipelineCache(vk, device, MERGE_CACHE_MISS);
1669 const VkPipelineCache sourceCaches[] =
1676 Move<VkPipelineCache> ret = createPipelineCache(vk, device, MERGE_CACHE_EMPTY);
1679 VK_CHECK(vk.mergePipelineCaches(device, *ret, DE_LENGTH_OF_ARRAY(sourceCaches), sourceCaches));
1684 TCU_FAIL("unhandled merge cache type");
1687 class CacheHeaderTest : public GraphicsCacheTest
1690 CacheHeaderTest (tcu::TestContext& testContext,
1691 const std::string& name,
1692 const std::string& description,
1693 const CacheTestParam* param)
1694 : GraphicsCacheTest(testContext, name, description, param)
1696 virtual ~CacheHeaderTest (void) { }
1697 virtual TestInstance* createInstance(Context& context) const;
1700 class CacheHeaderTestInstance : public GraphicsCacheTestInstance
1703 CacheHeaderTestInstance (Context& context, const CacheTestParam* param);
1704 virtual ~CacheHeaderTestInstance (void);
1710 deUint32 HeaderLength;
1711 deUint32 HeaderVersion;
1714 deUint8 PipelineCacheUUID[VK_UUID_SIZE];
1718 TestInstance* CacheHeaderTest::createInstance (Context& context) const
1720 return new CacheHeaderTestInstance(context, &m_param);
1723 CacheHeaderTestInstance::CacheHeaderTestInstance (Context& context, const CacheTestParam* param)
1724 : GraphicsCacheTestInstance (context, param)
1727 const DeviceInterface& vk = m_context.getDeviceInterface();
1728 const VkDevice vkDevice = m_context.getDevice();
1730 // Create more pipeline caches
1732 // Create a cache with init data from m_cache
1733 size_t dataSize = 0u;
1734 VK_CHECK(vk.getPipelineCacheData(vkDevice, *m_cache, (deUintptr*)&dataSize, DE_NULL));
1736 if (dataSize < sizeof(m_header))
1737 TCU_THROW(TestError, "Pipeline cache size is smaller than header size");
1739 m_data = new deUint8[dataSize];
1741 VK_CHECK(vk.getPipelineCacheData(vkDevice, *m_cache, (deUintptr*)&dataSize, (void*)m_data));
1743 deMemcpy(&m_header, m_data, sizeof(m_header));
1745 if (m_header.HeaderLength - VK_UUID_SIZE != 16)
1746 TCU_THROW(TestError, "Invalid header size!");
1748 if (m_header.HeaderVersion != 1)
1749 TCU_THROW(TestError, "Invalid header version!");
1751 if (m_header.VendorID != m_context.getDeviceProperties().vendorID)
1752 TCU_THROW(TestError, "Invalid header vendor ID!");
1754 if (m_header.DeviceID != m_context.getDeviceProperties().deviceID)
1755 TCU_THROW(TestError, "Invalid header device ID!");
1757 if (deMemCmp(&m_header.PipelineCacheUUID, &m_context.getDeviceProperties().pipelineCacheUUID, VK_UUID_SIZE) != 0)
1758 TCU_THROW(TestError, "Invalid header pipeline cache UUID!");
1762 CacheHeaderTestInstance::~CacheHeaderTestInstance (void)
1767 class InvalidSizeTest : public GraphicsCacheTest
1770 InvalidSizeTest (tcu::TestContext& testContext, const std::string& name, const std::string& description, const CacheTestParam* param);
1771 virtual ~InvalidSizeTest (void) {}
1772 virtual TestInstance* createInstance (Context& context) const;
1775 InvalidSizeTest::InvalidSizeTest (tcu::TestContext& testContext, const std::string& name, const std::string& description, const CacheTestParam* param)
1776 : GraphicsCacheTest(testContext, name, description, param)
1780 class InvalidSizeTestInstance : public GraphicsCacheTestInstance
1783 InvalidSizeTestInstance (Context& context, const CacheTestParam* param);
1784 virtual ~InvalidSizeTestInstance (void);
1787 deUint8* m_zeroBlock;
1790 TestInstance* InvalidSizeTest::createInstance (Context& context) const
1792 return new InvalidSizeTestInstance(context, &m_param);
1795 InvalidSizeTestInstance::InvalidSizeTestInstance (Context& context, const CacheTestParam* param)
1796 : GraphicsCacheTestInstance (context, param)
1798 , m_zeroBlock (DE_NULL)
1800 const DeviceInterface& vk = m_context.getDeviceInterface();
1801 const VkDevice vkDevice = m_context.getDevice();
1803 // Create more pipeline caches
1806 // Create a cache with init data from m_cache
1807 size_t dataSize = 0u;
1808 size_t savedDataSize = 0u;
1809 VK_CHECK(vk.getPipelineCacheData(vkDevice, *m_cache, (deUintptr*)&dataSize, DE_NULL));
1810 savedDataSize = dataSize;
1812 // If the value of dataSize is less than the maximum size that can be retrieved by the pipeline cache,
1813 // at most pDataSize bytes will be written to pData, and vkGetPipelineCacheData will return VK_INCOMPLETE.
1816 m_data = new deUint8[savedDataSize];
1817 deMemset(m_data, 0, savedDataSize);
1819 if (vk.getPipelineCacheData(vkDevice, *m_cache, (deUintptr*)&dataSize, (void*)m_data) != VK_INCOMPLETE)
1820 TCU_THROW(TestError, "GetPipelineCacheData should return VK_INCOMPLETE state!");
1825 // If the value of dataSize is less than what is necessary to store the header,
1826 // nothing will be written to pData and zero will be written to dataSize.
1827 dataSize = 16 + VK_UUID_SIZE - 1;
1829 m_data = new deUint8[savedDataSize];
1830 deMemset(m_data, 0, savedDataSize);
1832 if (vk.getPipelineCacheData(vkDevice, *m_cache, (deUintptr*)&dataSize, (void*)m_data) != VK_INCOMPLETE)
1833 TCU_THROW(TestError, "GetPipelineCacheData should return VK_INCOMPLETE state!");
1835 m_zeroBlock = new deUint8[savedDataSize];
1836 deMemset(m_zeroBlock, 0, savedDataSize);
1837 if (deMemCmp(m_data, m_zeroBlock, savedDataSize) != 0 || dataSize != 0)
1838 TCU_THROW(TestError, "Data needs to be empty and data size should be 0 when invalid size is passed to GetPipelineCacheData!");
1843 delete[] m_zeroBlock;
1848 InvalidSizeTestInstance::~InvalidSizeTestInstance (void)
1851 delete[] m_zeroBlock;
1854 class ZeroSizeTest : public GraphicsCacheTest
1857 ZeroSizeTest (tcu::TestContext& testContext, const std::string& name, const std::string& description, const CacheTestParam* param);
1858 virtual ~ZeroSizeTest (void) {}
1859 virtual TestInstance* createInstance (Context& context) const;
1862 ZeroSizeTest::ZeroSizeTest (tcu::TestContext& testContext, const std::string& name, const std::string& description, const CacheTestParam* param)
1863 : GraphicsCacheTest(testContext, name, description, param)
1867 class ZeroSizeTestInstance : public GraphicsCacheTestInstance
1870 ZeroSizeTestInstance (Context& context, const CacheTestParam* param);
1871 virtual ~ZeroSizeTestInstance (void);
1874 deUint8* m_zeroBlock;
1877 TestInstance* ZeroSizeTest::createInstance (Context& context) const
1879 return new ZeroSizeTestInstance(context, &m_param);
1882 ZeroSizeTestInstance::ZeroSizeTestInstance (Context& context, const CacheTestParam* param)
1883 : GraphicsCacheTestInstance (context, param)
1885 , m_zeroBlock (DE_NULL)
1887 const DeviceInterface& vk = m_context.getDeviceInterface();
1888 const VkDevice vkDevice = m_context.getDevice();
1890 // Create more pipeline caches
1893 // Create a cache with init data from m_cache
1894 size_t dataSize = 0u;
1896 VK_CHECK(vk.getPipelineCacheData(vkDevice, *m_cache, (deUintptr*)&dataSize, DE_NULL));
1898 m_data = new deUint8[dataSize];
1899 deMemset(m_data, 0, dataSize);
1902 VK_CHECK(vk.getPipelineCacheData(vkDevice, *m_cache, (deUintptr*)&dataSize, (void*)m_data));
1905 // Create a cache with initialDataSize = 0 & pInitialData != NULL
1906 const VkPipelineCacheCreateInfo pipelineCacheCreateInfo =
1908 VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO, // VkStructureType sType;
1909 DE_NULL, // const void* pNext;
1910 0u, // VkPipelineCacheCreateFlags flags;
1911 0u, // deUintptr initialDataSize;
1912 m_data, // const void* pInitialData;
1915 const Unique<VkPipelineCache> pipelineCache (createPipelineCache(vk, vkDevice, &pipelineCacheCreateInfo));
1921 delete[] m_zeroBlock;
1926 ZeroSizeTestInstance::~ZeroSizeTestInstance (void)
1929 delete[] m_zeroBlock;
1932 class InvalidBlobTest : public GraphicsCacheTest
1935 InvalidBlobTest (tcu::TestContext& testContext, const std::string& name, const std::string& description, const CacheTestParam* param);
1936 virtual ~InvalidBlobTest (void) {}
1937 virtual TestInstance* createInstance (Context& context) const;
1940 InvalidBlobTest::InvalidBlobTest (tcu::TestContext& testContext, const std::string& name, const std::string& description, const CacheTestParam* param)
1941 : GraphicsCacheTest(testContext, name, description, param)
1945 class InvalidBlobTestInstance : public GraphicsCacheTestInstance
1948 InvalidBlobTestInstance (Context& context, const CacheTestParam* param);
1949 virtual ~InvalidBlobTestInstance (void);
1952 deUint8* m_zeroBlock;
1955 TestInstance* InvalidBlobTest::createInstance (Context& context) const
1957 return new InvalidBlobTestInstance(context, &m_param);
1960 InvalidBlobTestInstance::InvalidBlobTestInstance (Context& context, const CacheTestParam* param)
1961 : GraphicsCacheTestInstance (context, param)
1963 , m_zeroBlock (DE_NULL)
1965 const DeviceInterface& vk = m_context.getDeviceInterface();
1966 const VkDevice vkDevice = m_context.getDevice();
1968 // Create more pipeline caches
1971 // Create a cache with init data from m_cache
1972 size_t dataSize = 0u;
1974 VK_CHECK(vk.getPipelineCacheData(vkDevice, *m_cache, (deUintptr*)&dataSize, DE_NULL));
1976 m_data = new deUint8[dataSize];
1977 deMemset(m_data, 0, dataSize);
1980 VK_CHECK(vk.getPipelineCacheData(vkDevice, *m_cache, (deUintptr*)&dataSize, (void*)m_data));
1988 { 4u, "pipeline cache header version" },
1989 { 8u, "vendor ID" },
1990 { 12u, "device ID" },
1991 { 16u, "pipeline cache ID" }
1994 for (deUint32 i = 0u; i < DE_LENGTH_OF_ARRAY(headerLayout); i++)
1996 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Creating pipeline cache using previously retrieved data with invalid " << headerLayout[i].name << tcu::TestLog::EndMessage;
1998 m_data[headerLayout[i].offset] = (deUint8)(m_data[headerLayout[i].offset] + 13u); // Add arbitrary number to create an invalid value
2000 const VkPipelineCacheCreateInfo pipelineCacheCreateInfo =
2002 VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO, // VkStructureType sType;
2003 DE_NULL, // const void* pNext;
2004 0u, // VkPipelineCacheCreateFlags flags;
2005 dataSize, // deUintptr initialDataSize;
2006 m_data, // const void* pInitialData;
2009 const Unique<VkPipelineCache> pipelineCache (createPipelineCache(vk, vkDevice, &pipelineCacheCreateInfo));
2011 m_data[headerLayout[i].offset] = (deUint8)(m_data[headerLayout[i].offset] - 13u); // Return to original value
2017 delete[] m_zeroBlock;
2022 InvalidBlobTestInstance::~InvalidBlobTestInstance (void)
2025 delete[] m_zeroBlock;
2029 tcu::TestCaseGroup* createCacheTests (tcu::TestContext& testCtx)
2032 de::MovePtr<tcu::TestCaseGroup> cacheTests (new tcu::TestCaseGroup(testCtx, "cache", "pipeline cache tests"));
2034 // Graphics Pipeline Tests
2036 de::MovePtr<tcu::TestCaseGroup> graphicsTests (new tcu::TestCaseGroup(testCtx, "graphics_tests", "Test pipeline cache with graphics pipeline."));
2038 const VkShaderStageFlagBits testParamShaders0[] =
2040 VK_SHADER_STAGE_VERTEX_BIT,
2041 VK_SHADER_STAGE_FRAGMENT_BIT,
2043 const VkShaderStageFlagBits testParamShaders1[] =
2045 VK_SHADER_STAGE_VERTEX_BIT,
2046 VK_SHADER_STAGE_GEOMETRY_BIT,
2047 VK_SHADER_STAGE_FRAGMENT_BIT,
2049 const VkShaderStageFlagBits testParamShaders2[] =
2051 VK_SHADER_STAGE_VERTEX_BIT,
2052 VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
2053 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
2054 VK_SHADER_STAGE_FRAGMENT_BIT,
2056 const CacheTestParam testParams[] =
2058 CacheTestParam(testParamShaders0, DE_LENGTH_OF_ARRAY(testParamShaders0), false),
2059 CacheTestParam(testParamShaders1, DE_LENGTH_OF_ARRAY(testParamShaders1), false),
2060 CacheTestParam(testParamShaders2, DE_LENGTH_OF_ARRAY(testParamShaders2), false),
2063 for (deUint32 i = 0; i < DE_LENGTH_OF_ARRAY(testParams); i++)
2064 graphicsTests->addChild(newTestCase<GraphicsCacheTest>(testCtx, &testParams[i]));
2066 cacheTests->addChild(graphicsTests.release());
2069 // Graphics Pipeline Tests
2071 de::MovePtr<tcu::TestCaseGroup> graphicsTests(new tcu::TestCaseGroup(testCtx, "pipeline_from_get_data", "Test pipeline cache with graphics pipeline."));
2073 const VkShaderStageFlagBits testParamShaders0[] =
2075 VK_SHADER_STAGE_VERTEX_BIT,
2076 VK_SHADER_STAGE_FRAGMENT_BIT,
2078 const VkShaderStageFlagBits testParamShaders1[] =
2080 VK_SHADER_STAGE_VERTEX_BIT,
2081 VK_SHADER_STAGE_GEOMETRY_BIT,
2082 VK_SHADER_STAGE_FRAGMENT_BIT,
2084 const VkShaderStageFlagBits testParamShaders2[] =
2086 VK_SHADER_STAGE_VERTEX_BIT,
2087 VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
2088 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
2089 VK_SHADER_STAGE_FRAGMENT_BIT,
2091 const CacheTestParam testParams[] =
2093 CacheTestParam(testParamShaders0, DE_LENGTH_OF_ARRAY(testParamShaders0), false),
2094 CacheTestParam(testParamShaders1, DE_LENGTH_OF_ARRAY(testParamShaders1), false),
2095 CacheTestParam(testParamShaders2, DE_LENGTH_OF_ARRAY(testParamShaders2), false),
2098 for (deUint32 i = 0; i < DE_LENGTH_OF_ARRAY(testParams); i++)
2099 graphicsTests->addChild(newTestCase<PipelineFromCacheTest>(testCtx, &testParams[i]));
2101 cacheTests->addChild(graphicsTests.release());
2104 // Graphics Pipeline Tests
2106 de::MovePtr<tcu::TestCaseGroup> graphicsTests(new tcu::TestCaseGroup(testCtx, "pipeline_from_incomplete_get_data", "Test pipeline cache with graphics pipeline."));
2108 const VkShaderStageFlagBits testParamShaders0[] =
2110 VK_SHADER_STAGE_VERTEX_BIT,
2111 VK_SHADER_STAGE_FRAGMENT_BIT,
2113 const VkShaderStageFlagBits testParamShaders1[] =
2115 VK_SHADER_STAGE_VERTEX_BIT,
2116 VK_SHADER_STAGE_GEOMETRY_BIT,
2117 VK_SHADER_STAGE_FRAGMENT_BIT,
2119 const VkShaderStageFlagBits testParamShaders2[] =
2121 VK_SHADER_STAGE_VERTEX_BIT,
2122 VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
2123 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
2124 VK_SHADER_STAGE_FRAGMENT_BIT,
2126 const CacheTestParam testParams[] =
2128 CacheTestParam(testParamShaders0, DE_LENGTH_OF_ARRAY(testParamShaders0), false),
2129 CacheTestParam(testParamShaders1, DE_LENGTH_OF_ARRAY(testParamShaders1), false),
2130 CacheTestParam(testParamShaders2, DE_LENGTH_OF_ARRAY(testParamShaders2), false),
2133 for (deUint32 i = 0; i < DE_LENGTH_OF_ARRAY(testParams); i++)
2134 graphicsTests->addChild(newTestCase<PipelineFromIncompleteCacheTest>(testCtx, &testParams[i]));
2136 cacheTests->addChild(graphicsTests.release());
2139 // Compute Pipeline Tests
2141 de::MovePtr<tcu::TestCaseGroup> computeTests (new tcu::TestCaseGroup(testCtx, "compute_tests", "Test pipeline cache with compute pipeline."));
2143 const VkShaderStageFlagBits testParamShaders0[] =
2145 VK_SHADER_STAGE_COMPUTE_BIT,
2147 const CacheTestParam testParams[] =
2149 CacheTestParam(testParamShaders0, DE_LENGTH_OF_ARRAY(testParamShaders0), false),
2152 for (deUint32 i = 0; i < DE_LENGTH_OF_ARRAY(testParams); i++)
2153 computeTests->addChild(newTestCase<ComputeCacheTest>(testCtx, &testParams[i]));
2155 cacheTests->addChild(computeTests.release());
2158 // Merge cache Tests
2160 de::MovePtr<tcu::TestCaseGroup> mergeTests (new tcu::TestCaseGroup(testCtx, "merge", "Cache merging tests"));
2162 const VkShaderStageFlagBits testParamShaders0[] =
2164 VK_SHADER_STAGE_VERTEX_BIT,
2165 VK_SHADER_STAGE_FRAGMENT_BIT,
2167 const VkShaderStageFlagBits testParamShaders1[] =
2169 VK_SHADER_STAGE_VERTEX_BIT,
2170 VK_SHADER_STAGE_GEOMETRY_BIT,
2171 VK_SHADER_STAGE_FRAGMENT_BIT,
2173 const VkShaderStageFlagBits testParamShaders2[] =
2175 VK_SHADER_STAGE_VERTEX_BIT,
2176 VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
2177 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
2178 VK_SHADER_STAGE_FRAGMENT_BIT,
2180 const CacheTestParam testParams[] =
2182 CacheTestParam(testParamShaders0, DE_LENGTH_OF_ARRAY(testParamShaders0), true),
2183 CacheTestParam(testParamShaders1, DE_LENGTH_OF_ARRAY(testParamShaders1), true),
2184 CacheTestParam(testParamShaders2, DE_LENGTH_OF_ARRAY(testParamShaders2), true),
2187 for (deUint32 i = 0; i < DE_LENGTH_OF_ARRAY(testParams); i++)
2190 de::MovePtr<tcu::TestCaseGroup> mergeStagesTests(new tcu::TestCaseGroup(testCtx, testParams[i].generateTestName().c_str(), testParams[i].generateTestDescription().c_str()));
2192 for (deUint32 destTypeIdx = 0u; destTypeIdx <= MERGE_CACHE_TYPE_LAST; destTypeIdx++)
2193 for (deUint32 srcType1Idx = 0u; srcType1Idx <= MERGE_CACHE_TYPE_LAST; srcType1Idx++)
2196 MergeCacheTestParam cacheTestParam;
2197 cacheTestParam.destCacheType = MergeCacheType(destTypeIdx);
2198 cacheTestParam.srcCacheTypes.push_back(MergeCacheType(srcType1Idx));
2200 // merge with one cache
2202 std::string testName = "src_" + getMergeCacheTypesStr(cacheTestParam.srcCacheTypes) + "_dst_" + getMergeCacheTypeStr(cacheTestParam.destCacheType);
2203 mergeStagesTests->addChild(new MergeCacheTest(testCtx,
2205 "Merge the caches test.",
2210 // merge with two caches
2211 for (deUint32 srcType2Idx = 0u; srcType2Idx <= MERGE_CACHE_TYPE_LAST; srcType2Idx++)
2213 MergeCacheTestParam cacheTestParamTwoCaches = cacheTestParam;
2215 cacheTestParamTwoCaches.srcCacheTypes.push_back(MergeCacheType(srcType2Idx));
2217 std::string testName = "src_" + getMergeCacheTypesStr(cacheTestParamTwoCaches.srcCacheTypes) + "_dst_" + getMergeCacheTypeStr(cacheTestParamTwoCaches.destCacheType);
2218 mergeStagesTests->addChild(new MergeCacheTest(testCtx,
2220 "Merge the caches test.",
2222 &cacheTestParamTwoCaches));
2225 mergeTests->addChild(mergeStagesTests.release());
2227 cacheTests->addChild(mergeTests.release());
2232 de::MovePtr<tcu::TestCaseGroup> miscTests(new tcu::TestCaseGroup(testCtx, "misc_tests", "Misc tests that can not be categorized to other group."));
2234 const VkShaderStageFlagBits testParamShaders[] =
2236 VK_SHADER_STAGE_VERTEX_BIT,
2237 VK_SHADER_STAGE_FRAGMENT_BIT,
2240 const CacheTestParam testParam(testParamShaders, DE_LENGTH_OF_ARRAY(testParamShaders), false);
2243 miscTests->addChild(new CacheHeaderTest(testCtx,
2244 "cache_header_test",
2245 "Cache header test.",
2248 miscTests->addChild(new InvalidSizeTest(testCtx,
2249 "invalid_size_test",
2250 "Invalid size test.",
2253 miscTests->addChild(new ZeroSizeTest(testCtx,
2258 miscTests->addChild(new InvalidBlobTest(testCtx,
2259 "invalid_blob_test",
2260 "Invalid cache blob test.",
2263 cacheTests->addChild(miscTests.release());
2266 return cacheTests.release();