Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Vulkan Tests |
| 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
| 26 | */ |
| 27 | |
| 28 | #ifndef VKRENDERFRAMEWORK_H |
| 29 | #define VKRENDERFRAMEWORK_H |
| 30 | |
| 31 | #include "vktestframework.h" |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 32 | #include "vk_debug_report_lunarg.h" |
| 33 | #include "vk_debug_marker_lunarg.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 34 | |
| 35 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 36 | class VkDeviceObj : public vk_testing::Device |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 37 | { |
| 38 | public: |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 39 | VkDeviceObj(uint32_t id, VkPhysicalDevice obj); |
Courtney Goeltzenleuchter | 5bac609 | 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 | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 43 | |
Chia-I Wu | f368b60 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 44 | VkDevice device() { return handle(); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 45 | void get_device_queue(); |
| 46 | |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 47 | uint32_t id; |
| 48 | VkPhysicalDeviceProperties props; |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 49 | const VkQueueFamilyProperties *queue_props; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 50 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 51 | VkQueue m_queue; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 52 | }; |
| 53 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 54 | class VkDepthStencilObj : public vk_testing::Image |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 55 | { |
| 56 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 57 | VkDepthStencilObj(); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 58 | void Init(VkDeviceObj *device, int32_t width, int32_t height, VkFormat format); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 59 | bool Initialized(); |
Courtney Goeltzenleuchter | 5861a1b | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 60 | VkImageView* BindInfo(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 61 | |
| 62 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 63 | VkDeviceObj *m_device; |
| 64 | bool m_initialized; |
Courtney Goeltzenleuchter | 5861a1b | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 65 | vk_testing::ImageView m_imageView; |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 66 | VkFormat m_depth_stencil_fmt; |
Courtney Goeltzenleuchter | 5861a1b | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 67 | VkImageView m_attachmentBindInfo; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 68 | }; |
| 69 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 70 | class VkCommandBufferObj; |
| 71 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 72 | class VkRenderFramework : public VkTestFramework |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 73 | { |
| 74 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 75 | VkRenderFramework(); |
| 76 | ~VkRenderFramework(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 77 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 78 | VkDevice device() {return m_device->device();} |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 79 | VkPhysicalDevice gpu() {return objs[0];} |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 80 | VkRenderPass renderPass() {return m_renderPass;} |
| 81 | VkFramebuffer framebuffer() {return m_framebuffer;} |
Tony Barbour | 823e6ca | 2015-07-27 13:31:04 -0600 | [diff] [blame] | 82 | std::vector<vk_testing::ShaderModule*> m_shader_modules; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 83 | void InitViewport(float width, float height); |
| 84 | void InitViewport(); |
| 85 | void InitRenderTarget(); |
| 86 | void InitRenderTarget(uint32_t targets); |
Courtney Goeltzenleuchter | 5861a1b | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 87 | void InitRenderTarget(VkImageView *dsBinding); |
| 88 | void InitRenderTarget(uint32_t targets, VkImageView *dsBinding); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 89 | void InitFramework(); |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 90 | void InitFramework( |
| 91 | std::vector<const char *> instance_layer_names, |
| 92 | std::vector<const char *> device_layer_names, |
| 93 | std::vector<const char *> instance_extension_names, |
| 94 | std::vector<const char *> device_extension_names, |
| 95 | PFN_vkDbgMsgCallback=NULL, |
| 96 | void *userData=NULL); |
| 97 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 98 | void ShutdownFramework(); |
| 99 | void InitState(); |
| 100 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 101 | const VkRenderPassBeginInfo &renderPassBeginInfo() const { return m_renderPassBeginInfo; } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 102 | |
| 103 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 104 | VkApplicationInfo app_info; |
| 105 | VkInstance inst; |
| 106 | VkPhysicalDevice objs[16]; |
| 107 | uint32_t gpu_count; |
| 108 | VkDeviceObj *m_device; |
Cody Northrop | e62183e | 2015-07-09 18:08:05 -0600 | [diff] [blame] | 109 | VkCmdPool m_cmdPool; |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 110 | VkCommandBufferObj *m_cmdBuffer; |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 111 | VkRenderPass m_renderPass; |
| 112 | VkFramebuffer m_framebuffer; |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 113 | std::vector<VkViewport> m_viewports; |
| 114 | std::vector<VkRect2D> m_scissors; |
| 115 | float m_lineWidth; |
| 116 | float m_depthBias; |
| 117 | float m_depthBiasClamp; |
| 118 | float m_slopeScaledDepthBias; |
| 119 | float m_blendConst[4]; |
| 120 | float m_minDepthBounds; |
| 121 | float m_maxDepthBounds; |
| 122 | uint32_t m_stencilCompareMask; |
| 123 | uint32_t m_stencilWriteMask; |
| 124 | uint32_t m_stencilReference; |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 125 | std::vector<VkClearValue> m_renderPassClearValues; |
| 126 | VkRenderPassBeginInfo m_renderPassBeginInfo; |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 127 | vector<VkImageObj*> m_renderTargets; |
| 128 | float m_width, m_height; |
| 129 | VkFormat m_render_target_fmt; |
| 130 | VkFormat m_depth_stencil_fmt; |
Chris Forbes | f0796e1 | 2015-06-24 14:34:53 +1200 | [diff] [blame] | 131 | VkClearColorValue m_clear_color; |
Chris Forbes | e182fe0 | 2015-06-15 09:32:35 +1200 | [diff] [blame] | 132 | bool m_clear_via_load_op; |
Courtney Goeltzenleuchter | d6079ec | 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; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 136 | PFN_vkDbgCreateMsgCallback m_dbgCreateMsgCallback; |
Courtney Goeltzenleuchter | 7e46b62 | 2015-06-08 15:16:04 -0600 | [diff] [blame] | 137 | PFN_vkDbgDestroyMsgCallback m_dbgDestroyMsgCallback; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 138 | VkDbgMsgCallback m_globalMsgCallback; |
| 139 | VkDbgMsgCallback m_devMsgCallback; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 140 | |
| 141 | /* |
| 142 | * SetUp and TearDown are called by the Google Test framework |
| 143 | * to initialize a test framework based on this class. |
| 144 | */ |
| 145 | virtual void SetUp() { |
| 146 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
| 147 | this->app_info.pNext = NULL; |
| 148 | this->app_info.pAppName = "base"; |
| 149 | this->app_info.appVersion = 1; |
| 150 | this->app_info.pEngineName = "unittest"; |
| 151 | this->app_info.engineVersion = 1; |
| 152 | this->app_info.apiVersion = VK_API_VERSION; |
| 153 | |
| 154 | InitFramework(); |
| 155 | } |
| 156 | |
| 157 | virtual void TearDown() { |
| 158 | ShutdownFramework(); |
| 159 | } |
| 160 | }; |
| 161 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 162 | class VkDescriptorSetObj; |
| 163 | class VkIndexBufferObj; |
| 164 | class VkConstantBufferObj; |
| 165 | class VkPipelineObj; |
| 166 | class VkDescriptorSetObj; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 167 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 168 | class VkCommandBufferObj : public vk_testing::CmdBuffer |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 169 | { |
| 170 | public: |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 171 | VkCommandBufferObj(VkDeviceObj *device, VkCmdPool pool); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 172 | VkCmdBuffer GetBufferHandle(); |
| 173 | VkResult BeginCommandBuffer(); |
| 174 | VkResult BeginCommandBuffer(VkCmdBufferBeginInfo *pInfo); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 175 | VkResult EndCommandBuffer(); |
Courtney Goeltzenleuchter | ceebbb1 | 2015-07-12 13:07:46 -0600 | [diff] [blame] | 176 | void PipelineBarrier(VkPipelineStageFlags src_stages, VkPipelineStageFlags dest_stages, VkBool32 byRegion, uint32_t memBarrierCount, const void* const* ppMemBarriers); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 177 | void AddRenderTarget(VkImageObj *renderTarget); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 178 | void AddDepthStencil(); |
Chris Forbes | f0796e1 | 2015-06-24 14:34:53 +1200 | [diff] [blame] | 179 | void ClearAllBuffers(VkClearColorValue clear_color, float depth_clear_color, uint32_t stencil_clear_color, VkDepthStencilObj *depthStencilObj); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 180 | void PrepareAttachments(); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 181 | void BindPipeline(VkPipelineObj &pipeline); |
| 182 | void BindDescriptorSet(VkDescriptorSetObj &descriptorSet); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 183 | void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding); |
Cody Northrop | d2ad034 | 2015-08-05 11:15:02 -0600 | [diff] [blame] | 184 | void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 185 | void BeginRenderPass(const VkRenderPassBeginInfo &info); |
Chia-I Wu | 0b50a1c | 2015-06-26 15:34:39 +0800 | [diff] [blame] | 186 | void EndRenderPass(); |
Tony Barbour | c1eb1a5 | 2015-07-20 13:00:10 -0600 | [diff] [blame] | 187 | void FillBuffer(VkBuffer buffer, VkDeviceSize offset, VkDeviceSize fill_size, uint32_t data); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 188 | void Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount); |
| 189 | void DrawIndexed(uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount); |
| 190 | void QueueCommandBuffer(); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 191 | void QueueCommandBuffer(VkFence fence); |
Courtney Goeltzenleuchter | 078f817 | 2015-09-21 11:44:06 -0600 | [diff] [blame^] | 192 | void SetViewport(uint32_t viewportCount, const VkViewport* pViewports); |
| 193 | void SetScissor(uint32_t scissorCount, const VkRect2D* pScissors); |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 194 | void SetLineWidth(float lineWidth); |
| 195 | void SetDepthBias(float depthBias, float depthBiasClamp, float slopeScaledDepthBias); |
| 196 | void SetBlendConstants(const float blendConst[4]); |
| 197 | void SetDepthBounds(float minDepthBounds, float maxDepthBounds); |
| 198 | void SetStencilReadMask(VkStencilFaceFlags faceMask, uint32_t stencilCompareMask); |
| 199 | void SetStencilWriteMask(VkStencilFaceFlags faceMask, uint32_t stencilWriteMask); |
| 200 | void SetStencilReference(VkStencilFaceFlags faceMask, uint32_t stencilReference); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 201 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 202 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 203 | VkDeviceObj *m_device; |
| 204 | vector<VkImageObj*> m_renderTargets; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 205 | }; |
| 206 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 207 | class VkConstantBufferObj : public vk_testing::Buffer |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 208 | { |
| 209 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 210 | VkConstantBufferObj(VkDeviceObj *device); |
| 211 | VkConstantBufferObj(VkDeviceObj *device, int constantCount, int constantSize, const void* data); |
| 212 | ~VkConstantBufferObj(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 213 | void BufferMemoryBarrier( |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 214 | VkFlags outputMask = |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 215 | VK_MEMORY_OUTPUT_HOST_WRITE_BIT | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 216 | VK_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 217 | VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 218 | VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 219 | VK_MEMORY_OUTPUT_TRANSFER_BIT, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 220 | VkFlags inputMask = |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 221 | VK_MEMORY_INPUT_HOST_READ_BIT | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 222 | VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 223 | VK_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 224 | VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 225 | VK_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 226 | VK_MEMORY_INPUT_SHADER_READ_BIT | |
| 227 | VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 228 | VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 229 | VK_MEMORY_INPUT_TRANSFER_BIT); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 230 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 231 | void Bind(VkCmdBuffer cmdBuffer, VkDeviceSize offset, uint32_t binding); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 232 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 233 | VkDescriptorInfo m_descriptorInfo; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 234 | |
| 235 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 236 | VkDeviceObj *m_device; |
| 237 | vk_testing::BufferView m_bufferView; |
| 238 | int m_numVertices; |
| 239 | int m_stride; |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 240 | vk_testing::CmdPool *m_cmdPool; |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 241 | VkCommandBufferObj *m_commandBuffer; |
| 242 | vk_testing::Fence m_fence; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 243 | }; |
| 244 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 245 | class VkIndexBufferObj : public VkConstantBufferObj |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 246 | { |
| 247 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 248 | VkIndexBufferObj(VkDeviceObj *device); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 249 | void CreateAndInitBuffer(int numIndexes, VkIndexType dataFormat, const void* data); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 250 | void Bind(VkCmdBuffer cmdBuffer, VkDeviceSize offset); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 251 | VkIndexType GetIndexType(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 252 | |
| 253 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 254 | VkIndexType m_indexType; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 255 | }; |
| 256 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 257 | class VkImageObj : public vk_testing::Image |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 258 | { |
| 259 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 260 | VkImageObj(VkDeviceObj *dev); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 261 | bool IsCompatible(VkFlags usage, VkFlags features); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 262 | |
| 263 | public: |
| 264 | void init(uint32_t w, uint32_t h, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 265 | VkFormat fmt, VkFlags usage, |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 266 | VkImageTiling tiling=VK_IMAGE_TILING_LINEAR, |
| 267 | VkMemoryPropertyFlags reqs=0); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 268 | |
| 269 | // void clear( CommandBuffer*, uint32_t[4] ); |
| 270 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 271 | void layout( VkImageLayout layout ) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 272 | { |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 273 | m_descriptorInfo.imageLayout = layout; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 274 | } |
| 275 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 276 | VkDeviceMemory memory() const |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 277 | { |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 278 | return Image::memory().handle(); |
| 279 | } |
| 280 | |
| 281 | void *MapMemory() |
| 282 | { |
| 283 | return Image::memory().map(); |
| 284 | } |
| 285 | |
| 286 | void UnmapMemory() |
| 287 | { |
| 288 | Image::memory().unmap(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 289 | } |
| 290 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 291 | void ImageMemoryBarrier(VkCommandBufferObj *cmd, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 292 | VkImageAspect aspect, |
| 293 | VkFlags output_mask, |
| 294 | VkFlags input_mask, |
| 295 | VkImageLayout image_layout); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 296 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 297 | VkResult CopyImage(VkImageObj &src_image); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 298 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 299 | VkImage image() const |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 300 | { |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 301 | return handle(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 302 | } |
| 303 | |
Courtney Goeltzenleuchter | 5861a1b | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 304 | VkImageView targetView(VkFormat format) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 305 | { |
| 306 | if (!m_targetView.initialized()) |
| 307 | { |
Courtney Goeltzenleuchter | 5861a1b | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 308 | VkImageViewCreateInfo createView = {}; |
| 309 | createView.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 310 | createView.image = handle(); |
| 311 | createView.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 312 | createView.format = format; |
| 313 | createView.channels.r = VK_CHANNEL_SWIZZLE_R; |
| 314 | createView.channels.g = VK_CHANNEL_SWIZZLE_G; |
| 315 | createView.channels.b = VK_CHANNEL_SWIZZLE_B; |
| 316 | createView.channels.a = VK_CHANNEL_SWIZZLE_A; |
Cody Northrop | 4232dad | 2015-09-14 13:48:12 -0600 | [diff] [blame] | 317 | createView.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; |
Courtney Goeltzenleuchter | 5861a1b | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 318 | createView.flags = 0; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 319 | m_targetView.init(*m_device, createView); |
| 320 | } |
Chia-I Wu | 3158bf3 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 321 | return m_targetView.handle(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 322 | } |
| 323 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 324 | void SetLayout(VkCommandBufferObj *cmd_buf, VkImageAspect aspect, VkImageLayout image_layout); |
| 325 | void SetLayout(VkImageAspect aspect, VkImageLayout image_layout); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 326 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 327 | VkImageLayout layout() const |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 328 | { |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 329 | return m_descriptorInfo.imageLayout; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 330 | } |
| 331 | uint32_t width() const |
| 332 | { |
| 333 | return extent().width; |
| 334 | } |
| 335 | uint32_t height() const |
| 336 | { |
| 337 | return extent().height; |
| 338 | } |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 339 | VkDeviceObj* device() const |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 340 | { |
| 341 | return m_device; |
| 342 | } |
| 343 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 344 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 345 | VkDeviceObj *m_device; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 346 | |
Courtney Goeltzenleuchter | 5861a1b | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 347 | vk_testing::ImageView m_targetView; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 348 | VkDescriptorInfo m_descriptorInfo; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 349 | }; |
| 350 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 351 | class VkTextureObj : public VkImageObj |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 352 | { |
| 353 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 354 | VkTextureObj(VkDeviceObj *device, uint32_t *colors = NULL); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 355 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 356 | VkDescriptorInfo m_descriptorInfo; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 357 | |
| 358 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 359 | VkDeviceObj *m_device; |
| 360 | vk_testing::ImageView m_textureView; |
| 361 | VkDeviceSize m_rowPitch; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 362 | }; |
| 363 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 364 | class VkSamplerObj : public vk_testing::Sampler |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 365 | { |
| 366 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 367 | VkSamplerObj(VkDeviceObj *device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 368 | |
| 369 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 370 | VkDeviceObj *m_device; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 371 | |
| 372 | }; |
| 373 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 374 | class VkDescriptorSetObj : public vk_testing::DescriptorPool |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 375 | { |
| 376 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 377 | VkDescriptorSetObj(VkDeviceObj *device); |
| 378 | ~VkDescriptorSetObj(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 379 | |
| 380 | int AppendDummy(); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 381 | int AppendBuffer(VkDescriptorType type, VkConstantBufferObj &constantBuffer); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 382 | int AppendSamplerTexture(VkSamplerObj* sampler, VkTextureObj* texture); |
| 383 | void CreateVKDescriptorSet(VkCommandBufferObj *cmdBuffer); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 384 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 385 | VkDescriptorSet GetDescriptorSetHandle() const; |
Mark Lobodzinski | 0fadf5f | 2015-04-17 14:11:39 -0500 | [diff] [blame] | 386 | VkPipelineLayout GetPipelineLayout() const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 387 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 388 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 389 | VkDeviceObj *m_device; |
| 390 | vector<VkDescriptorTypeCount> m_type_counts; |
| 391 | int m_nextSlot; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 392 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 393 | vector<VkDescriptorInfo> m_imageSamplerDescriptors; |
| 394 | vector<VkWriteDescriptorSet> m_writes; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 395 | |
| 396 | vk_testing::DescriptorSetLayout m_layout; |
Mark Lobodzinski | 0fadf5f | 2015-04-17 14:11:39 -0500 | [diff] [blame] | 397 | vk_testing::PipelineLayout m_pipeline_layout; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 398 | vk_testing::DescriptorSet *m_set; |
| 399 | }; |
| 400 | |
| 401 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 402 | class VkShaderObj : public vk_testing::Shader |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 403 | { |
| 404 | public: |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 405 | VkShaderObj(VkDeviceObj *device, const char * shaderText, VkShaderStage stage, VkRenderFramework *framework); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 406 | VkPipelineShaderStageCreateInfo* GetStageCreateInfo(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 407 | |
| 408 | protected: |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 409 | VkPipelineShaderStageCreateInfo stage_info; |
| 410 | VkShaderStage m_stage; |
| 411 | VkDeviceObj *m_device; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 412 | |
| 413 | }; |
| 414 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 415 | class VkPipelineObj : public vk_testing::Pipeline |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 416 | { |
| 417 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 418 | VkPipelineObj(VkDeviceObj *device); |
| 419 | void AddShader(VkShaderObj* shaderObj); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 420 | void AddVertexInputAttribs(VkVertexInputAttributeDescription* vi_attrib, int count); |
| 421 | void AddVertexInputBindings(VkVertexInputBindingDescription* vi_binding, int count); |
Tony Barbour | dd6e32e | 2015-07-10 15:29:03 -0600 | [diff] [blame] | 422 | void AddColorAttachment(uint32_t binding, const VkPipelineColorBlendAttachmentState *att); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 423 | |
| 424 | void AddColorAttachment() |
| 425 | { |
Tony Barbour | dd6e32e | 2015-07-10 15:29:03 -0600 | [diff] [blame] | 426 | VkPipelineColorBlendAttachmentState att = {}; |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 427 | att.blendEnable = VK_FALSE; |
| 428 | att.channelWriteMask = 0xf; |
| 429 | AddColorAttachment(0, &att); |
| 430 | } |
| 431 | |
Tony Barbour | dd6e32e | 2015-07-10 15:29:03 -0600 | [diff] [blame] | 432 | void SetDepthStencil(VkPipelineDepthStencilStateCreateInfo *); |
Tony Barbour | 0ec8cd5 | 2015-08-06 09:27:11 -0600 | [diff] [blame] | 433 | void SetMSAA(VkPipelineMultisampleStateCreateInfo *ms_state); |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 434 | VkResult CreateVKPipeline(VkPipelineLayout layout, VkRenderPass render_pass); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 435 | |
| 436 | protected: |
Tony Barbour | dd6e32e | 2015-07-10 15:29:03 -0600 | [diff] [blame] | 437 | VkPipelineVertexInputStateCreateInfo m_vi_state; |
| 438 | VkPipelineInputAssemblyStateCreateInfo m_ia_state; |
| 439 | VkPipelineRasterStateCreateInfo m_rs_state; |
| 440 | VkPipelineColorBlendStateCreateInfo m_cb_state; |
| 441 | VkPipelineDepthStencilStateCreateInfo m_ds_state; |
| 442 | VkPipelineViewportStateCreateInfo m_vp_state; |
| 443 | VkPipelineMultisampleStateCreateInfo m_ms_state; |
| 444 | VkDeviceObj *m_device; |
| 445 | vector<VkShaderObj*> m_shaderObjs; |
Tony Barbour | dd6e32e | 2015-07-10 15:29:03 -0600 | [diff] [blame] | 446 | vector<int> m_vertexBufferBindings; |
| 447 | vector<VkPipelineColorBlendAttachmentState> m_colorAttachments; |
| 448 | int m_vertexBufferCount; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 449 | }; |
| 450 | |
| 451 | #endif // VKRENDERFRAMEWORK_H |