blob: 3fa6a933bd6949920e882b01e71de27440430313 [file] [log] [blame]
Tony Barbourd04e8df2015-11-17 10:02:56 -07001//
2// Copyright (C) 2015 Valve Corporation
Tobin Ehliscb085292015-12-01 09:57:09 -07003// Copyright (C) 2015 Google, Inc.
Tony Barbourd04e8df2015-11-17 10:02:56 -07004//
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included
13// in all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE.
22//
23// Author: Chia-I Wu <olvaffe@gmail.com>
24// Author: Chris Forbes <chrisf@ijw.co.nz>
25// Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
26// Author: Mark Lobodzinski <mark@lunarg.com>
27// Author: Mike Stroyan <mike@LunarG.com>
Tobin Ehliscb085292015-12-01 09:57:09 -070028// Author: Tobin Ehlis <tobine@google.com>
Tony Barbourd04e8df2015-11-17 10:02:56 -070029// Author: Tony Barbour <tony@LunarG.com>
30
31
David Pinedo329ca9e2015-11-06 12:54:48 -070032#include <vulkan/vulkan.h>
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -070033#include <vulkan/vk_ext_debug_report.h>
Courtney Goeltzenleuchter0abdb662015-10-07 13:28:58 -060034#include "test_common.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060035#include "vkrenderframework.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060036#include "vk_layer_config.h"
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -060037#include "../icd/common/icd-spv.h"
Tony Barbour30486ea2015-04-07 13:44:53 -060038
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050039#define GLM_FORCE_RADIANS
40#include "glm/glm.hpp"
41#include <glm/gtc/matrix_transform.hpp>
42
Tobin Ehlis57e6a612015-05-26 16:11:58 -060043#define MEM_TRACKER_TESTS 1
44#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
Jesse Hall9b72eb82015-12-22 21:27:55 -0800102static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(
Tony Barboure84a8d62015-07-10 14:10:27 -0600103 VkFlags msgFlags,
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700104 VkDebugReportObjectTypeEXT objType,
Tony Barboure84a8d62015-07-10 14:10:27 -0600105 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,
Courtney Goeltzenleuchter072b6f22015-11-30 11:52:06 -0700110 const 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 Goeltzenleuchteracb13592015-12-09 15:48:16 -0700128 m_msgFlags = VK_DEBUG_REPORT_INFO_BIT_EXT;
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,
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700207 VkDebugReportObjectTypeEXT objType,
Tony Barboure84a8d62015-07-10 14:10:27 -0600208 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,
Courtney Goeltzenleuchter072b6f22015-11-30 11:52:06 -0700213 const void* pUserData)
Tony Barbour30486ea2015-04-07 13:44:53 -0600214{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700215 if (msgFlags & (VK_DEBUG_REPORT_WARN_BIT_EXT | VK_DEBUG_REPORT_PERF_WARN_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT)) {
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 Goeltzenleuchteracb13592015-12-09 15:48:16 -0700254 instance_extension_names.push_back(VK_EXT_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
Jon Ashburn1068ad52015-11-25 08:56:58 -0700261 instance_layer_names.push_back("VK_LAYER_LUNARG_Threading");
262 instance_layer_names.push_back("VK_LAYER_LUNARG_ObjectTracker");
263 instance_layer_names.push_back("VK_LAYER_LUNARG_MemTracker");
264 instance_layer_names.push_back("VK_LAYER_LUNARG_DrawState");
Jon Ashburn1068ad52015-11-25 08:56:58 -0700265 instance_layer_names.push_back("VK_LAYER_LUNARG_DeviceLimits");
266 instance_layer_names.push_back("VK_LAYER_LUNARG_Image");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600267
Jon Ashburn1068ad52015-11-25 08:56:58 -0700268 device_layer_names.push_back("VK_LAYER_LUNARG_Threading");
269 device_layer_names.push_back("VK_LAYER_LUNARG_ObjectTracker");
270 device_layer_names.push_back("VK_LAYER_LUNARG_MemTracker");
271 device_layer_names.push_back("VK_LAYER_LUNARG_DrawState");
Jon Ashburn1068ad52015-11-25 08:56:58 -0700272 device_layer_names.push_back("VK_LAYER_LUNARG_DeviceLimits");
273 device_layer_names.push_back("VK_LAYER_LUNARG_Image");
Tony Barbour30486ea2015-04-07 13:44:53 -0600274
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600275 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -0600276 this->app_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +0800277 this->app_info.pApplicationName = "layer_tests";
278 this->app_info.applicationVersion = 1;
Tony Barbour30486ea2015-04-07 13:44:53 -0600279 this->app_info.pEngineName = "unittest";
280 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600281 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -0600282
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600283 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600284 InitFramework(instance_layer_names, device_layer_names,
285 instance_extension_names, device_extension_names,
286 myDbgFunc, m_errorMonitor);
Tony Barbour30486ea2015-04-07 13:44:53 -0600287 }
288
289 virtual void TearDown() {
290 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600291 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600292 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600293 }
294};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500295
Chia-I Wu1f851912015-10-27 18:04:07 +0800296VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600297{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600298 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600299
Chia-I Wu1f851912015-10-27 18:04:07 +0800300 result = commandBuffer.BeginCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600301
302 /*
303 * For render test all drawing happens in a single render pass
304 * on a single command buffer.
305 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200306 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800307 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour30486ea2015-04-07 13:44:53 -0600308 }
309
310 return result;
311}
312
Chia-I Wu1f851912015-10-27 18:04:07 +0800313VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600314{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600315 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600316
Chris Forbesfe133ef2015-06-16 14:05:59 +1200317 if (renderPass()) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800318 commandBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200319 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600320
Chia-I Wu1f851912015-10-27 18:04:07 +0800321 result = commandBuffer.EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600322
323 return result;
324}
325
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500326void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
327{
328 // Create identity matrix
329 int i;
330 struct vktriangle_vs_uniform data;
331
332 glm::mat4 Projection = glm::mat4(1.0f);
333 glm::mat4 View = glm::mat4(1.0f);
334 glm::mat4 Model = glm::mat4(1.0f);
335 glm::mat4 MVP = Projection * View * Model;
336 const int matrixSize = sizeof(MVP);
337 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
338
339 memcpy(&data.mvp, &MVP[0][0], matrixSize);
340
341 static const Vertex tri_data[] =
342 {
343 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
344 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
345 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
346 };
347
348 for (i=0; i<3; i++) {
349 data.position[i][0] = tri_data[i].posX;
350 data.position[i][1] = tri_data[i].posY;
351 data.position[i][2] = tri_data[i].posZ;
352 data.position[i][3] = tri_data[i].posW;
353 data.color[i][0] = tri_data[i].r;
354 data.color[i][1] = tri_data[i].g;
355 data.color[i][2] = tri_data[i].b;
356 data.color[i][3] = tri_data[i].a;
357 }
358
359 ASSERT_NO_FATAL_FAILURE(InitState());
360 ASSERT_NO_FATAL_FAILURE(InitViewport());
361
362 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
363
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600364 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
365 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500366
367 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800368 pipelineobj.AddColorAttachment();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500369 pipelineobj.AddShader(&vs);
370 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600371 if (failMask & BsoFailLineWidth) {
372 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
373 }
374 if (failMask & BsoFailDepthBias) {
375 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
376 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600377 // Viewport and scissors must stay in synch or other errors will occur than the ones we want
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600378 if (failMask & BsoFailViewport) {
379 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600380 m_viewports.clear();
381 m_scissors.clear();
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600382 }
383 if (failMask & BsoFailScissor) {
384 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600385 m_scissors.clear();
386 m_viewports.clear();
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600387 }
388 if (failMask & BsoFailBlend) {
389 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
390 }
391 if (failMask & BsoFailDepthBounds) {
392 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
393 }
394 if (failMask & BsoFailStencilReadMask) {
395 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
396 }
397 if (failMask & BsoFailStencilWriteMask) {
398 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
399 }
400 if (failMask & BsoFailStencilReference) {
401 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
402 }
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500403
404 VkDescriptorSetObj descriptorSet(m_device);
405 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
406
407 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600408 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500409
Tony Barbour1490c912015-07-28 10:17:20 -0600410 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500411
412 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600413 Draw(3, 1, 0, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500414
415 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600416 EndCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500417
Tony Barbour1490c912015-07-28 10:17:20 -0600418 QueueCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500419}
420
Chia-I Wu1f851912015-10-27 18:04:07 +0800421void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500422{
423 if (m_depthStencil->Initialized()) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800424 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500425 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +0800426 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500427 }
428
Chia-I Wu1f851912015-10-27 18:04:07 +0800429 commandBuffer->PrepareAttachments();
Cody Northrop2605cb02015-08-18 15:21:16 -0600430 // Make sure depthWriteEnable is set so that Depth fail test will work correctly
431 // Make sure stencilTestEnable is set so that Stencil fail test will work correctly
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600432 VkStencilOpState stencil = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +0800433 stencil.failOp = VK_STENCIL_OP_KEEP;
434 stencil.passOp = VK_STENCIL_OP_KEEP;
435 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
436 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600437
438 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
439 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600440 ds_ci.pNext = NULL;
441 ds_ci.depthTestEnable = VK_FALSE;
442 ds_ci.depthWriteEnable = VK_TRUE;
443 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
444 ds_ci.depthBoundsTestEnable = VK_FALSE;
445 ds_ci.stencilTestEnable = VK_TRUE;
446 ds_ci.front = stencil;
447 ds_ci.back = stencil;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600448
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600449 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600450 pipelineobj.SetViewport(m_viewports);
451 pipelineobj.SetScissor(m_scissors);
Chia-I Wu1f851912015-10-27 18:04:07 +0800452 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Cody Northropccfa96d2015-08-27 10:20:35 -0600453 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
454 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +0800455 commandBuffer->BindPipeline(pipelineobj);
456 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500457}
458
459// ********************************************************************************************************************
460// ********************************************************************************************************************
461// ********************************************************************************************************************
462// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600463#if MEM_TRACKER_TESTS
Tobin Ehliscb085292015-12-01 09:57:09 -0700464#if 0
Chia-I Wu1f851912015-10-27 18:04:07 +0800465TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinski81078192015-05-19 10:28:29 -0500466{
467 vk_testing::Fence testFence;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500468 VkFenceCreateInfo fenceInfo = {};
469 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
470 fenceInfo.pNext = NULL;
471 fenceInfo.flags = 0;
472
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600474
Mark Lobodzinski81078192015-05-19 10:28:29 -0500475 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barboure389b882015-07-20 13:00:10 -0600476
477 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
478 vk_testing::Buffer buffer;
479 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500480
Tony Barbour1490c912015-07-28 10:17:20 -0600481 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800482 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbour1490c912015-07-28 10:17:20 -0600483 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500484
485 testFence.init(*m_device, fenceInfo);
486
487 // Bypass framework since it does the waits automatically
488 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600489 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +0800490 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
491 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800492 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600493 submit_info.pWaitSemaphores = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800494 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +0800495 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +0800496 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600497 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600498
499 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500500 ASSERT_VK_SUCCESS( err );
501
Mark Lobodzinski81078192015-05-19 10:28:29 -0500502 // Introduce failure by calling begin again before checking fence
Chia-I Wu1f851912015-10-27 18:04:07 +0800503 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500504
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600505 if (!m_errorMonitor->DesiredMsgFound()) {
506 FAIL() << "Did not receive Error 'Resetting CB (0xaddress) before it has completed. You must check CB flag before.'";
507 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500508 }
509}
510
Chia-I Wu1f851912015-10-27 18:04:07 +0800511TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinski81078192015-05-19 10:28:29 -0500512{
513 vk_testing::Fence testFence;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500514 VkFenceCreateInfo fenceInfo = {};
515 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
516 fenceInfo.pNext = NULL;
517 fenceInfo.flags = 0;
518
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600520
Mark Lobodzinski81078192015-05-19 10:28:29 -0500521 ASSERT_NO_FATAL_FAILURE(InitState());
522 ASSERT_NO_FATAL_FAILURE(InitViewport());
523 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
524
Tony Barbour1490c912015-07-28 10:17:20 -0600525 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800526 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -0600527 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500528
529 testFence.init(*m_device, fenceInfo);
530
531 // Bypass framework since it does the waits automatically
532 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600533 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +0800534 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
535 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800536 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600537 submit_info.pWaitSemaphores = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800538 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +0800539 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +0800540 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600541 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600542
543 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500544 ASSERT_VK_SUCCESS( err );
545
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600546
Chia-I Wu1f851912015-10-27 18:04:07 +0800547 VkCommandBufferBeginInfo info = {};
548 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
549 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600550 info.renderPass = VK_NULL_HANDLE;
551 info.subpass = 0;
552 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wufdc1cd02015-11-11 10:18:12 +0800553 info.occlusionQueryEnable = VK_FALSE;
554 info.queryFlags = 0;
555 info.pipelineStatistics = 0;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600556
557 // Introduce failure by calling BCB again before checking fence
Chia-I Wu1f851912015-10-27 18:04:07 +0800558 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500559
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600560 if (!m_errorMonitor->DesiredMsgFound()) {
561 FAIL() << "Did not receive Error 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
562 m_errorMonitor->DumpFailureMsgs();
563
Mark Lobodzinski81078192015-05-19 10:28:29 -0500564 }
565}
Tobin Ehliscb085292015-12-01 09:57:09 -0700566#endif
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500567TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
568{
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500569 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600570 bool pass;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500571
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600573 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
574
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500575 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500576
577 // Create an image, allocate memory, free it, and then try to bind it
578 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500579 VkDeviceMemory mem;
580 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500581
582 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
583 const int32_t tex_width = 32;
584 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500585
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600586 VkImageCreateInfo image_create_info = {};
587 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
588 image_create_info.pNext = NULL;
589 image_create_info.imageType = VK_IMAGE_TYPE_2D;
590 image_create_info.format = tex_format;
591 image_create_info.extent.width = tex_width;
592 image_create_info.extent.height = tex_height;
593 image_create_info.extent.depth = 1;
594 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600595 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800596 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600597 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
598 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
599 image_create_info.flags = 0;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600600
Chia-I Wu1f851912015-10-27 18:04:07 +0800601 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +0800602 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600603 mem_alloc.pNext = NULL;
604 mem_alloc.allocationSize = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500605 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600606 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500607
Chia-I Wu69f40122015-10-26 21:10:41 +0800608 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500609 ASSERT_VK_SUCCESS(err);
610
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600611 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500612 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500613 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500614
Mark Lobodzinski23182612015-05-29 09:32:35 -0500615 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500616
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600617 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
618 if(!pass) { // If we can't find any unmappable memory this test doesn't make sense
Chia-I Wu69f40122015-10-26 21:10:41 +0800619 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour49a3b652015-08-04 16:13:01 -0600620 return;
Mike Stroyan2237f522015-08-18 14:40:24 -0600621 }
Mike Stroyand72da752015-08-04 10:49:29 -0600622
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500623 // allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +0800624 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500625 ASSERT_VK_SUCCESS(err);
626
627 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600628 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500629 ASSERT_VK_SUCCESS(err);
630
631 // Map memory as if to initialize the image
632 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500633 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500634
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600635 if (!m_errorMonitor->DesiredMsgFound()) {
636 FAIL() << "Did not receive Error 'Error received did not match expected error message from vkMapMemory in MemTracker'";
637 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500638 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600639
Chia-I Wu69f40122015-10-26 21:10:41 +0800640 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500641}
642
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600643// TODO : Is this test still valid. Not sure it is with updates to memory binding model
644// Verify and delete the test of fix the check
645//TEST_F(VkLayerTest, FreeBoundMemory)
646//{
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600647// VkResult err;
648//
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700649// m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600650// "Freeing memory object while it still has references");
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600651//
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600652// ASSERT_NO_FATAL_FAILURE(InitState());
653
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600654// // Create an image, allocate memory, free it, and then try to bind it
655// VkImage image;
656// VkDeviceMemory mem;
657// VkMemoryRequirements mem_reqs;
658//
659// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
660// const int32_t tex_width = 32;
661// const int32_t tex_height = 32;
662//
663// const VkImageCreateInfo image_create_info = {
664// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
665// .pNext = NULL,
666// .imageType = VK_IMAGE_TYPE_2D,
667// .format = tex_format,
668// .extent = { tex_width, tex_height, 1 },
669// .mipLevels = 1,
670// .arraySize = 1,
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800671// .samples = VK_SAMPLE_COUNT_1_BIT,
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600672// .tiling = VK_IMAGE_TILING_LINEAR,
673// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
674// .flags = 0,
675// };
Chia-I Wu1f851912015-10-27 18:04:07 +0800676// VkMemoryAllocateInfo mem_alloc = {
Chia-I Wuc1f5e402015-11-10 16:21:09 +0800677// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600678// .pNext = NULL,
679// .allocationSize = 0,
680// .memoryTypeIndex = 0,
681// };
682//
Chia-I Wu69f40122015-10-26 21:10:41 +0800683// err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600684// ASSERT_VK_SUCCESS(err);
685//
686// err = vkGetImageMemoryRequirements(m_device->device(),
687// image,
688// &mem_reqs);
689// ASSERT_VK_SUCCESS(err);
690//
691// mem_alloc.allocationSize = mem_reqs.size;
692//
693// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
694// ASSERT_VK_SUCCESS(err);
695//
696// // allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +0800697// err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600698// ASSERT_VK_SUCCESS(err);
699//
700// // Bind memory to Image object
701// err = vkBindImageMemory(m_device->device(), image, mem, 0);
702// ASSERT_VK_SUCCESS(err);
703//
704// // Introduce validation failure, free memory while still bound to object
Chia-I Wu69f40122015-10-26 21:10:41 +0800705// vkFreeMemory(m_device->device(), mem, NULL);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600706//
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600707// if (!m_errorMonitor->DesiredMsgFound()) {
708// FAIL() << "Did not receive Warning 'Freeing memory object while it still has references'");
709// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600710// }
711//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500712
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500713TEST_F(VkLayerTest, RebindMemory)
714{
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500715 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600716 bool pass;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500717
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600719 "which has already been bound to mem object");
720
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500721 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500722
723 // Create an image, allocate memory, free it, and then try to bind it
724 VkImage image;
725 VkDeviceMemory mem1;
726 VkDeviceMemory mem2;
727 VkMemoryRequirements mem_reqs;
728
729 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
730 const int32_t tex_width = 32;
731 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500732
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600733 VkImageCreateInfo image_create_info = {};
734 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
735 image_create_info.pNext = NULL;
736 image_create_info.imageType = VK_IMAGE_TYPE_2D;
737 image_create_info.format = tex_format;
738 image_create_info.extent.width = tex_width;
739 image_create_info.extent.height = tex_height;
740 image_create_info.extent.depth = 1;
741 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600742 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800743 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600744 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
745 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
746 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500747
Chia-I Wu1f851912015-10-27 18:04:07 +0800748 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +0800749 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600750 mem_alloc.pNext = NULL;
751 mem_alloc.allocationSize = 0;
752 mem_alloc.memoryTypeIndex = 0;
753
754 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
755 mem_alloc.memoryTypeIndex = 1;
Chia-I Wu69f40122015-10-26 21:10:41 +0800756 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500757 ASSERT_VK_SUCCESS(err);
758
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600759 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500760 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500761 &mem_reqs);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500762
763 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600764 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
765 ASSERT_TRUE(pass);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500766
767 // allocate 2 memory objects
Chia-I Wu1f851912015-10-27 18:04:07 +0800768 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500769 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +0800770 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500771 ASSERT_VK_SUCCESS(err);
772
773 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600774 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500775 ASSERT_VK_SUCCESS(err);
776
777 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600778 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500779
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600780 if (!m_errorMonitor->DesiredMsgFound()) {
781 FAIL() << "Did not receive Error when rebinding memory to an object";
782 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500783 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600784
Chia-I Wu69f40122015-10-26 21:10:41 +0800785 vkDestroyImage(m_device->device(), image, NULL);
786 vkFreeMemory(m_device->device(), mem1, NULL);
787 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500788}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500789
Tony Barbour8508b8e2015-04-09 10:48:04 -0600790TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600791{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600792 vk_testing::Fence testFence;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600793
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600795 "submitted in SIGNALED state. Fences must be reset before being submitted");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600796
797 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600798 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
799 fenceInfo.pNext = NULL;
800 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600801
Tony Barbour30486ea2015-04-07 13:44:53 -0600802 ASSERT_NO_FATAL_FAILURE(InitState());
803 ASSERT_NO_FATAL_FAILURE(InitViewport());
804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
805
Tony Barbour1490c912015-07-28 10:17:20 -0600806 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800807 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -0600808 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600809
810 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600811
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600812 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +0800813 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
814 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800815 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600816 submit_info.pWaitSemaphores = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800817 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +0800818 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +0800819 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600820 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600821
822 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600823 vkQueueWaitIdle(m_device->m_queue );
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600824
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600825 if (!m_errorMonitor->DesiredMsgFound()) {
826 FAIL() << "Did not receive Error 'VkQueueSubmit with fence in SIGNALED_STATE'";
827 m_errorMonitor->DumpFailureMsgs();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600828 }
Tony Barbour8508b8e2015-04-09 10:48:04 -0600829}
830
831TEST_F(VkLayerTest, ResetUnsignaledFence)
832{
833 vk_testing::Fence testFence;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600834 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600835 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
836 fenceInfo.pNext = NULL;
837
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700838 // TODO: verify that this matches layer
839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600840 "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
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600860 "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
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600913 "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
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600990 "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
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid VkImage Object ");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001062
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{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001133 "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{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001148 "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{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001164 "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{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001179 "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{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001194 "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{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001209 "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{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001224 "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{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001241 "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{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001258 "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
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001275 "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
Mark Lobodzinski611cf592015-12-18 15:35:38 -07001317TEST_F(VkLayerTest, BindPipelineNoRenderPass)
1318{
1319 // Initiate Draw w/o a PSO bound
1320 VkResult err;
1321
1322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1323 "vkCmdBindPipeline: This call must be issued inside an active render pass");
1324
1325 ASSERT_NO_FATAL_FAILURE(InitState());
1326 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1327
1328 VkDescriptorPoolSize ds_type_count = {};
1329 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1330 ds_type_count.descriptorCount = 1;
1331
1332 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1333 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1334 ds_pool_ci.pNext = NULL;
1335 ds_pool_ci.maxSets = 1;
1336 ds_pool_ci.poolSizeCount = 1;
1337 ds_pool_ci.pPoolSizes = &ds_type_count;
1338
1339 VkDescriptorPool ds_pool;
1340 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1341 ASSERT_VK_SUCCESS(err);
1342
1343 VkDescriptorSetLayoutBinding dsl_binding = {};
1344 dsl_binding.binding = 0;
1345 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1346 dsl_binding.descriptorCount = 1;
1347 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;
1353 ds_layout_ci.bindingCount = 1;
1354 ds_layout_ci.pBinding = &dsl_binding;
1355
1356 VkDescriptorSetLayout ds_layout;
1357 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1358 ASSERT_VK_SUCCESS(err);
1359
1360 VkDescriptorSet descriptorSet;
1361 VkDescriptorSetAllocateInfo alloc_info = {};
1362 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1363 alloc_info.setLayoutCount = 1;
1364 alloc_info.descriptorPool = ds_pool;
1365 alloc_info.pSetLayouts = &ds_layout;
1366 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1367 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;
1371 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
1372 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;
1379 pipeline_layout_ci.setLayoutCount = 1;
1380 pipeline_layout_ci.pSetLayouts = &ds_layout;
1381 VkPipelineLayout pipeline_layout;
1382
1383 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
1384 ASSERT_VK_SUCCESS(err);
1385
1386 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
1388 // 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());
1394
1395 // 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;
1400 cmd_buf_info.pNext = NULL;
1401 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1402
1403 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
1404 vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1405
1406 if (!m_errorMonitor->DesiredMsgFound()) {
1407 FAIL() << "Did not receive Error 'vkCmdBindPipeline: This call must be issued inside an active render pass'";
1408 m_errorMonitor->DumpFailureMsgs();
1409 }
1410
1411 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1412 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1413 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1414}
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
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001422 "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
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001482 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001483 "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/*
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001549 "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//
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001581// m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001582// "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
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001601 // TODO: verify that this matches layer
1602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001603 " bound but it was never updated. ");
1604
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001605 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001606 ASSERT_NO_FATAL_FAILURE(InitViewport());
1607 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wuc51b1212015-10-27 19:25:11 +08001608 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001609 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001610 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001611
1612 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1613 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1614 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001615 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001616 ds_pool_ci.poolSizeCount = 1;
1617 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001618
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001619 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001620 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001621 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001622
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001623 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001624 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001625 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001626 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001627 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1628 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001629
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001630 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1631 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1632 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001633 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001634 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001635 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001636 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001637 ASSERT_VK_SUCCESS(err);
1638
1639 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001640 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001641 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001642 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001643 alloc_info.descriptorPool = ds_pool;
1644 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001645 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001646 ASSERT_VK_SUCCESS(err);
1647
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001648 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1649 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1650 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001651 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001652 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001653
1654 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001655 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001656 ASSERT_VK_SUCCESS(err);
1657
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001658 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001659 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
1660 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001661
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001662 VkPipelineObj pipe(m_device);
1663 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001664 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001665 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001666
1667 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08001668 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1669 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001670
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001671 if (!m_errorMonitor->DesiredMsgFound()) {
1672 FAIL() << "Did not recieve Warning 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1673 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001674 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001675
Chia-I Wu69f40122015-10-26 21:10:41 +08001676 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1677 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1678 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001679}
1680
Tobin Ehlis093ef922015-11-02 15:24:32 -07001681TEST_F(VkLayerTest, InvalidBufferViewObject)
1682{
1683 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
1684 VkResult err;
1685
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis093ef922015-11-02 15:24:32 -07001687 "Attempt to update descriptor with invalid bufferView ");
1688
1689 ASSERT_NO_FATAL_FAILURE(InitState());
1690 VkDescriptorPoolSize ds_type_count = {};
1691 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1692 ds_type_count.descriptorCount = 1;
1693
1694 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1695 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1696 ds_pool_ci.pNext = NULL;
1697 ds_pool_ci.maxSets = 1;
1698 ds_pool_ci.poolSizeCount = 1;
1699 ds_pool_ci.pPoolSizes = &ds_type_count;
1700
1701 VkDescriptorPool ds_pool;
1702 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1703 ASSERT_VK_SUCCESS(err);
1704
1705 VkDescriptorSetLayoutBinding dsl_binding = {};
1706 dsl_binding.binding = 0;
1707 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001708 dsl_binding.descriptorCount = 1;
Tobin Ehlis093ef922015-11-02 15:24:32 -07001709 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1710 dsl_binding.pImmutableSamplers = NULL;
1711
1712 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1713 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1714 ds_layout_ci.pNext = NULL;
1715 ds_layout_ci.bindingCount = 1;
1716 ds_layout_ci.pBinding = &dsl_binding;
1717 VkDescriptorSetLayout ds_layout;
1718 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1719 ASSERT_VK_SUCCESS(err);
1720
1721 VkDescriptorSet descriptorSet;
1722 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001723 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Tobin Ehlis093ef922015-11-02 15:24:32 -07001724 alloc_info.setLayoutCount = 1;
1725 alloc_info.descriptorPool = ds_pool;
1726 alloc_info.pSetLayouts = &ds_layout;
1727 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1728 ASSERT_VK_SUCCESS(err);
1729
1730 VkBufferView view = (VkBufferView) 0xbaadbeef; // invalid bufferView object
Tobin Ehlis093ef922015-11-02 15:24:32 -07001731 VkWriteDescriptorSet descriptor_write;
1732 memset(&descriptor_write, 0, sizeof(descriptor_write));
1733 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1734 descriptor_write.dstSet = descriptorSet;
1735 descriptor_write.dstBinding = 0;
1736 descriptor_write.descriptorCount = 1;
1737 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1738 descriptor_write.pTexelBufferView = &view;
1739
1740 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1741
1742 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlisd9491452015-11-05 10:27:49 -07001743 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid bufferView'";
Tobin Ehlis093ef922015-11-02 15:24:32 -07001744 m_errorMonitor->DumpFailureMsgs();
1745 }
1746
1747 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1748 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1749}
1750
Tobin Ehlise2194862015-11-04 13:30:34 -07001751TEST_F(VkLayerTest, InvalidDynamicOffsetCount)
1752{
1753 // Create a descriptorSet w/ some dynamic descriptors and then don't send offsets when binding
1754 VkResult err;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlise2194862015-11-04 13:30:34 -07001756 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but dynamicOffsetCount is 0. ");
1757
1758 ASSERT_NO_FATAL_FAILURE(InitState());
1759 ASSERT_NO_FATAL_FAILURE(InitViewport());
1760 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1761
1762 VkDescriptorPoolSize ds_type_count = {};
1763 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1764 ds_type_count.descriptorCount = 1;
1765
1766 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1767 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1768 ds_pool_ci.pNext = NULL;
1769 ds_pool_ci.maxSets = 1;
1770 ds_pool_ci.poolSizeCount = 1;
1771 ds_pool_ci.pPoolSizes = &ds_type_count;
1772
1773 VkDescriptorPool ds_pool;
1774 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1775 ASSERT_VK_SUCCESS(err);
1776
1777 VkDescriptorSetLayoutBinding dsl_binding = {};
1778 dsl_binding.binding = 0;
1779 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
Jon Ashburn96b714a2015-11-06 15:31:44 -07001780 dsl_binding.descriptorCount = 1;
Tobin Ehlise2194862015-11-04 13:30:34 -07001781 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1782 dsl_binding.pImmutableSamplers = NULL;
1783
1784 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1785 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1786 ds_layout_ci.pNext = NULL;
1787 ds_layout_ci.bindingCount = 1;
1788 ds_layout_ci.pBinding = &dsl_binding;
1789 VkDescriptorSetLayout ds_layout;
1790 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1791 ASSERT_VK_SUCCESS(err);
1792
1793 VkDescriptorSet descriptorSet;
1794 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001795 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Tobin Ehlise2194862015-11-04 13:30:34 -07001796 alloc_info.setLayoutCount = 1;
1797 alloc_info.descriptorPool = ds_pool;
1798 alloc_info.pSetLayouts = &ds_layout;
1799 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1800 ASSERT_VK_SUCCESS(err);
1801
1802 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1803 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1804 pipeline_layout_ci.pNext = NULL;
1805 pipeline_layout_ci.setLayoutCount = 1;
1806 pipeline_layout_ci.pSetLayouts = &ds_layout;
1807
1808 VkPipelineLayout pipeline_layout;
1809 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
1810 ASSERT_VK_SUCCESS(err);
1811
1812 // Create a buffer to update the descriptor with
1813 uint32_t qfi = 0;
1814 VkBufferCreateInfo buffCI = {};
1815 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1816 buffCI.size = 1024;
1817 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1818 buffCI.queueFamilyIndexCount = 1;
1819 buffCI.pQueueFamilyIndices = &qfi;
1820
1821 VkBuffer dyub;
1822 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
1823 ASSERT_VK_SUCCESS(err);
1824 // Correctly update descriptor to avoid "NOT_UPDATED" error
1825 VkDescriptorBufferInfo buffInfo = {};
1826 buffInfo.buffer = dyub;
1827 buffInfo.offset = 0;
1828 buffInfo.range = 1024;
1829
1830 VkWriteDescriptorSet descriptor_write;
1831 memset(&descriptor_write, 0, sizeof(descriptor_write));
1832 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1833 descriptor_write.dstSet = descriptorSet;
1834 descriptor_write.dstBinding = 0;
1835 descriptor_write.descriptorCount = 1;
1836 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1837 descriptor_write.pBufferInfo = &buffInfo;
1838
1839 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1840
1841 BeginCommandBuffer();
1842 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
1843
1844 if (!m_errorMonitor->DesiredMsgFound()) {
1845 FAIL() << "Error received was not 'Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but dynamicOffsetCount is 0...'";
1846 m_errorMonitor->DumpFailureMsgs();
1847 }
1848
1849 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1850 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1851}
1852
Tobin Ehlis982099b2015-11-05 09:52:49 -07001853TEST_F(VkLayerTest, DescriptorSetCompatibility)
1854{
1855 // Test various desriptorSet errors with bad binding combinations
1856 VkResult err;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001857
1858 ASSERT_NO_FATAL_FAILURE(InitState());
1859 ASSERT_NO_FATAL_FAILURE(InitViewport());
1860 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1861
1862 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
1863 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
1864 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Tobin Ehliscb085292015-12-01 09:57:09 -07001865 ds_type_count[0].descriptorCount = 10;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001866 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1867 ds_type_count[1].descriptorCount = 2;
1868 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
1869 ds_type_count[2].descriptorCount = 2;
1870 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
1871 ds_type_count[3].descriptorCount = 5;
1872 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT type
1873 //ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
1874 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1875 ds_type_count[4].descriptorCount = 2;
1876
1877 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1878 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1879 ds_pool_ci.pNext = NULL;
1880 ds_pool_ci.maxSets = 1;
1881 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
1882 ds_pool_ci.pPoolSizes = ds_type_count;
1883
1884 VkDescriptorPool ds_pool;
1885 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1886 ASSERT_VK_SUCCESS(err);
1887
1888 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
1889 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
1890 dsl_binding[0].binding = 0;
1891 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Tobin Ehliscb085292015-12-01 09:57:09 -07001892 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001893 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
1894 dsl_binding[0].pImmutableSamplers = NULL;
1895
Tobin Ehliscb085292015-12-01 09:57:09 -07001896 // Create layout identical to set0 layout but w/ different stageFlags
1897 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
1898 dsl_fs_stage_only.binding = 0;
1899 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1900 dsl_fs_stage_only.descriptorCount = 5;
1901 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at bind time
1902 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001903 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1904 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1905 ds_layout_ci.pNext = NULL;
1906 ds_layout_ci.bindingCount = 1;
1907 ds_layout_ci.pBinding = dsl_binding;
1908 static const uint32_t NUM_LAYOUTS = 4;
1909 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehliscb085292015-12-01 09:57:09 -07001910 VkDescriptorSetLayout ds_layout_fs_only = {};
1911 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only layout for error case
Tobin Ehlis982099b2015-11-05 09:52:49 -07001912 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
1913 ASSERT_VK_SUCCESS(err);
Tobin Ehliscb085292015-12-01 09:57:09 -07001914 ds_layout_ci.pBinding = &dsl_fs_stage_only;
1915 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
1916 ASSERT_VK_SUCCESS(err);
Tobin Ehlis982099b2015-11-05 09:52:49 -07001917 dsl_binding[0].binding = 0;
1918 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehliscb085292015-12-01 09:57:09 -07001919 dsl_binding[0].descriptorCount = 2;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001920 dsl_binding[0].binding = 1;
1921 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehliscb085292015-12-01 09:57:09 -07001922 dsl_binding[0].descriptorCount = 2;
1923 ds_layout_ci.pBinding = dsl_binding;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001924 ds_layout_ci.bindingCount = 2;
1925 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
1926 ASSERT_VK_SUCCESS(err);
1927 dsl_binding[0].binding = 0;
1928 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehliscb085292015-12-01 09:57:09 -07001929 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001930 ds_layout_ci.bindingCount = 1;
1931 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
1932 ASSERT_VK_SUCCESS(err);
1933 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehliscb085292015-12-01 09:57:09 -07001934 dsl_binding[0].descriptorCount = 2;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001935 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
1936 ASSERT_VK_SUCCESS(err);
1937
1938 static const uint32_t NUM_SETS = 4;
1939 VkDescriptorSet descriptorSet[NUM_SETS] = {};
1940 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehliscb085292015-12-01 09:57:09 -07001941 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001942 alloc_info.setLayoutCount = NUM_LAYOUTS;
1943 alloc_info.descriptorPool = ds_pool;
1944 alloc_info.pSetLayouts = ds_layout;
1945 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
1946 ASSERT_VK_SUCCESS(err);
Tobin Ehliscb085292015-12-01 09:57:09 -07001947 VkDescriptorSet ds0_fs_only = {};
1948 alloc_info.setLayoutCount = 1;
1949 alloc_info.pSetLayouts = &ds_layout_fs_only;
1950 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
1951 ASSERT_VK_SUCCESS(err);
Tobin Ehlis982099b2015-11-05 09:52:49 -07001952
1953 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1954 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1955 pipeline_layout_ci.pNext = NULL;
1956 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
1957 pipeline_layout_ci.pSetLayouts = ds_layout;
1958
1959 VkPipelineLayout pipeline_layout;
1960 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
1961 ASSERT_VK_SUCCESS(err);
Tobin Ehliscb085292015-12-01 09:57:09 -07001962 // Create pipelineLayout with only one setLayout
1963 pipeline_layout_ci.setLayoutCount = 1;
1964 VkPipelineLayout single_pipe_layout;
1965 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
1966 ASSERT_VK_SUCCESS(err);
1967 // Create pipelineLayout with 2 descriptor setLayout at index 0
1968 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
1969 VkPipelineLayout pipe_layout_one_desc;
1970 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
1971 ASSERT_VK_SUCCESS(err);
1972 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
1973 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
1974 VkPipelineLayout pipe_layout_five_samp;
1975 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
1976 ASSERT_VK_SUCCESS(err);
1977 // Create pipelineLayout with UB type, but stageFlags for FS only
1978 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
1979 VkPipelineLayout pipe_layout_fs_only;
1980 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
1981 ASSERT_VK_SUCCESS(err);
1982 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
1983 VkDescriptorSetLayout pl_bad_s0[2] = {};
1984 pl_bad_s0[0] = ds_layout_fs_only;
1985 pl_bad_s0[1] = ds_layout[1];
1986 pipeline_layout_ci.setLayoutCount = 2;
1987 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
1988 VkPipelineLayout pipe_layout_bad_set0;
1989 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
1990 ASSERT_VK_SUCCESS(err);
Tobin Ehlis982099b2015-11-05 09:52:49 -07001991
1992 // Create a buffer to update the descriptor with
1993 uint32_t qfi = 0;
1994 VkBufferCreateInfo buffCI = {};
1995 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1996 buffCI.size = 1024;
1997 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1998 buffCI.queueFamilyIndexCount = 1;
1999 buffCI.pQueueFamilyIndices = &qfi;
2000
2001 VkBuffer dyub;
2002 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
2003 ASSERT_VK_SUCCESS(err);
2004 // Correctly update descriptor to avoid "NOT_UPDATED" error
2005 static const uint32_t NUM_BUFFS = 5;
2006 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
2007 for (uint32_t i=0; i<NUM_BUFFS; ++i) {
2008 buffInfo[i].buffer = dyub;
2009 buffInfo[i].offset = 0;
2010 buffInfo[i].range = 1024;
2011 }
Tobin Ehliscb085292015-12-01 09:57:09 -07002012 VkImage image;
2013 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2014 const int32_t tex_width = 32;
2015 const int32_t tex_height = 32;
2016 VkImageCreateInfo image_create_info = {};
2017 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2018 image_create_info.pNext = NULL;
2019 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2020 image_create_info.format = tex_format;
2021 image_create_info.extent.width = tex_width;
2022 image_create_info.extent.height = tex_height;
2023 image_create_info.extent.depth = 1;
2024 image_create_info.mipLevels = 1;
2025 image_create_info.arrayLayers = 1;
2026 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2027 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2028 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2029 image_create_info.flags = 0;
2030 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2031 ASSERT_VK_SUCCESS(err);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002032
Tobin Ehliscb085292015-12-01 09:57:09 -07002033 VkImageViewCreateInfo image_view_create_info = {};
2034 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2035 image_view_create_info.image = image;
2036 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
2037 image_view_create_info.format = tex_format;
2038 image_view_create_info.subresourceRange.layerCount = 1;
2039 image_view_create_info.subresourceRange.baseMipLevel = 0;
2040 image_view_create_info.subresourceRange.levelCount = 1;
2041 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis982099b2015-11-05 09:52:49 -07002042
Tobin Ehliscb085292015-12-01 09:57:09 -07002043 VkImageView view;
2044 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
2045 ASSERT_VK_SUCCESS(err);
2046 VkDescriptorImageInfo imageInfo[2] = {};
2047 imageInfo[0].imageView = view;
2048 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2049 imageInfo[1].imageView = view;
2050 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2051
2052 static const uint32_t NUM_SET_UPDATES = 3;
2053 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
2054 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2055 descriptor_write[0].dstSet = descriptorSet[0];
2056 descriptor_write[0].dstBinding = 0;
2057 descriptor_write[0].descriptorCount = 5;
2058 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2059 descriptor_write[0].pBufferInfo = buffInfo;
2060 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2061 descriptor_write[1].dstSet = descriptorSet[1];
2062 descriptor_write[1].dstBinding = 0;
2063 descriptor_write[1].descriptorCount = 2;
2064 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
2065 descriptor_write[1].pImageInfo = imageInfo;
2066 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2067 descriptor_write[2].dstSet = descriptorSet[1];
2068 descriptor_write[2].dstBinding = 1;
2069 descriptor_write[2].descriptorCount = 2;
2070 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
2071 descriptor_write[2].pImageInfo = imageInfo;
2072
2073 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002074
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002075 // Create PSO to be used for draw-time errors below
2076 char const *vsSource =
2077 "#version 140\n"
2078 "#extension GL_ARB_separate_shader_objects: require\n"
2079 "#extension GL_ARB_shading_language_420pack: require\n"
2080 "\n"
2081 "void main(){\n"
2082 " gl_Position = vec4(1);\n"
2083 "}\n";
2084 char const *fsSource =
2085 "#version 140\n"
2086 "#extension GL_ARB_separate_shader_objects: require\n"
2087 "#extension GL_ARB_shading_language_420pack: require\n"
2088 "\n"
2089 "layout(location=0) out vec4 x;\n"
2090 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
2091 "void main(){\n"
2092 " x = vec4(bar.y);\n"
2093 "}\n";
2094 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2095 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002096 VkPipelineObj pipe(m_device);
2097 pipe.AddShader(&vs);
2098 pipe.AddShader(&fs);
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002099 pipe.AddColorAttachment();
2100 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis982099b2015-11-05 09:52:49 -07002101
2102 BeginCommandBuffer();
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002103
Tobin Ehlis982099b2015-11-05 09:52:49 -07002104 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2105 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding of PSO
2106 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of cmd_pipeline.c
2107 // due to the fact that cmd_alloc_dset_data() has not been called in cmd_bind_graphics_pipeline()
2108 // TODO : Want to cause various binding incompatibility issues here to test DrawState
2109 // First cause various verify_layout_compatibility() fails
2110 // Second disturb early and late sets and verify INFO msgs
Tobin Ehliscb085292015-12-01 09:57:09 -07002111 // verify_set_layout_compatibility fail cases:
2112 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " due to: invalid VkPipelineLayout ");
Tobin Ehliscb085292015-12-01 09:57:09 -07002114 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, (VkPipelineLayout)0xbaadb1be, 0, 1, &descriptorSet[0], 0, NULL);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002115 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehliscb085292015-12-01 09:57:09 -07002116 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSets with invalid VkPipelineLayout.";
Tobin Ehlis982099b2015-11-05 09:52:49 -07002117 m_errorMonitor->DumpFailureMsgs();
2118 }
Tobin Ehliscb085292015-12-01 09:57:09 -07002119 // 2. layoutIndex exceeds # of layouts in layout
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
Tobin Ehliscb085292015-12-01 09:57:09 -07002121 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2, &descriptorSet[0], 0, NULL);
2122 if (!m_errorMonitor->DesiredMsgFound()) {
2123 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSet to index 1 when pipelineLayout only has index 0.";
2124 m_errorMonitor->DumpFailureMsgs();
2125 }
2126 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
2127 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 descriptors
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", but corresponding set being bound has 5 descriptors.");
Tobin Ehliscb085292015-12-01 09:57:09 -07002129 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
2130 if (!m_errorMonitor->DesiredMsgFound()) {
2131 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSet w/ 5 descriptors to pipelineLayout with only 2 descriptors.";
2132 m_errorMonitor->DumpFailureMsgs();
2133 }
2134 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
2135 // 4. same # of descriptors but mismatch in type
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " descriptor from pipelineLayout is type 'VK_DESCRIPTOR_TYPE_SAMPLER'");
Tobin Ehliscb085292015-12-01 09:57:09 -07002137 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
2138 if (!m_errorMonitor->DesiredMsgFound()) {
2139 FAIL() << "Did not receive correct error msg when attempting to bind UNIFORM_BUFFER descriptorSet to pipelineLayout with overlapping SAMPLER type.";
2140 m_errorMonitor->DumpFailureMsgs();
2141 }
2142 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
2143 // 5. same # of descriptors but mismatch in stageFlags
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " descriptor from pipelineLayout has stageFlags ");
Tobin Ehliscb085292015-12-01 09:57:09 -07002145 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
2146 if (!m_errorMonitor->DesiredMsgFound()) {
2147 FAIL() << "Did not receive correct error msg when attempting to bind UNIFORM_BUFFER descriptorSet with ALL stageFlags to pipelineLayout with FS-only stageFlags.";
2148 m_errorMonitor->DumpFailureMsgs();
2149 }
2150 // Cause INFO messages due to disturbing previously bound Sets
2151 // First bind sets 0 & 1
2152 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2153 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, " previously bound as set #0 was disturbed ");
Tobin Ehliscb085292015-12-01 09:57:09 -07002155 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
2156 if (!m_errorMonitor->DesiredMsgFound()) {
2157 FAIL() << "Did not receive correct info msg when binding Set1 w/ pipelineLayout that should disturb Set0.";
2158 m_errorMonitor->DumpFailureMsgs();
2159 }
2160 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
2161 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2162 // 2. Disturb set after last bound set
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, " newly bound as set #0 so set #1 and any subsequent sets were disturbed ");
Tobin Ehliscb085292015-12-01 09:57:09 -07002164 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
2165 if (!m_errorMonitor->DesiredMsgFound()) {
2166 FAIL() << "Did not receive correct info msg when re-binding Set0 w/ pipelineLayout that should disturb Set1.";
2167 m_errorMonitor->DumpFailureMsgs();
2168 }
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002169
2170 // Cause draw-time errors due to PSO incompatibilities
2171 // 1. Error due to not binding required set (we actually use same code as above to disturb set0)
2172 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2173 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " uses set #0 but that set is not bound.");
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002175 Draw(1, 0, 0, 0);
2176 if (!m_errorMonitor->DesiredMsgFound()) {
2177 FAIL() << "Did not receive correct error msg when attempting draw requiring Set0 but Set0 is not bound.";
2178 m_errorMonitor->DumpFailureMsgs();
2179 }
2180 // 2. Error due to bound set not being compatible with PSO's VkPipelineLayout (diff stageFlags in this case)
2181 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002183 Draw(1, 0, 0, 0);
2184 if (!m_errorMonitor->DesiredMsgFound()) {
2185 FAIL() << "Did not receive correct error msg when attempted draw where bound Set0 layout is not compatible PSO Set0 layout.";
2186 m_errorMonitor->DumpFailureMsgs();
2187 }
Tobin Ehliscb085292015-12-01 09:57:09 -07002188 // Remaining clean-up
2189 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
2190 for (uint32_t i=0; i<NUM_LAYOUTS; ++i) {
2191 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
2192 }
2193 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
2194 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, descriptorSet);
2195 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002196 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2197 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
2198}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002199
Chia-I Wu1f851912015-10-27 18:04:07 +08002200TEST_F(VkLayerTest, NoBeginCommandBuffer)
Tobin Ehlis254eca02015-06-25 15:46:59 -06002201{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002202
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002204 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlis254eca02015-06-25 15:46:59 -06002205
2206 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +08002207 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002208 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu1f851912015-10-27 18:04:07 +08002209 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002210
2211 if (!m_errorMonitor->DesiredMsgFound()) {
2212 FAIL() << "Did not recieve Error 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
2213 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06002214 }
2215}
2216
Chia-I Wu1f851912015-10-27 18:04:07 +08002217TEST_F(VkLayerTest, PrimaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002218{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002219
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002221 "may not specify framebuffer or renderpass parameters");
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002222
2223 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002224
Chia-I Wu1f851912015-10-27 18:04:07 +08002225 // Calls AllocateCommandBuffers
2226 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002227
2228 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Chia-I Wu1f851912015-10-27 18:04:07 +08002229 VkCommandBufferBeginInfo cmd_buf_info = {};
2230 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06002231 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002232 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Cody Northrop10d8f982015-08-04 17:35:57 -06002233 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
2234 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
2235
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002236
2237 // The error should be caught by validation of the BeginCommandBuffer call
Chia-I Wu1f851912015-10-27 18:04:07 +08002238 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002239
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002240 if (!m_errorMonitor->DesiredMsgFound()) {
2241 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
2242 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002243 }
2244}
2245
Chia-I Wu1f851912015-10-27 18:04:07 +08002246TEST_F(VkLayerTest, SecondaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002247{
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002248 VkResult err;
Chia-I Wu1f851912015-10-27 18:04:07 +08002249 VkCommandBuffer draw_cmd;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002250
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002252 "must specify framebuffer and renderpass parameters");
2253
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002254 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002255
Chia-I Wu1f851912015-10-27 18:04:07 +08002256 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002257 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06002258 cmd.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002259 cmd.commandPool = m_commandPool;
2260 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Chia-I Wu763a7492015-10-26 20:48:51 +08002261 cmd.bufferCount = 1;
Cody Northrop10d8f982015-08-04 17:35:57 -06002262
Chia-I Wu1f851912015-10-27 18:04:07 +08002263 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyan2237f522015-08-18 14:40:24 -06002264 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002265
2266 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu1f851912015-10-27 18:04:07 +08002267 VkCommandBufferBeginInfo cmd_buf_info = {};
2268 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06002269 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002270 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002271
2272 // The error should be caught by validation of the BeginCommandBuffer call
2273 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
2274
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002275 if (!m_errorMonitor->DesiredMsgFound()) {
2276 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
2277 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002278 }
Chia-I Wu1f851912015-10-27 18:04:07 +08002279 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002280}
2281
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002282TEST_F(VkLayerTest, CommandBufferResetErrors)
2283{
2284 // Cause error due to Begin while recording CB
2285 // Then cause 2 errors for attempting to reset CB w/o having
2286 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
2287 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002289 "Cannot call Begin on CB");
2290
2291 ASSERT_NO_FATAL_FAILURE(InitState());
2292
2293 // Calls AllocateCommandBuffers
2294 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
2295
2296 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
2297 VkCommandBufferBeginInfo cmd_buf_info = {};
2298 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2299 cmd_buf_info.pNext = NULL;
2300 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
2301
2302 // Begin CB to transition to recording state
2303 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2304 // Can't re-begin. This should trigger error
2305 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2306 if (!m_errorMonitor->DesiredMsgFound()) {
2307 FAIL() << "Did not receive Error 'Cannot call Begin on CB (0x<ADDR>) in the RECORDING state...'";
2308 m_errorMonitor->DumpFailureMsgs();
2309 }
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002311 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
2312 // Reset attempt will trigger error due to incorrect CommandPool state
2313 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
2314 if (!m_errorMonitor->DesiredMsgFound()) {
2315 FAIL() << "Did not receive Error 'Attempt to reset command buffer (0x<ADDR>) created from command pool...'";
2316 m_errorMonitor->DumpFailureMsgs();
2317 }
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002319 // Transition CB to RECORDED state
2320 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
2321 // Now attempting to Begin will implicitly reset, which triggers error
2322 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2323 if (!m_errorMonitor->DesiredMsgFound()) {
2324 FAIL() << "Did not receive Error 'Call to vkBeginCommandBuffer() on command buffer (0x<ADDR>) attempts to implicitly reset...'";
2325 m_errorMonitor->DumpFailureMsgs();
2326 }
2327}
2328
Tobin Ehlis254eca02015-06-25 15:46:59 -06002329TEST_F(VkLayerTest, InvalidPipelineCreateState)
2330{
2331 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis254eca02015-06-25 15:46:59 -06002332 VkResult err;
2333
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002335 "Invalid Pipeline CreateInfo State: Vtx Shader required");
2336
Tobin Ehlis254eca02015-06-25 15:46:59 -06002337 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002338 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002339
Chia-I Wuc51b1212015-10-27 19:25:11 +08002340 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002341 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002342 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002343
2344 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2345 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2346 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002347 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002348 ds_pool_ci.poolSizeCount = 1;
2349 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002350
Tobin Ehlis254eca02015-06-25 15:46:59 -06002351 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002352 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002353 ASSERT_VK_SUCCESS(err);
2354
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002355 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002356 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002357 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002358 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002359 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2360 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002361
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002362 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2363 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2364 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002365 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002366 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002367
Tobin Ehlis254eca02015-06-25 15:46:59 -06002368 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002369 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002370 ASSERT_VK_SUCCESS(err);
2371
2372 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002373 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002374 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002375 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002376 alloc_info.descriptorPool = ds_pool;
2377 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002378 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002379 ASSERT_VK_SUCCESS(err);
2380
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002381 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2382 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002383 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002384 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002385
2386 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002387 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002388 ASSERT_VK_SUCCESS(err);
2389
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002390 VkViewport vp = {}; // Just need dummy vp to point to
2391 VkRect2D sc = {}; // dummy scissor to point to
2392
2393 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2394 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2395 vp_state_ci.scissorCount = 1;
2396 vp_state_ci.pScissors = &sc;
2397 vp_state_ci.viewportCount = 1;
2398 vp_state_ci.pViewports = &vp;
2399
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002400 VkGraphicsPipelineCreateInfo gp_ci = {};
2401 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002402 gp_ci.pViewportState = &vp_state_ci;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002403 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2404 gp_ci.layout = pipeline_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002405 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002406
2407 VkPipelineCacheCreateInfo pc_ci = {};
2408 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Chia-I Wu7e470702015-10-26 17:24:52 +08002409 pc_ci.initialDataSize = 0;
2410 pc_ci.pInitialData = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002411
2412 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06002413 VkPipelineCache pipelineCache;
2414
Chia-I Wu69f40122015-10-26 21:10:41 +08002415 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06002416 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002417 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002418
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002419 if (!m_errorMonitor->DesiredMsgFound()) {
2420 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
2421 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06002422 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002423
Chia-I Wu69f40122015-10-26 21:10:41 +08002424 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2425 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2426 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2427 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002428}
Tobin Ehlis20693172015-09-17 08:46:18 -06002429/*// TODO : This test should be good, but needs Tess support in compiler to run
2430TEST_F(VkLayerTest, InvalidPatchControlPoints)
2431{
2432 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis20693172015-09-17 08:46:18 -06002433 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002434
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002436 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ");
2437
Tobin Ehlis20693172015-09-17 08:46:18 -06002438 ASSERT_NO_FATAL_FAILURE(InitState());
2439 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis20693172015-09-17 08:46:18 -06002440
Chia-I Wuc51b1212015-10-27 19:25:11 +08002441 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis20693172015-09-17 08:46:18 -06002442 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002443 ds_type_count.descriptorCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002444
2445 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2446 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2447 ds_pool_ci.pNext = NULL;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002448 ds_pool_ci.poolSizeCount = 1;
2449 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis20693172015-09-17 08:46:18 -06002450
2451 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002452 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 -06002453 ASSERT_VK_SUCCESS(err);
2454
2455 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002456 dsl_binding.binding = 0;
Tobin Ehlis20693172015-09-17 08:46:18 -06002457 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002458 dsl_binding.descriptorCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002459 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2460 dsl_binding.pImmutableSamplers = NULL;
2461
2462 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2463 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2464 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002465 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002466 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis20693172015-09-17 08:46:18 -06002467
2468 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002469 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis20693172015-09-17 08:46:18 -06002470 ASSERT_VK_SUCCESS(err);
2471
2472 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002473 err = vkAllocateDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis20693172015-09-17 08:46:18 -06002474 ASSERT_VK_SUCCESS(err);
2475
2476 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2477 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2478 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002479 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002480 pipeline_layout_ci.pSetLayouts = &ds_layout;
2481
2482 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002483 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis20693172015-09-17 08:46:18 -06002484 ASSERT_VK_SUCCESS(err);
2485
2486 VkPipelineShaderStageCreateInfo shaderStages[3];
2487 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
2488
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002489 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06002490 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002491 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
2492 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06002493
2494 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002495 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002496 shaderStages[0].shader = vs.handle();
2497 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002498 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002499 shaderStages[1].shader = tc.handle();
2500 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002501 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002502 shaderStages[2].shader = te.handle();
2503
2504 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
2505 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08002506 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis20693172015-09-17 08:46:18 -06002507
2508 VkPipelineTessellationStateCreateInfo tsCI = {};
2509 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
2510 tsCI.patchControlPoints = 0; // This will cause an error
2511
2512 VkGraphicsPipelineCreateInfo gp_ci = {};
2513 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2514 gp_ci.pNext = NULL;
2515 gp_ci.stageCount = 3;
2516 gp_ci.pStages = shaderStages;
2517 gp_ci.pVertexInputState = NULL;
2518 gp_ci.pInputAssemblyState = &iaCI;
2519 gp_ci.pTessellationState = &tsCI;
2520 gp_ci.pViewportState = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002521 gp_ci.pRasterizationState = NULL;
Tobin Ehlis20693172015-09-17 08:46:18 -06002522 gp_ci.pMultisampleState = NULL;
2523 gp_ci.pDepthStencilState = NULL;
2524 gp_ci.pColorBlendState = NULL;
2525 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2526 gp_ci.layout = pipeline_layout;
2527 gp_ci.renderPass = renderPass();
2528
2529 VkPipelineCacheCreateInfo pc_ci = {};
2530 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2531 pc_ci.pNext = NULL;
2532 pc_ci.initialSize = 0;
2533 pc_ci.initialData = 0;
2534 pc_ci.maxSize = 0;
2535
2536 VkPipeline pipeline;
2537 VkPipelineCache pipelineCache;
2538
Chia-I Wu69f40122015-10-26 21:10:41 +08002539 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis20693172015-09-17 08:46:18 -06002540 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002541 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis20693172015-09-17 08:46:18 -06002542
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002543 if (!m_errorMonitor->DesiredMsgFound()) {
2544 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...'";
2545 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis20693172015-09-17 08:46:18 -06002546 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002547
Chia-I Wu69f40122015-10-26 21:10:41 +08002548 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2549 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2550 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2551 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis20693172015-09-17 08:46:18 -06002552}
2553*/
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002554// Set scissor and viewport counts to different numbers
2555TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
2556{
2557 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002558 VkResult err;
2559
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002561 "Gfx Pipeline viewport count (1) must match scissor count (0).");
2562
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002563 ASSERT_NO_FATAL_FAILURE(InitState());
2564 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002565
Chia-I Wuc51b1212015-10-27 19:25:11 +08002566 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002567 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002568 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002569
2570 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2571 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002572 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002573 ds_pool_ci.poolSizeCount = 1;
2574 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002575
2576 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002577 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002578 ASSERT_VK_SUCCESS(err);
2579
2580 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002581 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002582 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002583 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002584 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2585
2586 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2587 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002588 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002589 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002590
2591 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002592 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002593 ASSERT_VK_SUCCESS(err);
2594
2595 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002596 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002597 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002598 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002599 alloc_info.descriptorPool = ds_pool;
2600 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002601 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002602 ASSERT_VK_SUCCESS(err);
2603
2604 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2605 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002606 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002607 pipeline_layout_ci.pSetLayouts = &ds_layout;
2608
2609 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002610 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002611 ASSERT_VK_SUCCESS(err);
2612
2613 VkViewport vp = {}; // Just need dummy vp to point to
2614
2615 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2616 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2617 vp_state_ci.scissorCount = 0;
2618 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2619 vp_state_ci.pViewports = &vp;
2620
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002621 VkPipelineShaderStageCreateInfo shaderStages[2];
2622 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002623
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002624 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2625 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 -06002626 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002627 shaderStages[0] = vs.GetStageCreateInfo();
2628 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002629
2630 VkGraphicsPipelineCreateInfo gp_ci = {};
2631 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002632 gp_ci.stageCount = 2;
2633 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002634 gp_ci.pViewportState = &vp_state_ci;
2635 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2636 gp_ci.layout = pipeline_layout;
2637 gp_ci.renderPass = renderPass();
2638
2639 VkPipelineCacheCreateInfo pc_ci = {};
2640 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2641
2642 VkPipeline pipeline;
2643 VkPipelineCache pipelineCache;
2644
Chia-I Wu69f40122015-10-26 21:10:41 +08002645 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002646 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002647 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002648
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002649 if (!m_errorMonitor->DesiredMsgFound()) {
2650 FAIL() << "Did not receive Error 'Gfx Pipeline viewport count (1) must match scissor count (0).'";
2651 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002652 }
2653
Chia-I Wu69f40122015-10-26 21:10:41 +08002654 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2655 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2656 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2657 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002658}
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002659// Don't set viewport state in PSO. This is an error b/c we always need this state
2660// for the counts even if the data is going to be set dynamically.
2661TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002662{
2663 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002664 VkResult err;
2665
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002667 "Gfx Pipeline pViewportState is null. Even if ");
2668
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002669 ASSERT_NO_FATAL_FAILURE(InitState());
2670 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002671
Chia-I Wuc51b1212015-10-27 19:25:11 +08002672 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002673 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002674 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002675
2676 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2677 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002678 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002679 ds_pool_ci.poolSizeCount = 1;
2680 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002681
2682 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002683 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002684 ASSERT_VK_SUCCESS(err);
2685
2686 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002687 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002688 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002689 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002690 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2691
2692 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2693 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002694 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002695 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002696
2697 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002698 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002699 ASSERT_VK_SUCCESS(err);
2700
2701 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002702 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002703 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002704 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002705 alloc_info.descriptorPool = ds_pool;
2706 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002707 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002708 ASSERT_VK_SUCCESS(err);
2709
2710 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2711 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002712 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002713 pipeline_layout_ci.pSetLayouts = &ds_layout;
2714
2715 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002716 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002717 ASSERT_VK_SUCCESS(err);
2718
2719 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2720 // Set scissor as dynamic to avoid second error
2721 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2722 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2723 dyn_state_ci.dynamicStateCount = 1;
2724 dyn_state_ci.pDynamicStates = &sc_state;
2725
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002726 VkPipelineShaderStageCreateInfo shaderStages[2];
2727 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002728
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002729 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2730 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 -06002731 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002732 shaderStages[0] = vs.GetStageCreateInfo();
2733 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002734
2735 VkGraphicsPipelineCreateInfo gp_ci = {};
2736 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002737 gp_ci.stageCount = 2;
2738 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002739 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2740 gp_ci.pDynamicState = &dyn_state_ci;
2741 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2742 gp_ci.layout = pipeline_layout;
2743 gp_ci.renderPass = renderPass();
2744
2745 VkPipelineCacheCreateInfo pc_ci = {};
2746 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2747
2748 VkPipeline pipeline;
2749 VkPipelineCache pipelineCache;
2750
Chia-I Wu69f40122015-10-26 21:10:41 +08002751 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002752 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002753 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002754
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002755 if (!m_errorMonitor->DesiredMsgFound()) {
2756 FAIL() << "Did not receive Error 'Gfx Pipeline pViewportState is null. Even if...'";
2757 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002758 }
2759
Chia-I Wu69f40122015-10-26 21:10:41 +08002760 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2761 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2762 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2763 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002764}
2765// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002766// Then run second test where dynamic scissor count doesn't match PSO scissor count
2767TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002768{
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002769 VkResult err;
2770
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002772 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
2773
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002774 ASSERT_NO_FATAL_FAILURE(InitState());
2775 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002776
Chia-I Wuc51b1212015-10-27 19:25:11 +08002777 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002778 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002779 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002780
2781 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2782 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002783 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002784 ds_pool_ci.poolSizeCount = 1;
2785 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002786
2787 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002788 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002789 ASSERT_VK_SUCCESS(err);
2790
2791 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002792 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002793 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002794 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002795 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2796
2797 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2798 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002799 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002800 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002801
2802 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002803 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002804 ASSERT_VK_SUCCESS(err);
2805
2806 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002807 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002808 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002809 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002810 alloc_info.descriptorPool = ds_pool;
2811 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002812 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002813 ASSERT_VK_SUCCESS(err);
2814
2815 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2816 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002817 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002818 pipeline_layout_ci.pSetLayouts = &ds_layout;
2819
2820 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002821 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002822 ASSERT_VK_SUCCESS(err);
2823
2824 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2825 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2826 vp_state_ci.viewportCount = 1;
2827 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2828 vp_state_ci.scissorCount = 1;
2829 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2830
2831 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2832 // Set scissor as dynamic to avoid that error
2833 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2834 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2835 dyn_state_ci.dynamicStateCount = 1;
2836 dyn_state_ci.pDynamicStates = &sc_state;
2837
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002838 VkPipelineShaderStageCreateInfo shaderStages[2];
2839 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002840
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002841 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2842 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 -06002843 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002844 shaderStages[0] = vs.GetStageCreateInfo();
2845 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002846
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002847 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2848 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2849 vi_ci.pNext = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002850 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002851 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002852 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002853 vi_ci.pVertexAttributeDescriptions = nullptr;
2854
2855 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2856 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2857 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2858
Chia-I Wu1f851912015-10-27 18:04:07 +08002859 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +08002860 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002861 rs_ci.pNext = nullptr;
2862
2863 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2864 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2865 cb_ci.pNext = nullptr;
2866
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002867 VkGraphicsPipelineCreateInfo gp_ci = {};
2868 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002869 gp_ci.stageCount = 2;
2870 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002871 gp_ci.pVertexInputState = &vi_ci;
2872 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002873 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu1f851912015-10-27 18:04:07 +08002874 gp_ci.pRasterizationState = &rs_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002875 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002876 gp_ci.pDynamicState = &dyn_state_ci;
2877 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2878 gp_ci.layout = pipeline_layout;
2879 gp_ci.renderPass = renderPass();
2880
2881 VkPipelineCacheCreateInfo pc_ci = {};
2882 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2883
2884 VkPipeline pipeline;
2885 VkPipelineCache pipelineCache;
2886
Chia-I Wu69f40122015-10-26 21:10:41 +08002887 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002888 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002889 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002890
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002891 if (!m_errorMonitor->DesiredMsgFound()) {
2892 FAIL() << "Did not recieve Error 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...'";
2893 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002894 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002895
2896
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002897 // Now hit second fail case where we set scissor w/ different count than PSO
2898 // First need to successfully create the PSO from above by setting pViewports
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002900 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.");
2901
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002902 VkViewport vp = {}; // Just need dummy vp to point to
2903 vp_state_ci.pViewports = &vp;
Chia-I Wu69f40122015-10-26 21:10:41 +08002904 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002905 ASSERT_VK_SUCCESS(err);
2906 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08002907 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002908 VkRect2D scissors[2] = {}; // don't care about data
2909 // Count of 2 doesn't match PSO count of 1
Chia-I Wu1f851912015-10-27 18:04:07 +08002910 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 2, scissors);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002911 Draw(1, 0, 0, 0);
2912
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002913 if (!m_errorMonitor->DesiredMsgFound()) {
2914 FAIL() << "Did not receive Error 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...'";
2915 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002916 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002917
Chia-I Wu69f40122015-10-26 21:10:41 +08002918 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2919 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2920 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2921 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002922}
2923// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002924// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2925TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002926{
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002927 VkResult err;
2928
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002930 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
2931
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002932 ASSERT_NO_FATAL_FAILURE(InitState());
2933 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002934
Chia-I Wuc51b1212015-10-27 19:25:11 +08002935 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002936 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002937 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002938
2939 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2940 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002941 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002942 ds_pool_ci.poolSizeCount = 1;
2943 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002944
2945 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002946 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002947 ASSERT_VK_SUCCESS(err);
2948
2949 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002950 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002951 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002952 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002953 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2954
2955 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2956 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002957 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002958 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002959
2960 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002961 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002962 ASSERT_VK_SUCCESS(err);
2963
2964 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002965 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002966 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002967 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002968 alloc_info.descriptorPool = ds_pool;
2969 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002970 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002971 ASSERT_VK_SUCCESS(err);
2972
2973 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2974 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002975 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002976 pipeline_layout_ci.pSetLayouts = &ds_layout;
2977
2978 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002979 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002980 ASSERT_VK_SUCCESS(err);
2981
2982 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2983 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2984 vp_state_ci.scissorCount = 1;
2985 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2986 vp_state_ci.viewportCount = 1;
2987 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2988
2989 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2990 // Set scissor as dynamic to avoid that error
2991 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2992 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2993 dyn_state_ci.dynamicStateCount = 1;
2994 dyn_state_ci.pDynamicStates = &vp_state;
2995
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002996 VkPipelineShaderStageCreateInfo shaderStages[2];
2997 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002998
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002999 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
3000 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 -06003001 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08003002 shaderStages[0] = vs.GetStageCreateInfo();
3003 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003004
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003005 VkPipelineVertexInputStateCreateInfo vi_ci = {};
3006 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
3007 vi_ci.pNext = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08003008 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003009 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08003010 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003011 vi_ci.pVertexAttributeDescriptions = nullptr;
3012
3013 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
3014 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
3015 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
3016
Chia-I Wu1f851912015-10-27 18:04:07 +08003017 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +08003018 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003019 rs_ci.pNext = nullptr;
3020
3021 VkPipelineColorBlendStateCreateInfo cb_ci = {};
3022 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
3023 cb_ci.pNext = nullptr;
3024
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003025 VkGraphicsPipelineCreateInfo gp_ci = {};
3026 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06003027 gp_ci.stageCount = 2;
3028 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003029 gp_ci.pVertexInputState = &vi_ci;
3030 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003031 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu1f851912015-10-27 18:04:07 +08003032 gp_ci.pRasterizationState = &rs_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003033 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003034 gp_ci.pDynamicState = &dyn_state_ci;
3035 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
3036 gp_ci.layout = pipeline_layout;
3037 gp_ci.renderPass = renderPass();
3038
3039 VkPipelineCacheCreateInfo pc_ci = {};
3040 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
3041
3042 VkPipeline pipeline;
3043 VkPipelineCache pipelineCache;
3044
Chia-I Wu69f40122015-10-26 21:10:41 +08003045 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003046 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08003047 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003048
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003049 if (!m_errorMonitor->DesiredMsgFound()) {
3050 FAIL() << "Did not recieve Error 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...'";
3051 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003052 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003053
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003054 // Now hit second fail case where we set scissor w/ different count than PSO
3055 // First need to successfully create the PSO from above by setting pViewports
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003057 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.");
3058
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003059 VkRect2D sc = {}; // Just need dummy vp to point to
3060 vp_state_ci.pScissors = &sc;
Chia-I Wu69f40122015-10-26 21:10:41 +08003061 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003062 ASSERT_VK_SUCCESS(err);
3063 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08003064 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003065 VkViewport viewports[2] = {}; // don't care about data
3066 // Count of 2 doesn't match PSO count of 1
Chia-I Wu1f851912015-10-27 18:04:07 +08003067 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 2, viewports);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003068 Draw(1, 0, 0, 0);
3069
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003070 if (!m_errorMonitor->DesiredMsgFound()) {
3071 FAIL() << "Did not receive Error 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...'";
3072 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003073 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003074
Chia-I Wu69f40122015-10-26 21:10:41 +08003075 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
3076 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3077 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3078 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003079}
3080
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003081TEST_F(VkLayerTest, NullRenderPass)
3082{
3083 // Bind a NULL RenderPass
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003085 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003086
3087 ASSERT_NO_FATAL_FAILURE(InitState());
3088 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003089
Tony Barbour1490c912015-07-28 10:17:20 -06003090 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003091 // Don't care about RenderPass handle b/c error should be flagged before that
Chia-I Wuc51b1212015-10-27 19:25:11 +08003092 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003093
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003094 if (!m_errorMonitor->DesiredMsgFound()) {
3095 FAIL() << "Did not receive Error 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
3096 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003097 }
3098}
3099
Tobin Ehlis254eca02015-06-25 15:46:59 -06003100TEST_F(VkLayerTest, RenderPassWithinRenderPass)
3101{
3102 // Bind a BeginRenderPass within an active RenderPass
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003104 "It is invalid to issue this call inside an active render pass");
Tobin Ehlis254eca02015-06-25 15:46:59 -06003105
3106 ASSERT_NO_FATAL_FAILURE(InitState());
3107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis254eca02015-06-25 15:46:59 -06003108
Tony Barbour1490c912015-07-28 10:17:20 -06003109 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003110 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003111 VkRenderPassBeginInfo rp_begin = {};
3112 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
3113 rp_begin.pNext = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003114 rp_begin.renderPass = renderPass();
3115 rp_begin.framebuffer = framebuffer();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003116
Chia-I Wuc51b1212015-10-27 19:25:11 +08003117 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06003118
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003119 if (!m_errorMonitor->DesiredMsgFound()) {
3120 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3121 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06003122 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003123}
3124
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003125TEST_F(VkLayerTest, FillBufferWithinRenderPass)
3126{
3127 // Call CmdFillBuffer within an active renderpass
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003129 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003130
3131 ASSERT_NO_FATAL_FAILURE(InitState());
3132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003133
3134 // Renderpass is started here
3135 BeginCommandBuffer();
3136
3137 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08003138 vk_testing::Buffer dstBuffer;
3139 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003140
Chia-I Wu1f851912015-10-27 18:04:07 +08003141 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003142
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003143 if (!m_errorMonitor->DesiredMsgFound()) {
3144 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3145 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003146 }
3147}
3148
3149TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
3150{
3151 // Call CmdUpdateBuffer within an active renderpass
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003153 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003154
3155 ASSERT_NO_FATAL_FAILURE(InitState());
3156 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003157
3158 // Renderpass is started here
3159 BeginCommandBuffer();
3160
3161 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08003162 vk_testing::Buffer dstBuffer;
3163 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003164
Chia-I Wu1f851912015-10-27 18:04:07 +08003165 VkDeviceSize dstOffset = 0;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003166 VkDeviceSize dataSize = 1024;
3167 const uint32_t *pData = NULL;
3168
Chia-I Wu1f851912015-10-27 18:04:07 +08003169 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003170
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003171 if (!m_errorMonitor->DesiredMsgFound()) {
3172 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3173 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003174 }
3175}
3176
3177TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
3178{
3179 // Call CmdClearColorImage within an active RenderPass
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003181 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003182
3183 ASSERT_NO_FATAL_FAILURE(InitState());
3184 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003185
3186 // Renderpass is started here
3187 BeginCommandBuffer();
3188
3189 VkClearColorValue clear_color = {0};
3190 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3191 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3192 const int32_t tex_width = 32;
3193 const int32_t tex_height = 32;
3194 VkImageCreateInfo image_create_info = {};
3195 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3196 image_create_info.pNext = NULL;
3197 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3198 image_create_info.format = tex_format;
3199 image_create_info.extent.width = tex_width;
3200 image_create_info.extent.height = tex_height;
3201 image_create_info.extent.depth = 1;
3202 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06003203 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08003204 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003205 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3206 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3207
Chia-I Wu1f851912015-10-27 18:04:07 +08003208 vk_testing::Image dstImage;
3209 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003210
3211 const VkImageSubresourceRange range =
3212 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
3213
Chia-I Wu1f851912015-10-27 18:04:07 +08003214 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(),
3215 dstImage.handle(),
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003216 VK_IMAGE_LAYOUT_GENERAL,
3217 &clear_color,
3218 1,
3219 &range);
3220
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003221 if (!m_errorMonitor->DesiredMsgFound()) {
3222 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3223 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003224 }
3225}
3226
3227TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
3228{
3229 // Call CmdClearDepthStencilImage within an active RenderPass
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003231 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003232
3233 ASSERT_NO_FATAL_FAILURE(InitState());
3234 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003235
3236 // Renderpass is started here
3237 BeginCommandBuffer();
3238
3239 VkClearDepthStencilValue clear_value = {0};
3240 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3241 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
3242 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3243 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
3244 image_create_info.extent.width = 64;
3245 image_create_info.extent.height = 64;
3246 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3247 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
3248
Chia-I Wu1f851912015-10-27 18:04:07 +08003249 vk_testing::Image dstImage;
3250 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003251
3252 const VkImageSubresourceRange range =
3253 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
3254
Chia-I Wu1f851912015-10-27 18:04:07 +08003255 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(),
3256 dstImage.handle(),
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003257 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
3258 &clear_value,
3259 1,
3260 &range);
3261
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003262 if (!m_errorMonitor->DesiredMsgFound()) {
3263 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3264 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003265 }
3266}
3267
3268TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
3269{
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003270 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003271 VkResult err;
3272
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003274 "vkCmdClearAttachments: This call must be issued inside an active render pass");
3275
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003276 ASSERT_NO_FATAL_FAILURE(InitState());
3277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003278
3279 // Start no RenderPass
Chia-I Wu1f851912015-10-27 18:04:07 +08003280 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003281 ASSERT_VK_SUCCESS(err);
3282
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003283 VkClearAttachment color_attachment;
3284 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3285 color_attachment.clearValue.color.float32[0] = 0;
3286 color_attachment.clearValue.color.float32[1] = 0;
3287 color_attachment.clearValue.color.float32[2] = 0;
3288 color_attachment.clearValue.color.float32[3] = 0;
3289 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06003290 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Chia-I Wu1f851912015-10-27 18:04:07 +08003291 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(),
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003292 1, &color_attachment,
3293 1, &clear_rect);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003294
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003295 if (!m_errorMonitor->DesiredMsgFound()) {
3296 FAIL() << "Did not receive Error 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
3297 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003298 }
3299}
3300
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003301TEST_F(VkLayerTest, InvalidDynamicStateObject)
3302{
3303 // Create a valid cmd buffer
3304 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06003305 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
3306 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003307}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06003308
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003309TEST_F(VkLayerTest, IdxBufferAlignmentError)
3310{
3311 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003312 VkResult err;
3313
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003315 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
3316
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003317 ASSERT_NO_FATAL_FAILURE(InitState());
3318 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003319 uint32_t qfi = 0;
3320 VkBufferCreateInfo buffCI = {};
3321 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3322 buffCI.size = 1024;
3323 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
Chia-I Wu763a7492015-10-26 20:48:51 +08003324 buffCI.queueFamilyIndexCount = 1;
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003325 buffCI.pQueueFamilyIndices = &qfi;
3326
3327 VkBuffer ib;
Chia-I Wu69f40122015-10-26 21:10:41 +08003328 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003329 ASSERT_VK_SUCCESS(err);
3330
3331 BeginCommandBuffer();
3332 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08003333 //vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003334 // Should error before calling to driver so don't care about actual data
Chia-I Wu1f851912015-10-27 18:04:07 +08003335 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003336
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003337 if (!m_errorMonitor->DesiredMsgFound()) {
3338 FAIL() << "Did not receive Error 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...'";
3339 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003340 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003341
Chia-I Wu69f40122015-10-26 21:10:41 +08003342 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003343}
3344
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003345TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
3346{
3347 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003348
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003350 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003351
3352 ASSERT_NO_FATAL_FAILURE(InitState());
3353 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003354
3355 BeginCommandBuffer();
3356 //ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08003357 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
3358 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003359
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003360 if (!m_errorMonitor->DesiredMsgFound()) {
3361 FAIL() << "Did not receive Error 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer '";
3362 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003363 }
3364}
3365
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003366TEST_F(VkLayerTest, DSTypeMismatch)
3367{
3368 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003369 VkResult err;
3370
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003372 "Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match ");
3373
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003374 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003375 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003376 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003377 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003378 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003379
3380 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3381 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3382 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003383 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003384 ds_pool_ci.poolSizeCount = 1;
3385 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003386
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003387 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003388 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003389 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003390 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003391 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003392 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003393 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003394 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3395 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003396
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003397 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3398 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3399 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003400 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003401 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003402
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003403 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003404 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003405 ASSERT_VK_SUCCESS(err);
3406
3407 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003408 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003409 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003410 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003411 alloc_info.descriptorPool = ds_pool;
3412 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003413 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003414 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003415
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003416 VkSamplerCreateInfo sampler_ci = {};
3417 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3418 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003419 sampler_ci.magFilter = VK_FILTER_NEAREST;
3420 sampler_ci.minFilter = VK_FILTER_NEAREST;
3421 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003422 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3423 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3424 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003425 sampler_ci.mipLodBias = 1.0;
Jon Ashburn0717ed52015-12-14 14:59:20 -07003426 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003427 sampler_ci.maxAnisotropy = 1;
3428 sampler_ci.compareEnable = VK_FALSE;
3429 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3430 sampler_ci.minLod = 1.0;
3431 sampler_ci.maxLod = 1.0;
3432 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003433 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3434
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003435 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003436 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003437 ASSERT_VK_SUCCESS(err);
3438
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003439 VkDescriptorImageInfo info = {};
3440 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003441
3442 VkWriteDescriptorSet descriptor_write;
3443 memset(&descriptor_write, 0, sizeof(descriptor_write));
3444 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003445 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08003446 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003447 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003448 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003449 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003450
3451 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3452
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003453 if (!m_errorMonitor->DesiredMsgFound()) {
3454 FAIL() << "Did not receive Error 'Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...'";
3455 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003456 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003457
Chia-I Wu69f40122015-10-26 21:10:41 +08003458 vkDestroySampler(m_device->device(), sampler, NULL);
3459 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3460 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003461}
3462
3463TEST_F(VkLayerTest, DSUpdateOutOfBounds)
3464{
3465 // For overlapping Update, have arrayIndex exceed that of layout
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003466 VkResult err;
3467
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003469 "Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding");
3470
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003471 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003472 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003473 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003474 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003475 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003476
3477 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3478 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3479 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003480 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003481 ds_pool_ci.poolSizeCount = 1;
3482 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003483
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003484 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003485 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003486 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003487
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003488 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003489 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003490 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003491 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003492 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3493 dsl_binding.pImmutableSamplers = NULL;
3494
3495 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3496 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3497 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003498 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003499 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003500
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003501 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003502 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003503 ASSERT_VK_SUCCESS(err);
3504
3505 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003506 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003507 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003508 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003509 alloc_info.descriptorPool = ds_pool;
3510 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003511 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003512 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003513
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003514 VkSamplerCreateInfo sampler_ci = {};
3515 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3516 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003517 sampler_ci.magFilter = VK_FILTER_NEAREST;
3518 sampler_ci.minFilter = VK_FILTER_NEAREST;
3519 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003520 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3521 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3522 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003523 sampler_ci.mipLodBias = 1.0;
Jon Ashburn0717ed52015-12-14 14:59:20 -07003524 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003525 sampler_ci.maxAnisotropy = 1;
3526 sampler_ci.compareEnable = VK_FALSE;
3527 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3528 sampler_ci.minLod = 1.0;
3529 sampler_ci.maxLod = 1.0;
3530 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003531 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003532
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003533 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003534 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003535 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003536
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003537 VkDescriptorImageInfo info = {};
3538 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003539
3540 VkWriteDescriptorSet descriptor_write;
3541 memset(&descriptor_write, 0, sizeof(descriptor_write));
3542 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003543 descriptor_write.dstSet = descriptorSet;
3544 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wu763a7492015-10-26 20:48:51 +08003545 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003546 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003547 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003548 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003549
3550 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3551
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003552 if (!m_errorMonitor->DesiredMsgFound()) {
3553 FAIL() << "Did not receive Error 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
3554 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003555 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003556
Chia-I Wu69f40122015-10-26 21:10:41 +08003557 vkDestroySampler(m_device->device(), sampler, NULL);
3558 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3559 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003560}
3561
3562TEST_F(VkLayerTest, InvalidDSUpdateIndex)
3563{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003564 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003565 VkResult err;
3566
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003568 " does not have binding to match update binding ");
3569
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003570 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003571 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003572 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003573 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003574 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003575
3576 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3577 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3578 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003579 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003580 ds_pool_ci.poolSizeCount = 1;
3581 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003582
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003583 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003584 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003585 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003586
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003587 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003588 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003589 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003590 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003591 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3592 dsl_binding.pImmutableSamplers = NULL;
3593
3594 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3595 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3596 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003597 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003598 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003599 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003600 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003601 ASSERT_VK_SUCCESS(err);
3602
3603 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003604 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003605 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003606 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003607 alloc_info.descriptorPool = ds_pool;
3608 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003609 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003610 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003611
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003612 VkSamplerCreateInfo sampler_ci = {};
3613 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3614 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003615 sampler_ci.magFilter = VK_FILTER_NEAREST;
3616 sampler_ci.minFilter = VK_FILTER_NEAREST;
3617 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003618 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3619 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3620 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003621 sampler_ci.mipLodBias = 1.0;
Jon Ashburn0717ed52015-12-14 14:59:20 -07003622 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003623 sampler_ci.maxAnisotropy = 1;
3624 sampler_ci.compareEnable = VK_FALSE;
3625 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3626 sampler_ci.minLod = 1.0;
3627 sampler_ci.maxLod = 1.0;
3628 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003629 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003630
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003631 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003632 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003633 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003634
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003635 VkDescriptorImageInfo info = {};
3636 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003637
3638 VkWriteDescriptorSet descriptor_write;
3639 memset(&descriptor_write, 0, sizeof(descriptor_write));
3640 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003641 descriptor_write.dstSet = descriptorSet;
3642 descriptor_write.dstBinding = 2;
Chia-I Wu763a7492015-10-26 20:48:51 +08003643 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003644 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003645 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003646 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003647
3648 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3649
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003650 if (!m_errorMonitor->DesiredMsgFound()) {
3651 FAIL() << "Did not receive Error 'Descriptor Set <blah> does not have binding to match update binding '";
3652 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003653 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003654
Chia-I Wu69f40122015-10-26 21:10:41 +08003655 vkDestroySampler(m_device->device(), sampler, NULL);
3656 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3657 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003658}
3659
3660TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3661{
3662 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003663 VkResult err;
3664
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003666 "Unexpected UPDATE struct of type ");
3667
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003668 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003669
Chia-I Wuc51b1212015-10-27 19:25:11 +08003670 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003671 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003672 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003673
3674 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3675 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3676 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003677 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003678 ds_pool_ci.poolSizeCount = 1;
3679 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003680
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003681 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003682 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003683 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003684 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003685 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003686 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003687 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003688 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3689 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003690
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003691 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3692 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3693 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003694 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003695 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003696
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003697 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003698 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003699 ASSERT_VK_SUCCESS(err);
3700
3701 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003702 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003703 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003704 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003705 alloc_info.descriptorPool = ds_pool;
3706 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003707 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003708 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003709
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003710 VkSamplerCreateInfo sampler_ci = {};
3711 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3712 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003713 sampler_ci.magFilter = VK_FILTER_NEAREST;
3714 sampler_ci.minFilter = VK_FILTER_NEAREST;
3715 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003716 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3717 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3718 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003719 sampler_ci.mipLodBias = 1.0;
Jon Ashburn0717ed52015-12-14 14:59:20 -07003720 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003721 sampler_ci.maxAnisotropy = 1;
3722 sampler_ci.compareEnable = VK_FALSE;
3723 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3724 sampler_ci.minLod = 1.0;
3725 sampler_ci.maxLod = 1.0;
3726 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003727 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003728 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003729 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003730 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003731
3732
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003733 VkDescriptorImageInfo info = {};
3734 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003735
3736 VkWriteDescriptorSet descriptor_write;
3737 memset(&descriptor_write, 0, sizeof(descriptor_write));
3738 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu1f851912015-10-27 18:04:07 +08003739 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08003740 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003741 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003742 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003743 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003744
3745 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3746
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003747 if (!m_errorMonitor->DesiredMsgFound()) {
3748 FAIL() << "Did not receive Error 'Unexpected UPDATE struct of type '";
3749 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003750 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003751
Chia-I Wu69f40122015-10-26 21:10:41 +08003752 vkDestroySampler(m_device->device(), sampler, NULL);
3753 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3754 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003755}
3756
Tobin Ehlisb46be812015-10-23 16:00:08 -06003757TEST_F(VkLayerTest, SampleDescriptorUpdateError)
3758{
3759 // Create a single Sampler descriptor and send it an invalid Sampler
Tobin Ehlisb46be812015-10-23 16:00:08 -06003760 VkResult err;
3761
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003763 "Attempt to update descriptor with invalid sampler 0xbaadbeef");
3764
Tobin Ehlisb46be812015-10-23 16:00:08 -06003765 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb46be812015-10-23 16:00:08 -06003766 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied code
Chia-I Wuc51b1212015-10-27 19:25:11 +08003767 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003768 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003769 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003770
3771 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3772 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3773 ds_pool_ci.pNext = NULL;
3774 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003775 ds_pool_ci.poolSizeCount = 1;
3776 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003777
3778 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003779 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003780 ASSERT_VK_SUCCESS(err);
3781
3782 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003783 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003784 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003785 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003786 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3787 dsl_binding.pImmutableSamplers = NULL;
3788
3789 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3790 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3791 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003792 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003793 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003794 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003795 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003796 ASSERT_VK_SUCCESS(err);
3797
3798 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003799 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003800 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003801 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003802 alloc_info.descriptorPool = ds_pool;
3803 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003804 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003805 ASSERT_VK_SUCCESS(err);
3806
Chia-I Wue420a332015-10-26 20:04:44 +08003807 VkSampler sampler = (VkSampler) 0xbaadbeef; // Sampler with invalid handle
Tobin Ehlisb46be812015-10-23 16:00:08 -06003808
3809 VkDescriptorImageInfo descriptor_info;
3810 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3811 descriptor_info.sampler = sampler;
3812
3813 VkWriteDescriptorSet descriptor_write;
3814 memset(&descriptor_write, 0, sizeof(descriptor_write));
3815 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003816 descriptor_write.dstSet = descriptorSet;
3817 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003818 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003819 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3820 descriptor_write.pImageInfo = &descriptor_info;
3821
3822 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3823
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003824 if (!m_errorMonitor->DesiredMsgFound()) {
3825 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid sampler...'";
3826 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06003827 }
3828
Chia-I Wu69f40122015-10-26 21:10:41 +08003829 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3830 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003831}
3832
3833TEST_F(VkLayerTest, ImageViewDescriptorUpdateError)
3834{
3835 // Create a single combined Image/Sampler descriptor and send it an invalid imageView
Tobin Ehlisb46be812015-10-23 16:00:08 -06003836 VkResult err;
3837
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003839 "Attempt to update descriptor with invalid imageView 0xbaadbeef");
3840
Tobin Ehlisb46be812015-10-23 16:00:08 -06003841 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wuc51b1212015-10-27 19:25:11 +08003842 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003843 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003844 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003845
3846 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3847 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3848 ds_pool_ci.pNext = NULL;
3849 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003850 ds_pool_ci.poolSizeCount = 1;
3851 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003852
3853 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003854 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003855 ASSERT_VK_SUCCESS(err);
3856
3857 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003858 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003859 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003860 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003861 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3862 dsl_binding.pImmutableSamplers = NULL;
3863
3864 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3865 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3866 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003867 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003868 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003869 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003870 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003871 ASSERT_VK_SUCCESS(err);
3872
3873 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003874 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003875 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003876 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003877 alloc_info.descriptorPool = ds_pool;
3878 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003879 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003880 ASSERT_VK_SUCCESS(err);
3881
3882 VkSamplerCreateInfo sampler_ci = {};
3883 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3884 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003885 sampler_ci.magFilter = VK_FILTER_NEAREST;
3886 sampler_ci.minFilter = VK_FILTER_NEAREST;
3887 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003888 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3889 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3890 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003891 sampler_ci.mipLodBias = 1.0;
Jon Ashburn0717ed52015-12-14 14:59:20 -07003892 sampler_ci.anisotropyEnable = VK_FALSE;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003893 sampler_ci.maxAnisotropy = 1;
3894 sampler_ci.compareEnable = VK_FALSE;
3895 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3896 sampler_ci.minLod = 1.0;
3897 sampler_ci.maxLod = 1.0;
3898 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3899 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3900
3901 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003902 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003903 ASSERT_VK_SUCCESS(err);
3904
Chia-I Wue420a332015-10-26 20:04:44 +08003905 VkImageView view = (VkImageView) 0xbaadbeef; // invalid imageView object
Tobin Ehlisb46be812015-10-23 16:00:08 -06003906
3907 VkDescriptorImageInfo descriptor_info;
3908 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3909 descriptor_info.sampler = sampler;
3910 descriptor_info.imageView = view;
3911
3912 VkWriteDescriptorSet descriptor_write;
3913 memset(&descriptor_write, 0, sizeof(descriptor_write));
3914 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003915 descriptor_write.dstSet = descriptorSet;
3916 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003917 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003918 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3919 descriptor_write.pImageInfo = &descriptor_info;
3920
3921 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3922
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003923 if (!m_errorMonitor->DesiredMsgFound()) {
3924 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid imageView...'";
3925 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06003926 }
3927
Chia-I Wu69f40122015-10-26 21:10:41 +08003928 vkDestroySampler(m_device->device(), sampler, NULL);
3929 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3930 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003931}
3932
Tobin Ehlis3e676262015-10-27 16:35:27 -06003933TEST_F(VkLayerTest, CopyDescriptorUpdateErrors)
3934{
3935 // 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 -06003936 VkResult err;
3937
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003939 "Copy descriptor update index 0, update count #1, has src update descriptor type VK_DESCRIPTOR_TYPE_SAMPLER ");
3940
Tobin Ehlis3e676262015-10-27 16:35:27 -06003941 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3e676262015-10-27 16:35:27 -06003942 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003943 VkDescriptorPoolSize ds_type_count[2] = {};
Tobin Ehlis3e676262015-10-27 16:35:27 -06003944 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003945 ds_type_count[0].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003946 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003947 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003948
3949 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3950 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3951 ds_pool_ci.pNext = NULL;
3952 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003953 ds_pool_ci.poolSizeCount = 2;
3954 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003955
3956 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003957 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003958 ASSERT_VK_SUCCESS(err);
3959 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003960 dsl_binding[0].binding = 0;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003961 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003962 dsl_binding[0].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003963 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3964 dsl_binding[0].pImmutableSamplers = NULL;
Chia-I Wub5689ee2015-10-31 00:31:16 +08003965 dsl_binding[1].binding = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003966 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003967 dsl_binding[1].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003968 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
3969 dsl_binding[1].pImmutableSamplers = NULL;
3970
3971 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3972 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3973 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003974 ds_layout_ci.bindingCount = 2;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003975 ds_layout_ci.pBinding = dsl_binding;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003976
3977 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003978 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003979 ASSERT_VK_SUCCESS(err);
3980
3981 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003982 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003983 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003984 alloc_info.setLayoutCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003985 alloc_info.descriptorPool = ds_pool;
3986 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003987 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003988 ASSERT_VK_SUCCESS(err);
3989
3990 VkSamplerCreateInfo sampler_ci = {};
3991 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3992 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003993 sampler_ci.magFilter = VK_FILTER_NEAREST;
3994 sampler_ci.minFilter = VK_FILTER_NEAREST;
3995 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003996 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3997 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3998 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003999 sampler_ci.mipLodBias = 1.0;
Jon Ashburn0717ed52015-12-14 14:59:20 -07004000 sampler_ci.anisotropyEnable = VK_FALSE;
Tobin Ehlis3e676262015-10-27 16:35:27 -06004001 sampler_ci.maxAnisotropy = 1;
4002 sampler_ci.compareEnable = VK_FALSE;
4003 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4004 sampler_ci.minLod = 1.0;
4005 sampler_ci.maxLod = 1.0;
4006 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4007 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4008
4009 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08004010 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3e676262015-10-27 16:35:27 -06004011 ASSERT_VK_SUCCESS(err);
4012
4013 VkDescriptorImageInfo info = {};
4014 info.sampler = sampler;
4015
4016 VkWriteDescriptorSet descriptor_write;
4017 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
4018 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08004019 descriptor_write.dstSet = descriptorSet;
4020 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wu763a7492015-10-26 20:48:51 +08004021 descriptor_write.descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06004022 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4023 descriptor_write.pImageInfo = &info;
4024 // This write update should succeed
4025 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4026 // Now perform a copy update that fails due to type mismatch
4027 VkCopyDescriptorSet copy_ds_update;
4028 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4029 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4030 copy_ds_update.srcSet = descriptorSet;
4031 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
Chia-I Wu1f851912015-10-27 18:04:07 +08004032 copy_ds_update.dstSet = descriptorSet;
4033 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wu763a7492015-10-26 20:48:51 +08004034 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06004035 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4036
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004037 if (!m_errorMonitor->DesiredMsgFound()) {
4038 FAIL() << "Did not receive Error 'Copy descriptor update index 0, update count #1, has src update descriptor type_DESCRIPTOR_TYPE_SAMPLER'";
4039 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06004040 }
4041 // Now perform a copy update that fails due to binding out of bounds
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004043 "Copy descriptor update 0 has srcBinding 3 which is out of bounds ");
Tobin Ehlis3e676262015-10-27 16:35:27 -06004044 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4045 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4046 copy_ds_update.srcSet = descriptorSet;
4047 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu1f851912015-10-27 18:04:07 +08004048 copy_ds_update.dstSet = descriptorSet;
4049 copy_ds_update.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08004050 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06004051 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4052
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004053 if (!m_errorMonitor->DesiredMsgFound()) {
4054 FAIL() << "Did not receive Error 'Copy descriptor update 0 has srcBinding 3 which is out of bounds...'";
4055 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06004056 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004057
Tobin Ehlis3e676262015-10-27 16:35:27 -06004058 // Now perform a copy update that fails due to binding out of bounds
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004060 "Copy descriptor src update is out of bounds for matching binding 1 ");
4061
Tobin Ehlis3e676262015-10-27 16:35:27 -06004062 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4063 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4064 copy_ds_update.srcSet = descriptorSet;
4065 copy_ds_update.srcBinding = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08004066 copy_ds_update.dstSet = descriptorSet;
4067 copy_ds_update.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08004068 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis3e676262015-10-27 16:35:27 -06004069 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4070
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004071 if (!m_errorMonitor->DesiredMsgFound()) {
4072 FAIL() << "Did not receive Error 'Copy descriptor src update is out of bounds for matching binding 1...'";
4073 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06004074 }
4075
Chia-I Wu69f40122015-10-26 21:10:41 +08004076 vkDestroySampler(m_device->device(), sampler, NULL);
4077 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4078 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis3e676262015-10-27 16:35:27 -06004079}
4080
Tobin Ehlis138b7f12015-05-22 12:38:55 -06004081TEST_F(VkLayerTest, NumSamplesMismatch)
4082{
Chia-I Wu1f851912015-10-27 18:04:07 +08004083 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004084 VkResult err;
4085
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004087 "Num samples mismatch! ");
4088
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004089 ASSERT_NO_FATAL_FAILURE(InitState());
4090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wuc51b1212015-10-27 19:25:11 +08004091 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004092 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08004093 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004094
4095 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004096 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4097 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004098 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08004099 ds_pool_ci.poolSizeCount = 1;
4100 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004101
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004102 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08004103 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004104 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004105
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004106 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08004107 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004108 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08004109 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004110 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4111 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004112
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004113 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4114 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4115 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004116 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08004117 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004118
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004119 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004120 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004121 ASSERT_VK_SUCCESS(err);
4122
4123 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004124 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004125 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08004126 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004127 alloc_info.descriptorPool = ds_pool;
4128 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08004129 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004130 ASSERT_VK_SUCCESS(err);
4131
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004132 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4133 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4134 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004135 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004136 pipe_ms_state_ci.sampleShadingEnable = 0;
4137 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06004138 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004139
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004140 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4141 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4142 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004143 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004144 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004145
4146 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004147 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004148 ASSERT_VK_SUCCESS(err);
4149
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004150 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4151 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 -06004152 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06004153 VkPipelineObj pipe(m_device);
4154 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004155 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004156 pipe.SetMSAA(&pipe_ms_state_ci);
4157 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004158
Tony Barbour1490c912015-07-28 10:17:20 -06004159 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08004160 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004161
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004162 if (!m_errorMonitor->DesiredMsgFound()) {
4163 FAIL() << "Did not recieve Error 'Num samples mismatch!...'";
4164 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004165 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004166
Chia-I Wu69f40122015-10-26 21:10:41 +08004167 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4168 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4169 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06004170}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004171
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004172TEST_F(VkLayerTest, ClearCmdNoDraw)
4173{
Chia-I Wu1f851912015-10-27 18:04:07 +08004174 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004175 VkResult err;
4176
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004177 // TODO: verify that this matches layer
4178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004179 "vkCmdClearAttachments() issued on CB object ");
4180
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004181 ASSERT_NO_FATAL_FAILURE(InitState());
4182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004183
Chia-I Wuc51b1212015-10-27 19:25:11 +08004184 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004185 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08004186 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004187
4188 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4189 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4190 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004191 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08004192 ds_pool_ci.poolSizeCount = 1;
4193 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004194
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004195 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08004196 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004197 ASSERT_VK_SUCCESS(err);
4198
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004199 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08004200 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004201 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08004202 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004203 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4204 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004205
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004206 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4207 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4208 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004209 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08004210 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004211
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004212 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004213 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004214 ASSERT_VK_SUCCESS(err);
4215
4216 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004217 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004218 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08004219 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004220 alloc_info.descriptorPool = ds_pool;
4221 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08004222 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004223 ASSERT_VK_SUCCESS(err);
4224
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004225 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4226 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4227 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004228 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004229 pipe_ms_state_ci.sampleShadingEnable = 0;
4230 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06004231 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004232
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004233 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4234 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4235 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004236 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004237 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004238
4239 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004240 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004241 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004242
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004243 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004244 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
4245 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4246
Tony Barbourd7d828b2015-08-06 10:16:07 -06004247 VkPipelineObj pipe(m_device);
4248 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004249 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004250 pipe.SetMSAA(&pipe_ms_state_ci);
4251 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06004252
4253 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004254
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004255 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
4256 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004257 VkClearAttachment color_attachment;
4258 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4259 color_attachment.clearValue.color.float32[0] = 1.0;
4260 color_attachment.clearValue.color.float32[1] = 1.0;
4261 color_attachment.clearValue.color.float32[2] = 1.0;
4262 color_attachment.clearValue.color.float32[3] = 1.0;
4263 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004264 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004265
Chia-I Wu1f851912015-10-27 18:04:07 +08004266 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004267
4268 if (!m_errorMonitor->DesiredMsgFound()) {
4269 FAIL() << "Did not receive Error 'vkCommandClearAttachments() issued on CB object...'";
4270 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004271 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004272
Chia-I Wu69f40122015-10-26 21:10:41 +08004273 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4274 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4275 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004276}
4277
Tobin Ehlise4076782015-06-24 15:53:07 -06004278TEST_F(VkLayerTest, VtxBufferBadIndex)
4279{
Tobin Ehlise4076782015-06-24 15:53:07 -06004280 VkResult err;
4281
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT,
Mark Lobodzinski74e84692015-12-14 15:14:10 -07004283 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004284
Tobin Ehlise4076782015-06-24 15:53:07 -06004285 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06004286 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlise4076782015-06-24 15:53:07 -06004287 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004288
Chia-I Wuc51b1212015-10-27 19:25:11 +08004289 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004290 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08004291 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004292
4293 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4294 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4295 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004296 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08004297 ds_pool_ci.poolSizeCount = 1;
4298 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004299
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004300 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08004301 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06004302 ASSERT_VK_SUCCESS(err);
4303
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004304 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08004305 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004306 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08004307 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004308 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4309 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06004310
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004311 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4312 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4313 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004314 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08004315 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004316
Tobin Ehlise4076782015-06-24 15:53:07 -06004317 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004318 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06004319 ASSERT_VK_SUCCESS(err);
4320
4321 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004322 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004323 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08004324 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004325 alloc_info.descriptorPool = ds_pool;
4326 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08004327 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06004328 ASSERT_VK_SUCCESS(err);
4329
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004330 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4331 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4332 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004333 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004334 pipe_ms_state_ci.sampleShadingEnable = 0;
4335 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06004336 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06004337
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004338 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4339 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4340 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004341 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004342 pipeline_layout_ci.pSetLayouts = &ds_layout;
4343 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06004344
Chia-I Wu69f40122015-10-26 21:10:41 +08004345 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06004346 ASSERT_VK_SUCCESS(err);
4347
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004348 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4349 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 -06004350 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06004351 VkPipelineObj pipe(m_device);
4352 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004353 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004354 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06004355 pipe.SetViewport(m_viewports);
4356 pipe.SetScissor(m_scissors);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004357 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06004358
4359 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08004360 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06004361 // Don't care about actual data, just need to get to draw to flag error
4362 static const float vbo_data[3] = {1.f, 0.f, 1.f};
4363 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
4364 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06004365 Draw(1, 0, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06004366
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004367 if (!m_errorMonitor->DesiredMsgFound()) {
4368 FAIL() << "Did not receive Error 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
4369 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise4076782015-06-24 15:53:07 -06004370 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004371
Chia-I Wu69f40122015-10-26 21:10:41 +08004372 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4373 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4374 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise4076782015-06-24 15:53:07 -06004375}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004376#endif // DRAW_STATE_TESTS
4377
Tobin Ehlis57e6a612015-05-26 16:11:58 -06004378#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06004379#if GTEST_IS_THREADSAFE
4380struct thread_data_struct {
Chia-I Wu1f851912015-10-27 18:04:07 +08004381 VkCommandBuffer commandBuffer;
Mike Stroyan09aae812015-05-12 16:00:45 -06004382 VkEvent event;
4383 bool bailout;
4384};
4385
4386extern "C" void *AddToCommandBuffer(void *arg)
4387{
4388 struct thread_data_struct *data = (struct thread_data_struct *) arg;
Mike Stroyan09aae812015-05-12 16:00:45 -06004389
4390 for (int i = 0; i<10000; i++) {
Chia-I Wucba6cea2015-10-31 00:31:16 +08004391 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyan09aae812015-05-12 16:00:45 -06004392 if (data->bailout) {
4393 break;
4394 }
4395 }
4396 return NULL;
4397}
4398
Chia-I Wu1f851912015-10-27 18:04:07 +08004399TEST_F(VkLayerTest, ThreadCommandBufferCollision)
Mike Stroyan09aae812015-05-12 16:00:45 -06004400{
Mike Stroyan7016f4f2015-07-13 14:45:35 -06004401 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06004402
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004404
Mike Stroyan09aae812015-05-12 16:00:45 -06004405 ASSERT_NO_FATAL_FAILURE(InitState());
4406 ASSERT_NO_FATAL_FAILURE(InitViewport());
4407 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4408
Chia-I Wu1f851912015-10-27 18:04:07 +08004409 // Calls AllocateCommandBuffers
4410 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004411
4412 // Avoid creating RenderPass
Chia-I Wu1f851912015-10-27 18:04:07 +08004413 commandBuffer.BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06004414
4415 VkEventCreateInfo event_info;
4416 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06004417 VkResult err;
4418
4419 memset(&event_info, 0, sizeof(event_info));
4420 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4421
Chia-I Wu69f40122015-10-26 21:10:41 +08004422 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyan09aae812015-05-12 16:00:45 -06004423 ASSERT_VK_SUCCESS(err);
4424
Mike Stroyan09aae812015-05-12 16:00:45 -06004425 err = vkResetEvent(device(), event);
4426 ASSERT_VK_SUCCESS(err);
4427
4428 struct thread_data_struct data;
Chia-I Wu1f851912015-10-27 18:04:07 +08004429 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyan09aae812015-05-12 16:00:45 -06004430 data.event = event;
4431 data.bailout = false;
4432 m_errorMonitor->SetBailout(&data.bailout);
4433 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06004434 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06004435 // Add many entries to command buffer from this thread at the same time.
4436 AddToCommandBuffer(&data);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004437
Mike Stroyan7016f4f2015-07-13 14:45:35 -06004438 test_platform_thread_join(thread, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08004439 commandBuffer.EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06004440
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004441 if (!m_errorMonitor->DesiredMsgFound()) {
4442 FAIL() << "Did not receive Error 'THREADING ERROR' from using one VkCommandBufferObj in two threads";
4443 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan09aae812015-05-12 16:00:45 -06004444 }
4445
Chia-I Wu69f40122015-10-26 21:10:41 +08004446 vkDestroyEvent(device(), event, NULL);
Mike Stroyan09aae812015-05-12 16:00:45 -06004447}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004448#endif // GTEST_IS_THREADSAFE
4449#endif // THREADING_TESTS
4450
Chris Forbes5af3bf22015-05-25 11:13:08 +12004451#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004452TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
4453{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004455 "Shader is not SPIR-V");
4456
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004457 ASSERT_NO_FATAL_FAILURE(InitState());
4458 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4459
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004460 VkShaderModule module;
4461 VkShaderModuleCreateInfo moduleCreateInfo;
4462 struct icd_spv_header spv;
4463
4464 spv.magic = ICD_SPV_MAGIC;
4465 spv.version = ICD_SPV_VERSION;
4466 spv.gen_magic = 0;
4467
4468 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4469 moduleCreateInfo.pNext = NULL;
Chia-I Wu036b1612015-10-26 19:22:06 +08004470 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004471 moduleCreateInfo.codeSize = 4;
4472 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004473 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004474
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004475 if (!m_errorMonitor->DesiredMsgFound()) {
4476 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4477 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004478 }
4479}
4480
4481TEST_F(VkLayerTest, InvalidSPIRVMagic)
4482{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004484 "Shader is not SPIR-V");
4485
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004486 ASSERT_NO_FATAL_FAILURE(InitState());
4487 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4488
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004489 VkShaderModule module;
4490 VkShaderModuleCreateInfo moduleCreateInfo;
4491 struct icd_spv_header spv;
4492
4493 spv.magic = ~ICD_SPV_MAGIC;
4494 spv.version = ICD_SPV_VERSION;
4495 spv.gen_magic = 0;
4496
4497 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4498 moduleCreateInfo.pNext = NULL;
Chia-I Wu036b1612015-10-26 19:22:06 +08004499 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004500 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4501 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004502 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004503
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004504 if (!m_errorMonitor->DesiredMsgFound()) {
4505 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4506 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004507 }
4508}
4509
4510TEST_F(VkLayerTest, InvalidSPIRVVersion)
4511{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004513 "Shader is not SPIR-V");
4514
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004515 ASSERT_NO_FATAL_FAILURE(InitState());
4516 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4517
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004518 VkShaderModule module;
4519 VkShaderModuleCreateInfo moduleCreateInfo;
4520 struct icd_spv_header spv;
4521
4522 spv.magic = ICD_SPV_MAGIC;
4523 spv.version = ~ICD_SPV_VERSION;
4524 spv.gen_magic = 0;
4525
4526 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4527 moduleCreateInfo.pNext = NULL;
4528
Chia-I Wu036b1612015-10-26 19:22:06 +08004529 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004530 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4531 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004532 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004533
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004534 if (!m_errorMonitor->DesiredMsgFound()) {
4535 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4536 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004537 }
4538}
4539
Chris Forbes5af3bf22015-05-25 11:13:08 +12004540TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
4541{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004543 "not consumed by fragment shader");
4544
Chris Forbes5af3bf22015-05-25 11:13:08 +12004545 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12004547
4548 char const *vsSource =
4549 "#version 140\n"
4550 "#extension GL_ARB_separate_shader_objects: require\n"
4551 "#extension GL_ARB_shading_language_420pack: require\n"
4552 "\n"
4553 "layout(location=0) out float x;\n"
4554 "void main(){\n"
4555 " gl_Position = vec4(1);\n"
4556 " x = 0;\n"
4557 "}\n";
4558 char const *fsSource =
4559 "#version 140\n"
4560 "#extension GL_ARB_separate_shader_objects: require\n"
4561 "#extension GL_ARB_shading_language_420pack: require\n"
4562 "\n"
4563 "layout(location=0) out vec4 color;\n"
4564 "void main(){\n"
4565 " color = vec4(1);\n"
4566 "}\n";
4567
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004568 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4569 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5af3bf22015-05-25 11:13:08 +12004570
4571 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004572 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12004573 pipe.AddShader(&vs);
4574 pipe.AddShader(&fs);
4575
Chris Forbes5af3bf22015-05-25 11:13:08 +12004576 VkDescriptorSetObj descriptorSet(m_device);
4577 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004578 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12004579
Tony Barboured132432015-08-04 16:23:11 -06004580 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12004581
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004582 if (!m_errorMonitor->DesiredMsgFound()) {
4583 FAIL() << "Did not receive Warning 'not consumed by fragment shader'";
4584 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5af3bf22015-05-25 11:13:08 +12004585 }
4586}
Chris Forbes5af3bf22015-05-25 11:13:08 +12004587
Chris Forbes3c10b852015-05-25 11:13:13 +12004588TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
4589{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004591 "not written by vertex shader");
4592
Chris Forbes3c10b852015-05-25 11:13:13 +12004593 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004594 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12004595
4596 char const *vsSource =
4597 "#version 140\n"
4598 "#extension GL_ARB_separate_shader_objects: require\n"
4599 "#extension GL_ARB_shading_language_420pack: require\n"
4600 "\n"
4601 "void main(){\n"
4602 " gl_Position = vec4(1);\n"
4603 "}\n";
4604 char const *fsSource =
4605 "#version 140\n"
4606 "#extension GL_ARB_separate_shader_objects: require\n"
4607 "#extension GL_ARB_shading_language_420pack: require\n"
4608 "\n"
4609 "layout(location=0) in float x;\n"
4610 "layout(location=0) out vec4 color;\n"
4611 "void main(){\n"
4612 " color = vec4(x);\n"
4613 "}\n";
4614
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004615 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4616 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes3c10b852015-05-25 11:13:13 +12004617
4618 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004619 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12004620 pipe.AddShader(&vs);
4621 pipe.AddShader(&fs);
4622
Chris Forbes3c10b852015-05-25 11:13:13 +12004623 VkDescriptorSetObj descriptorSet(m_device);
4624 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004625 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12004626
Tony Barboured132432015-08-04 16:23:11 -06004627 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12004628
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004629 if (!m_errorMonitor->DesiredMsgFound()) {
4630 FAIL() << "Did not receive Error 'not written by vertex shader'";
4631 m_errorMonitor->DumpFailureMsgs();
Chris Forbes3c10b852015-05-25 11:13:13 +12004632 }
4633}
4634
Chris Forbescc281692015-05-25 11:13:17 +12004635TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
4636{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004638 "Type mismatch on location 0");
4639
Chris Forbescc281692015-05-25 11:13:17 +12004640 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004641 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12004642
4643 char const *vsSource =
4644 "#version 140\n"
4645 "#extension GL_ARB_separate_shader_objects: require\n"
4646 "#extension GL_ARB_shading_language_420pack: require\n"
4647 "\n"
4648 "layout(location=0) out int x;\n"
4649 "void main(){\n"
4650 " x = 0;\n"
4651 " gl_Position = vec4(1);\n"
4652 "}\n";
4653 char const *fsSource =
4654 "#version 140\n"
4655 "#extension GL_ARB_separate_shader_objects: require\n"
4656 "#extension GL_ARB_shading_language_420pack: require\n"
4657 "\n"
4658 "layout(location=0) in float x;\n" /* VS writes int */
4659 "layout(location=0) out vec4 color;\n"
4660 "void main(){\n"
4661 " color = vec4(x);\n"
4662 "}\n";
4663
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004664 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4665 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbescc281692015-05-25 11:13:17 +12004666
4667 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004668 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12004669 pipe.AddShader(&vs);
4670 pipe.AddShader(&fs);
4671
Chris Forbescc281692015-05-25 11:13:17 +12004672 VkDescriptorSetObj descriptorSet(m_device);
4673 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004674 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12004675
Tony Barboured132432015-08-04 16:23:11 -06004676 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12004677
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004678 if (!m_errorMonitor->DesiredMsgFound()) {
4679 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
4680 m_errorMonitor->DumpFailureMsgs();
Chris Forbescc281692015-05-25 11:13:17 +12004681 }
4682}
4683
Chris Forbes8291c052015-05-25 11:13:28 +12004684TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
4685{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004687 "location 0 not consumed by VS");
4688
Chris Forbes8291c052015-05-25 11:13:28 +12004689 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004690 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12004691
4692 VkVertexInputBindingDescription input_binding;
4693 memset(&input_binding, 0, sizeof(input_binding));
4694
4695 VkVertexInputAttributeDescription input_attrib;
4696 memset(&input_attrib, 0, sizeof(input_attrib));
4697 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4698
4699 char const *vsSource =
4700 "#version 140\n"
4701 "#extension GL_ARB_separate_shader_objects: require\n"
4702 "#extension GL_ARB_shading_language_420pack: require\n"
4703 "\n"
4704 "void main(){\n"
4705 " gl_Position = vec4(1);\n"
4706 "}\n";
4707 char const *fsSource =
4708 "#version 140\n"
4709 "#extension GL_ARB_separate_shader_objects: require\n"
4710 "#extension GL_ARB_shading_language_420pack: require\n"
4711 "\n"
4712 "layout(location=0) out vec4 color;\n"
4713 "void main(){\n"
4714 " color = vec4(1);\n"
4715 "}\n";
4716
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004717 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4718 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes8291c052015-05-25 11:13:28 +12004719
4720 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004721 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12004722 pipe.AddShader(&vs);
4723 pipe.AddShader(&fs);
4724
4725 pipe.AddVertexInputBindings(&input_binding, 1);
4726 pipe.AddVertexInputAttribs(&input_attrib, 1);
4727
Chris Forbes8291c052015-05-25 11:13:28 +12004728 VkDescriptorSetObj descriptorSet(m_device);
4729 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004730 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12004731
Tony Barboured132432015-08-04 16:23:11 -06004732 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12004733
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004734 if (!m_errorMonitor->DesiredMsgFound()) {
4735 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
4736 m_errorMonitor->DumpFailureMsgs();
Chris Forbes8291c052015-05-25 11:13:28 +12004737 }
4738}
4739
Chris Forbes37367e62015-05-25 11:13:29 +12004740TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
4741{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004743 "VS consumes input at location 0 but not provided");
4744
Chris Forbes37367e62015-05-25 11:13:29 +12004745 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004746 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12004747
4748 char const *vsSource =
4749 "#version 140\n"
4750 "#extension GL_ARB_separate_shader_objects: require\n"
4751 "#extension GL_ARB_shading_language_420pack: require\n"
4752 "\n"
4753 "layout(location=0) in vec4 x;\n" /* not provided */
4754 "void main(){\n"
4755 " gl_Position = x;\n"
4756 "}\n";
4757 char const *fsSource =
4758 "#version 140\n"
4759 "#extension GL_ARB_separate_shader_objects: require\n"
4760 "#extension GL_ARB_shading_language_420pack: require\n"
4761 "\n"
4762 "layout(location=0) out vec4 color;\n"
4763 "void main(){\n"
4764 " color = vec4(1);\n"
4765 "}\n";
4766
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004767 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4768 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes37367e62015-05-25 11:13:29 +12004769
4770 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004771 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12004772 pipe.AddShader(&vs);
4773 pipe.AddShader(&fs);
4774
Chris Forbes37367e62015-05-25 11:13:29 +12004775 VkDescriptorSetObj descriptorSet(m_device);
4776 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004777 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12004778
Tony Barboured132432015-08-04 16:23:11 -06004779 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12004780
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004781 if (!m_errorMonitor->DesiredMsgFound()) {
4782 FAIL() << "Did not receive Error 'VS consumes input at location 0 but not provided'";
4783 m_errorMonitor->DumpFailureMsgs();
Chris Forbes37367e62015-05-25 11:13:29 +12004784 }
4785}
4786
Chris Forbesa4b02322015-05-25 11:13:31 +12004787TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
4788{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004790 "location 0 does not match VS input type");
4791
Chris Forbesa4b02322015-05-25 11:13:31 +12004792 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004793 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12004794
4795 VkVertexInputBindingDescription input_binding;
4796 memset(&input_binding, 0, sizeof(input_binding));
4797
4798 VkVertexInputAttributeDescription input_attrib;
4799 memset(&input_attrib, 0, sizeof(input_attrib));
4800 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4801
4802 char const *vsSource =
4803 "#version 140\n"
4804 "#extension GL_ARB_separate_shader_objects: require\n"
4805 "#extension GL_ARB_shading_language_420pack: require\n"
4806 "\n"
4807 "layout(location=0) in int x;\n" /* attrib provided float */
4808 "void main(){\n"
4809 " gl_Position = vec4(x);\n"
4810 "}\n";
4811 char const *fsSource =
4812 "#version 140\n"
4813 "#extension GL_ARB_separate_shader_objects: require\n"
4814 "#extension GL_ARB_shading_language_420pack: require\n"
4815 "\n"
4816 "layout(location=0) out vec4 color;\n"
4817 "void main(){\n"
4818 " color = vec4(1);\n"
4819 "}\n";
4820
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004821 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4822 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa4b02322015-05-25 11:13:31 +12004823
4824 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004825 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12004826 pipe.AddShader(&vs);
4827 pipe.AddShader(&fs);
4828
4829 pipe.AddVertexInputBindings(&input_binding, 1);
4830 pipe.AddVertexInputAttribs(&input_attrib, 1);
4831
Chris Forbesa4b02322015-05-25 11:13:31 +12004832 VkDescriptorSetObj descriptorSet(m_device);
4833 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004834 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12004835
Tony Barboured132432015-08-04 16:23:11 -06004836 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12004837
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004838 if (!m_errorMonitor->DesiredMsgFound()) {
4839 FAIL() << "Did not receive Error 'location 0 does not match VS input type'";
4840 m_errorMonitor->DumpFailureMsgs();
Chris Forbesa4b02322015-05-25 11:13:31 +12004841 }
4842}
4843
Chris Forbes03e6d762015-11-24 11:13:14 +13004844TEST_F(VkLayerTest, CreatePipelineAttribMatrixType)
4845{
4846 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
4847
4848 ASSERT_NO_FATAL_FAILURE(InitState());
4849 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4850
4851 VkVertexInputBindingDescription input_binding;
4852 memset(&input_binding, 0, sizeof(input_binding));
4853
4854 VkVertexInputAttributeDescription input_attribs[2];
4855 memset(input_attribs, 0, sizeof(input_attribs));
4856
4857 for (int i = 0; i < 2; i++) {
4858 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
4859 input_attribs[i].location = i;
4860 }
4861
4862 char const *vsSource =
4863 "#version 140\n"
4864 "#extension GL_ARB_separate_shader_objects: require\n"
4865 "#extension GL_ARB_shading_language_420pack: require\n"
4866 "\n"
4867 "layout(location=0) in mat2x4 x;\n"
4868 "void main(){\n"
4869 " gl_Position = x[0] + x[1];\n"
4870 "}\n";
4871 char const *fsSource =
4872 "#version 140\n"
4873 "#extension GL_ARB_separate_shader_objects: require\n"
4874 "#extension GL_ARB_shading_language_420pack: require\n"
4875 "\n"
4876 "layout(location=0) out vec4 color;\n"
4877 "void main(){\n"
4878 " color = vec4(1);\n"
4879 "}\n";
4880
4881 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4882 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4883
4884 VkPipelineObj pipe(m_device);
4885 pipe.AddColorAttachment();
4886 pipe.AddShader(&vs);
4887 pipe.AddShader(&fs);
4888
4889 pipe.AddVertexInputBindings(&input_binding, 1);
4890 pipe.AddVertexInputAttribs(input_attribs, 2);
4891
4892 VkDescriptorSetObj descriptorSet(m_device);
4893 descriptorSet.AppendDummy();
4894 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
4895
4896 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4897
4898 /* expect success */
4899 if (m_errorMonitor->DesiredMsgFound()) {
4900 FAIL() << "Expected to succeed but: " << m_errorMonitor->GetFailureMsg();
4901 m_errorMonitor->DumpFailureMsgs();
4902 }
4903}
4904
4905/*
4906 * Would work, but not supported by glslang! This is similar to the matrix case above.
4907 *
4908TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
4909{
4910 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
4911
4912 ASSERT_NO_FATAL_FAILURE(InitState());
4913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4914
4915 VkVertexInputBindingDescription input_binding;
4916 memset(&input_binding, 0, sizeof(input_binding));
4917
4918 VkVertexInputAttributeDescription input_attribs[2];
4919 memset(input_attribs, 0, sizeof(input_attribs));
4920
4921 for (int i = 0; i < 2; i++) {
4922 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
4923 input_attribs[i].location = i;
4924 }
4925
4926 char const *vsSource =
4927 "#version 140\n"
4928 "#extension GL_ARB_separate_shader_objects: require\n"
4929 "#extension GL_ARB_shading_language_420pack: require\n"
4930 "\n"
4931 "layout(location=0) in vec4 x[2];\n"
4932 "void main(){\n"
4933 " gl_Position = x[0] + x[1];\n"
4934 "}\n";
4935 char const *fsSource =
4936 "#version 140\n"
4937 "#extension GL_ARB_separate_shader_objects: require\n"
4938 "#extension GL_ARB_shading_language_420pack: require\n"
4939 "\n"
4940 "layout(location=0) out vec4 color;\n"
4941 "void main(){\n"
4942 " color = vec4(1);\n"
4943 "}\n";
4944
4945 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4946 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4947
4948 VkPipelineObj pipe(m_device);
4949 pipe.AddColorAttachment();
4950 pipe.AddShader(&vs);
4951 pipe.AddShader(&fs);
4952
4953 pipe.AddVertexInputBindings(&input_binding, 1);
4954 pipe.AddVertexInputAttribs(input_attribs, 2);
4955
4956 VkDescriptorSetObj descriptorSet(m_device);
4957 descriptorSet.AppendDummy();
4958 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
4959
4960 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4961
4962 if (m_errorMonitor->DesiredMsgFound()) {
4963 FAIL() << "Expected to succeed but: " << m_errorMonitor->GetFailureMsg();
4964 m_errorMonitor->DumpFailureMsgs();
4965 }
4966}
4967*/
4968
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004969TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
4970{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004972 "Duplicate vertex input binding descriptions for binding 0");
4973
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004974 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004975 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004976
4977 /* Two binding descriptions for binding 0 */
4978 VkVertexInputBindingDescription input_bindings[2];
4979 memset(input_bindings, 0, sizeof(input_bindings));
4980
4981 VkVertexInputAttributeDescription input_attrib;
4982 memset(&input_attrib, 0, sizeof(input_attrib));
4983 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4984
4985 char const *vsSource =
4986 "#version 140\n"
4987 "#extension GL_ARB_separate_shader_objects: require\n"
4988 "#extension GL_ARB_shading_language_420pack: require\n"
4989 "\n"
4990 "layout(location=0) in float x;\n" /* attrib provided float */
4991 "void main(){\n"
4992 " gl_Position = vec4(x);\n"
4993 "}\n";
4994 char const *fsSource =
4995 "#version 140\n"
4996 "#extension GL_ARB_separate_shader_objects: require\n"
4997 "#extension GL_ARB_shading_language_420pack: require\n"
4998 "\n"
4999 "layout(location=0) out vec4 color;\n"
5000 "void main(){\n"
5001 " color = vec4(1);\n"
5002 "}\n";
5003
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005004 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5005 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12005006
5007 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08005008 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12005009 pipe.AddShader(&vs);
5010 pipe.AddShader(&fs);
5011
5012 pipe.AddVertexInputBindings(input_bindings, 2);
5013 pipe.AddVertexInputAttribs(&input_attrib, 1);
5014
Chris Forbes0bf8fe12015-06-12 11:16:41 +12005015 VkDescriptorSetObj descriptorSet(m_device);
5016 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005017 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12005018
Tony Barboured132432015-08-04 16:23:11 -06005019 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12005020
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005021 if (!m_errorMonitor->DesiredMsgFound()) {
5022 FAIL() << "Did not receive Error 'Duplicate vertex input binding descriptions for binding 0'";
5023 m_errorMonitor->DumpFailureMsgs();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12005024 }
5025}
Chris Forbes4c948702015-05-25 11:13:32 +12005026
Chris Forbesc12ef122015-05-25 11:13:40 +12005027TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
5028{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005030 "Attachment 0 not written by FS");
5031
Chris Forbesc12ef122015-05-25 11:13:40 +12005032 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12005033
5034 char const *vsSource =
5035 "#version 140\n"
5036 "#extension GL_ARB_separate_shader_objects: require\n"
5037 "#extension GL_ARB_shading_language_420pack: require\n"
5038 "\n"
5039 "void main(){\n"
5040 " gl_Position = vec4(1);\n"
5041 "}\n";
5042 char const *fsSource =
5043 "#version 140\n"
5044 "#extension GL_ARB_separate_shader_objects: require\n"
5045 "#extension GL_ARB_shading_language_420pack: require\n"
5046 "\n"
5047 "void main(){\n"
5048 "}\n";
5049
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005050 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5051 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc12ef122015-05-25 11:13:40 +12005052
5053 VkPipelineObj pipe(m_device);
5054 pipe.AddShader(&vs);
5055 pipe.AddShader(&fs);
5056
Chia-I Wuc278df82015-07-07 11:50:03 +08005057 /* set up CB 0, not written */
5058 pipe.AddColorAttachment();
5059 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12005060
Chris Forbesc12ef122015-05-25 11:13:40 +12005061 VkDescriptorSetObj descriptorSet(m_device);
5062 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005063 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12005064
Tony Barboured132432015-08-04 16:23:11 -06005065 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12005066
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005067 if (!m_errorMonitor->DesiredMsgFound()) {
5068 FAIL() << "Did not receive Error 'Attachment 0 not written by FS'";
5069 m_errorMonitor->DumpFailureMsgs();
Chris Forbesc12ef122015-05-25 11:13:40 +12005070 }
5071}
5072
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005073TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
5074{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005075 // TODO: verify that this matches layer
5076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005077 "FS writes to output location 1 with no matching attachment");
5078
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005079 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005080
5081 char const *vsSource =
5082 "#version 140\n"
5083 "#extension GL_ARB_separate_shader_objects: require\n"
5084 "#extension GL_ARB_shading_language_420pack: require\n"
5085 "\n"
5086 "void main(){\n"
5087 " gl_Position = vec4(1);\n"
5088 "}\n";
5089 char const *fsSource =
5090 "#version 140\n"
5091 "#extension GL_ARB_separate_shader_objects: require\n"
5092 "#extension GL_ARB_shading_language_420pack: require\n"
5093 "\n"
5094 "layout(location=0) out vec4 x;\n"
5095 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
5096 "void main(){\n"
5097 " x = vec4(1);\n"
5098 " y = vec4(1);\n"
5099 "}\n";
5100
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005101 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5102 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005103
5104 VkPipelineObj pipe(m_device);
5105 pipe.AddShader(&vs);
5106 pipe.AddShader(&fs);
5107
Chia-I Wuc278df82015-07-07 11:50:03 +08005108 /* set up CB 0, not written */
5109 pipe.AddColorAttachment();
5110 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005111 /* FS writes CB 1, but we don't configure it */
5112
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005113 VkDescriptorSetObj descriptorSet(m_device);
5114 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005115 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005116
Tony Barboured132432015-08-04 16:23:11 -06005117 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005118
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005119 if (!m_errorMonitor->DesiredMsgFound()) {
5120 FAIL() << "Did not receive Error 'FS writes to output location 1 with no matching attachment'";
5121 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005122 }
5123}
5124
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005125TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
5126{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005128 "does not match FS output type");
5129
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005130 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005131
5132 char const *vsSource =
5133 "#version 140\n"
5134 "#extension GL_ARB_separate_shader_objects: require\n"
5135 "#extension GL_ARB_shading_language_420pack: require\n"
5136 "\n"
5137 "void main(){\n"
5138 " gl_Position = vec4(1);\n"
5139 "}\n";
5140 char const *fsSource =
5141 "#version 140\n"
5142 "#extension GL_ARB_separate_shader_objects: require\n"
5143 "#extension GL_ARB_shading_language_420pack: require\n"
5144 "\n"
5145 "layout(location=0) out ivec4 x;\n" /* not UNORM */
5146 "void main(){\n"
5147 " x = ivec4(1);\n"
5148 "}\n";
5149
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005150 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5151 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005152
5153 VkPipelineObj pipe(m_device);
5154 pipe.AddShader(&vs);
5155 pipe.AddShader(&fs);
5156
Chia-I Wuc278df82015-07-07 11:50:03 +08005157 /* set up CB 0; type is UNORM by default */
5158 pipe.AddColorAttachment();
5159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005160
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005161 VkDescriptorSetObj descriptorSet(m_device);
5162 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005163 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005164
Tony Barboured132432015-08-04 16:23:11 -06005165 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005166
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005167 if (!m_errorMonitor->DesiredMsgFound()) {
5168 FAIL() << "Did not receive Error 'does not match FS output type'";
5169 m_errorMonitor->DumpFailureMsgs();
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005170 }
5171}
Chris Forbesc2050732015-06-05 14:43:36 +12005172
Chris Forbes76ce7882015-08-14 12:04:59 +12005173TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
5174{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005176 "not declared in pipeline layout");
5177
Chris Forbes76ce7882015-08-14 12:04:59 +12005178 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +12005179
5180 char const *vsSource =
5181 "#version 140\n"
5182 "#extension GL_ARB_separate_shader_objects: require\n"
5183 "#extension GL_ARB_shading_language_420pack: require\n"
5184 "\n"
5185 "void main(){\n"
5186 " gl_Position = vec4(1);\n"
5187 "}\n";
5188 char const *fsSource =
5189 "#version 140\n"
5190 "#extension GL_ARB_separate_shader_objects: require\n"
5191 "#extension GL_ARB_shading_language_420pack: require\n"
5192 "\n"
5193 "layout(location=0) out vec4 x;\n"
5194 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5195 "void main(){\n"
5196 " x = vec4(bar.y);\n"
5197 "}\n";
5198
Chris Forbes76ce7882015-08-14 12:04:59 +12005199
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005200 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5201 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes76ce7882015-08-14 12:04:59 +12005202
Chris Forbes76ce7882015-08-14 12:04:59 +12005203 VkPipelineObj pipe(m_device);
5204 pipe.AddShader(&vs);
5205 pipe.AddShader(&fs);
5206
5207 /* set up CB 0; type is UNORM by default */
5208 pipe.AddColorAttachment();
5209 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5210
5211 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1f851912015-10-27 18:04:07 +08005212 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes76ce7882015-08-14 12:04:59 +12005213
5214 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5215
5216 /* should have generated an error -- pipeline layout does not
5217 * provide a uniform buffer in 0.0
5218 */
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005219 if (!m_errorMonitor->DesiredMsgFound()) {
5220 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
5221 m_errorMonitor->DumpFailureMsgs();
Chris Forbes76ce7882015-08-14 12:04:59 +12005222 }
5223}
5224
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06005225#endif // SHADER_CHECKER_TESTS
5226
5227#if DEVICE_LIMITS_TESTS
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005228TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
5229{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005231 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005232
5233 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005234
5235 // Create an image
5236 VkImage image;
5237
5238 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5239 const int32_t tex_width = 32;
5240 const int32_t tex_height = 32;
5241
5242 VkImageCreateInfo image_create_info = {};
5243 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5244 image_create_info.pNext = NULL;
5245 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5246 image_create_info.format = tex_format;
5247 image_create_info.extent.width = tex_width;
5248 image_create_info.extent.height = tex_height;
5249 image_create_info.extent.depth = 1;
5250 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005251 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005252 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005253 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5254 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5255 image_create_info.flags = 0;
5256
5257 // Introduce error by sending down a bogus width extent
5258 image_create_info.extent.width = 65536;
Chia-I Wu69f40122015-10-26 21:10:41 +08005259 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005260
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005261 if (!m_errorMonitor->DesiredMsgFound()) {
5262 FAIL() << "Did not receive Error 'CreateImage extents exceed allowable limits for format'";
5263 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005264 }
5265}
5266
5267TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
5268{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005270 "CreateImage resource size exceeds allowable maximum");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005271
5272 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005273
5274 // Create an image
5275 VkImage image;
5276
5277 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5278 const int32_t tex_width = 32;
5279 const int32_t tex_height = 32;
5280
5281 VkImageCreateInfo image_create_info = {};
5282 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5283 image_create_info.pNext = NULL;
5284 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5285 image_create_info.format = tex_format;
5286 image_create_info.extent.width = tex_width;
5287 image_create_info.extent.height = tex_height;
5288 image_create_info.extent.depth = 1;
5289 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005290 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005291 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005292 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5293 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5294 image_create_info.flags = 0;
5295
5296 // Introduce error by sending down individually allowable values that result in a surface size
5297 // exceeding the device maximum
5298 image_create_info.extent.width = 8192;
5299 image_create_info.extent.height = 8192;
5300 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005301 image_create_info.arrayLayers = 4;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005302 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005303 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
Chia-I Wu69f40122015-10-26 21:10:41 +08005304 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005305
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005306 if (!m_errorMonitor->DesiredMsgFound()) {
5307 FAIL() << "Did not receive Error 'CreateImage resource size exceeds allowable maximum'";
5308 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005309 }
5310}
5311
Mike Stroyan43909d82015-09-25 13:39:21 -06005312TEST_F(VkLayerTest, UpdateBufferAlignment)
5313{
Mike Stroyan43909d82015-09-25 13:39:21 -06005314 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
5315
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005317 "dstOffset, is not a multiple of 4");
5318
Mike Stroyan43909d82015-09-25 13:39:21 -06005319 ASSERT_NO_FATAL_FAILURE(InitState());
5320
5321 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5322 vk_testing::Buffer buffer;
5323 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
5324
5325 BeginCommandBuffer();
5326 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08005327 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005328 if (!m_errorMonitor->DesiredMsgFound()) {
5329 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
5330 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005331 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005332
Mike Stroyan43909d82015-09-25 13:39:21 -06005333 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005335 "dataSize, is not a multiple of 4");
5336
Chia-I Wu1f851912015-10-27 18:04:07 +08005337 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005338
5339 if (!m_errorMonitor->DesiredMsgFound()) {
5340 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
5341 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005342 }
5343 EndCommandBuffer();
5344}
5345
5346TEST_F(VkLayerTest, FillBufferAlignment)
5347{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005349 "dstOffset, is not a multiple of 4");
Mike Stroyan43909d82015-09-25 13:39:21 -06005350
5351 ASSERT_NO_FATAL_FAILURE(InitState());
5352
5353 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5354 vk_testing::Buffer buffer;
5355 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
5356
5357 BeginCommandBuffer();
5358 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08005359 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005360 if (!m_errorMonitor->DesiredMsgFound()) {
5361 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
5362 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005363 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005364
Mike Stroyan43909d82015-09-25 13:39:21 -06005365 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005367 "size, is not a multiple of 4");
5368
Chia-I Wu1f851912015-10-27 18:04:07 +08005369 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005370
5371 if (!m_errorMonitor->DesiredMsgFound()) {
5372 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize size, is not a multiple of 4'";
5373 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005374 }
5375 EndCommandBuffer();
5376}
5377
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06005378#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005379
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005380#if IMAGE_TESTS
5381TEST_F(VkLayerTest, InvalidImageView)
5382{
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005383 VkResult err;
5384
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005386 "vkCreateImageView called with baseMipLevel 10 ");
5387
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005388 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005389
Mike Stroyan43909d82015-09-25 13:39:21 -06005390 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005391 VkImage image;
5392
5393 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5394 const int32_t tex_width = 32;
5395 const int32_t tex_height = 32;
5396
5397 VkImageCreateInfo image_create_info = {};
5398 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5399 image_create_info.pNext = NULL;
5400 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5401 image_create_info.format = tex_format;
5402 image_create_info.extent.width = tex_width;
5403 image_create_info.extent.height = tex_height;
5404 image_create_info.extent.depth = 1;
5405 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005406 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005407 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005408 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5409 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5410 image_create_info.flags = 0;
5411
Chia-I Wu69f40122015-10-26 21:10:41 +08005412 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005413 ASSERT_VK_SUCCESS(err);
5414
5415 VkImageViewCreateInfo image_view_create_info = {};
5416 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5417 image_view_create_info.image = image;
5418 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5419 image_view_create_info.format = tex_format;
Chia-I Wu1f851912015-10-27 18:04:07 +08005420 image_view_create_info.subresourceRange.layerCount = 1;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005421 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Chia-I Wu1f851912015-10-27 18:04:07 +08005422 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005423 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005424
5425 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08005426 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005427
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005428 if (!m_errorMonitor->DesiredMsgFound()) {
5429 FAIL() << "Did not receive Error 'vkCreateImageView called with baseMipLevel 10...'";
5430 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005431 }
5432}
Mike Stroyan43909d82015-09-25 13:39:21 -06005433
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005434TEST_F(VkLayerTest, InvalidImageViewAspect)
5435{
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005436 VkResult err;
5437
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005439 "vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set");
5440
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005441 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005442
5443 // Create an image and try to create a view with an invalid aspectMask
5444 VkImage image;
5445
5446 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5447 const int32_t tex_width = 32;
5448 const int32_t tex_height = 32;
5449
5450 VkImageCreateInfo image_create_info = {};
5451 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5452 image_create_info.pNext = NULL;
5453 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5454 image_create_info.format = tex_format;
5455 image_create_info.extent.width = tex_width;
5456 image_create_info.extent.height = tex_height;
5457 image_create_info.extent.depth = 1;
5458 image_create_info.mipLevels = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005459 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005460 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5461 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5462 image_create_info.flags = 0;
5463
Chia-I Wu69f40122015-10-26 21:10:41 +08005464 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005465 ASSERT_VK_SUCCESS(err);
5466
5467 VkImageViewCreateInfo image_view_create_info = {};
5468 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5469 image_view_create_info.image = image;
5470 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5471 image_view_create_info.format = tex_format;
5472 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005473 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005474 // Cause an error by setting an invalid image aspect
5475 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
5476
5477 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08005478 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005479
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005480 if (!m_errorMonitor->DesiredMsgFound()) {
5481 FAIL() << "Did not receive Error 'VkCreateImageView: Color image formats must have ...'";
5482 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005483 }
5484}
5485
Mike Stroyan43909d82015-09-25 13:39:21 -06005486TEST_F(VkLayerTest, CopyImageTypeMismatch)
5487{
Mike Stroyan43909d82015-09-25 13:39:21 -06005488 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005489 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005490
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005492 "vkCmdCopyImage called with unmatched source and dest image types");
5493
Mike Stroyan43909d82015-09-25 13:39:21 -06005494 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005495
5496 // Create two images of different types and try to copy between them
5497 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005498 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005499 VkDeviceMemory srcMem;
5500 VkDeviceMemory destMem;
5501 VkMemoryRequirements memReqs;
5502
5503 VkImageCreateInfo image_create_info = {};
5504 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5505 image_create_info.pNext = NULL;
5506 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5507 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5508 image_create_info.extent.width = 32;
5509 image_create_info.extent.height = 32;
5510 image_create_info.extent.depth = 1;
5511 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005512 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005513 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005514 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005515 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005516 image_create_info.flags = 0;
5517
Chia-I Wu69f40122015-10-26 21:10:41 +08005518 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005519 ASSERT_VK_SUCCESS(err);
5520
5521 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005522 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005523
Chia-I Wu1f851912015-10-27 18:04:07 +08005524 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005525 ASSERT_VK_SUCCESS(err);
5526
5527 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005528 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005529 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005530 memAlloc.pNext = NULL;
5531 memAlloc.allocationSize = 0;
5532 memAlloc.memoryTypeIndex = 0;
5533
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005534 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005535 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005536 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5537 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005538 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005539 ASSERT_VK_SUCCESS(err);
5540
Chia-I Wu1f851912015-10-27 18:04:07 +08005541 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005542 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005543 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005544 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005545 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005546 ASSERT_VK_SUCCESS(err);
5547
5548 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5549 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005550 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005551 ASSERT_VK_SUCCESS(err);
5552
5553 BeginCommandBuffer();
5554 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005555 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005556 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005557 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005558 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005559 copyRegion.srcOffset.x = 0;
5560 copyRegion.srcOffset.y = 0;
5561 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005562 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005563 copyRegion.dstSubresource.mipLevel = 0;
5564 copyRegion.dstSubresource.baseArrayLayer = 0;
5565 copyRegion.dstSubresource.layerCount = 0;
5566 copyRegion.dstOffset.x = 0;
5567 copyRegion.dstOffset.y = 0;
5568 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005569 copyRegion.extent.width = 1;
5570 copyRegion.extent.height = 1;
5571 copyRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005572 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005573 EndCommandBuffer();
5574
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005575 if (!m_errorMonitor->DesiredMsgFound()) {
5576 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5577 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005578 }
5579
Chia-I Wu69f40122015-10-26 21:10:41 +08005580 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005581 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005582 vkFreeMemory(m_device->device(), srcMem, NULL);
5583 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005584}
5585
5586TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
5587{
5588 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
5589}
5590
5591TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
5592{
Mike Stroyan43909d82015-09-25 13:39:21 -06005593 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005594 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005595
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005597 "vkCmdCopyImage called with unmatched source and dest image types");
5598
Mike Stroyan43909d82015-09-25 13:39:21 -06005599 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005600
5601 // Create two images of different types and try to copy between them
5602 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005603 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005604 VkDeviceMemory srcMem;
5605 VkDeviceMemory destMem;
5606 VkMemoryRequirements memReqs;
5607
5608 VkImageCreateInfo image_create_info = {};
5609 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5610 image_create_info.pNext = NULL;
5611 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5612 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5613 image_create_info.extent.width = 32;
5614 image_create_info.extent.height = 32;
5615 image_create_info.extent.depth = 1;
5616 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005617 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005618 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005619 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005620 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005621 image_create_info.flags = 0;
5622
Chia-I Wu69f40122015-10-26 21:10:41 +08005623 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005624 ASSERT_VK_SUCCESS(err);
5625
5626 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005627 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005628
Chia-I Wu1f851912015-10-27 18:04:07 +08005629 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005630 ASSERT_VK_SUCCESS(err);
5631
5632 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005633 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005634 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005635 memAlloc.pNext = NULL;
5636 memAlloc.allocationSize = 0;
5637 memAlloc.memoryTypeIndex = 0;
5638
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005639 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005640 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005641 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5642 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005643 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005644 ASSERT_VK_SUCCESS(err);
5645
Chia-I Wu1f851912015-10-27 18:04:07 +08005646 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005647 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005648 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5649 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005650 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005651 ASSERT_VK_SUCCESS(err);
5652
5653 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5654 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005655 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005656 ASSERT_VK_SUCCESS(err);
5657
5658 BeginCommandBuffer();
5659 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005660 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005661 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005662 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005663 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005664 copyRegion.srcOffset.x = 0;
5665 copyRegion.srcOffset.y = 0;
5666 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005667 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005668 copyRegion.dstSubresource.mipLevel = 0;
5669 copyRegion.dstSubresource.baseArrayLayer = 0;
5670 copyRegion.dstSubresource.layerCount = 0;
5671 copyRegion.dstOffset.x = 0;
5672 copyRegion.dstOffset.y = 0;
5673 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005674 copyRegion.extent.width = 1;
5675 copyRegion.extent.height = 1;
5676 copyRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005677 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005678 EndCommandBuffer();
5679
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005680 if (!m_errorMonitor->DesiredMsgFound()) {
5681 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5682 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005683 }
5684
Chia-I Wu69f40122015-10-26 21:10:41 +08005685 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005686 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005687 vkFreeMemory(m_device->device(), srcMem, NULL);
5688 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005689}
5690
5691TEST_F(VkLayerTest, ResolveImageLowSampleCount)
5692{
Mike Stroyan43909d82015-09-25 13:39:21 -06005693 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005694 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005695
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005697 "vkCmdResolveImage called with source sample count less than 2.");
5698
Mike Stroyan43909d82015-09-25 13:39:21 -06005699 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005700
5701 // Create two images of sample count 1 and try to Resolve between them
5702 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005703 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005704 VkDeviceMemory srcMem;
5705 VkDeviceMemory destMem;
5706 VkMemoryRequirements memReqs;
5707
5708 VkImageCreateInfo image_create_info = {};
5709 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5710 image_create_info.pNext = NULL;
5711 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5712 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5713 image_create_info.extent.width = 32;
5714 image_create_info.extent.height = 1;
5715 image_create_info.extent.depth = 1;
5716 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005717 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005718 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005719 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005720 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005721 image_create_info.flags = 0;
5722
Chia-I Wu69f40122015-10-26 21:10:41 +08005723 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005724 ASSERT_VK_SUCCESS(err);
5725
5726 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005727 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005728
Chia-I Wu1f851912015-10-27 18:04:07 +08005729 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005730 ASSERT_VK_SUCCESS(err);
5731
5732 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005733 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005734 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005735 memAlloc.pNext = NULL;
5736 memAlloc.allocationSize = 0;
5737 memAlloc.memoryTypeIndex = 0;
5738
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005739 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005740 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005741 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5742 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005743 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005744 ASSERT_VK_SUCCESS(err);
5745
Chia-I Wu1f851912015-10-27 18:04:07 +08005746 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005747 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005748 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5749 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005750 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005751 ASSERT_VK_SUCCESS(err);
5752
5753 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5754 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005755 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005756 ASSERT_VK_SUCCESS(err);
5757
5758 BeginCommandBuffer();
5759 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5760 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5761 //VK_IMAGE_LAYOUT_GENERAL = 1,
5762 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005763 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005764 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005765 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005766 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005767 resolveRegion.srcOffset.x = 0;
5768 resolveRegion.srcOffset.y = 0;
5769 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005770 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005771 resolveRegion.dstSubresource.mipLevel = 0;
5772 resolveRegion.dstSubresource.baseArrayLayer = 0;
5773 resolveRegion.dstSubresource.layerCount = 0;
5774 resolveRegion.dstOffset.x = 0;
5775 resolveRegion.dstOffset.y = 0;
5776 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005777 resolveRegion.extent.width = 1;
5778 resolveRegion.extent.height = 1;
5779 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005780 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005781 EndCommandBuffer();
5782
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005783 if (!m_errorMonitor->DesiredMsgFound()) {
5784 FAIL() << "Did not receive Error 'vkCmdResolveImage called with source sample count less than 2.'";
5785 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005786 }
5787
Chia-I Wu69f40122015-10-26 21:10:41 +08005788 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005789 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005790 vkFreeMemory(m_device->device(), srcMem, NULL);
5791 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005792}
5793
5794TEST_F(VkLayerTest, ResolveImageHighSampleCount)
5795{
Mike Stroyan43909d82015-09-25 13:39:21 -06005796 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005797 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005798
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005800 "vkCmdResolveImage called with dest sample count greater than 1.");
5801
Mike Stroyan43909d82015-09-25 13:39:21 -06005802 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005803
5804 // Create two images of sample count 2 and try to Resolve between them
5805 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005806 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005807 VkDeviceMemory srcMem;
5808 VkDeviceMemory destMem;
5809 VkMemoryRequirements memReqs;
5810
5811 VkImageCreateInfo image_create_info = {};
5812 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5813 image_create_info.pNext = NULL;
5814 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5815 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5816 image_create_info.extent.width = 32;
5817 image_create_info.extent.height = 1;
5818 image_create_info.extent.depth = 1;
5819 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005820 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005821 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005822 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005823 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005824 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005825 image_create_info.flags = 0;
5826
Chia-I Wu69f40122015-10-26 21:10:41 +08005827 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005828 ASSERT_VK_SUCCESS(err);
5829
5830 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005831 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005832 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005833
Chia-I Wu1f851912015-10-27 18:04:07 +08005834 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005835 ASSERT_VK_SUCCESS(err);
5836
5837 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005838 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005839 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005840 memAlloc.pNext = NULL;
5841 memAlloc.allocationSize = 0;
5842 memAlloc.memoryTypeIndex = 0;
5843
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005844 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005845 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005846 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5847 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005848 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005849 ASSERT_VK_SUCCESS(err);
5850
Chia-I Wu1f851912015-10-27 18:04:07 +08005851 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005852 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005853 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5854 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005855 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005856 ASSERT_VK_SUCCESS(err);
5857
5858 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5859 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005860 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005861 ASSERT_VK_SUCCESS(err);
5862
5863 BeginCommandBuffer();
5864 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5865 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5866 //VK_IMAGE_LAYOUT_GENERAL = 1,
5867 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005868 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005869 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005870 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005871 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005872 resolveRegion.srcOffset.x = 0;
5873 resolveRegion.srcOffset.y = 0;
5874 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005875 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005876 resolveRegion.dstSubresource.mipLevel = 0;
5877 resolveRegion.dstSubresource.baseArrayLayer = 0;
5878 resolveRegion.dstSubresource.layerCount = 0;
5879 resolveRegion.dstOffset.x = 0;
5880 resolveRegion.dstOffset.y = 0;
5881 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005882 resolveRegion.extent.width = 1;
5883 resolveRegion.extent.height = 1;
5884 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005885 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005886 EndCommandBuffer();
5887
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005888 if (!m_errorMonitor->DesiredMsgFound()) {
5889 FAIL() << "Did not receive Error 'vkCmdResolveImage called with dest sample count greater than 1.'";
5890 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005891 }
5892
Chia-I Wu69f40122015-10-26 21:10:41 +08005893 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005894 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005895 vkFreeMemory(m_device->device(), srcMem, NULL);
5896 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005897}
5898
5899TEST_F(VkLayerTest, ResolveImageFormatMismatch)
5900{
Mike Stroyan43909d82015-09-25 13:39:21 -06005901 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005902 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005903
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005905 "vkCmdResolveImage called with unmatched source and dest formats.");
5906
Mike Stroyan43909d82015-09-25 13:39:21 -06005907 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005908
5909 // Create two images of different types and try to copy between them
5910 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005911 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005912 VkDeviceMemory srcMem;
5913 VkDeviceMemory destMem;
5914 VkMemoryRequirements memReqs;
5915
5916 VkImageCreateInfo image_create_info = {};
5917 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5918 image_create_info.pNext = NULL;
5919 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5920 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5921 image_create_info.extent.width = 32;
5922 image_create_info.extent.height = 1;
5923 image_create_info.extent.depth = 1;
5924 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005925 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005926 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005927 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005928 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005929 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005930 image_create_info.flags = 0;
5931
Chia-I Wu69f40122015-10-26 21:10:41 +08005932 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005933 ASSERT_VK_SUCCESS(err);
5934
Cody Northropb3bf94f2015-10-27 13:50:04 -06005935 // Set format to something other than source image
5936 image_create_info.format = VK_FORMAT_R32_SFLOAT;
5937 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005938 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005939 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005940
Chia-I Wu1f851912015-10-27 18:04:07 +08005941 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005942 ASSERT_VK_SUCCESS(err);
5943
5944 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005945 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005946 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005947 memAlloc.pNext = NULL;
5948 memAlloc.allocationSize = 0;
5949 memAlloc.memoryTypeIndex = 0;
5950
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005951 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005952 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005953 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5954 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005955 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005956 ASSERT_VK_SUCCESS(err);
5957
Chia-I Wu1f851912015-10-27 18:04:07 +08005958 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005959 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005960 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5961 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005962 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005963 ASSERT_VK_SUCCESS(err);
5964
5965 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5966 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005967 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005968 ASSERT_VK_SUCCESS(err);
5969
5970 BeginCommandBuffer();
5971 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5972 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5973 //VK_IMAGE_LAYOUT_GENERAL = 1,
5974 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005975 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005976 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005977 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005978 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005979 resolveRegion.srcOffset.x = 0;
5980 resolveRegion.srcOffset.y = 0;
5981 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005982 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005983 resolveRegion.dstSubresource.mipLevel = 0;
5984 resolveRegion.dstSubresource.baseArrayLayer = 0;
5985 resolveRegion.dstSubresource.layerCount = 0;
5986 resolveRegion.dstOffset.x = 0;
5987 resolveRegion.dstOffset.y = 0;
5988 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005989 resolveRegion.extent.width = 1;
5990 resolveRegion.extent.height = 1;
5991 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005992 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005993 EndCommandBuffer();
5994
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005995 if (!m_errorMonitor->DesiredMsgFound()) {
5996 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest formats.'";
5997 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005998 }
5999
Chia-I Wu69f40122015-10-26 21:10:41 +08006000 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08006001 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08006002 vkFreeMemory(m_device->device(), srcMem, NULL);
6003 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06006004}
6005
6006TEST_F(VkLayerTest, ResolveImageTypeMismatch)
6007{
Mike Stroyan43909d82015-09-25 13:39:21 -06006008 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06006009 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06006010
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07006011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006012 "vkCmdResolveImage called with unmatched source and dest image types.");
6013
Mike Stroyan43909d82015-09-25 13:39:21 -06006014 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06006015
6016 // Create two images of different types and try to copy between them
6017 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08006018 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06006019 VkDeviceMemory srcMem;
6020 VkDeviceMemory destMem;
6021 VkMemoryRequirements memReqs;
6022
6023 VkImageCreateInfo image_create_info = {};
6024 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6025 image_create_info.pNext = NULL;
6026 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6027 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6028 image_create_info.extent.width = 32;
6029 image_create_info.extent.height = 1;
6030 image_create_info.extent.depth = 1;
6031 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06006032 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08006033 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006034 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06006035 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08006036 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006037 image_create_info.flags = 0;
6038
Chia-I Wu69f40122015-10-26 21:10:41 +08006039 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06006040 ASSERT_VK_SUCCESS(err);
6041
6042 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northropb3bf94f2015-10-27 13:50:04 -06006043 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08006044 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08006045 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006046
Chia-I Wu1f851912015-10-27 18:04:07 +08006047 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06006048 ASSERT_VK_SUCCESS(err);
6049
6050 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08006051 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08006052 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06006053 memAlloc.pNext = NULL;
6054 memAlloc.allocationSize = 0;
6055 memAlloc.memoryTypeIndex = 0;
6056
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06006057 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06006058 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06006059 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6060 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08006061 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06006062 ASSERT_VK_SUCCESS(err);
6063
Chia-I Wu1f851912015-10-27 18:04:07 +08006064 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06006065 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06006066 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6067 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08006068 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06006069 ASSERT_VK_SUCCESS(err);
6070
6071 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6072 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08006073 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06006074 ASSERT_VK_SUCCESS(err);
6075
6076 BeginCommandBuffer();
6077 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
6078 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
6079 //VK_IMAGE_LAYOUT_GENERAL = 1,
6080 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08006081 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006082 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06006083 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08006084 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006085 resolveRegion.srcOffset.x = 0;
6086 resolveRegion.srcOffset.y = 0;
6087 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08006088 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08006089 resolveRegion.dstSubresource.mipLevel = 0;
6090 resolveRegion.dstSubresource.baseArrayLayer = 0;
6091 resolveRegion.dstSubresource.layerCount = 0;
6092 resolveRegion.dstOffset.x = 0;
6093 resolveRegion.dstOffset.y = 0;
6094 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006095 resolveRegion.extent.width = 1;
6096 resolveRegion.extent.height = 1;
6097 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08006098 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06006099 EndCommandBuffer();
6100
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006101 if (!m_errorMonitor->DesiredMsgFound()) {
6102 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest image types.'";
6103 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06006104 }
6105
Chia-I Wu69f40122015-10-26 21:10:41 +08006106 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08006107 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08006108 vkFreeMemory(m_device->device(), srcMem, NULL);
6109 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06006110}
Tobin Ehlisb46be812015-10-23 16:00:08 -06006111
6112TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError)
6113{
6114 // Create a single Image descriptor and cause it to first hit an error due
6115 // to using a DS format, then cause it to hit error due to COLOR_BIT not set in aspect
6116 // The image format check comes 2nd in validation so we trigger it first,
6117 // then when we cause aspect fail next, bad format check will be preempted
Tobin Ehlisb46be812015-10-23 16:00:08 -06006118 VkResult err;
6119
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07006120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006121 "Combination depth/stencil image formats can have only the ");
6122
Tobin Ehlisb46be812015-10-23 16:00:08 -06006123 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006124
Chia-I Wuc51b1212015-10-27 19:25:11 +08006125 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06006126 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu763a7492015-10-26 20:48:51 +08006127 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006128
6129 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6130 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6131 ds_pool_ci.pNext = NULL;
6132 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08006133 ds_pool_ci.poolSizeCount = 1;
6134 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006135
6136 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08006137 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006138 ASSERT_VK_SUCCESS(err);
6139
6140 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08006141 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006142 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu045654f2015-11-06 06:42:02 +08006143 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006144 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6145 dsl_binding.pImmutableSamplers = NULL;
6146
6147 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6148 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6149 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08006150 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08006151 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006152 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08006153 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006154 ASSERT_VK_SUCCESS(err);
6155
6156 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08006157 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08006158 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08006159 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006160 alloc_info.descriptorPool = ds_pool;
6161 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08006162 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006163 ASSERT_VK_SUCCESS(err);
6164
6165 VkImage image_bad;
6166 VkImage image_good;
6167 // One bad format and one good format for Color attachment
6168 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
6169 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
6170 const int32_t tex_width = 32;
6171 const int32_t tex_height = 32;
6172
6173 VkImageCreateInfo image_create_info = {};
6174 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6175 image_create_info.pNext = NULL;
6176 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6177 image_create_info.format = tex_format_bad;
6178 image_create_info.extent.width = tex_width;
6179 image_create_info.extent.height = tex_height;
6180 image_create_info.extent.depth = 1;
6181 image_create_info.mipLevels = 1;
6182 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08006183 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006184 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6185 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
6186 image_create_info.flags = 0;
6187
Chia-I Wu69f40122015-10-26 21:10:41 +08006188 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006189 ASSERT_VK_SUCCESS(err);
6190 image_create_info.format = tex_format_good;
6191 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu69f40122015-10-26 21:10:41 +08006192 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006193 ASSERT_VK_SUCCESS(err);
6194
6195 VkImageViewCreateInfo image_view_create_info = {};
6196 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6197 image_view_create_info.image = image_bad;
6198 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6199 image_view_create_info.format = tex_format_bad;
6200 image_view_create_info.subresourceRange.baseArrayLayer = 0;
6201 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08006202 image_view_create_info.subresourceRange.layerCount = 1;
6203 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006204 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6205
6206 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08006207 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006208
6209 if (!m_errorMonitor->DesiredMsgFound()) {
6210 FAIL() << "Did not receive Error 'Combination depth-stencil image formats can have only the....'";
6211 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06006212 }
6213
Chia-I Wu69f40122015-10-26 21:10:41 +08006214 vkDestroyImage(m_device->device(), image_bad, NULL);
6215 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08006216 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6217 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006218}
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06006219#endif // IMAGE_TESTS
6220
Tony Barbour30486ea2015-04-07 13:44:53 -06006221int main(int argc, char **argv) {
6222 int result;
6223
6224 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06006225 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06006226
6227 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
6228
6229 result = RUN_ALL_TESTS();
6230
Tony Barbour01999182015-04-09 12:58:51 -06006231 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06006232 return result;
6233}