blob: 7db800f2de41fcc5c11891ddf4485279046c6b73 [file] [log] [blame]
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001/*
Karl Schultz99e9d1d2016-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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06005 *
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and/or associated documentation files (the "Materials"), to
8 * deal in the Materials without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Materials, and to permit persons to whom the Materials are
11 * furnished to do so, subject to the following conditions:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060012 *
Karl Schultz99e9d1d2016-02-02 17:17:23 -070013 * The above copyright notice(s) and this permission notice shall be included in
14 * all copies or substantial portions of the Materials.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060015 *
Karl Schultz99e9d1d2016-02-02 17:17:23 -070016 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060017 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Karl Schultz99e9d1d2016-02-02 17:17:23 -070018 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 *
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
23 * USE OR OTHER DEALINGS IN THE MATERIALS.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060024 *
Courtney Goeltzenleuchter96cd7952015-10-30 11:14:30 -060025 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060026 */
27
28#ifndef VKRENDERFRAMEWORK_H
29#define VKRENDERFRAMEWORK_H
30
Michael Lentinee6c6dd52015-11-03 16:20:30 -080031#ifdef ANDROID
32#include "vktestframeworkandroid.h"
33class VkImageObj;
34#else
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060035#include "vktestframework.h"
Michael Lentinee6c6dd52015-11-03 16:20:30 -080036#endif
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060037
Tony Barbourdc14f892016-04-11 11:39:43 -060038#include <map>
Michael Lentinee6c6dd52015-11-03 16:20:30 -080039#include <vector>
40
41using namespace std;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060042
Karl Schultz99e9d1d2016-02-02 17:17:23 -070043class VkDeviceObj : public vk_testing::Device {
44 public:
Tony Barbour8205d902015-04-16 15:59:00 -060045 VkDeviceObj(uint32_t id, VkPhysicalDevice obj);
Courtney Goeltzenleuchter61414de2015-07-07 11:47:33 -060046 VkDeviceObj(uint32_t id, VkPhysicalDevice obj,
47 std::vector<const char *> &layers,
48 std::vector<const char *> &extension_names);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060049
Chia-I Wua2636292015-07-03 10:41:20 +080050 VkDevice device() { return handle(); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060051 void get_device_queue();
52
Karl Schultz99e9d1d2016-02-02 17:17:23 -070053 uint32_t id;
54 VkPhysicalDeviceProperties props;
55 const VkQueueFamilyProperties *queue_props;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060056
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060057 VkQueue m_queue;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060058};
59
Tony Barbour1490c912015-07-28 10:17:20 -060060class VkCommandBufferObj;
Tony Barbourc729ba82016-04-05 11:44:03 -060061class VkDepthStencilObj;
Tony Barbour1490c912015-07-28 10:17:20 -060062
Karl Schultz99e9d1d2016-02-02 17:17:23 -070063class VkRenderFramework : public VkTestFramework {
64 public:
Tony Barbour01999182015-04-09 12:58:51 -060065 VkRenderFramework();
66 ~VkRenderFramework();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060067
Karl Schultz99e9d1d2016-02-02 17:17:23 -070068 VkDevice device() { return m_device->device(); }
69 VkPhysicalDevice gpu() { return objs[0]; }
70 VkRenderPass renderPass() { return m_renderPass; }
71 VkFramebuffer framebuffer() { return m_framebuffer; }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060072 void InitViewport(float width, float height);
73 void InitViewport();
74 void InitRenderTarget();
75 void InitRenderTarget(uint32_t targets);
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -060076 void InitRenderTarget(VkImageView *dsBinding);
77 void InitRenderTarget(uint32_t targets, VkImageView *dsBinding);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060078 void InitFramework();
Karl Schultz99e9d1d2016-02-02 17:17:23 -070079 void InitFramework(std::vector<const char *> instance_layer_names,
80 std::vector<const char *> device_layer_names,
81 std::vector<const char *> instance_extension_names,
82 std::vector<const char *> device_extension_names,
83 PFN_vkDebugReportCallbackEXT = NULL,
84 void *userData = NULL);
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -060085
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060086 void ShutdownFramework();
87 void InitState();
88
Karl Schultz99e9d1d2016-02-02 17:17:23 -070089 const VkRenderPassBeginInfo &renderPassBeginInfo() const {
90 return m_renderPassBeginInfo;
91 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060092
Karl Schultz99e9d1d2016-02-02 17:17:23 -070093 protected:
94 VkApplicationInfo app_info;
95 VkInstance inst;
96 VkPhysicalDevice objs[16];
97 uint32_t gpu_count;
98 VkDeviceObj *m_device;
99 VkCommandPool m_commandPool;
100 VkCommandBufferObj *m_commandBuffer;
101 VkRenderPass m_renderPass;
102 VkFramebuffer m_framebuffer;
103 std::vector<VkViewport> m_viewports;
104 std::vector<VkRect2D> m_scissors;
105 float m_lineWidth;
106 float m_depthBiasConstantFactor;
107 float m_depthBiasClamp;
108 float m_depthBiasSlopeFactor;
109 float m_blendConstants[4];
110 float m_minDepthBounds;
111 float m_maxDepthBounds;
112 uint32_t m_compareMask;
113 uint32_t m_writeMask;
114 uint32_t m_reference;
115 std::vector<VkClearValue> m_renderPassClearValues;
116 VkRenderPassBeginInfo m_renderPassBeginInfo;
117 vector<VkImageObj *> m_renderTargets;
118 float m_width, m_height;
119 VkFormat m_render_target_fmt;
120 VkFormat m_depth_stencil_fmt;
121 VkClearColorValue m_clear_color;
122 bool m_clear_via_load_op;
123 float m_depth_clear_color;
124 uint32_t m_stencil_clear_color;
125 VkDepthStencilObj *m_depthStencil;
126 PFN_vkCreateDebugReportCallbackEXT m_CreateDebugReportCallback;
Courtney Goeltzenleuchter895819d2015-12-15 09:25:15 -0700127 PFN_vkDestroyDebugReportCallbackEXT m_DestroyDebugReportCallback;
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700128 PFN_vkDebugReportMessageEXT m_DebugReportMessage;
129 VkDebugReportCallbackEXT m_globalMsgCallback;
130 VkDebugReportCallbackEXT m_devMsgCallback;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600131
132 /*
133 * SetUp and TearDown are called by the Google Test framework
134 * to initialize a test framework based on this class.
135 */
136 virtual void SetUp() {
137 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
138 this->app_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +0800139 this->app_info.pApplicationName = "base";
140 this->app_info.applicationVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600141 this->app_info.pEngineName = "unittest";
142 this->app_info.engineVersion = 1;
Jon Ashburnd3995c92016-03-22 13:57:46 -0600143 this->app_info.apiVersion = VK_API_VERSION_1_0;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600144
145 InitFramework();
146 }
147
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700148 virtual void TearDown() { ShutdownFramework(); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600149};
150
Tony Barbour01999182015-04-09 12:58:51 -0600151class VkDescriptorSetObj;
152class VkIndexBufferObj;
153class VkConstantBufferObj;
154class VkPipelineObj;
155class VkDescriptorSetObj;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600156
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700157class VkCommandBufferObj : public vk_testing::CommandBuffer {
158 public:
Chia-I Wu1f851912015-10-27 18:04:07 +0800159 VkCommandBufferObj(VkDeviceObj *device, VkCommandPool pool);
160 VkCommandBuffer GetBufferHandle();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600161 VkResult BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800162 VkResult BeginCommandBuffer(VkCommandBufferBeginInfo *pInfo);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600163 VkResult EndCommandBuffer();
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700164 void PipelineBarrier(VkPipelineStageFlags src_stages,
165 VkPipelineStageFlags dest_stages,
166 VkDependencyFlags dependencyFlags,
167 uint32_t memoryBarrierCount,
168 const VkMemoryBarrier *pMemoryBarriers,
169 uint32_t bufferMemoryBarrierCount,
170 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
171 uint32_t imageMemoryBarrierCount,
172 const VkImageMemoryBarrier *pImageMemoryBarriers);
Tony Barbour01999182015-04-09 12:58:51 -0600173 void AddRenderTarget(VkImageObj *renderTarget);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600174 void AddDepthStencil();
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700175 void ClearAllBuffers(VkClearColorValue clear_color, float depth_clear_color,
176 uint32_t stencil_clear_color,
177 VkDepthStencilObj *depthStencilObj);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600178 void PrepareAttachments();
Tony Barbour01999182015-04-09 12:58:51 -0600179 void BindPipeline(VkPipelineObj &pipeline);
180 void BindDescriptorSet(VkDescriptorSetObj &descriptorSet);
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700181 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer,
182 VkDeviceSize offset, uint32_t binding);
Cody Northrop1684adb2015-08-05 11:15:02 -0600183 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset);
Chia-I Wuc278df82015-07-07 11:50:03 +0800184 void BeginRenderPass(const VkRenderPassBeginInfo &info);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800185 void EndRenderPass();
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700186 void FillBuffer(VkBuffer buffer, VkDeviceSize offset,
187 VkDeviceSize fill_size, uint32_t data);
188 void Draw(uint32_t vertexCount, uint32_t instanceCount,
189 uint32_t firstVertex, uint32_t firstInstance);
190 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount,
191 uint32_t firstIndex, int32_t vertexOffset,
192 uint32_t firstInstance);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600193 void QueueCommandBuffer();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600194 void QueueCommandBuffer(VkFence fence);
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700195 void SetViewport(uint32_t firstViewport, uint32_t viewportCount,
196 const VkViewport *pViewports);
197 void SetScissor(uint32_t firstScissor, uint32_t scissorCount,
198 const VkRect2D *pScissors);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600199 void SetLineWidth(float lineWidth);
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700200 void SetDepthBias(float depthBiasConstantFactor, float depthBiasClamp,
201 float depthBiasSlopeFactor);
Chia-I Wu7e470702015-10-26 17:24:52 +0800202 void SetBlendConstants(const float blendConstants[4]);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600203 void SetDepthBounds(float minDepthBounds, float maxDepthBounds);
Chia-I Wuc51b1212015-10-27 19:25:11 +0800204 void SetStencilReadMask(VkStencilFaceFlags faceMask, uint32_t compareMask);
205 void SetStencilWriteMask(VkStencilFaceFlags faceMask, uint32_t writeMask);
206 void SetStencilReference(VkStencilFaceFlags faceMask, uint32_t reference);
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700207 void UpdateBuffer(VkBuffer buffer, VkDeviceSize dstOffset,
208 VkDeviceSize dataSize, const uint32_t *pData);
209 void CopyImage(VkImage srcImage, VkImageLayout srcImageLayout,
210 VkImage dstImage, VkImageLayout dstImageLayout,
211 uint32_t regionCount, const VkImageCopy *pRegions);
212 void ResolveImage(VkImage srcImage, VkImageLayout srcImageLayout,
213 VkImage dstImage, VkImageLayout dstImageLayout,
214 uint32_t regionCount, const VkImageResolve *pRegions);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600215
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700216 protected:
217 VkDeviceObj *m_device;
218 vector<VkImageObj *> m_renderTargets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600219};
220
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700221class VkConstantBufferObj : public vk_testing::Buffer {
222 public:
Tony Barbour01999182015-04-09 12:58:51 -0600223 VkConstantBufferObj(VkDeviceObj *device);
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700224 VkConstantBufferObj(VkDeviceObj *device, int constantCount,
225 int constantSize, const void *data);
Tony Barbour01999182015-04-09 12:58:51 -0600226 ~VkConstantBufferObj();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600227 void BufferMemoryBarrier(
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700228 VkFlags srcAccessMask = VK_ACCESS_HOST_WRITE_BIT |
229 VK_ACCESS_SHADER_WRITE_BIT |
230 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
231 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
232 VK_ACCESS_TRANSFER_WRITE_BIT,
233 VkFlags dstAccessMask = VK_ACCESS_HOST_READ_BIT |
234 VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
235 VK_ACCESS_INDEX_READ_BIT |
236 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
237 VK_ACCESS_UNIFORM_READ_BIT |
238 VK_ACCESS_SHADER_READ_BIT |
239 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
240 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
241 VK_ACCESS_MEMORY_READ_BIT);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600242
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700243 void Bind(VkCommandBuffer commandBuffer, VkDeviceSize offset,
244 uint32_t binding);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600245
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700246 VkDescriptorBufferInfo m_descriptorBufferInfo;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600247
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700248 protected:
249 VkDeviceObj *m_device;
250 vk_testing::BufferView m_bufferView;
251 int m_numVertices;
252 int m_stride;
253 vk_testing::CommandPool *m_commandPool;
254 VkCommandBufferObj *m_commandBuffer;
255 vk_testing::Fence m_fence;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600256};
257
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700258class VkIndexBufferObj : public VkConstantBufferObj {
259 public:
Tony Barbour01999182015-04-09 12:58:51 -0600260 VkIndexBufferObj(VkDeviceObj *device);
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700261 void CreateAndInitBuffer(int numIndexes, VkIndexType dataFormat,
262 const void *data);
Chia-I Wu1f851912015-10-27 18:04:07 +0800263 void Bind(VkCommandBuffer commandBuffer, VkDeviceSize offset);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600264 VkIndexType GetIndexType();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600265
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700266 protected:
267 VkIndexType m_indexType;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600268};
269
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700270class VkImageObj : public vk_testing::Image {
271 public:
Tony Barbour01999182015-04-09 12:58:51 -0600272 VkImageObj(VkDeviceObj *dev);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600273 bool IsCompatible(VkFlags usage, VkFlags features);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600274
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700275 public:
276 void init(uint32_t w, uint32_t h, VkFormat fmt, VkFlags usage,
277 VkImageTiling tiling = VK_IMAGE_TILING_LINEAR,
278 VkMemoryPropertyFlags reqs = 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600279
280 // void clear( CommandBuffer*, uint32_t[4] );
281
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700282 void layout(VkImageLayout layout) {
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -0600283 m_descriptorImageInfo.imageLayout = layout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600284 }
285
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700286 VkDeviceMemory memory() const { return Image::memory().handle(); }
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800287
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700288 void *MapMemory() { return Image::memory().map(); }
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800289
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700290 void UnmapMemory() { Image::memory().unmap(); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600291
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700292 void ImageMemoryBarrier(VkCommandBufferObj *cmd, VkImageAspectFlags aspect,
293 VkFlags output_mask, VkFlags input_mask,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600294 VkImageLayout image_layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600295
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600296 VkResult CopyImage(VkImageObj &src_image);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600297
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700298 VkImage image() const { return handle(); }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600299
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700300 VkImageView targetView(VkFormat format) {
301 if (!m_targetView.initialized()) {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -0600302 VkImageViewCreateInfo createView = {};
303 createView.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
304 createView.image = handle();
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700305 createView.viewType = VK_IMAGE_VIEW_TYPE_2D;
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -0600306 createView.format = format;
Chia-I Wu4291d882015-10-27 19:00:15 +0800307 createView.components.r = VK_COMPONENT_SWIZZLE_R;
308 createView.components.g = VK_COMPONENT_SWIZZLE_G;
309 createView.components.b = VK_COMPONENT_SWIZZLE_B;
310 createView.components.a = VK_COMPONENT_SWIZZLE_A;
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700311 createView.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0,
312 1};
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -0600313 createView.flags = 0;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600314 m_targetView.init(*m_device, createView);
315 }
Chia-I Wu76ab1ff2015-07-03 11:49:42 +0800316 return m_targetView.handle();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600317 }
318
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700319 void SetLayout(VkCommandBufferObj *cmd_buf, VkImageAspectFlagBits aspect,
320 VkImageLayout image_layout);
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -0600321 void SetLayout(VkImageAspectFlagBits aspect, VkImageLayout image_layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600322
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700323 VkImageLayout layout() const { return m_descriptorImageInfo.imageLayout; }
324 uint32_t width() const { return extent().width; }
325 uint32_t height() const { return extent().height; }
326 VkDeviceObj *device() const { return m_device; }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600327
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700328 protected:
329 VkDeviceObj *m_device;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600330
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700331 vk_testing::ImageView m_targetView;
332 VkDescriptorImageInfo m_descriptorImageInfo;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600333};
334
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700335class VkTextureObj : public VkImageObj {
336 public:
Tony Barbour01999182015-04-09 12:58:51 -0600337 VkTextureObj(VkDeviceObj *device, uint32_t *colors = NULL);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600338
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700339 VkDescriptorImageInfo m_imageInfo;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600340
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700341 protected:
342 VkDeviceObj *m_device;
343 vk_testing::ImageView m_textureView;
344 VkDeviceSize m_rowPitch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600345};
346
Tony Barbourc729ba82016-04-05 11:44:03 -0600347class VkDepthStencilObj : public VkImageObj {
348 public:
349 VkDepthStencilObj(VkDeviceObj *device);
350 void Init(VkDeviceObj *device, int32_t width, int32_t height,
351 VkFormat format);
352 bool Initialized();
353 VkImageView *BindInfo();
354
355 protected:
356 VkDeviceObj *m_device;
357 bool m_initialized;
358 vk_testing::ImageView m_imageView;
359 VkFormat m_depth_stencil_fmt;
360 VkImageView m_attachmentBindInfo;
361};
362
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700363class VkSamplerObj : public vk_testing::Sampler {
364 public:
Tony Barbour01999182015-04-09 12:58:51 -0600365 VkSamplerObj(VkDeviceObj *device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600366
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700367 protected:
368 VkDeviceObj *m_device;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600369};
370
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700371class VkDescriptorSetObj : public vk_testing::DescriptorPool {
372 public:
Tony Barbour01999182015-04-09 12:58:51 -0600373 VkDescriptorSetObj(VkDeviceObj *device);
374 ~VkDescriptorSetObj();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600375
376 int AppendDummy();
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700377 int AppendBuffer(VkDescriptorType type,
378 VkConstantBufferObj &constantBuffer);
379 int AppendSamplerTexture(VkSamplerObj *sampler, VkTextureObj *texture);
Chia-I Wu1f851912015-10-27 18:04:07 +0800380 void CreateVKDescriptorSet(VkCommandBufferObj *commandBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600381
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600382 VkDescriptorSet GetDescriptorSetHandle() const;
Mark Lobodzinski556f7212015-04-17 14:11:39 -0500383 VkPipelineLayout GetPipelineLayout() const;
Tony Barbour61a1cd62016-03-02 15:35:27 -0700384 int GetTypeCounts() {return m_type_counts.size();}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600385
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700386 protected:
387 VkDeviceObj *m_device;
Tony Barbourdc14f892016-04-11 11:39:43 -0600388 std::vector<VkDescriptorSetLayoutBinding> m_layout_bindings;
389 std::map<VkDescriptorType, int> m_type_counts;
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700390 int m_nextSlot;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600391
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700392 vector<VkDescriptorImageInfo> m_imageSamplerDescriptors;
393 vector<VkWriteDescriptorSet> m_writes;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600394
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700395 vk_testing::DescriptorSetLayout m_layout;
396 vk_testing::PipelineLayout m_pipeline_layout;
Tony Barbour61a1cd62016-03-02 15:35:27 -0700397 vk_testing::DescriptorSet *m_set = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600398};
399
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700400class VkShaderObj : public vk_testing::ShaderModule {
401 public:
402 VkShaderObj(VkDeviceObj *device, const char *shaderText,
Chris Forbes57e10d72015-12-30 11:49:04 +1300403 VkShaderStageFlagBits stage, VkRenderFramework *framework,
404 char const *name = "main");
Chia-I Wu062ad152015-10-31 00:31:16 +0800405 VkPipelineShaderStageCreateInfo GetStageCreateInfo() const;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600406
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700407 protected:
408 VkPipelineShaderStageCreateInfo stage_info;
409 VkShaderStageFlagBits m_stage;
Chris Forbes57e10d72015-12-30 11:49:04 +1300410 char const *m_name;
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700411 VkDeviceObj *m_device;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600412};
413
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700414class VkPipelineObj : public vk_testing::Pipeline {
415 public:
Tony Barbour01999182015-04-09 12:58:51 -0600416 VkPipelineObj(VkDeviceObj *device);
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700417 void AddShader(VkShaderObj *shaderObj);
418 void AddVertexInputAttribs(VkVertexInputAttributeDescription *vi_attrib,
419 int count);
420 void AddVertexInputBindings(VkVertexInputBindingDescription *vi_binding,
421 int count);
422 void AddColorAttachment(uint32_t binding,
423 const VkPipelineColorBlendAttachmentState *att);
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600424 void MakeDynamic(VkDynamicState state);
Chia-I Wuc278df82015-07-07 11:50:03 +0800425
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700426 void AddColorAttachment() {
Tony Barboure307f582015-07-10 15:29:03 -0600427 VkPipelineColorBlendAttachmentState att = {};
Chia-I Wuc278df82015-07-07 11:50:03 +0800428 att.blendEnable = VK_FALSE;
Chia-I Wuc51b1212015-10-27 19:25:11 +0800429 att.colorWriteMask = 0xf;
Chia-I Wuc278df82015-07-07 11:50:03 +0800430 AddColorAttachment(0, &att);
431 }
432
Tobin Ehlis3d3e06b2016-03-28 11:18:19 -0600433 void SetDepthStencil(const VkPipelineDepthStencilStateCreateInfo *);
434 void SetMSAA(const VkPipelineMultisampleStateCreateInfo *ms_state);
Chris Forbes8c13a2e2016-04-04 19:15:00 +1200435 void SetInputAssembly(const VkPipelineInputAssemblyStateCreateInfo *ia_state);
436 void SetRasterization(const VkPipelineRasterizationStateCreateInfo *rs_state);
437 void SetTessellation(const VkPipelineTessellationStateCreateInfo *te_state);
Tobin Ehlis3d3e06b2016-03-28 11:18:19 -0600438 void SetViewport(const vector<VkViewport> viewports);
439 void SetScissor(const vector<VkRect2D> scissors);
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700440 VkResult CreateVKPipeline(VkPipelineLayout layout,
441 VkRenderPass render_pass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600442
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700443 protected:
444 VkPipelineVertexInputStateCreateInfo m_vi_state;
445 VkPipelineInputAssemblyStateCreateInfo m_ia_state;
446 VkPipelineRasterizationStateCreateInfo m_rs_state;
447 VkPipelineColorBlendStateCreateInfo m_cb_state;
448 VkPipelineDepthStencilStateCreateInfo m_ds_state;
449 VkPipelineViewportStateCreateInfo m_vp_state;
450 VkPipelineMultisampleStateCreateInfo m_ms_state;
Chris Forbes8c13a2e2016-04-04 19:15:00 +1200451 VkPipelineTessellationStateCreateInfo m_te_state;
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700452 vector<VkDynamicState> m_dynamic_state_enables;
453 vector<VkViewport> m_viewports;
454 vector<VkRect2D> m_scissors;
455 VkDeviceObj *m_device;
456 vector<VkShaderObj *> m_shaderObjs;
457 vector<int> m_vertexBufferBindings;
458 vector<VkPipelineColorBlendAttachmentState> m_colorAttachments;
459 int m_vertexBufferCount;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600460};
461
462#endif // VKRENDERFRAMEWORK_H