Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Vulkan Tests |
| 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
| 26 | */ |
| 27 | |
| 28 | #ifndef VKRENDERFRAMEWORK_H |
| 29 | #define VKRENDERFRAMEWORK_H |
| 30 | |
| 31 | #include "vktestframework.h" |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 32 | #include "vk_debug_report_lunarg.h" |
| 33 | #include "vk_debug_marker_lunarg.h" |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 34 | |
| 35 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 36 | class VkDeviceObj : public vk_testing::Device |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 37 | { |
| 38 | public: |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 39 | VkDeviceObj(uint32_t id, VkPhysicalDevice obj); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 40 | VkDeviceObj(uint32_t id, VkPhysicalDevice obj, std::vector<VkExtensionProperties> extension_names); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 41 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 42 | VkDevice device() { return obj(); } |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 43 | void get_device_queue(); |
| 44 | |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 45 | uint32_t id; |
| 46 | VkPhysicalDeviceProperties props; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 47 | const VkPhysicalDeviceQueueProperties *queue_props; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 48 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 49 | VkQueue m_queue; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 50 | }; |
| 51 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 52 | class VkMemoryRefManager |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 53 | { |
| 54 | public: |
| 55 | void AddMemoryRefs(vk_testing::Object &vkObject); |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 56 | void AddMemoryRefs(vector<VkDeviceMemory> mem); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 57 | void EmitAddMemoryRefs(VkQueue queue); |
| 58 | void EmitRemoveMemoryRefs(VkQueue queue); |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 59 | vector<VkDeviceMemory> mem_refs() const; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 60 | |
| 61 | protected: |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 62 | vector<VkDeviceMemory> mem_refs_; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 63 | |
| 64 | }; |
| 65 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 66 | class VkDepthStencilObj : public vk_testing::Image |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 67 | { |
| 68 | public: |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 69 | VkDepthStencilObj(); |
| 70 | void Init(VkDeviceObj *device, int32_t width, int32_t height); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 71 | bool Initialized(); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 72 | VkDepthStencilBindInfo* BindInfo(); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 73 | |
| 74 | protected: |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 75 | VkDeviceObj *m_device; |
| 76 | bool m_initialized; |
| 77 | vk_testing::DepthStencilView m_depthStencilView; |
| 78 | VkFormat m_depth_stencil_fmt; |
| 79 | VkDepthStencilBindInfo m_depthStencilBindInfo; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 80 | }; |
| 81 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 82 | class VkRenderFramework : public VkTestFramework |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 83 | { |
| 84 | public: |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 85 | VkRenderFramework(); |
| 86 | ~VkRenderFramework(); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 87 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 88 | VkDevice device() {return m_device->device();} |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 89 | VkPhysicalDevice gpu() {return objs[0];} |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 90 | VkRenderPass renderPass() {return m_renderPass;} |
| 91 | VkFramebuffer framebuffer() {return m_framebuffer;} |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 92 | void InitViewport(float width, float height); |
| 93 | void InitViewport(); |
| 94 | void InitRenderTarget(); |
| 95 | void InitRenderTarget(uint32_t targets); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 96 | void InitRenderTarget(VkDepthStencilBindInfo *dsBinding); |
| 97 | void InitRenderTarget(uint32_t targets, VkDepthStencilBindInfo *dsBinding); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 98 | void InitFramework(); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 99 | void InitFramework(std::vector<const char *> instance_extension_names, |
| 100 | std::vector<const char *> device_extension_names, |
| 101 | PFN_vkDbgMsgCallback=NULL, |
| 102 | void *userData=NULL); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 103 | void ShutdownFramework(); |
| 104 | void InitState(); |
| 105 | |
| 106 | |
| 107 | protected: |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 108 | VkApplicationInfo app_info; |
| 109 | VkInstance inst; |
| 110 | VkPhysicalDevice objs[16]; |
| 111 | uint32_t gpu_count; |
| 112 | VkDeviceObj *m_device; |
| 113 | VkCmdBuffer m_cmdBuffer; |
| 114 | VkRenderPass m_renderPass; |
| 115 | VkFramebuffer m_framebuffer; |
| 116 | VkDynamicRsState m_stateRaster; |
| 117 | VkDynamicCbState m_colorBlend; |
| 118 | VkDynamicVpState m_stateViewport; |
| 119 | VkDynamicDsState m_stateDepthStencil; |
| 120 | vector<VkImageObj*> m_renderTargets; |
| 121 | float m_width, m_height; |
| 122 | VkFormat m_render_target_fmt; |
| 123 | VkFormat m_depth_stencil_fmt; |
| 124 | VkColorAttachmentBindInfo m_colorBindings[8]; |
| 125 | VkClearColor m_clear_color; |
Chris Forbes | 23e6db6 | 2015-06-15 09:32:35 +1200 | [diff] [blame] | 126 | bool m_clear_via_load_op; |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 127 | float m_depth_clear_color; |
| 128 | uint32_t m_stencil_clear_color; |
| 129 | VkDepthStencilObj *m_depthStencil; |
| 130 | VkMemoryRefManager m_mem_ref_mgr; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 131 | PFN_vkDbgCreateMsgCallback m_dbgCreateMsgCallback; |
| 132 | VkDbgMsgCallback m_msgCallback; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 133 | |
| 134 | /* |
| 135 | * SetUp and TearDown are called by the Google Test framework |
| 136 | * to initialize a test framework based on this class. |
| 137 | */ |
| 138 | virtual void SetUp() { |
| 139 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
| 140 | this->app_info.pNext = NULL; |
| 141 | this->app_info.pAppName = "base"; |
| 142 | this->app_info.appVersion = 1; |
| 143 | this->app_info.pEngineName = "unittest"; |
| 144 | this->app_info.engineVersion = 1; |
| 145 | this->app_info.apiVersion = VK_API_VERSION; |
| 146 | |
| 147 | InitFramework(); |
| 148 | } |
| 149 | |
| 150 | virtual void TearDown() { |
| 151 | ShutdownFramework(); |
| 152 | } |
| 153 | }; |
| 154 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 155 | class VkDescriptorSetObj; |
| 156 | class VkIndexBufferObj; |
| 157 | class VkConstantBufferObj; |
| 158 | class VkPipelineObj; |
| 159 | class VkDescriptorSetObj; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 160 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 161 | class VkCommandBufferObj : public vk_testing::CmdBuffer |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 162 | { |
| 163 | public: |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 164 | VkCommandBufferObj(VkDeviceObj *device); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 165 | VkCmdBuffer GetBufferHandle(); |
| 166 | VkResult BeginCommandBuffer(); |
| 167 | VkResult BeginCommandBuffer(VkCmdBufferBeginInfo *pInfo); |
| 168 | VkResult BeginCommandBuffer(VkRenderPass renderpass_obj, VkFramebuffer framebuffer_obj); |
| 169 | VkResult EndCommandBuffer(); |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 170 | void PipelineBarrier(VkWaitEvent waitEvent, uint32_t pipeEventCount, const VkPipeEvent* pPipeEvents, uint32_t memBarrierCount, const void** ppMemBarriers); |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 171 | void AddRenderTarget(VkImageObj *renderTarget); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 172 | void AddDepthStencil(); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 173 | void ClearAllBuffers(VkClearColor clear_color, float depth_clear_color, uint32_t stencil_clear_color, VkDepthStencilObj *depthStencilObj); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 174 | void PrepareAttachments(); |
| 175 | void AddMemoryRefs(vk_testing::Object &vkObject); |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 176 | void AddMemoryRefs(uint32_t ref_count, const VkDeviceMemory *mem); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 177 | void AddMemoryRefs(vector<vk_testing::Object *> images); |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 178 | void BindPipeline(VkPipelineObj &pipeline); |
| 179 | void BindDescriptorSet(VkDescriptorSetObj &descriptorSet); |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 180 | void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding); |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 181 | void BindIndexBuffer(VkIndexBufferObj *indexBuffer, uint32_t offset); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 182 | void BindStateObject(VkStateBindPoint stateBindPoint, VkDynamicStateObject stateObject); |
| 183 | void BeginRenderPass(VkRenderPass renderpass, VkFramebuffer framebuffer); |
| 184 | void EndRenderPass(VkRenderPass renderpass); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 185 | void Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount); |
| 186 | void DrawIndexed(uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount); |
| 187 | void QueueCommandBuffer(); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 188 | void QueueCommandBuffer(VkFence fence); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 189 | |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 190 | VkMemoryRefManager mem_ref_mgr; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 191 | |
| 192 | protected: |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 193 | VkDeviceObj *m_device; |
| 194 | vector<VkImageObj*> m_renderTargets; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 195 | }; |
| 196 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 197 | class VkConstantBufferObj : public vk_testing::Buffer |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 198 | { |
| 199 | public: |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 200 | VkConstantBufferObj(VkDeviceObj *device); |
| 201 | VkConstantBufferObj(VkDeviceObj *device, int constantCount, int constantSize, const void* data); |
| 202 | ~VkConstantBufferObj(); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 203 | void BufferMemoryBarrier( |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 204 | VkFlags outputMask = |
Courtney Goeltzenleuchter | a569a50 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 205 | VK_MEMORY_OUTPUT_HOST_WRITE_BIT | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 206 | VK_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 207 | VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 208 | VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
Courtney Goeltzenleuchter | ad87081 | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 209 | VK_MEMORY_OUTPUT_TRANSFER_BIT, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 210 | VkFlags inputMask = |
Courtney Goeltzenleuchter | a569a50 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 211 | VK_MEMORY_INPUT_HOST_READ_BIT | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 212 | VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 213 | VK_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 214 | VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 215 | VK_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 216 | VK_MEMORY_INPUT_SHADER_READ_BIT | |
| 217 | VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 218 | VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
Courtney Goeltzenleuchter | ad87081 | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 219 | VK_MEMORY_INPUT_TRANSFER_BIT); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 220 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 221 | void Bind(VkCmdBuffer cmdBuffer, VkDeviceSize offset, uint32_t binding); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 222 | |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 223 | VkDescriptorInfo m_descriptorInfo; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 224 | |
| 225 | protected: |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 226 | VkDeviceObj *m_device; |
| 227 | vk_testing::BufferView m_bufferView; |
| 228 | int m_numVertices; |
| 229 | int m_stride; |
| 230 | VkCommandBufferObj *m_commandBuffer; |
| 231 | vk_testing::Fence m_fence; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 232 | }; |
| 233 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 234 | class VkIndexBufferObj : public VkConstantBufferObj |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 235 | { |
| 236 | public: |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 237 | VkIndexBufferObj(VkDeviceObj *device); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 238 | void CreateAndInitBuffer(int numIndexes, VkIndexType dataFormat, const void* data); |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 239 | void Bind(VkCmdBuffer cmdBuffer, VkDeviceSize offset); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 240 | VkIndexType GetIndexType(); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 241 | |
| 242 | protected: |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 243 | VkIndexType m_indexType; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 244 | }; |
| 245 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 246 | class VkImageObj : public vk_testing::Image |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 247 | { |
| 248 | public: |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 249 | VkImageObj(VkDeviceObj *dev); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 250 | bool IsCompatible(VkFlags usage, VkFlags features); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 251 | |
| 252 | public: |
| 253 | void init(uint32_t w, uint32_t h, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 254 | VkFormat fmt, VkFlags usage, |
Tony Barbour | 9431056 | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 255 | VkImageTiling tiling=VK_IMAGE_TILING_LINEAR, |
| 256 | VkMemoryPropertyFlags reqs=0); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 257 | |
| 258 | // void clear( CommandBuffer*, uint32_t[4] ); |
| 259 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 260 | void layout( VkImageLayout layout ) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 261 | { |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 262 | m_descriptorInfo.imageLayout = layout; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 263 | } |
| 264 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 265 | VkDeviceMemory memory() const |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 266 | { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 267 | const std::vector<VkDeviceMemory> mems = memories(); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 268 | return mems.empty() ? VK_NULL_HANDLE : mems[0]; |
| 269 | } |
| 270 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 271 | void ImageMemoryBarrier(VkCommandBufferObj *cmd, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 272 | VkImageAspect aspect, |
| 273 | VkFlags output_mask, |
| 274 | VkFlags input_mask, |
| 275 | VkImageLayout image_layout); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 276 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 277 | VkResult CopyImage(VkImageObj &src_image); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 278 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 279 | VkImage image() const |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 280 | { |
| 281 | return obj(); |
| 282 | } |
| 283 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 284 | VkColorAttachmentView targetView() |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 285 | { |
| 286 | if (!m_targetView.initialized()) |
| 287 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 288 | VkColorAttachmentViewCreateInfo createView = { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 289 | VK_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO, |
| 290 | VK_NULL_HANDLE, |
| 291 | obj(), |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 292 | VK_FORMAT_B8G8R8A8_UNORM, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 293 | 0, |
| 294 | 0, |
| 295 | 1 |
| 296 | }; |
| 297 | m_targetView.init(*m_device, createView); |
| 298 | } |
| 299 | return m_targetView.obj(); |
| 300 | } |
| 301 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 302 | void SetLayout(VkCommandBufferObj *cmd_buf, VkImageAspect aspect, VkImageLayout image_layout); |
| 303 | void SetLayout(VkImageAspect aspect, VkImageLayout image_layout); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 304 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 305 | VkImageLayout layout() const |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 306 | { |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 307 | return m_descriptorInfo.imageLayout; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 308 | } |
| 309 | uint32_t width() const |
| 310 | { |
| 311 | return extent().width; |
| 312 | } |
| 313 | uint32_t height() const |
| 314 | { |
| 315 | return extent().height; |
| 316 | } |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 317 | VkDeviceObj* device() const |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 318 | { |
| 319 | return m_device; |
| 320 | } |
| 321 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 322 | VkResult MapMemory(void** ptr); |
| 323 | VkResult UnmapMemory(); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 324 | |
| 325 | protected: |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 326 | VkDeviceObj *m_device; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 327 | |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 328 | vk_testing::ColorAttachmentView m_targetView; |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 329 | VkDescriptorInfo m_descriptorInfo; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 330 | }; |
| 331 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 332 | class VkTextureObj : public VkImageObj |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 333 | { |
| 334 | public: |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 335 | VkTextureObj(VkDeviceObj *device, uint32_t *colors = NULL); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 336 | |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 337 | VkDescriptorInfo m_descriptorInfo; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 338 | |
| 339 | protected: |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 340 | VkDeviceObj *m_device; |
| 341 | vk_testing::ImageView m_textureView; |
| 342 | VkDeviceSize m_rowPitch; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 343 | }; |
| 344 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 345 | class VkSamplerObj : public vk_testing::Sampler |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 346 | { |
| 347 | public: |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 348 | VkSamplerObj(VkDeviceObj *device); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 349 | |
| 350 | protected: |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 351 | VkDeviceObj *m_device; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 352 | |
| 353 | }; |
| 354 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 355 | class VkDescriptorSetObj : public vk_testing::DescriptorPool |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 356 | { |
| 357 | public: |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 358 | VkDescriptorSetObj(VkDeviceObj *device); |
| 359 | ~VkDescriptorSetObj(); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 360 | |
| 361 | int AppendDummy(); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 362 | int AppendBuffer(VkDescriptorType type, VkConstantBufferObj &constantBuffer); |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 363 | int AppendSamplerTexture(VkSamplerObj* sampler, VkTextureObj* texture); |
| 364 | void CreateVKDescriptorSet(VkCommandBufferObj *cmdBuffer); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 365 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 366 | VkDescriptorSet GetDescriptorSetHandle() const; |
Mark Lobodzinski | 556f721 | 2015-04-17 14:11:39 -0500 | [diff] [blame] | 367 | VkPipelineLayout GetPipelineLayout() const; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 368 | |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 369 | VkMemoryRefManager mem_ref_mgr; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 370 | |
| 371 | protected: |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 372 | VkDeviceObj *m_device; |
| 373 | vector<VkDescriptorTypeCount> m_type_counts; |
| 374 | int m_nextSlot; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 375 | |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 376 | vector<VkDescriptorInfo> m_imageSamplerDescriptors; |
| 377 | vector<VkWriteDescriptorSet> m_writes; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 378 | |
| 379 | vk_testing::DescriptorSetLayout m_layout; |
Mark Lobodzinski | 556f721 | 2015-04-17 14:11:39 -0500 | [diff] [blame] | 380 | vk_testing::PipelineLayout m_pipeline_layout; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 381 | vk_testing::DescriptorSet *m_set; |
| 382 | }; |
| 383 | |
| 384 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 385 | class VkShaderObj : public vk_testing::Shader |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 386 | { |
| 387 | public: |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 388 | VkShaderObj(VkDeviceObj *device, const char * shaderText, VkShaderStage stage, VkRenderFramework *framework); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 389 | VkPipelineShaderStageCreateInfo* GetStageCreateInfo(); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 390 | |
| 391 | protected: |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 392 | VkPipelineShaderStageCreateInfo stage_info; |
| 393 | VkShaderStage m_stage; |
| 394 | VkDeviceObj *m_device; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 395 | |
| 396 | }; |
| 397 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 398 | class VkPipelineObj : public vk_testing::Pipeline |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 399 | { |
| 400 | public: |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 401 | VkPipelineObj(VkDeviceObj *device); |
| 402 | void AddShader(VkShaderObj* shaderObj); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 403 | void AddVertexInputAttribs(VkVertexInputAttributeDescription* vi_attrib, int count); |
| 404 | void AddVertexInputBindings(VkVertexInputBindingDescription* vi_binding, int count); |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 405 | void AddVertexDataBuffer(VkConstantBufferObj* vertexDataBuffer, int binding); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 406 | void AddColorAttachment(uint32_t binding, const VkPipelineCbAttachmentState *att); |
| 407 | void SetDepthStencil(VkPipelineDsStateCreateInfo *); |
Chris Forbes | dc2188c | 2015-05-25 11:13:26 +1200 | [diff] [blame] | 408 | VkResult CreateVKPipeline(VkDescriptorSetObj &descriptorSet); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 409 | |
| 410 | protected: |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 411 | VkPipelineVertexInputCreateInfo m_vi_state; |
| 412 | VkPipelineIaStateCreateInfo m_ia_state; |
| 413 | VkPipelineRsStateCreateInfo m_rs_state; |
| 414 | VkPipelineCbStateCreateInfo m_cb_state; |
| 415 | VkPipelineDsStateCreateInfo m_ds_state; |
Tony Barbour | 5e24513 | 2015-05-15 09:37:57 -0600 | [diff] [blame] | 416 | VkPipelineVpStateCreateInfo m_vp_state; |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 417 | VkPipelineMsStateCreateInfo m_ms_state; |
| 418 | VkDeviceObj *m_device; |
| 419 | vector<VkShaderObj*> m_shaderObjs; |
| 420 | vector<VkConstantBufferObj*> m_vertexBufferObjs; |
| 421 | vector<int> m_vertexBufferBindings; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 422 | vector<VkPipelineCbAttachmentState> m_colorAttachments; |
Courtney Goeltzenleuchter | ec69b9c | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 423 | int m_vertexBufferCount; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 424 | |
| 425 | }; |
| 426 | |
| 427 | #endif // VKRENDERFRAMEWORK_H |