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