blob: 18e3a85f6b45fe7f40590cf7c43a251dc0382e04 [file] [log] [blame]
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001/*
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002 *
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Courtney Goeltzenleuchter <courtney@lunarg.com>
25 */
26
27#ifndef VKRENDERFRAMEWORK_H
28#define VKRENDERFRAMEWORK_H
29
30#include "vktestframework.h"
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060031#include "vk_debug_report_lunarg.h"
32#include "vk_debug_marker_lunarg.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060033
34
Tony Barbour6918cd52015-04-09 12:58:51 -060035class VkDeviceObj : public vk_testing::Device
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060036{
37public:
Tony Barbourd1c35722015-04-16 15:59:00 -060038 VkDeviceObj(uint32_t id, VkPhysicalDevice obj);
Courtney Goeltzenleuchter5bac6092015-07-07 11:47:33 -060039 VkDeviceObj(uint32_t id, VkPhysicalDevice obj,
40 std::vector<const char *> &layers,
41 std::vector<const char *> &extension_names);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060042
Chia-I Wuf368b602015-07-03 10:41:20 +080043 VkDevice device() { return handle(); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060044 void get_device_queue();
45
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -060046 uint32_t id;
47 VkPhysicalDeviceProperties props;
Cody Northropd0802882015-08-03 17:04:53 -060048 const VkQueueFamilyProperties *queue_props;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060049
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060050 VkQueue m_queue;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060051};
52
Tony Barbour6918cd52015-04-09 12:58:51 -060053class VkDepthStencilObj : public vk_testing::Image
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060054{
55public:
Tony Barbour6918cd52015-04-09 12:58:51 -060056 VkDepthStencilObj();
Chia-I Wu08accc62015-07-07 11:50:03 +080057 void Init(VkDeviceObj *device, int32_t width, int32_t height, VkFormat format);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060058 bool Initialized();
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -060059 VkImageView* BindInfo();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060060
61protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -060062 VkDeviceObj *m_device;
63 bool m_initialized;
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -060064 vk_testing::ImageView m_imageView;
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -060065 VkFormat m_depth_stencil_fmt;
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -060066 VkImageView m_attachmentBindInfo;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060067};
68
Tony Barbourfe3351b2015-07-28 10:17:20 -060069class VkCommandBufferObj;
70
Tony Barbour6918cd52015-04-09 12:58:51 -060071class VkRenderFramework : public VkTestFramework
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060072{
73public:
Tony Barbour6918cd52015-04-09 12:58:51 -060074 VkRenderFramework();
75 ~VkRenderFramework();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060076
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060077 VkDevice device() {return m_device->device();}
Tony Barbourd1c35722015-04-16 15:59:00 -060078 VkPhysicalDevice gpu() {return objs[0];}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060079 VkRenderPass renderPass() {return m_renderPass;}
80 VkFramebuffer framebuffer() {return m_framebuffer;}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060081 void InitViewport(float width, float height);
82 void InitViewport();
83 void InitRenderTarget();
84 void InitRenderTarget(uint32_t targets);
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -060085 void InitRenderTarget(VkImageView *dsBinding);
86 void InitRenderTarget(uint32_t targets, VkImageView *dsBinding);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060087 void InitFramework();
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -060088 void InitFramework(
89 std::vector<const char *> instance_layer_names,
90 std::vector<const char *> device_layer_names,
91 std::vector<const char *> instance_extension_names,
92 std::vector<const char *> device_extension_names,
93 PFN_vkDbgMsgCallback=NULL,
94 void *userData=NULL);
95
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060096 void ShutdownFramework();
97 void InitState();
98
Chia-I Wu08accc62015-07-07 11:50:03 +080099 const VkRenderPassBeginInfo &renderPassBeginInfo() const { return m_renderPassBeginInfo; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600100
101protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600102 VkApplicationInfo app_info;
103 VkInstance inst;
104 VkPhysicalDevice objs[16];
105 uint32_t gpu_count;
106 VkDeviceObj *m_device;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800107 VkCommandPool m_commandPool;
108 VkCommandBufferObj *m_commandBuffer;
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600109 VkRenderPass m_renderPass;
110 VkFramebuffer m_framebuffer;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600111 std::vector<VkViewport> m_viewports;
112 std::vector<VkRect2D> m_scissors;
113 float m_lineWidth;
Chia-I Wud8c946a2015-10-26 19:08:09 +0800114 float m_depthBiasConstantFactor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600115 float m_depthBiasClamp;
Chia-I Wud8c946a2015-10-26 19:08:09 +0800116 float m_depthBiasSlopeFactor;
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800117 float m_blendConstants[4];
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600118 float m_minDepthBounds;
119 float m_maxDepthBounds;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800120 uint32_t m_compareMask;
121 uint32_t m_writeMask;
122 uint32_t m_reference;
Chia-I Wu08accc62015-07-07 11:50:03 +0800123 std::vector<VkClearValue> m_renderPassClearValues;
124 VkRenderPassBeginInfo m_renderPassBeginInfo;
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600125 vector<VkImageObj*> m_renderTargets;
126 float m_width, m_height;
127 VkFormat m_render_target_fmt;
128 VkFormat m_depth_stencil_fmt;
Chris Forbesf0796e12015-06-24 14:34:53 +1200129 VkClearColorValue m_clear_color;
Chris Forbese182fe02015-06-15 09:32:35 +1200130 bool m_clear_via_load_op;
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600131 float m_depth_clear_color;
132 uint32_t m_stencil_clear_color;
133 VkDepthStencilObj *m_depthStencil;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600134 PFN_vkDbgCreateMsgCallback m_dbgCreateMsgCallback;
Courtney Goeltzenleuchter7e46b622015-06-08 15:16:04 -0600135 PFN_vkDbgDestroyMsgCallback m_dbgDestroyMsgCallback;
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600136 VkDbgMsgCallback m_globalMsgCallback;
137 VkDbgMsgCallback m_devMsgCallback;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600138
139 /*
140 * SetUp and TearDown are called by the Google Test framework
141 * to initialize a test framework based on this class.
142 */
143 virtual void SetUp() {
144 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
145 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800146 this->app_info.pApplicationName = "base";
147 this->app_info.applicationVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600148 this->app_info.pEngineName = "unittest";
149 this->app_info.engineVersion = 1;
150 this->app_info.apiVersion = VK_API_VERSION;
151
152 InitFramework();
153 }
154
155 virtual void TearDown() {
156 ShutdownFramework();
157 }
158};
159
Tony Barbour6918cd52015-04-09 12:58:51 -0600160class VkDescriptorSetObj;
161class VkIndexBufferObj;
162class VkConstantBufferObj;
163class VkPipelineObj;
164class VkDescriptorSetObj;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600165
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800166class VkCommandBufferObj : public vk_testing::CommandBuffer
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600167{
168public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800169 VkCommandBufferObj(VkDeviceObj *device, VkCommandPool pool);
170 VkCommandBuffer GetBufferHandle();
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600171 VkResult BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800172 VkResult BeginCommandBuffer(VkCommandBufferBeginInfo *pInfo);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600173 VkResult EndCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800174 void PipelineBarrier(VkPipelineStageFlags src_stages, VkPipelineStageFlags dest_stages, VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, const void* const* ppMemoryBarriers);
Tony Barbour6918cd52015-04-09 12:58:51 -0600175 void AddRenderTarget(VkImageObj *renderTarget);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600176 void AddDepthStencil();
Chris Forbesf0796e12015-06-24 14:34:53 +1200177 void ClearAllBuffers(VkClearColorValue clear_color, float depth_clear_color, uint32_t stencil_clear_color, VkDepthStencilObj *depthStencilObj);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600178 void PrepareAttachments();
Tony Barbour6918cd52015-04-09 12:58:51 -0600179 void BindPipeline(VkPipelineObj &pipeline);
180 void BindDescriptorSet(VkDescriptorSetObj &descriptorSet);
Tony Barbourd1c35722015-04-16 15:59:00 -0600181 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding);
Cody Northropd2ad0342015-08-05 11:15:02 -0600182 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset);
Chia-I Wu08accc62015-07-07 11:50:03 +0800183 void BeginRenderPass(const VkRenderPassBeginInfo &info);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +0800184 void EndRenderPass();
Tony Barbourc1eb1a52015-07-20 13:00:10 -0600185 void FillBuffer(VkBuffer buffer, VkDeviceSize offset, VkDeviceSize fill_size, uint32_t data);
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600186 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance);
187 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600188 void QueueCommandBuffer();
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600189 void QueueCommandBuffer(VkFence fence);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600190 void SetViewport(uint32_t viewportCount, const VkViewport* pViewports);
191 void SetScissor(uint32_t scissorCount, const VkRect2D* pScissors);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600192 void SetLineWidth(float lineWidth);
Chia-I Wud8c946a2015-10-26 19:08:09 +0800193 void SetDepthBias(float depthBiasConstantFactor, float depthBiasClamp, float depthBiasSlopeFactor);
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800194 void SetBlendConstants(const float blendConstants[4]);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600195 void SetDepthBounds(float minDepthBounds, float maxDepthBounds);
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800196 void SetStencilReadMask(VkStencilFaceFlags faceMask, uint32_t compareMask);
197 void SetStencilWriteMask(VkStencilFaceFlags faceMask, uint32_t writeMask);
198 void SetStencilReference(VkStencilFaceFlags faceMask, uint32_t reference);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800199 void UpdateBuffer(VkBuffer buffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const uint32_t *pData);
200 void CopyImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy* pRegions);
201 void ResolveImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageResolve* pRegions);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600202
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600203protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600204 VkDeviceObj *m_device;
205 vector<VkImageObj*> m_renderTargets;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600206};
207
Tony Barbour6918cd52015-04-09 12:58:51 -0600208class VkConstantBufferObj : public vk_testing::Buffer
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600209{
210public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600211 VkConstantBufferObj(VkDeviceObj *device);
212 VkConstantBufferObj(VkDeviceObj *device, int constantCount, int constantSize, const void* data);
213 ~VkConstantBufferObj();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600214 void BufferMemoryBarrier(
Chia-I Wua4594202015-10-27 19:54:37 +0800215 VkFlags srcAccessMask =
216 VK_ACCESS_HOST_WRITE_BIT |
217 VK_ACCESS_SHADER_WRITE_BIT |
218 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
219 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
220 VK_ACCESS_TRANSFER_WRITE_BIT,
221 VkFlags dstAccessMask =
222 VK_ACCESS_HOST_READ_BIT |
223 VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
224 VK_ACCESS_INDEX_READ_BIT |
225 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
226 VK_ACCESS_UNIFORM_READ_BIT |
227 VK_ACCESS_SHADER_READ_BIT |
228 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
229 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
230 VK_ACCESS_MEMORY_READ_BIT);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600231
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800232 void Bind(VkCommandBuffer commandBuffer, VkDeviceSize offset, uint32_t binding);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600233
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600234 VkDescriptorBufferInfo m_descriptorBufferInfo;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600235
236protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600237 VkDeviceObj *m_device;
238 vk_testing::BufferView m_bufferView;
239 int m_numVertices;
240 int m_stride;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800241 vk_testing::CommandPool *m_commandPool;
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600242 VkCommandBufferObj *m_commandBuffer;
243 vk_testing::Fence m_fence;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600244};
245
Tony Barbour6918cd52015-04-09 12:58:51 -0600246class VkIndexBufferObj : public VkConstantBufferObj
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600247{
248public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600249 VkIndexBufferObj(VkDeviceObj *device);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600250 void CreateAndInitBuffer(int numIndexes, VkIndexType dataFormat, const void* data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800251 void Bind(VkCommandBuffer commandBuffer, VkDeviceSize offset);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600252 VkIndexType GetIndexType();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600253
254protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600255 VkIndexType m_indexType;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600256};
257
Tony Barbour6918cd52015-04-09 12:58:51 -0600258class VkImageObj : public vk_testing::Image
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600259{
260public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600261 VkImageObj(VkDeviceObj *dev);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600262 bool IsCompatible(VkFlags usage, VkFlags features);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600263
264public:
265 void init(uint32_t w, uint32_t h,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600266 VkFormat fmt, VkFlags usage,
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600267 VkImageTiling tiling=VK_IMAGE_TILING_LINEAR,
268 VkMemoryPropertyFlags reqs=0);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600269
270 // void clear( CommandBuffer*, uint32_t[4] );
271
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600272 void layout( VkImageLayout layout )
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600273 {
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600274 m_descriptorImageInfo.imageLayout = layout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600275 }
276
Tony Barbourd1c35722015-04-16 15:59:00 -0600277 VkDeviceMemory memory() const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600278 {
Chia-I Wu681d7a02015-07-03 13:44:34 +0800279 return Image::memory().handle();
280 }
281
282 void *MapMemory()
283 {
284 return Image::memory().map();
285 }
286
287 void UnmapMemory()
288 {
289 Image::memory().unmap();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600290 }
291
Tony Barbour6918cd52015-04-09 12:58:51 -0600292 void ImageMemoryBarrier(VkCommandBufferObj *cmd,
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600293 VkImageAspectFlags aspect,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600294 VkFlags output_mask,
295 VkFlags input_mask,
296 VkImageLayout image_layout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600297
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600298 VkResult CopyImage(VkImageObj &src_image);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600299
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600300 VkImage image() const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600301 {
Chia-I Wu681d7a02015-07-03 13:44:34 +0800302 return handle();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600303 }
304
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -0600305 VkImageView targetView(VkFormat format)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600306 {
307 if (!m_targetView.initialized())
308 {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -0600309 VkImageViewCreateInfo createView = {};
310 createView.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
311 createView.image = handle();
312 createView.viewType = VK_IMAGE_VIEW_TYPE_2D;
313 createView.format = format;
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800314 createView.components.r = VK_COMPONENT_SWIZZLE_R;
315 createView.components.g = VK_COMPONENT_SWIZZLE_G;
316 createView.components.b = VK_COMPONENT_SWIZZLE_B;
317 createView.components.a = VK_COMPONENT_SWIZZLE_A;
Cody Northrop4232dad2015-09-14 13:48:12 -0600318 createView.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -0600319 createView.flags = 0;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600320 m_targetView.init(*m_device, createView);
321 }
Chia-I Wu3158bf32015-07-03 11:49:42 +0800322 return m_targetView.handle();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600323 }
324
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600325 void SetLayout(VkCommandBufferObj *cmd_buf, VkImageAspectFlagBits aspect, VkImageLayout image_layout);
326 void SetLayout(VkImageAspectFlagBits aspect, VkImageLayout image_layout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600327
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600328 VkImageLayout layout() const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600329 {
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600330 return m_descriptorImageInfo.imageLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600331 }
332 uint32_t width() const
333 {
334 return extent().width;
335 }
336 uint32_t height() const
337 {
338 return extent().height;
339 }
Tony Barbour6918cd52015-04-09 12:58:51 -0600340 VkDeviceObj* device() const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600341 {
342 return m_device;
343 }
344
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600345protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600346 VkDeviceObj *m_device;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600347
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -0600348 vk_testing::ImageView m_targetView;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600349 VkDescriptorImageInfo m_descriptorImageInfo;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600350};
351
Tony Barbour6918cd52015-04-09 12:58:51 -0600352class VkTextureObj : public VkImageObj
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600353{
354public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600355 VkTextureObj(VkDeviceObj *device, uint32_t *colors = NULL);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600356
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600357 VkDescriptorImageInfo m_imageInfo;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600358
359protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600360 VkDeviceObj *m_device;
361 vk_testing::ImageView m_textureView;
362 VkDeviceSize m_rowPitch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600363};
364
Tony Barbour6918cd52015-04-09 12:58:51 -0600365class VkSamplerObj : public vk_testing::Sampler
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600366{
367public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600368 VkSamplerObj(VkDeviceObj *device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600369
370protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600371 VkDeviceObj *m_device;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600372
373};
374
Tony Barbour6918cd52015-04-09 12:58:51 -0600375class VkDescriptorSetObj : public vk_testing::DescriptorPool
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600376{
377public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600378 VkDescriptorSetObj(VkDeviceObj *device);
379 ~VkDescriptorSetObj();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600380
381 int AppendDummy();
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600382 int AppendBuffer(VkDescriptorType type, VkConstantBufferObj &constantBuffer);
Tony Barbour6918cd52015-04-09 12:58:51 -0600383 int AppendSamplerTexture(VkSamplerObj* sampler, VkTextureObj* texture);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800384 void CreateVKDescriptorSet(VkCommandBufferObj *commandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600385
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600386 VkDescriptorSet GetDescriptorSetHandle() const;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -0500387 VkPipelineLayout GetPipelineLayout() const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600388
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600389protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600390 VkDeviceObj *m_device;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800391 vector<VkDescriptorPoolSize> m_type_counts;
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600392 int m_nextSlot;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600393
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600394 vector<VkDescriptorImageInfo> m_imageSamplerDescriptors;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800395 vector<VkWriteDescriptorSet> m_writes;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600396
397 vk_testing::DescriptorSetLayout m_layout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -0500398 vk_testing::PipelineLayout m_pipeline_layout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600399 vk_testing::DescriptorSet *m_set;
400};
401
402
Chia-I Wu28e06912015-10-31 00:31:16 +0800403class VkShaderObj : public vk_testing::ShaderModule
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600404{
405public:
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600406 VkShaderObj(VkDeviceObj *device, const char * shaderText, VkShaderStageFlagBits stage, VkRenderFramework *framework);
Chia-I Wu28e06912015-10-31 00:31:16 +0800407 VkPipelineShaderStageCreateInfo GetStageCreateInfo() const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600408
409protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600410 VkPipelineShaderStageCreateInfo stage_info;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600411 VkShaderStageFlagBits m_stage;
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600412 VkDeviceObj *m_device;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600413
414};
415
Tony Barbour6918cd52015-04-09 12:58:51 -0600416class VkPipelineObj : public vk_testing::Pipeline
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600417{
418public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600419 VkPipelineObj(VkDeviceObj *device);
420 void AddShader(VkShaderObj* shaderObj);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600421 void AddVertexInputAttribs(VkVertexInputAttributeDescription* vi_attrib, int count);
422 void AddVertexInputBindings(VkVertexInputBindingDescription* vi_binding, int count);
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600423 void AddColorAttachment(uint32_t binding, const VkPipelineColorBlendAttachmentState *att);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600424 void MakeDynamic(VkDynamicState state);
Chia-I Wu08accc62015-07-07 11:50:03 +0800425
426 void AddColorAttachment()
427 {
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600428 VkPipelineColorBlendAttachmentState att = {};
Chia-I Wu08accc62015-07-07 11:50:03 +0800429 att.blendEnable = VK_FALSE;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800430 att.colorWriteMask = 0xf;
Chia-I Wu08accc62015-07-07 11:50:03 +0800431 AddColorAttachment(0, &att);
432 }
433
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600434 void SetDepthStencil(VkPipelineDepthStencilStateCreateInfo *);
Tony Barbour0ec8cd52015-08-06 09:27:11 -0600435 void SetMSAA(VkPipelineMultisampleStateCreateInfo *ms_state);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600436 void SetViewport(vector<VkViewport> viewports);
437 void SetScissor(vector<VkRect2D> scissors);
Tony Barbour5781e8f2015-08-04 16:23:11 -0600438 VkResult CreateVKPipeline(VkPipelineLayout layout, VkRenderPass render_pass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600439
440protected:
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600441 VkPipelineVertexInputStateCreateInfo m_vi_state;
442 VkPipelineInputAssemblyStateCreateInfo m_ia_state;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800443 VkPipelineRasterizationStateCreateInfo m_rs_state;
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600444 VkPipelineColorBlendStateCreateInfo m_cb_state;
445 VkPipelineDepthStencilStateCreateInfo m_ds_state;
446 VkPipelineViewportStateCreateInfo m_vp_state;
447 VkPipelineMultisampleStateCreateInfo m_ms_state;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600448 vector<VkDynamicState> m_dynamic_state_enables;
449 vector<VkViewport> m_viewports;
450 vector<VkRect2D> m_scissors;
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600451 VkDeviceObj *m_device;
452 vector<VkShaderObj*> m_shaderObjs;
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600453 vector<int> m_vertexBufferBindings;
454 vector<VkPipelineColorBlendAttachmentState> m_colorAttachments;
455 int m_vertexBufferCount;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600456};
457
458#endif // VKRENDERFRAMEWORK_H