blob: f5b3bf7321b519630cfbd71bb1a654d4959e2e2c [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
Michael Lentine83ab3412015-11-03 16:20:30 -08004 * Copyright (C) 2015 Google, Inc.
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005 *
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 *
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060024 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
25 *
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060026 */
27
28#ifndef VKRENDERFRAMEWORK_H
29#define VKRENDERFRAMEWORK_H
30
Michael Lentine83ab3412015-11-03 16:20:30 -080031#ifdef ANDROID
32#include "vktestframeworkandroid.h"
33class VkImageObj;
34#else
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060035#include "vktestframework.h"
Michael Lentine83ab3412015-11-03 16:20:30 -080036#endif
David Pinedoabd07722015-11-24 09:00:24 -070037#include "vulkan/vk_lunarg_debug_report.h"
38#include "vulkan/vk_lunarg_debug_marker.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060039
Michael Lentine83ab3412015-11-03 16:20:30 -080040#include <vector>
41
42using namespace std;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060043
Tony Barbour6918cd52015-04-09 12:58:51 -060044class VkDeviceObj : public vk_testing::Device
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060045{
46public:
Tony Barbourd1c35722015-04-16 15:59:00 -060047 VkDeviceObj(uint32_t id, VkPhysicalDevice obj);
Courtney Goeltzenleuchter5bac6092015-07-07 11:47:33 -060048 VkDeviceObj(uint32_t id, VkPhysicalDevice obj,
49 std::vector<const char *> &layers,
50 std::vector<const char *> &extension_names);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060051
Chia-I Wuf368b602015-07-03 10:41:20 +080052 VkDevice device() { return handle(); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060053 void get_device_queue();
54
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -060055 uint32_t id;
56 VkPhysicalDeviceProperties props;
Cody Northropd0802882015-08-03 17:04:53 -060057 const VkQueueFamilyProperties *queue_props;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060058
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060059 VkQueue m_queue;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060060};
61
Tony Barbour6918cd52015-04-09 12:58:51 -060062class VkDepthStencilObj : public vk_testing::Image
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060063{
64public:
Tony Barbour6918cd52015-04-09 12:58:51 -060065 VkDepthStencilObj();
Chia-I Wu08accc62015-07-07 11:50:03 +080066 void Init(VkDeviceObj *device, int32_t width, int32_t height, VkFormat format);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060067 bool Initialized();
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -060068 VkImageView* BindInfo();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060069
70protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -060071 VkDeviceObj *m_device;
72 bool m_initialized;
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -060073 vk_testing::ImageView m_imageView;
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -060074 VkFormat m_depth_stencil_fmt;
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -060075 VkImageView m_attachmentBindInfo;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060076};
77
Tony Barbourfe3351b2015-07-28 10:17:20 -060078class VkCommandBufferObj;
79
Tony Barbour6918cd52015-04-09 12:58:51 -060080class VkRenderFramework : public VkTestFramework
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060081{
82public:
Tony Barbour6918cd52015-04-09 12:58:51 -060083 VkRenderFramework();
84 ~VkRenderFramework();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060085
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060086 VkDevice device() {return m_device->device();}
Tony Barbourd1c35722015-04-16 15:59:00 -060087 VkPhysicalDevice gpu() {return objs[0];}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060088 VkRenderPass renderPass() {return m_renderPass;}
89 VkFramebuffer framebuffer() {return m_framebuffer;}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060090 void InitViewport(float width, float height);
91 void InitViewport();
92 void InitRenderTarget();
93 void InitRenderTarget(uint32_t targets);
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -060094 void InitRenderTarget(VkImageView *dsBinding);
95 void InitRenderTarget(uint32_t targets, VkImageView *dsBinding);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060096 void InitFramework();
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -060097 void InitFramework(
98 std::vector<const char *> instance_layer_names,
99 std::vector<const char *> device_layer_names,
100 std::vector<const char *> instance_extension_names,
101 std::vector<const char *> device_extension_names,
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700102 PFN_vkDebugReportCallbackLUNARG=NULL,
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600103 void *userData=NULL);
104
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600105 void ShutdownFramework();
106 void InitState();
107
Chia-I Wu08accc62015-07-07 11:50:03 +0800108 const VkRenderPassBeginInfo &renderPassBeginInfo() const { return m_renderPassBeginInfo; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600109
110protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600111 VkApplicationInfo app_info;
112 VkInstance inst;
113 VkPhysicalDevice objs[16];
114 uint32_t gpu_count;
115 VkDeviceObj *m_device;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800116 VkCommandPool m_commandPool;
117 VkCommandBufferObj *m_commandBuffer;
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600118 VkRenderPass m_renderPass;
119 VkFramebuffer m_framebuffer;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600120 std::vector<VkViewport> m_viewports;
121 std::vector<VkRect2D> m_scissors;
122 float m_lineWidth;
Chia-I Wud8c946a2015-10-26 19:08:09 +0800123 float m_depthBiasConstantFactor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600124 float m_depthBiasClamp;
Chia-I Wud8c946a2015-10-26 19:08:09 +0800125 float m_depthBiasSlopeFactor;
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800126 float m_blendConstants[4];
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600127 float m_minDepthBounds;
128 float m_maxDepthBounds;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800129 uint32_t m_compareMask;
130 uint32_t m_writeMask;
131 uint32_t m_reference;
Chia-I Wu08accc62015-07-07 11:50:03 +0800132 std::vector<VkClearValue> m_renderPassClearValues;
133 VkRenderPassBeginInfo m_renderPassBeginInfo;
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600134 vector<VkImageObj*> m_renderTargets;
135 float m_width, m_height;
136 VkFormat m_render_target_fmt;
137 VkFormat m_depth_stencil_fmt;
Chris Forbesf0796e12015-06-24 14:34:53 +1200138 VkClearColorValue m_clear_color;
Chris Forbese182fe02015-06-15 09:32:35 +1200139 bool m_clear_via_load_op;
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600140 float m_depth_clear_color;
141 uint32_t m_stencil_clear_color;
142 VkDepthStencilObj *m_depthStencil;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700143 PFN_vkCreateDebugReportCallbackLUNARG m_CreateDebugReportCallback;
144 PFN_vkDestroyDebugReportCallbackLUNARG m_DestroyDebugReportCallback;
Courtney Goeltzenleuchter107a0d22015-11-25 14:07:05 -0700145 VkDebugReportCallbackLUNARG m_globalMsgCallback;
146 VkDebugReportCallbackLUNARG m_devMsgCallback;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600147
148 /*
149 * SetUp and TearDown are called by the Google Test framework
150 * to initialize a test framework based on this class.
151 */
152 virtual void SetUp() {
153 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
154 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800155 this->app_info.pApplicationName = "base";
156 this->app_info.applicationVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600157 this->app_info.pEngineName = "unittest";
158 this->app_info.engineVersion = 1;
159 this->app_info.apiVersion = VK_API_VERSION;
160
161 InitFramework();
162 }
163
164 virtual void TearDown() {
165 ShutdownFramework();
166 }
167};
168
Tony Barbour6918cd52015-04-09 12:58:51 -0600169class VkDescriptorSetObj;
170class VkIndexBufferObj;
171class VkConstantBufferObj;
172class VkPipelineObj;
173class VkDescriptorSetObj;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600174
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800175class VkCommandBufferObj : public vk_testing::CommandBuffer
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600176{
177public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800178 VkCommandBufferObj(VkDeviceObj *device, VkCommandPool pool);
179 VkCommandBuffer GetBufferHandle();
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600180 VkResult BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800181 VkResult BeginCommandBuffer(VkCommandBufferBeginInfo *pInfo);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600182 VkResult EndCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800183 void PipelineBarrier(VkPipelineStageFlags src_stages, VkPipelineStageFlags dest_stages, VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, const void* const* ppMemoryBarriers);
Tony Barbour6918cd52015-04-09 12:58:51 -0600184 void AddRenderTarget(VkImageObj *renderTarget);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600185 void AddDepthStencil();
Chris Forbesf0796e12015-06-24 14:34:53 +1200186 void ClearAllBuffers(VkClearColorValue clear_color, float depth_clear_color, uint32_t stencil_clear_color, VkDepthStencilObj *depthStencilObj);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600187 void PrepareAttachments();
Tony Barbour6918cd52015-04-09 12:58:51 -0600188 void BindPipeline(VkPipelineObj &pipeline);
189 void BindDescriptorSet(VkDescriptorSetObj &descriptorSet);
Tony Barbourd1c35722015-04-16 15:59:00 -0600190 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding);
Cody Northropd2ad0342015-08-05 11:15:02 -0600191 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset);
Chia-I Wu08accc62015-07-07 11:50:03 +0800192 void BeginRenderPass(const VkRenderPassBeginInfo &info);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +0800193 void EndRenderPass();
Tony Barbourc1eb1a52015-07-20 13:00:10 -0600194 void FillBuffer(VkBuffer buffer, VkDeviceSize offset, VkDeviceSize fill_size, uint32_t data);
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600195 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance);
196 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600197 void QueueCommandBuffer();
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600198 void QueueCommandBuffer(VkFence fence);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600199 void SetViewport(uint32_t viewportCount, const VkViewport* pViewports);
200 void SetScissor(uint32_t scissorCount, const VkRect2D* pScissors);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600201 void SetLineWidth(float lineWidth);
Chia-I Wud8c946a2015-10-26 19:08:09 +0800202 void SetDepthBias(float depthBiasConstantFactor, float depthBiasClamp, float depthBiasSlopeFactor);
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800203 void SetBlendConstants(const float blendConstants[4]);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600204 void SetDepthBounds(float minDepthBounds, float maxDepthBounds);
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800205 void SetStencilReadMask(VkStencilFaceFlags faceMask, uint32_t compareMask);
206 void SetStencilWriteMask(VkStencilFaceFlags faceMask, uint32_t writeMask);
207 void SetStencilReference(VkStencilFaceFlags faceMask, uint32_t reference);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800208 void UpdateBuffer(VkBuffer buffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const uint32_t *pData);
209 void CopyImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy* pRegions);
210 void ResolveImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageResolve* pRegions);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600211
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600212protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600213 VkDeviceObj *m_device;
214 vector<VkImageObj*> m_renderTargets;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600215};
216
Tony Barbour6918cd52015-04-09 12:58:51 -0600217class VkConstantBufferObj : public vk_testing::Buffer
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600218{
219public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600220 VkConstantBufferObj(VkDeviceObj *device);
221 VkConstantBufferObj(VkDeviceObj *device, int constantCount, int constantSize, const void* data);
222 ~VkConstantBufferObj();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600223 void BufferMemoryBarrier(
Chia-I Wua4594202015-10-27 19:54:37 +0800224 VkFlags srcAccessMask =
225 VK_ACCESS_HOST_WRITE_BIT |
226 VK_ACCESS_SHADER_WRITE_BIT |
227 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
228 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
229 VK_ACCESS_TRANSFER_WRITE_BIT,
230 VkFlags dstAccessMask =
231 VK_ACCESS_HOST_READ_BIT |
232 VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
233 VK_ACCESS_INDEX_READ_BIT |
234 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
235 VK_ACCESS_UNIFORM_READ_BIT |
236 VK_ACCESS_SHADER_READ_BIT |
237 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
238 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
239 VK_ACCESS_MEMORY_READ_BIT);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600240
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800241 void Bind(VkCommandBuffer commandBuffer, VkDeviceSize offset, uint32_t binding);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600242
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600243 VkDescriptorBufferInfo m_descriptorBufferInfo;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600244
245protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600246 VkDeviceObj *m_device;
247 vk_testing::BufferView m_bufferView;
248 int m_numVertices;
249 int m_stride;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800250 vk_testing::CommandPool *m_commandPool;
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600251 VkCommandBufferObj *m_commandBuffer;
252 vk_testing::Fence m_fence;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600253};
254
Tony Barbour6918cd52015-04-09 12:58:51 -0600255class VkIndexBufferObj : public VkConstantBufferObj
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600256{
257public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600258 VkIndexBufferObj(VkDeviceObj *device);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600259 void CreateAndInitBuffer(int numIndexes, VkIndexType dataFormat, const void* data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800260 void Bind(VkCommandBuffer commandBuffer, VkDeviceSize offset);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600261 VkIndexType GetIndexType();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600262
263protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600264 VkIndexType m_indexType;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600265};
266
Tony Barbour6918cd52015-04-09 12:58:51 -0600267class VkImageObj : public vk_testing::Image
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600268{
269public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600270 VkImageObj(VkDeviceObj *dev);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600271 bool IsCompatible(VkFlags usage, VkFlags features);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600272
273public:
274 void init(uint32_t w, uint32_t h,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600275 VkFormat fmt, VkFlags usage,
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600276 VkImageTiling tiling=VK_IMAGE_TILING_LINEAR,
277 VkMemoryPropertyFlags reqs=0);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600278
279 // void clear( CommandBuffer*, uint32_t[4] );
280
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600281 void layout( VkImageLayout layout )
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600282 {
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600283 m_descriptorImageInfo.imageLayout = layout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600284 }
285
Tony Barbourd1c35722015-04-16 15:59:00 -0600286 VkDeviceMemory memory() const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600287 {
Chia-I Wu681d7a02015-07-03 13:44:34 +0800288 return Image::memory().handle();
289 }
290
291 void *MapMemory()
292 {
293 return Image::memory().map();
294 }
295
296 void UnmapMemory()
297 {
298 Image::memory().unmap();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600299 }
300
Tony Barbour6918cd52015-04-09 12:58:51 -0600301 void ImageMemoryBarrier(VkCommandBufferObj *cmd,
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600302 VkImageAspectFlags aspect,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600303 VkFlags output_mask,
304 VkFlags input_mask,
305 VkImageLayout image_layout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600306
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600307 VkResult CopyImage(VkImageObj &src_image);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600308
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600309 VkImage image() const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600310 {
Chia-I Wu681d7a02015-07-03 13:44:34 +0800311 return handle();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600312 }
313
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -0600314 VkImageView targetView(VkFormat format)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600315 {
316 if (!m_targetView.initialized())
317 {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -0600318 VkImageViewCreateInfo createView = {};
319 createView.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
320 createView.image = handle();
321 createView.viewType = VK_IMAGE_VIEW_TYPE_2D;
322 createView.format = format;
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800323 createView.components.r = VK_COMPONENT_SWIZZLE_R;
324 createView.components.g = VK_COMPONENT_SWIZZLE_G;
325 createView.components.b = VK_COMPONENT_SWIZZLE_B;
326 createView.components.a = VK_COMPONENT_SWIZZLE_A;
Cody Northrop4232dad2015-09-14 13:48:12 -0600327 createView.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -0600328 createView.flags = 0;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600329 m_targetView.init(*m_device, createView);
330 }
Chia-I Wu3158bf32015-07-03 11:49:42 +0800331 return m_targetView.handle();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600332 }
333
Courtney Goeltzenleuchter908e7672015-10-21 17:00:51 -0600334 void SetLayout(VkCommandBufferObj *cmd_buf, VkImageAspectFlagBits aspect, VkImageLayout image_layout);
335 void SetLayout(VkImageAspectFlagBits aspect, VkImageLayout image_layout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600336
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600337 VkImageLayout layout() const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600338 {
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600339 return m_descriptorImageInfo.imageLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600340 }
341 uint32_t width() const
342 {
343 return extent().width;
344 }
345 uint32_t height() const
346 {
347 return extent().height;
348 }
Tony Barbour6918cd52015-04-09 12:58:51 -0600349 VkDeviceObj* device() const
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600350 {
351 return m_device;
352 }
353
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600354protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600355 VkDeviceObj *m_device;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600356
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -0600357 vk_testing::ImageView m_targetView;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600358 VkDescriptorImageInfo m_descriptorImageInfo;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600359};
360
Tony Barbour6918cd52015-04-09 12:58:51 -0600361class VkTextureObj : public VkImageObj
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600362{
363public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600364 VkTextureObj(VkDeviceObj *device, uint32_t *colors = NULL);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600365
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600366 VkDescriptorImageInfo m_imageInfo;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600367
368protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600369 VkDeviceObj *m_device;
370 vk_testing::ImageView m_textureView;
371 VkDeviceSize m_rowPitch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600372};
373
Tony Barbour6918cd52015-04-09 12:58:51 -0600374class VkSamplerObj : public vk_testing::Sampler
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600375{
376public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600377 VkSamplerObj(VkDeviceObj *device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600378
379protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600380 VkDeviceObj *m_device;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600381
382};
383
Tony Barbour6918cd52015-04-09 12:58:51 -0600384class VkDescriptorSetObj : public vk_testing::DescriptorPool
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600385{
386public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600387 VkDescriptorSetObj(VkDeviceObj *device);
388 ~VkDescriptorSetObj();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600389
390 int AppendDummy();
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600391 int AppendBuffer(VkDescriptorType type, VkConstantBufferObj &constantBuffer);
Tony Barbour6918cd52015-04-09 12:58:51 -0600392 int AppendSamplerTexture(VkSamplerObj* sampler, VkTextureObj* texture);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800393 void CreateVKDescriptorSet(VkCommandBufferObj *commandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600394
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600395 VkDescriptorSet GetDescriptorSetHandle() const;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -0500396 VkPipelineLayout GetPipelineLayout() const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600397
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600398protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600399 VkDeviceObj *m_device;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800400 vector<VkDescriptorPoolSize> m_type_counts;
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600401 int m_nextSlot;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600402
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -0600403 vector<VkDescriptorImageInfo> m_imageSamplerDescriptors;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800404 vector<VkWriteDescriptorSet> m_writes;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600405
406 vk_testing::DescriptorSetLayout m_layout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -0500407 vk_testing::PipelineLayout m_pipeline_layout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600408 vk_testing::DescriptorSet *m_set;
409};
410
411
Chia-I Wu28e06912015-10-31 00:31:16 +0800412class VkShaderObj : public vk_testing::ShaderModule
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600413{
414public:
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600415 VkShaderObj(VkDeviceObj *device, const char * shaderText, VkShaderStageFlagBits stage, VkRenderFramework *framework);
Chia-I Wu28e06912015-10-31 00:31:16 +0800416 VkPipelineShaderStageCreateInfo GetStageCreateInfo() const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600417
418protected:
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600419 VkPipelineShaderStageCreateInfo stage_info;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600420 VkShaderStageFlagBits m_stage;
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600421 VkDeviceObj *m_device;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600422
423};
424
Tony Barbour6918cd52015-04-09 12:58:51 -0600425class VkPipelineObj : public vk_testing::Pipeline
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600426{
427public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600428 VkPipelineObj(VkDeviceObj *device);
429 void AddShader(VkShaderObj* shaderObj);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600430 void AddVertexInputAttribs(VkVertexInputAttributeDescription* vi_attrib, int count);
431 void AddVertexInputBindings(VkVertexInputBindingDescription* vi_binding, int count);
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600432 void AddColorAttachment(uint32_t binding, const VkPipelineColorBlendAttachmentState *att);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600433 void MakeDynamic(VkDynamicState state);
Chia-I Wu08accc62015-07-07 11:50:03 +0800434
435 void AddColorAttachment()
436 {
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600437 VkPipelineColorBlendAttachmentState att = {};
Chia-I Wu08accc62015-07-07 11:50:03 +0800438 att.blendEnable = VK_FALSE;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800439 att.colorWriteMask = 0xf;
Chia-I Wu08accc62015-07-07 11:50:03 +0800440 AddColorAttachment(0, &att);
441 }
442
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600443 void SetDepthStencil(VkPipelineDepthStencilStateCreateInfo *);
Tony Barbour0ec8cd52015-08-06 09:27:11 -0600444 void SetMSAA(VkPipelineMultisampleStateCreateInfo *ms_state);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600445 void SetViewport(vector<VkViewport> viewports);
446 void SetScissor(vector<VkRect2D> scissors);
Tony Barbour5781e8f2015-08-04 16:23:11 -0600447 VkResult CreateVKPipeline(VkPipelineLayout layout, VkRenderPass render_pass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600448
449protected:
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600450 VkPipelineVertexInputStateCreateInfo m_vi_state;
451 VkPipelineInputAssemblyStateCreateInfo m_ia_state;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800452 VkPipelineRasterizationStateCreateInfo m_rs_state;
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600453 VkPipelineColorBlendStateCreateInfo m_cb_state;
454 VkPipelineDepthStencilStateCreateInfo m_ds_state;
455 VkPipelineViewportStateCreateInfo m_vp_state;
456 VkPipelineMultisampleStateCreateInfo m_ms_state;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600457 vector<VkDynamicState> m_dynamic_state_enables;
458 vector<VkViewport> m_viewports;
459 vector<VkRect2D> m_scissors;
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600460 VkDeviceObj *m_device;
461 vector<VkShaderObj*> m_shaderObjs;
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600462 vector<int> m_vertexBufferBindings;
463 vector<VkPipelineColorBlendAttachmentState> m_colorAttachments;
464 int m_vertexBufferCount;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600465};
466
467#endif // VKRENDERFRAMEWORK_H