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