1 #ifndef _VKTROBUSTNESSUTIL_HPP 2 #define _VKTROBUSTNESSUTIL_HPP 3 /*------------------------------------------------------------------------ 4 * Vulkan Conformance Tests 5 * ------------------------ 6 * 7 * Copyright (c) 2016 The Khronos Group Inc. 8 * Copyright (c) 2016 Imagination Technologies Ltd. 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); 11 * you may not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 * See the License for the specific language governing permissions and 20 * limitations under the License. 21 * 22 *//*! 23 * \file 24 * \brief Robustness Utilities 25 *//*--------------------------------------------------------------------*/ 26 27 #include "tcuDefs.hpp" 28 #include "vkDefs.hpp" 29 #include "vkRefUtil.hpp" 30 #include "vktTestCase.hpp" 31 #include "vkMemUtil.hpp" 32 #include "deUniquePtr.hpp" 33 #include "tcuVectorUtil.hpp" 34 #include "vktCustomInstancesDevices.hpp" 35 36 namespace vkt 37 { 38 namespace robustness 39 { 40 41 vk::Move<vk::VkDevice> createRobustBufferAccessDevice(Context &context, 42 #ifdef CTS_USES_VULKANSC 43 const vkt::CustomInstance &customInstance, 44 #endif // CTS_USES_VULKANSC 45 const vk::VkPhysicalDeviceFeatures2 *enabledFeatures2 = DE_NULL); 46 bool areEqual(float a, float b); 47 bool isValueZero(const void *valuePtr, size_t valueSize); 48 bool isValueWithinBuffer(const void *buffer, vk::VkDeviceSize bufferSize, const void *valuePtr, 49 size_t valueSizeInBytes); 50 bool isValueWithinBufferOrZero(const void *buffer, vk::VkDeviceSize bufferSize, const void *valuePtr, 51 size_t valueSizeInBytes); 52 bool verifyOutOfBoundsVec4(const void *vecPtr, vk::VkFormat bufferFormat); 53 void populateBufferWithTestValues(void *buffer, vk::VkDeviceSize size, vk::VkFormat format); 54 void logValue(std::ostringstream &logMsg, const void *valuePtr, vk::VkFormat valueFormat, size_t valueSize); 55 56 class TestEnvironment 57 { 58 public: 59 TestEnvironment(Context &context, const vk::DeviceInterface &vk, vk::VkDevice device, 60 vk::VkDescriptorSetLayout descriptorSetLayout, vk::VkDescriptorSet descriptorSet); 61 ~TestEnvironment(void)62 virtual ~TestEnvironment(void) 63 { 64 } 65 66 virtual vk::VkCommandBuffer getCommandBuffer(void); 67 68 protected: 69 Context &m_context; 70 vk::VkDevice m_device; 71 vk::VkDescriptorSetLayout m_descriptorSetLayout; 72 vk::VkDescriptorSet m_descriptorSet; 73 74 vk::Move<vk::VkCommandPool> m_commandPool; 75 vk::Move<vk::VkCommandBuffer> m_commandBuffer; 76 }; 77 78 class GraphicsEnvironment : public TestEnvironment 79 { 80 public: 81 typedef std::vector<vk::VkVertexInputBindingDescription> VertexBindings; 82 typedef std::vector<vk::VkVertexInputAttributeDescription> VertexAttributes; 83 84 struct DrawConfig 85 { 86 std::vector<vk::VkBuffer> vertexBuffers; 87 uint32_t vertexCount; 88 uint32_t instanceCount; 89 90 vk::VkBuffer indexBuffer; 91 uint32_t indexCount; 92 }; 93 94 GraphicsEnvironment(Context &context, const vk::DeviceInterface &vk, vk::VkDevice device, 95 vk::VkDescriptorSetLayout descriptorSetLayout, vk::VkDescriptorSet descriptorSet, 96 const VertexBindings &vertexBindings, const VertexAttributes &vertexAttributes, 97 const DrawConfig &drawConfig, bool testPipelineRobustness = false); 98 ~GraphicsEnvironment(void)99 virtual ~GraphicsEnvironment(void) 100 { 101 } 102 103 private: 104 const tcu::UVec2 m_renderSize; 105 const vk::VkFormat m_colorFormat; 106 107 vk::Move<vk::VkImage> m_colorImage; 108 de::MovePtr<vk::Allocation> m_colorImageAlloc; 109 vk::Move<vk::VkImageView> m_colorAttachmentView; 110 vk::Move<vk::VkRenderPass> m_renderPass; 111 vk::Move<vk::VkFramebuffer> m_framebuffer; 112 113 vk::Move<vk::VkShaderModule> m_vertexShaderModule; 114 vk::Move<vk::VkShaderModule> m_fragmentShaderModule; 115 116 vk::Move<vk::VkBuffer> m_vertexBuffer; 117 de::MovePtr<vk::Allocation> m_vertexBufferAlloc; 118 119 vk::Move<vk::VkPipelineLayout> m_pipelineLayout; 120 vk::Move<vk::VkPipeline> m_graphicsPipeline; 121 }; 122 123 class ComputeEnvironment : public TestEnvironment 124 { 125 public: 126 ComputeEnvironment(Context &context, const vk::DeviceInterface &vk, vk::VkDevice device, 127 vk::VkDescriptorSetLayout descriptorSetLayout, vk::VkDescriptorSet descriptorSet, 128 bool testPipelineRobustness = false); 129 ~ComputeEnvironment(void)130 virtual ~ComputeEnvironment(void) 131 { 132 } 133 134 private: 135 vk::Move<vk::VkShaderModule> m_computeShaderModule; 136 vk::Move<vk::VkPipelineLayout> m_pipelineLayout; 137 vk::Move<vk::VkPipeline> m_computePipeline; 138 }; 139 140 } // namespace robustness 141 } // namespace vkt 142 143 #endif // _VKTROBUSTNESSUTIL_HPP 144