blob: 81af77434170f0bea0a36c086e246ce38ff19805 [file] [log] [blame]
Tony Barbourd04e8df2015-11-17 10:02:56 -07001//
2// Copyright (C) 2015 Valve Corporation
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included
12// in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21//
22// Author: Chia-I Wu <olvaffe@gmail.com>
23// Author: Chris Forbes <chrisf@ijw.co.nz>
24// Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
25// Author: Mark Lobodzinski <mark@lunarg.com>
26// Author: Mike Stroyan <mike@LunarG.com>
27// Author: Tobin Ehlis <tobin@lunarg.com>
28// Author: Tony Barbour <tony@LunarG.com>
29
30
David Pinedo329ca9e2015-11-06 12:54:48 -070031#include <vulkan/vulkan.h>
David Pinedoa31fe0b2015-11-24 09:00:24 -070032#include "vulkan/vk_lunarg_debug_report.h"
Courtney Goeltzenleuchter0abdb662015-10-07 13:28:58 -060033#include "test_common.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060034#include "vkrenderframework.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060035#include "vk_layer_config.h"
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -060036#include "../icd/common/icd-spv.h"
Tony Barbour30486ea2015-04-07 13:44:53 -060037
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050038#define GLM_FORCE_RADIANS
39#include "glm/glm.hpp"
40#include <glm/gtc/matrix_transform.hpp>
41
Tobin Ehlis57e6a612015-05-26 16:11:58 -060042#define MEM_TRACKER_TESTS 1
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -060043
Tobin Ehlis57e6a612015-05-26 16:11:58 -060044#define OBJ_TRACKER_TESTS 1
45#define DRAW_STATE_TESTS 1
46#define THREADING_TESTS 1
Chris Forbes5af3bf22015-05-25 11:13:08 +120047#define SHADER_CHECKER_TESTS 1
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -060048#define DEVICE_LIMITS_TESTS 1
Tobin Ehlis342b9bf2015-09-22 10:11:37 -060049#define IMAGE_TESTS 1
Tobin Ehlis57e6a612015-05-26 16:11:58 -060050
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050051//--------------------------------------------------------------------------------------
52// Mesh and VertexFormat Data
53//--------------------------------------------------------------------------------------
54struct Vertex
55{
56 float posX, posY, posZ, posW; // Position data
57 float r, g, b, a; // Color
58};
59
60#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
61
62typedef enum _BsoFailSelect {
63 BsoFailNone = 0x00000000,
Cody Northrope4bc6942015-08-26 10:01:32 -060064 BsoFailLineWidth = 0x00000001,
65 BsoFailDepthBias = 0x00000002,
Cody Northropf5bd2252015-08-17 11:10:49 -060066 BsoFailViewport = 0x00000004,
Tobin Ehlisf6cb4672015-09-29 08:18:34 -060067 BsoFailScissor = 0x00000008,
68 BsoFailBlend = 0x00000010,
69 BsoFailDepthBounds = 0x00000020,
70 BsoFailStencilReadMask = 0x00000040,
71 BsoFailStencilWriteMask = 0x00000080,
72 BsoFailStencilReference = 0x00000100,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050073} BsoFailSelect;
74
75struct vktriangle_vs_uniform {
76 // Must start with MVP
77 float mvp[4][4];
78 float position[3][4];
79 float color[3][4];
80};
81
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050082static const char bindStateVertShaderText[] =
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050083 "#version 130\n"
84 "vec2 vertices[3];\n"
85 "void main() {\n"
86 " vertices[0] = vec2(-1.0, -1.0);\n"
87 " vertices[1] = vec2( 1.0, -1.0);\n"
88 " vertices[2] = vec2( 0.0, 1.0);\n"
89 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
90 "}\n";
91
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050092static const char bindStateFragShaderText[] =
Cody Northrop74a2d2c2015-06-16 17:32:04 -060093 "#version 140\n"
94 "#extension GL_ARB_separate_shader_objects: require\n"
95 "#extension GL_ARB_shading_language_420pack: require\n"
96 "\n"
97 "layout(location = 0) out vec4 uFragColor;\n"
98 "void main(){\n"
99 " uFragColor = vec4(0,1,0,1);\n"
100 "}\n";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500101
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600102static VkBool32 myDbgFunc(
Tony Barboure84a8d62015-07-10 14:10:27 -0600103 VkFlags msgFlags,
104 VkDbgObjectType objType,
105 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600106 size_t location,
107 int32_t msgCode,
108 const char* pLayerPrefix,
109 const char* pMsg,
110 void* pUserData);
Tony Barbour30486ea2015-04-07 13:44:53 -0600111
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600112// ********************************************************
113// ErrorMonitor Usage:
114//
115// Call SetDesiredFailureMsg with a string to be compared against all
116// encountered log messages. Passing NULL will match all log messages.
117// logMsg will return true for skipCall only if msg is matched or NULL.
118//
119// Call DesiredMsgFound to determine if the desired failure message
120// was encountered.
121
Tony Barbour30486ea2015-04-07 13:44:53 -0600122class ErrorMonitor {
123public:
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600124 ErrorMonitor()
Tony Barbour30486ea2015-04-07 13:44:53 -0600125 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600126 test_platform_thread_create_mutex(&m_mutex);
127 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600128 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600129 m_bailout = NULL;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600130 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -0600131 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600132
133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -0600134 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600135 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600136 m_desiredMsg.clear();
137 m_failureMsg.clear();
138 m_otherMsgs.clear();
139 m_desiredMsg = msgString;
140 m_msgFound = VK_FALSE;
141 m_msgFlags = msgFlags;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600142 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -0600143 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600144
145 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -0600146 {
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600147 VkBool32 result = VK_FALSE;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600148 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600149 if (m_bailout != NULL) {
150 *m_bailout = true;
151 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600152 string errorString(msgString);
153 if (msgFlags & m_msgFlags) {
154 if (errorString.find(m_desiredMsg) != string::npos) {
155 m_failureMsg = errorString;
156 m_msgFound = VK_TRUE;
157 result = VK_TRUE;
158 } else {
159 m_otherMsgs.push_back(errorString);
160 }
161 }
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600162 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600163 return result;
Mike Stroyan09aae812015-05-12 16:00:45 -0600164 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600165
166 vector<string> GetOtherFailureMsgs(void)
167 {
168 return m_otherMsgs;
169 }
170
171 string GetFailureMsg(void)
172 {
173 return m_failureMsg;
174 }
175
176 VkBool32 DesiredMsgFound(void)
177 {
178 return m_msgFound;
179 }
180
Mike Stroyan09aae812015-05-12 16:00:45 -0600181 void SetBailout(bool *bailout)
182 {
183 m_bailout = bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600184 }
185
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600186 void DumpFailureMsgs(void)
187 {
188 vector<string> otherMsgs = GetOtherFailureMsgs();
189 cout << "Other error messages logged for this test were:" << endl;
190 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
191 cout << " " << *iter << endl;
192 }
193 }
194
Tony Barbour30486ea2015-04-07 13:44:53 -0600195private:
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600196 VkFlags m_msgFlags;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600197 string m_desiredMsg;
198 string m_failureMsg;
199 vector<string> m_otherMsgs;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600200 test_platform_thread_mutex m_mutex;
201 bool* m_bailout;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600202 VkBool32 m_msgFound;
Tony Barbour30486ea2015-04-07 13:44:53 -0600203};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500204
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600205static VkBool32 myDbgFunc(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600206 VkFlags msgFlags,
Tony Barboure84a8d62015-07-10 14:10:27 -0600207 VkDbgObjectType objType,
208 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600209 size_t location,
210 int32_t msgCode,
211 const char* pLayerPrefix,
212 const char* pMsg,
213 void* pUserData)
Tony Barbour30486ea2015-04-07 13:44:53 -0600214{
Tony Barbour192f02b2015-11-06 14:21:31 -0700215 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_PERF_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour8508b8e2015-04-09 10:48:04 -0600216 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600217 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour8508b8e2015-04-09 10:48:04 -0600218 }
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600219 return false;
Tony Barbour30486ea2015-04-07 13:44:53 -0600220}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500221
Tony Barbour01999182015-04-09 12:58:51 -0600222class VkLayerTest : public VkRenderFramework
Tony Barbour30486ea2015-04-07 13:44:53 -0600223{
224public:
Chia-I Wu1f851912015-10-27 18:04:07 +0800225 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
226 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500227 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
Chia-I Wu1f851912015-10-27 18:04:07 +0800228 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbour1490c912015-07-28 10:17:20 -0600229 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
Chia-I Wu1f851912015-10-27 18:04:07 +0800230 { GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600231
Tony Barbour1490c912015-07-28 10:17:20 -0600232 /* Convenience functions that use built-in command buffer */
Chia-I Wu1f851912015-10-27 18:04:07 +0800233 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
234 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600235 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
Chia-I Wu1f851912015-10-27 18:04:07 +0800236 { m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance); }
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600237 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
Chia-I Wu1f851912015-10-27 18:04:07 +0800238 { m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); }
239 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
240 void QueueCommandBuffer(const VkFence& fence) { m_commandBuffer->QueueCommandBuffer(fence); }
Tony Barbour1490c912015-07-28 10:17:20 -0600241 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
Chia-I Wu1f851912015-10-27 18:04:07 +0800242 { m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
Tony Barbour1490c912015-07-28 10:17:20 -0600243 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
Chia-I Wu1f851912015-10-27 18:04:07 +0800244 { m_commandBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600245protected:
Tony Barbour01999182015-04-09 12:58:51 -0600246 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600247
248 virtual void SetUp() {
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600249 std::vector<const char *> instance_layer_names;
250 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600251 std::vector<const char *> instance_extension_names;
252 std::vector<const char *> device_extension_names;
Tony Barbour950ebc02015-04-23 12:55:36 -0600253
Courtney Goeltzenleuchter846298c2015-07-30 11:32:46 -0600254 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600255 /*
256 * Since CreateDbgMsgCallback is an instance level extension call
257 * any extension / layer that utilizes that feature also needs
258 * to be enabled at create instance time.
259 */
Chia-I Wu1f851912015-10-27 18:04:07 +0800260 // Use Threading layer first to protect others from ThreadCommandBufferCollision test
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600261 instance_layer_names.push_back("Threading");
262 instance_layer_names.push_back("ObjectTracker");
263 instance_layer_names.push_back("MemTracker");
264 instance_layer_names.push_back("DrawState");
265 instance_layer_names.push_back("ShaderChecker");
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600266 instance_layer_names.push_back("DeviceLimits");
Tobin Ehlis342b9bf2015-09-22 10:11:37 -0600267 instance_layer_names.push_back("Image");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600268
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600269 device_layer_names.push_back("Threading");
270 device_layer_names.push_back("ObjectTracker");
271 device_layer_names.push_back("MemTracker");
272 device_layer_names.push_back("DrawState");
273 device_layer_names.push_back("ShaderChecker");
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600274 device_layer_names.push_back("DeviceLimits");
Tobin Ehlis342b9bf2015-09-22 10:11:37 -0600275 device_layer_names.push_back("Image");
Tony Barbour30486ea2015-04-07 13:44:53 -0600276
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600277 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -0600278 this->app_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +0800279 this->app_info.pApplicationName = "layer_tests";
280 this->app_info.applicationVersion = 1;
Tony Barbour30486ea2015-04-07 13:44:53 -0600281 this->app_info.pEngineName = "unittest";
282 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600283 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -0600284
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600285 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600286 InitFramework(instance_layer_names, device_layer_names,
287 instance_extension_names, device_extension_names,
288 myDbgFunc, m_errorMonitor);
Tony Barbour30486ea2015-04-07 13:44:53 -0600289 }
290
291 virtual void TearDown() {
292 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600293 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600294 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600295 }
296};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500297
Chia-I Wu1f851912015-10-27 18:04:07 +0800298VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600299{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600300 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600301
Chia-I Wu1f851912015-10-27 18:04:07 +0800302 result = commandBuffer.BeginCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600303
304 /*
305 * For render test all drawing happens in a single render pass
306 * on a single command buffer.
307 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200308 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800309 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour30486ea2015-04-07 13:44:53 -0600310 }
311
312 return result;
313}
314
Chia-I Wu1f851912015-10-27 18:04:07 +0800315VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600316{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600317 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600318
Chris Forbesfe133ef2015-06-16 14:05:59 +1200319 if (renderPass()) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800320 commandBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200321 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600322
Chia-I Wu1f851912015-10-27 18:04:07 +0800323 result = commandBuffer.EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600324
325 return result;
326}
327
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500328void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
329{
330 // Create identity matrix
331 int i;
332 struct vktriangle_vs_uniform data;
333
334 glm::mat4 Projection = glm::mat4(1.0f);
335 glm::mat4 View = glm::mat4(1.0f);
336 glm::mat4 Model = glm::mat4(1.0f);
337 glm::mat4 MVP = Projection * View * Model;
338 const int matrixSize = sizeof(MVP);
339 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
340
341 memcpy(&data.mvp, &MVP[0][0], matrixSize);
342
343 static const Vertex tri_data[] =
344 {
345 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
346 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
347 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
348 };
349
350 for (i=0; i<3; i++) {
351 data.position[i][0] = tri_data[i].posX;
352 data.position[i][1] = tri_data[i].posY;
353 data.position[i][2] = tri_data[i].posZ;
354 data.position[i][3] = tri_data[i].posW;
355 data.color[i][0] = tri_data[i].r;
356 data.color[i][1] = tri_data[i].g;
357 data.color[i][2] = tri_data[i].b;
358 data.color[i][3] = tri_data[i].a;
359 }
360
361 ASSERT_NO_FATAL_FAILURE(InitState());
362 ASSERT_NO_FATAL_FAILURE(InitViewport());
363
364 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
365
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600366 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
367 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500368
369 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800370 pipelineobj.AddColorAttachment();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500371 pipelineobj.AddShader(&vs);
372 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600373 if (failMask & BsoFailLineWidth) {
374 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
375 }
376 if (failMask & BsoFailDepthBias) {
377 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
378 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600379 // Viewport and scissors must stay in synch or other errors will occur than the ones we want
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600380 if (failMask & BsoFailViewport) {
381 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600382 m_viewports.clear();
383 m_scissors.clear();
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600384 }
385 if (failMask & BsoFailScissor) {
386 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600387 m_scissors.clear();
388 m_viewports.clear();
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600389 }
390 if (failMask & BsoFailBlend) {
391 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
392 }
393 if (failMask & BsoFailDepthBounds) {
394 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
395 }
396 if (failMask & BsoFailStencilReadMask) {
397 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
398 }
399 if (failMask & BsoFailStencilWriteMask) {
400 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
401 }
402 if (failMask & BsoFailStencilReference) {
403 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
404 }
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500405
406 VkDescriptorSetObj descriptorSet(m_device);
407 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
408
409 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600410 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500411
Tony Barbour1490c912015-07-28 10:17:20 -0600412 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500413
414 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600415 Draw(3, 1, 0, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500416
417 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600418 EndCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500419
Tony Barbour1490c912015-07-28 10:17:20 -0600420 QueueCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500421}
422
Chia-I Wu1f851912015-10-27 18:04:07 +0800423void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500424{
425 if (m_depthStencil->Initialized()) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800426 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500427 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +0800428 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500429 }
430
Chia-I Wu1f851912015-10-27 18:04:07 +0800431 commandBuffer->PrepareAttachments();
Cody Northrop2605cb02015-08-18 15:21:16 -0600432 // Make sure depthWriteEnable is set so that Depth fail test will work correctly
433 // Make sure stencilTestEnable is set so that Stencil fail test will work correctly
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600434 VkStencilOpState stencil = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +0800435 stencil.failOp = VK_STENCIL_OP_KEEP;
436 stencil.passOp = VK_STENCIL_OP_KEEP;
437 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
438 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600439
440 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
441 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600442 ds_ci.pNext = NULL;
443 ds_ci.depthTestEnable = VK_FALSE;
444 ds_ci.depthWriteEnable = VK_TRUE;
445 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
446 ds_ci.depthBoundsTestEnable = VK_FALSE;
447 ds_ci.stencilTestEnable = VK_TRUE;
448 ds_ci.front = stencil;
449 ds_ci.back = stencil;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600450
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600451 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600452 pipelineobj.SetViewport(m_viewports);
453 pipelineobj.SetScissor(m_scissors);
Chia-I Wu1f851912015-10-27 18:04:07 +0800454 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Cody Northropccfa96d2015-08-27 10:20:35 -0600455 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
456 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +0800457 commandBuffer->BindPipeline(pipelineobj);
458 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500459}
460
461// ********************************************************************************************************************
462// ********************************************************************************************************************
463// ********************************************************************************************************************
464// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600465#if MEM_TRACKER_TESTS
Chia-I Wu1f851912015-10-27 18:04:07 +0800466TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinski81078192015-05-19 10:28:29 -0500467{
468 vk_testing::Fence testFence;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500469 VkFenceCreateInfo fenceInfo = {};
470 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
471 fenceInfo.pNext = NULL;
472 fenceInfo.flags = 0;
473
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600474 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Resetting CB");
475
Mark Lobodzinski81078192015-05-19 10:28:29 -0500476 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barboure389b882015-07-20 13:00:10 -0600477
478 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
479 vk_testing::Buffer buffer;
480 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500481
Tony Barbour1490c912015-07-28 10:17:20 -0600482 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800483 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbour1490c912015-07-28 10:17:20 -0600484 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500485
486 testFence.init(*m_device, fenceInfo);
487
488 // Bypass framework since it does the waits automatically
489 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600490 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +0800491 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
492 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800493 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600494 submit_info.pWaitSemaphores = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800495 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +0800496 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +0800497 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600498 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600499
500 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500501 ASSERT_VK_SUCCESS( err );
502
Mark Lobodzinski81078192015-05-19 10:28:29 -0500503 // Introduce failure by calling begin again before checking fence
Chia-I Wu1f851912015-10-27 18:04:07 +0800504 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500505
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600506 if (!m_errorMonitor->DesiredMsgFound()) {
507 FAIL() << "Did not receive Error 'Resetting CB (0xaddress) before it has completed. You must check CB flag before.'";
508 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500509 }
510}
511
Chia-I Wu1f851912015-10-27 18:04:07 +0800512TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinski81078192015-05-19 10:28:29 -0500513{
514 vk_testing::Fence testFence;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500515 VkFenceCreateInfo fenceInfo = {};
516 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
517 fenceInfo.pNext = NULL;
518 fenceInfo.flags = 0;
519
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600520 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Calling vkBeginCommandBuffer() on active CB");
521
Mark Lobodzinski81078192015-05-19 10:28:29 -0500522 ASSERT_NO_FATAL_FAILURE(InitState());
523 ASSERT_NO_FATAL_FAILURE(InitViewport());
524 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
525
Tony Barbour1490c912015-07-28 10:17:20 -0600526 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800527 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -0600528 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500529
530 testFence.init(*m_device, fenceInfo);
531
532 // Bypass framework since it does the waits automatically
533 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600534 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +0800535 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
536 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800537 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600538 submit_info.pWaitSemaphores = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800539 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +0800540 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +0800541 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600542 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600543
544 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500545 ASSERT_VK_SUCCESS( err );
546
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600547
Chia-I Wu1f851912015-10-27 18:04:07 +0800548 VkCommandBufferBeginInfo info = {};
549 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
550 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600551 info.renderPass = VK_NULL_HANDLE;
552 info.subpass = 0;
553 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wufdc1cd02015-11-11 10:18:12 +0800554 info.occlusionQueryEnable = VK_FALSE;
555 info.queryFlags = 0;
556 info.pipelineStatistics = 0;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600557
558 // Introduce failure by calling BCB again before checking fence
Chia-I Wu1f851912015-10-27 18:04:07 +0800559 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500560
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600561 if (!m_errorMonitor->DesiredMsgFound()) {
562 FAIL() << "Did not receive Error 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
563 m_errorMonitor->DumpFailureMsgs();
564
Mark Lobodzinski81078192015-05-19 10:28:29 -0500565 }
566}
567
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500568TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
569{
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500570 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600571 bool pass;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500572
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600573 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
574 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
575
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500576 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500577
578 // Create an image, allocate memory, free it, and then try to bind it
579 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500580 VkDeviceMemory mem;
581 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500582
583 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
584 const int32_t tex_width = 32;
585 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500586
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600587 VkImageCreateInfo image_create_info = {};
588 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
589 image_create_info.pNext = NULL;
590 image_create_info.imageType = VK_IMAGE_TYPE_2D;
591 image_create_info.format = tex_format;
592 image_create_info.extent.width = tex_width;
593 image_create_info.extent.height = tex_height;
594 image_create_info.extent.depth = 1;
595 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600596 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800597 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600598 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
599 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
600 image_create_info.flags = 0;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600601
Chia-I Wu1f851912015-10-27 18:04:07 +0800602 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +0800603 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600604 mem_alloc.pNext = NULL;
605 mem_alloc.allocationSize = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500606 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600607 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500608
Chia-I Wu69f40122015-10-26 21:10:41 +0800609 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500610 ASSERT_VK_SUCCESS(err);
611
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600612 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500613 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500614 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500615
Mark Lobodzinski23182612015-05-29 09:32:35 -0500616 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500617
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600618 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
619 if(!pass) { // If we can't find any unmappable memory this test doesn't make sense
Chia-I Wu69f40122015-10-26 21:10:41 +0800620 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour49a3b652015-08-04 16:13:01 -0600621 return;
Mike Stroyan2237f522015-08-18 14:40:24 -0600622 }
Mike Stroyand72da752015-08-04 10:49:29 -0600623
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500624 // allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +0800625 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500626 ASSERT_VK_SUCCESS(err);
627
628 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600629 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500630 ASSERT_VK_SUCCESS(err);
631
632 // Map memory as if to initialize the image
633 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500634 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500635
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600636 if (!m_errorMonitor->DesiredMsgFound()) {
637 FAIL() << "Did not receive Error 'Error received did not match expected error message from vkMapMemory in MemTracker'";
638 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500639 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600640
Chia-I Wu69f40122015-10-26 21:10:41 +0800641 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500642}
643
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600644// TODO : Is this test still valid. Not sure it is with updates to memory binding model
645// Verify and delete the test of fix the check
646//TEST_F(VkLayerTest, FreeBoundMemory)
647//{
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600648// VkResult err;
649//
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600650// m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
651// "Freeing memory object while it still has references");
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600652//
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600653// ASSERT_NO_FATAL_FAILURE(InitState());
654
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600655// // Create an image, allocate memory, free it, and then try to bind it
656// VkImage image;
657// VkDeviceMemory mem;
658// VkMemoryRequirements mem_reqs;
659//
660// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
661// const int32_t tex_width = 32;
662// const int32_t tex_height = 32;
663//
664// const VkImageCreateInfo image_create_info = {
665// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
666// .pNext = NULL,
667// .imageType = VK_IMAGE_TYPE_2D,
668// .format = tex_format,
669// .extent = { tex_width, tex_height, 1 },
670// .mipLevels = 1,
671// .arraySize = 1,
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800672// .samples = VK_SAMPLE_COUNT_1_BIT,
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600673// .tiling = VK_IMAGE_TILING_LINEAR,
674// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
675// .flags = 0,
676// };
Chia-I Wu1f851912015-10-27 18:04:07 +0800677// VkMemoryAllocateInfo mem_alloc = {
Chia-I Wuc1f5e402015-11-10 16:21:09 +0800678// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600679// .pNext = NULL,
680// .allocationSize = 0,
681// .memoryTypeIndex = 0,
682// };
683//
Chia-I Wu69f40122015-10-26 21:10:41 +0800684// err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600685// ASSERT_VK_SUCCESS(err);
686//
687// err = vkGetImageMemoryRequirements(m_device->device(),
688// image,
689// &mem_reqs);
690// ASSERT_VK_SUCCESS(err);
691//
692// mem_alloc.allocationSize = mem_reqs.size;
693//
694// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
695// ASSERT_VK_SUCCESS(err);
696//
697// // allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +0800698// err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600699// ASSERT_VK_SUCCESS(err);
700//
701// // Bind memory to Image object
702// err = vkBindImageMemory(m_device->device(), image, mem, 0);
703// ASSERT_VK_SUCCESS(err);
704//
705// // Introduce validation failure, free memory while still bound to object
Chia-I Wu69f40122015-10-26 21:10:41 +0800706// vkFreeMemory(m_device->device(), mem, NULL);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600707//
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600708// if (!m_errorMonitor->DesiredMsgFound()) {
709// FAIL() << "Did not receive Warning 'Freeing memory object while it still has references'");
710// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600711// }
712//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500713
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500714TEST_F(VkLayerTest, RebindMemory)
715{
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500716 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600717 bool pass;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500718
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600719 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
720 "which has already been bound to mem object");
721
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500722 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500723
724 // Create an image, allocate memory, free it, and then try to bind it
725 VkImage image;
726 VkDeviceMemory mem1;
727 VkDeviceMemory mem2;
728 VkMemoryRequirements mem_reqs;
729
730 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
731 const int32_t tex_width = 32;
732 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500733
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600734 VkImageCreateInfo image_create_info = {};
735 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
736 image_create_info.pNext = NULL;
737 image_create_info.imageType = VK_IMAGE_TYPE_2D;
738 image_create_info.format = tex_format;
739 image_create_info.extent.width = tex_width;
740 image_create_info.extent.height = tex_height;
741 image_create_info.extent.depth = 1;
742 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600743 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800744 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600745 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
746 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
747 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500748
Chia-I Wu1f851912015-10-27 18:04:07 +0800749 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +0800750 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600751 mem_alloc.pNext = NULL;
752 mem_alloc.allocationSize = 0;
753 mem_alloc.memoryTypeIndex = 0;
754
755 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
756 mem_alloc.memoryTypeIndex = 1;
Chia-I Wu69f40122015-10-26 21:10:41 +0800757 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500758 ASSERT_VK_SUCCESS(err);
759
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600760 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500761 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500762 &mem_reqs);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500763
764 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600765 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
766 ASSERT_TRUE(pass);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500767
768 // allocate 2 memory objects
Chia-I Wu1f851912015-10-27 18:04:07 +0800769 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500770 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +0800771 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500772 ASSERT_VK_SUCCESS(err);
773
774 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600775 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500776 ASSERT_VK_SUCCESS(err);
777
778 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600779 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500780
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600781 if (!m_errorMonitor->DesiredMsgFound()) {
782 FAIL() << "Did not receive Error when rebinding memory to an object";
783 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500784 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600785
Chia-I Wu69f40122015-10-26 21:10:41 +0800786 vkDestroyImage(m_device->device(), image, NULL);
787 vkFreeMemory(m_device->device(), mem1, NULL);
788 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500789}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500790
Tony Barbour8508b8e2015-04-09 10:48:04 -0600791TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600792{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600793 vk_testing::Fence testFence;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600794
795 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
796 "submitted in SIGNALED state. Fences must be reset before being submitted");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600797
798 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600799 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
800 fenceInfo.pNext = NULL;
801 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600802
Tony Barbour30486ea2015-04-07 13:44:53 -0600803 ASSERT_NO_FATAL_FAILURE(InitState());
804 ASSERT_NO_FATAL_FAILURE(InitViewport());
805 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
806
Tony Barbour1490c912015-07-28 10:17:20 -0600807 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800808 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -0600809 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600810
811 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600812
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600813 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +0800814 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
815 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800816 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600817 submit_info.pWaitSemaphores = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800818 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +0800819 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +0800820 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600821 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600822
823 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600824 vkQueueWaitIdle(m_device->m_queue );
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600825
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600826 if (!m_errorMonitor->DesiredMsgFound()) {
827 FAIL() << "Did not receive Error 'VkQueueSubmit with fence in SIGNALED_STATE'";
828 m_errorMonitor->DumpFailureMsgs();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600829 }
Tony Barbour8508b8e2015-04-09 10:48:04 -0600830}
831
832TEST_F(VkLayerTest, ResetUnsignaledFence)
833{
834 vk_testing::Fence testFence;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600835 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600836 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
837 fenceInfo.pNext = NULL;
838
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600839 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
840 "submitted to VkResetFences in UNSIGNALED STATE");
841
Tony Barbour8508b8e2015-04-09 10:48:04 -0600842 ASSERT_NO_FATAL_FAILURE(InitState());
843 testFence.init(*m_device, fenceInfo);
Chia-I Wua4992342015-07-03 11:45:55 +0800844 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600845 vkResetFences(m_device->device(), 1, fences);
Tony Barbour30486ea2015-04-07 13:44:53 -0600846
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600847 if (!m_errorMonitor->DesiredMsgFound()) {
848 FAIL() << "Did not receive Error 'VkResetFences with fence in UNSIGNALED_STATE'";
849 m_errorMonitor->DumpFailureMsgs();
850 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600851}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600852
Chia-I Wuc278df82015-07-07 11:50:03 +0800853/* TODO: Update for changes due to bug-14075 tiling across render passes */
854#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600855TEST_F(VkLayerTest, InvalidUsageBits)
856{
857 // Initiate Draw w/o a PSO bound
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600858
859 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
860 "Invalid usage flag for image ");
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600861
862 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +0800863 VkCommandBufferObj commandBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600864 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600865
866 const VkExtent3D e3d = {
867 .width = 128,
868 .height = 128,
869 .depth = 1,
870 };
871 const VkImageCreateInfo ici = {
872 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
873 .pNext = NULL,
874 .imageType = VK_IMAGE_TYPE_2D,
875 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
876 .extent = e3d,
877 .mipLevels = 1,
878 .arraySize = 1,
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800879 .samples = VK_SAMPLE_COUNT_1_BIT,
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600880 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchterc3b8eea2015-09-10 14:14:11 -0600881 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600882 .flags = 0,
883 };
884
885 VkImage dsi;
Chia-I Wu69f40122015-10-26 21:10:41 +0800886 vkCreateImage(m_device->device(), &ici, NULL, &dsi);
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600887 VkDepthStencilView dsv;
888 const VkDepthStencilViewCreateInfo dsvci = {
889 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
890 .pNext = NULL,
891 .image = dsi,
892 .mipLevel = 0,
Courtney Goeltzenleuchter3dee8082015-09-10 16:38:41 -0600893 .baseArrayLayer = 0,
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600894 .arraySize = 1,
895 .flags = 0,
896 };
Chia-I Wu69f40122015-10-26 21:10:41 +0800897 vkCreateDepthStencilView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600898
899 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600900 FAIL() << "Error received was not 'Invalid usage flag for image...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600901 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600902 }
903}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600904#endif // 0
905#endif // MEM_TRACKER_TESTS
906
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600907#if OBJ_TRACKER_TESTS
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600908TEST_F(VkLayerTest, PipelineNotBound)
909{
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600910 VkResult err;
911
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600912 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
913 "Invalid VkPipeline Object ");
914
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600915 ASSERT_NO_FATAL_FAILURE(InitState());
916 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600917
Chia-I Wuc51b1212015-10-27 19:25:11 +0800918 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600919 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +0800920 ds_type_count.descriptorCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600921
922 VkDescriptorPoolCreateInfo ds_pool_ci = {};
923 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
924 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600925 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +0800926 ds_pool_ci.poolSizeCount = 1;
927 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600928
929 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +0800930 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600931 ASSERT_VK_SUCCESS(err);
932
933 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +0800934 dsl_binding.binding = 0;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600935 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +0800936 dsl_binding.descriptorCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600937 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
938 dsl_binding.pImmutableSamplers = NULL;
939
940 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
941 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
942 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800943 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +0800944 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600945
946 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +0800947 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600948 ASSERT_VK_SUCCESS(err);
949
950 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +0800951 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +0800952 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +0800953 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -0600954 alloc_info.descriptorPool = ds_pool;
955 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +0800956 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600957 ASSERT_VK_SUCCESS(err);
958
959 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
960 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
961 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800962 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600963 pipeline_layout_ci.pSetLayouts = &ds_layout;
964
965 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +0800966 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600967 ASSERT_VK_SUCCESS(err);
968
969 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
970
971 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800972 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600973
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600974 if (!m_errorMonitor->DesiredMsgFound()) {
975 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be'" << endl;
976 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600977 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600978
Chia-I Wu69f40122015-10-26 21:10:41 +0800979 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
980 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
981 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600982}
983
984TEST_F(VkLayerTest, BindInvalidMemory)
985{
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600986 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600987 bool pass;
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600988
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600989 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
990 "Invalid VkDeviceMemory Object ");
991
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600992 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600993
994 // Create an image, allocate memory, free it, and then try to bind it
995 VkImage image;
996 VkDeviceMemory mem;
997 VkMemoryRequirements mem_reqs;
998
999 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1000 const int32_t tex_width = 32;
1001 const int32_t tex_height = 32;
1002
1003 VkImageCreateInfo image_create_info = {};
1004 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1005 image_create_info.pNext = NULL;
1006 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1007 image_create_info.format = tex_format;
1008 image_create_info.extent.width = tex_width;
1009 image_create_info.extent.height = tex_height;
1010 image_create_info.extent.depth = 1;
1011 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06001012 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001013 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001014 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1015 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1016 image_create_info.flags = 0;
1017
Chia-I Wu1f851912015-10-27 18:04:07 +08001018 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001019 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001020 mem_alloc.pNext = NULL;
1021 mem_alloc.allocationSize = 0;
1022 mem_alloc.memoryTypeIndex = 0;
1023
Chia-I Wu69f40122015-10-26 21:10:41 +08001024 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001025 ASSERT_VK_SUCCESS(err);
1026
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06001027 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001028 image,
1029 &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001030
1031 mem_alloc.allocationSize = mem_reqs.size;
1032
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001033 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1034 ASSERT_TRUE(pass);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001035
1036 // allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08001037 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001038 ASSERT_VK_SUCCESS(err);
1039
1040 // Introduce validation failure, free memory before binding
Chia-I Wu69f40122015-10-26 21:10:41 +08001041 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001042
1043 // Try to bind free memory that has been freed
1044 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1045 // This may very well return an error.
1046 (void)err;
1047
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001048 if (!m_errorMonitor->DesiredMsgFound()) {
1049 FAIL() << "Did not receive Error 'Invalid VkDeviceMemory Object 0x<handle>'";
1050 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001051 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001052
Chia-I Wu69f40122015-10-26 21:10:41 +08001053 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001054}
1055
1056TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
1057{
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001058 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001059 bool pass;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001060
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001061 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Invalid VkImage Object ");
1062
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001063 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001064
1065 // Create an image object, allocate memory, destroy the object and then try to bind it
1066 VkImage image;
1067 VkDeviceMemory mem;
1068 VkMemoryRequirements mem_reqs;
1069
1070 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1071 const int32_t tex_width = 32;
1072 const int32_t tex_height = 32;
1073
1074 VkImageCreateInfo image_create_info = {};
1075 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1076 image_create_info.pNext = NULL;
1077 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1078 image_create_info.format = tex_format;
1079 image_create_info.extent.width = tex_width;
1080 image_create_info.extent.height = tex_height;
1081 image_create_info.extent.depth = 1;
1082 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06001083 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001084 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001085 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1086 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1087 image_create_info.flags = 0;
1088
Chia-I Wu1f851912015-10-27 18:04:07 +08001089 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001090 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001091 mem_alloc.pNext = NULL;
1092 mem_alloc.allocationSize = 0;
1093 mem_alloc.memoryTypeIndex = 0;
1094
Chia-I Wu69f40122015-10-26 21:10:41 +08001095 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001096 ASSERT_VK_SUCCESS(err);
1097
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06001098 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001099 image,
1100 &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001101
1102 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001103 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1104 ASSERT_TRUE(pass);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001105
1106 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08001107 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001108 ASSERT_VK_SUCCESS(err);
1109
1110 // Introduce validation failure, destroy Image object before binding
Chia-I Wu69f40122015-10-26 21:10:41 +08001111 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001112 ASSERT_VK_SUCCESS(err);
1113
1114 // Now Try to bind memory to this destroyed object
1115 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1116 // This may very well return an error.
1117 (void) err;
1118
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001119 if (!m_errorMonitor->DesiredMsgFound()) {
1120 FAIL() << "Did not receive Error 'Invalid VkImage Object 0x<handle>'";
1121 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001122 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001123
Chia-I Wu69f40122015-10-26 21:10:41 +08001124 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001125}
Tobin Ehlisb46be812015-10-23 16:00:08 -06001126
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001127#endif // OBJ_TRACKER_TESTS
1128
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001129#if DRAW_STATE_TESTS
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001130TEST_F(VkLayerTest, LineWidthStateNotBound)
1131{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001132 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1133 "Dynamic line width state not set for this command buffer");
1134
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001135 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
1136
1137 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
1138
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001139 if (!m_errorMonitor->DesiredMsgFound()) {
1140 FAIL() << "Did not receive Error 'Dynamic line width state not set for this command buffer'";
1141 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001142 }
1143}
1144
1145TEST_F(VkLayerTest, DepthBiasStateNotBound)
1146{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001147 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1148 "Dynamic depth bias state not set for this command buffer");
1149
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001150 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
1151
1152 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
1153
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001154 if (!m_errorMonitor->DesiredMsgFound()) {
1155 FAIL() << "Did not receive Error 'Dynamic depth bias state not set for this command buffer'";
1156 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001157 }
1158}
1159
Cody Northropbca3bcd2015-10-27 16:54:28 -06001160// Disable these two tests until we can sort out how to track multiple layer errors
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001161TEST_F(VkLayerTest, ViewportStateNotBound)
1162{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001163 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1164 "Dynamic viewport state not set for this command buffer");
1165
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001166 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1167
1168 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1169
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001170 if (!m_errorMonitor->DesiredMsgFound()) {
1171 FAIL() << "Did not recieve Error 'Dynamic scissor state not set for this command buffer'";
1172 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001173 }
1174}
1175
1176TEST_F(VkLayerTest, ScissorStateNotBound)
1177{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001178 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1179 "Dynamic scissor state not set for this command buffer");
1180
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001181 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1182
1183 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1184
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001185 if (!m_errorMonitor->DesiredMsgFound()) {
1186 FAIL() << "Did not recieve Error ' Expected: 'Dynamic scissor state not set for this command buffer'";
1187 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001188 }
1189}
1190
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001191TEST_F(VkLayerTest, BlendStateNotBound)
1192{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001193 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1194 "Dynamic blend object state not set for this command buffer");
1195
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001196 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1197
1198 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1199
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001200 if (!m_errorMonitor->DesiredMsgFound()) {
1201 FAIL() << "Did not recieve Error 'Dynamic blend object state not set for this command buffer'";
1202 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001203 }
1204}
1205
1206TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1207{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001208 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1209 "Dynamic depth bounds state not set for this command buffer");
1210
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001211 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1212
1213 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1214
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001215 if (!m_errorMonitor->DesiredMsgFound()) {
1216 FAIL() << "Did not receive Error 'Dynamic depth bounds state not set for this command buffer'";
1217 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001218 }
1219}
1220
1221TEST_F(VkLayerTest, StencilReadMaskNotSet)
1222{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001223 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1224 "Dynamic stencil read mask state not set for this command buffer");
1225
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001226 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001227
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001228 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1229
1230 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1231
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001232 if (!m_errorMonitor->DesiredMsgFound()) {
1233 FAIL() << "Did not receive Error 'Dynamic stencil read mask state not set for this command buffer'";
1234 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001235 }
1236}
1237
1238TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1239{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001240 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1241 "Dynamic stencil write mask state not set for this command buffer");
1242
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001243 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001244
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001245 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1246
1247 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1248
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001249 if (!m_errorMonitor->DesiredMsgFound()) {
1250 FAIL() << "Did not receive Error 'Dynamic stencil write mask state not set for this command buffer'";
1251 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001252 }
1253}
1254
1255TEST_F(VkLayerTest, StencilReferenceNotSet)
1256{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001257 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1258 "Dynamic stencil reference state not set for this command buffer");
1259
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001260 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1261
1262 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1263
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001264 if (!m_errorMonitor->DesiredMsgFound()) {
1265 FAIL() << "Did not receive Error 'Dynamic stencil reference state not set for this command buffer'";
1266 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001267 }
1268}
1269
Chia-I Wu1f851912015-10-27 18:04:07 +08001270TEST_F(VkLayerTest, CommandBufferTwoSubmits)
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001271{
1272 vk_testing::Fence testFence;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001273
1274 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1275 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted");
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001276
1277 VkFenceCreateInfo fenceInfo = {};
1278 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1279 fenceInfo.pNext = NULL;
1280 fenceInfo.flags = 0;
1281
1282 ASSERT_NO_FATAL_FAILURE(InitState());
1283 ASSERT_NO_FATAL_FAILURE(InitViewport());
1284 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1285
Chia-I Wu1f851912015-10-27 18:04:07 +08001286 // We luck out b/c by default the framework creates CB w/ the VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001287 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08001288 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001289 EndCommandBuffer();
1290
1291 testFence.init(*m_device, fenceInfo);
1292
1293 // Bypass framework since it does the waits automatically
1294 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001295 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +08001296 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1297 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001298 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001299 submit_info.pWaitSemaphores = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001300 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08001301 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +08001302 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001303 submit_info.pSignalSemaphores = NULL;
1304
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06001305 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001306 ASSERT_VK_SUCCESS( err );
1307
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001308 // Cause validation error by re-submitting cmd buffer that should only be submitted once
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06001309 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001310
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001311 if (!m_errorMonitor->DesiredMsgFound()) {
1312 FAIL() << "Did not receive Error 'CB (0xaddress) was created w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set...'";
1313 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001314 }
1315}
1316
Tobin Ehlise4076782015-06-24 15:53:07 -06001317TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001318{
1319 // Initiate Draw w/o a PSO bound
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001320 VkResult err;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001321
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001322 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1323 "Incorrectly binding graphics pipeline ");
1324
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001325 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001326 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001327
Chia-I Wuc51b1212015-10-27 19:25:11 +08001328 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001329 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001330 ds_type_count.descriptorCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001331
1332 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1333 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1334 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001335 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001336 ds_pool_ci.poolSizeCount = 1;
1337 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001338
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001339 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001340 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001341 ASSERT_VK_SUCCESS(err);
1342
1343 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001344 dsl_binding.binding = 0;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001345 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001346 dsl_binding.descriptorCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001347 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1348 dsl_binding.pImmutableSamplers = NULL;
1349
1350 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1351 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1352 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001353 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001354 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001355
1356 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001357 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001358 ASSERT_VK_SUCCESS(err);
1359
1360 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001361 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001362 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001363 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001364 alloc_info.descriptorPool = ds_pool;
1365 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001366 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001367 ASSERT_VK_SUCCESS(err);
1368 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1369 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1370 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001371 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001372 pipe_ms_state_ci.sampleShadingEnable = 0;
1373 pipe_ms_state_ci.minSampleShading = 1.0;
1374 pipe_ms_state_ci.pSampleMask = NULL;
1375
1376 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1377 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1378 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001379 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001380 pipeline_layout_ci.pSetLayouts = &ds_layout;
1381 VkPipelineLayout pipeline_layout;
1382
Chia-I Wu69f40122015-10-26 21:10:41 +08001383 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001384 ASSERT_VK_SUCCESS(err);
1385
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001386 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1387 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001388 // but add it to be able to run on more devices
1389 VkPipelineObj pipe(m_device);
1390 pipe.AddShader(&vs);
1391 pipe.AddShader(&fs);
1392 pipe.SetMSAA(&pipe_ms_state_ci);
1393 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001394
Chia-I Wu1f851912015-10-27 18:04:07 +08001395 // Calls AllocateCommandBuffers
1396 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
1397 VkCommandBufferBeginInfo cmd_buf_info = {};
1398 memset(&cmd_buf_info, 0, sizeof(VkCommandBufferBeginInfo));
1399 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001400 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08001401 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001402
Chia-I Wu1f851912015-10-27 18:04:07 +08001403 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
1404 vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001405
1406 if (!m_errorMonitor->DesiredMsgFound()) {
1407 FAIL() << "Did not receive Error 'Incorrectly binding graphics pipeline (0x<handle>) without an active RenderPass'";
1408 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001409 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001410
Chia-I Wu69f40122015-10-26 21:10:41 +08001411 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1412 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1413 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001414}
1415
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001416TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1417{
1418 // Initiate Draw w/o a PSO bound
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001419 VkResult err;
1420
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001421 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1422 "Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
1423
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001424 ASSERT_NO_FATAL_FAILURE(InitState());
1425 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001426
1427 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
Chia-I Wuc51b1212015-10-27 19:25:11 +08001428 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001429 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001430 ds_type_count.descriptorCount = 1;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001431
1432 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1433 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1434 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001435 ds_pool_ci.flags = 0;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001436 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001437 ds_pool_ci.poolSizeCount = 1;
1438 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001439
1440 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001441 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001442 ASSERT_VK_SUCCESS(err);
1443
1444 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001445 dsl_binding.binding = 0;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001446 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001447 dsl_binding.descriptorCount = 1;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001448 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1449 dsl_binding.pImmutableSamplers = NULL;
1450
1451 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1452 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1453 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001454 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001455 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001456
1457 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001458 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001459 ASSERT_VK_SUCCESS(err);
1460
1461 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001462 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001463 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001464 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001465 alloc_info.descriptorPool = ds_pool;
1466 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001467 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001468
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001469 if (!m_errorMonitor->DesiredMsgFound()) {
1470 FAIL() << "Did not receive Error 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...'";
1471 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001472 }
1473
Chia-I Wu69f40122015-10-26 21:10:41 +08001474 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1475 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001476}
1477
Tobin Ehlis3c543112015-10-08 13:13:50 -06001478TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1479{
Tobin Ehlis3c543112015-10-08 13:13:50 -06001480 VkResult err;
1481
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001482 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1483 "It is invalid to call vkFreeDescriptorSets() with a pool created without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
1484
Tobin Ehlis3c543112015-10-08 13:13:50 -06001485 ASSERT_NO_FATAL_FAILURE(InitState());
1486 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis3c543112015-10-08 13:13:50 -06001487
Chia-I Wuc51b1212015-10-27 19:25:11 +08001488 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis3c543112015-10-08 13:13:50 -06001489 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001490 ds_type_count.descriptorCount = 1;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001491
1492 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1493 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1494 ds_pool_ci.pNext = NULL;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001495 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001496 ds_pool_ci.poolSizeCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001497 ds_pool_ci.flags = 0;
1498 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
1499 // app can only call vkResetDescriptorPool on this pool.;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001500 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001501
1502 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001503 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001504 ASSERT_VK_SUCCESS(err);
1505
1506 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001507 dsl_binding.binding = 0;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001508 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001509 dsl_binding.descriptorCount = 1;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001510 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1511 dsl_binding.pImmutableSamplers = NULL;
1512
1513 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1514 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1515 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001516 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001517 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001518
1519 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001520 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001521 ASSERT_VK_SUCCESS(err);
1522
1523 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001524 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001525 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001526 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001527 alloc_info.descriptorPool = ds_pool;
1528 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001529 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001530 ASSERT_VK_SUCCESS(err);
1531
1532 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001533 if (!m_errorMonitor->DesiredMsgFound()) {
1534 FAIL() << "Did not receive Error 'It is invalid to call vkFreeDescriptorSets() with a pool created with...'";
1535 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3c543112015-10-08 13:13:50 -06001536 }
1537
Chia-I Wu69f40122015-10-26 21:10:41 +08001538 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1539 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001540}
1541
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001542TEST_F(VkLayerTest, InvalidDescriptorPool)
1543{
1544 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1545 // The DS check for this is after driver has been called to validate DS internal data struct
1546 // Attempt to clear DS Pool with bad object
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001547/*
1548 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1549 "Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call");
1550
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001551 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1552 vkResetDescriptorPool(device(), badPool);
1553
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001554 if (!m_errorMonitor->DesiredMsgFound()) {
1555 FAIL() << "Did not receive Error 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1556 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001557 }*/
1558}
1559
1560TEST_F(VkLayerTest, InvalidDescriptorSet)
1561{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001562 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1563 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001564 // Create a valid cmd buffer
1565 // call vkCmdBindDescriptorSets w/ false DS
1566}
1567
1568TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1569{
1570 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1571 // The DS check for this is after driver has been called to validate DS internal data struct
1572}
1573
1574TEST_F(VkLayerTest, InvalidPipeline)
1575{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001576 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1577 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001578 // Create a valid cmd buffer
1579 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001580//
1581// m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1582// "Attempt to bind Pipeline ");
Tobin Ehlise4076782015-06-24 15:53:07 -06001583//
1584// ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +08001585// VkCommandBufferObj commandBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001586// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001587// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Chia-I Wu1f851912015-10-27 18:04:07 +08001588// vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001589//
1590// if (!m_errorMonitor->DesiredMsgFound()) {
1591// FAIL() << "Did not receive Error 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1592// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise4076782015-06-24 15:53:07 -06001593// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001594}
1595
Tobin Ehlis254eca02015-06-25 15:46:59 -06001596TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001597{
Chia-I Wu1f851912015-10-27 18:04:07 +08001598 // Create and update CommandBuffer then call QueueSubmit w/o calling End on CommandBuffer
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001599 VkResult err;
1600
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001601 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
1602 " bound but it was never updated. ");
1603
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001604 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001605 ASSERT_NO_FATAL_FAILURE(InitViewport());
1606 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wuc51b1212015-10-27 19:25:11 +08001607 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001608 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001609 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001610
1611 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1612 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1613 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001614 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001615 ds_pool_ci.poolSizeCount = 1;
1616 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001617
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001618 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001619 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001620 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001621
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001622 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001623 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001624 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001625 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001626 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1627 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001628
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001629 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1630 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1631 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001632 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001633 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001634 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001635 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001636 ASSERT_VK_SUCCESS(err);
1637
1638 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001639 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001640 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001641 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001642 alloc_info.descriptorPool = ds_pool;
1643 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001644 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001645 ASSERT_VK_SUCCESS(err);
1646
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001647 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1648 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1649 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001650 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001651 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001652
1653 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001654 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001655 ASSERT_VK_SUCCESS(err);
1656
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001657 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001658 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
1659 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001660
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001661 VkPipelineObj pipe(m_device);
1662 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001663 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001664 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001665
1666 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08001667 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1668 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001669
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001670 if (!m_errorMonitor->DesiredMsgFound()) {
1671 FAIL() << "Did not recieve Warning 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1672 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001673 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001674
Chia-I Wu69f40122015-10-26 21:10:41 +08001675 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1676 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1677 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001678}
1679
Tobin Ehlis093ef922015-11-02 15:24:32 -07001680TEST_F(VkLayerTest, InvalidBufferViewObject)
1681{
1682 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
1683 VkResult err;
1684
1685 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1686 "Attempt to update descriptor with invalid bufferView ");
1687
1688 ASSERT_NO_FATAL_FAILURE(InitState());
1689 VkDescriptorPoolSize ds_type_count = {};
1690 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1691 ds_type_count.descriptorCount = 1;
1692
1693 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1694 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1695 ds_pool_ci.pNext = NULL;
1696 ds_pool_ci.maxSets = 1;
1697 ds_pool_ci.poolSizeCount = 1;
1698 ds_pool_ci.pPoolSizes = &ds_type_count;
1699
1700 VkDescriptorPool ds_pool;
1701 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1702 ASSERT_VK_SUCCESS(err);
1703
1704 VkDescriptorSetLayoutBinding dsl_binding = {};
1705 dsl_binding.binding = 0;
1706 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001707 dsl_binding.descriptorCount = 1;
Tobin Ehlis093ef922015-11-02 15:24:32 -07001708 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1709 dsl_binding.pImmutableSamplers = NULL;
1710
1711 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1712 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1713 ds_layout_ci.pNext = NULL;
1714 ds_layout_ci.bindingCount = 1;
1715 ds_layout_ci.pBinding = &dsl_binding;
1716 VkDescriptorSetLayout ds_layout;
1717 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1718 ASSERT_VK_SUCCESS(err);
1719
1720 VkDescriptorSet descriptorSet;
1721 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001722 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Tobin Ehlis093ef922015-11-02 15:24:32 -07001723 alloc_info.setLayoutCount = 1;
1724 alloc_info.descriptorPool = ds_pool;
1725 alloc_info.pSetLayouts = &ds_layout;
1726 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1727 ASSERT_VK_SUCCESS(err);
1728
1729 VkBufferView view = (VkBufferView) 0xbaadbeef; // invalid bufferView object
Tobin Ehlis093ef922015-11-02 15:24:32 -07001730 VkWriteDescriptorSet descriptor_write;
1731 memset(&descriptor_write, 0, sizeof(descriptor_write));
1732 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1733 descriptor_write.dstSet = descriptorSet;
1734 descriptor_write.dstBinding = 0;
1735 descriptor_write.descriptorCount = 1;
1736 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1737 descriptor_write.pTexelBufferView = &view;
1738
1739 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1740
1741 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlisd9491452015-11-05 10:27:49 -07001742 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid bufferView'";
Tobin Ehlis093ef922015-11-02 15:24:32 -07001743 m_errorMonitor->DumpFailureMsgs();
1744 }
1745
1746 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1747 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1748}
1749
Tobin Ehlise2194862015-11-04 13:30:34 -07001750TEST_F(VkLayerTest, InvalidDynamicOffsetCount)
1751{
1752 // Create a descriptorSet w/ some dynamic descriptors and then don't send offsets when binding
1753 VkResult err;
1754 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1755 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but dynamicOffsetCount is 0. ");
1756
1757 ASSERT_NO_FATAL_FAILURE(InitState());
1758 ASSERT_NO_FATAL_FAILURE(InitViewport());
1759 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1760
1761 VkDescriptorPoolSize ds_type_count = {};
1762 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1763 ds_type_count.descriptorCount = 1;
1764
1765 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1766 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1767 ds_pool_ci.pNext = NULL;
1768 ds_pool_ci.maxSets = 1;
1769 ds_pool_ci.poolSizeCount = 1;
1770 ds_pool_ci.pPoolSizes = &ds_type_count;
1771
1772 VkDescriptorPool ds_pool;
1773 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1774 ASSERT_VK_SUCCESS(err);
1775
1776 VkDescriptorSetLayoutBinding dsl_binding = {};
1777 dsl_binding.binding = 0;
1778 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
Jon Ashburn96b714a2015-11-06 15:31:44 -07001779 dsl_binding.descriptorCount = 1;
Tobin Ehlise2194862015-11-04 13:30:34 -07001780 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1781 dsl_binding.pImmutableSamplers = NULL;
1782
1783 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1784 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1785 ds_layout_ci.pNext = NULL;
1786 ds_layout_ci.bindingCount = 1;
1787 ds_layout_ci.pBinding = &dsl_binding;
1788 VkDescriptorSetLayout ds_layout;
1789 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1790 ASSERT_VK_SUCCESS(err);
1791
1792 VkDescriptorSet descriptorSet;
1793 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001794 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Tobin Ehlise2194862015-11-04 13:30:34 -07001795 alloc_info.setLayoutCount = 1;
1796 alloc_info.descriptorPool = ds_pool;
1797 alloc_info.pSetLayouts = &ds_layout;
1798 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1799 ASSERT_VK_SUCCESS(err);
1800
1801 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1802 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1803 pipeline_layout_ci.pNext = NULL;
1804 pipeline_layout_ci.setLayoutCount = 1;
1805 pipeline_layout_ci.pSetLayouts = &ds_layout;
1806
1807 VkPipelineLayout pipeline_layout;
1808 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
1809 ASSERT_VK_SUCCESS(err);
1810
1811 // Create a buffer to update the descriptor with
1812 uint32_t qfi = 0;
1813 VkBufferCreateInfo buffCI = {};
1814 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1815 buffCI.size = 1024;
1816 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1817 buffCI.queueFamilyIndexCount = 1;
1818 buffCI.pQueueFamilyIndices = &qfi;
1819
1820 VkBuffer dyub;
1821 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
1822 ASSERT_VK_SUCCESS(err);
1823 // Correctly update descriptor to avoid "NOT_UPDATED" error
1824 VkDescriptorBufferInfo buffInfo = {};
1825 buffInfo.buffer = dyub;
1826 buffInfo.offset = 0;
1827 buffInfo.range = 1024;
1828
1829 VkWriteDescriptorSet descriptor_write;
1830 memset(&descriptor_write, 0, sizeof(descriptor_write));
1831 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1832 descriptor_write.dstSet = descriptorSet;
1833 descriptor_write.dstBinding = 0;
1834 descriptor_write.descriptorCount = 1;
1835 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1836 descriptor_write.pBufferInfo = &buffInfo;
1837
1838 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1839
1840 BeginCommandBuffer();
1841 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
1842
1843 if (!m_errorMonitor->DesiredMsgFound()) {
1844 FAIL() << "Error received was not 'Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but dynamicOffsetCount is 0...'";
1845 m_errorMonitor->DumpFailureMsgs();
1846 }
1847
1848 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1849 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1850}
1851
Tobin Ehlis982099b2015-11-05 09:52:49 -07001852/* WIP for Tobin's follow-on descriptor set validation efforts
1853TEST_F(VkLayerTest, DescriptorSetCompatibility)
1854{
1855 // Test various desriptorSet errors with bad binding combinations
1856 VkResult err;
1857 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1858 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but dynamicOffsetCount is 0. ");
1859
1860 ASSERT_NO_FATAL_FAILURE(InitState());
1861 ASSERT_NO_FATAL_FAILURE(InitViewport());
1862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1863
1864 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
1865 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
1866 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1867 ds_type_count[0].descriptorCount = 5;
1868 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1869 ds_type_count[1].descriptorCount = 2;
1870 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
1871 ds_type_count[2].descriptorCount = 2;
1872 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
1873 ds_type_count[3].descriptorCount = 5;
1874 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT type
1875 //ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
1876 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1877 ds_type_count[4].descriptorCount = 2;
1878
1879 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1880 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1881 ds_pool_ci.pNext = NULL;
1882 ds_pool_ci.maxSets = 1;
1883 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
1884 ds_pool_ci.pPoolSizes = ds_type_count;
1885
1886 VkDescriptorPool ds_pool;
1887 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1888 ASSERT_VK_SUCCESS(err);
1889
1890 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
1891 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
1892 dsl_binding[0].binding = 0;
1893 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1894 dsl_binding[0].arraySize = 5;
1895 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
1896 dsl_binding[0].pImmutableSamplers = NULL;
1897
1898 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1899 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1900 ds_layout_ci.pNext = NULL;
1901 ds_layout_ci.bindingCount = 1;
1902 ds_layout_ci.pBinding = dsl_binding;
1903 static const uint32_t NUM_LAYOUTS = 4;
1904 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
1905 // Create 4 unique layouts
1906 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
1907 ASSERT_VK_SUCCESS(err);
1908 dsl_binding[0].binding = 0;
1909 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1910 dsl_binding[0].arraySize = 2;
1911 dsl_binding[0].binding = 1;
1912 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
1913 dsl_binding[0].arraySize = 2;
1914 ds_layout_ci.bindingCount = 2;
1915 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
1916 ASSERT_VK_SUCCESS(err);
1917 dsl_binding[0].binding = 0;
1918 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1919 dsl_binding[0].arraySize = 5;
1920 ds_layout_ci.bindingCount = 1;
1921 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
1922 ASSERT_VK_SUCCESS(err);
1923 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1924 dsl_binding[0].arraySize = 2;
1925 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
1926 ASSERT_VK_SUCCESS(err);
1927
1928 static const uint32_t NUM_SETS = 4;
1929 VkDescriptorSet descriptorSet[NUM_SETS] = {};
1930 VkDescriptorSetAllocateInfo alloc_info = {};
1931 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1932 alloc_info.setLayoutCount = NUM_LAYOUTS;
1933 alloc_info.descriptorPool = ds_pool;
1934 alloc_info.pSetLayouts = ds_layout;
1935 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
1936 ASSERT_VK_SUCCESS(err);
1937
1938 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1939 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1940 pipeline_layout_ci.pNext = NULL;
1941 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
1942 pipeline_layout_ci.pSetLayouts = ds_layout;
1943
1944 VkPipelineLayout pipeline_layout;
1945 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
1946 ASSERT_VK_SUCCESS(err);
1947
1948 // Create a buffer to update the descriptor with
1949 uint32_t qfi = 0;
1950 VkBufferCreateInfo buffCI = {};
1951 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1952 buffCI.size = 1024;
1953 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1954 buffCI.queueFamilyIndexCount = 1;
1955 buffCI.pQueueFamilyIndices = &qfi;
1956
1957 VkBuffer dyub;
1958 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
1959 ASSERT_VK_SUCCESS(err);
1960 // Correctly update descriptor to avoid "NOT_UPDATED" error
1961 static const uint32_t NUM_BUFFS = 5;
1962 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
1963 for (uint32_t i=0; i<NUM_BUFFS; ++i) {
1964 buffInfo[i].buffer = dyub;
1965 buffInfo[i].offset = 0;
1966 buffInfo[i].range = 1024;
1967 }
1968
1969 VkWriteDescriptorSet descriptor_write;
1970 memset(&descriptor_write, 0, sizeof(descriptor_write));
1971 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1972 descriptor_write.dstSet = descriptorSet[0];
1973 descriptor_write.dstBinding = 0;
1974 descriptor_write.descriptorCount = 5;
1975 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1976 descriptor_write.pBufferInfo = buffInfo;
1977
1978 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1979
1980 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1981 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
1982 // but add it to be able to run on more devices
1983 VkPipelineObj pipe(m_device);
1984 pipe.AddShader(&vs);
1985 pipe.AddShader(&fs);
1986 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1987
1988 BeginCommandBuffer();
1989 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1990 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding of PSO
1991 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of cmd_pipeline.c
1992 // due to the fact that cmd_alloc_dset_data() has not been called in cmd_bind_graphics_pipeline()
1993 // TODO : Want to cause various binding incompatibility issues here to test DrawState
1994 // First cause various verify_layout_compatibility() fails
1995 // Second disturb early and late sets and verify INFO msgs
1996 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet[0], 0, NULL);
1997
1998 if (!m_errorMonitor->DesiredMsgFound()) {
1999 FAIL() << "Error received was not 'Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but dynamicOffsetCount is 0...'";
2000 m_errorMonitor->DumpFailureMsgs();
2001 }
2002
2003 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2004 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
2005}
2006*/
2007
Chia-I Wu1f851912015-10-27 18:04:07 +08002008TEST_F(VkLayerTest, NoBeginCommandBuffer)
Tobin Ehlis254eca02015-06-25 15:46:59 -06002009{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002010
2011 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2012 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlis254eca02015-06-25 15:46:59 -06002013
2014 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +08002015 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002016 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu1f851912015-10-27 18:04:07 +08002017 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002018
2019 if (!m_errorMonitor->DesiredMsgFound()) {
2020 FAIL() << "Did not recieve Error 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
2021 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06002022 }
2023}
2024
Chia-I Wu1f851912015-10-27 18:04:07 +08002025TEST_F(VkLayerTest, PrimaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002026{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002027
2028 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2029 "may not specify framebuffer or renderpass parameters");
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002030
2031 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002032
Chia-I Wu1f851912015-10-27 18:04:07 +08002033 // Calls AllocateCommandBuffers
2034 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002035
2036 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Chia-I Wu1f851912015-10-27 18:04:07 +08002037 VkCommandBufferBeginInfo cmd_buf_info = {};
2038 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06002039 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002040 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Cody Northrop10d8f982015-08-04 17:35:57 -06002041 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
2042 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
2043
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002044
2045 // The error should be caught by validation of the BeginCommandBuffer call
Chia-I Wu1f851912015-10-27 18:04:07 +08002046 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002047
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002048 if (!m_errorMonitor->DesiredMsgFound()) {
2049 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
2050 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002051 }
2052}
2053
Chia-I Wu1f851912015-10-27 18:04:07 +08002054TEST_F(VkLayerTest, SecondaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002055{
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002056 VkResult err;
Chia-I Wu1f851912015-10-27 18:04:07 +08002057 VkCommandBuffer draw_cmd;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002058
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002059 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2060 "must specify framebuffer and renderpass parameters");
2061
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002062 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002063
Chia-I Wu1f851912015-10-27 18:04:07 +08002064 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002065 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06002066 cmd.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002067 cmd.commandPool = m_commandPool;
2068 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Chia-I Wu763a7492015-10-26 20:48:51 +08002069 cmd.bufferCount = 1;
Cody Northrop10d8f982015-08-04 17:35:57 -06002070
Chia-I Wu1f851912015-10-27 18:04:07 +08002071 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyan2237f522015-08-18 14:40:24 -06002072 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002073
2074 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu1f851912015-10-27 18:04:07 +08002075 VkCommandBufferBeginInfo cmd_buf_info = {};
2076 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06002077 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002078 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002079
2080 // The error should be caught by validation of the BeginCommandBuffer call
2081 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
2082
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002083 if (!m_errorMonitor->DesiredMsgFound()) {
2084 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
2085 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002086 }
Chia-I Wu1f851912015-10-27 18:04:07 +08002087 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002088}
2089
Tobin Ehlis254eca02015-06-25 15:46:59 -06002090TEST_F(VkLayerTest, InvalidPipelineCreateState)
2091{
2092 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis254eca02015-06-25 15:46:59 -06002093 VkResult err;
2094
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002095 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2096 "Invalid Pipeline CreateInfo State: Vtx Shader required");
2097
Tobin Ehlis254eca02015-06-25 15:46:59 -06002098 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002099 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002100
Chia-I Wuc51b1212015-10-27 19:25:11 +08002101 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002102 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002103 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002104
2105 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2106 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2107 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002108 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002109 ds_pool_ci.poolSizeCount = 1;
2110 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002111
Tobin Ehlis254eca02015-06-25 15:46:59 -06002112 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002113 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002114 ASSERT_VK_SUCCESS(err);
2115
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002116 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002117 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002118 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002119 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002120 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2121 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002122
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002123 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2124 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2125 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002126 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002127 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002128
Tobin Ehlis254eca02015-06-25 15:46:59 -06002129 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002130 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002131 ASSERT_VK_SUCCESS(err);
2132
2133 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002134 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002135 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002136 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002137 alloc_info.descriptorPool = ds_pool;
2138 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002139 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002140 ASSERT_VK_SUCCESS(err);
2141
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002142 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2143 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002144 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002145 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002146
2147 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002148 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002149 ASSERT_VK_SUCCESS(err);
2150
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002151 VkViewport vp = {}; // Just need dummy vp to point to
2152 VkRect2D sc = {}; // dummy scissor to point to
2153
2154 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2155 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2156 vp_state_ci.scissorCount = 1;
2157 vp_state_ci.pScissors = &sc;
2158 vp_state_ci.viewportCount = 1;
2159 vp_state_ci.pViewports = &vp;
2160
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002161 VkGraphicsPipelineCreateInfo gp_ci = {};
2162 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002163 gp_ci.pViewportState = &vp_state_ci;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002164 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2165 gp_ci.layout = pipeline_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002166 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002167
2168 VkPipelineCacheCreateInfo pc_ci = {};
2169 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Chia-I Wu7e470702015-10-26 17:24:52 +08002170 pc_ci.initialDataSize = 0;
2171 pc_ci.pInitialData = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002172
2173 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06002174 VkPipelineCache pipelineCache;
2175
Chia-I Wu69f40122015-10-26 21:10:41 +08002176 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06002177 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002178 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002179
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002180 if (!m_errorMonitor->DesiredMsgFound()) {
2181 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
2182 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06002183 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002184
Chia-I Wu69f40122015-10-26 21:10:41 +08002185 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2186 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2187 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2188 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002189}
Tobin Ehlis20693172015-09-17 08:46:18 -06002190/*// TODO : This test should be good, but needs Tess support in compiler to run
2191TEST_F(VkLayerTest, InvalidPatchControlPoints)
2192{
2193 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis20693172015-09-17 08:46:18 -06002194 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002195
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002196 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2197 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ");
2198
Tobin Ehlis20693172015-09-17 08:46:18 -06002199 ASSERT_NO_FATAL_FAILURE(InitState());
2200 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis20693172015-09-17 08:46:18 -06002201
Chia-I Wuc51b1212015-10-27 19:25:11 +08002202 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis20693172015-09-17 08:46:18 -06002203 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002204 ds_type_count.descriptorCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002205
2206 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2207 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2208 ds_pool_ci.pNext = NULL;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002209 ds_pool_ci.poolSizeCount = 1;
2210 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis20693172015-09-17 08:46:18 -06002211
2212 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002213 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis20693172015-09-17 08:46:18 -06002214 ASSERT_VK_SUCCESS(err);
2215
2216 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002217 dsl_binding.binding = 0;
Tobin Ehlis20693172015-09-17 08:46:18 -06002218 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002219 dsl_binding.descriptorCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002220 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2221 dsl_binding.pImmutableSamplers = NULL;
2222
2223 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2224 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2225 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002226 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002227 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis20693172015-09-17 08:46:18 -06002228
2229 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002230 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis20693172015-09-17 08:46:18 -06002231 ASSERT_VK_SUCCESS(err);
2232
2233 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002234 err = vkAllocateDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis20693172015-09-17 08:46:18 -06002235 ASSERT_VK_SUCCESS(err);
2236
2237 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2238 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2239 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002240 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002241 pipeline_layout_ci.pSetLayouts = &ds_layout;
2242
2243 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002244 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis20693172015-09-17 08:46:18 -06002245 ASSERT_VK_SUCCESS(err);
2246
2247 VkPipelineShaderStageCreateInfo shaderStages[3];
2248 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
2249
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002250 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06002251 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002252 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
2253 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06002254
2255 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002256 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002257 shaderStages[0].shader = vs.handle();
2258 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002259 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002260 shaderStages[1].shader = tc.handle();
2261 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002262 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002263 shaderStages[2].shader = te.handle();
2264
2265 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
2266 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08002267 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis20693172015-09-17 08:46:18 -06002268
2269 VkPipelineTessellationStateCreateInfo tsCI = {};
2270 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
2271 tsCI.patchControlPoints = 0; // This will cause an error
2272
2273 VkGraphicsPipelineCreateInfo gp_ci = {};
2274 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2275 gp_ci.pNext = NULL;
2276 gp_ci.stageCount = 3;
2277 gp_ci.pStages = shaderStages;
2278 gp_ci.pVertexInputState = NULL;
2279 gp_ci.pInputAssemblyState = &iaCI;
2280 gp_ci.pTessellationState = &tsCI;
2281 gp_ci.pViewportState = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002282 gp_ci.pRasterizationState = NULL;
Tobin Ehlis20693172015-09-17 08:46:18 -06002283 gp_ci.pMultisampleState = NULL;
2284 gp_ci.pDepthStencilState = NULL;
2285 gp_ci.pColorBlendState = NULL;
2286 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2287 gp_ci.layout = pipeline_layout;
2288 gp_ci.renderPass = renderPass();
2289
2290 VkPipelineCacheCreateInfo pc_ci = {};
2291 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2292 pc_ci.pNext = NULL;
2293 pc_ci.initialSize = 0;
2294 pc_ci.initialData = 0;
2295 pc_ci.maxSize = 0;
2296
2297 VkPipeline pipeline;
2298 VkPipelineCache pipelineCache;
2299
Chia-I Wu69f40122015-10-26 21:10:41 +08002300 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis20693172015-09-17 08:46:18 -06002301 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002302 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis20693172015-09-17 08:46:18 -06002303
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002304 if (!m_errorMonitor->DesiredMsgFound()) {
2305 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...'";
2306 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis20693172015-09-17 08:46:18 -06002307 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002308
Chia-I Wu69f40122015-10-26 21:10:41 +08002309 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2310 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2311 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2312 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis20693172015-09-17 08:46:18 -06002313}
2314*/
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002315// Set scissor and viewport counts to different numbers
2316TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
2317{
2318 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002319 VkResult err;
2320
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002321 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2322 "Gfx Pipeline viewport count (1) must match scissor count (0).");
2323
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002324 ASSERT_NO_FATAL_FAILURE(InitState());
2325 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002326
Chia-I Wuc51b1212015-10-27 19:25:11 +08002327 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002328 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002329 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002330
2331 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2332 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002333 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002334 ds_pool_ci.poolSizeCount = 1;
2335 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002336
2337 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002338 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002339 ASSERT_VK_SUCCESS(err);
2340
2341 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002342 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002343 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002344 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002345 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2346
2347 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2348 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002349 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002350 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002351
2352 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002353 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002354 ASSERT_VK_SUCCESS(err);
2355
2356 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002357 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002358 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002359 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002360 alloc_info.descriptorPool = ds_pool;
2361 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002362 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002363 ASSERT_VK_SUCCESS(err);
2364
2365 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2366 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002367 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002368 pipeline_layout_ci.pSetLayouts = &ds_layout;
2369
2370 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002371 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002372 ASSERT_VK_SUCCESS(err);
2373
2374 VkViewport vp = {}; // Just need dummy vp to point to
2375
2376 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2377 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2378 vp_state_ci.scissorCount = 0;
2379 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2380 vp_state_ci.pViewports = &vp;
2381
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002382 VkPipelineShaderStageCreateInfo shaderStages[2];
2383 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002384
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002385 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2386 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002387 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002388 shaderStages[0] = vs.GetStageCreateInfo();
2389 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002390
2391 VkGraphicsPipelineCreateInfo gp_ci = {};
2392 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002393 gp_ci.stageCount = 2;
2394 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002395 gp_ci.pViewportState = &vp_state_ci;
2396 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2397 gp_ci.layout = pipeline_layout;
2398 gp_ci.renderPass = renderPass();
2399
2400 VkPipelineCacheCreateInfo pc_ci = {};
2401 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2402
2403 VkPipeline pipeline;
2404 VkPipelineCache pipelineCache;
2405
Chia-I Wu69f40122015-10-26 21:10:41 +08002406 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002407 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002408 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002409
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002410 if (!m_errorMonitor->DesiredMsgFound()) {
2411 FAIL() << "Did not receive Error 'Gfx Pipeline viewport count (1) must match scissor count (0).'";
2412 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002413 }
2414
Chia-I Wu69f40122015-10-26 21:10:41 +08002415 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2416 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2417 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2418 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002419}
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002420// Don't set viewport state in PSO. This is an error b/c we always need this state
2421// for the counts even if the data is going to be set dynamically.
2422TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002423{
2424 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002425 VkResult err;
2426
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002427 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2428 "Gfx Pipeline pViewportState is null. Even if ");
2429
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002430 ASSERT_NO_FATAL_FAILURE(InitState());
2431 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002432
Chia-I Wuc51b1212015-10-27 19:25:11 +08002433 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002434 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002435 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002436
2437 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2438 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002439 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002440 ds_pool_ci.poolSizeCount = 1;
2441 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002442
2443 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002444 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002445 ASSERT_VK_SUCCESS(err);
2446
2447 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002448 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002449 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002450 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002451 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2452
2453 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2454 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002455 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002456 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002457
2458 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002459 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002460 ASSERT_VK_SUCCESS(err);
2461
2462 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002463 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002464 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002465 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002466 alloc_info.descriptorPool = ds_pool;
2467 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002468 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002469 ASSERT_VK_SUCCESS(err);
2470
2471 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2472 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002473 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002474 pipeline_layout_ci.pSetLayouts = &ds_layout;
2475
2476 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002477 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002478 ASSERT_VK_SUCCESS(err);
2479
2480 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2481 // Set scissor as dynamic to avoid second error
2482 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2483 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2484 dyn_state_ci.dynamicStateCount = 1;
2485 dyn_state_ci.pDynamicStates = &sc_state;
2486
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002487 VkPipelineShaderStageCreateInfo shaderStages[2];
2488 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002489
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002490 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2491 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002492 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002493 shaderStages[0] = vs.GetStageCreateInfo();
2494 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002495
2496 VkGraphicsPipelineCreateInfo gp_ci = {};
2497 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002498 gp_ci.stageCount = 2;
2499 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002500 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2501 gp_ci.pDynamicState = &dyn_state_ci;
2502 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2503 gp_ci.layout = pipeline_layout;
2504 gp_ci.renderPass = renderPass();
2505
2506 VkPipelineCacheCreateInfo pc_ci = {};
2507 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2508
2509 VkPipeline pipeline;
2510 VkPipelineCache pipelineCache;
2511
Chia-I Wu69f40122015-10-26 21:10:41 +08002512 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002513 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002514 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002515
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002516 if (!m_errorMonitor->DesiredMsgFound()) {
2517 FAIL() << "Did not receive Error 'Gfx Pipeline pViewportState is null. Even if...'";
2518 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002519 }
2520
Chia-I Wu69f40122015-10-26 21:10:41 +08002521 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2522 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2523 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2524 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002525}
2526// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002527// Then run second test where dynamic scissor count doesn't match PSO scissor count
2528TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002529{
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002530 VkResult err;
2531
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002532 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2533 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
2534
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002535 ASSERT_NO_FATAL_FAILURE(InitState());
2536 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002537
Chia-I Wuc51b1212015-10-27 19:25:11 +08002538 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002539 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002540 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002541
2542 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2543 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002544 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002545 ds_pool_ci.poolSizeCount = 1;
2546 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002547
2548 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002549 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002550 ASSERT_VK_SUCCESS(err);
2551
2552 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002553 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002554 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002555 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002556 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2557
2558 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2559 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002560 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002561 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002562
2563 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002564 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002565 ASSERT_VK_SUCCESS(err);
2566
2567 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002568 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002569 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002570 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002571 alloc_info.descriptorPool = ds_pool;
2572 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002573 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002574 ASSERT_VK_SUCCESS(err);
2575
2576 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2577 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002578 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002579 pipeline_layout_ci.pSetLayouts = &ds_layout;
2580
2581 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002582 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002583 ASSERT_VK_SUCCESS(err);
2584
2585 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2586 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2587 vp_state_ci.viewportCount = 1;
2588 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2589 vp_state_ci.scissorCount = 1;
2590 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2591
2592 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2593 // Set scissor as dynamic to avoid that error
2594 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2595 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2596 dyn_state_ci.dynamicStateCount = 1;
2597 dyn_state_ci.pDynamicStates = &sc_state;
2598
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002599 VkPipelineShaderStageCreateInfo shaderStages[2];
2600 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002601
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002602 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2603 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002604 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002605 shaderStages[0] = vs.GetStageCreateInfo();
2606 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002607
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002608 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2609 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2610 vi_ci.pNext = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002611 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002612 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002613 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002614 vi_ci.pVertexAttributeDescriptions = nullptr;
2615
2616 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2617 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2618 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2619
Chia-I Wu1f851912015-10-27 18:04:07 +08002620 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +08002621 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002622 rs_ci.pNext = nullptr;
2623
2624 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2625 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2626 cb_ci.pNext = nullptr;
2627
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002628 VkGraphicsPipelineCreateInfo gp_ci = {};
2629 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002630 gp_ci.stageCount = 2;
2631 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002632 gp_ci.pVertexInputState = &vi_ci;
2633 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002634 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu1f851912015-10-27 18:04:07 +08002635 gp_ci.pRasterizationState = &rs_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002636 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002637 gp_ci.pDynamicState = &dyn_state_ci;
2638 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2639 gp_ci.layout = pipeline_layout;
2640 gp_ci.renderPass = renderPass();
2641
2642 VkPipelineCacheCreateInfo pc_ci = {};
2643 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2644
2645 VkPipeline pipeline;
2646 VkPipelineCache pipelineCache;
2647
Chia-I Wu69f40122015-10-26 21:10:41 +08002648 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002649 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002650 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002651
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002652 if (!m_errorMonitor->DesiredMsgFound()) {
2653 FAIL() << "Did not recieve Error 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...'";
2654 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002655 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002656
2657
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002658 // Now hit second fail case where we set scissor w/ different count than PSO
2659 // First need to successfully create the PSO from above by setting pViewports
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002660 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2661 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.");
2662
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002663 VkViewport vp = {}; // Just need dummy vp to point to
2664 vp_state_ci.pViewports = &vp;
Chia-I Wu69f40122015-10-26 21:10:41 +08002665 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002666 ASSERT_VK_SUCCESS(err);
2667 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08002668 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002669 VkRect2D scissors[2] = {}; // don't care about data
2670 // Count of 2 doesn't match PSO count of 1
Chia-I Wu1f851912015-10-27 18:04:07 +08002671 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 2, scissors);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002672 Draw(1, 0, 0, 0);
2673
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002674 if (!m_errorMonitor->DesiredMsgFound()) {
2675 FAIL() << "Did not receive Error 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...'";
2676 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002677 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002678
Chia-I Wu69f40122015-10-26 21:10:41 +08002679 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2680 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2681 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2682 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002683}
2684// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002685// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2686TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002687{
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002688 VkResult err;
2689
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002690 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2691 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
2692
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002693 ASSERT_NO_FATAL_FAILURE(InitState());
2694 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002695
Chia-I Wuc51b1212015-10-27 19:25:11 +08002696 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002697 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002698 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002699
2700 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2701 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002702 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002703 ds_pool_ci.poolSizeCount = 1;
2704 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002705
2706 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002707 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002708 ASSERT_VK_SUCCESS(err);
2709
2710 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002711 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002712 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002713 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002714 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2715
2716 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2717 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002718 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002719 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002720
2721 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002722 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002723 ASSERT_VK_SUCCESS(err);
2724
2725 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002726 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002727 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002728 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002729 alloc_info.descriptorPool = ds_pool;
2730 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002731 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002732 ASSERT_VK_SUCCESS(err);
2733
2734 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2735 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002736 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002737 pipeline_layout_ci.pSetLayouts = &ds_layout;
2738
2739 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002740 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002741 ASSERT_VK_SUCCESS(err);
2742
2743 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2744 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2745 vp_state_ci.scissorCount = 1;
2746 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2747 vp_state_ci.viewportCount = 1;
2748 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2749
2750 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2751 // Set scissor as dynamic to avoid that error
2752 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2753 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2754 dyn_state_ci.dynamicStateCount = 1;
2755 dyn_state_ci.pDynamicStates = &vp_state;
2756
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002757 VkPipelineShaderStageCreateInfo shaderStages[2];
2758 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002759
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002760 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2761 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002762 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002763 shaderStages[0] = vs.GetStageCreateInfo();
2764 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002765
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002766 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2767 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2768 vi_ci.pNext = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002769 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002770 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002771 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002772 vi_ci.pVertexAttributeDescriptions = nullptr;
2773
2774 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2775 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2776 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2777
Chia-I Wu1f851912015-10-27 18:04:07 +08002778 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +08002779 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002780 rs_ci.pNext = nullptr;
2781
2782 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2783 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2784 cb_ci.pNext = nullptr;
2785
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002786 VkGraphicsPipelineCreateInfo gp_ci = {};
2787 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002788 gp_ci.stageCount = 2;
2789 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002790 gp_ci.pVertexInputState = &vi_ci;
2791 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002792 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu1f851912015-10-27 18:04:07 +08002793 gp_ci.pRasterizationState = &rs_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002794 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002795 gp_ci.pDynamicState = &dyn_state_ci;
2796 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2797 gp_ci.layout = pipeline_layout;
2798 gp_ci.renderPass = renderPass();
2799
2800 VkPipelineCacheCreateInfo pc_ci = {};
2801 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2802
2803 VkPipeline pipeline;
2804 VkPipelineCache pipelineCache;
2805
Chia-I Wu69f40122015-10-26 21:10:41 +08002806 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002807 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002808 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002809
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002810 if (!m_errorMonitor->DesiredMsgFound()) {
2811 FAIL() << "Did not recieve Error 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...'";
2812 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002813 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002814
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002815 // Now hit second fail case where we set scissor w/ different count than PSO
2816 // First need to successfully create the PSO from above by setting pViewports
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002817 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2818 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.");
2819
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002820 VkRect2D sc = {}; // Just need dummy vp to point to
2821 vp_state_ci.pScissors = &sc;
Chia-I Wu69f40122015-10-26 21:10:41 +08002822 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002823 ASSERT_VK_SUCCESS(err);
2824 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08002825 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002826 VkViewport viewports[2] = {}; // don't care about data
2827 // Count of 2 doesn't match PSO count of 1
Chia-I Wu1f851912015-10-27 18:04:07 +08002828 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 2, viewports);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002829 Draw(1, 0, 0, 0);
2830
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002831 if (!m_errorMonitor->DesiredMsgFound()) {
2832 FAIL() << "Did not receive Error 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...'";
2833 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002834 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002835
Chia-I Wu69f40122015-10-26 21:10:41 +08002836 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2837 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2838 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2839 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002840}
2841
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002842TEST_F(VkLayerTest, NullRenderPass)
2843{
2844 // Bind a NULL RenderPass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002845 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2846 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002847
2848 ASSERT_NO_FATAL_FAILURE(InitState());
2849 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002850
Tony Barbour1490c912015-07-28 10:17:20 -06002851 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002852 // Don't care about RenderPass handle b/c error should be flagged before that
Chia-I Wuc51b1212015-10-27 19:25:11 +08002853 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002854
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002855 if (!m_errorMonitor->DesiredMsgFound()) {
2856 FAIL() << "Did not receive Error 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
2857 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002858 }
2859}
2860
Tobin Ehlis254eca02015-06-25 15:46:59 -06002861TEST_F(VkLayerTest, RenderPassWithinRenderPass)
2862{
2863 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002864 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2865 "It is invalid to issue this call inside an active render pass");
Tobin Ehlis254eca02015-06-25 15:46:59 -06002866
2867 ASSERT_NO_FATAL_FAILURE(InitState());
2868 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis254eca02015-06-25 15:46:59 -06002869
Tony Barbour1490c912015-07-28 10:17:20 -06002870 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002871 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002872 VkRenderPassBeginInfo rp_begin = {};
2873 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
2874 rp_begin.pNext = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002875 rp_begin.renderPass = renderPass();
2876 rp_begin.framebuffer = framebuffer();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002877
Chia-I Wuc51b1212015-10-27 19:25:11 +08002878 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002879
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002880 if (!m_errorMonitor->DesiredMsgFound()) {
2881 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2882 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002883 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002884}
2885
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002886TEST_F(VkLayerTest, FillBufferWithinRenderPass)
2887{
2888 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002889 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2890 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002891
2892 ASSERT_NO_FATAL_FAILURE(InitState());
2893 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002894
2895 // Renderpass is started here
2896 BeginCommandBuffer();
2897
2898 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08002899 vk_testing::Buffer dstBuffer;
2900 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002901
Chia-I Wu1f851912015-10-27 18:04:07 +08002902 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002903
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002904 if (!m_errorMonitor->DesiredMsgFound()) {
2905 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2906 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002907 }
2908}
2909
2910TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
2911{
2912 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002913 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2914 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002915
2916 ASSERT_NO_FATAL_FAILURE(InitState());
2917 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002918
2919 // Renderpass is started here
2920 BeginCommandBuffer();
2921
2922 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08002923 vk_testing::Buffer dstBuffer;
2924 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002925
Chia-I Wu1f851912015-10-27 18:04:07 +08002926 VkDeviceSize dstOffset = 0;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002927 VkDeviceSize dataSize = 1024;
2928 const uint32_t *pData = NULL;
2929
Chia-I Wu1f851912015-10-27 18:04:07 +08002930 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002931
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002932 if (!m_errorMonitor->DesiredMsgFound()) {
2933 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2934 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002935 }
2936}
2937
2938TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
2939{
2940 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002941 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2942 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002943
2944 ASSERT_NO_FATAL_FAILURE(InitState());
2945 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002946
2947 // Renderpass is started here
2948 BeginCommandBuffer();
2949
2950 VkClearColorValue clear_color = {0};
2951 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2952 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2953 const int32_t tex_width = 32;
2954 const int32_t tex_height = 32;
2955 VkImageCreateInfo image_create_info = {};
2956 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2957 image_create_info.pNext = NULL;
2958 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2959 image_create_info.format = tex_format;
2960 image_create_info.extent.width = tex_width;
2961 image_create_info.extent.height = tex_height;
2962 image_create_info.extent.depth = 1;
2963 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06002964 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08002965 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002966 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2967 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2968
Chia-I Wu1f851912015-10-27 18:04:07 +08002969 vk_testing::Image dstImage;
2970 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002971
2972 const VkImageSubresourceRange range =
2973 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
2974
Chia-I Wu1f851912015-10-27 18:04:07 +08002975 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(),
2976 dstImage.handle(),
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002977 VK_IMAGE_LAYOUT_GENERAL,
2978 &clear_color,
2979 1,
2980 &range);
2981
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002982 if (!m_errorMonitor->DesiredMsgFound()) {
2983 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2984 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002985 }
2986}
2987
2988TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
2989{
2990 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002991 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2992 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002993
2994 ASSERT_NO_FATAL_FAILURE(InitState());
2995 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002996
2997 // Renderpass is started here
2998 BeginCommandBuffer();
2999
3000 VkClearDepthStencilValue clear_value = {0};
3001 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3002 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
3003 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3004 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
3005 image_create_info.extent.width = 64;
3006 image_create_info.extent.height = 64;
3007 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3008 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
3009
Chia-I Wu1f851912015-10-27 18:04:07 +08003010 vk_testing::Image dstImage;
3011 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003012
3013 const VkImageSubresourceRange range =
3014 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
3015
Chia-I Wu1f851912015-10-27 18:04:07 +08003016 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(),
3017 dstImage.handle(),
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003018 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
3019 &clear_value,
3020 1,
3021 &range);
3022
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003023 if (!m_errorMonitor->DesiredMsgFound()) {
3024 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3025 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003026 }
3027}
3028
3029TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
3030{
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003031 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003032 VkResult err;
3033
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003034 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3035 "vkCmdClearAttachments: This call must be issued inside an active render pass");
3036
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003037 ASSERT_NO_FATAL_FAILURE(InitState());
3038 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003039
3040 // Start no RenderPass
Chia-I Wu1f851912015-10-27 18:04:07 +08003041 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003042 ASSERT_VK_SUCCESS(err);
3043
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003044 VkClearAttachment color_attachment;
3045 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3046 color_attachment.clearValue.color.float32[0] = 0;
3047 color_attachment.clearValue.color.float32[1] = 0;
3048 color_attachment.clearValue.color.float32[2] = 0;
3049 color_attachment.clearValue.color.float32[3] = 0;
3050 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06003051 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Chia-I Wu1f851912015-10-27 18:04:07 +08003052 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(),
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003053 1, &color_attachment,
3054 1, &clear_rect);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003055
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003056 if (!m_errorMonitor->DesiredMsgFound()) {
3057 FAIL() << "Did not receive Error 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
3058 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003059 }
3060}
3061
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003062TEST_F(VkLayerTest, InvalidDynamicStateObject)
3063{
3064 // Create a valid cmd buffer
3065 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06003066 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
3067 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003068}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06003069
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003070TEST_F(VkLayerTest, IdxBufferAlignmentError)
3071{
3072 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003073 VkResult err;
3074
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003075 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3076 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
3077
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003078 ASSERT_NO_FATAL_FAILURE(InitState());
3079 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003080 uint32_t qfi = 0;
3081 VkBufferCreateInfo buffCI = {};
3082 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3083 buffCI.size = 1024;
3084 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
Chia-I Wu763a7492015-10-26 20:48:51 +08003085 buffCI.queueFamilyIndexCount = 1;
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003086 buffCI.pQueueFamilyIndices = &qfi;
3087
3088 VkBuffer ib;
Chia-I Wu69f40122015-10-26 21:10:41 +08003089 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003090 ASSERT_VK_SUCCESS(err);
3091
3092 BeginCommandBuffer();
3093 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08003094 //vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003095 // Should error before calling to driver so don't care about actual data
Chia-I Wu1f851912015-10-27 18:04:07 +08003096 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003097
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003098 if (!m_errorMonitor->DesiredMsgFound()) {
3099 FAIL() << "Did not receive Error 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...'";
3100 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003101 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003102
Chia-I Wu69f40122015-10-26 21:10:41 +08003103 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003104}
3105
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003106TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
3107{
3108 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003109
3110 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3111 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003112
3113 ASSERT_NO_FATAL_FAILURE(InitState());
3114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003115
3116 BeginCommandBuffer();
3117 //ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08003118 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
3119 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003120
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003121 if (!m_errorMonitor->DesiredMsgFound()) {
3122 FAIL() << "Did not receive Error 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer '";
3123 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003124 }
3125}
3126
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003127TEST_F(VkLayerTest, DSTypeMismatch)
3128{
3129 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003130 VkResult err;
3131
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003132 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3133 "Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match ");
3134
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003135 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003136 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003137 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003138 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003139 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003140
3141 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3142 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3143 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003144 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003145 ds_pool_ci.poolSizeCount = 1;
3146 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003147
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003148 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003149 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003150 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003151 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003152 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003153 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003154 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003155 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3156 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003157
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003158 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3159 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3160 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003161 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003162 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003163
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003164 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003165 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003166 ASSERT_VK_SUCCESS(err);
3167
3168 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003169 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003170 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003171 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003172 alloc_info.descriptorPool = ds_pool;
3173 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003174 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003175 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003176
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003177 VkSamplerCreateInfo sampler_ci = {};
3178 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3179 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003180 sampler_ci.magFilter = VK_FILTER_NEAREST;
3181 sampler_ci.minFilter = VK_FILTER_NEAREST;
3182 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003183 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3184 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3185 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003186 sampler_ci.mipLodBias = 1.0;
3187 sampler_ci.maxAnisotropy = 1;
3188 sampler_ci.compareEnable = VK_FALSE;
3189 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3190 sampler_ci.minLod = 1.0;
3191 sampler_ci.maxLod = 1.0;
3192 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003193 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3194
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003195 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003196 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003197 ASSERT_VK_SUCCESS(err);
3198
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003199 VkDescriptorImageInfo info = {};
3200 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003201
3202 VkWriteDescriptorSet descriptor_write;
3203 memset(&descriptor_write, 0, sizeof(descriptor_write));
3204 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003205 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08003206 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003207 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003208 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003209 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003210
3211 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3212
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003213 if (!m_errorMonitor->DesiredMsgFound()) {
3214 FAIL() << "Did not receive Error 'Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...'";
3215 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003216 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003217
Chia-I Wu69f40122015-10-26 21:10:41 +08003218 vkDestroySampler(m_device->device(), sampler, NULL);
3219 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3220 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003221}
3222
3223TEST_F(VkLayerTest, DSUpdateOutOfBounds)
3224{
3225 // For overlapping Update, have arrayIndex exceed that of layout
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003226 VkResult err;
3227
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003228 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3229 "Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding");
3230
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003231 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003232 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003233 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003234 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003235 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003236
3237 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3238 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3239 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003240 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003241 ds_pool_ci.poolSizeCount = 1;
3242 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003243
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003244 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003245 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003246 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003247
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003248 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003249 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003250 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003251 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003252 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3253 dsl_binding.pImmutableSamplers = NULL;
3254
3255 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3256 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3257 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003258 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003259 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003260
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003261 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003262 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003263 ASSERT_VK_SUCCESS(err);
3264
3265 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003266 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003267 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003268 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003269 alloc_info.descriptorPool = ds_pool;
3270 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003271 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003272 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003273
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003274 VkSamplerCreateInfo sampler_ci = {};
3275 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3276 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003277 sampler_ci.magFilter = VK_FILTER_NEAREST;
3278 sampler_ci.minFilter = VK_FILTER_NEAREST;
3279 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003280 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3281 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3282 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003283 sampler_ci.mipLodBias = 1.0;
3284 sampler_ci.maxAnisotropy = 1;
3285 sampler_ci.compareEnable = VK_FALSE;
3286 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3287 sampler_ci.minLod = 1.0;
3288 sampler_ci.maxLod = 1.0;
3289 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003290 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003291
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003292 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003293 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003294 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003295
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003296 VkDescriptorImageInfo info = {};
3297 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003298
3299 VkWriteDescriptorSet descriptor_write;
3300 memset(&descriptor_write, 0, sizeof(descriptor_write));
3301 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003302 descriptor_write.dstSet = descriptorSet;
3303 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wu763a7492015-10-26 20:48:51 +08003304 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003305 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003306 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003307 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003308
3309 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3310
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003311 if (!m_errorMonitor->DesiredMsgFound()) {
3312 FAIL() << "Did not receive Error 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
3313 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003314 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003315
Chia-I Wu69f40122015-10-26 21:10:41 +08003316 vkDestroySampler(m_device->device(), sampler, NULL);
3317 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3318 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003319}
3320
3321TEST_F(VkLayerTest, InvalidDSUpdateIndex)
3322{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003323 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003324 VkResult err;
3325
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003326 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3327 " does not have binding to match update binding ");
3328
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003329 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003330 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003331 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003332 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003333 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003334
3335 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3336 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3337 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003338 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003339 ds_pool_ci.poolSizeCount = 1;
3340 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003341
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003342 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003343 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003344 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003345
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003346 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003347 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003348 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003349 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003350 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3351 dsl_binding.pImmutableSamplers = NULL;
3352
3353 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3354 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3355 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003356 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003357 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003358 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003359 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003360 ASSERT_VK_SUCCESS(err);
3361
3362 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003363 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003364 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003365 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003366 alloc_info.descriptorPool = ds_pool;
3367 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003368 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003369 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003370
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003371 VkSamplerCreateInfo sampler_ci = {};
3372 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3373 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003374 sampler_ci.magFilter = VK_FILTER_NEAREST;
3375 sampler_ci.minFilter = VK_FILTER_NEAREST;
3376 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003377 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3378 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3379 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003380 sampler_ci.mipLodBias = 1.0;
3381 sampler_ci.maxAnisotropy = 1;
3382 sampler_ci.compareEnable = VK_FALSE;
3383 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3384 sampler_ci.minLod = 1.0;
3385 sampler_ci.maxLod = 1.0;
3386 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003387 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003388
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003389 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003390 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003391 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003392
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003393 VkDescriptorImageInfo info = {};
3394 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003395
3396 VkWriteDescriptorSet descriptor_write;
3397 memset(&descriptor_write, 0, sizeof(descriptor_write));
3398 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003399 descriptor_write.dstSet = descriptorSet;
3400 descriptor_write.dstBinding = 2;
Chia-I Wu763a7492015-10-26 20:48:51 +08003401 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003402 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003403 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003404 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003405
3406 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3407
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003408 if (!m_errorMonitor->DesiredMsgFound()) {
3409 FAIL() << "Did not receive Error 'Descriptor Set <blah> does not have binding to match update binding '";
3410 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003411 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003412
Chia-I Wu69f40122015-10-26 21:10:41 +08003413 vkDestroySampler(m_device->device(), sampler, NULL);
3414 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3415 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003416}
3417
3418TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3419{
3420 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003421 VkResult err;
3422
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003423 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3424 "Unexpected UPDATE struct of type ");
3425
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003426 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003427
Chia-I Wuc51b1212015-10-27 19:25:11 +08003428 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003429 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003430 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003431
3432 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3433 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3434 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003435 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003436 ds_pool_ci.poolSizeCount = 1;
3437 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003438
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003439 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003440 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003441 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003442 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003443 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003444 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003445 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003446 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3447 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003448
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003449 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3450 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3451 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003452 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003453 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003454
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003455 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003456 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003457 ASSERT_VK_SUCCESS(err);
3458
3459 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003460 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003461 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003462 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003463 alloc_info.descriptorPool = ds_pool;
3464 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003465 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003466 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003467
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003468 VkSamplerCreateInfo sampler_ci = {};
3469 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3470 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003471 sampler_ci.magFilter = VK_FILTER_NEAREST;
3472 sampler_ci.minFilter = VK_FILTER_NEAREST;
3473 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003474 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3475 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3476 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003477 sampler_ci.mipLodBias = 1.0;
3478 sampler_ci.maxAnisotropy = 1;
3479 sampler_ci.compareEnable = VK_FALSE;
3480 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3481 sampler_ci.minLod = 1.0;
3482 sampler_ci.maxLod = 1.0;
3483 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003484 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003485 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003486 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003487 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003488
3489
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003490 VkDescriptorImageInfo info = {};
3491 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003492
3493 VkWriteDescriptorSet descriptor_write;
3494 memset(&descriptor_write, 0, sizeof(descriptor_write));
3495 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu1f851912015-10-27 18:04:07 +08003496 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08003497 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003498 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003499 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003500 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003501
3502 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3503
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003504 if (!m_errorMonitor->DesiredMsgFound()) {
3505 FAIL() << "Did not receive Error 'Unexpected UPDATE struct of type '";
3506 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003507 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003508
Chia-I Wu69f40122015-10-26 21:10:41 +08003509 vkDestroySampler(m_device->device(), sampler, NULL);
3510 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3511 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003512}
3513
Tobin Ehlisb46be812015-10-23 16:00:08 -06003514TEST_F(VkLayerTest, SampleDescriptorUpdateError)
3515{
3516 // Create a single Sampler descriptor and send it an invalid Sampler
Tobin Ehlisb46be812015-10-23 16:00:08 -06003517 VkResult err;
3518
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003519 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3520 "Attempt to update descriptor with invalid sampler 0xbaadbeef");
3521
Tobin Ehlisb46be812015-10-23 16:00:08 -06003522 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb46be812015-10-23 16:00:08 -06003523 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied code
Chia-I Wuc51b1212015-10-27 19:25:11 +08003524 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003525 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003526 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003527
3528 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3529 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3530 ds_pool_ci.pNext = NULL;
3531 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003532 ds_pool_ci.poolSizeCount = 1;
3533 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003534
3535 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003536 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003537 ASSERT_VK_SUCCESS(err);
3538
3539 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003540 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003541 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003542 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003543 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3544 dsl_binding.pImmutableSamplers = NULL;
3545
3546 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3547 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3548 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003549 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003550 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003551 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003552 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003553 ASSERT_VK_SUCCESS(err);
3554
3555 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003556 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003557 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003558 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003559 alloc_info.descriptorPool = ds_pool;
3560 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003561 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003562 ASSERT_VK_SUCCESS(err);
3563
Chia-I Wue420a332015-10-26 20:04:44 +08003564 VkSampler sampler = (VkSampler) 0xbaadbeef; // Sampler with invalid handle
Tobin Ehlisb46be812015-10-23 16:00:08 -06003565
3566 VkDescriptorImageInfo descriptor_info;
3567 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3568 descriptor_info.sampler = sampler;
3569
3570 VkWriteDescriptorSet descriptor_write;
3571 memset(&descriptor_write, 0, sizeof(descriptor_write));
3572 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003573 descriptor_write.dstSet = descriptorSet;
3574 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003575 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003576 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3577 descriptor_write.pImageInfo = &descriptor_info;
3578
3579 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3580
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003581 if (!m_errorMonitor->DesiredMsgFound()) {
3582 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid sampler...'";
3583 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06003584 }
3585
Chia-I Wu69f40122015-10-26 21:10:41 +08003586 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3587 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003588}
3589
3590TEST_F(VkLayerTest, ImageViewDescriptorUpdateError)
3591{
3592 // Create a single combined Image/Sampler descriptor and send it an invalid imageView
Tobin Ehlisb46be812015-10-23 16:00:08 -06003593 VkResult err;
3594
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003595 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3596 "Attempt to update descriptor with invalid imageView 0xbaadbeef");
3597
Tobin Ehlisb46be812015-10-23 16:00:08 -06003598 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wuc51b1212015-10-27 19:25:11 +08003599 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003600 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003601 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003602
3603 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3604 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3605 ds_pool_ci.pNext = NULL;
3606 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003607 ds_pool_ci.poolSizeCount = 1;
3608 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003609
3610 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003611 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003612 ASSERT_VK_SUCCESS(err);
3613
3614 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003615 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003616 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003617 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003618 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3619 dsl_binding.pImmutableSamplers = NULL;
3620
3621 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3622 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3623 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003624 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003625 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003626 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003627 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003628 ASSERT_VK_SUCCESS(err);
3629
3630 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003631 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003632 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003633 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003634 alloc_info.descriptorPool = ds_pool;
3635 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003636 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003637 ASSERT_VK_SUCCESS(err);
3638
3639 VkSamplerCreateInfo sampler_ci = {};
3640 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3641 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003642 sampler_ci.magFilter = VK_FILTER_NEAREST;
3643 sampler_ci.minFilter = VK_FILTER_NEAREST;
3644 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003645 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3646 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3647 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003648 sampler_ci.mipLodBias = 1.0;
3649 sampler_ci.maxAnisotropy = 1;
3650 sampler_ci.compareEnable = VK_FALSE;
3651 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3652 sampler_ci.minLod = 1.0;
3653 sampler_ci.maxLod = 1.0;
3654 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3655 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3656
3657 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003658 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003659 ASSERT_VK_SUCCESS(err);
3660
Chia-I Wue420a332015-10-26 20:04:44 +08003661 VkImageView view = (VkImageView) 0xbaadbeef; // invalid imageView object
Tobin Ehlisb46be812015-10-23 16:00:08 -06003662
3663 VkDescriptorImageInfo descriptor_info;
3664 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3665 descriptor_info.sampler = sampler;
3666 descriptor_info.imageView = view;
3667
3668 VkWriteDescriptorSet descriptor_write;
3669 memset(&descriptor_write, 0, sizeof(descriptor_write));
3670 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003671 descriptor_write.dstSet = descriptorSet;
3672 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003673 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003674 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3675 descriptor_write.pImageInfo = &descriptor_info;
3676
3677 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3678
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003679 if (!m_errorMonitor->DesiredMsgFound()) {
3680 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid imageView...'";
3681 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06003682 }
3683
Chia-I Wu69f40122015-10-26 21:10:41 +08003684 vkDestroySampler(m_device->device(), sampler, NULL);
3685 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3686 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003687}
3688
Tobin Ehlis3e676262015-10-27 16:35:27 -06003689TEST_F(VkLayerTest, CopyDescriptorUpdateErrors)
3690{
3691 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update into the other
Tobin Ehlis3e676262015-10-27 16:35:27 -06003692 VkResult err;
3693
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003694 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3695 "Copy descriptor update index 0, update count #1, has src update descriptor type VK_DESCRIPTOR_TYPE_SAMPLER ");
3696
Tobin Ehlis3e676262015-10-27 16:35:27 -06003697 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3e676262015-10-27 16:35:27 -06003698 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003699 VkDescriptorPoolSize ds_type_count[2] = {};
Tobin Ehlis3e676262015-10-27 16:35:27 -06003700 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003701 ds_type_count[0].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003702 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003703 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003704
3705 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3706 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3707 ds_pool_ci.pNext = NULL;
3708 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003709 ds_pool_ci.poolSizeCount = 2;
3710 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003711
3712 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003713 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003714 ASSERT_VK_SUCCESS(err);
3715 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003716 dsl_binding[0].binding = 0;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003717 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003718 dsl_binding[0].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003719 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3720 dsl_binding[0].pImmutableSamplers = NULL;
Chia-I Wub5689ee2015-10-31 00:31:16 +08003721 dsl_binding[1].binding = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003722 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003723 dsl_binding[1].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003724 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
3725 dsl_binding[1].pImmutableSamplers = NULL;
3726
3727 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3728 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3729 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003730 ds_layout_ci.bindingCount = 2;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003731 ds_layout_ci.pBinding = dsl_binding;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003732
3733 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003734 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003735 ASSERT_VK_SUCCESS(err);
3736
3737 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003738 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003739 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003740 alloc_info.setLayoutCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003741 alloc_info.descriptorPool = ds_pool;
3742 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003743 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003744 ASSERT_VK_SUCCESS(err);
3745
3746 VkSamplerCreateInfo sampler_ci = {};
3747 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3748 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003749 sampler_ci.magFilter = VK_FILTER_NEAREST;
3750 sampler_ci.minFilter = VK_FILTER_NEAREST;
3751 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003752 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3753 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3754 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003755 sampler_ci.mipLodBias = 1.0;
3756 sampler_ci.maxAnisotropy = 1;
3757 sampler_ci.compareEnable = VK_FALSE;
3758 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3759 sampler_ci.minLod = 1.0;
3760 sampler_ci.maxLod = 1.0;
3761 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3762 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3763
3764 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003765 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003766 ASSERT_VK_SUCCESS(err);
3767
3768 VkDescriptorImageInfo info = {};
3769 info.sampler = sampler;
3770
3771 VkWriteDescriptorSet descriptor_write;
3772 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
3773 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003774 descriptor_write.dstSet = descriptorSet;
3775 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wu763a7492015-10-26 20:48:51 +08003776 descriptor_write.descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003777 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3778 descriptor_write.pImageInfo = &info;
3779 // This write update should succeed
3780 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3781 // Now perform a copy update that fails due to type mismatch
3782 VkCopyDescriptorSet copy_ds_update;
3783 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3784 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3785 copy_ds_update.srcSet = descriptorSet;
3786 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
Chia-I Wu1f851912015-10-27 18:04:07 +08003787 copy_ds_update.dstSet = descriptorSet;
3788 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wu763a7492015-10-26 20:48:51 +08003789 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06003790 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3791
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003792 if (!m_errorMonitor->DesiredMsgFound()) {
3793 FAIL() << "Did not receive Error 'Copy descriptor update index 0, update count #1, has src update descriptor type_DESCRIPTOR_TYPE_SAMPLER'";
3794 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06003795 }
3796 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003797 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3798 "Copy descriptor update 0 has srcBinding 3 which is out of bounds ");
Tobin Ehlis3e676262015-10-27 16:35:27 -06003799 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3800 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3801 copy_ds_update.srcSet = descriptorSet;
3802 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu1f851912015-10-27 18:04:07 +08003803 copy_ds_update.dstSet = descriptorSet;
3804 copy_ds_update.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003805 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06003806 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3807
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003808 if (!m_errorMonitor->DesiredMsgFound()) {
3809 FAIL() << "Did not receive Error 'Copy descriptor update 0 has srcBinding 3 which is out of bounds...'";
3810 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06003811 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003812
Tobin Ehlis3e676262015-10-27 16:35:27 -06003813 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003814 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3815 "Copy descriptor src update is out of bounds for matching binding 1 ");
3816
Tobin Ehlis3e676262015-10-27 16:35:27 -06003817 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3818 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3819 copy_ds_update.srcSet = descriptorSet;
3820 copy_ds_update.srcBinding = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08003821 copy_ds_update.dstSet = descriptorSet;
3822 copy_ds_update.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003823 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis3e676262015-10-27 16:35:27 -06003824 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3825
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003826 if (!m_errorMonitor->DesiredMsgFound()) {
3827 FAIL() << "Did not receive Error 'Copy descriptor src update is out of bounds for matching binding 1...'";
3828 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06003829 }
3830
Chia-I Wu69f40122015-10-26 21:10:41 +08003831 vkDestroySampler(m_device->device(), sampler, NULL);
3832 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3833 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003834}
3835
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003836TEST_F(VkLayerTest, NumSamplesMismatch)
3837{
Chia-I Wu1f851912015-10-27 18:04:07 +08003838 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003839 VkResult err;
3840
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003841 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3842 "Num samples mismatch! ");
3843
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003844 ASSERT_NO_FATAL_FAILURE(InitState());
3845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wuc51b1212015-10-27 19:25:11 +08003846 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003847 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003848 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003849
3850 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003851 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3852 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003853 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003854 ds_pool_ci.poolSizeCount = 1;
3855 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003856
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003857 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003858 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003859 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003860
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003861 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003862 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003863 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003864 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003865 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3866 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003867
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003868 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3869 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3870 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003871 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003872 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003873
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003874 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003875 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003876 ASSERT_VK_SUCCESS(err);
3877
3878 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003879 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003880 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003881 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003882 alloc_info.descriptorPool = ds_pool;
3883 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003884 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003885 ASSERT_VK_SUCCESS(err);
3886
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003887 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3888 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3889 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08003890 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003891 pipe_ms_state_ci.sampleShadingEnable = 0;
3892 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003893 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003894
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003895 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3896 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3897 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003898 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003899 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003900
3901 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003902 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003903 ASSERT_VK_SUCCESS(err);
3904
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003905 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3906 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003907 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003908 VkPipelineObj pipe(m_device);
3909 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003910 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003911 pipe.SetMSAA(&pipe_ms_state_ci);
3912 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003913
Tony Barbour1490c912015-07-28 10:17:20 -06003914 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08003915 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003916
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003917 if (!m_errorMonitor->DesiredMsgFound()) {
3918 FAIL() << "Did not recieve Error 'Num samples mismatch!...'";
3919 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003920 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003921
Chia-I Wu69f40122015-10-26 21:10:41 +08003922 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3923 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3924 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003925}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003926
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003927TEST_F(VkLayerTest, ClearCmdNoDraw)
3928{
Chia-I Wu1f851912015-10-27 18:04:07 +08003929 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003930 VkResult err;
3931
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003932 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
3933 "vkCmdClearAttachments() issued on CB object ");
3934
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003935 ASSERT_NO_FATAL_FAILURE(InitState());
3936 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003937
Chia-I Wuc51b1212015-10-27 19:25:11 +08003938 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003939 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003940 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003941
3942 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3943 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3944 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003945 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003946 ds_pool_ci.poolSizeCount = 1;
3947 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003948
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003949 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003950 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003951 ASSERT_VK_SUCCESS(err);
3952
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003953 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003954 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003955 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003956 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003957 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3958 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003959
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003960 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3961 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3962 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003963 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003964 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003965
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003966 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003967 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003968 ASSERT_VK_SUCCESS(err);
3969
3970 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003971 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003972 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003973 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003974 alloc_info.descriptorPool = ds_pool;
3975 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003976 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003977 ASSERT_VK_SUCCESS(err);
3978
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003979 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3980 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3981 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08003982 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003983 pipe_ms_state_ci.sampleShadingEnable = 0;
3984 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003985 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003986
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003987 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3988 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3989 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003990 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003991 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003992
3993 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003994 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003995 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003996
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003997 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003998 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
3999 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4000
Tony Barbourd7d828b2015-08-06 10:16:07 -06004001 VkPipelineObj pipe(m_device);
4002 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004003 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004004 pipe.SetMSAA(&pipe_ms_state_ci);
4005 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06004006
4007 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004008
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004009 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
4010 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004011 VkClearAttachment color_attachment;
4012 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4013 color_attachment.clearValue.color.float32[0] = 1.0;
4014 color_attachment.clearValue.color.float32[1] = 1.0;
4015 color_attachment.clearValue.color.float32[2] = 1.0;
4016 color_attachment.clearValue.color.float32[3] = 1.0;
4017 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004018 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004019
Chia-I Wu1f851912015-10-27 18:04:07 +08004020 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004021
4022 if (!m_errorMonitor->DesiredMsgFound()) {
4023 FAIL() << "Did not receive Error 'vkCommandClearAttachments() issued on CB object...'";
4024 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004025 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004026
Chia-I Wu69f40122015-10-26 21:10:41 +08004027 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4028 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4029 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004030}
4031
Tobin Ehlise4076782015-06-24 15:53:07 -06004032TEST_F(VkLayerTest, VtxBufferBadIndex)
4033{
Chia-I Wu1f851912015-10-27 18:04:07 +08004034 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlise4076782015-06-24 15:53:07 -06004035 VkResult err;
4036
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004037 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4038 "Vtx Buffer Index 1 was bound, but no vtx buffers are attached to PSO.");
4039
Tobin Ehlise4076782015-06-24 15:53:07 -06004040 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06004041 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlise4076782015-06-24 15:53:07 -06004042 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004043
Chia-I Wuc51b1212015-10-27 19:25:11 +08004044 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004045 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08004046 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004047
4048 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4049 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4050 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004051 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08004052 ds_pool_ci.poolSizeCount = 1;
4053 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004054
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004055 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08004056 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06004057 ASSERT_VK_SUCCESS(err);
4058
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004059 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08004060 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004061 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08004062 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004063 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4064 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06004065
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004066 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4067 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4068 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004069 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08004070 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004071
Tobin Ehlise4076782015-06-24 15:53:07 -06004072 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004073 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06004074 ASSERT_VK_SUCCESS(err);
4075
4076 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004077 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004078 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08004079 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004080 alloc_info.descriptorPool = ds_pool;
4081 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08004082 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06004083 ASSERT_VK_SUCCESS(err);
4084
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004085 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4086 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4087 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004088 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004089 pipe_ms_state_ci.sampleShadingEnable = 0;
4090 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06004091 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06004092
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004093 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4094 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4095 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004096 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004097 pipeline_layout_ci.pSetLayouts = &ds_layout;
4098 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06004099
Chia-I Wu69f40122015-10-26 21:10:41 +08004100 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06004101 ASSERT_VK_SUCCESS(err);
4102
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004103 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4104 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004105 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06004106 VkPipelineObj pipe(m_device);
4107 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004108 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004109 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06004110 pipe.SetViewport(m_viewports);
4111 pipe.SetScissor(m_scissors);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004112 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06004113
4114 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08004115 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06004116 // Don't care about actual data, just need to get to draw to flag error
4117 static const float vbo_data[3] = {1.f, 0.f, 1.f};
4118 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
4119 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06004120 Draw(1, 0, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06004121
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004122 if (!m_errorMonitor->DesiredMsgFound()) {
4123 FAIL() << "Did not receive Error 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
4124 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise4076782015-06-24 15:53:07 -06004125 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004126
Chia-I Wu69f40122015-10-26 21:10:41 +08004127 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4128 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4129 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise4076782015-06-24 15:53:07 -06004130}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004131#endif // DRAW_STATE_TESTS
4132
Tobin Ehlis57e6a612015-05-26 16:11:58 -06004133#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06004134#if GTEST_IS_THREADSAFE
4135struct thread_data_struct {
Chia-I Wu1f851912015-10-27 18:04:07 +08004136 VkCommandBuffer commandBuffer;
Mike Stroyan09aae812015-05-12 16:00:45 -06004137 VkEvent event;
4138 bool bailout;
4139};
4140
4141extern "C" void *AddToCommandBuffer(void *arg)
4142{
4143 struct thread_data_struct *data = (struct thread_data_struct *) arg;
Mike Stroyan09aae812015-05-12 16:00:45 -06004144
4145 for (int i = 0; i<10000; i++) {
Chia-I Wucba6cea2015-10-31 00:31:16 +08004146 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyan09aae812015-05-12 16:00:45 -06004147 if (data->bailout) {
4148 break;
4149 }
4150 }
4151 return NULL;
4152}
4153
Chia-I Wu1f851912015-10-27 18:04:07 +08004154TEST_F(VkLayerTest, ThreadCommandBufferCollision)
Mike Stroyan09aae812015-05-12 16:00:45 -06004155{
Mike Stroyan7016f4f2015-07-13 14:45:35 -06004156 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06004157
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004158 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "THREADING ERROR");
4159
Mike Stroyan09aae812015-05-12 16:00:45 -06004160 ASSERT_NO_FATAL_FAILURE(InitState());
4161 ASSERT_NO_FATAL_FAILURE(InitViewport());
4162 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4163
Chia-I Wu1f851912015-10-27 18:04:07 +08004164 // Calls AllocateCommandBuffers
4165 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004166
4167 // Avoid creating RenderPass
Chia-I Wu1f851912015-10-27 18:04:07 +08004168 commandBuffer.BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06004169
4170 VkEventCreateInfo event_info;
4171 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06004172 VkResult err;
4173
4174 memset(&event_info, 0, sizeof(event_info));
4175 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4176
Chia-I Wu69f40122015-10-26 21:10:41 +08004177 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyan09aae812015-05-12 16:00:45 -06004178 ASSERT_VK_SUCCESS(err);
4179
Mike Stroyan09aae812015-05-12 16:00:45 -06004180 err = vkResetEvent(device(), event);
4181 ASSERT_VK_SUCCESS(err);
4182
4183 struct thread_data_struct data;
Chia-I Wu1f851912015-10-27 18:04:07 +08004184 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyan09aae812015-05-12 16:00:45 -06004185 data.event = event;
4186 data.bailout = false;
4187 m_errorMonitor->SetBailout(&data.bailout);
4188 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06004189 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06004190 // Add many entries to command buffer from this thread at the same time.
4191 AddToCommandBuffer(&data);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004192
Mike Stroyan7016f4f2015-07-13 14:45:35 -06004193 test_platform_thread_join(thread, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08004194 commandBuffer.EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06004195
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004196 if (!m_errorMonitor->DesiredMsgFound()) {
4197 FAIL() << "Did not receive Error 'THREADING ERROR' from using one VkCommandBufferObj in two threads";
4198 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan09aae812015-05-12 16:00:45 -06004199 }
4200
Chia-I Wu69f40122015-10-26 21:10:41 +08004201 vkDestroyEvent(device(), event, NULL);
Mike Stroyan09aae812015-05-12 16:00:45 -06004202}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004203#endif // GTEST_IS_THREADSAFE
4204#endif // THREADING_TESTS
4205
Chris Forbes5af3bf22015-05-25 11:13:08 +12004206#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004207TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
4208{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004209 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4210 "Shader is not SPIR-V");
4211
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004212 ASSERT_NO_FATAL_FAILURE(InitState());
4213 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4214
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004215 VkShaderModule module;
4216 VkShaderModuleCreateInfo moduleCreateInfo;
4217 struct icd_spv_header spv;
4218
4219 spv.magic = ICD_SPV_MAGIC;
4220 spv.version = ICD_SPV_VERSION;
4221 spv.gen_magic = 0;
4222
4223 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4224 moduleCreateInfo.pNext = NULL;
Chia-I Wu036b1612015-10-26 19:22:06 +08004225 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004226 moduleCreateInfo.codeSize = 4;
4227 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004228 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004229
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004230 if (!m_errorMonitor->DesiredMsgFound()) {
4231 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4232 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004233 }
4234}
4235
4236TEST_F(VkLayerTest, InvalidSPIRVMagic)
4237{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004238 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4239 "Shader is not SPIR-V");
4240
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004241 ASSERT_NO_FATAL_FAILURE(InitState());
4242 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4243
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004244 VkShaderModule module;
4245 VkShaderModuleCreateInfo moduleCreateInfo;
4246 struct icd_spv_header spv;
4247
4248 spv.magic = ~ICD_SPV_MAGIC;
4249 spv.version = ICD_SPV_VERSION;
4250 spv.gen_magic = 0;
4251
4252 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4253 moduleCreateInfo.pNext = NULL;
Chia-I Wu036b1612015-10-26 19:22:06 +08004254 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004255 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4256 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004257 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004258
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004259 if (!m_errorMonitor->DesiredMsgFound()) {
4260 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4261 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004262 }
4263}
4264
4265TEST_F(VkLayerTest, InvalidSPIRVVersion)
4266{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004267 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4268 "Shader is not SPIR-V");
4269
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004270 ASSERT_NO_FATAL_FAILURE(InitState());
4271 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4272
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004273 VkShaderModule module;
4274 VkShaderModuleCreateInfo moduleCreateInfo;
4275 struct icd_spv_header spv;
4276
4277 spv.magic = ICD_SPV_MAGIC;
4278 spv.version = ~ICD_SPV_VERSION;
4279 spv.gen_magic = 0;
4280
4281 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4282 moduleCreateInfo.pNext = NULL;
4283
Chia-I Wu036b1612015-10-26 19:22:06 +08004284 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004285 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4286 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004287 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004288
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004289 if (!m_errorMonitor->DesiredMsgFound()) {
4290 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4291 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004292 }
4293}
4294
Chris Forbes5af3bf22015-05-25 11:13:08 +12004295TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
4296{
Tony Barbour192f02b2015-11-06 14:21:31 -07004297 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_PERF_WARN_BIT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004298 "not consumed by fragment shader");
4299
Chris Forbes5af3bf22015-05-25 11:13:08 +12004300 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12004302
4303 char const *vsSource =
4304 "#version 140\n"
4305 "#extension GL_ARB_separate_shader_objects: require\n"
4306 "#extension GL_ARB_shading_language_420pack: require\n"
4307 "\n"
4308 "layout(location=0) out float x;\n"
4309 "void main(){\n"
4310 " gl_Position = vec4(1);\n"
4311 " x = 0;\n"
4312 "}\n";
4313 char const *fsSource =
4314 "#version 140\n"
4315 "#extension GL_ARB_separate_shader_objects: require\n"
4316 "#extension GL_ARB_shading_language_420pack: require\n"
4317 "\n"
4318 "layout(location=0) out vec4 color;\n"
4319 "void main(){\n"
4320 " color = vec4(1);\n"
4321 "}\n";
4322
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004323 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4324 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5af3bf22015-05-25 11:13:08 +12004325
4326 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004327 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12004328 pipe.AddShader(&vs);
4329 pipe.AddShader(&fs);
4330
Chris Forbes5af3bf22015-05-25 11:13:08 +12004331 VkDescriptorSetObj descriptorSet(m_device);
4332 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004333 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12004334
Tony Barboured132432015-08-04 16:23:11 -06004335 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12004336
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004337 if (!m_errorMonitor->DesiredMsgFound()) {
4338 FAIL() << "Did not receive Warning 'not consumed by fragment shader'";
4339 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5af3bf22015-05-25 11:13:08 +12004340 }
4341}
Chris Forbes5af3bf22015-05-25 11:13:08 +12004342
Chris Forbes3c10b852015-05-25 11:13:13 +12004343TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
4344{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004345 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4346 "not written by vertex shader");
4347
Chris Forbes3c10b852015-05-25 11:13:13 +12004348 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004349 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12004350
4351 char const *vsSource =
4352 "#version 140\n"
4353 "#extension GL_ARB_separate_shader_objects: require\n"
4354 "#extension GL_ARB_shading_language_420pack: require\n"
4355 "\n"
4356 "void main(){\n"
4357 " gl_Position = vec4(1);\n"
4358 "}\n";
4359 char const *fsSource =
4360 "#version 140\n"
4361 "#extension GL_ARB_separate_shader_objects: require\n"
4362 "#extension GL_ARB_shading_language_420pack: require\n"
4363 "\n"
4364 "layout(location=0) in float x;\n"
4365 "layout(location=0) out vec4 color;\n"
4366 "void main(){\n"
4367 " color = vec4(x);\n"
4368 "}\n";
4369
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004370 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4371 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes3c10b852015-05-25 11:13:13 +12004372
4373 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004374 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12004375 pipe.AddShader(&vs);
4376 pipe.AddShader(&fs);
4377
Chris Forbes3c10b852015-05-25 11:13:13 +12004378 VkDescriptorSetObj descriptorSet(m_device);
4379 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004380 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12004381
Tony Barboured132432015-08-04 16:23:11 -06004382 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12004383
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004384 if (!m_errorMonitor->DesiredMsgFound()) {
4385 FAIL() << "Did not receive Error 'not written by vertex shader'";
4386 m_errorMonitor->DumpFailureMsgs();
Chris Forbes3c10b852015-05-25 11:13:13 +12004387 }
4388}
4389
Chris Forbescc281692015-05-25 11:13:17 +12004390TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
4391{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004392 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4393 "Type mismatch on location 0");
4394
Chris Forbescc281692015-05-25 11:13:17 +12004395 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004396 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12004397
4398 char const *vsSource =
4399 "#version 140\n"
4400 "#extension GL_ARB_separate_shader_objects: require\n"
4401 "#extension GL_ARB_shading_language_420pack: require\n"
4402 "\n"
4403 "layout(location=0) out int x;\n"
4404 "void main(){\n"
4405 " x = 0;\n"
4406 " gl_Position = vec4(1);\n"
4407 "}\n";
4408 char const *fsSource =
4409 "#version 140\n"
4410 "#extension GL_ARB_separate_shader_objects: require\n"
4411 "#extension GL_ARB_shading_language_420pack: require\n"
4412 "\n"
4413 "layout(location=0) in float x;\n" /* VS writes int */
4414 "layout(location=0) out vec4 color;\n"
4415 "void main(){\n"
4416 " color = vec4(x);\n"
4417 "}\n";
4418
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004419 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4420 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbescc281692015-05-25 11:13:17 +12004421
4422 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004423 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12004424 pipe.AddShader(&vs);
4425 pipe.AddShader(&fs);
4426
Chris Forbescc281692015-05-25 11:13:17 +12004427 VkDescriptorSetObj descriptorSet(m_device);
4428 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004429 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12004430
Tony Barboured132432015-08-04 16:23:11 -06004431 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12004432
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004433 if (!m_errorMonitor->DesiredMsgFound()) {
4434 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
4435 m_errorMonitor->DumpFailureMsgs();
Chris Forbescc281692015-05-25 11:13:17 +12004436 }
4437}
4438
Chris Forbes8291c052015-05-25 11:13:28 +12004439TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
4440{
Tony Barbour192f02b2015-11-06 14:21:31 -07004441 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_PERF_WARN_BIT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004442 "location 0 not consumed by VS");
4443
Chris Forbes8291c052015-05-25 11:13:28 +12004444 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004445 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12004446
4447 VkVertexInputBindingDescription input_binding;
4448 memset(&input_binding, 0, sizeof(input_binding));
4449
4450 VkVertexInputAttributeDescription input_attrib;
4451 memset(&input_attrib, 0, sizeof(input_attrib));
4452 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4453
4454 char const *vsSource =
4455 "#version 140\n"
4456 "#extension GL_ARB_separate_shader_objects: require\n"
4457 "#extension GL_ARB_shading_language_420pack: require\n"
4458 "\n"
4459 "void main(){\n"
4460 " gl_Position = vec4(1);\n"
4461 "}\n";
4462 char const *fsSource =
4463 "#version 140\n"
4464 "#extension GL_ARB_separate_shader_objects: require\n"
4465 "#extension GL_ARB_shading_language_420pack: require\n"
4466 "\n"
4467 "layout(location=0) out vec4 color;\n"
4468 "void main(){\n"
4469 " color = vec4(1);\n"
4470 "}\n";
4471
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004472 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4473 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes8291c052015-05-25 11:13:28 +12004474
4475 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004476 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12004477 pipe.AddShader(&vs);
4478 pipe.AddShader(&fs);
4479
4480 pipe.AddVertexInputBindings(&input_binding, 1);
4481 pipe.AddVertexInputAttribs(&input_attrib, 1);
4482
Chris Forbes8291c052015-05-25 11:13:28 +12004483 VkDescriptorSetObj descriptorSet(m_device);
4484 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004485 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12004486
Tony Barboured132432015-08-04 16:23:11 -06004487 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12004488
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004489 if (!m_errorMonitor->DesiredMsgFound()) {
4490 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
4491 m_errorMonitor->DumpFailureMsgs();
Chris Forbes8291c052015-05-25 11:13:28 +12004492 }
4493}
4494
Chris Forbes37367e62015-05-25 11:13:29 +12004495TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
4496{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004497 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4498 "VS consumes input at location 0 but not provided");
4499
Chris Forbes37367e62015-05-25 11:13:29 +12004500 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12004502
4503 char const *vsSource =
4504 "#version 140\n"
4505 "#extension GL_ARB_separate_shader_objects: require\n"
4506 "#extension GL_ARB_shading_language_420pack: require\n"
4507 "\n"
4508 "layout(location=0) in vec4 x;\n" /* not provided */
4509 "void main(){\n"
4510 " gl_Position = x;\n"
4511 "}\n";
4512 char const *fsSource =
4513 "#version 140\n"
4514 "#extension GL_ARB_separate_shader_objects: require\n"
4515 "#extension GL_ARB_shading_language_420pack: require\n"
4516 "\n"
4517 "layout(location=0) out vec4 color;\n"
4518 "void main(){\n"
4519 " color = vec4(1);\n"
4520 "}\n";
4521
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004522 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4523 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes37367e62015-05-25 11:13:29 +12004524
4525 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004526 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12004527 pipe.AddShader(&vs);
4528 pipe.AddShader(&fs);
4529
Chris Forbes37367e62015-05-25 11:13:29 +12004530 VkDescriptorSetObj descriptorSet(m_device);
4531 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004532 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12004533
Tony Barboured132432015-08-04 16:23:11 -06004534 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12004535
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004536 if (!m_errorMonitor->DesiredMsgFound()) {
4537 FAIL() << "Did not receive Error 'VS consumes input at location 0 but not provided'";
4538 m_errorMonitor->DumpFailureMsgs();
Chris Forbes37367e62015-05-25 11:13:29 +12004539 }
4540}
4541
Chris Forbesa4b02322015-05-25 11:13:31 +12004542TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
4543{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004544 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4545 "location 0 does not match VS input type");
4546
Chris Forbesa4b02322015-05-25 11:13:31 +12004547 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004548 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12004549
4550 VkVertexInputBindingDescription input_binding;
4551 memset(&input_binding, 0, sizeof(input_binding));
4552
4553 VkVertexInputAttributeDescription input_attrib;
4554 memset(&input_attrib, 0, sizeof(input_attrib));
4555 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4556
4557 char const *vsSource =
4558 "#version 140\n"
4559 "#extension GL_ARB_separate_shader_objects: require\n"
4560 "#extension GL_ARB_shading_language_420pack: require\n"
4561 "\n"
4562 "layout(location=0) in int x;\n" /* attrib provided float */
4563 "void main(){\n"
4564 " gl_Position = vec4(x);\n"
4565 "}\n";
4566 char const *fsSource =
4567 "#version 140\n"
4568 "#extension GL_ARB_separate_shader_objects: require\n"
4569 "#extension GL_ARB_shading_language_420pack: require\n"
4570 "\n"
4571 "layout(location=0) out vec4 color;\n"
4572 "void main(){\n"
4573 " color = vec4(1);\n"
4574 "}\n";
4575
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004576 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4577 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa4b02322015-05-25 11:13:31 +12004578
4579 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004580 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12004581 pipe.AddShader(&vs);
4582 pipe.AddShader(&fs);
4583
4584 pipe.AddVertexInputBindings(&input_binding, 1);
4585 pipe.AddVertexInputAttribs(&input_attrib, 1);
4586
Chris Forbesa4b02322015-05-25 11:13:31 +12004587 VkDescriptorSetObj descriptorSet(m_device);
4588 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004589 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12004590
Tony Barboured132432015-08-04 16:23:11 -06004591 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12004592
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004593 if (!m_errorMonitor->DesiredMsgFound()) {
4594 FAIL() << "Did not receive Error 'location 0 does not match VS input type'";
4595 m_errorMonitor->DumpFailureMsgs();
Chris Forbesa4b02322015-05-25 11:13:31 +12004596 }
4597}
4598
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004599TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
4600{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004601 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4602 "Duplicate vertex input binding descriptions for binding 0");
4603
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004604 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004605 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004606
4607 /* Two binding descriptions for binding 0 */
4608 VkVertexInputBindingDescription input_bindings[2];
4609 memset(input_bindings, 0, sizeof(input_bindings));
4610
4611 VkVertexInputAttributeDescription input_attrib;
4612 memset(&input_attrib, 0, sizeof(input_attrib));
4613 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4614
4615 char const *vsSource =
4616 "#version 140\n"
4617 "#extension GL_ARB_separate_shader_objects: require\n"
4618 "#extension GL_ARB_shading_language_420pack: require\n"
4619 "\n"
4620 "layout(location=0) in float x;\n" /* attrib provided float */
4621 "void main(){\n"
4622 " gl_Position = vec4(x);\n"
4623 "}\n";
4624 char const *fsSource =
4625 "#version 140\n"
4626 "#extension GL_ARB_separate_shader_objects: require\n"
4627 "#extension GL_ARB_shading_language_420pack: require\n"
4628 "\n"
4629 "layout(location=0) out vec4 color;\n"
4630 "void main(){\n"
4631 " color = vec4(1);\n"
4632 "}\n";
4633
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004634 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4635 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004636
4637 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004638 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004639 pipe.AddShader(&vs);
4640 pipe.AddShader(&fs);
4641
4642 pipe.AddVertexInputBindings(input_bindings, 2);
4643 pipe.AddVertexInputAttribs(&input_attrib, 1);
4644
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004645 VkDescriptorSetObj descriptorSet(m_device);
4646 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004647 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004648
Tony Barboured132432015-08-04 16:23:11 -06004649 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004650
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004651 if (!m_errorMonitor->DesiredMsgFound()) {
4652 FAIL() << "Did not receive Error 'Duplicate vertex input binding descriptions for binding 0'";
4653 m_errorMonitor->DumpFailureMsgs();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004654 }
4655}
Chris Forbes4c948702015-05-25 11:13:32 +12004656
Chris Forbesc12ef122015-05-25 11:13:40 +12004657/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
4658 * rejects it. */
4659
4660TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
4661{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004662 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4663 "Attachment 0 not written by FS");
4664
Chris Forbesc12ef122015-05-25 11:13:40 +12004665 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12004666
4667 char const *vsSource =
4668 "#version 140\n"
4669 "#extension GL_ARB_separate_shader_objects: require\n"
4670 "#extension GL_ARB_shading_language_420pack: require\n"
4671 "\n"
4672 "void main(){\n"
4673 " gl_Position = vec4(1);\n"
4674 "}\n";
4675 char const *fsSource =
4676 "#version 140\n"
4677 "#extension GL_ARB_separate_shader_objects: require\n"
4678 "#extension GL_ARB_shading_language_420pack: require\n"
4679 "\n"
4680 "void main(){\n"
4681 "}\n";
4682
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004683 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4684 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc12ef122015-05-25 11:13:40 +12004685
4686 VkPipelineObj pipe(m_device);
4687 pipe.AddShader(&vs);
4688 pipe.AddShader(&fs);
4689
Chia-I Wuc278df82015-07-07 11:50:03 +08004690 /* set up CB 0, not written */
4691 pipe.AddColorAttachment();
4692 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12004693
Chris Forbesc12ef122015-05-25 11:13:40 +12004694 VkDescriptorSetObj descriptorSet(m_device);
4695 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004696 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12004697
Tony Barboured132432015-08-04 16:23:11 -06004698 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12004699
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004700 if (!m_errorMonitor->DesiredMsgFound()) {
4701 FAIL() << "Did not receive Error 'Attachment 0 not written by FS'";
4702 m_errorMonitor->DumpFailureMsgs();
Chris Forbesc12ef122015-05-25 11:13:40 +12004703 }
4704}
4705
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004706TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
4707{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004708 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
4709 "FS writes to output location 1 with no matching attachment");
4710
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004711 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004712
4713 char const *vsSource =
4714 "#version 140\n"
4715 "#extension GL_ARB_separate_shader_objects: require\n"
4716 "#extension GL_ARB_shading_language_420pack: require\n"
4717 "\n"
4718 "void main(){\n"
4719 " gl_Position = vec4(1);\n"
4720 "}\n";
4721 char const *fsSource =
4722 "#version 140\n"
4723 "#extension GL_ARB_separate_shader_objects: require\n"
4724 "#extension GL_ARB_shading_language_420pack: require\n"
4725 "\n"
4726 "layout(location=0) out vec4 x;\n"
4727 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
4728 "void main(){\n"
4729 " x = vec4(1);\n"
4730 " y = vec4(1);\n"
4731 "}\n";
4732
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004733 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4734 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004735
4736 VkPipelineObj pipe(m_device);
4737 pipe.AddShader(&vs);
4738 pipe.AddShader(&fs);
4739
Chia-I Wuc278df82015-07-07 11:50:03 +08004740 /* set up CB 0, not written */
4741 pipe.AddColorAttachment();
4742 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004743 /* FS writes CB 1, but we don't configure it */
4744
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004745 VkDescriptorSetObj descriptorSet(m_device);
4746 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004747 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004748
Tony Barboured132432015-08-04 16:23:11 -06004749 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004750
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004751 if (!m_errorMonitor->DesiredMsgFound()) {
4752 FAIL() << "Did not receive Error 'FS writes to output location 1 with no matching attachment'";
4753 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004754 }
4755}
4756
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004757TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
4758{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004759 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4760 "does not match FS output type");
4761
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004762 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004763
4764 char const *vsSource =
4765 "#version 140\n"
4766 "#extension GL_ARB_separate_shader_objects: require\n"
4767 "#extension GL_ARB_shading_language_420pack: require\n"
4768 "\n"
4769 "void main(){\n"
4770 " gl_Position = vec4(1);\n"
4771 "}\n";
4772 char const *fsSource =
4773 "#version 140\n"
4774 "#extension GL_ARB_separate_shader_objects: require\n"
4775 "#extension GL_ARB_shading_language_420pack: require\n"
4776 "\n"
4777 "layout(location=0) out ivec4 x;\n" /* not UNORM */
4778 "void main(){\n"
4779 " x = ivec4(1);\n"
4780 "}\n";
4781
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004782 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4783 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004784
4785 VkPipelineObj pipe(m_device);
4786 pipe.AddShader(&vs);
4787 pipe.AddShader(&fs);
4788
Chia-I Wuc278df82015-07-07 11:50:03 +08004789 /* set up CB 0; type is UNORM by default */
4790 pipe.AddColorAttachment();
4791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004792
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004793 VkDescriptorSetObj descriptorSet(m_device);
4794 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004795 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004796
Tony Barboured132432015-08-04 16:23:11 -06004797 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004798
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004799 if (!m_errorMonitor->DesiredMsgFound()) {
4800 FAIL() << "Did not receive Error 'does not match FS output type'";
4801 m_errorMonitor->DumpFailureMsgs();
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004802 }
4803}
Chris Forbesc2050732015-06-05 14:43:36 +12004804
Chris Forbes76ce7882015-08-14 12:04:59 +12004805TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
4806{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004807 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4808 "not declared in pipeline layout");
4809
Chris Forbes76ce7882015-08-14 12:04:59 +12004810 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +12004811
4812 char const *vsSource =
4813 "#version 140\n"
4814 "#extension GL_ARB_separate_shader_objects: require\n"
4815 "#extension GL_ARB_shading_language_420pack: require\n"
4816 "\n"
4817 "void main(){\n"
4818 " gl_Position = vec4(1);\n"
4819 "}\n";
4820 char const *fsSource =
4821 "#version 140\n"
4822 "#extension GL_ARB_separate_shader_objects: require\n"
4823 "#extension GL_ARB_shading_language_420pack: require\n"
4824 "\n"
4825 "layout(location=0) out vec4 x;\n"
4826 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4827 "void main(){\n"
4828 " x = vec4(bar.y);\n"
4829 "}\n";
4830
Chris Forbes76ce7882015-08-14 12:04:59 +12004831
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004832 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4833 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes76ce7882015-08-14 12:04:59 +12004834
Chris Forbes76ce7882015-08-14 12:04:59 +12004835 VkPipelineObj pipe(m_device);
4836 pipe.AddShader(&vs);
4837 pipe.AddShader(&fs);
4838
4839 /* set up CB 0; type is UNORM by default */
4840 pipe.AddColorAttachment();
4841 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4842
4843 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1f851912015-10-27 18:04:07 +08004844 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes76ce7882015-08-14 12:04:59 +12004845
4846 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4847
4848 /* should have generated an error -- pipeline layout does not
4849 * provide a uniform buffer in 0.0
4850 */
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004851 if (!m_errorMonitor->DesiredMsgFound()) {
4852 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
4853 m_errorMonitor->DumpFailureMsgs();
Chris Forbes76ce7882015-08-14 12:04:59 +12004854 }
4855}
4856
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004857#endif // SHADER_CHECKER_TESTS
4858
4859#if DEVICE_LIMITS_TESTS
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004860TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
4861{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004862 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4863 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004864
4865 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004866
4867 // Create an image
4868 VkImage image;
4869
4870 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4871 const int32_t tex_width = 32;
4872 const int32_t tex_height = 32;
4873
4874 VkImageCreateInfo image_create_info = {};
4875 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4876 image_create_info.pNext = NULL;
4877 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4878 image_create_info.format = tex_format;
4879 image_create_info.extent.width = tex_width;
4880 image_create_info.extent.height = tex_height;
4881 image_create_info.extent.depth = 1;
4882 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004883 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004884 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004885 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4886 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4887 image_create_info.flags = 0;
4888
4889 // Introduce error by sending down a bogus width extent
4890 image_create_info.extent.width = 65536;
Chia-I Wu69f40122015-10-26 21:10:41 +08004891 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004892
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004893 if (!m_errorMonitor->DesiredMsgFound()) {
4894 FAIL() << "Did not receive Error 'CreateImage extents exceed allowable limits for format'";
4895 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004896 }
4897}
4898
4899TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
4900{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004901 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4902 "CreateImage resource size exceeds allowable maximum");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004903
4904 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004905
4906 // Create an image
4907 VkImage image;
4908
4909 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4910 const int32_t tex_width = 32;
4911 const int32_t tex_height = 32;
4912
4913 VkImageCreateInfo image_create_info = {};
4914 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4915 image_create_info.pNext = NULL;
4916 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4917 image_create_info.format = tex_format;
4918 image_create_info.extent.width = tex_width;
4919 image_create_info.extent.height = tex_height;
4920 image_create_info.extent.depth = 1;
4921 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004922 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004923 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004924 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4925 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4926 image_create_info.flags = 0;
4927
4928 // Introduce error by sending down individually allowable values that result in a surface size
4929 // exceeding the device maximum
4930 image_create_info.extent.width = 8192;
4931 image_create_info.extent.height = 8192;
4932 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004933 image_create_info.arrayLayers = 4;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004934 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004935 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
Chia-I Wu69f40122015-10-26 21:10:41 +08004936 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004937
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004938 if (!m_errorMonitor->DesiredMsgFound()) {
4939 FAIL() << "Did not receive Error 'CreateImage resource size exceeds allowable maximum'";
4940 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004941 }
4942}
4943
Mike Stroyan43909d82015-09-25 13:39:21 -06004944TEST_F(VkLayerTest, UpdateBufferAlignment)
4945{
Mike Stroyan43909d82015-09-25 13:39:21 -06004946 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
4947
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004948 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4949 "dstOffset, is not a multiple of 4");
4950
Mike Stroyan43909d82015-09-25 13:39:21 -06004951 ASSERT_NO_FATAL_FAILURE(InitState());
4952
4953 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4954 vk_testing::Buffer buffer;
4955 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4956
4957 BeginCommandBuffer();
4958 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08004959 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004960 if (!m_errorMonitor->DesiredMsgFound()) {
4961 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
4962 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06004963 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004964
Mike Stroyan43909d82015-09-25 13:39:21 -06004965 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004966 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4967 "dataSize, is not a multiple of 4");
4968
Chia-I Wu1f851912015-10-27 18:04:07 +08004969 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004970
4971 if (!m_errorMonitor->DesiredMsgFound()) {
4972 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
4973 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06004974 }
4975 EndCommandBuffer();
4976}
4977
4978TEST_F(VkLayerTest, FillBufferAlignment)
4979{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004980 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4981 "dstOffset, is not a multiple of 4");
Mike Stroyan43909d82015-09-25 13:39:21 -06004982
4983 ASSERT_NO_FATAL_FAILURE(InitState());
4984
4985 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4986 vk_testing::Buffer buffer;
4987 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4988
4989 BeginCommandBuffer();
4990 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08004991 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004992 if (!m_errorMonitor->DesiredMsgFound()) {
4993 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
4994 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06004995 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004996
Mike Stroyan43909d82015-09-25 13:39:21 -06004997 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004998 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4999 "size, is not a multiple of 4");
5000
Chia-I Wu1f851912015-10-27 18:04:07 +08005001 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005002
5003 if (!m_errorMonitor->DesiredMsgFound()) {
5004 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize size, is not a multiple of 4'";
5005 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005006 }
5007 EndCommandBuffer();
5008}
5009
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06005010#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005011
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005012#if IMAGE_TESTS
5013TEST_F(VkLayerTest, InvalidImageView)
5014{
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005015 VkResult err;
5016
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005017 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5018 "vkCreateImageView called with baseMipLevel 10 ");
5019
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005020 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005021
Mike Stroyan43909d82015-09-25 13:39:21 -06005022 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005023 VkImage image;
5024
5025 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5026 const int32_t tex_width = 32;
5027 const int32_t tex_height = 32;
5028
5029 VkImageCreateInfo image_create_info = {};
5030 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5031 image_create_info.pNext = NULL;
5032 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5033 image_create_info.format = tex_format;
5034 image_create_info.extent.width = tex_width;
5035 image_create_info.extent.height = tex_height;
5036 image_create_info.extent.depth = 1;
5037 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005038 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005039 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005040 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5041 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5042 image_create_info.flags = 0;
5043
Chia-I Wu69f40122015-10-26 21:10:41 +08005044 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005045 ASSERT_VK_SUCCESS(err);
5046
5047 VkImageViewCreateInfo image_view_create_info = {};
5048 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5049 image_view_create_info.image = image;
5050 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5051 image_view_create_info.format = tex_format;
Chia-I Wu1f851912015-10-27 18:04:07 +08005052 image_view_create_info.subresourceRange.layerCount = 1;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005053 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Chia-I Wu1f851912015-10-27 18:04:07 +08005054 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005055 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005056
5057 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08005058 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005059
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005060 if (!m_errorMonitor->DesiredMsgFound()) {
5061 FAIL() << "Did not receive Error 'vkCreateImageView called with baseMipLevel 10...'";
5062 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005063 }
5064}
Mike Stroyan43909d82015-09-25 13:39:21 -06005065
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005066TEST_F(VkLayerTest, InvalidImageViewAspect)
5067{
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005068 VkResult err;
5069
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005070 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5071 "vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set");
5072
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005073 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005074
5075 // Create an image and try to create a view with an invalid aspectMask
5076 VkImage image;
5077
5078 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5079 const int32_t tex_width = 32;
5080 const int32_t tex_height = 32;
5081
5082 VkImageCreateInfo image_create_info = {};
5083 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5084 image_create_info.pNext = NULL;
5085 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5086 image_create_info.format = tex_format;
5087 image_create_info.extent.width = tex_width;
5088 image_create_info.extent.height = tex_height;
5089 image_create_info.extent.depth = 1;
5090 image_create_info.mipLevels = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005091 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005092 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5093 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5094 image_create_info.flags = 0;
5095
Chia-I Wu69f40122015-10-26 21:10:41 +08005096 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005097 ASSERT_VK_SUCCESS(err);
5098
5099 VkImageViewCreateInfo image_view_create_info = {};
5100 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5101 image_view_create_info.image = image;
5102 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5103 image_view_create_info.format = tex_format;
5104 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005105 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005106 // Cause an error by setting an invalid image aspect
5107 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
5108
5109 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08005110 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005111
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005112 if (!m_errorMonitor->DesiredMsgFound()) {
5113 FAIL() << "Did not receive Error 'VkCreateImageView: Color image formats must have ...'";
5114 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005115 }
5116}
5117
Mike Stroyan43909d82015-09-25 13:39:21 -06005118TEST_F(VkLayerTest, CopyImageTypeMismatch)
5119{
Mike Stroyan43909d82015-09-25 13:39:21 -06005120 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005121 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005122
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005123 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5124 "vkCmdCopyImage called with unmatched source and dest image types");
5125
Mike Stroyan43909d82015-09-25 13:39:21 -06005126 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005127
5128 // Create two images of different types and try to copy between them
5129 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005130 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005131 VkDeviceMemory srcMem;
5132 VkDeviceMemory destMem;
5133 VkMemoryRequirements memReqs;
5134
5135 VkImageCreateInfo image_create_info = {};
5136 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5137 image_create_info.pNext = NULL;
5138 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5139 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5140 image_create_info.extent.width = 32;
5141 image_create_info.extent.height = 32;
5142 image_create_info.extent.depth = 1;
5143 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005144 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005145 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005146 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005147 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005148 image_create_info.flags = 0;
5149
Chia-I Wu69f40122015-10-26 21:10:41 +08005150 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005151 ASSERT_VK_SUCCESS(err);
5152
5153 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005154 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005155
Chia-I Wu1f851912015-10-27 18:04:07 +08005156 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005157 ASSERT_VK_SUCCESS(err);
5158
5159 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005160 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005161 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005162 memAlloc.pNext = NULL;
5163 memAlloc.allocationSize = 0;
5164 memAlloc.memoryTypeIndex = 0;
5165
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005166 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005167 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005168 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5169 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005170 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005171 ASSERT_VK_SUCCESS(err);
5172
Chia-I Wu1f851912015-10-27 18:04:07 +08005173 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005174 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005175 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005176 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005177 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005178 ASSERT_VK_SUCCESS(err);
5179
5180 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5181 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005182 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005183 ASSERT_VK_SUCCESS(err);
5184
5185 BeginCommandBuffer();
5186 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005187 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005188 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005189 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005190 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005191 copyRegion.srcOffset.x = 0;
5192 copyRegion.srcOffset.y = 0;
5193 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005194 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005195 copyRegion.dstSubresource.mipLevel = 0;
5196 copyRegion.dstSubresource.baseArrayLayer = 0;
5197 copyRegion.dstSubresource.layerCount = 0;
5198 copyRegion.dstOffset.x = 0;
5199 copyRegion.dstOffset.y = 0;
5200 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005201 copyRegion.extent.width = 1;
5202 copyRegion.extent.height = 1;
5203 copyRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005204 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005205 EndCommandBuffer();
5206
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005207 if (!m_errorMonitor->DesiredMsgFound()) {
5208 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5209 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005210 }
5211
Chia-I Wu69f40122015-10-26 21:10:41 +08005212 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005213 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005214 vkFreeMemory(m_device->device(), srcMem, NULL);
5215 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005216}
5217
5218TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
5219{
5220 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
5221}
5222
5223TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
5224{
Mike Stroyan43909d82015-09-25 13:39:21 -06005225 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005226 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005227
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005228 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5229 "vkCmdCopyImage called with unmatched source and dest image types");
5230
Mike Stroyan43909d82015-09-25 13:39:21 -06005231 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005232
5233 // Create two images of different types and try to copy between them
5234 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005235 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005236 VkDeviceMemory srcMem;
5237 VkDeviceMemory destMem;
5238 VkMemoryRequirements memReqs;
5239
5240 VkImageCreateInfo image_create_info = {};
5241 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5242 image_create_info.pNext = NULL;
5243 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5244 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5245 image_create_info.extent.width = 32;
5246 image_create_info.extent.height = 32;
5247 image_create_info.extent.depth = 1;
5248 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005249 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005250 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005251 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005252 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005253 image_create_info.flags = 0;
5254
Chia-I Wu69f40122015-10-26 21:10:41 +08005255 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005256 ASSERT_VK_SUCCESS(err);
5257
5258 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005259 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005260
Chia-I Wu1f851912015-10-27 18:04:07 +08005261 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005262 ASSERT_VK_SUCCESS(err);
5263
5264 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005265 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005266 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005267 memAlloc.pNext = NULL;
5268 memAlloc.allocationSize = 0;
5269 memAlloc.memoryTypeIndex = 0;
5270
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005271 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005272 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005273 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5274 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005275 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005276 ASSERT_VK_SUCCESS(err);
5277
Chia-I Wu1f851912015-10-27 18:04:07 +08005278 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005279 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005280 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5281 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005282 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005283 ASSERT_VK_SUCCESS(err);
5284
5285 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5286 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005287 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005288 ASSERT_VK_SUCCESS(err);
5289
5290 BeginCommandBuffer();
5291 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005292 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005293 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005294 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005295 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005296 copyRegion.srcOffset.x = 0;
5297 copyRegion.srcOffset.y = 0;
5298 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005299 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005300 copyRegion.dstSubresource.mipLevel = 0;
5301 copyRegion.dstSubresource.baseArrayLayer = 0;
5302 copyRegion.dstSubresource.layerCount = 0;
5303 copyRegion.dstOffset.x = 0;
5304 copyRegion.dstOffset.y = 0;
5305 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005306 copyRegion.extent.width = 1;
5307 copyRegion.extent.height = 1;
5308 copyRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005309 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005310 EndCommandBuffer();
5311
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005312 if (!m_errorMonitor->DesiredMsgFound()) {
5313 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5314 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005315 }
5316
Chia-I Wu69f40122015-10-26 21:10:41 +08005317 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005318 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005319 vkFreeMemory(m_device->device(), srcMem, NULL);
5320 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005321}
5322
5323TEST_F(VkLayerTest, ResolveImageLowSampleCount)
5324{
Mike Stroyan43909d82015-09-25 13:39:21 -06005325 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005326 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005327
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005328 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5329 "vkCmdResolveImage called with source sample count less than 2.");
5330
Mike Stroyan43909d82015-09-25 13:39:21 -06005331 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005332
5333 // Create two images of sample count 1 and try to Resolve between them
5334 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005335 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005336 VkDeviceMemory srcMem;
5337 VkDeviceMemory destMem;
5338 VkMemoryRequirements memReqs;
5339
5340 VkImageCreateInfo image_create_info = {};
5341 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5342 image_create_info.pNext = NULL;
5343 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5344 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5345 image_create_info.extent.width = 32;
5346 image_create_info.extent.height = 1;
5347 image_create_info.extent.depth = 1;
5348 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005349 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005350 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005351 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005352 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005353 image_create_info.flags = 0;
5354
Chia-I Wu69f40122015-10-26 21:10:41 +08005355 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005356 ASSERT_VK_SUCCESS(err);
5357
5358 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005359 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005360
Chia-I Wu1f851912015-10-27 18:04:07 +08005361 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005362 ASSERT_VK_SUCCESS(err);
5363
5364 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005365 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005366 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005367 memAlloc.pNext = NULL;
5368 memAlloc.allocationSize = 0;
5369 memAlloc.memoryTypeIndex = 0;
5370
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005371 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005372 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005373 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5374 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005375 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005376 ASSERT_VK_SUCCESS(err);
5377
Chia-I Wu1f851912015-10-27 18:04:07 +08005378 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005379 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005380 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5381 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005382 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005383 ASSERT_VK_SUCCESS(err);
5384
5385 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5386 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005387 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005388 ASSERT_VK_SUCCESS(err);
5389
5390 BeginCommandBuffer();
5391 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5392 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5393 //VK_IMAGE_LAYOUT_GENERAL = 1,
5394 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005395 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005396 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005397 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005398 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005399 resolveRegion.srcOffset.x = 0;
5400 resolveRegion.srcOffset.y = 0;
5401 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005402 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005403 resolveRegion.dstSubresource.mipLevel = 0;
5404 resolveRegion.dstSubresource.baseArrayLayer = 0;
5405 resolveRegion.dstSubresource.layerCount = 0;
5406 resolveRegion.dstOffset.x = 0;
5407 resolveRegion.dstOffset.y = 0;
5408 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005409 resolveRegion.extent.width = 1;
5410 resolveRegion.extent.height = 1;
5411 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005412 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005413 EndCommandBuffer();
5414
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005415 if (!m_errorMonitor->DesiredMsgFound()) {
5416 FAIL() << "Did not receive Error 'vkCmdResolveImage called with source sample count less than 2.'";
5417 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005418 }
5419
Chia-I Wu69f40122015-10-26 21:10:41 +08005420 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005421 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005422 vkFreeMemory(m_device->device(), srcMem, NULL);
5423 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005424}
5425
5426TEST_F(VkLayerTest, ResolveImageHighSampleCount)
5427{
Mike Stroyan43909d82015-09-25 13:39:21 -06005428 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005429 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005430
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005431 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5432 "vkCmdResolveImage called with dest sample count greater than 1.");
5433
Mike Stroyan43909d82015-09-25 13:39:21 -06005434 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005435
5436 // Create two images of sample count 2 and try to Resolve between them
5437 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005438 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005439 VkDeviceMemory srcMem;
5440 VkDeviceMemory destMem;
5441 VkMemoryRequirements memReqs;
5442
5443 VkImageCreateInfo image_create_info = {};
5444 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5445 image_create_info.pNext = NULL;
5446 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5447 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5448 image_create_info.extent.width = 32;
5449 image_create_info.extent.height = 1;
5450 image_create_info.extent.depth = 1;
5451 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005452 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005453 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005454 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005455 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005456 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005457 image_create_info.flags = 0;
5458
Chia-I Wu69f40122015-10-26 21:10:41 +08005459 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005460 ASSERT_VK_SUCCESS(err);
5461
5462 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005463 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005464 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005465
Chia-I Wu1f851912015-10-27 18:04:07 +08005466 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005467 ASSERT_VK_SUCCESS(err);
5468
5469 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005470 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005471 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005472 memAlloc.pNext = NULL;
5473 memAlloc.allocationSize = 0;
5474 memAlloc.memoryTypeIndex = 0;
5475
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005476 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005477 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005478 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5479 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005480 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005481 ASSERT_VK_SUCCESS(err);
5482
Chia-I Wu1f851912015-10-27 18:04:07 +08005483 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005484 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005485 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5486 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005487 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005488 ASSERT_VK_SUCCESS(err);
5489
5490 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5491 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005492 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005493 ASSERT_VK_SUCCESS(err);
5494
5495 BeginCommandBuffer();
5496 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5497 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5498 //VK_IMAGE_LAYOUT_GENERAL = 1,
5499 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005500 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005501 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005502 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005503 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005504 resolveRegion.srcOffset.x = 0;
5505 resolveRegion.srcOffset.y = 0;
5506 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005507 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005508 resolveRegion.dstSubresource.mipLevel = 0;
5509 resolveRegion.dstSubresource.baseArrayLayer = 0;
5510 resolveRegion.dstSubresource.layerCount = 0;
5511 resolveRegion.dstOffset.x = 0;
5512 resolveRegion.dstOffset.y = 0;
5513 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005514 resolveRegion.extent.width = 1;
5515 resolveRegion.extent.height = 1;
5516 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005517 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005518 EndCommandBuffer();
5519
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005520 if (!m_errorMonitor->DesiredMsgFound()) {
5521 FAIL() << "Did not receive Error 'vkCmdResolveImage called with dest sample count greater than 1.'";
5522 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005523 }
5524
Chia-I Wu69f40122015-10-26 21:10:41 +08005525 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005526 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005527 vkFreeMemory(m_device->device(), srcMem, NULL);
5528 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005529}
5530
5531TEST_F(VkLayerTest, ResolveImageFormatMismatch)
5532{
Mike Stroyan43909d82015-09-25 13:39:21 -06005533 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005534 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005535
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005536 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5537 "vkCmdResolveImage called with unmatched source and dest formats.");
5538
Mike Stroyan43909d82015-09-25 13:39:21 -06005539 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005540
5541 // Create two images of different types and try to copy between them
5542 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005543 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005544 VkDeviceMemory srcMem;
5545 VkDeviceMemory destMem;
5546 VkMemoryRequirements memReqs;
5547
5548 VkImageCreateInfo image_create_info = {};
5549 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5550 image_create_info.pNext = NULL;
5551 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5552 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5553 image_create_info.extent.width = 32;
5554 image_create_info.extent.height = 1;
5555 image_create_info.extent.depth = 1;
5556 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005557 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005558 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005559 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005560 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005561 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005562 image_create_info.flags = 0;
5563
Chia-I Wu69f40122015-10-26 21:10:41 +08005564 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005565 ASSERT_VK_SUCCESS(err);
5566
Cody Northropb3bf94f2015-10-27 13:50:04 -06005567 // Set format to something other than source image
5568 image_create_info.format = VK_FORMAT_R32_SFLOAT;
5569 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005570 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005571 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005572
Chia-I Wu1f851912015-10-27 18:04:07 +08005573 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005574 ASSERT_VK_SUCCESS(err);
5575
5576 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005577 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005578 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005579 memAlloc.pNext = NULL;
5580 memAlloc.allocationSize = 0;
5581 memAlloc.memoryTypeIndex = 0;
5582
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005583 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005584 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005585 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5586 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005587 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005588 ASSERT_VK_SUCCESS(err);
5589
Chia-I Wu1f851912015-10-27 18:04:07 +08005590 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005591 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005592 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5593 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005594 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005595 ASSERT_VK_SUCCESS(err);
5596
5597 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5598 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005599 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005600 ASSERT_VK_SUCCESS(err);
5601
5602 BeginCommandBuffer();
5603 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5604 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5605 //VK_IMAGE_LAYOUT_GENERAL = 1,
5606 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005607 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005608 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005609 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005610 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005611 resolveRegion.srcOffset.x = 0;
5612 resolveRegion.srcOffset.y = 0;
5613 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005614 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005615 resolveRegion.dstSubresource.mipLevel = 0;
5616 resolveRegion.dstSubresource.baseArrayLayer = 0;
5617 resolveRegion.dstSubresource.layerCount = 0;
5618 resolveRegion.dstOffset.x = 0;
5619 resolveRegion.dstOffset.y = 0;
5620 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005621 resolveRegion.extent.width = 1;
5622 resolveRegion.extent.height = 1;
5623 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005624 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005625 EndCommandBuffer();
5626
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005627 if (!m_errorMonitor->DesiredMsgFound()) {
5628 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest formats.'";
5629 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005630 }
5631
Chia-I Wu69f40122015-10-26 21:10:41 +08005632 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005633 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005634 vkFreeMemory(m_device->device(), srcMem, NULL);
5635 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005636}
5637
5638TEST_F(VkLayerTest, ResolveImageTypeMismatch)
5639{
Mike Stroyan43909d82015-09-25 13:39:21 -06005640 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005641 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005642
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005643 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5644 "vkCmdResolveImage called with unmatched source and dest image types.");
5645
Mike Stroyan43909d82015-09-25 13:39:21 -06005646 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005647
5648 // Create two images of different types and try to copy between them
5649 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005650 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005651 VkDeviceMemory srcMem;
5652 VkDeviceMemory destMem;
5653 VkMemoryRequirements memReqs;
5654
5655 VkImageCreateInfo image_create_info = {};
5656 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5657 image_create_info.pNext = NULL;
5658 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5659 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5660 image_create_info.extent.width = 32;
5661 image_create_info.extent.height = 1;
5662 image_create_info.extent.depth = 1;
5663 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005664 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005665 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005666 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005667 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005668 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005669 image_create_info.flags = 0;
5670
Chia-I Wu69f40122015-10-26 21:10:41 +08005671 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005672 ASSERT_VK_SUCCESS(err);
5673
5674 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005675 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005676 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005677 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005678
Chia-I Wu1f851912015-10-27 18:04:07 +08005679 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005680 ASSERT_VK_SUCCESS(err);
5681
5682 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005683 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005684 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005685 memAlloc.pNext = NULL;
5686 memAlloc.allocationSize = 0;
5687 memAlloc.memoryTypeIndex = 0;
5688
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005689 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005690 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005691 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5692 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005693 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005694 ASSERT_VK_SUCCESS(err);
5695
Chia-I Wu1f851912015-10-27 18:04:07 +08005696 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005697 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005698 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5699 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005700 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005701 ASSERT_VK_SUCCESS(err);
5702
5703 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5704 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005705 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005706 ASSERT_VK_SUCCESS(err);
5707
5708 BeginCommandBuffer();
5709 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5710 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5711 //VK_IMAGE_LAYOUT_GENERAL = 1,
5712 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005713 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005714 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005715 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005716 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005717 resolveRegion.srcOffset.x = 0;
5718 resolveRegion.srcOffset.y = 0;
5719 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005720 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005721 resolveRegion.dstSubresource.mipLevel = 0;
5722 resolveRegion.dstSubresource.baseArrayLayer = 0;
5723 resolveRegion.dstSubresource.layerCount = 0;
5724 resolveRegion.dstOffset.x = 0;
5725 resolveRegion.dstOffset.y = 0;
5726 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005727 resolveRegion.extent.width = 1;
5728 resolveRegion.extent.height = 1;
5729 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005730 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005731 EndCommandBuffer();
5732
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005733 if (!m_errorMonitor->DesiredMsgFound()) {
5734 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest image types.'";
5735 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005736 }
5737
Chia-I Wu69f40122015-10-26 21:10:41 +08005738 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005739 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005740 vkFreeMemory(m_device->device(), srcMem, NULL);
5741 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005742}
Tobin Ehlisb46be812015-10-23 16:00:08 -06005743
5744TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError)
5745{
5746 // Create a single Image descriptor and cause it to first hit an error due
5747 // to using a DS format, then cause it to hit error due to COLOR_BIT not set in aspect
5748 // The image format check comes 2nd in validation so we trigger it first,
5749 // then when we cause aspect fail next, bad format check will be preempted
Tobin Ehlisb46be812015-10-23 16:00:08 -06005750 VkResult err;
5751
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005752 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5753 "Combination depth/stencil image formats can have only the ");
5754
Tobin Ehlisb46be812015-10-23 16:00:08 -06005755 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005756
Chia-I Wuc51b1212015-10-27 19:25:11 +08005757 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06005758 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu763a7492015-10-26 20:48:51 +08005759 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005760
5761 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5762 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5763 ds_pool_ci.pNext = NULL;
5764 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08005765 ds_pool_ci.poolSizeCount = 1;
5766 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005767
5768 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08005769 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005770 ASSERT_VK_SUCCESS(err);
5771
5772 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08005773 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005774 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu045654f2015-11-06 06:42:02 +08005775 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005776 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5777 dsl_binding.pImmutableSamplers = NULL;
5778
5779 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5780 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5781 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08005782 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08005783 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005784 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08005785 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005786 ASSERT_VK_SUCCESS(err);
5787
5788 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08005789 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005790 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08005791 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005792 alloc_info.descriptorPool = ds_pool;
5793 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08005794 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005795 ASSERT_VK_SUCCESS(err);
5796
5797 VkImage image_bad;
5798 VkImage image_good;
5799 // One bad format and one good format for Color attachment
5800 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
5801 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
5802 const int32_t tex_width = 32;
5803 const int32_t tex_height = 32;
5804
5805 VkImageCreateInfo image_create_info = {};
5806 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5807 image_create_info.pNext = NULL;
5808 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5809 image_create_info.format = tex_format_bad;
5810 image_create_info.extent.width = tex_width;
5811 image_create_info.extent.height = tex_height;
5812 image_create_info.extent.depth = 1;
5813 image_create_info.mipLevels = 1;
5814 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005815 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005816 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5817 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
5818 image_create_info.flags = 0;
5819
Chia-I Wu69f40122015-10-26 21:10:41 +08005820 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005821 ASSERT_VK_SUCCESS(err);
5822 image_create_info.format = tex_format_good;
5823 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu69f40122015-10-26 21:10:41 +08005824 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005825 ASSERT_VK_SUCCESS(err);
5826
5827 VkImageViewCreateInfo image_view_create_info = {};
5828 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5829 image_view_create_info.image = image_bad;
5830 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5831 image_view_create_info.format = tex_format_bad;
5832 image_view_create_info.subresourceRange.baseArrayLayer = 0;
5833 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005834 image_view_create_info.subresourceRange.layerCount = 1;
5835 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005836 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5837
5838 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08005839 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005840
5841 if (!m_errorMonitor->DesiredMsgFound()) {
5842 FAIL() << "Did not receive Error 'Combination depth-stencil image formats can have only the....'";
5843 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06005844 }
5845
Chia-I Wu69f40122015-10-26 21:10:41 +08005846 vkDestroyImage(m_device->device(), image_bad, NULL);
5847 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005848 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5849 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005850}
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005851#endif // IMAGE_TESTS
5852
Tony Barbour30486ea2015-04-07 13:44:53 -06005853int main(int argc, char **argv) {
5854 int result;
5855
5856 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06005857 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06005858
5859 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
5860
5861 result = RUN_ALL_TESTS();
5862
Tony Barbour01999182015-04-09 12:58:51 -06005863 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06005864 return result;
5865}