blob: 26aff66d08588bcb5f6396db24d56af3dbc77453 [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);
Mike Stroyan43909d82015-09-25 13:39:21 -0600201 void UpdateBuffer(VkBuffer buffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t *pData);
202 void CopyImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage destImage, VkImageLayout destImageLayout, uint32_t regionCount, const VkImageCopy* pRegions);
203 void ResolveImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage destImage, VkImageLayout destImageLayout, uint32_t regionCount, const VkImageResolve* pRegions);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600204
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600205protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600206 VkDeviceObj *m_device;
207 vector<VkImageObj*> m_renderTargets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600208};
209
Tony Barbour01999182015-04-09 12:58:51 -0600210class VkConstantBufferObj : public vk_testing::Buffer
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600211{
212public:
Tony Barbour01999182015-04-09 12:58:51 -0600213 VkConstantBufferObj(VkDeviceObj *device);
214 VkConstantBufferObj(VkDeviceObj *device, int constantCount, int constantSize, const void* data);
215 ~VkConstantBufferObj();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600216 void BufferMemoryBarrier(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600217 VkFlags outputMask =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -0600218 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600219 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
220 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
221 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600222 VK_MEMORY_OUTPUT_TRANSFER_BIT,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600223 VkFlags inputMask =
Courtney Goeltzenleuchtera569a502015-04-29 17:16:21 -0600224 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600225 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
226 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
227 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
228 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
229 VK_MEMORY_INPUT_SHADER_READ_BIT |
230 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
231 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600232 VK_MEMORY_INPUT_TRANSFER_BIT);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600233
Tony Barbour8205d902015-04-16 15:59:00 -0600234 void Bind(VkCmdBuffer cmdBuffer, VkDeviceSize offset, uint32_t binding);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600235
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -0600236 VkDescriptorBufferInfo m_descriptorBufferInfo;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600237
238protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600239 VkDeviceObj *m_device;
240 vk_testing::BufferView m_bufferView;
241 int m_numVertices;
242 int m_stride;
Tony Barbour1490c912015-07-28 10:17:20 -0600243 vk_testing::CmdPool *m_cmdPool;
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600244 VkCommandBufferObj *m_commandBuffer;
245 vk_testing::Fence m_fence;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600246};
247
Tony Barbour01999182015-04-09 12:58:51 -0600248class VkIndexBufferObj : public VkConstantBufferObj
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600249{
250public:
Tony Barbour01999182015-04-09 12:58:51 -0600251 VkIndexBufferObj(VkDeviceObj *device);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600252 void CreateAndInitBuffer(int numIndexes, VkIndexType dataFormat, const void* data);
Tony Barbour8205d902015-04-16 15:59:00 -0600253 void Bind(VkCmdBuffer cmdBuffer, VkDeviceSize offset);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600254 VkIndexType GetIndexType();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600255
256protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600257 VkIndexType m_indexType;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600258};
259
Tony Barbour01999182015-04-09 12:58:51 -0600260class VkImageObj : public vk_testing::Image
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600261{
262public:
Tony Barbour01999182015-04-09 12:58:51 -0600263 VkImageObj(VkDeviceObj *dev);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600264 bool IsCompatible(VkFlags usage, VkFlags features);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600265
266public:
267 void init(uint32_t w, uint32_t h,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600268 VkFormat fmt, VkFlags usage,
Tony Barbour94310562015-04-22 15:10:33 -0600269 VkImageTiling tiling=VK_IMAGE_TILING_LINEAR,
270 VkMemoryPropertyFlags reqs=0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600271
272 // void clear( CommandBuffer*, uint32_t[4] );
273
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600274 void layout( VkImageLayout layout )
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600275 {
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -0600276 m_descriptorImageInfo.imageLayout = layout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600277 }
278
Tony Barbour8205d902015-04-16 15:59:00 -0600279 VkDeviceMemory memory() const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600280 {
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800281 return Image::memory().handle();
282 }
283
284 void *MapMemory()
285 {
286 return Image::memory().map();
287 }
288
289 void UnmapMemory()
290 {
291 Image::memory().unmap();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600292 }
293
Tony Barbour01999182015-04-09 12:58:51 -0600294 void ImageMemoryBarrier(VkCommandBufferObj *cmd,
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -0600295 VkImageAspectFlags aspect,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600296 VkFlags output_mask,
297 VkFlags input_mask,
298 VkImageLayout image_layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600299
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600300 VkResult CopyImage(VkImageObj &src_image);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600301
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600302 VkImage image() const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600303 {
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800304 return handle();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600305 }
306
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -0600307 VkImageView targetView(VkFormat format)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600308 {
309 if (!m_targetView.initialized())
310 {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -0600311 VkImageViewCreateInfo createView = {};
312 createView.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
313 createView.image = handle();
314 createView.viewType = VK_IMAGE_VIEW_TYPE_2D;
315 createView.format = format;
316 createView.channels.r = VK_CHANNEL_SWIZZLE_R;
317 createView.channels.g = VK_CHANNEL_SWIZZLE_G;
318 createView.channels.b = VK_CHANNEL_SWIZZLE_B;
319 createView.channels.a = VK_CHANNEL_SWIZZLE_A;
Cody Northrop95b8bb32015-09-14 13:48:12 -0600320 createView.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -0600321 createView.flags = 0;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600322 m_targetView.init(*m_device, createView);
323 }
Chia-I Wu76ab1ff2015-07-03 11:49:42 +0800324 return m_targetView.handle();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600325 }
326
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -0600327 void SetLayout(VkCommandBufferObj *cmd_buf, VkImageAspectFlagBits aspect, VkImageLayout image_layout);
328 void SetLayout(VkImageAspectFlagBits aspect, VkImageLayout image_layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600329
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600330 VkImageLayout layout() const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600331 {
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -0600332 return m_descriptorImageInfo.imageLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600333 }
334 uint32_t width() const
335 {
336 return extent().width;
337 }
338 uint32_t height() const
339 {
340 return extent().height;
341 }
Tony Barbour01999182015-04-09 12:58:51 -0600342 VkDeviceObj* device() const
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600343 {
344 return m_device;
345 }
346
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600347protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600348 VkDeviceObj *m_device;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600349
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -0600350 vk_testing::ImageView m_targetView;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -0600351 VkDescriptorImageInfo m_descriptorImageInfo;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600352};
353
Tony Barbour01999182015-04-09 12:58:51 -0600354class VkTextureObj : public VkImageObj
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600355{
356public:
Tony Barbour01999182015-04-09 12:58:51 -0600357 VkTextureObj(VkDeviceObj *device, uint32_t *colors = NULL);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600358
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -0600359 VkDescriptorImageInfo m_imageInfo;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600360
361protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600362 VkDeviceObj *m_device;
363 vk_testing::ImageView m_textureView;
364 VkDeviceSize m_rowPitch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600365};
366
Tony Barbour01999182015-04-09 12:58:51 -0600367class VkSamplerObj : public vk_testing::Sampler
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600368{
369public:
Tony Barbour01999182015-04-09 12:58:51 -0600370 VkSamplerObj(VkDeviceObj *device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600371
372protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600373 VkDeviceObj *m_device;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600374
375};
376
Tony Barbour01999182015-04-09 12:58:51 -0600377class VkDescriptorSetObj : public vk_testing::DescriptorPool
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600378{
379public:
Tony Barbour01999182015-04-09 12:58:51 -0600380 VkDescriptorSetObj(VkDeviceObj *device);
381 ~VkDescriptorSetObj();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600382
383 int AppendDummy();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600384 int AppendBuffer(VkDescriptorType type, VkConstantBufferObj &constantBuffer);
Tony Barbour01999182015-04-09 12:58:51 -0600385 int AppendSamplerTexture(VkSamplerObj* sampler, VkTextureObj* texture);
386 void CreateVKDescriptorSet(VkCommandBufferObj *cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600387
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600388 VkDescriptorSet GetDescriptorSetHandle() const;
Mark Lobodzinski556f7212015-04-17 14:11:39 -0500389 VkPipelineLayout GetPipelineLayout() const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600390
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600391protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600392 VkDeviceObj *m_device;
393 vector<VkDescriptorTypeCount> m_type_counts;
394 int m_nextSlot;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600395
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -0600396 vector<VkDescriptorImageInfo> m_imageSamplerDescriptors;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800397 vector<VkWriteDescriptorSet> m_writes;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600398
399 vk_testing::DescriptorSetLayout m_layout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -0500400 vk_testing::PipelineLayout m_pipeline_layout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600401 vk_testing::DescriptorSet *m_set;
402};
403
404
Tony Barbour01999182015-04-09 12:58:51 -0600405class VkShaderObj : public vk_testing::Shader
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600406{
407public:
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600408 VkShaderObj(VkDeviceObj *device, const char * shaderText, VkShaderStageFlagBits stage, VkRenderFramework *framework);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600409 VkPipelineShaderStageCreateInfo* GetStageCreateInfo();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600410
411protected:
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600412 VkPipelineShaderStageCreateInfo stage_info;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600413 VkShaderStageFlagBits m_stage;
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600414 VkDeviceObj *m_device;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600415
416};
417
Tony Barbour01999182015-04-09 12:58:51 -0600418class VkPipelineObj : public vk_testing::Pipeline
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600419{
420public:
Tony Barbour01999182015-04-09 12:58:51 -0600421 VkPipelineObj(VkDeviceObj *device);
422 void AddShader(VkShaderObj* shaderObj);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600423 void AddVertexInputAttribs(VkVertexInputAttributeDescription* vi_attrib, int count);
424 void AddVertexInputBindings(VkVertexInputBindingDescription* vi_binding, int count);
Tony Barboure307f582015-07-10 15:29:03 -0600425 void AddColorAttachment(uint32_t binding, const VkPipelineColorBlendAttachmentState *att);
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600426 void MakeDynamic(VkDynamicState state);
Chia-I Wuc278df82015-07-07 11:50:03 +0800427
428 void AddColorAttachment()
429 {
Tony Barboure307f582015-07-10 15:29:03 -0600430 VkPipelineColorBlendAttachmentState att = {};
Chia-I Wuc278df82015-07-07 11:50:03 +0800431 att.blendEnable = VK_FALSE;
432 att.channelWriteMask = 0xf;
433 AddColorAttachment(0, &att);
434 }
435
Tony Barboure307f582015-07-10 15:29:03 -0600436 void SetDepthStencil(VkPipelineDepthStencilStateCreateInfo *);
Tony Barbour875e7462015-08-06 09:27:11 -0600437 void SetMSAA(VkPipelineMultisampleStateCreateInfo *ms_state);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600438 void SetViewport(vector<VkViewport> viewports);
439 void SetScissor(vector<VkRect2D> scissors);
Tony Barboured132432015-08-04 16:23:11 -0600440 VkResult CreateVKPipeline(VkPipelineLayout layout, VkRenderPass render_pass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600441
442protected:
Tony Barboure307f582015-07-10 15:29:03 -0600443 VkPipelineVertexInputStateCreateInfo m_vi_state;
444 VkPipelineInputAssemblyStateCreateInfo m_ia_state;
445 VkPipelineRasterStateCreateInfo m_rs_state;
446 VkPipelineColorBlendStateCreateInfo m_cb_state;
447 VkPipelineDepthStencilStateCreateInfo m_ds_state;
448 VkPipelineViewportStateCreateInfo m_vp_state;
449 VkPipelineMultisampleStateCreateInfo m_ms_state;
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600450 vector<VkDynamicState> m_dynamic_state_enables;
451 vector<VkViewport> m_viewports;
452 vector<VkRect2D> m_scissors;
Tony Barboure307f582015-07-10 15:29:03 -0600453 VkDeviceObj *m_device;
454 vector<VkShaderObj*> m_shaderObjs;
Tony Barboure307f582015-07-10 15:29:03 -0600455 vector<int> m_vertexBufferBindings;
456 vector<VkPipelineColorBlendAttachmentState> m_colorAttachments;
457 int m_vertexBufferCount;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600458};
459
460#endif // VKRENDERFRAMEWORK_H