blob: 18c2b3295cbefe0d47655ffc292f37b901824ede [file] [log] [blame]
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001/*
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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060032#include "vk_debug_report_lunarg.h"
33#include "vk_debug_marker_lunarg.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060034
35
Tony Barbour01999182015-04-09 12:58:51 -060036class VkDeviceObj : public vk_testing::Device
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060037{
38public:
Tony Barbour8205d902015-04-16 15:59:00 -060039 VkDeviceObj(uint32_t id, VkPhysicalDevice obj);
Courtney Goeltzenleuchter61414de2015-07-07 11:47:33 -060040 VkDeviceObj(uint32_t id, VkPhysicalDevice obj,
41 std::vector<const char *> &layers,
42 std::vector<const char *> &extension_names);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060043
Chia-I Wua2636292015-07-03 10:41:20 +080044 VkDevice device() { return handle(); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060045 void get_device_queue();
46
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -060047 uint32_t id;
48 VkPhysicalDeviceProperties props;
Cody Northropef72e2a2015-08-03 17:04:53 -060049 const VkQueueFamilyProperties *queue_props;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060050
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060051 VkQueue m_queue;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060052};
53
Tony Barbour01999182015-04-09 12:58:51 -060054class VkDepthStencilObj : public vk_testing::Image
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060055{
56public:
Tony Barbour01999182015-04-09 12:58:51 -060057 VkDepthStencilObj();
Chia-I Wuc278df82015-07-07 11:50:03 +080058 void Init(VkDeviceObj *device, int32_t width, int32_t height, VkFormat format);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060059 bool Initialized();
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -060060 VkImageView* BindInfo();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060061
62protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -060063 VkDeviceObj *m_device;
64 bool m_initialized;
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -060065 vk_testing::ImageView m_imageView;
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -060066 VkFormat m_depth_stencil_fmt;
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -060067 VkImageView m_attachmentBindInfo;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060068};
69
Tony Barbour1490c912015-07-28 10:17:20 -060070class VkCommandBufferObj;
71
Tony Barbour01999182015-04-09 12:58:51 -060072class VkRenderFramework : public VkTestFramework
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060073{
74public:
Tony Barbour01999182015-04-09 12:58:51 -060075 VkRenderFramework();
76 ~VkRenderFramework();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060077
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060078 VkDevice device() {return m_device->device();}
Tony Barbour8205d902015-04-16 15:59:00 -060079 VkPhysicalDevice gpu() {return objs[0];}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060080 VkRenderPass renderPass() {return m_renderPass;}
81 VkFramebuffer framebuffer() {return m_framebuffer;}
Tony Barboura024aa02015-07-27 13:31:04 -060082 std::vector<vk_testing::ShaderModule*> m_shader_modules;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060083 void InitViewport(float width, float height);
84 void InitViewport();
85 void InitRenderTarget();
86 void InitRenderTarget(uint32_t targets);
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -060087 void InitRenderTarget(VkImageView *dsBinding);
88 void InitRenderTarget(uint32_t targets, VkImageView *dsBinding);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060089 void InitFramework();
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -060090 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060098 void ShutdownFramework();
99 void InitState();
100
Chia-I Wuc278df82015-07-07 11:50:03 +0800101 const VkRenderPassBeginInfo &renderPassBeginInfo() const { return m_renderPassBeginInfo; }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600102
103protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600104 VkApplicationInfo app_info;
105 VkInstance inst;
106 VkPhysicalDevice objs[16];
107 uint32_t gpu_count;
108 VkDeviceObj *m_device;
Cody Northropf02f9f82015-07-09 18:08:05 -0600109 VkCmdPool m_cmdPool;
Tony Barbour1490c912015-07-28 10:17:20 -0600110 VkCommandBufferObj *m_cmdBuffer;
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600111 VkRenderPass m_renderPass;
112 VkFramebuffer m_framebuffer;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600113 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 Wuc278df82015-07-07 11:50:03 +0800125 std::vector<VkClearValue> m_renderPassClearValues;
126 VkRenderPassBeginInfo m_renderPassBeginInfo;
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600127 vector<VkImageObj*> m_renderTargets;
128 float m_width, m_height;
129 VkFormat m_render_target_fmt;
130 VkFormat m_depth_stencil_fmt;
Chris Forbese3105972015-06-24 14:34:53 +1200131 VkClearColorValue m_clear_color;
Chris Forbes23e6db62015-06-15 09:32:35 +1200132 bool m_clear_via_load_op;
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600133 float m_depth_clear_color;
134 uint32_t m_stencil_clear_color;
135 VkDepthStencilObj *m_depthStencil;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600136 PFN_vkDbgCreateMsgCallback m_dbgCreateMsgCallback;
Courtney Goeltzenleuchter18e8a492015-06-08 15:16:04 -0600137 PFN_vkDbgDestroyMsgCallback m_dbgDestroyMsgCallback;
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600138 VkDbgMsgCallback m_globalMsgCallback;
139 VkDbgMsgCallback m_devMsgCallback;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600140
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 Barbour01999182015-04-09 12:58:51 -0600162class VkDescriptorSetObj;
163class VkIndexBufferObj;
164class VkConstantBufferObj;
165class VkPipelineObj;
166class VkDescriptorSetObj;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600167
Tony Barbour01999182015-04-09 12:58:51 -0600168class VkCommandBufferObj : public vk_testing::CmdBuffer
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600169{
170public:
Tony Barbour1490c912015-07-28 10:17:20 -0600171 VkCommandBufferObj(VkDeviceObj *device, VkCmdPool pool);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600172 VkCmdBuffer GetBufferHandle();
173 VkResult BeginCommandBuffer();
174 VkResult BeginCommandBuffer(VkCmdBufferBeginInfo *pInfo);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600175 VkResult EndCommandBuffer();
Courtney Goeltzenleuchter82b348f2015-07-12 13:07:46 -0600176 void PipelineBarrier(VkPipelineStageFlags src_stages, VkPipelineStageFlags dest_stages, VkBool32 byRegion, uint32_t memBarrierCount, const void* const* ppMemBarriers);
Tony Barbour01999182015-04-09 12:58:51 -0600177 void AddRenderTarget(VkImageObj *renderTarget);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600178 void AddDepthStencil();
Chris Forbese3105972015-06-24 14:34:53 +1200179 void ClearAllBuffers(VkClearColorValue clear_color, float depth_clear_color, uint32_t stencil_clear_color, VkDepthStencilObj *depthStencilObj);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600180 void PrepareAttachments();
Tony Barbour01999182015-04-09 12:58:51 -0600181 void BindPipeline(VkPipelineObj &pipeline);
182 void BindDescriptorSet(VkDescriptorSetObj &descriptorSet);
Tony Barbour8205d902015-04-16 15:59:00 -0600183 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding);
Cody Northrop1684adb2015-08-05 11:15:02 -0600184 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset);
Chia-I Wuc278df82015-07-07 11:50:03 +0800185 void BeginRenderPass(const VkRenderPassBeginInfo &info);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800186 void EndRenderPass();
Tony Barboure389b882015-07-20 13:00:10 -0600187 void FillBuffer(VkBuffer buffer, VkDeviceSize offset, VkDeviceSize fill_size, uint32_t data);
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600188 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance);
189 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600190 void QueueCommandBuffer();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600191 void QueueCommandBuffer(VkFence fence);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600192 void SetViewport(uint32_t viewportCount, const VkViewport* pViewports);
193 void SetScissor(uint32_t scissorCount, const VkRect2D* pScissors);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600194 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600201
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600202protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600203 VkDeviceObj *m_device;
204 vector<VkImageObj*> m_renderTargets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600205};
206
Tony Barbour01999182015-04-09 12:58:51 -0600207class VkConstantBufferObj : public vk_testing::Buffer
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600208{
209public:
Tony Barbour01999182015-04-09 12:58:51 -0600210 VkConstantBufferObj(VkDeviceObj *device);
211 VkConstantBufferObj(VkDeviceObj *device, int constantCount, int constantSize, const void* data);
212 ~VkConstantBufferObj();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600213 void BufferMemoryBarrier(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600214 VkFlags outputMask =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -0600215 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600216 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
217 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
218 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600219 VK_MEMORY_OUTPUT_TRANSFER_BIT,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600220 VkFlags inputMask =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -0600221 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600222 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 Goeltzenleuchterad870812015-04-15 15:29:59 -0600229 VK_MEMORY_INPUT_TRANSFER_BIT);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600230
Tony Barbour8205d902015-04-16 15:59:00 -0600231 void Bind(VkCmdBuffer cmdBuffer, VkDeviceSize offset, uint32_t binding);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600232
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800233 VkDescriptorInfo m_descriptorInfo;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600234
235protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600236 VkDeviceObj *m_device;
237 vk_testing::BufferView m_bufferView;
238 int m_numVertices;
239 int m_stride;
Tony Barbour1490c912015-07-28 10:17:20 -0600240 vk_testing::CmdPool *m_cmdPool;
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600241 VkCommandBufferObj *m_commandBuffer;
242 vk_testing::Fence m_fence;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600243};
244
Tony Barbour01999182015-04-09 12:58:51 -0600245class VkIndexBufferObj : public VkConstantBufferObj
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600246{
247public:
Tony Barbour01999182015-04-09 12:58:51 -0600248 VkIndexBufferObj(VkDeviceObj *device);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600249 void CreateAndInitBuffer(int numIndexes, VkIndexType dataFormat, const void* data);
Tony Barbour8205d902015-04-16 15:59:00 -0600250 void Bind(VkCmdBuffer cmdBuffer, VkDeviceSize offset);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600251 VkIndexType GetIndexType();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600252
253protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600254 VkIndexType m_indexType;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600255};
256
Tony Barbour01999182015-04-09 12:58:51 -0600257class VkImageObj : public vk_testing::Image
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600258{
259public:
Tony Barbour01999182015-04-09 12:58:51 -0600260 VkImageObj(VkDeviceObj *dev);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600261 bool IsCompatible(VkFlags usage, VkFlags features);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600262
263public:
264 void init(uint32_t w, uint32_t h,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600265 VkFormat fmt, VkFlags usage,
Tony Barbour94310562015-04-22 15:10:33 -0600266 VkImageTiling tiling=VK_IMAGE_TILING_LINEAR,
267 VkMemoryPropertyFlags reqs=0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600268
269 // void clear( CommandBuffer*, uint32_t[4] );
270
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600271 void layout( VkImageLayout layout )
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600272 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800273 m_descriptorInfo.imageLayout = layout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600274 }
275
Tony Barbour8205d902015-04-16 15:59:00 -0600276 VkDeviceMemory memory() const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600277 {
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800278 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600289 }
290
Tony Barbour01999182015-04-09 12:58:51 -0600291 void ImageMemoryBarrier(VkCommandBufferObj *cmd,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600292 VkImageAspect aspect,
293 VkFlags output_mask,
294 VkFlags input_mask,
295 VkImageLayout image_layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600296
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600297 VkResult CopyImage(VkImageObj &src_image);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600298
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600299 VkImage image() const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600300 {
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800301 return handle();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600302 }
303
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -0600304 VkImageView targetView(VkFormat format)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600305 {
306 if (!m_targetView.initialized())
307 {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -0600308 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 Northrop95b8bb32015-09-14 13:48:12 -0600317 createView.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -0600318 createView.flags = 0;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600319 m_targetView.init(*m_device, createView);
320 }
Chia-I Wu76ab1ff2015-07-03 11:49:42 +0800321 return m_targetView.handle();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600322 }
323
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600324 void SetLayout(VkCommandBufferObj *cmd_buf, VkImageAspect aspect, VkImageLayout image_layout);
325 void SetLayout(VkImageAspect aspect, VkImageLayout image_layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600326
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600327 VkImageLayout layout() const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600328 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800329 return m_descriptorInfo.imageLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600330 }
331 uint32_t width() const
332 {
333 return extent().width;
334 }
335 uint32_t height() const
336 {
337 return extent().height;
338 }
Tony Barbour01999182015-04-09 12:58:51 -0600339 VkDeviceObj* device() const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600340 {
341 return m_device;
342 }
343
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600344protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600345 VkDeviceObj *m_device;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600346
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -0600347 vk_testing::ImageView m_targetView;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800348 VkDescriptorInfo m_descriptorInfo;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600349};
350
Tony Barbour01999182015-04-09 12:58:51 -0600351class VkTextureObj : public VkImageObj
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600352{
353public:
Tony Barbour01999182015-04-09 12:58:51 -0600354 VkTextureObj(VkDeviceObj *device, uint32_t *colors = NULL);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600355
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800356 VkDescriptorInfo m_descriptorInfo;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600357
358protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600359 VkDeviceObj *m_device;
360 vk_testing::ImageView m_textureView;
361 VkDeviceSize m_rowPitch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600362};
363
Tony Barbour01999182015-04-09 12:58:51 -0600364class VkSamplerObj : public vk_testing::Sampler
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600365{
366public:
Tony Barbour01999182015-04-09 12:58:51 -0600367 VkSamplerObj(VkDeviceObj *device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600368
369protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600370 VkDeviceObj *m_device;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600371
372};
373
Tony Barbour01999182015-04-09 12:58:51 -0600374class VkDescriptorSetObj : public vk_testing::DescriptorPool
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600375{
376public:
Tony Barbour01999182015-04-09 12:58:51 -0600377 VkDescriptorSetObj(VkDeviceObj *device);
378 ~VkDescriptorSetObj();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600379
380 int AppendDummy();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600381 int AppendBuffer(VkDescriptorType type, VkConstantBufferObj &constantBuffer);
Tony Barbour01999182015-04-09 12:58:51 -0600382 int AppendSamplerTexture(VkSamplerObj* sampler, VkTextureObj* texture);
383 void CreateVKDescriptorSet(VkCommandBufferObj *cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600384
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600385 VkDescriptorSet GetDescriptorSetHandle() const;
Mark Lobodzinski556f7212015-04-17 14:11:39 -0500386 VkPipelineLayout GetPipelineLayout() const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600387
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600388protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600389 VkDeviceObj *m_device;
390 vector<VkDescriptorTypeCount> m_type_counts;
391 int m_nextSlot;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600392
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800393 vector<VkDescriptorInfo> m_imageSamplerDescriptors;
394 vector<VkWriteDescriptorSet> m_writes;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600395
396 vk_testing::DescriptorSetLayout m_layout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -0500397 vk_testing::PipelineLayout m_pipeline_layout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600398 vk_testing::DescriptorSet *m_set;
399};
400
401
Tony Barbour01999182015-04-09 12:58:51 -0600402class VkShaderObj : public vk_testing::Shader
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600403{
404public:
Tony Barbour8205d902015-04-16 15:59:00 -0600405 VkShaderObj(VkDeviceObj *device, const char * shaderText, VkShaderStage stage, VkRenderFramework *framework);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600406 VkPipelineShaderStageCreateInfo* GetStageCreateInfo();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600407
408protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600409 VkPipelineShaderStageCreateInfo stage_info;
410 VkShaderStage m_stage;
411 VkDeviceObj *m_device;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600412
413};
414
Tony Barbour01999182015-04-09 12:58:51 -0600415class VkPipelineObj : public vk_testing::Pipeline
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600416{
417public:
Tony Barbour01999182015-04-09 12:58:51 -0600418 VkPipelineObj(VkDeviceObj *device);
419 void AddShader(VkShaderObj* shaderObj);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600420 void AddVertexInputAttribs(VkVertexInputAttributeDescription* vi_attrib, int count);
421 void AddVertexInputBindings(VkVertexInputBindingDescription* vi_binding, int count);
Tony Barboure307f582015-07-10 15:29:03 -0600422 void AddColorAttachment(uint32_t binding, const VkPipelineColorBlendAttachmentState *att);
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600423 void MakeDynamic(VkDynamicState state);
Chia-I Wuc278df82015-07-07 11:50:03 +0800424
425 void AddColorAttachment()
426 {
Tony Barboure307f582015-07-10 15:29:03 -0600427 VkPipelineColorBlendAttachmentState att = {};
Chia-I Wuc278df82015-07-07 11:50:03 +0800428 att.blendEnable = VK_FALSE;
429 att.channelWriteMask = 0xf;
430 AddColorAttachment(0, &att);
431 }
432
Tony Barboure307f582015-07-10 15:29:03 -0600433 void SetDepthStencil(VkPipelineDepthStencilStateCreateInfo *);
Tony Barbour875e7462015-08-06 09:27:11 -0600434 void SetMSAA(VkPipelineMultisampleStateCreateInfo *ms_state);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600435 void SetViewport(vector<VkViewport> viewports);
436 void SetScissor(vector<VkRect2D> scissors);
Tony Barboured132432015-08-04 16:23:11 -0600437 VkResult CreateVKPipeline(VkPipelineLayout layout, VkRenderPass render_pass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600438
439protected:
Tony Barboure307f582015-07-10 15:29:03 -0600440 VkPipelineVertexInputStateCreateInfo m_vi_state;
441 VkPipelineInputAssemblyStateCreateInfo m_ia_state;
442 VkPipelineRasterStateCreateInfo m_rs_state;
443 VkPipelineColorBlendStateCreateInfo m_cb_state;
444 VkPipelineDepthStencilStateCreateInfo m_ds_state;
445 VkPipelineViewportStateCreateInfo m_vp_state;
446 VkPipelineMultisampleStateCreateInfo m_ms_state;
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600447 vector<VkDynamicState> m_dynamic_state_enables;
448 vector<VkViewport> m_viewports;
449 vector<VkRect2D> m_scissors;
Tony Barboure307f582015-07-10 15:29:03 -0600450 VkDeviceObj *m_device;
451 vector<VkShaderObj*> m_shaderObjs;
Tony Barboure307f582015-07-10 15:29:03 -0600452 vector<int> m_vertexBufferBindings;
453 vector<VkPipelineColorBlendAttachmentState> m_colorAttachments;
454 int m_vertexBufferCount;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600455};
456
457#endif // VKRENDERFRAMEWORK_H