blob: 0c76db1c4fc8deabaed791ffd5275c749e42257e [file] [log] [blame]
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 *
Courtney Goeltzenleuchter8a17da52015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Michael Lentinee6c6dd52015-11-03 16:20:30 -08004 * Copyright (C) 2015 Google, Inc.
Courtney Goeltzenleuchter9cc421e2015-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 Goeltzenleuchter96cd7952015-10-30 11:14:30 -060024 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
25 *
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060026 */
27
28#ifndef VKRENDERFRAMEWORK_H
29#define VKRENDERFRAMEWORK_H
30
Michael Lentinee6c6dd52015-11-03 16:20:30 -080031#ifdef ANDROID
32#include "vktestframeworkandroid.h"
33class VkImageObj;
34#else
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060035#include "vktestframework.h"
Michael Lentinee6c6dd52015-11-03 16:20:30 -080036#endif
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -070037#include "vulkan/vk_ext_debug_report.h"
David Pinedoa31fe0b2015-11-24 09:00:24 -070038#include "vulkan/vk_lunarg_debug_marker.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060039
Michael Lentinee6c6dd52015-11-03 16:20:30 -080040#include <vector>
41
42using namespace std;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060043
Tony Barbour01999182015-04-09 12:58:51 -060044class VkDeviceObj : public vk_testing::Device
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060045{
46public:
Tony Barbour8205d902015-04-16 15:59:00 -060047 VkDeviceObj(uint32_t id, VkPhysicalDevice obj);
Courtney Goeltzenleuchter61414de2015-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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060051
Chia-I Wua2636292015-07-03 10:41:20 +080052 VkDevice device() { return handle(); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060053 void get_device_queue();
54
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -060055 uint32_t id;
56 VkPhysicalDeviceProperties props;
Cody Northropef72e2a2015-08-03 17:04:53 -060057 const VkQueueFamilyProperties *queue_props;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060058
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060059 VkQueue m_queue;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060060};
61
Tony Barbour01999182015-04-09 12:58:51 -060062class VkDepthStencilObj : public vk_testing::Image
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060063{
64public:
Tony Barbour01999182015-04-09 12:58:51 -060065 VkDepthStencilObj();
Chia-I Wuc278df82015-07-07 11:50:03 +080066 void Init(VkDeviceObj *device, int32_t width, int32_t height, VkFormat format);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060067 bool Initialized();
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -060068 VkImageView* BindInfo();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060069
70protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -060071 VkDeviceObj *m_device;
72 bool m_initialized;
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -060073 vk_testing::ImageView m_imageView;
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -060074 VkFormat m_depth_stencil_fmt;
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -060075 VkImageView m_attachmentBindInfo;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060076};
77
Tony Barbour1490c912015-07-28 10:17:20 -060078class VkCommandBufferObj;
79
Tony Barbour01999182015-04-09 12:58:51 -060080class VkRenderFramework : public VkTestFramework
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060081{
82public:
Tony Barbour01999182015-04-09 12:58:51 -060083 VkRenderFramework();
84 ~VkRenderFramework();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060085
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060086 VkDevice device() {return m_device->device();}
Tony Barbour8205d902015-04-16 15:59:00 -060087 VkPhysicalDevice gpu() {return objs[0];}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060088 VkRenderPass renderPass() {return m_renderPass;}
89 VkFramebuffer framebuffer() {return m_framebuffer;}
Courtney Goeltzenleuchter9cc421e2015-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 Goeltzenleuchter1856d6f2015-09-01 17:30:39 -060094 void InitRenderTarget(VkImageView *dsBinding);
95 void InitRenderTarget(uint32_t targets, VkImageView *dsBinding);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060096 void InitFramework();
Courtney Goeltzenleuchterf5c61952015-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 Goeltzenleuchteracb13592015-12-09 15:48:16 -0700102 PFN_vkDebugReportCallbackEXT=NULL,
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600103 void *userData=NULL);
104
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600105 void ShutdownFramework();
106 void InitState();
107
Chia-I Wuc278df82015-07-07 11:50:03 +0800108 const VkRenderPassBeginInfo &renderPassBeginInfo() const { return m_renderPassBeginInfo; }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600109
110protected:
Courtney Goeltzenleuchterec69b9c2015-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 Wu1f851912015-10-27 18:04:07 +0800116 VkCommandPool m_commandPool;
117 VkCommandBufferObj *m_commandBuffer;
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600118 VkRenderPass m_renderPass;
119 VkFramebuffer m_framebuffer;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600120 std::vector<VkViewport> m_viewports;
121 std::vector<VkRect2D> m_scissors;
122 float m_lineWidth;
Chia-I Wufa950c52015-10-26 19:08:09 +0800123 float m_depthBiasConstantFactor;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600124 float m_depthBiasClamp;
Chia-I Wufa950c52015-10-26 19:08:09 +0800125 float m_depthBiasSlopeFactor;
Chia-I Wu7e470702015-10-26 17:24:52 +0800126 float m_blendConstants[4];
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600127 float m_minDepthBounds;
128 float m_maxDepthBounds;
Chia-I Wuc51b1212015-10-27 19:25:11 +0800129 uint32_t m_compareMask;
130 uint32_t m_writeMask;
131 uint32_t m_reference;
Chia-I Wuc278df82015-07-07 11:50:03 +0800132 std::vector<VkClearValue> m_renderPassClearValues;
133 VkRenderPassBeginInfo m_renderPassBeginInfo;
Courtney Goeltzenleuchterec69b9c2015-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 Forbese3105972015-06-24 14:34:53 +1200138 VkClearColorValue m_clear_color;
Chris Forbes23e6db62015-06-15 09:32:35 +1200139 bool m_clear_via_load_op;
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600140 float m_depth_clear_color;
141 uint32_t m_stencil_clear_color;
142 VkDepthStencilObj *m_depthStencil;
Courtney Goeltzenleuchter895819d2015-12-15 09:25:15 -0700143 PFN_vkCreateDebugReportCallbackEXT m_CreateDebugReportCallback;
144 PFN_vkDestroyDebugReportCallbackEXT m_DestroyDebugReportCallback;
145 PFN_vkDebugReportMessageEXT m_DebugReportMessage;
146 VkDebugReportCallbackEXT m_globalMsgCallback;
147 VkDebugReportCallbackEXT m_devMsgCallback;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600148
149 /*
150 * SetUp and TearDown are called by the Google Test framework
151 * to initialize a test framework based on this class.
152 */
153 virtual void SetUp() {
154 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
155 this->app_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +0800156 this->app_info.pApplicationName = "base";
157 this->app_info.applicationVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600158 this->app_info.pEngineName = "unittest";
159 this->app_info.engineVersion = 1;
160 this->app_info.apiVersion = VK_API_VERSION;
161
162 InitFramework();
163 }
164
165 virtual void TearDown() {
166 ShutdownFramework();
167 }
168};
169
Tony Barbour01999182015-04-09 12:58:51 -0600170class VkDescriptorSetObj;
171class VkIndexBufferObj;
172class VkConstantBufferObj;
173class VkPipelineObj;
174class VkDescriptorSetObj;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600175
Chia-I Wu1f851912015-10-27 18:04:07 +0800176class VkCommandBufferObj : public vk_testing::CommandBuffer
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600177{
178public:
Chia-I Wu1f851912015-10-27 18:04:07 +0800179 VkCommandBufferObj(VkDeviceObj *device, VkCommandPool pool);
180 VkCommandBuffer GetBufferHandle();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600181 VkResult BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800182 VkResult BeginCommandBuffer(VkCommandBufferBeginInfo *pInfo);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600183 VkResult EndCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800184 void PipelineBarrier(VkPipelineStageFlags src_stages, VkPipelineStageFlags dest_stages, VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, const void* const* ppMemoryBarriers);
Tony Barbour01999182015-04-09 12:58:51 -0600185 void AddRenderTarget(VkImageObj *renderTarget);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600186 void AddDepthStencil();
Chris Forbese3105972015-06-24 14:34:53 +1200187 void ClearAllBuffers(VkClearColorValue clear_color, float depth_clear_color, uint32_t stencil_clear_color, VkDepthStencilObj *depthStencilObj);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600188 void PrepareAttachments();
Tony Barbour01999182015-04-09 12:58:51 -0600189 void BindPipeline(VkPipelineObj &pipeline);
190 void BindDescriptorSet(VkDescriptorSetObj &descriptorSet);
Tony Barbour8205d902015-04-16 15:59:00 -0600191 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding);
Cody Northrop1684adb2015-08-05 11:15:02 -0600192 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset);
Chia-I Wuc278df82015-07-07 11:50:03 +0800193 void BeginRenderPass(const VkRenderPassBeginInfo &info);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800194 void EndRenderPass();
Tony Barboure389b882015-07-20 13:00:10 -0600195 void FillBuffer(VkBuffer buffer, VkDeviceSize offset, VkDeviceSize fill_size, uint32_t data);
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600196 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance);
197 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600198 void QueueCommandBuffer();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600199 void QueueCommandBuffer(VkFence fence);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600200 void SetViewport(uint32_t viewportCount, const VkViewport* pViewports);
201 void SetScissor(uint32_t scissorCount, const VkRect2D* pScissors);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600202 void SetLineWidth(float lineWidth);
Chia-I Wufa950c52015-10-26 19:08:09 +0800203 void SetDepthBias(float depthBiasConstantFactor, float depthBiasClamp, float depthBiasSlopeFactor);
Chia-I Wu7e470702015-10-26 17:24:52 +0800204 void SetBlendConstants(const float blendConstants[4]);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600205 void SetDepthBounds(float minDepthBounds, float maxDepthBounds);
Chia-I Wuc51b1212015-10-27 19:25:11 +0800206 void SetStencilReadMask(VkStencilFaceFlags faceMask, uint32_t compareMask);
207 void SetStencilWriteMask(VkStencilFaceFlags faceMask, uint32_t writeMask);
208 void SetStencilReference(VkStencilFaceFlags faceMask, uint32_t reference);
Chia-I Wu1f851912015-10-27 18:04:07 +0800209 void UpdateBuffer(VkBuffer buffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const uint32_t *pData);
210 void CopyImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy* pRegions);
211 void ResolveImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageResolve* pRegions);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600212
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600213protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600214 VkDeviceObj *m_device;
215 vector<VkImageObj*> m_renderTargets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600216};
217
Tony Barbour01999182015-04-09 12:58:51 -0600218class VkConstantBufferObj : public vk_testing::Buffer
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600219{
220public:
Tony Barbour01999182015-04-09 12:58:51 -0600221 VkConstantBufferObj(VkDeviceObj *device);
222 VkConstantBufferObj(VkDeviceObj *device, int constantCount, int constantSize, const void* data);
223 ~VkConstantBufferObj();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600224 void BufferMemoryBarrier(
Chia-I Wu989de842015-10-27 19:54:37 +0800225 VkFlags srcAccessMask =
226 VK_ACCESS_HOST_WRITE_BIT |
227 VK_ACCESS_SHADER_WRITE_BIT |
228 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
229 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
230 VK_ACCESS_TRANSFER_WRITE_BIT,
231 VkFlags dstAccessMask =
232 VK_ACCESS_HOST_READ_BIT |
233 VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
234 VK_ACCESS_INDEX_READ_BIT |
235 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
236 VK_ACCESS_UNIFORM_READ_BIT |
237 VK_ACCESS_SHADER_READ_BIT |
238 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
239 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
240 VK_ACCESS_MEMORY_READ_BIT);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600241
Chia-I Wu1f851912015-10-27 18:04:07 +0800242 void Bind(VkCommandBuffer commandBuffer, VkDeviceSize offset, uint32_t binding);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600243
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -0600244 VkDescriptorBufferInfo m_descriptorBufferInfo;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600245
246protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600247 VkDeviceObj *m_device;
248 vk_testing::BufferView m_bufferView;
249 int m_numVertices;
250 int m_stride;
Chia-I Wu1f851912015-10-27 18:04:07 +0800251 vk_testing::CommandPool *m_commandPool;
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600252 VkCommandBufferObj *m_commandBuffer;
253 vk_testing::Fence m_fence;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600254};
255
Tony Barbour01999182015-04-09 12:58:51 -0600256class VkIndexBufferObj : public VkConstantBufferObj
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600257{
258public:
Tony Barbour01999182015-04-09 12:58:51 -0600259 VkIndexBufferObj(VkDeviceObj *device);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600260 void CreateAndInitBuffer(int numIndexes, VkIndexType dataFormat, const void* data);
Chia-I Wu1f851912015-10-27 18:04:07 +0800261 void Bind(VkCommandBuffer commandBuffer, VkDeviceSize offset);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600262 VkIndexType GetIndexType();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600263
264protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600265 VkIndexType m_indexType;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600266};
267
Tony Barbour01999182015-04-09 12:58:51 -0600268class VkImageObj : public vk_testing::Image
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600269{
270public:
Tony Barbour01999182015-04-09 12:58:51 -0600271 VkImageObj(VkDeviceObj *dev);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600272 bool IsCompatible(VkFlags usage, VkFlags features);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600273
274public:
275 void init(uint32_t w, uint32_t h,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600276 VkFormat fmt, VkFlags usage,
Tony Barbour94310562015-04-22 15:10:33 -0600277 VkImageTiling tiling=VK_IMAGE_TILING_LINEAR,
278 VkMemoryPropertyFlags reqs=0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600279
280 // void clear( CommandBuffer*, uint32_t[4] );
281
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600282 void layout( VkImageLayout layout )
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600283 {
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -0600284 m_descriptorImageInfo.imageLayout = layout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600285 }
286
Tony Barbour8205d902015-04-16 15:59:00 -0600287 VkDeviceMemory memory() const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600288 {
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800289 return Image::memory().handle();
290 }
291
292 void *MapMemory()
293 {
294 return Image::memory().map();
295 }
296
297 void UnmapMemory()
298 {
299 Image::memory().unmap();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600300 }
301
Tony Barbour01999182015-04-09 12:58:51 -0600302 void ImageMemoryBarrier(VkCommandBufferObj *cmd,
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -0600303 VkImageAspectFlags aspect,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600304 VkFlags output_mask,
305 VkFlags input_mask,
306 VkImageLayout image_layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600307
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600308 VkResult CopyImage(VkImageObj &src_image);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600309
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600310 VkImage image() const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600311 {
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800312 return handle();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600313 }
314
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -0600315 VkImageView targetView(VkFormat format)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600316 {
317 if (!m_targetView.initialized())
318 {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -0600319 VkImageViewCreateInfo createView = {};
320 createView.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
321 createView.image = handle();
322 createView.viewType = VK_IMAGE_VIEW_TYPE_2D;
323 createView.format = format;
Chia-I Wu4291d882015-10-27 19:00:15 +0800324 createView.components.r = VK_COMPONENT_SWIZZLE_R;
325 createView.components.g = VK_COMPONENT_SWIZZLE_G;
326 createView.components.b = VK_COMPONENT_SWIZZLE_B;
327 createView.components.a = VK_COMPONENT_SWIZZLE_A;
Cody Northrop95b8bb32015-09-14 13:48:12 -0600328 createView.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -0600329 createView.flags = 0;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600330 m_targetView.init(*m_device, createView);
331 }
Chia-I Wu76ab1ff2015-07-03 11:49:42 +0800332 return m_targetView.handle();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600333 }
334
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -0600335 void SetLayout(VkCommandBufferObj *cmd_buf, VkImageAspectFlagBits aspect, VkImageLayout image_layout);
336 void SetLayout(VkImageAspectFlagBits aspect, VkImageLayout image_layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600337
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600338 VkImageLayout layout() const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600339 {
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -0600340 return m_descriptorImageInfo.imageLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600341 }
342 uint32_t width() const
343 {
344 return extent().width;
345 }
346 uint32_t height() const
347 {
348 return extent().height;
349 }
Tony Barbour01999182015-04-09 12:58:51 -0600350 VkDeviceObj* device() const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600351 {
352 return m_device;
353 }
354
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600355protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600356 VkDeviceObj *m_device;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600357
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -0600358 vk_testing::ImageView m_targetView;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -0600359 VkDescriptorImageInfo m_descriptorImageInfo;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600360};
361
Tony Barbour01999182015-04-09 12:58:51 -0600362class VkTextureObj : public VkImageObj
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600363{
364public:
Tony Barbour01999182015-04-09 12:58:51 -0600365 VkTextureObj(VkDeviceObj *device, uint32_t *colors = NULL);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600366
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -0600367 VkDescriptorImageInfo m_imageInfo;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600368
369protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600370 VkDeviceObj *m_device;
371 vk_testing::ImageView m_textureView;
372 VkDeviceSize m_rowPitch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600373};
374
Tony Barbour01999182015-04-09 12:58:51 -0600375class VkSamplerObj : public vk_testing::Sampler
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600376{
377public:
Tony Barbour01999182015-04-09 12:58:51 -0600378 VkSamplerObj(VkDeviceObj *device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600379
380protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600381 VkDeviceObj *m_device;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600382
383};
384
Tony Barbour01999182015-04-09 12:58:51 -0600385class VkDescriptorSetObj : public vk_testing::DescriptorPool
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600386{
387public:
Tony Barbour01999182015-04-09 12:58:51 -0600388 VkDescriptorSetObj(VkDeviceObj *device);
389 ~VkDescriptorSetObj();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600390
391 int AppendDummy();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600392 int AppendBuffer(VkDescriptorType type, VkConstantBufferObj &constantBuffer);
Tony Barbour01999182015-04-09 12:58:51 -0600393 int AppendSamplerTexture(VkSamplerObj* sampler, VkTextureObj* texture);
Chia-I Wu1f851912015-10-27 18:04:07 +0800394 void CreateVKDescriptorSet(VkCommandBufferObj *commandBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600395
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600396 VkDescriptorSet GetDescriptorSetHandle() const;
Mark Lobodzinski556f7212015-04-17 14:11:39 -0500397 VkPipelineLayout GetPipelineLayout() const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600398
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600399protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600400 VkDeviceObj *m_device;
Chia-I Wuc51b1212015-10-27 19:25:11 +0800401 vector<VkDescriptorPoolSize> m_type_counts;
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600402 int m_nextSlot;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600403
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -0600404 vector<VkDescriptorImageInfo> m_imageSamplerDescriptors;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800405 vector<VkWriteDescriptorSet> m_writes;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600406
407 vk_testing::DescriptorSetLayout m_layout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -0500408 vk_testing::PipelineLayout m_pipeline_layout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600409 vk_testing::DescriptorSet *m_set;
410};
411
412
Chia-I Wu062ad152015-10-31 00:31:16 +0800413class VkShaderObj : public vk_testing::ShaderModule
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600414{
415public:
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600416 VkShaderObj(VkDeviceObj *device, const char * shaderText, VkShaderStageFlagBits stage, VkRenderFramework *framework);
Chia-I Wu062ad152015-10-31 00:31:16 +0800417 VkPipelineShaderStageCreateInfo GetStageCreateInfo() const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600418
419protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600420 VkPipelineShaderStageCreateInfo stage_info;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600421 VkShaderStageFlagBits m_stage;
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600422 VkDeviceObj *m_device;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600423
424};
425
Tony Barbour01999182015-04-09 12:58:51 -0600426class VkPipelineObj : public vk_testing::Pipeline
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600427{
428public:
Tony Barbour01999182015-04-09 12:58:51 -0600429 VkPipelineObj(VkDeviceObj *device);
430 void AddShader(VkShaderObj* shaderObj);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600431 void AddVertexInputAttribs(VkVertexInputAttributeDescription* vi_attrib, int count);
432 void AddVertexInputBindings(VkVertexInputBindingDescription* vi_binding, int count);
Tony Barboure307f582015-07-10 15:29:03 -0600433 void AddColorAttachment(uint32_t binding, const VkPipelineColorBlendAttachmentState *att);
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600434 void MakeDynamic(VkDynamicState state);
Chia-I Wuc278df82015-07-07 11:50:03 +0800435
436 void AddColorAttachment()
437 {
Tony Barboure307f582015-07-10 15:29:03 -0600438 VkPipelineColorBlendAttachmentState att = {};
Chia-I Wuc278df82015-07-07 11:50:03 +0800439 att.blendEnable = VK_FALSE;
Chia-I Wuc51b1212015-10-27 19:25:11 +0800440 att.colorWriteMask = 0xf;
Chia-I Wuc278df82015-07-07 11:50:03 +0800441 AddColorAttachment(0, &att);
442 }
443
Tony Barboure307f582015-07-10 15:29:03 -0600444 void SetDepthStencil(VkPipelineDepthStencilStateCreateInfo *);
Tony Barbour875e7462015-08-06 09:27:11 -0600445 void SetMSAA(VkPipelineMultisampleStateCreateInfo *ms_state);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600446 void SetViewport(vector<VkViewport> viewports);
447 void SetScissor(vector<VkRect2D> scissors);
Tony Barboured132432015-08-04 16:23:11 -0600448 VkResult CreateVKPipeline(VkPipelineLayout layout, VkRenderPass render_pass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600449
450protected:
Tony Barboure307f582015-07-10 15:29:03 -0600451 VkPipelineVertexInputStateCreateInfo m_vi_state;
452 VkPipelineInputAssemblyStateCreateInfo m_ia_state;
Chia-I Wu1f851912015-10-27 18:04:07 +0800453 VkPipelineRasterizationStateCreateInfo m_rs_state;
Tony Barboure307f582015-07-10 15:29:03 -0600454 VkPipelineColorBlendStateCreateInfo m_cb_state;
455 VkPipelineDepthStencilStateCreateInfo m_ds_state;
456 VkPipelineViewportStateCreateInfo m_vp_state;
457 VkPipelineMultisampleStateCreateInfo m_ms_state;
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600458 vector<VkDynamicState> m_dynamic_state_enables;
459 vector<VkViewport> m_viewports;
460 vector<VkRect2D> m_scissors;
Tony Barboure307f582015-07-10 15:29:03 -0600461 VkDeviceObj *m_device;
462 vector<VkShaderObj*> m_shaderObjs;
Tony Barboure307f582015-07-10 15:29:03 -0600463 vector<int> m_vertexBufferBindings;
464 vector<VkPipelineColorBlendAttachmentState> m_colorAttachments;
465 int m_vertexBufferCount;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600466};
467
468#endif // VKRENDERFRAMEWORK_H