Courtney Goeltzenleuchter | d8e229c | 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 | f579fa6 | 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 | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 34 | |
| 35 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 36 | class VkDeviceObj : public vk_testing::Device |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 37 | { |
| 38 | public: |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 39 | VkDeviceObj(uint32_t id, VkPhysicalDevice obj); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 40 | VkDeviceObj(uint32_t id, VkPhysicalDevice obj, std::vector<VkExtensionProperties> extension_names); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 41 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 42 | VkDevice device() { return obj(); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 43 | void get_device_queue(); |
| 44 | |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 45 | uint32_t id; |
| 46 | VkPhysicalDeviceProperties props; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 47 | const VkPhysicalDeviceQueueProperties *queue_props; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 48 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 49 | VkQueue m_queue; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 50 | }; |
| 51 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 52 | class VkMemoryRefManager |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 53 | { |
| 54 | public: |
| 55 | void AddMemoryRefs(vk_testing::Object &vkObject); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 56 | void AddMemoryRefs(vector<VkDeviceMemory> mem); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 57 | void EmitAddMemoryRefs(VkQueue queue); |
| 58 | void EmitRemoveMemoryRefs(VkQueue queue); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 59 | vector<VkDeviceMemory> mem_refs() const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 60 | |
| 61 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 62 | vector<VkDeviceMemory> mem_refs_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 63 | |
| 64 | }; |
| 65 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 66 | class VkDepthStencilObj : public vk_testing::Image |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 67 | { |
| 68 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 69 | VkDepthStencilObj(); |
| 70 | void Init(VkDeviceObj *device, int32_t width, int32_t height); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 71 | bool Initialized(); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 72 | VkDepthStencilBindInfo* BindInfo(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 73 | |
| 74 | protected: |
Courtney Goeltzenleuchter | d6079ec | 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 | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 80 | }; |
| 81 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 82 | class VkRenderFramework : public VkTestFramework |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 83 | { |
| 84 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 85 | VkRenderFramework(); |
| 86 | ~VkRenderFramework(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 87 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 88 | VkDevice device() {return m_device->device();} |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 89 | VkPhysicalDevice gpu() {return objs[0];} |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 90 | VkRenderPass renderPass() {return m_renderPass;} |
| 91 | VkFramebuffer framebuffer() {return m_framebuffer;} |
Courtney Goeltzenleuchter | d8e229c | 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 | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 96 | void InitRenderTarget(VkDepthStencilBindInfo *dsBinding); |
| 97 | void InitRenderTarget(uint32_t targets, VkDepthStencilBindInfo *dsBinding); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 98 | void InitFramework(); |
Courtney Goeltzenleuchter | f579fa6 | 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 | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 103 | void ShutdownFramework(); |
| 104 | void InitState(); |
| 105 | |
| 106 | |
| 107 | protected: |
Courtney Goeltzenleuchter | d6079ec | 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 | e182fe0 | 2015-06-15 09:32:35 +1200 | [diff] [blame] | 126 | bool m_clear_via_load_op; |
Courtney Goeltzenleuchter | d6079ec | 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 | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 131 | PFN_vkDbgCreateMsgCallback m_dbgCreateMsgCallback; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame^] | 132 | VkDbgMsgCallback m_globalMsgCallback; |
| 133 | VkDbgMsgCallback m_devMsgCallback; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * SetUp and TearDown are called by the Google Test framework |
| 137 | * to initialize a test framework based on this class. |
| 138 | */ |
| 139 | virtual void SetUp() { |
| 140 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
| 141 | this->app_info.pNext = NULL; |
| 142 | this->app_info.pAppName = "base"; |
| 143 | this->app_info.appVersion = 1; |
| 144 | this->app_info.pEngineName = "unittest"; |
| 145 | this->app_info.engineVersion = 1; |
| 146 | this->app_info.apiVersion = VK_API_VERSION; |
| 147 | |
| 148 | InitFramework(); |
| 149 | } |
| 150 | |
| 151 | virtual void TearDown() { |
| 152 | ShutdownFramework(); |
| 153 | } |
| 154 | }; |
| 155 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 156 | class VkDescriptorSetObj; |
| 157 | class VkIndexBufferObj; |
| 158 | class VkConstantBufferObj; |
| 159 | class VkPipelineObj; |
| 160 | class VkDescriptorSetObj; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 161 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 162 | class VkCommandBufferObj : public vk_testing::CmdBuffer |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 163 | { |
| 164 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 165 | VkCommandBufferObj(VkDeviceObj *device); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 166 | VkCmdBuffer GetBufferHandle(); |
| 167 | VkResult BeginCommandBuffer(); |
| 168 | VkResult BeginCommandBuffer(VkCmdBufferBeginInfo *pInfo); |
| 169 | VkResult BeginCommandBuffer(VkRenderPass renderpass_obj, VkFramebuffer framebuffer_obj); |
| 170 | VkResult EndCommandBuffer(); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 171 | void PipelineBarrier(VkWaitEvent waitEvent, uint32_t pipeEventCount, const VkPipeEvent* pPipeEvents, uint32_t memBarrierCount, const void** ppMemBarriers); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 172 | void AddRenderTarget(VkImageObj *renderTarget); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 173 | void AddDepthStencil(); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 174 | void ClearAllBuffers(VkClearColor clear_color, float depth_clear_color, uint32_t stencil_clear_color, VkDepthStencilObj *depthStencilObj); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 175 | void PrepareAttachments(); |
| 176 | void AddMemoryRefs(vk_testing::Object &vkObject); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 177 | void AddMemoryRefs(uint32_t ref_count, const VkDeviceMemory *mem); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 178 | void AddMemoryRefs(vector<vk_testing::Object *> images); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 179 | void BindPipeline(VkPipelineObj &pipeline); |
| 180 | void BindDescriptorSet(VkDescriptorSetObj &descriptorSet); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 181 | void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 182 | void BindIndexBuffer(VkIndexBufferObj *indexBuffer, uint32_t offset); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 183 | void BindStateObject(VkStateBindPoint stateBindPoint, VkDynamicStateObject stateObject); |
| 184 | void BeginRenderPass(VkRenderPass renderpass, VkFramebuffer framebuffer); |
| 185 | void EndRenderPass(VkRenderPass renderpass); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 186 | void Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount); |
| 187 | void DrawIndexed(uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount); |
| 188 | void QueueCommandBuffer(); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 189 | void QueueCommandBuffer(VkFence fence); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 190 | |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 191 | VkMemoryRefManager mem_ref_mgr; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 192 | |
| 193 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 194 | VkDeviceObj *m_device; |
| 195 | vector<VkImageObj*> m_renderTargets; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 196 | }; |
| 197 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 198 | class VkConstantBufferObj : public vk_testing::Buffer |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 199 | { |
| 200 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 201 | VkConstantBufferObj(VkDeviceObj *device); |
| 202 | VkConstantBufferObj(VkDeviceObj *device, int constantCount, int constantSize, const void* data); |
| 203 | ~VkConstantBufferObj(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 204 | void BufferMemoryBarrier( |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 205 | VkFlags outputMask = |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 206 | VK_MEMORY_OUTPUT_HOST_WRITE_BIT | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 207 | VK_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 208 | VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 209 | VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 210 | VK_MEMORY_OUTPUT_TRANSFER_BIT, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 211 | VkFlags inputMask = |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 212 | VK_MEMORY_INPUT_HOST_READ_BIT | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 213 | VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 214 | VK_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 215 | VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 216 | VK_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 217 | VK_MEMORY_INPUT_SHADER_READ_BIT | |
| 218 | VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 219 | VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 220 | VK_MEMORY_INPUT_TRANSFER_BIT); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 221 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 222 | void Bind(VkCmdBuffer cmdBuffer, VkDeviceSize offset, uint32_t binding); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 223 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 224 | VkDescriptorInfo m_descriptorInfo; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 225 | |
| 226 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 227 | VkDeviceObj *m_device; |
| 228 | vk_testing::BufferView m_bufferView; |
| 229 | int m_numVertices; |
| 230 | int m_stride; |
| 231 | VkCommandBufferObj *m_commandBuffer; |
| 232 | vk_testing::Fence m_fence; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 233 | }; |
| 234 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 235 | class VkIndexBufferObj : public VkConstantBufferObj |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 236 | { |
| 237 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 238 | VkIndexBufferObj(VkDeviceObj *device); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 239 | void CreateAndInitBuffer(int numIndexes, VkIndexType dataFormat, const void* data); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 240 | void Bind(VkCmdBuffer cmdBuffer, VkDeviceSize offset); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 241 | VkIndexType GetIndexType(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 242 | |
| 243 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 244 | VkIndexType m_indexType; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 245 | }; |
| 246 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 247 | class VkImageObj : public vk_testing::Image |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 248 | { |
| 249 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 250 | VkImageObj(VkDeviceObj *dev); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 251 | bool IsCompatible(VkFlags usage, VkFlags features); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 252 | |
| 253 | public: |
| 254 | void init(uint32_t w, uint32_t h, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 255 | VkFormat fmt, VkFlags usage, |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 256 | VkImageTiling tiling=VK_IMAGE_TILING_LINEAR, |
| 257 | VkMemoryPropertyFlags reqs=0); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 258 | |
| 259 | // void clear( CommandBuffer*, uint32_t[4] ); |
| 260 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 261 | void layout( VkImageLayout layout ) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 262 | { |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 263 | m_descriptorInfo.imageLayout = layout; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 264 | } |
| 265 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 266 | VkDeviceMemory memory() const |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 267 | { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 268 | const std::vector<VkDeviceMemory> mems = memories(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 269 | return mems.empty() ? VK_NULL_HANDLE : mems[0]; |
| 270 | } |
| 271 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 272 | void ImageMemoryBarrier(VkCommandBufferObj *cmd, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 273 | VkImageAspect aspect, |
| 274 | VkFlags output_mask, |
| 275 | VkFlags input_mask, |
| 276 | VkImageLayout image_layout); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 277 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 278 | VkResult CopyImage(VkImageObj &src_image); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 279 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 280 | VkImage image() const |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 281 | { |
| 282 | return obj(); |
| 283 | } |
| 284 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 285 | VkColorAttachmentView targetView() |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 286 | { |
| 287 | if (!m_targetView.initialized()) |
| 288 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 289 | VkColorAttachmentViewCreateInfo createView = { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 290 | VK_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO, |
| 291 | VK_NULL_HANDLE, |
| 292 | obj(), |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 293 | VK_FORMAT_B8G8R8A8_UNORM, |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 294 | 0, |
| 295 | 0, |
| 296 | 1 |
| 297 | }; |
| 298 | m_targetView.init(*m_device, createView); |
| 299 | } |
| 300 | return m_targetView.obj(); |
| 301 | } |
| 302 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 303 | void SetLayout(VkCommandBufferObj *cmd_buf, VkImageAspect aspect, VkImageLayout image_layout); |
| 304 | void SetLayout(VkImageAspect aspect, VkImageLayout image_layout); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 305 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 306 | VkImageLayout layout() const |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 307 | { |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 308 | return m_descriptorInfo.imageLayout; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 309 | } |
| 310 | uint32_t width() const |
| 311 | { |
| 312 | return extent().width; |
| 313 | } |
| 314 | uint32_t height() const |
| 315 | { |
| 316 | return extent().height; |
| 317 | } |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 318 | VkDeviceObj* device() const |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 319 | { |
| 320 | return m_device; |
| 321 | } |
| 322 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 323 | VkResult MapMemory(void** ptr); |
| 324 | VkResult UnmapMemory(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 325 | |
| 326 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 327 | VkDeviceObj *m_device; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 328 | |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 329 | vk_testing::ColorAttachmentView m_targetView; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 330 | VkDescriptorInfo m_descriptorInfo; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 331 | }; |
| 332 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 333 | class VkTextureObj : public VkImageObj |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 334 | { |
| 335 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 336 | VkTextureObj(VkDeviceObj *device, uint32_t *colors = NULL); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 337 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 338 | VkDescriptorInfo m_descriptorInfo; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 339 | |
| 340 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 341 | VkDeviceObj *m_device; |
| 342 | vk_testing::ImageView m_textureView; |
| 343 | VkDeviceSize m_rowPitch; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 344 | }; |
| 345 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 346 | class VkSamplerObj : public vk_testing::Sampler |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 347 | { |
| 348 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 349 | VkSamplerObj(VkDeviceObj *device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 350 | |
| 351 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 352 | VkDeviceObj *m_device; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 353 | |
| 354 | }; |
| 355 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 356 | class VkDescriptorSetObj : public vk_testing::DescriptorPool |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 357 | { |
| 358 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 359 | VkDescriptorSetObj(VkDeviceObj *device); |
| 360 | ~VkDescriptorSetObj(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 361 | |
| 362 | int AppendDummy(); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 363 | int AppendBuffer(VkDescriptorType type, VkConstantBufferObj &constantBuffer); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 364 | int AppendSamplerTexture(VkSamplerObj* sampler, VkTextureObj* texture); |
| 365 | void CreateVKDescriptorSet(VkCommandBufferObj *cmdBuffer); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 366 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 367 | VkDescriptorSet GetDescriptorSetHandle() const; |
Mark Lobodzinski | 0fadf5f | 2015-04-17 14:11:39 -0500 | [diff] [blame] | 368 | VkPipelineLayout GetPipelineLayout() const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 369 | |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 370 | VkMemoryRefManager mem_ref_mgr; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 371 | |
| 372 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 373 | VkDeviceObj *m_device; |
| 374 | vector<VkDescriptorTypeCount> m_type_counts; |
| 375 | int m_nextSlot; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 376 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 377 | vector<VkDescriptorInfo> m_imageSamplerDescriptors; |
| 378 | vector<VkWriteDescriptorSet> m_writes; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 379 | |
| 380 | vk_testing::DescriptorSetLayout m_layout; |
Mark Lobodzinski | 0fadf5f | 2015-04-17 14:11:39 -0500 | [diff] [blame] | 381 | vk_testing::PipelineLayout m_pipeline_layout; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 382 | vk_testing::DescriptorSet *m_set; |
| 383 | }; |
| 384 | |
| 385 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 386 | class VkShaderObj : public vk_testing::Shader |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 387 | { |
| 388 | public: |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 389 | VkShaderObj(VkDeviceObj *device, const char * shaderText, VkShaderStage stage, VkRenderFramework *framework); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 390 | VkPipelineShaderStageCreateInfo* GetStageCreateInfo(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 391 | |
| 392 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 393 | VkPipelineShaderStageCreateInfo stage_info; |
| 394 | VkShaderStage m_stage; |
| 395 | VkDeviceObj *m_device; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 396 | |
| 397 | }; |
| 398 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 399 | class VkPipelineObj : public vk_testing::Pipeline |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 400 | { |
| 401 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 402 | VkPipelineObj(VkDeviceObj *device); |
| 403 | void AddShader(VkShaderObj* shaderObj); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 404 | void AddVertexInputAttribs(VkVertexInputAttributeDescription* vi_attrib, int count); |
| 405 | void AddVertexInputBindings(VkVertexInputBindingDescription* vi_binding, int count); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 406 | void AddVertexDataBuffer(VkConstantBufferObj* vertexDataBuffer, int binding); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 407 | void AddColorAttachment(uint32_t binding, const VkPipelineCbAttachmentState *att); |
| 408 | void SetDepthStencil(VkPipelineDsStateCreateInfo *); |
Chris Forbes | 95292b1 | 2015-05-25 11:13:26 +1200 | [diff] [blame] | 409 | VkResult CreateVKPipeline(VkDescriptorSetObj &descriptorSet); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 410 | |
| 411 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 412 | VkPipelineVertexInputCreateInfo m_vi_state; |
| 413 | VkPipelineIaStateCreateInfo m_ia_state; |
| 414 | VkPipelineRsStateCreateInfo m_rs_state; |
| 415 | VkPipelineCbStateCreateInfo m_cb_state; |
| 416 | VkPipelineDsStateCreateInfo m_ds_state; |
Tony Barbour | d81b888 | 2015-05-15 09:37:57 -0600 | [diff] [blame] | 417 | VkPipelineVpStateCreateInfo m_vp_state; |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 418 | VkPipelineMsStateCreateInfo m_ms_state; |
| 419 | VkDeviceObj *m_device; |
| 420 | vector<VkShaderObj*> m_shaderObjs; |
| 421 | vector<VkConstantBufferObj*> m_vertexBufferObjs; |
| 422 | vector<int> m_vertexBufferBindings; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 423 | vector<VkPipelineCbAttachmentState> m_colorAttachments; |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 424 | int m_vertexBufferCount; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 425 | |
| 426 | }; |
| 427 | |
| 428 | #endif // VKRENDERFRAMEWORK_H |