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