blob: 8bfbf12572e74a3d80700568b01a942ad371eacf [file] [log] [blame]
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001/*
Karl Schultz6addd812016-02-02 17:17:23 -07002 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06006 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06009 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060010 * http://www.apache.org/licenses/LICENSE-2.0
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060011 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060012 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060017 *
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060018 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060019 */
20
21#ifndef VKRENDERFRAMEWORK_H
22#define VKRENDERFRAMEWORK_H
23
Michael Lentine83ab3412015-11-03 16:20:30 -080024#ifdef ANDROID
25#include "vktestframeworkandroid.h"
26class VkImageObj;
27#else
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060028#include "vktestframework.h"
Michael Lentine83ab3412015-11-03 16:20:30 -080029#endif
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060030
Mark Lobodzinski0556a632016-09-07 16:34:10 -060031#include <array>
Tony Barbourb31ae812016-04-11 11:39:43 -060032#include <map>
Michael Lentine83ab3412015-11-03 16:20:30 -080033#include <vector>
34
35using namespace std;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060036
Karl Schultz6addd812016-02-02 17:17:23 -070037class VkDeviceObj : public vk_testing::Device {
38 public:
Tony Barbourd1c35722015-04-16 15:59:00 -060039 VkDeviceObj(uint32_t id, VkPhysicalDevice obj);
Mark Lobodzinski0556a632016-09-07 16:34:10 -060040 VkDeviceObj(uint32_t id, VkPhysicalDevice obj, std::vector<const char *> &extension_names,
Tony Barbour53f7e892016-08-09 13:44:00 -060041 VkPhysicalDeviceFeatures *features = nullptr);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060042
Chia-I Wuf368b602015-07-03 10:41:20 +080043 VkDevice device() { return handle(); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060044 void get_device_queue();
45
Karl Schultz6addd812016-02-02 17:17:23 -070046 uint32_t id;
47 VkPhysicalDeviceProperties props;
Dustin Graves48458142016-04-29 16:11:55 -060048 std::vector<VkQueueFamilyProperties> queue_props;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060049
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060050 VkQueue m_queue;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060051};
52
Tony Barbourfe3351b2015-07-28 10:17:20 -060053class VkCommandBufferObj;
Tony Barbour0371eb52016-04-05 11:44:03 -060054class VkDepthStencilObj;
Tony Barbourfe3351b2015-07-28 10:17:20 -060055
Karl Schultz6addd812016-02-02 17:17:23 -070056class VkRenderFramework : public VkTestFramework {
57 public:
Tony Barbour6918cd52015-04-09 12:58:51 -060058 VkRenderFramework();
59 ~VkRenderFramework();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060060
Ian Elliott1c32c772016-04-28 14:47:13 -060061 VkInstance instance() { return inst; }
Karl Schultz6addd812016-02-02 17:17:23 -070062 VkDevice device() { return m_device->device(); }
63 VkPhysicalDevice gpu() { return objs[0]; }
64 VkRenderPass renderPass() { return m_renderPass; }
65 VkFramebuffer framebuffer() { return m_framebuffer; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060066 void InitViewport(float width, float height);
67 void InitViewport();
68 void InitRenderTarget();
69 void InitRenderTarget(uint32_t targets);
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -060070 void InitRenderTarget(VkImageView *dsBinding);
71 void InitRenderTarget(uint32_t targets, VkImageView *dsBinding);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060072 void InitFramework();
Mark Lobodzinski0556a632016-09-07 16:34:10 -060073 void InitFramework(std::vector<const char *> instance_layer_names, std::vector<const char *> instance_extension_names,
74 std::vector<const char *> device_extension_names, PFN_vkDebugReportCallbackEXT = NULL,
Karl Schultz6addd812016-02-02 17:17:23 -070075 void *userData = NULL);
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -060076
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060077 void ShutdownFramework();
Cody Northropc31a84f2016-08-22 10:41:47 -060078 void InitState(VkPhysicalDeviceFeatures *features = nullptr);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060079
Mark Lobodzinski0556a632016-09-07 16:34:10 -060080 const VkRenderPassBeginInfo &renderPassBeginInfo() const { return m_renderPassBeginInfo; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060081
Karl Schultz6addd812016-02-02 17:17:23 -070082 protected:
83 VkApplicationInfo app_info;
84 VkInstance inst;
85 VkPhysicalDevice objs[16];
86 uint32_t gpu_count;
87 VkDeviceObj *m_device;
88 VkCommandPool m_commandPool;
89 VkCommandBufferObj *m_commandBuffer;
90 VkRenderPass m_renderPass;
91 VkFramebuffer m_framebuffer;
92 std::vector<VkViewport> m_viewports;
93 std::vector<VkRect2D> m_scissors;
94 float m_lineWidth;
95 float m_depthBiasConstantFactor;
96 float m_depthBiasClamp;
97 float m_depthBiasSlopeFactor;
98 float m_blendConstants[4];
99 float m_minDepthBounds;
100 float m_maxDepthBounds;
101 uint32_t m_compareMask;
102 uint32_t m_writeMask;
103 uint32_t m_reference;
104 std::vector<VkClearValue> m_renderPassClearValues;
105 VkRenderPassBeginInfo m_renderPassBeginInfo;
106 vector<VkImageObj *> m_renderTargets;
107 float m_width, m_height;
108 VkFormat m_render_target_fmt;
109 VkFormat m_depth_stencil_fmt;
110 VkClearColorValue m_clear_color;
111 bool m_clear_via_load_op;
112 float m_depth_clear_color;
113 uint32_t m_stencil_clear_color;
114 VkDepthStencilObj *m_depthStencil;
115 PFN_vkCreateDebugReportCallbackEXT m_CreateDebugReportCallback;
Courtney Goeltzenleuchter011ccf82015-12-15 09:25:15 -0700116 PFN_vkDestroyDebugReportCallbackEXT m_DestroyDebugReportCallback;
Karl Schultz6addd812016-02-02 17:17:23 -0700117 PFN_vkDebugReportMessageEXT m_DebugReportMessage;
118 VkDebugReportCallbackEXT m_globalMsgCallback;
119 VkDebugReportCallbackEXT m_devMsgCallback;
Cody Northropc31a84f2016-08-22 10:41:47 -0600120 std::vector<const char *> device_extension_names;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600121
122 /*
123 * SetUp and TearDown are called by the Google Test framework
124 * to initialize a test framework based on this class.
125 */
126 virtual void SetUp() {
127 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
128 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800129 this->app_info.pApplicationName = "base";
130 this->app_info.applicationVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600131 this->app_info.pEngineName = "unittest";
132 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600133 this->app_info.apiVersion = VK_API_VERSION_1_0;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600134
135 InitFramework();
136 }
137
Karl Schultz6addd812016-02-02 17:17:23 -0700138 virtual void TearDown() { ShutdownFramework(); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600139};
140
Tony Barbour6918cd52015-04-09 12:58:51 -0600141class VkDescriptorSetObj;
142class VkIndexBufferObj;
143class VkConstantBufferObj;
144class VkPipelineObj;
145class VkDescriptorSetObj;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600146
Karl Schultz6addd812016-02-02 17:17:23 -0700147class VkCommandBufferObj : public vk_testing::CommandBuffer {
148 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800149 VkCommandBufferObj(VkDeviceObj *device, VkCommandPool pool);
150 VkCommandBuffer GetBufferHandle();
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600151 VkResult BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800152 VkResult BeginCommandBuffer(VkCommandBufferBeginInfo *pInfo);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600153 VkResult EndCommandBuffer();
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600154 void PipelineBarrier(VkPipelineStageFlags src_stages, VkPipelineStageFlags dest_stages, VkDependencyFlags dependencyFlags,
155 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount,
156 const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount,
Karl Schultz6addd812016-02-02 17:17:23 -0700157 const VkImageMemoryBarrier *pImageMemoryBarriers);
Tony Barbour6918cd52015-04-09 12:58:51 -0600158 void AddRenderTarget(VkImageObj *renderTarget);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600159 void AddDepthStencil();
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600160 void ClearAllBuffers(VkClearColorValue clear_color, float depth_clear_color, uint32_t stencil_clear_color,
Karl Schultz6addd812016-02-02 17:17:23 -0700161 VkDepthStencilObj *depthStencilObj);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600162 void PrepareAttachments();
Tony Barbour6918cd52015-04-09 12:58:51 -0600163 void BindPipeline(VkPipelineObj &pipeline);
164 void BindDescriptorSet(VkDescriptorSetObj &descriptorSet);
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600165 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding);
Cody Northropd2ad0342015-08-05 11:15:02 -0600166 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset);
Chia-I Wu08accc62015-07-07 11:50:03 +0800167 void BeginRenderPass(const VkRenderPassBeginInfo &info);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +0800168 void EndRenderPass();
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600169 void FillBuffer(VkBuffer buffer, VkDeviceSize offset, VkDeviceSize fill_size, uint32_t data);
170 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance);
171 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700172 uint32_t firstInstance);
Mark Muellerdfe37552016-07-07 14:47:42 -0600173 void QueueCommandBuffer(bool checkSuccess = true);
174 void QueueCommandBuffer(VkFence fence, bool checkSuccess = true);
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600175 void SetViewport(uint32_t firstViewport, uint32_t viewportCount, const VkViewport *pViewports);
176 void SetScissor(uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600177 void SetLineWidth(float lineWidth);
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600178 void SetDepthBias(float depthBiasConstantFactor, float depthBiasClamp, float depthBiasSlopeFactor);
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800179 void SetBlendConstants(const float blendConstants[4]);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600180 void SetDepthBounds(float minDepthBounds, float maxDepthBounds);
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800181 void SetStencilReadMask(VkStencilFaceFlags faceMask, uint32_t compareMask);
182 void SetStencilWriteMask(VkStencilFaceFlags faceMask, uint32_t writeMask);
183 void SetStencilReference(VkStencilFaceFlags faceMask, uint32_t reference);
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600184 void UpdateBuffer(VkBuffer buffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData);
185 void CopyImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
Karl Schultz6addd812016-02-02 17:17:23 -0700186 uint32_t regionCount, const VkImageCopy *pRegions);
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600187 void ResolveImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
Karl Schultz6addd812016-02-02 17:17:23 -0700188 uint32_t regionCount, const VkImageResolve *pRegions);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600189
Karl Schultz6addd812016-02-02 17:17:23 -0700190 protected:
191 VkDeviceObj *m_device;
192 vector<VkImageObj *> m_renderTargets;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600193};
194
Karl Schultz6addd812016-02-02 17:17:23 -0700195class VkConstantBufferObj : public vk_testing::Buffer {
196 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600197 VkConstantBufferObj(VkDeviceObj *device,
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600198 VkBufferUsageFlags usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT);
199 VkConstantBufferObj(VkDeviceObj *device, int constantCount, int constantSize, const void *data,
200 VkBufferUsageFlags usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT);
Tony Barbour6918cd52015-04-09 12:58:51 -0600201 ~VkConstantBufferObj();
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600202 void BufferMemoryBarrier(VkFlags srcAccessMask = VK_ACCESS_HOST_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT |
203 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
204 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT,
205 VkFlags dstAccessMask = VK_ACCESS_HOST_READ_BIT | VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
206 VK_ACCESS_INDEX_READ_BIT | VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
207 VK_ACCESS_UNIFORM_READ_BIT | VK_ACCESS_SHADER_READ_BIT |
208 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
209 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_MEMORY_READ_BIT);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600210
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600211 void Bind(VkCommandBuffer commandBuffer, VkDeviceSize offset, uint32_t binding);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600212
Karl Schultz6addd812016-02-02 17:17:23 -0700213 VkDescriptorBufferInfo m_descriptorBufferInfo;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600214
Karl Schultz6addd812016-02-02 17:17:23 -0700215 protected:
216 VkDeviceObj *m_device;
217 vk_testing::BufferView m_bufferView;
218 int m_numVertices;
219 int m_stride;
220 vk_testing::CommandPool *m_commandPool;
221 VkCommandBufferObj *m_commandBuffer;
222 vk_testing::Fence m_fence;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600223};
224
Karl Schultz6addd812016-02-02 17:17:23 -0700225class VkIndexBufferObj : public VkConstantBufferObj {
226 public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600227 VkIndexBufferObj(VkDeviceObj *device);
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600228 void CreateAndInitBuffer(int numIndexes, VkIndexType dataFormat, const void *data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800229 void Bind(VkCommandBuffer commandBuffer, VkDeviceSize offset);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600230 VkIndexType GetIndexType();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600231
Karl Schultz6addd812016-02-02 17:17:23 -0700232 protected:
233 VkIndexType m_indexType;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600234};
235
Tony Barbourc157b7c2016-08-09 15:42:33 -0600236class VkRenderpassObj {
237 public:
238 VkRenderpassObj(VkDeviceObj *device);
239 ~VkRenderpassObj();
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600240 VkRenderPass handle() { return m_renderpass; }
Tony Barbourc157b7c2016-08-09 15:42:33 -0600241
242 protected:
243 VkRenderPass m_renderpass;
244 VkDevice device;
245};
246
Karl Schultz6addd812016-02-02 17:17:23 -0700247class VkImageObj : public vk_testing::Image {
248 public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600249 VkImageObj(VkDeviceObj *dev);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600250 bool IsCompatible(VkFlags usage, VkFlags features);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600251
Karl Schultz6addd812016-02-02 17:17:23 -0700252 public:
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600253 void init(uint32_t w, uint32_t h, VkFormat fmt, VkFlags usage, VkImageTiling tiling = VK_IMAGE_TILING_LINEAR,
Karl Schultz6addd812016-02-02 17:17:23 -0700254 VkMemoryPropertyFlags reqs = 0);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600255
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600256 void init_no_layout(uint32_t w, uint32_t h, VkFormat fmt, VkFlags usage, VkImageTiling tiling = VK_IMAGE_TILING_LINEAR,
257 VkMemoryPropertyFlags reqs = 0);
Tony Barbour59dddeb2016-08-02 13:04:47 -0600258
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600259 // void clear( CommandBuffer*, uint32_t[4] );
260
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600261 void layout(VkImageLayout layout) { m_descriptorImageInfo.imageLayout = layout; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600262
Karl Schultz6addd812016-02-02 17:17:23 -0700263 VkDeviceMemory memory() const { return Image::memory().handle(); }
Chia-I Wu681d7a02015-07-03 13:44:34 +0800264
Karl Schultz6addd812016-02-02 17:17:23 -0700265 void *MapMemory() { return Image::memory().map(); }
Chia-I Wu681d7a02015-07-03 13:44:34 +0800266
Karl Schultz6addd812016-02-02 17:17:23 -0700267 void UnmapMemory() { Image::memory().unmap(); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600268
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600269 void ImageMemoryBarrier(VkCommandBufferObj *cmd, VkImageAspectFlags aspect, VkFlags output_mask, VkFlags input_mask,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600270 VkImageLayout image_layout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600271
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600272 VkResult CopyImage(VkImageObj &src_image);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600273
Karl Schultz6addd812016-02-02 17:17:23 -0700274 VkImage image() const { return handle(); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600275
Karl Schultz6addd812016-02-02 17:17:23 -0700276 VkImageView targetView(VkFormat format) {
277 if (!m_targetView.initialized()) {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -0600278 VkImageViewCreateInfo createView = {};
279 createView.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
280 createView.image = handle();
Karl Schultz6addd812016-02-02 17:17:23 -0700281 createView.viewType = VK_IMAGE_VIEW_TYPE_2D;
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -0600282 createView.format = format;
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800283 createView.components.r = VK_COMPONENT_SWIZZLE_R;
284 createView.components.g = VK_COMPONENT_SWIZZLE_G;
285 createView.components.b = VK_COMPONENT_SWIZZLE_B;
286 createView.components.a = VK_COMPONENT_SWIZZLE_A;
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600287 createView.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -0600288 createView.flags = 0;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600289 m_targetView.init(*m_device, createView);
290 }
Chia-I Wu3158bf32015-07-03 11:49:42 +0800291 return m_targetView.handle();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600292 }
293
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600294 void SetLayout(VkCommandBufferObj *cmd_buf, VkImageAspectFlags aspect, VkImageLayout image_layout);
Tony Barbour9a359b62016-06-16 13:17:35 -0600295 void SetLayout(VkImageAspectFlags aspect, VkImageLayout image_layout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600296
Karl Schultz6addd812016-02-02 17:17:23 -0700297 VkImageLayout layout() const { return m_descriptorImageInfo.imageLayout; }
298 uint32_t width() const { return extent().width; }
299 uint32_t height() const { return extent().height; }
300 VkDeviceObj *device() const { return m_device; }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600301
Karl Schultz6addd812016-02-02 17:17:23 -0700302 protected:
303 VkDeviceObj *m_device;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600304
Karl Schultz6addd812016-02-02 17:17:23 -0700305 vk_testing::ImageView m_targetView;
306 VkDescriptorImageInfo m_descriptorImageInfo;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600307};
308
Karl Schultz6addd812016-02-02 17:17:23 -0700309class VkTextureObj : public VkImageObj {
310 public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600311 VkTextureObj(VkDeviceObj *device, uint32_t *colors = NULL);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600312
Karl Schultz6addd812016-02-02 17:17:23 -0700313 VkDescriptorImageInfo m_imageInfo;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600314
Karl Schultz6addd812016-02-02 17:17:23 -0700315 protected:
316 VkDeviceObj *m_device;
317 vk_testing::ImageView m_textureView;
318 VkDeviceSize m_rowPitch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600319};
320
Tony Barbour0371eb52016-04-05 11:44:03 -0600321class VkDepthStencilObj : public VkImageObj {
322 public:
323 VkDepthStencilObj(VkDeviceObj *device);
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600324 void Init(VkDeviceObj *device, int32_t width, int32_t height, VkFormat format,
325 VkImageUsageFlags usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
Tony Barbour0371eb52016-04-05 11:44:03 -0600326 bool Initialized();
327 VkImageView *BindInfo();
328
329 protected:
330 VkDeviceObj *m_device;
331 bool m_initialized;
332 vk_testing::ImageView m_imageView;
333 VkFormat m_depth_stencil_fmt;
334 VkImageView m_attachmentBindInfo;
335};
336
Karl Schultz6addd812016-02-02 17:17:23 -0700337class VkSamplerObj : public vk_testing::Sampler {
338 public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600339 VkSamplerObj(VkDeviceObj *device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600340
Karl Schultz6addd812016-02-02 17:17:23 -0700341 protected:
342 VkDeviceObj *m_device;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600343};
344
Karl Schultz6addd812016-02-02 17:17:23 -0700345class VkDescriptorSetObj : public vk_testing::DescriptorPool {
346 public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600347 VkDescriptorSetObj(VkDeviceObj *device);
348 ~VkDescriptorSetObj();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600349
350 int AppendDummy();
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600351 int AppendBuffer(VkDescriptorType type, VkConstantBufferObj &constantBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700352 int AppendSamplerTexture(VkSamplerObj *sampler, VkTextureObj *texture);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800353 void CreateVKDescriptorSet(VkCommandBufferObj *commandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600354
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600355 VkDescriptorSet GetDescriptorSetHandle() const;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -0500356 VkPipelineLayout GetPipelineLayout() const;
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600357 int GetTypeCounts() { return m_type_counts.size(); }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600358
Karl Schultz6addd812016-02-02 17:17:23 -0700359 protected:
360 VkDeviceObj *m_device;
Tony Barbourb31ae812016-04-11 11:39:43 -0600361 std::vector<VkDescriptorSetLayoutBinding> m_layout_bindings;
362 std::map<VkDescriptorType, int> m_type_counts;
Karl Schultz6addd812016-02-02 17:17:23 -0700363 int m_nextSlot;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600364
Karl Schultz6addd812016-02-02 17:17:23 -0700365 vector<VkDescriptorImageInfo> m_imageSamplerDescriptors;
366 vector<VkWriteDescriptorSet> m_writes;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600367
Karl Schultz6addd812016-02-02 17:17:23 -0700368 vk_testing::DescriptorSetLayout m_layout;
369 vk_testing::PipelineLayout m_pipeline_layout;
Tony Barbour26aa42b2016-03-02 15:35:27 -0700370 vk_testing::DescriptorSet *m_set = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600371};
372
Karl Schultz6addd812016-02-02 17:17:23 -0700373class VkShaderObj : public vk_testing::ShaderModule {
374 public:
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600375 VkShaderObj(VkDeviceObj *device, const char *shaderText, VkShaderStageFlagBits stage, VkRenderFramework *framework,
Chris Forbes4f9b0e62015-12-30 11:49:04 +1300376 char const *name = "main");
Chia-I Wu28e06912015-10-31 00:31:16 +0800377 VkPipelineShaderStageCreateInfo GetStageCreateInfo() const;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600378
Karl Schultz6addd812016-02-02 17:17:23 -0700379 protected:
380 VkPipelineShaderStageCreateInfo stage_info;
381 VkShaderStageFlagBits m_stage;
Chris Forbes4f9b0e62015-12-30 11:49:04 +1300382 char const *m_name;
Karl Schultz6addd812016-02-02 17:17:23 -0700383 VkDeviceObj *m_device;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600384};
385
Karl Schultz6addd812016-02-02 17:17:23 -0700386class VkPipelineObj : public vk_testing::Pipeline {
387 public:
Tony Barbour6918cd52015-04-09 12:58:51 -0600388 VkPipelineObj(VkDeviceObj *device);
Karl Schultz6addd812016-02-02 17:17:23 -0700389 void AddShader(VkShaderObj *shaderObj);
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600390 void AddVertexInputAttribs(VkVertexInputAttributeDescription *vi_attrib, uint32_t count);
391 void AddVertexInputBindings(VkVertexInputBindingDescription *vi_binding, uint32_t count);
392 void AddColorAttachment(uint32_t binding, const VkPipelineColorBlendAttachmentState *att);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600393 void MakeDynamic(VkDynamicState state);
Chia-I Wu08accc62015-07-07 11:50:03 +0800394
Karl Schultz6addd812016-02-02 17:17:23 -0700395 void AddColorAttachment() {
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600396 VkPipelineColorBlendAttachmentState att = {};
Chia-I Wu08accc62015-07-07 11:50:03 +0800397 att.blendEnable = VK_FALSE;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800398 att.colorWriteMask = 0xf;
Chia-I Wu08accc62015-07-07 11:50:03 +0800399 AddColorAttachment(0, &att);
400 }
401
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600402 void SetDepthStencil(const VkPipelineDepthStencilStateCreateInfo *);
403 void SetMSAA(const VkPipelineMultisampleStateCreateInfo *ms_state);
Chris Forbesb4cacb62016-04-04 19:15:00 +1200404 void SetInputAssembly(const VkPipelineInputAssemblyStateCreateInfo *ia_state);
405 void SetRasterization(const VkPipelineRasterizationStateCreateInfo *rs_state);
406 void SetTessellation(const VkPipelineTessellationStateCreateInfo *te_state);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600407 void SetViewport(const vector<VkViewport> viewports);
408 void SetScissor(const vector<VkRect2D> scissors);
Mark Lobodzinski0556a632016-09-07 16:34:10 -0600409 VkResult CreateVKPipeline(VkPipelineLayout layout, VkRenderPass render_pass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600410
Karl Schultz6addd812016-02-02 17:17:23 -0700411 protected:
412 VkPipelineVertexInputStateCreateInfo m_vi_state;
413 VkPipelineInputAssemblyStateCreateInfo m_ia_state;
414 VkPipelineRasterizationStateCreateInfo m_rs_state;
415 VkPipelineColorBlendStateCreateInfo m_cb_state;
Chris Forbescda41892016-09-13 15:52:00 +1200416 VkPipelineDepthStencilStateCreateInfo const *m_ds_state;
Karl Schultz6addd812016-02-02 17:17:23 -0700417 VkPipelineViewportStateCreateInfo m_vp_state;
418 VkPipelineMultisampleStateCreateInfo m_ms_state;
Chris Forbesb4cacb62016-04-04 19:15:00 +1200419 VkPipelineTessellationStateCreateInfo m_te_state;
Karl Schultz6addd812016-02-02 17:17:23 -0700420 vector<VkDynamicState> m_dynamic_state_enables;
421 vector<VkViewport> m_viewports;
422 vector<VkRect2D> m_scissors;
423 VkDeviceObj *m_device;
424 vector<VkShaderObj *> m_shaderObjs;
425 vector<int> m_vertexBufferBindings;
426 vector<VkPipelineColorBlendAttachmentState> m_colorAttachments;
427 int m_vertexBufferCount;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600428};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600429#endif // VKRENDERFRAMEWORK_H