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