blob: c41893d8ae6ea25339808f62b9cc05d3644bd874 [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
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600102static VkBool32 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
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001317TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1318{
1319 // Initiate Draw w/o a PSO bound
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001320 VkResult err;
1321
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001323 "Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
1324
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001325 ASSERT_NO_FATAL_FAILURE(InitState());
1326 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001327
1328 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
Chia-I Wuc51b1212015-10-27 19:25:11 +08001329 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001330 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001331 ds_type_count.descriptorCount = 1;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001332
1333 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1334 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1335 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001336 ds_pool_ci.flags = 0;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001337 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001338 ds_pool_ci.poolSizeCount = 1;
1339 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001340
1341 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001342 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001343 ASSERT_VK_SUCCESS(err);
1344
1345 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001346 dsl_binding.binding = 0;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001347 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001348 dsl_binding.descriptorCount = 1;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001349 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1350 dsl_binding.pImmutableSamplers = NULL;
1351
1352 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1353 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1354 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001355 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001356 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001357
1358 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001359 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001360 ASSERT_VK_SUCCESS(err);
1361
1362 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001363 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001364 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001365 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001366 alloc_info.descriptorPool = ds_pool;
1367 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001368 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001369
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001370 if (!m_errorMonitor->DesiredMsgFound()) {
1371 FAIL() << "Did not receive Error 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...'";
1372 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001373 }
1374
Chia-I Wu69f40122015-10-26 21:10:41 +08001375 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1376 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001377}
1378
Tobin Ehlis3c543112015-10-08 13:13:50 -06001379TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1380{
Tobin Ehlis3c543112015-10-08 13:13:50 -06001381 VkResult err;
1382
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001384 "It is invalid to call vkFreeDescriptorSets() with a pool created without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
1385
Tobin Ehlis3c543112015-10-08 13:13:50 -06001386 ASSERT_NO_FATAL_FAILURE(InitState());
1387 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis3c543112015-10-08 13:13:50 -06001388
Chia-I Wuc51b1212015-10-27 19:25:11 +08001389 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis3c543112015-10-08 13:13:50 -06001390 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001391 ds_type_count.descriptorCount = 1;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001392
1393 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1394 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1395 ds_pool_ci.pNext = NULL;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001396 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001397 ds_pool_ci.poolSizeCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001398 ds_pool_ci.flags = 0;
1399 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
1400 // app can only call vkResetDescriptorPool on this pool.;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001401 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001402
1403 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001404 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001405 ASSERT_VK_SUCCESS(err);
1406
1407 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001408 dsl_binding.binding = 0;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001409 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001410 dsl_binding.descriptorCount = 1;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001411 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1412 dsl_binding.pImmutableSamplers = NULL;
1413
1414 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1415 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1416 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001417 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001418 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001419
1420 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001421 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001422 ASSERT_VK_SUCCESS(err);
1423
1424 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001425 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001426 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001427 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001428 alloc_info.descriptorPool = ds_pool;
1429 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001430 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001431 ASSERT_VK_SUCCESS(err);
1432
1433 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001434 if (!m_errorMonitor->DesiredMsgFound()) {
1435 FAIL() << "Did not receive Error 'It is invalid to call vkFreeDescriptorSets() with a pool created with...'";
1436 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3c543112015-10-08 13:13:50 -06001437 }
1438
Chia-I Wu69f40122015-10-26 21:10:41 +08001439 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1440 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001441}
1442
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001443TEST_F(VkLayerTest, InvalidDescriptorPool)
1444{
1445 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1446 // The DS check for this is after driver has been called to validate DS internal data struct
1447 // Attempt to clear DS Pool with bad object
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001448/*
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001450 "Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call");
1451
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001452 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1453 vkResetDescriptorPool(device(), badPool);
1454
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001455 if (!m_errorMonitor->DesiredMsgFound()) {
1456 FAIL() << "Did not receive Error 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1457 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001458 }*/
1459}
1460
1461TEST_F(VkLayerTest, InvalidDescriptorSet)
1462{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001463 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1464 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001465 // Create a valid cmd buffer
1466 // call vkCmdBindDescriptorSets w/ false DS
1467}
1468
1469TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1470{
1471 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1472 // The DS check for this is after driver has been called to validate DS internal data struct
1473}
1474
1475TEST_F(VkLayerTest, InvalidPipeline)
1476{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001477 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1478 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001479 // Create a valid cmd buffer
1480 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001481//
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// "Attempt to bind Pipeline ");
Tobin Ehlise4076782015-06-24 15:53:07 -06001484//
1485// ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +08001486// VkCommandBufferObj commandBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001487// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001488// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Chia-I Wu1f851912015-10-27 18:04:07 +08001489// vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001490//
1491// if (!m_errorMonitor->DesiredMsgFound()) {
1492// FAIL() << "Did not receive Error 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1493// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise4076782015-06-24 15:53:07 -06001494// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001495}
1496
Tobin Ehlis254eca02015-06-25 15:46:59 -06001497TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001498{
Chia-I Wu1f851912015-10-27 18:04:07 +08001499 // Create and update CommandBuffer then call QueueSubmit w/o calling End on CommandBuffer
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001500 VkResult err;
1501
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001502 // TODO: verify that this matches layer
1503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001504 " bound but it was never updated. ");
1505
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001506 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001507 ASSERT_NO_FATAL_FAILURE(InitViewport());
1508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wuc51b1212015-10-27 19:25:11 +08001509 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001510 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001511 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001512
1513 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1514 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1515 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001516 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001517 ds_pool_ci.poolSizeCount = 1;
1518 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001519
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001520 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001521 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001522 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001523
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001524 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001525 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001526 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001527 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001528 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1529 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001530
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001531 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1532 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1533 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001534 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001535 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001536 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001537 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001538 ASSERT_VK_SUCCESS(err);
1539
1540 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001541 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001542 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001543 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001544 alloc_info.descriptorPool = ds_pool;
1545 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001546 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001547 ASSERT_VK_SUCCESS(err);
1548
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001549 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1550 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1551 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001552 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001553 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001554
1555 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001556 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001557 ASSERT_VK_SUCCESS(err);
1558
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001559 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001560 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
1561 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001562
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001563 VkPipelineObj pipe(m_device);
1564 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001565 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001566 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001567
1568 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08001569 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1570 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001571
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001572 if (!m_errorMonitor->DesiredMsgFound()) {
1573 FAIL() << "Did not recieve Warning 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1574 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001575 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001576
Chia-I Wu69f40122015-10-26 21:10:41 +08001577 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1578 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1579 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001580}
1581
Tobin Ehlis093ef922015-11-02 15:24:32 -07001582TEST_F(VkLayerTest, InvalidBufferViewObject)
1583{
1584 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
1585 VkResult err;
1586
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis093ef922015-11-02 15:24:32 -07001588 "Attempt to update descriptor with invalid bufferView ");
1589
1590 ASSERT_NO_FATAL_FAILURE(InitState());
1591 VkDescriptorPoolSize ds_type_count = {};
1592 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1593 ds_type_count.descriptorCount = 1;
1594
1595 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1596 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1597 ds_pool_ci.pNext = NULL;
1598 ds_pool_ci.maxSets = 1;
1599 ds_pool_ci.poolSizeCount = 1;
1600 ds_pool_ci.pPoolSizes = &ds_type_count;
1601
1602 VkDescriptorPool ds_pool;
1603 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1604 ASSERT_VK_SUCCESS(err);
1605
1606 VkDescriptorSetLayoutBinding dsl_binding = {};
1607 dsl_binding.binding = 0;
1608 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001609 dsl_binding.descriptorCount = 1;
Tobin Ehlis093ef922015-11-02 15:24:32 -07001610 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1611 dsl_binding.pImmutableSamplers = NULL;
1612
1613 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1614 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1615 ds_layout_ci.pNext = NULL;
1616 ds_layout_ci.bindingCount = 1;
1617 ds_layout_ci.pBinding = &dsl_binding;
1618 VkDescriptorSetLayout ds_layout;
1619 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1620 ASSERT_VK_SUCCESS(err);
1621
1622 VkDescriptorSet descriptorSet;
1623 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001624 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Tobin Ehlis093ef922015-11-02 15:24:32 -07001625 alloc_info.setLayoutCount = 1;
1626 alloc_info.descriptorPool = ds_pool;
1627 alloc_info.pSetLayouts = &ds_layout;
1628 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1629 ASSERT_VK_SUCCESS(err);
1630
1631 VkBufferView view = (VkBufferView) 0xbaadbeef; // invalid bufferView object
Tobin Ehlis093ef922015-11-02 15:24:32 -07001632 VkWriteDescriptorSet descriptor_write;
1633 memset(&descriptor_write, 0, sizeof(descriptor_write));
1634 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1635 descriptor_write.dstSet = descriptorSet;
1636 descriptor_write.dstBinding = 0;
1637 descriptor_write.descriptorCount = 1;
1638 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1639 descriptor_write.pTexelBufferView = &view;
1640
1641 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1642
1643 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlisd9491452015-11-05 10:27:49 -07001644 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid bufferView'";
Tobin Ehlis093ef922015-11-02 15:24:32 -07001645 m_errorMonitor->DumpFailureMsgs();
1646 }
1647
1648 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1649 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1650}
1651
Tobin Ehlise2194862015-11-04 13:30:34 -07001652TEST_F(VkLayerTest, InvalidDynamicOffsetCount)
1653{
1654 // Create a descriptorSet w/ some dynamic descriptors and then don't send offsets when binding
1655 VkResult err;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlise2194862015-11-04 13:30:34 -07001657 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but dynamicOffsetCount is 0. ");
1658
1659 ASSERT_NO_FATAL_FAILURE(InitState());
1660 ASSERT_NO_FATAL_FAILURE(InitViewport());
1661 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1662
1663 VkDescriptorPoolSize ds_type_count = {};
1664 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1665 ds_type_count.descriptorCount = 1;
1666
1667 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1668 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1669 ds_pool_ci.pNext = NULL;
1670 ds_pool_ci.maxSets = 1;
1671 ds_pool_ci.poolSizeCount = 1;
1672 ds_pool_ci.pPoolSizes = &ds_type_count;
1673
1674 VkDescriptorPool ds_pool;
1675 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1676 ASSERT_VK_SUCCESS(err);
1677
1678 VkDescriptorSetLayoutBinding dsl_binding = {};
1679 dsl_binding.binding = 0;
1680 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
Jon Ashburn96b714a2015-11-06 15:31:44 -07001681 dsl_binding.descriptorCount = 1;
Tobin Ehlise2194862015-11-04 13:30:34 -07001682 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1683 dsl_binding.pImmutableSamplers = NULL;
1684
1685 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1686 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1687 ds_layout_ci.pNext = NULL;
1688 ds_layout_ci.bindingCount = 1;
1689 ds_layout_ci.pBinding = &dsl_binding;
1690 VkDescriptorSetLayout ds_layout;
1691 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1692 ASSERT_VK_SUCCESS(err);
1693
1694 VkDescriptorSet descriptorSet;
1695 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001696 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Tobin Ehlise2194862015-11-04 13:30:34 -07001697 alloc_info.setLayoutCount = 1;
1698 alloc_info.descriptorPool = ds_pool;
1699 alloc_info.pSetLayouts = &ds_layout;
1700 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1701 ASSERT_VK_SUCCESS(err);
1702
1703 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1704 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1705 pipeline_layout_ci.pNext = NULL;
1706 pipeline_layout_ci.setLayoutCount = 1;
1707 pipeline_layout_ci.pSetLayouts = &ds_layout;
1708
1709 VkPipelineLayout pipeline_layout;
1710 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
1711 ASSERT_VK_SUCCESS(err);
1712
1713 // Create a buffer to update the descriptor with
1714 uint32_t qfi = 0;
1715 VkBufferCreateInfo buffCI = {};
1716 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1717 buffCI.size = 1024;
1718 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1719 buffCI.queueFamilyIndexCount = 1;
1720 buffCI.pQueueFamilyIndices = &qfi;
1721
1722 VkBuffer dyub;
1723 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
1724 ASSERT_VK_SUCCESS(err);
1725 // Correctly update descriptor to avoid "NOT_UPDATED" error
1726 VkDescriptorBufferInfo buffInfo = {};
1727 buffInfo.buffer = dyub;
1728 buffInfo.offset = 0;
1729 buffInfo.range = 1024;
1730
1731 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_BUFFER_DYNAMIC;
1738 descriptor_write.pBufferInfo = &buffInfo;
1739
1740 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1741
1742 BeginCommandBuffer();
1743 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
1744
1745 if (!m_errorMonitor->DesiredMsgFound()) {
1746 FAIL() << "Error received was not 'Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but dynamicOffsetCount is 0...'";
1747 m_errorMonitor->DumpFailureMsgs();
1748 }
1749
1750 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1751 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1752}
1753
Tobin Ehlis982099b2015-11-05 09:52:49 -07001754TEST_F(VkLayerTest, DescriptorSetCompatibility)
1755{
1756 // Test various desriptorSet errors with bad binding combinations
1757 VkResult err;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001758
1759 ASSERT_NO_FATAL_FAILURE(InitState());
1760 ASSERT_NO_FATAL_FAILURE(InitViewport());
1761 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1762
1763 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
1764 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
1765 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Tobin Ehliscb085292015-12-01 09:57:09 -07001766 ds_type_count[0].descriptorCount = 10;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001767 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1768 ds_type_count[1].descriptorCount = 2;
1769 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
1770 ds_type_count[2].descriptorCount = 2;
1771 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
1772 ds_type_count[3].descriptorCount = 5;
1773 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT type
1774 //ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
1775 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1776 ds_type_count[4].descriptorCount = 2;
1777
1778 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1779 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1780 ds_pool_ci.pNext = NULL;
1781 ds_pool_ci.maxSets = 1;
1782 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
1783 ds_pool_ci.pPoolSizes = ds_type_count;
1784
1785 VkDescriptorPool ds_pool;
1786 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1787 ASSERT_VK_SUCCESS(err);
1788
1789 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
1790 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
1791 dsl_binding[0].binding = 0;
1792 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Tobin Ehliscb085292015-12-01 09:57:09 -07001793 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001794 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
1795 dsl_binding[0].pImmutableSamplers = NULL;
1796
Tobin Ehliscb085292015-12-01 09:57:09 -07001797 // Create layout identical to set0 layout but w/ different stageFlags
1798 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
1799 dsl_fs_stage_only.binding = 0;
1800 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1801 dsl_fs_stage_only.descriptorCount = 5;
1802 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at bind time
1803 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001804 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1805 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1806 ds_layout_ci.pNext = NULL;
1807 ds_layout_ci.bindingCount = 1;
1808 ds_layout_ci.pBinding = dsl_binding;
1809 static const uint32_t NUM_LAYOUTS = 4;
1810 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehliscb085292015-12-01 09:57:09 -07001811 VkDescriptorSetLayout ds_layout_fs_only = {};
1812 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only layout for error case
Tobin Ehlis982099b2015-11-05 09:52:49 -07001813 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
1814 ASSERT_VK_SUCCESS(err);
Tobin Ehliscb085292015-12-01 09:57:09 -07001815 ds_layout_ci.pBinding = &dsl_fs_stage_only;
1816 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
1817 ASSERT_VK_SUCCESS(err);
Tobin Ehlis982099b2015-11-05 09:52:49 -07001818 dsl_binding[0].binding = 0;
1819 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehliscb085292015-12-01 09:57:09 -07001820 dsl_binding[0].descriptorCount = 2;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001821 dsl_binding[0].binding = 1;
1822 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehliscb085292015-12-01 09:57:09 -07001823 dsl_binding[0].descriptorCount = 2;
1824 ds_layout_ci.pBinding = dsl_binding;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001825 ds_layout_ci.bindingCount = 2;
1826 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
1827 ASSERT_VK_SUCCESS(err);
1828 dsl_binding[0].binding = 0;
1829 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehliscb085292015-12-01 09:57:09 -07001830 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001831 ds_layout_ci.bindingCount = 1;
1832 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
1833 ASSERT_VK_SUCCESS(err);
1834 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehliscb085292015-12-01 09:57:09 -07001835 dsl_binding[0].descriptorCount = 2;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001836 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
1837 ASSERT_VK_SUCCESS(err);
1838
1839 static const uint32_t NUM_SETS = 4;
1840 VkDescriptorSet descriptorSet[NUM_SETS] = {};
1841 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehliscb085292015-12-01 09:57:09 -07001842 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001843 alloc_info.setLayoutCount = NUM_LAYOUTS;
1844 alloc_info.descriptorPool = ds_pool;
1845 alloc_info.pSetLayouts = ds_layout;
1846 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
1847 ASSERT_VK_SUCCESS(err);
Tobin Ehliscb085292015-12-01 09:57:09 -07001848 VkDescriptorSet ds0_fs_only = {};
1849 alloc_info.setLayoutCount = 1;
1850 alloc_info.pSetLayouts = &ds_layout_fs_only;
1851 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
1852 ASSERT_VK_SUCCESS(err);
Tobin Ehlis982099b2015-11-05 09:52:49 -07001853
1854 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1855 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1856 pipeline_layout_ci.pNext = NULL;
1857 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
1858 pipeline_layout_ci.pSetLayouts = ds_layout;
1859
1860 VkPipelineLayout pipeline_layout;
1861 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
1862 ASSERT_VK_SUCCESS(err);
Tobin Ehliscb085292015-12-01 09:57:09 -07001863 // Create pipelineLayout with only one setLayout
1864 pipeline_layout_ci.setLayoutCount = 1;
1865 VkPipelineLayout single_pipe_layout;
1866 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
1867 ASSERT_VK_SUCCESS(err);
1868 // Create pipelineLayout with 2 descriptor setLayout at index 0
1869 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
1870 VkPipelineLayout pipe_layout_one_desc;
1871 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
1872 ASSERT_VK_SUCCESS(err);
1873 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
1874 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
1875 VkPipelineLayout pipe_layout_five_samp;
1876 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
1877 ASSERT_VK_SUCCESS(err);
1878 // Create pipelineLayout with UB type, but stageFlags for FS only
1879 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
1880 VkPipelineLayout pipe_layout_fs_only;
1881 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
1882 ASSERT_VK_SUCCESS(err);
1883 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
1884 VkDescriptorSetLayout pl_bad_s0[2] = {};
1885 pl_bad_s0[0] = ds_layout_fs_only;
1886 pl_bad_s0[1] = ds_layout[1];
1887 pipeline_layout_ci.setLayoutCount = 2;
1888 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
1889 VkPipelineLayout pipe_layout_bad_set0;
1890 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
1891 ASSERT_VK_SUCCESS(err);
Tobin Ehlis982099b2015-11-05 09:52:49 -07001892
1893 // Create a buffer to update the descriptor with
1894 uint32_t qfi = 0;
1895 VkBufferCreateInfo buffCI = {};
1896 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1897 buffCI.size = 1024;
1898 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1899 buffCI.queueFamilyIndexCount = 1;
1900 buffCI.pQueueFamilyIndices = &qfi;
1901
1902 VkBuffer dyub;
1903 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
1904 ASSERT_VK_SUCCESS(err);
1905 // Correctly update descriptor to avoid "NOT_UPDATED" error
1906 static const uint32_t NUM_BUFFS = 5;
1907 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
1908 for (uint32_t i=0; i<NUM_BUFFS; ++i) {
1909 buffInfo[i].buffer = dyub;
1910 buffInfo[i].offset = 0;
1911 buffInfo[i].range = 1024;
1912 }
Tobin Ehliscb085292015-12-01 09:57:09 -07001913 VkImage image;
1914 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1915 const int32_t tex_width = 32;
1916 const int32_t tex_height = 32;
1917 VkImageCreateInfo image_create_info = {};
1918 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1919 image_create_info.pNext = NULL;
1920 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1921 image_create_info.format = tex_format;
1922 image_create_info.extent.width = tex_width;
1923 image_create_info.extent.height = tex_height;
1924 image_create_info.extent.depth = 1;
1925 image_create_info.mipLevels = 1;
1926 image_create_info.arrayLayers = 1;
1927 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1928 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1929 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1930 image_create_info.flags = 0;
1931 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1932 ASSERT_VK_SUCCESS(err);
Tobin Ehlis982099b2015-11-05 09:52:49 -07001933
Tobin Ehliscb085292015-12-01 09:57:09 -07001934 VkImageViewCreateInfo image_view_create_info = {};
1935 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1936 image_view_create_info.image = image;
1937 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
1938 image_view_create_info.format = tex_format;
1939 image_view_create_info.subresourceRange.layerCount = 1;
1940 image_view_create_info.subresourceRange.baseMipLevel = 0;
1941 image_view_create_info.subresourceRange.levelCount = 1;
1942 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001943
Tobin Ehliscb085292015-12-01 09:57:09 -07001944 VkImageView view;
1945 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
1946 ASSERT_VK_SUCCESS(err);
1947 VkDescriptorImageInfo imageInfo[2] = {};
1948 imageInfo[0].imageView = view;
1949 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
1950 imageInfo[1].imageView = view;
1951 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
1952
1953 static const uint32_t NUM_SET_UPDATES = 3;
1954 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
1955 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1956 descriptor_write[0].dstSet = descriptorSet[0];
1957 descriptor_write[0].dstBinding = 0;
1958 descriptor_write[0].descriptorCount = 5;
1959 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1960 descriptor_write[0].pBufferInfo = buffInfo;
1961 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1962 descriptor_write[1].dstSet = descriptorSet[1];
1963 descriptor_write[1].dstBinding = 0;
1964 descriptor_write[1].descriptorCount = 2;
1965 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1966 descriptor_write[1].pImageInfo = imageInfo;
1967 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1968 descriptor_write[2].dstSet = descriptorSet[1];
1969 descriptor_write[2].dstBinding = 1;
1970 descriptor_write[2].descriptorCount = 2;
1971 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
1972 descriptor_write[2].pImageInfo = imageInfo;
1973
1974 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis982099b2015-11-05 09:52:49 -07001975
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07001976 // Create PSO to be used for draw-time errors below
1977 char const *vsSource =
1978 "#version 140\n"
1979 "#extension GL_ARB_separate_shader_objects: require\n"
1980 "#extension GL_ARB_shading_language_420pack: require\n"
1981 "\n"
1982 "void main(){\n"
1983 " gl_Position = vec4(1);\n"
1984 "}\n";
1985 char const *fsSource =
1986 "#version 140\n"
1987 "#extension GL_ARB_separate_shader_objects: require\n"
1988 "#extension GL_ARB_shading_language_420pack: require\n"
1989 "\n"
1990 "layout(location=0) out vec4 x;\n"
1991 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
1992 "void main(){\n"
1993 " x = vec4(bar.y);\n"
1994 "}\n";
1995 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
1996 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis982099b2015-11-05 09:52:49 -07001997 VkPipelineObj pipe(m_device);
1998 pipe.AddShader(&vs);
1999 pipe.AddShader(&fs);
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002000 pipe.AddColorAttachment();
2001 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis982099b2015-11-05 09:52:49 -07002002
2003 BeginCommandBuffer();
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002004
Tobin Ehlis982099b2015-11-05 09:52:49 -07002005 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2006 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding of PSO
2007 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of cmd_pipeline.c
2008 // due to the fact that cmd_alloc_dset_data() has not been called in cmd_bind_graphics_pipeline()
2009 // TODO : Want to cause various binding incompatibility issues here to test DrawState
2010 // First cause various verify_layout_compatibility() fails
2011 // Second disturb early and late sets and verify INFO msgs
Tobin Ehliscb085292015-12-01 09:57:09 -07002012 // verify_set_layout_compatibility fail cases:
2013 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " due to: invalid VkPipelineLayout ");
Tobin Ehliscb085292015-12-01 09:57:09 -07002015 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, (VkPipelineLayout)0xbaadb1be, 0, 1, &descriptorSet[0], 0, NULL);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002016 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehliscb085292015-12-01 09:57:09 -07002017 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSets with invalid VkPipelineLayout.";
Tobin Ehlis982099b2015-11-05 09:52:49 -07002018 m_errorMonitor->DumpFailureMsgs();
2019 }
Tobin Ehliscb085292015-12-01 09:57:09 -07002020 // 2. layoutIndex exceeds # of layouts in layout
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
Tobin Ehliscb085292015-12-01 09:57:09 -07002022 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2, &descriptorSet[0], 0, NULL);
2023 if (!m_errorMonitor->DesiredMsgFound()) {
2024 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSet to index 1 when pipelineLayout only has index 0.";
2025 m_errorMonitor->DumpFailureMsgs();
2026 }
2027 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
2028 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 descriptors
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", but corresponding set being bound has 5 descriptors.");
Tobin Ehliscb085292015-12-01 09:57:09 -07002030 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
2031 if (!m_errorMonitor->DesiredMsgFound()) {
2032 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSet w/ 5 descriptors to pipelineLayout with only 2 descriptors.";
2033 m_errorMonitor->DumpFailureMsgs();
2034 }
2035 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
2036 // 4. same # of descriptors but mismatch in type
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002037 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 -07002038 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
2039 if (!m_errorMonitor->DesiredMsgFound()) {
2040 FAIL() << "Did not receive correct error msg when attempting to bind UNIFORM_BUFFER descriptorSet to pipelineLayout with overlapping SAMPLER type.";
2041 m_errorMonitor->DumpFailureMsgs();
2042 }
2043 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
2044 // 5. same # of descriptors but mismatch in stageFlags
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " descriptor from pipelineLayout has stageFlags ");
Tobin Ehliscb085292015-12-01 09:57:09 -07002046 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
2047 if (!m_errorMonitor->DesiredMsgFound()) {
2048 FAIL() << "Did not receive correct error msg when attempting to bind UNIFORM_BUFFER descriptorSet with ALL stageFlags to pipelineLayout with FS-only stageFlags.";
2049 m_errorMonitor->DumpFailureMsgs();
2050 }
2051 // Cause INFO messages due to disturbing previously bound Sets
2052 // First bind sets 0 & 1
2053 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2054 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, " previously bound as set #0 was disturbed ");
Tobin Ehliscb085292015-12-01 09:57:09 -07002056 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
2057 if (!m_errorMonitor->DesiredMsgFound()) {
2058 FAIL() << "Did not receive correct info msg when binding Set1 w/ pipelineLayout that should disturb Set0.";
2059 m_errorMonitor->DumpFailureMsgs();
2060 }
2061 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
2062 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2063 // 2. Disturb set after last bound set
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002064 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 -07002065 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
2066 if (!m_errorMonitor->DesiredMsgFound()) {
2067 FAIL() << "Did not receive correct info msg when re-binding Set0 w/ pipelineLayout that should disturb Set1.";
2068 m_errorMonitor->DumpFailureMsgs();
2069 }
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002070
2071 // Cause draw-time errors due to PSO incompatibilities
2072 // 1. Error due to not binding required set (we actually use same code as above to disturb set0)
2073 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2074 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 -07002075 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 -07002076 Draw(1, 0, 0, 0);
2077 if (!m_errorMonitor->DesiredMsgFound()) {
2078 FAIL() << "Did not receive correct error msg when attempting draw requiring Set0 but Set0 is not bound.";
2079 m_errorMonitor->DumpFailureMsgs();
2080 }
2081 // 2. Error due to bound set not being compatible with PSO's VkPipelineLayout (diff stageFlags in this case)
2082 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002084 Draw(1, 0, 0, 0);
2085 if (!m_errorMonitor->DesiredMsgFound()) {
2086 FAIL() << "Did not receive correct error msg when attempted draw where bound Set0 layout is not compatible PSO Set0 layout.";
2087 m_errorMonitor->DumpFailureMsgs();
2088 }
Tobin Ehliscb085292015-12-01 09:57:09 -07002089 // Remaining clean-up
2090 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
2091 for (uint32_t i=0; i<NUM_LAYOUTS; ++i) {
2092 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
2093 }
2094 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
2095 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, descriptorSet);
2096 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002097 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2098 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
2099}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002100
Chia-I Wu1f851912015-10-27 18:04:07 +08002101TEST_F(VkLayerTest, NoBeginCommandBuffer)
Tobin Ehlis254eca02015-06-25 15:46:59 -06002102{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002103
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002105 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlis254eca02015-06-25 15:46:59 -06002106
2107 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +08002108 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002109 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu1f851912015-10-27 18:04:07 +08002110 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002111
2112 if (!m_errorMonitor->DesiredMsgFound()) {
2113 FAIL() << "Did not recieve Error 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
2114 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06002115 }
2116}
2117
Chia-I Wu1f851912015-10-27 18:04:07 +08002118TEST_F(VkLayerTest, PrimaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002119{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002120
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002122 "may not specify framebuffer or renderpass parameters");
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002123
2124 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002125
Chia-I Wu1f851912015-10-27 18:04:07 +08002126 // Calls AllocateCommandBuffers
2127 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002128
2129 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Chia-I Wu1f851912015-10-27 18:04:07 +08002130 VkCommandBufferBeginInfo cmd_buf_info = {};
2131 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06002132 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002133 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Cody Northrop10d8f982015-08-04 17:35:57 -06002134 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
2135 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
2136
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002137
2138 // The error should be caught by validation of the BeginCommandBuffer call
Chia-I Wu1f851912015-10-27 18:04:07 +08002139 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002140
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002141 if (!m_errorMonitor->DesiredMsgFound()) {
2142 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
2143 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002144 }
2145}
2146
Chia-I Wu1f851912015-10-27 18:04:07 +08002147TEST_F(VkLayerTest, SecondaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002148{
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002149 VkResult err;
Chia-I Wu1f851912015-10-27 18:04:07 +08002150 VkCommandBuffer draw_cmd;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002151
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002153 "must specify framebuffer and renderpass parameters");
2154
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002155 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002156
Chia-I Wu1f851912015-10-27 18:04:07 +08002157 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002158 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06002159 cmd.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002160 cmd.commandPool = m_commandPool;
2161 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Chia-I Wu763a7492015-10-26 20:48:51 +08002162 cmd.bufferCount = 1;
Cody Northrop10d8f982015-08-04 17:35:57 -06002163
Chia-I Wu1f851912015-10-27 18:04:07 +08002164 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyan2237f522015-08-18 14:40:24 -06002165 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002166
2167 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu1f851912015-10-27 18:04:07 +08002168 VkCommandBufferBeginInfo cmd_buf_info = {};
2169 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06002170 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002171 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002172
2173 // The error should be caught by validation of the BeginCommandBuffer call
2174 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
2175
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002176 if (!m_errorMonitor->DesiredMsgFound()) {
2177 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
2178 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002179 }
Chia-I Wu1f851912015-10-27 18:04:07 +08002180 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002181}
2182
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002183TEST_F(VkLayerTest, CommandBufferResetErrors)
2184{
2185 // Cause error due to Begin while recording CB
2186 // Then cause 2 errors for attempting to reset CB w/o having
2187 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
2188 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002190 "Cannot call Begin on CB");
2191
2192 ASSERT_NO_FATAL_FAILURE(InitState());
2193
2194 // Calls AllocateCommandBuffers
2195 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
2196
2197 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
2198 VkCommandBufferBeginInfo cmd_buf_info = {};
2199 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2200 cmd_buf_info.pNext = NULL;
2201 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
2202
2203 // Begin CB to transition to recording state
2204 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2205 // Can't re-begin. This should trigger error
2206 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2207 if (!m_errorMonitor->DesiredMsgFound()) {
2208 FAIL() << "Did not receive Error 'Cannot call Begin on CB (0x<ADDR>) in the RECORDING state...'";
2209 m_errorMonitor->DumpFailureMsgs();
2210 }
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002212 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
2213 // Reset attempt will trigger error due to incorrect CommandPool state
2214 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
2215 if (!m_errorMonitor->DesiredMsgFound()) {
2216 FAIL() << "Did not receive Error 'Attempt to reset command buffer (0x<ADDR>) created from command pool...'";
2217 m_errorMonitor->DumpFailureMsgs();
2218 }
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002220 // Transition CB to RECORDED state
2221 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
2222 // Now attempting to Begin will implicitly reset, which triggers error
2223 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2224 if (!m_errorMonitor->DesiredMsgFound()) {
2225 FAIL() << "Did not receive Error 'Call to vkBeginCommandBuffer() on command buffer (0x<ADDR>) attempts to implicitly reset...'";
2226 m_errorMonitor->DumpFailureMsgs();
2227 }
2228}
2229
Tobin Ehlis254eca02015-06-25 15:46:59 -06002230TEST_F(VkLayerTest, InvalidPipelineCreateState)
2231{
2232 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis254eca02015-06-25 15:46:59 -06002233 VkResult err;
2234
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002236 "Invalid Pipeline CreateInfo State: Vtx Shader required");
2237
Tobin Ehlis254eca02015-06-25 15:46:59 -06002238 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002240
Chia-I Wuc51b1212015-10-27 19:25:11 +08002241 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002242 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002243 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002244
2245 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2246 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2247 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002248 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002249 ds_pool_ci.poolSizeCount = 1;
2250 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002251
Tobin Ehlis254eca02015-06-25 15:46:59 -06002252 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002253 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002254 ASSERT_VK_SUCCESS(err);
2255
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002256 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002257 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002258 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002259 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002260 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2261 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002262
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002263 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2264 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2265 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002266 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002267 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002268
Tobin Ehlis254eca02015-06-25 15:46:59 -06002269 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002270 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002271 ASSERT_VK_SUCCESS(err);
2272
2273 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002274 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002275 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002276 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002277 alloc_info.descriptorPool = ds_pool;
2278 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002279 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002280 ASSERT_VK_SUCCESS(err);
2281
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002282 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2283 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002284 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002285 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002286
2287 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002288 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002289 ASSERT_VK_SUCCESS(err);
2290
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002291 VkViewport vp = {}; // Just need dummy vp to point to
2292 VkRect2D sc = {}; // dummy scissor to point to
2293
2294 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2295 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2296 vp_state_ci.scissorCount = 1;
2297 vp_state_ci.pScissors = &sc;
2298 vp_state_ci.viewportCount = 1;
2299 vp_state_ci.pViewports = &vp;
2300
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002301 VkGraphicsPipelineCreateInfo gp_ci = {};
2302 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002303 gp_ci.pViewportState = &vp_state_ci;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002304 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2305 gp_ci.layout = pipeline_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002306 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002307
2308 VkPipelineCacheCreateInfo pc_ci = {};
2309 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Chia-I Wu7e470702015-10-26 17:24:52 +08002310 pc_ci.initialDataSize = 0;
2311 pc_ci.pInitialData = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002312
2313 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06002314 VkPipelineCache pipelineCache;
2315
Chia-I Wu69f40122015-10-26 21:10:41 +08002316 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06002317 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002318 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002319
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002320 if (!m_errorMonitor->DesiredMsgFound()) {
2321 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
2322 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06002323 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002324
Chia-I Wu69f40122015-10-26 21:10:41 +08002325 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2326 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2327 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2328 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002329}
Tobin Ehlis20693172015-09-17 08:46:18 -06002330/*// TODO : This test should be good, but needs Tess support in compiler to run
2331TEST_F(VkLayerTest, InvalidPatchControlPoints)
2332{
2333 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis20693172015-09-17 08:46:18 -06002334 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002335
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002337 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ");
2338
Tobin Ehlis20693172015-09-17 08:46:18 -06002339 ASSERT_NO_FATAL_FAILURE(InitState());
2340 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis20693172015-09-17 08:46:18 -06002341
Chia-I Wuc51b1212015-10-27 19:25:11 +08002342 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis20693172015-09-17 08:46:18 -06002343 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002344 ds_type_count.descriptorCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002345
2346 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2347 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2348 ds_pool_ci.pNext = NULL;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002349 ds_pool_ci.poolSizeCount = 1;
2350 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis20693172015-09-17 08:46:18 -06002351
2352 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002353 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 -06002354 ASSERT_VK_SUCCESS(err);
2355
2356 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002357 dsl_binding.binding = 0;
Tobin Ehlis20693172015-09-17 08:46:18 -06002358 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002359 dsl_binding.descriptorCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002360 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2361 dsl_binding.pImmutableSamplers = NULL;
2362
2363 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2364 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2365 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002366 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002367 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis20693172015-09-17 08:46:18 -06002368
2369 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002370 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis20693172015-09-17 08:46:18 -06002371 ASSERT_VK_SUCCESS(err);
2372
2373 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002374 err = vkAllocateDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis20693172015-09-17 08:46:18 -06002375 ASSERT_VK_SUCCESS(err);
2376
2377 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2378 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2379 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002380 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002381 pipeline_layout_ci.pSetLayouts = &ds_layout;
2382
2383 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002384 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis20693172015-09-17 08:46:18 -06002385 ASSERT_VK_SUCCESS(err);
2386
2387 VkPipelineShaderStageCreateInfo shaderStages[3];
2388 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
2389
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002390 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06002391 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002392 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
2393 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06002394
2395 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002396 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002397 shaderStages[0].shader = vs.handle();
2398 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002399 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002400 shaderStages[1].shader = tc.handle();
2401 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002402 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002403 shaderStages[2].shader = te.handle();
2404
2405 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
2406 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08002407 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis20693172015-09-17 08:46:18 -06002408
2409 VkPipelineTessellationStateCreateInfo tsCI = {};
2410 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
2411 tsCI.patchControlPoints = 0; // This will cause an error
2412
2413 VkGraphicsPipelineCreateInfo gp_ci = {};
2414 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2415 gp_ci.pNext = NULL;
2416 gp_ci.stageCount = 3;
2417 gp_ci.pStages = shaderStages;
2418 gp_ci.pVertexInputState = NULL;
2419 gp_ci.pInputAssemblyState = &iaCI;
2420 gp_ci.pTessellationState = &tsCI;
2421 gp_ci.pViewportState = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002422 gp_ci.pRasterizationState = NULL;
Tobin Ehlis20693172015-09-17 08:46:18 -06002423 gp_ci.pMultisampleState = NULL;
2424 gp_ci.pDepthStencilState = NULL;
2425 gp_ci.pColorBlendState = NULL;
2426 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2427 gp_ci.layout = pipeline_layout;
2428 gp_ci.renderPass = renderPass();
2429
2430 VkPipelineCacheCreateInfo pc_ci = {};
2431 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2432 pc_ci.pNext = NULL;
2433 pc_ci.initialSize = 0;
2434 pc_ci.initialData = 0;
2435 pc_ci.maxSize = 0;
2436
2437 VkPipeline pipeline;
2438 VkPipelineCache pipelineCache;
2439
Chia-I Wu69f40122015-10-26 21:10:41 +08002440 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis20693172015-09-17 08:46:18 -06002441 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002442 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis20693172015-09-17 08:46:18 -06002443
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002444 if (!m_errorMonitor->DesiredMsgFound()) {
2445 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...'";
2446 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis20693172015-09-17 08:46:18 -06002447 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002448
Chia-I Wu69f40122015-10-26 21:10:41 +08002449 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2450 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2451 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2452 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis20693172015-09-17 08:46:18 -06002453}
2454*/
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002455// Set scissor and viewport counts to different numbers
2456TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
2457{
2458 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002459 VkResult err;
2460
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002462 "Gfx Pipeline viewport count (1) must match scissor count (0).");
2463
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002464 ASSERT_NO_FATAL_FAILURE(InitState());
2465 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002466
Chia-I Wuc51b1212015-10-27 19:25:11 +08002467 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002468 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002469 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002470
2471 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2472 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002473 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002474 ds_pool_ci.poolSizeCount = 1;
2475 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002476
2477 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002478 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002479 ASSERT_VK_SUCCESS(err);
2480
2481 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002482 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002483 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002484 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002485 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2486
2487 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2488 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002489 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002490 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002491
2492 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002493 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002494 ASSERT_VK_SUCCESS(err);
2495
2496 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002497 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002498 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002499 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002500 alloc_info.descriptorPool = ds_pool;
2501 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002502 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002503 ASSERT_VK_SUCCESS(err);
2504
2505 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2506 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002507 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002508 pipeline_layout_ci.pSetLayouts = &ds_layout;
2509
2510 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002511 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002512 ASSERT_VK_SUCCESS(err);
2513
2514 VkViewport vp = {}; // Just need dummy vp to point to
2515
2516 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2517 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2518 vp_state_ci.scissorCount = 0;
2519 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2520 vp_state_ci.pViewports = &vp;
2521
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002522 VkPipelineShaderStageCreateInfo shaderStages[2];
2523 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002524
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002525 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2526 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 -06002527 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002528 shaderStages[0] = vs.GetStageCreateInfo();
2529 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002530
2531 VkGraphicsPipelineCreateInfo gp_ci = {};
2532 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002533 gp_ci.stageCount = 2;
2534 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002535 gp_ci.pViewportState = &vp_state_ci;
2536 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2537 gp_ci.layout = pipeline_layout;
2538 gp_ci.renderPass = renderPass();
2539
2540 VkPipelineCacheCreateInfo pc_ci = {};
2541 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2542
2543 VkPipeline pipeline;
2544 VkPipelineCache pipelineCache;
2545
Chia-I Wu69f40122015-10-26 21:10:41 +08002546 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002547 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002548 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002549
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002550 if (!m_errorMonitor->DesiredMsgFound()) {
2551 FAIL() << "Did not receive Error 'Gfx Pipeline viewport count (1) must match scissor count (0).'";
2552 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002553 }
2554
Chia-I Wu69f40122015-10-26 21:10:41 +08002555 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2556 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2557 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2558 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002559}
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002560// Don't set viewport state in PSO. This is an error b/c we always need this state
2561// for the counts even if the data is going to be set dynamically.
2562TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002563{
2564 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002565 VkResult err;
2566
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002568 "Gfx Pipeline pViewportState is null. Even if ");
2569
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002570 ASSERT_NO_FATAL_FAILURE(InitState());
2571 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002572
Chia-I Wuc51b1212015-10-27 19:25:11 +08002573 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002574 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002575 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002576
2577 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2578 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002579 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002580 ds_pool_ci.poolSizeCount = 1;
2581 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002582
2583 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002584 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002585 ASSERT_VK_SUCCESS(err);
2586
2587 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002588 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002589 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002590 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002591 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2592
2593 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2594 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002595 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002596 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002597
2598 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002599 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002600 ASSERT_VK_SUCCESS(err);
2601
2602 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002603 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002604 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002605 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002606 alloc_info.descriptorPool = ds_pool;
2607 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002608 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002609 ASSERT_VK_SUCCESS(err);
2610
2611 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2612 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002613 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002614 pipeline_layout_ci.pSetLayouts = &ds_layout;
2615
2616 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002617 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002618 ASSERT_VK_SUCCESS(err);
2619
2620 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2621 // Set scissor as dynamic to avoid second error
2622 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2623 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2624 dyn_state_ci.dynamicStateCount = 1;
2625 dyn_state_ci.pDynamicStates = &sc_state;
2626
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002627 VkPipelineShaderStageCreateInfo shaderStages[2];
2628 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002629
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002630 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2631 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 -06002632 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002633 shaderStages[0] = vs.GetStageCreateInfo();
2634 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002635
2636 VkGraphicsPipelineCreateInfo gp_ci = {};
2637 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002638 gp_ci.stageCount = 2;
2639 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002640 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2641 gp_ci.pDynamicState = &dyn_state_ci;
2642 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2643 gp_ci.layout = pipeline_layout;
2644 gp_ci.renderPass = renderPass();
2645
2646 VkPipelineCacheCreateInfo pc_ci = {};
2647 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2648
2649 VkPipeline pipeline;
2650 VkPipelineCache pipelineCache;
2651
Chia-I Wu69f40122015-10-26 21:10:41 +08002652 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002653 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002654 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002655
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002656 if (!m_errorMonitor->DesiredMsgFound()) {
2657 FAIL() << "Did not receive Error 'Gfx Pipeline pViewportState is null. Even if...'";
2658 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002659 }
2660
Chia-I Wu69f40122015-10-26 21:10:41 +08002661 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2662 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2663 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2664 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002665}
2666// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002667// Then run second test where dynamic scissor count doesn't match PSO scissor count
2668TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002669{
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002670 VkResult err;
2671
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002673 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
2674
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002675 ASSERT_NO_FATAL_FAILURE(InitState());
2676 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002677
Chia-I Wuc51b1212015-10-27 19:25:11 +08002678 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002679 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002680 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002681
2682 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2683 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002684 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002685 ds_pool_ci.poolSizeCount = 1;
2686 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002687
2688 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002689 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002690 ASSERT_VK_SUCCESS(err);
2691
2692 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002693 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002694 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002695 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002696 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2697
2698 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2699 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002700 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002701 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002702
2703 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002704 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002705 ASSERT_VK_SUCCESS(err);
2706
2707 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002708 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002709 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002710 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002711 alloc_info.descriptorPool = ds_pool;
2712 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002713 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002714 ASSERT_VK_SUCCESS(err);
2715
2716 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2717 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002718 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002719 pipeline_layout_ci.pSetLayouts = &ds_layout;
2720
2721 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002722 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002723 ASSERT_VK_SUCCESS(err);
2724
2725 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2726 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2727 vp_state_ci.viewportCount = 1;
2728 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2729 vp_state_ci.scissorCount = 1;
2730 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2731
2732 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2733 // Set scissor as dynamic to avoid that error
2734 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2735 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2736 dyn_state_ci.dynamicStateCount = 1;
2737 dyn_state_ci.pDynamicStates = &sc_state;
2738
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002739 VkPipelineShaderStageCreateInfo shaderStages[2];
2740 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002741
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002742 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2743 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 -06002744 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002745 shaderStages[0] = vs.GetStageCreateInfo();
2746 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002747
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002748 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2749 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2750 vi_ci.pNext = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002751 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002752 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002753 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002754 vi_ci.pVertexAttributeDescriptions = nullptr;
2755
2756 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2757 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2758 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2759
Chia-I Wu1f851912015-10-27 18:04:07 +08002760 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +08002761 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002762 rs_ci.pNext = nullptr;
2763
2764 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2765 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2766 cb_ci.pNext = nullptr;
2767
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002768 VkGraphicsPipelineCreateInfo gp_ci = {};
2769 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002770 gp_ci.stageCount = 2;
2771 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002772 gp_ci.pVertexInputState = &vi_ci;
2773 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002774 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu1f851912015-10-27 18:04:07 +08002775 gp_ci.pRasterizationState = &rs_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002776 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002777 gp_ci.pDynamicState = &dyn_state_ci;
2778 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2779 gp_ci.layout = pipeline_layout;
2780 gp_ci.renderPass = renderPass();
2781
2782 VkPipelineCacheCreateInfo pc_ci = {};
2783 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2784
2785 VkPipeline pipeline;
2786 VkPipelineCache pipelineCache;
2787
Chia-I Wu69f40122015-10-26 21:10:41 +08002788 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002789 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002790 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002791
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002792 if (!m_errorMonitor->DesiredMsgFound()) {
2793 FAIL() << "Did not recieve Error 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...'";
2794 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002795 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002796
2797
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002798 // Now hit second fail case where we set scissor w/ different count than PSO
2799 // First need to successfully create the PSO from above by setting pViewports
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002801 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.");
2802
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002803 VkViewport vp = {}; // Just need dummy vp to point to
2804 vp_state_ci.pViewports = &vp;
Chia-I Wu69f40122015-10-26 21:10:41 +08002805 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002806 ASSERT_VK_SUCCESS(err);
2807 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08002808 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002809 VkRect2D scissors[2] = {}; // don't care about data
2810 // Count of 2 doesn't match PSO count of 1
Chia-I Wu1f851912015-10-27 18:04:07 +08002811 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 2, scissors);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002812 Draw(1, 0, 0, 0);
2813
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002814 if (!m_errorMonitor->DesiredMsgFound()) {
2815 FAIL() << "Did not receive Error 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...'";
2816 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002817 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002818
Chia-I Wu69f40122015-10-26 21:10:41 +08002819 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2820 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2821 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2822 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002823}
2824// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002825// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2826TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002827{
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002828 VkResult err;
2829
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002831 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
2832
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002833 ASSERT_NO_FATAL_FAILURE(InitState());
2834 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002835
Chia-I Wuc51b1212015-10-27 19:25:11 +08002836 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002837 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002838 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002839
2840 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2841 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002842 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002843 ds_pool_ci.poolSizeCount = 1;
2844 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002845
2846 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002847 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002848 ASSERT_VK_SUCCESS(err);
2849
2850 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002851 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002852 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002853 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002854 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2855
2856 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2857 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002858 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002859 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002860
2861 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002862 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002863 ASSERT_VK_SUCCESS(err);
2864
2865 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002866 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002867 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002868 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002869 alloc_info.descriptorPool = ds_pool;
2870 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002871 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002872 ASSERT_VK_SUCCESS(err);
2873
2874 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2875 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002876 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002877 pipeline_layout_ci.pSetLayouts = &ds_layout;
2878
2879 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002880 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002881 ASSERT_VK_SUCCESS(err);
2882
2883 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2884 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2885 vp_state_ci.scissorCount = 1;
2886 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2887 vp_state_ci.viewportCount = 1;
2888 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2889
2890 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2891 // Set scissor as dynamic to avoid that error
2892 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2893 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2894 dyn_state_ci.dynamicStateCount = 1;
2895 dyn_state_ci.pDynamicStates = &vp_state;
2896
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002897 VkPipelineShaderStageCreateInfo shaderStages[2];
2898 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002899
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002900 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2901 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 -06002902 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002903 shaderStages[0] = vs.GetStageCreateInfo();
2904 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002905
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002906 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2907 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2908 vi_ci.pNext = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002909 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002910 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002911 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002912 vi_ci.pVertexAttributeDescriptions = nullptr;
2913
2914 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2915 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2916 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2917
Chia-I Wu1f851912015-10-27 18:04:07 +08002918 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +08002919 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002920 rs_ci.pNext = nullptr;
2921
2922 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2923 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2924 cb_ci.pNext = nullptr;
2925
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002926 VkGraphicsPipelineCreateInfo gp_ci = {};
2927 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002928 gp_ci.stageCount = 2;
2929 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002930 gp_ci.pVertexInputState = &vi_ci;
2931 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002932 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu1f851912015-10-27 18:04:07 +08002933 gp_ci.pRasterizationState = &rs_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002934 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002935 gp_ci.pDynamicState = &dyn_state_ci;
2936 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2937 gp_ci.layout = pipeline_layout;
2938 gp_ci.renderPass = renderPass();
2939
2940 VkPipelineCacheCreateInfo pc_ci = {};
2941 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2942
2943 VkPipeline pipeline;
2944 VkPipelineCache pipelineCache;
2945
Chia-I Wu69f40122015-10-26 21:10:41 +08002946 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002947 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002948 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002949
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002950 if (!m_errorMonitor->DesiredMsgFound()) {
2951 FAIL() << "Did not recieve Error 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...'";
2952 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002953 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002954
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002955 // Now hit second fail case where we set scissor w/ different count than PSO
2956 // First need to successfully create the PSO from above by setting pViewports
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002958 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.");
2959
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002960 VkRect2D sc = {}; // Just need dummy vp to point to
2961 vp_state_ci.pScissors = &sc;
Chia-I Wu69f40122015-10-26 21:10:41 +08002962 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002963 ASSERT_VK_SUCCESS(err);
2964 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08002965 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002966 VkViewport viewports[2] = {}; // don't care about data
2967 // Count of 2 doesn't match PSO count of 1
Chia-I Wu1f851912015-10-27 18:04:07 +08002968 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 2, viewports);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002969 Draw(1, 0, 0, 0);
2970
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002971 if (!m_errorMonitor->DesiredMsgFound()) {
2972 FAIL() << "Did not receive Error 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...'";
2973 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002974 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002975
Chia-I Wu69f40122015-10-26 21:10:41 +08002976 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2977 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2978 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2979 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002980}
2981
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002982TEST_F(VkLayerTest, NullRenderPass)
2983{
2984 // Bind a NULL RenderPass
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002986 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002987
2988 ASSERT_NO_FATAL_FAILURE(InitState());
2989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002990
Tony Barbour1490c912015-07-28 10:17:20 -06002991 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002992 // Don't care about RenderPass handle b/c error should be flagged before that
Chia-I Wuc51b1212015-10-27 19:25:11 +08002993 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002994
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002995 if (!m_errorMonitor->DesiredMsgFound()) {
2996 FAIL() << "Did not receive Error 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
2997 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002998 }
2999}
3000
Tobin Ehlis254eca02015-06-25 15:46:59 -06003001TEST_F(VkLayerTest, RenderPassWithinRenderPass)
3002{
3003 // Bind a BeginRenderPass within an active RenderPass
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003005 "It is invalid to issue this call inside an active render pass");
Tobin Ehlis254eca02015-06-25 15:46:59 -06003006
3007 ASSERT_NO_FATAL_FAILURE(InitState());
3008 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis254eca02015-06-25 15:46:59 -06003009
Tony Barbour1490c912015-07-28 10:17:20 -06003010 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003011 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003012 VkRenderPassBeginInfo rp_begin = {};
3013 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
3014 rp_begin.pNext = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003015 rp_begin.renderPass = renderPass();
3016 rp_begin.framebuffer = framebuffer();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003017
Chia-I Wuc51b1212015-10-27 19:25:11 +08003018 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06003019
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003020 if (!m_errorMonitor->DesiredMsgFound()) {
3021 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3022 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06003023 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003024}
3025
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003026TEST_F(VkLayerTest, FillBufferWithinRenderPass)
3027{
3028 // Call CmdFillBuffer within an active renderpass
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003030 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003031
3032 ASSERT_NO_FATAL_FAILURE(InitState());
3033 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003034
3035 // Renderpass is started here
3036 BeginCommandBuffer();
3037
3038 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08003039 vk_testing::Buffer dstBuffer;
3040 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003041
Chia-I Wu1f851912015-10-27 18:04:07 +08003042 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003043
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003044 if (!m_errorMonitor->DesiredMsgFound()) {
3045 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3046 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003047 }
3048}
3049
3050TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
3051{
3052 // Call CmdUpdateBuffer within an active renderpass
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003054 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003055
3056 ASSERT_NO_FATAL_FAILURE(InitState());
3057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003058
3059 // Renderpass is started here
3060 BeginCommandBuffer();
3061
3062 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08003063 vk_testing::Buffer dstBuffer;
3064 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003065
Chia-I Wu1f851912015-10-27 18:04:07 +08003066 VkDeviceSize dstOffset = 0;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003067 VkDeviceSize dataSize = 1024;
3068 const uint32_t *pData = NULL;
3069
Chia-I Wu1f851912015-10-27 18:04:07 +08003070 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003071
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003072 if (!m_errorMonitor->DesiredMsgFound()) {
3073 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3074 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003075 }
3076}
3077
3078TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
3079{
3080 // Call CmdClearColorImage within an active RenderPass
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003082 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003083
3084 ASSERT_NO_FATAL_FAILURE(InitState());
3085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003086
3087 // Renderpass is started here
3088 BeginCommandBuffer();
3089
3090 VkClearColorValue clear_color = {0};
3091 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3092 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3093 const int32_t tex_width = 32;
3094 const int32_t tex_height = 32;
3095 VkImageCreateInfo image_create_info = {};
3096 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3097 image_create_info.pNext = NULL;
3098 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3099 image_create_info.format = tex_format;
3100 image_create_info.extent.width = tex_width;
3101 image_create_info.extent.height = tex_height;
3102 image_create_info.extent.depth = 1;
3103 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06003104 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08003105 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003106 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3107 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3108
Chia-I Wu1f851912015-10-27 18:04:07 +08003109 vk_testing::Image dstImage;
3110 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003111
3112 const VkImageSubresourceRange range =
3113 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
3114
Chia-I Wu1f851912015-10-27 18:04:07 +08003115 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(),
3116 dstImage.handle(),
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003117 VK_IMAGE_LAYOUT_GENERAL,
3118 &clear_color,
3119 1,
3120 &range);
3121
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003122 if (!m_errorMonitor->DesiredMsgFound()) {
3123 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3124 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003125 }
3126}
3127
3128TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
3129{
3130 // Call CmdClearDepthStencilImage within an active RenderPass
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003132 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003133
3134 ASSERT_NO_FATAL_FAILURE(InitState());
3135 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003136
3137 // Renderpass is started here
3138 BeginCommandBuffer();
3139
3140 VkClearDepthStencilValue clear_value = {0};
3141 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3142 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
3143 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3144 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
3145 image_create_info.extent.width = 64;
3146 image_create_info.extent.height = 64;
3147 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3148 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
3149
Chia-I Wu1f851912015-10-27 18:04:07 +08003150 vk_testing::Image dstImage;
3151 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003152
3153 const VkImageSubresourceRange range =
3154 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
3155
Chia-I Wu1f851912015-10-27 18:04:07 +08003156 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(),
3157 dstImage.handle(),
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003158 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
3159 &clear_value,
3160 1,
3161 &range);
3162
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003163 if (!m_errorMonitor->DesiredMsgFound()) {
3164 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3165 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003166 }
3167}
3168
3169TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
3170{
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003171 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003172 VkResult err;
3173
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003175 "vkCmdClearAttachments: This call must be issued inside an active render pass");
3176
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003177 ASSERT_NO_FATAL_FAILURE(InitState());
3178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003179
3180 // Start no RenderPass
Chia-I Wu1f851912015-10-27 18:04:07 +08003181 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003182 ASSERT_VK_SUCCESS(err);
3183
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003184 VkClearAttachment color_attachment;
3185 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3186 color_attachment.clearValue.color.float32[0] = 0;
3187 color_attachment.clearValue.color.float32[1] = 0;
3188 color_attachment.clearValue.color.float32[2] = 0;
3189 color_attachment.clearValue.color.float32[3] = 0;
3190 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06003191 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Chia-I Wu1f851912015-10-27 18:04:07 +08003192 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(),
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003193 1, &color_attachment,
3194 1, &clear_rect);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003195
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003196 if (!m_errorMonitor->DesiredMsgFound()) {
3197 FAIL() << "Did not receive Error 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
3198 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003199 }
3200}
3201
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003202TEST_F(VkLayerTest, InvalidDynamicStateObject)
3203{
3204 // Create a valid cmd buffer
3205 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06003206 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
3207 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003208}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06003209
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003210TEST_F(VkLayerTest, IdxBufferAlignmentError)
3211{
3212 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003213 VkResult err;
3214
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003216 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
3217
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003218 ASSERT_NO_FATAL_FAILURE(InitState());
3219 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003220 uint32_t qfi = 0;
3221 VkBufferCreateInfo buffCI = {};
3222 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3223 buffCI.size = 1024;
3224 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
Chia-I Wu763a7492015-10-26 20:48:51 +08003225 buffCI.queueFamilyIndexCount = 1;
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003226 buffCI.pQueueFamilyIndices = &qfi;
3227
3228 VkBuffer ib;
Chia-I Wu69f40122015-10-26 21:10:41 +08003229 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003230 ASSERT_VK_SUCCESS(err);
3231
3232 BeginCommandBuffer();
3233 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08003234 //vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003235 // Should error before calling to driver so don't care about actual data
Chia-I Wu1f851912015-10-27 18:04:07 +08003236 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003237
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003238 if (!m_errorMonitor->DesiredMsgFound()) {
3239 FAIL() << "Did not receive Error 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...'";
3240 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003241 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003242
Chia-I Wu69f40122015-10-26 21:10:41 +08003243 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003244}
3245
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003246TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
3247{
3248 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003249
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003251 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003252
3253 ASSERT_NO_FATAL_FAILURE(InitState());
3254 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003255
3256 BeginCommandBuffer();
3257 //ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08003258 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
3259 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003260
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003261 if (!m_errorMonitor->DesiredMsgFound()) {
3262 FAIL() << "Did not receive Error 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer '";
3263 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003264 }
3265}
3266
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003267TEST_F(VkLayerTest, DSTypeMismatch)
3268{
3269 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003270 VkResult err;
3271
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003273 "Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match ");
3274
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003275 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003276 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003277 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003278 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003279 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003280
3281 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3282 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3283 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003284 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003285 ds_pool_ci.poolSizeCount = 1;
3286 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003287
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003288 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003289 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003290 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003291 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003292 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003293 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003294 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003295 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3296 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003297
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003298 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3299 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3300 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003301 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003302 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003303
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003304 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003305 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003306 ASSERT_VK_SUCCESS(err);
3307
3308 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003309 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003310 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003311 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003312 alloc_info.descriptorPool = ds_pool;
3313 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003314 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003315 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003316
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003317 VkSamplerCreateInfo sampler_ci = {};
3318 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3319 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003320 sampler_ci.magFilter = VK_FILTER_NEAREST;
3321 sampler_ci.minFilter = VK_FILTER_NEAREST;
3322 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003323 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3324 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3325 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003326 sampler_ci.mipLodBias = 1.0;
Jon Ashburn0717ed52015-12-14 14:59:20 -07003327 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003328 sampler_ci.maxAnisotropy = 1;
3329 sampler_ci.compareEnable = VK_FALSE;
3330 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3331 sampler_ci.minLod = 1.0;
3332 sampler_ci.maxLod = 1.0;
3333 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003334 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3335
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003336 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003337 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003338 ASSERT_VK_SUCCESS(err);
3339
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003340 VkDescriptorImageInfo info = {};
3341 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003342
3343 VkWriteDescriptorSet descriptor_write;
3344 memset(&descriptor_write, 0, sizeof(descriptor_write));
3345 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003346 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08003347 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003348 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003349 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003350 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003351
3352 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3353
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003354 if (!m_errorMonitor->DesiredMsgFound()) {
3355 FAIL() << "Did not receive Error 'Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...'";
3356 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003357 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003358
Chia-I Wu69f40122015-10-26 21:10:41 +08003359 vkDestroySampler(m_device->device(), sampler, NULL);
3360 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3361 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003362}
3363
3364TEST_F(VkLayerTest, DSUpdateOutOfBounds)
3365{
3366 // For overlapping Update, have arrayIndex exceed that of layout
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003367 VkResult err;
3368
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003370 "Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding");
3371
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003372 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003373 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003374 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003375 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003376 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003377
3378 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3379 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3380 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003381 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003382 ds_pool_ci.poolSizeCount = 1;
3383 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003384
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003385 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003386 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003387 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003388
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003389 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003390 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003391 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003392 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003393 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3394 dsl_binding.pImmutableSamplers = NULL;
3395
3396 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3397 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3398 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003399 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003400 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003401
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003402 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003403 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003404 ASSERT_VK_SUCCESS(err);
3405
3406 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003407 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003408 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003409 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003410 alloc_info.descriptorPool = ds_pool;
3411 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003412 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003413 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003414
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003415 VkSamplerCreateInfo sampler_ci = {};
3416 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3417 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003418 sampler_ci.magFilter = VK_FILTER_NEAREST;
3419 sampler_ci.minFilter = VK_FILTER_NEAREST;
3420 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003421 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3422 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3423 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003424 sampler_ci.mipLodBias = 1.0;
Jon Ashburn0717ed52015-12-14 14:59:20 -07003425 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003426 sampler_ci.maxAnisotropy = 1;
3427 sampler_ci.compareEnable = VK_FALSE;
3428 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3429 sampler_ci.minLod = 1.0;
3430 sampler_ci.maxLod = 1.0;
3431 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003432 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003433
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003434 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003435 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003436 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003437
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003438 VkDescriptorImageInfo info = {};
3439 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003440
3441 VkWriteDescriptorSet descriptor_write;
3442 memset(&descriptor_write, 0, sizeof(descriptor_write));
3443 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003444 descriptor_write.dstSet = descriptorSet;
3445 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wu763a7492015-10-26 20:48:51 +08003446 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003447 // This is the wrong type, but out of bounds will be flagged first
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 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
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, InvalidDSUpdateIndex)
3464{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003465 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
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 " does not have binding to match update 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;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -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;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003500 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003501 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003502 ASSERT_VK_SUCCESS(err);
3503
3504 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003505 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003506 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003507 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003508 alloc_info.descriptorPool = ds_pool;
3509 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003510 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003511 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003512
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003513 VkSamplerCreateInfo sampler_ci = {};
3514 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3515 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003516 sampler_ci.magFilter = VK_FILTER_NEAREST;
3517 sampler_ci.minFilter = VK_FILTER_NEAREST;
3518 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003519 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3520 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3521 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003522 sampler_ci.mipLodBias = 1.0;
Jon Ashburn0717ed52015-12-14 14:59:20 -07003523 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003524 sampler_ci.maxAnisotropy = 1;
3525 sampler_ci.compareEnable = VK_FALSE;
3526 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3527 sampler_ci.minLod = 1.0;
3528 sampler_ci.maxLod = 1.0;
3529 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003530 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003531
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003532 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003533 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003534 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003535
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003536 VkDescriptorImageInfo info = {};
3537 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003538
3539 VkWriteDescriptorSet descriptor_write;
3540 memset(&descriptor_write, 0, sizeof(descriptor_write));
3541 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003542 descriptor_write.dstSet = descriptorSet;
3543 descriptor_write.dstBinding = 2;
Chia-I Wu763a7492015-10-26 20:48:51 +08003544 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003545 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003546 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003547 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003548
3549 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3550
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003551 if (!m_errorMonitor->DesiredMsgFound()) {
3552 FAIL() << "Did not receive Error 'Descriptor Set <blah> does not have binding to match update binding '";
3553 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003554 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003555
Chia-I Wu69f40122015-10-26 21:10:41 +08003556 vkDestroySampler(m_device->device(), sampler, NULL);
3557 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3558 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003559}
3560
3561TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3562{
3563 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003564 VkResult err;
3565
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003567 "Unexpected UPDATE struct of type ");
3568
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003569 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003570
Chia-I Wuc51b1212015-10-27 19:25:11 +08003571 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003572 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003573 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003574
3575 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3576 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3577 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003578 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003579 ds_pool_ci.poolSizeCount = 1;
3580 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003581
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003582 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003583 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003584 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003585 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003586 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003587 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003588 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003589 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3590 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003591
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003592 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3593 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3594 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003595 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003596 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003597
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003598 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003599 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003600 ASSERT_VK_SUCCESS(err);
3601
3602 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003603 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003604 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003605 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003606 alloc_info.descriptorPool = ds_pool;
3607 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003608 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003609 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003610
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003611 VkSamplerCreateInfo sampler_ci = {};
3612 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3613 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003614 sampler_ci.magFilter = VK_FILTER_NEAREST;
3615 sampler_ci.minFilter = VK_FILTER_NEAREST;
3616 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003617 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3618 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3619 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003620 sampler_ci.mipLodBias = 1.0;
Jon Ashburn0717ed52015-12-14 14:59:20 -07003621 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003622 sampler_ci.maxAnisotropy = 1;
3623 sampler_ci.compareEnable = VK_FALSE;
3624 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3625 sampler_ci.minLod = 1.0;
3626 sampler_ci.maxLod = 1.0;
3627 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003628 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003629 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003630 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003631 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003632
3633
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003634 VkDescriptorImageInfo info = {};
3635 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003636
3637 VkWriteDescriptorSet descriptor_write;
3638 memset(&descriptor_write, 0, sizeof(descriptor_write));
3639 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu1f851912015-10-27 18:04:07 +08003640 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08003641 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003642 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003643 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003644 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003645
3646 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3647
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003648 if (!m_errorMonitor->DesiredMsgFound()) {
3649 FAIL() << "Did not receive Error 'Unexpected UPDATE struct of type '";
3650 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003651 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003652
Chia-I Wu69f40122015-10-26 21:10:41 +08003653 vkDestroySampler(m_device->device(), sampler, NULL);
3654 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3655 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003656}
3657
Tobin Ehlisb46be812015-10-23 16:00:08 -06003658TEST_F(VkLayerTest, SampleDescriptorUpdateError)
3659{
3660 // Create a single Sampler descriptor and send it an invalid Sampler
Tobin Ehlisb46be812015-10-23 16:00:08 -06003661 VkResult err;
3662
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003664 "Attempt to update descriptor with invalid sampler 0xbaadbeef");
3665
Tobin Ehlisb46be812015-10-23 16:00:08 -06003666 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb46be812015-10-23 16:00:08 -06003667 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied code
Chia-I Wuc51b1212015-10-27 19:25:11 +08003668 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003669 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003670 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003671
3672 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3673 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3674 ds_pool_ci.pNext = NULL;
3675 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003676 ds_pool_ci.poolSizeCount = 1;
3677 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003678
3679 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003680 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003681 ASSERT_VK_SUCCESS(err);
3682
3683 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003684 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003685 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003686 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003687 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3688 dsl_binding.pImmutableSamplers = NULL;
3689
3690 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3691 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3692 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003693 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003694 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003695 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003696 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003697 ASSERT_VK_SUCCESS(err);
3698
3699 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003700 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003701 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003702 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003703 alloc_info.descriptorPool = ds_pool;
3704 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003705 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003706 ASSERT_VK_SUCCESS(err);
3707
Chia-I Wue420a332015-10-26 20:04:44 +08003708 VkSampler sampler = (VkSampler) 0xbaadbeef; // Sampler with invalid handle
Tobin Ehlisb46be812015-10-23 16:00:08 -06003709
3710 VkDescriptorImageInfo descriptor_info;
3711 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3712 descriptor_info.sampler = sampler;
3713
3714 VkWriteDescriptorSet descriptor_write;
3715 memset(&descriptor_write, 0, sizeof(descriptor_write));
3716 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003717 descriptor_write.dstSet = descriptorSet;
3718 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003719 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003720 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3721 descriptor_write.pImageInfo = &descriptor_info;
3722
3723 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3724
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003725 if (!m_errorMonitor->DesiredMsgFound()) {
3726 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid sampler...'";
3727 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06003728 }
3729
Chia-I Wu69f40122015-10-26 21:10:41 +08003730 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3731 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003732}
3733
3734TEST_F(VkLayerTest, ImageViewDescriptorUpdateError)
3735{
3736 // Create a single combined Image/Sampler descriptor and send it an invalid imageView
Tobin Ehlisb46be812015-10-23 16:00:08 -06003737 VkResult err;
3738
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003740 "Attempt to update descriptor with invalid imageView 0xbaadbeef");
3741
Tobin Ehlisb46be812015-10-23 16:00:08 -06003742 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wuc51b1212015-10-27 19:25:11 +08003743 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003744 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003745 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003746
3747 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3748 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3749 ds_pool_ci.pNext = NULL;
3750 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003751 ds_pool_ci.poolSizeCount = 1;
3752 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003753
3754 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003755 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003756 ASSERT_VK_SUCCESS(err);
3757
3758 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003759 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003760 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003761 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003762 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3763 dsl_binding.pImmutableSamplers = NULL;
3764
3765 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3766 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3767 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003768 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003769 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003770 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003771 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003772 ASSERT_VK_SUCCESS(err);
3773
3774 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003775 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003776 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003777 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003778 alloc_info.descriptorPool = ds_pool;
3779 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003780 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003781 ASSERT_VK_SUCCESS(err);
3782
3783 VkSamplerCreateInfo sampler_ci = {};
3784 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3785 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003786 sampler_ci.magFilter = VK_FILTER_NEAREST;
3787 sampler_ci.minFilter = VK_FILTER_NEAREST;
3788 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003789 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3790 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3791 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003792 sampler_ci.mipLodBias = 1.0;
Jon Ashburn0717ed52015-12-14 14:59:20 -07003793 sampler_ci.anisotropyEnable = VK_FALSE;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003794 sampler_ci.maxAnisotropy = 1;
3795 sampler_ci.compareEnable = VK_FALSE;
3796 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3797 sampler_ci.minLod = 1.0;
3798 sampler_ci.maxLod = 1.0;
3799 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3800 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3801
3802 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003803 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003804 ASSERT_VK_SUCCESS(err);
3805
Chia-I Wue420a332015-10-26 20:04:44 +08003806 VkImageView view = (VkImageView) 0xbaadbeef; // invalid imageView object
Tobin Ehlisb46be812015-10-23 16:00:08 -06003807
3808 VkDescriptorImageInfo descriptor_info;
3809 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3810 descriptor_info.sampler = sampler;
3811 descriptor_info.imageView = view;
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_COMBINED_IMAGE_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 imageView...'";
3826 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06003827 }
3828
Chia-I Wu69f40122015-10-26 21:10:41 +08003829 vkDestroySampler(m_device->device(), sampler, NULL);
3830 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3831 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003832}
3833
Tobin Ehlis3e676262015-10-27 16:35:27 -06003834TEST_F(VkLayerTest, CopyDescriptorUpdateErrors)
3835{
3836 // 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 -06003837 VkResult err;
3838
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003840 "Copy descriptor update index 0, update count #1, has src update descriptor type VK_DESCRIPTOR_TYPE_SAMPLER ");
3841
Tobin Ehlis3e676262015-10-27 16:35:27 -06003842 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3e676262015-10-27 16:35:27 -06003843 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003844 VkDescriptorPoolSize ds_type_count[2] = {};
Tobin Ehlis3e676262015-10-27 16:35:27 -06003845 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003846 ds_type_count[0].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003847 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003848 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003849
3850 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3851 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3852 ds_pool_ci.pNext = NULL;
3853 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003854 ds_pool_ci.poolSizeCount = 2;
3855 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003856
3857 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003858 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003859 ASSERT_VK_SUCCESS(err);
3860 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003861 dsl_binding[0].binding = 0;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003862 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003863 dsl_binding[0].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003864 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3865 dsl_binding[0].pImmutableSamplers = NULL;
Chia-I Wub5689ee2015-10-31 00:31:16 +08003866 dsl_binding[1].binding = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003867 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003868 dsl_binding[1].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003869 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
3870 dsl_binding[1].pImmutableSamplers = NULL;
3871
3872 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3873 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3874 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003875 ds_layout_ci.bindingCount = 2;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003876 ds_layout_ci.pBinding = dsl_binding;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003877
3878 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003879 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003880 ASSERT_VK_SUCCESS(err);
3881
3882 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003883 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003884 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003885 alloc_info.setLayoutCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003886 alloc_info.descriptorPool = ds_pool;
3887 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003888 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003889 ASSERT_VK_SUCCESS(err);
3890
3891 VkSamplerCreateInfo sampler_ci = {};
3892 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3893 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003894 sampler_ci.magFilter = VK_FILTER_NEAREST;
3895 sampler_ci.minFilter = VK_FILTER_NEAREST;
3896 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003897 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3898 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3899 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003900 sampler_ci.mipLodBias = 1.0;
Jon Ashburn0717ed52015-12-14 14:59:20 -07003901 sampler_ci.anisotropyEnable = VK_FALSE;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003902 sampler_ci.maxAnisotropy = 1;
3903 sampler_ci.compareEnable = VK_FALSE;
3904 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3905 sampler_ci.minLod = 1.0;
3906 sampler_ci.maxLod = 1.0;
3907 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3908 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3909
3910 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003911 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003912 ASSERT_VK_SUCCESS(err);
3913
3914 VkDescriptorImageInfo info = {};
3915 info.sampler = sampler;
3916
3917 VkWriteDescriptorSet descriptor_write;
3918 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
3919 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003920 descriptor_write.dstSet = descriptorSet;
3921 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wu763a7492015-10-26 20:48:51 +08003922 descriptor_write.descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003923 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3924 descriptor_write.pImageInfo = &info;
3925 // This write update should succeed
3926 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3927 // Now perform a copy update that fails due to type mismatch
3928 VkCopyDescriptorSet copy_ds_update;
3929 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3930 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3931 copy_ds_update.srcSet = descriptorSet;
3932 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
Chia-I Wu1f851912015-10-27 18:04:07 +08003933 copy_ds_update.dstSet = descriptorSet;
3934 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wu763a7492015-10-26 20:48:51 +08003935 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06003936 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3937
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003938 if (!m_errorMonitor->DesiredMsgFound()) {
3939 FAIL() << "Did not receive Error 'Copy descriptor update index 0, update count #1, has src update descriptor type_DESCRIPTOR_TYPE_SAMPLER'";
3940 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06003941 }
3942 // Now perform a copy update that fails due to binding out of bounds
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003944 "Copy descriptor update 0 has srcBinding 3 which is out of bounds ");
Tobin Ehlis3e676262015-10-27 16:35:27 -06003945 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3946 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3947 copy_ds_update.srcSet = descriptorSet;
3948 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu1f851912015-10-27 18:04:07 +08003949 copy_ds_update.dstSet = descriptorSet;
3950 copy_ds_update.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003951 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06003952 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3953
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003954 if (!m_errorMonitor->DesiredMsgFound()) {
3955 FAIL() << "Did not receive Error 'Copy descriptor update 0 has srcBinding 3 which is out of bounds...'";
3956 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06003957 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003958
Tobin Ehlis3e676262015-10-27 16:35:27 -06003959 // Now perform a copy update that fails due to binding out of bounds
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003961 "Copy descriptor src update is out of bounds for matching binding 1 ");
3962
Tobin Ehlis3e676262015-10-27 16:35:27 -06003963 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3964 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3965 copy_ds_update.srcSet = descriptorSet;
3966 copy_ds_update.srcBinding = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08003967 copy_ds_update.dstSet = descriptorSet;
3968 copy_ds_update.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003969 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis3e676262015-10-27 16:35:27 -06003970 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3971
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003972 if (!m_errorMonitor->DesiredMsgFound()) {
3973 FAIL() << "Did not receive Error 'Copy descriptor src update is out of bounds for matching binding 1...'";
3974 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06003975 }
3976
Chia-I Wu69f40122015-10-26 21:10:41 +08003977 vkDestroySampler(m_device->device(), sampler, NULL);
3978 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3979 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003980}
3981
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003982TEST_F(VkLayerTest, NumSamplesMismatch)
3983{
Chia-I Wu1f851912015-10-27 18:04:07 +08003984 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003985 VkResult err;
3986
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003988 "Num samples mismatch! ");
3989
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003990 ASSERT_NO_FATAL_FAILURE(InitState());
3991 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wuc51b1212015-10-27 19:25:11 +08003992 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003993 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003994 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003995
3996 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003997 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3998 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003999 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08004000 ds_pool_ci.poolSizeCount = 1;
4001 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004002
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004003 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08004004 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004005 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004006
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004007 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08004008 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004009 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08004010 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004011 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4012 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004013
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004014 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4015 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4016 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004017 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08004018 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004019
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004020 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004021 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004022 ASSERT_VK_SUCCESS(err);
4023
4024 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004025 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004026 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08004027 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004028 alloc_info.descriptorPool = ds_pool;
4029 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08004030 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004031 ASSERT_VK_SUCCESS(err);
4032
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004033 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4034 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4035 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004036 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004037 pipe_ms_state_ci.sampleShadingEnable = 0;
4038 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06004039 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004040
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004041 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4042 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4043 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004044 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004045 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004046
4047 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004048 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004049 ASSERT_VK_SUCCESS(err);
4050
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004051 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4052 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 -06004053 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06004054 VkPipelineObj pipe(m_device);
4055 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004056 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004057 pipe.SetMSAA(&pipe_ms_state_ci);
4058 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004059
Tony Barbour1490c912015-07-28 10:17:20 -06004060 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08004061 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004062
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004063 if (!m_errorMonitor->DesiredMsgFound()) {
4064 FAIL() << "Did not recieve Error 'Num samples mismatch!...'";
4065 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004066 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004067
Chia-I Wu69f40122015-10-26 21:10:41 +08004068 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4069 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4070 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06004071}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004072
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004073TEST_F(VkLayerTest, ClearCmdNoDraw)
4074{
Chia-I Wu1f851912015-10-27 18:04:07 +08004075 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004076 VkResult err;
4077
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004078 // TODO: verify that this matches layer
4079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004080 "vkCmdClearAttachments() issued on CB object ");
4081
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004082 ASSERT_NO_FATAL_FAILURE(InitState());
4083 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004084
Chia-I Wuc51b1212015-10-27 19:25:11 +08004085 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004086 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08004087 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004088
4089 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4090 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4091 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004092 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08004093 ds_pool_ci.poolSizeCount = 1;
4094 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004095
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004096 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08004097 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004098 ASSERT_VK_SUCCESS(err);
4099
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004100 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08004101 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004102 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08004103 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004104 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4105 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004106
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004107 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4108 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4109 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004110 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08004111 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004112
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004113 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004114 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004115 ASSERT_VK_SUCCESS(err);
4116
4117 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004118 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004119 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08004120 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004121 alloc_info.descriptorPool = ds_pool;
4122 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08004123 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004124 ASSERT_VK_SUCCESS(err);
4125
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004126 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4127 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4128 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004129 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004130 pipe_ms_state_ci.sampleShadingEnable = 0;
4131 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06004132 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004133
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004134 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4135 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4136 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004137 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004138 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004139
4140 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004141 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004142 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004143
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004144 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004145 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
4146 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4147
Tony Barbourd7d828b2015-08-06 10:16:07 -06004148 VkPipelineObj pipe(m_device);
4149 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004150 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004151 pipe.SetMSAA(&pipe_ms_state_ci);
4152 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06004153
4154 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004155
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004156 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
4157 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004158 VkClearAttachment color_attachment;
4159 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4160 color_attachment.clearValue.color.float32[0] = 1.0;
4161 color_attachment.clearValue.color.float32[1] = 1.0;
4162 color_attachment.clearValue.color.float32[2] = 1.0;
4163 color_attachment.clearValue.color.float32[3] = 1.0;
4164 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004165 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004166
Chia-I Wu1f851912015-10-27 18:04:07 +08004167 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004168
4169 if (!m_errorMonitor->DesiredMsgFound()) {
4170 FAIL() << "Did not receive Error 'vkCommandClearAttachments() issued on CB object...'";
4171 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004172 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004173
Chia-I Wu69f40122015-10-26 21:10:41 +08004174 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4175 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4176 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004177}
4178
Tobin Ehlise4076782015-06-24 15:53:07 -06004179TEST_F(VkLayerTest, VtxBufferBadIndex)
4180{
Tobin Ehlise4076782015-06-24 15:53:07 -06004181 VkResult err;
4182
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT,
Mark Lobodzinski74e84692015-12-14 15:14:10 -07004184 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004185
Tobin Ehlise4076782015-06-24 15:53:07 -06004186 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06004187 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlise4076782015-06-24 15:53:07 -06004188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004189
Chia-I Wuc51b1212015-10-27 19:25:11 +08004190 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004191 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08004192 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004193
4194 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4195 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4196 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004197 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08004198 ds_pool_ci.poolSizeCount = 1;
4199 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004200
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004201 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08004202 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06004203 ASSERT_VK_SUCCESS(err);
4204
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004205 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08004206 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004207 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08004208 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004209 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4210 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06004211
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004212 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4213 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4214 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004215 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08004216 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004217
Tobin Ehlise4076782015-06-24 15:53:07 -06004218 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004219 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06004220 ASSERT_VK_SUCCESS(err);
4221
4222 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004223 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004224 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08004225 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004226 alloc_info.descriptorPool = ds_pool;
4227 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08004228 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06004229 ASSERT_VK_SUCCESS(err);
4230
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004231 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4232 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4233 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004234 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004235 pipe_ms_state_ci.sampleShadingEnable = 0;
4236 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06004237 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06004238
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004239 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4240 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4241 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004242 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004243 pipeline_layout_ci.pSetLayouts = &ds_layout;
4244 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06004245
Chia-I Wu69f40122015-10-26 21:10:41 +08004246 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06004247 ASSERT_VK_SUCCESS(err);
4248
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004249 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4250 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 -06004251 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06004252 VkPipelineObj pipe(m_device);
4253 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004254 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004255 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06004256 pipe.SetViewport(m_viewports);
4257 pipe.SetScissor(m_scissors);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004258 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06004259
4260 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08004261 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06004262 // Don't care about actual data, just need to get to draw to flag error
4263 static const float vbo_data[3] = {1.f, 0.f, 1.f};
4264 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
4265 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06004266 Draw(1, 0, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06004267
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004268 if (!m_errorMonitor->DesiredMsgFound()) {
4269 FAIL() << "Did not receive Error 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
4270 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise4076782015-06-24 15:53:07 -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 Ehlise4076782015-06-24 15:53:07 -06004276}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004277#endif // DRAW_STATE_TESTS
4278
Tobin Ehlis57e6a612015-05-26 16:11:58 -06004279#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06004280#if GTEST_IS_THREADSAFE
4281struct thread_data_struct {
Chia-I Wu1f851912015-10-27 18:04:07 +08004282 VkCommandBuffer commandBuffer;
Mike Stroyan09aae812015-05-12 16:00:45 -06004283 VkEvent event;
4284 bool bailout;
4285};
4286
4287extern "C" void *AddToCommandBuffer(void *arg)
4288{
4289 struct thread_data_struct *data = (struct thread_data_struct *) arg;
Mike Stroyan09aae812015-05-12 16:00:45 -06004290
4291 for (int i = 0; i<10000; i++) {
Chia-I Wucba6cea2015-10-31 00:31:16 +08004292 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyan09aae812015-05-12 16:00:45 -06004293 if (data->bailout) {
4294 break;
4295 }
4296 }
4297 return NULL;
4298}
4299
Chia-I Wu1f851912015-10-27 18:04:07 +08004300TEST_F(VkLayerTest, ThreadCommandBufferCollision)
Mike Stroyan09aae812015-05-12 16:00:45 -06004301{
Mike Stroyan7016f4f2015-07-13 14:45:35 -06004302 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06004303
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004305
Mike Stroyan09aae812015-05-12 16:00:45 -06004306 ASSERT_NO_FATAL_FAILURE(InitState());
4307 ASSERT_NO_FATAL_FAILURE(InitViewport());
4308 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4309
Chia-I Wu1f851912015-10-27 18:04:07 +08004310 // Calls AllocateCommandBuffers
4311 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004312
4313 // Avoid creating RenderPass
Chia-I Wu1f851912015-10-27 18:04:07 +08004314 commandBuffer.BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06004315
4316 VkEventCreateInfo event_info;
4317 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06004318 VkResult err;
4319
4320 memset(&event_info, 0, sizeof(event_info));
4321 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4322
Chia-I Wu69f40122015-10-26 21:10:41 +08004323 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyan09aae812015-05-12 16:00:45 -06004324 ASSERT_VK_SUCCESS(err);
4325
Mike Stroyan09aae812015-05-12 16:00:45 -06004326 err = vkResetEvent(device(), event);
4327 ASSERT_VK_SUCCESS(err);
4328
4329 struct thread_data_struct data;
Chia-I Wu1f851912015-10-27 18:04:07 +08004330 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyan09aae812015-05-12 16:00:45 -06004331 data.event = event;
4332 data.bailout = false;
4333 m_errorMonitor->SetBailout(&data.bailout);
4334 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06004335 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06004336 // Add many entries to command buffer from this thread at the same time.
4337 AddToCommandBuffer(&data);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004338
Mike Stroyan7016f4f2015-07-13 14:45:35 -06004339 test_platform_thread_join(thread, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08004340 commandBuffer.EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06004341
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004342 if (!m_errorMonitor->DesiredMsgFound()) {
4343 FAIL() << "Did not receive Error 'THREADING ERROR' from using one VkCommandBufferObj in two threads";
4344 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan09aae812015-05-12 16:00:45 -06004345 }
4346
Chia-I Wu69f40122015-10-26 21:10:41 +08004347 vkDestroyEvent(device(), event, NULL);
Mike Stroyan09aae812015-05-12 16:00:45 -06004348}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004349#endif // GTEST_IS_THREADSAFE
4350#endif // THREADING_TESTS
4351
Chris Forbes5af3bf22015-05-25 11:13:08 +12004352#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004353TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
4354{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004356 "Shader is not SPIR-V");
4357
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004358 ASSERT_NO_FATAL_FAILURE(InitState());
4359 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4360
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004361 VkShaderModule module;
4362 VkShaderModuleCreateInfo moduleCreateInfo;
4363 struct icd_spv_header spv;
4364
4365 spv.magic = ICD_SPV_MAGIC;
4366 spv.version = ICD_SPV_VERSION;
4367 spv.gen_magic = 0;
4368
4369 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4370 moduleCreateInfo.pNext = NULL;
Chia-I Wu036b1612015-10-26 19:22:06 +08004371 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004372 moduleCreateInfo.codeSize = 4;
4373 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004374 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004375
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004376 if (!m_errorMonitor->DesiredMsgFound()) {
4377 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4378 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004379 }
4380}
4381
4382TEST_F(VkLayerTest, InvalidSPIRVMagic)
4383{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004385 "Shader is not SPIR-V");
4386
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004387 ASSERT_NO_FATAL_FAILURE(InitState());
4388 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4389
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004390 VkShaderModule module;
4391 VkShaderModuleCreateInfo moduleCreateInfo;
4392 struct icd_spv_header spv;
4393
4394 spv.magic = ~ICD_SPV_MAGIC;
4395 spv.version = ICD_SPV_VERSION;
4396 spv.gen_magic = 0;
4397
4398 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4399 moduleCreateInfo.pNext = NULL;
Chia-I Wu036b1612015-10-26 19:22:06 +08004400 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004401 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4402 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004403 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004404
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004405 if (!m_errorMonitor->DesiredMsgFound()) {
4406 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4407 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004408 }
4409}
4410
4411TEST_F(VkLayerTest, InvalidSPIRVVersion)
4412{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004414 "Shader is not SPIR-V");
4415
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004416 ASSERT_NO_FATAL_FAILURE(InitState());
4417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4418
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004419 VkShaderModule module;
4420 VkShaderModuleCreateInfo moduleCreateInfo;
4421 struct icd_spv_header spv;
4422
4423 spv.magic = ICD_SPV_MAGIC;
4424 spv.version = ~ICD_SPV_VERSION;
4425 spv.gen_magic = 0;
4426
4427 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4428 moduleCreateInfo.pNext = NULL;
4429
Chia-I Wu036b1612015-10-26 19:22:06 +08004430 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004431 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4432 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004433 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004434
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004435 if (!m_errorMonitor->DesiredMsgFound()) {
4436 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4437 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004438 }
4439}
4440
Chris Forbes5af3bf22015-05-25 11:13:08 +12004441TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
4442{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004444 "not consumed by fragment shader");
4445
Chris Forbes5af3bf22015-05-25 11:13:08 +12004446 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12004448
4449 char const *vsSource =
4450 "#version 140\n"
4451 "#extension GL_ARB_separate_shader_objects: require\n"
4452 "#extension GL_ARB_shading_language_420pack: require\n"
4453 "\n"
4454 "layout(location=0) out float x;\n"
4455 "void main(){\n"
4456 " gl_Position = vec4(1);\n"
4457 " x = 0;\n"
4458 "}\n";
4459 char const *fsSource =
4460 "#version 140\n"
4461 "#extension GL_ARB_separate_shader_objects: require\n"
4462 "#extension GL_ARB_shading_language_420pack: require\n"
4463 "\n"
4464 "layout(location=0) out vec4 color;\n"
4465 "void main(){\n"
4466 " color = vec4(1);\n"
4467 "}\n";
4468
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004469 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4470 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5af3bf22015-05-25 11:13:08 +12004471
4472 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004473 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12004474 pipe.AddShader(&vs);
4475 pipe.AddShader(&fs);
4476
Chris Forbes5af3bf22015-05-25 11:13:08 +12004477 VkDescriptorSetObj descriptorSet(m_device);
4478 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004479 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12004480
Tony Barboured132432015-08-04 16:23:11 -06004481 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12004482
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004483 if (!m_errorMonitor->DesiredMsgFound()) {
4484 FAIL() << "Did not receive Warning 'not consumed by fragment shader'";
4485 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5af3bf22015-05-25 11:13:08 +12004486 }
4487}
Chris Forbes5af3bf22015-05-25 11:13:08 +12004488
Chris Forbes3c10b852015-05-25 11:13:13 +12004489TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
4490{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004492 "not written by vertex shader");
4493
Chris Forbes3c10b852015-05-25 11:13:13 +12004494 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12004496
4497 char const *vsSource =
4498 "#version 140\n"
4499 "#extension GL_ARB_separate_shader_objects: require\n"
4500 "#extension GL_ARB_shading_language_420pack: require\n"
4501 "\n"
4502 "void main(){\n"
4503 " gl_Position = vec4(1);\n"
4504 "}\n";
4505 char const *fsSource =
4506 "#version 140\n"
4507 "#extension GL_ARB_separate_shader_objects: require\n"
4508 "#extension GL_ARB_shading_language_420pack: require\n"
4509 "\n"
4510 "layout(location=0) in float x;\n"
4511 "layout(location=0) out vec4 color;\n"
4512 "void main(){\n"
4513 " color = vec4(x);\n"
4514 "}\n";
4515
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004516 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4517 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes3c10b852015-05-25 11:13:13 +12004518
4519 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004520 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12004521 pipe.AddShader(&vs);
4522 pipe.AddShader(&fs);
4523
Chris Forbes3c10b852015-05-25 11:13:13 +12004524 VkDescriptorSetObj descriptorSet(m_device);
4525 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004526 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12004527
Tony Barboured132432015-08-04 16:23:11 -06004528 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12004529
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004530 if (!m_errorMonitor->DesiredMsgFound()) {
4531 FAIL() << "Did not receive Error 'not written by vertex shader'";
4532 m_errorMonitor->DumpFailureMsgs();
Chris Forbes3c10b852015-05-25 11:13:13 +12004533 }
4534}
4535
Chris Forbescc281692015-05-25 11:13:17 +12004536TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
4537{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004539 "Type mismatch on location 0");
4540
Chris Forbescc281692015-05-25 11:13:17 +12004541 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12004543
4544 char const *vsSource =
4545 "#version 140\n"
4546 "#extension GL_ARB_separate_shader_objects: require\n"
4547 "#extension GL_ARB_shading_language_420pack: require\n"
4548 "\n"
4549 "layout(location=0) out int x;\n"
4550 "void main(){\n"
4551 " x = 0;\n"
4552 " gl_Position = vec4(1);\n"
4553 "}\n";
4554 char const *fsSource =
4555 "#version 140\n"
4556 "#extension GL_ARB_separate_shader_objects: require\n"
4557 "#extension GL_ARB_shading_language_420pack: require\n"
4558 "\n"
4559 "layout(location=0) in float x;\n" /* VS writes int */
4560 "layout(location=0) out vec4 color;\n"
4561 "void main(){\n"
4562 " color = vec4(x);\n"
4563 "}\n";
4564
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004565 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4566 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbescc281692015-05-25 11:13:17 +12004567
4568 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004569 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12004570 pipe.AddShader(&vs);
4571 pipe.AddShader(&fs);
4572
Chris Forbescc281692015-05-25 11:13:17 +12004573 VkDescriptorSetObj descriptorSet(m_device);
4574 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004575 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12004576
Tony Barboured132432015-08-04 16:23:11 -06004577 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12004578
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004579 if (!m_errorMonitor->DesiredMsgFound()) {
4580 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
4581 m_errorMonitor->DumpFailureMsgs();
Chris Forbescc281692015-05-25 11:13:17 +12004582 }
4583}
4584
Chris Forbes8291c052015-05-25 11:13:28 +12004585TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
4586{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERF_WARN_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004588 "location 0 not consumed by VS");
4589
Chris Forbes8291c052015-05-25 11:13:28 +12004590 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12004592
4593 VkVertexInputBindingDescription input_binding;
4594 memset(&input_binding, 0, sizeof(input_binding));
4595
4596 VkVertexInputAttributeDescription input_attrib;
4597 memset(&input_attrib, 0, sizeof(input_attrib));
4598 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4599
4600 char const *vsSource =
4601 "#version 140\n"
4602 "#extension GL_ARB_separate_shader_objects: require\n"
4603 "#extension GL_ARB_shading_language_420pack: require\n"
4604 "\n"
4605 "void main(){\n"
4606 " gl_Position = vec4(1);\n"
4607 "}\n";
4608 char const *fsSource =
4609 "#version 140\n"
4610 "#extension GL_ARB_separate_shader_objects: require\n"
4611 "#extension GL_ARB_shading_language_420pack: require\n"
4612 "\n"
4613 "layout(location=0) out vec4 color;\n"
4614 "void main(){\n"
4615 " color = vec4(1);\n"
4616 "}\n";
4617
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004618 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4619 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes8291c052015-05-25 11:13:28 +12004620
4621 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004622 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12004623 pipe.AddShader(&vs);
4624 pipe.AddShader(&fs);
4625
4626 pipe.AddVertexInputBindings(&input_binding, 1);
4627 pipe.AddVertexInputAttribs(&input_attrib, 1);
4628
Chris Forbes8291c052015-05-25 11:13:28 +12004629 VkDescriptorSetObj descriptorSet(m_device);
4630 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004631 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12004632
Tony Barboured132432015-08-04 16:23:11 -06004633 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12004634
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004635 if (!m_errorMonitor->DesiredMsgFound()) {
4636 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
4637 m_errorMonitor->DumpFailureMsgs();
Chris Forbes8291c052015-05-25 11:13:28 +12004638 }
4639}
4640
Chris Forbes37367e62015-05-25 11:13:29 +12004641TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
4642{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004644 "VS consumes input at location 0 but not provided");
4645
Chris Forbes37367e62015-05-25 11:13:29 +12004646 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12004648
4649 char const *vsSource =
4650 "#version 140\n"
4651 "#extension GL_ARB_separate_shader_objects: require\n"
4652 "#extension GL_ARB_shading_language_420pack: require\n"
4653 "\n"
4654 "layout(location=0) in vec4 x;\n" /* not provided */
4655 "void main(){\n"
4656 " gl_Position = x;\n"
4657 "}\n";
4658 char const *fsSource =
4659 "#version 140\n"
4660 "#extension GL_ARB_separate_shader_objects: require\n"
4661 "#extension GL_ARB_shading_language_420pack: require\n"
4662 "\n"
4663 "layout(location=0) out vec4 color;\n"
4664 "void main(){\n"
4665 " color = vec4(1);\n"
4666 "}\n";
4667
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004668 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4669 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes37367e62015-05-25 11:13:29 +12004670
4671 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004672 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12004673 pipe.AddShader(&vs);
4674 pipe.AddShader(&fs);
4675
Chris Forbes37367e62015-05-25 11:13:29 +12004676 VkDescriptorSetObj descriptorSet(m_device);
4677 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004678 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12004679
Tony Barboured132432015-08-04 16:23:11 -06004680 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12004681
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004682 if (!m_errorMonitor->DesiredMsgFound()) {
4683 FAIL() << "Did not receive Error 'VS consumes input at location 0 but not provided'";
4684 m_errorMonitor->DumpFailureMsgs();
Chris Forbes37367e62015-05-25 11:13:29 +12004685 }
4686}
4687
Chris Forbesa4b02322015-05-25 11:13:31 +12004688TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
4689{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004691 "location 0 does not match VS input type");
4692
Chris Forbesa4b02322015-05-25 11:13:31 +12004693 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004694 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12004695
4696 VkVertexInputBindingDescription input_binding;
4697 memset(&input_binding, 0, sizeof(input_binding));
4698
4699 VkVertexInputAttributeDescription input_attrib;
4700 memset(&input_attrib, 0, sizeof(input_attrib));
4701 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4702
4703 char const *vsSource =
4704 "#version 140\n"
4705 "#extension GL_ARB_separate_shader_objects: require\n"
4706 "#extension GL_ARB_shading_language_420pack: require\n"
4707 "\n"
4708 "layout(location=0) in int x;\n" /* attrib provided float */
4709 "void main(){\n"
4710 " gl_Position = vec4(x);\n"
4711 "}\n";
4712 char const *fsSource =
4713 "#version 140\n"
4714 "#extension GL_ARB_separate_shader_objects: require\n"
4715 "#extension GL_ARB_shading_language_420pack: require\n"
4716 "\n"
4717 "layout(location=0) out vec4 color;\n"
4718 "void main(){\n"
4719 " color = vec4(1);\n"
4720 "}\n";
4721
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004722 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4723 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa4b02322015-05-25 11:13:31 +12004724
4725 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004726 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12004727 pipe.AddShader(&vs);
4728 pipe.AddShader(&fs);
4729
4730 pipe.AddVertexInputBindings(&input_binding, 1);
4731 pipe.AddVertexInputAttribs(&input_attrib, 1);
4732
Chris Forbesa4b02322015-05-25 11:13:31 +12004733 VkDescriptorSetObj descriptorSet(m_device);
4734 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004735 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12004736
Tony Barboured132432015-08-04 16:23:11 -06004737 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12004738
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004739 if (!m_errorMonitor->DesiredMsgFound()) {
4740 FAIL() << "Did not receive Error 'location 0 does not match VS input type'";
4741 m_errorMonitor->DumpFailureMsgs();
Chris Forbesa4b02322015-05-25 11:13:31 +12004742 }
4743}
4744
Chris Forbes03e6d762015-11-24 11:13:14 +13004745TEST_F(VkLayerTest, CreatePipelineAttribMatrixType)
4746{
4747 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
4748
4749 ASSERT_NO_FATAL_FAILURE(InitState());
4750 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4751
4752 VkVertexInputBindingDescription input_binding;
4753 memset(&input_binding, 0, sizeof(input_binding));
4754
4755 VkVertexInputAttributeDescription input_attribs[2];
4756 memset(input_attribs, 0, sizeof(input_attribs));
4757
4758 for (int i = 0; i < 2; i++) {
4759 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
4760 input_attribs[i].location = i;
4761 }
4762
4763 char const *vsSource =
4764 "#version 140\n"
4765 "#extension GL_ARB_separate_shader_objects: require\n"
4766 "#extension GL_ARB_shading_language_420pack: require\n"
4767 "\n"
4768 "layout(location=0) in mat2x4 x;\n"
4769 "void main(){\n"
4770 " gl_Position = x[0] + x[1];\n"
4771 "}\n";
4772 char const *fsSource =
4773 "#version 140\n"
4774 "#extension GL_ARB_separate_shader_objects: require\n"
4775 "#extension GL_ARB_shading_language_420pack: require\n"
4776 "\n"
4777 "layout(location=0) out vec4 color;\n"
4778 "void main(){\n"
4779 " color = vec4(1);\n"
4780 "}\n";
4781
4782 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4783 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4784
4785 VkPipelineObj pipe(m_device);
4786 pipe.AddColorAttachment();
4787 pipe.AddShader(&vs);
4788 pipe.AddShader(&fs);
4789
4790 pipe.AddVertexInputBindings(&input_binding, 1);
4791 pipe.AddVertexInputAttribs(input_attribs, 2);
4792
4793 VkDescriptorSetObj descriptorSet(m_device);
4794 descriptorSet.AppendDummy();
4795 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
4796
4797 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4798
4799 /* expect success */
4800 if (m_errorMonitor->DesiredMsgFound()) {
4801 FAIL() << "Expected to succeed but: " << m_errorMonitor->GetFailureMsg();
4802 m_errorMonitor->DumpFailureMsgs();
4803 }
4804}
4805
4806/*
4807 * Would work, but not supported by glslang! This is similar to the matrix case above.
4808 *
4809TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
4810{
4811 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
4812
4813 ASSERT_NO_FATAL_FAILURE(InitState());
4814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4815
4816 VkVertexInputBindingDescription input_binding;
4817 memset(&input_binding, 0, sizeof(input_binding));
4818
4819 VkVertexInputAttributeDescription input_attribs[2];
4820 memset(input_attribs, 0, sizeof(input_attribs));
4821
4822 for (int i = 0; i < 2; i++) {
4823 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
4824 input_attribs[i].location = i;
4825 }
4826
4827 char const *vsSource =
4828 "#version 140\n"
4829 "#extension GL_ARB_separate_shader_objects: require\n"
4830 "#extension GL_ARB_shading_language_420pack: require\n"
4831 "\n"
4832 "layout(location=0) in vec4 x[2];\n"
4833 "void main(){\n"
4834 " gl_Position = x[0] + x[1];\n"
4835 "}\n";
4836 char const *fsSource =
4837 "#version 140\n"
4838 "#extension GL_ARB_separate_shader_objects: require\n"
4839 "#extension GL_ARB_shading_language_420pack: require\n"
4840 "\n"
4841 "layout(location=0) out vec4 color;\n"
4842 "void main(){\n"
4843 " color = vec4(1);\n"
4844 "}\n";
4845
4846 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4847 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4848
4849 VkPipelineObj pipe(m_device);
4850 pipe.AddColorAttachment();
4851 pipe.AddShader(&vs);
4852 pipe.AddShader(&fs);
4853
4854 pipe.AddVertexInputBindings(&input_binding, 1);
4855 pipe.AddVertexInputAttribs(input_attribs, 2);
4856
4857 VkDescriptorSetObj descriptorSet(m_device);
4858 descriptorSet.AppendDummy();
4859 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
4860
4861 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4862
4863 if (m_errorMonitor->DesiredMsgFound()) {
4864 FAIL() << "Expected to succeed but: " << m_errorMonitor->GetFailureMsg();
4865 m_errorMonitor->DumpFailureMsgs();
4866 }
4867}
4868*/
4869
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004870TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
4871{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004873 "Duplicate vertex input binding descriptions for binding 0");
4874
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004875 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004876 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004877
4878 /* Two binding descriptions for binding 0 */
4879 VkVertexInputBindingDescription input_bindings[2];
4880 memset(input_bindings, 0, sizeof(input_bindings));
4881
4882 VkVertexInputAttributeDescription input_attrib;
4883 memset(&input_attrib, 0, sizeof(input_attrib));
4884 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4885
4886 char const *vsSource =
4887 "#version 140\n"
4888 "#extension GL_ARB_separate_shader_objects: require\n"
4889 "#extension GL_ARB_shading_language_420pack: require\n"
4890 "\n"
4891 "layout(location=0) in float x;\n" /* attrib provided float */
4892 "void main(){\n"
4893 " gl_Position = vec4(x);\n"
4894 "}\n";
4895 char const *fsSource =
4896 "#version 140\n"
4897 "#extension GL_ARB_separate_shader_objects: require\n"
4898 "#extension GL_ARB_shading_language_420pack: require\n"
4899 "\n"
4900 "layout(location=0) out vec4 color;\n"
4901 "void main(){\n"
4902 " color = vec4(1);\n"
4903 "}\n";
4904
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004905 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4906 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004907
4908 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004909 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004910 pipe.AddShader(&vs);
4911 pipe.AddShader(&fs);
4912
4913 pipe.AddVertexInputBindings(input_bindings, 2);
4914 pipe.AddVertexInputAttribs(&input_attrib, 1);
4915
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004916 VkDescriptorSetObj descriptorSet(m_device);
4917 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004918 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004919
Tony Barboured132432015-08-04 16:23:11 -06004920 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004921
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004922 if (!m_errorMonitor->DesiredMsgFound()) {
4923 FAIL() << "Did not receive Error 'Duplicate vertex input binding descriptions for binding 0'";
4924 m_errorMonitor->DumpFailureMsgs();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004925 }
4926}
Chris Forbes4c948702015-05-25 11:13:32 +12004927
Chris Forbesc12ef122015-05-25 11:13:40 +12004928TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
4929{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004931 "Attachment 0 not written by FS");
4932
Chris Forbesc12ef122015-05-25 11:13:40 +12004933 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12004934
4935 char const *vsSource =
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 "void main(){\n"
4941 " gl_Position = vec4(1);\n"
4942 "}\n";
4943 char const *fsSource =
4944 "#version 140\n"
4945 "#extension GL_ARB_separate_shader_objects: require\n"
4946 "#extension GL_ARB_shading_language_420pack: require\n"
4947 "\n"
4948 "void main(){\n"
4949 "}\n";
4950
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004951 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4952 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc12ef122015-05-25 11:13:40 +12004953
4954 VkPipelineObj pipe(m_device);
4955 pipe.AddShader(&vs);
4956 pipe.AddShader(&fs);
4957
Chia-I Wuc278df82015-07-07 11:50:03 +08004958 /* set up CB 0, not written */
4959 pipe.AddColorAttachment();
4960 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12004961
Chris Forbesc12ef122015-05-25 11:13:40 +12004962 VkDescriptorSetObj descriptorSet(m_device);
4963 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004964 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12004965
Tony Barboured132432015-08-04 16:23:11 -06004966 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12004967
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004968 if (!m_errorMonitor->DesiredMsgFound()) {
4969 FAIL() << "Did not receive Error 'Attachment 0 not written by FS'";
4970 m_errorMonitor->DumpFailureMsgs();
Chris Forbesc12ef122015-05-25 11:13:40 +12004971 }
4972}
4973
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004974TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
4975{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004976 // TODO: verify that this matches layer
4977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARN_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004978 "FS writes to output location 1 with no matching attachment");
4979
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004980 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004981
4982 char const *vsSource =
4983 "#version 140\n"
4984 "#extension GL_ARB_separate_shader_objects: require\n"
4985 "#extension GL_ARB_shading_language_420pack: require\n"
4986 "\n"
4987 "void main(){\n"
4988 " gl_Position = vec4(1);\n"
4989 "}\n";
4990 char const *fsSource =
4991 "#version 140\n"
4992 "#extension GL_ARB_separate_shader_objects: require\n"
4993 "#extension GL_ARB_shading_language_420pack: require\n"
4994 "\n"
4995 "layout(location=0) out vec4 x;\n"
4996 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
4997 "void main(){\n"
4998 " x = vec4(1);\n"
4999 " y = vec4(1);\n"
5000 "}\n";
5001
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005002 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5003 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005004
5005 VkPipelineObj pipe(m_device);
5006 pipe.AddShader(&vs);
5007 pipe.AddShader(&fs);
5008
Chia-I Wuc278df82015-07-07 11:50:03 +08005009 /* set up CB 0, not written */
5010 pipe.AddColorAttachment();
5011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005012 /* FS writes CB 1, but we don't configure it */
5013
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005014 VkDescriptorSetObj descriptorSet(m_device);
5015 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005016 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005017
Tony Barboured132432015-08-04 16:23:11 -06005018 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005019
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005020 if (!m_errorMonitor->DesiredMsgFound()) {
5021 FAIL() << "Did not receive Error 'FS writes to output location 1 with no matching attachment'";
5022 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005023 }
5024}
5025
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005026TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
5027{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005029 "does not match FS output type");
5030
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005031 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005032
5033 char const *vsSource =
5034 "#version 140\n"
5035 "#extension GL_ARB_separate_shader_objects: require\n"
5036 "#extension GL_ARB_shading_language_420pack: require\n"
5037 "\n"
5038 "void main(){\n"
5039 " gl_Position = vec4(1);\n"
5040 "}\n";
5041 char const *fsSource =
5042 "#version 140\n"
5043 "#extension GL_ARB_separate_shader_objects: require\n"
5044 "#extension GL_ARB_shading_language_420pack: require\n"
5045 "\n"
5046 "layout(location=0) out ivec4 x;\n" /* not UNORM */
5047 "void main(){\n"
5048 " x = ivec4(1);\n"
5049 "}\n";
5050
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005051 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5052 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005053
5054 VkPipelineObj pipe(m_device);
5055 pipe.AddShader(&vs);
5056 pipe.AddShader(&fs);
5057
Chia-I Wuc278df82015-07-07 11:50:03 +08005058 /* set up CB 0; type is UNORM by default */
5059 pipe.AddColorAttachment();
5060 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005061
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005062 VkDescriptorSetObj descriptorSet(m_device);
5063 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005064 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005065
Tony Barboured132432015-08-04 16:23:11 -06005066 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005067
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005068 if (!m_errorMonitor->DesiredMsgFound()) {
5069 FAIL() << "Did not receive Error 'does not match FS output type'";
5070 m_errorMonitor->DumpFailureMsgs();
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005071 }
5072}
Chris Forbesc2050732015-06-05 14:43:36 +12005073
Chris Forbes76ce7882015-08-14 12:04:59 +12005074TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
5075{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005077 "not declared in pipeline layout");
5078
Chris Forbes76ce7882015-08-14 12:04:59 +12005079 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +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(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5096 "void main(){\n"
5097 " x = vec4(bar.y);\n"
5098 "}\n";
5099
Chris Forbes76ce7882015-08-14 12:04:59 +12005100
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 Forbes76ce7882015-08-14 12:04:59 +12005103
Chris Forbes76ce7882015-08-14 12:04:59 +12005104 VkPipelineObj pipe(m_device);
5105 pipe.AddShader(&vs);
5106 pipe.AddShader(&fs);
5107
5108 /* set up CB 0; type is UNORM by default */
5109 pipe.AddColorAttachment();
5110 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5111
5112 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1f851912015-10-27 18:04:07 +08005113 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes76ce7882015-08-14 12:04:59 +12005114
5115 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5116
5117 /* should have generated an error -- pipeline layout does not
5118 * provide a uniform buffer in 0.0
5119 */
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005120 if (!m_errorMonitor->DesiredMsgFound()) {
5121 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
5122 m_errorMonitor->DumpFailureMsgs();
Chris Forbes76ce7882015-08-14 12:04:59 +12005123 }
5124}
5125
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06005126#endif // SHADER_CHECKER_TESTS
5127
5128#if DEVICE_LIMITS_TESTS
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005129TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
5130{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005132 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005133
5134 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005135
5136 // Create an image
5137 VkImage image;
5138
5139 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5140 const int32_t tex_width = 32;
5141 const int32_t tex_height = 32;
5142
5143 VkImageCreateInfo image_create_info = {};
5144 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5145 image_create_info.pNext = NULL;
5146 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5147 image_create_info.format = tex_format;
5148 image_create_info.extent.width = tex_width;
5149 image_create_info.extent.height = tex_height;
5150 image_create_info.extent.depth = 1;
5151 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005152 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005153 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005154 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5155 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5156 image_create_info.flags = 0;
5157
5158 // Introduce error by sending down a bogus width extent
5159 image_create_info.extent.width = 65536;
Chia-I Wu69f40122015-10-26 21:10:41 +08005160 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005161
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005162 if (!m_errorMonitor->DesiredMsgFound()) {
5163 FAIL() << "Did not receive Error 'CreateImage extents exceed allowable limits for format'";
5164 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005165 }
5166}
5167
5168TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
5169{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005171 "CreateImage resource size exceeds allowable maximum");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005172
5173 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005174
5175 // Create an image
5176 VkImage image;
5177
5178 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5179 const int32_t tex_width = 32;
5180 const int32_t tex_height = 32;
5181
5182 VkImageCreateInfo image_create_info = {};
5183 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5184 image_create_info.pNext = NULL;
5185 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5186 image_create_info.format = tex_format;
5187 image_create_info.extent.width = tex_width;
5188 image_create_info.extent.height = tex_height;
5189 image_create_info.extent.depth = 1;
5190 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005191 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005192 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005193 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5194 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5195 image_create_info.flags = 0;
5196
5197 // Introduce error by sending down individually allowable values that result in a surface size
5198 // exceeding the device maximum
5199 image_create_info.extent.width = 8192;
5200 image_create_info.extent.height = 8192;
5201 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005202 image_create_info.arrayLayers = 4;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005203 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005204 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
Chia-I Wu69f40122015-10-26 21:10:41 +08005205 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005206
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005207 if (!m_errorMonitor->DesiredMsgFound()) {
5208 FAIL() << "Did not receive Error 'CreateImage resource size exceeds allowable maximum'";
5209 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005210 }
5211}
5212
Mike Stroyan43909d82015-09-25 13:39:21 -06005213TEST_F(VkLayerTest, UpdateBufferAlignment)
5214{
Mike Stroyan43909d82015-09-25 13:39:21 -06005215 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
5216
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005218 "dstOffset, is not a multiple of 4");
5219
Mike Stroyan43909d82015-09-25 13:39:21 -06005220 ASSERT_NO_FATAL_FAILURE(InitState());
5221
5222 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5223 vk_testing::Buffer buffer;
5224 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
5225
5226 BeginCommandBuffer();
5227 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08005228 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005229 if (!m_errorMonitor->DesiredMsgFound()) {
5230 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
5231 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005232 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005233
Mike Stroyan43909d82015-09-25 13:39:21 -06005234 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005236 "dataSize, is not a multiple of 4");
5237
Chia-I Wu1f851912015-10-27 18:04:07 +08005238 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005239
5240 if (!m_errorMonitor->DesiredMsgFound()) {
5241 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
5242 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005243 }
5244 EndCommandBuffer();
5245}
5246
5247TEST_F(VkLayerTest, FillBufferAlignment)
5248{
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005250 "dstOffset, is not a multiple of 4");
Mike Stroyan43909d82015-09-25 13:39:21 -06005251
5252 ASSERT_NO_FATAL_FAILURE(InitState());
5253
5254 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5255 vk_testing::Buffer buffer;
5256 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
5257
5258 BeginCommandBuffer();
5259 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08005260 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005261 if (!m_errorMonitor->DesiredMsgFound()) {
5262 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
5263 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005264 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005265
Mike Stroyan43909d82015-09-25 13:39:21 -06005266 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005268 "size, is not a multiple of 4");
5269
Chia-I Wu1f851912015-10-27 18:04:07 +08005270 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005271
5272 if (!m_errorMonitor->DesiredMsgFound()) {
5273 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize size, is not a multiple of 4'";
5274 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005275 }
5276 EndCommandBuffer();
5277}
5278
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06005279#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005280
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005281#if IMAGE_TESTS
5282TEST_F(VkLayerTest, InvalidImageView)
5283{
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005284 VkResult err;
5285
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005287 "vkCreateImageView called with baseMipLevel 10 ");
5288
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005289 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005290
Mike Stroyan43909d82015-09-25 13:39:21 -06005291 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005292 VkImage image;
5293
5294 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5295 const int32_t tex_width = 32;
5296 const int32_t tex_height = 32;
5297
5298 VkImageCreateInfo image_create_info = {};
5299 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5300 image_create_info.pNext = NULL;
5301 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5302 image_create_info.format = tex_format;
5303 image_create_info.extent.width = tex_width;
5304 image_create_info.extent.height = tex_height;
5305 image_create_info.extent.depth = 1;
5306 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005307 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005308 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005309 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5310 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5311 image_create_info.flags = 0;
5312
Chia-I Wu69f40122015-10-26 21:10:41 +08005313 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005314 ASSERT_VK_SUCCESS(err);
5315
5316 VkImageViewCreateInfo image_view_create_info = {};
5317 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5318 image_view_create_info.image = image;
5319 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5320 image_view_create_info.format = tex_format;
Chia-I Wu1f851912015-10-27 18:04:07 +08005321 image_view_create_info.subresourceRange.layerCount = 1;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005322 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Chia-I Wu1f851912015-10-27 18:04:07 +08005323 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005324 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005325
5326 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08005327 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005328
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005329 if (!m_errorMonitor->DesiredMsgFound()) {
5330 FAIL() << "Did not receive Error 'vkCreateImageView called with baseMipLevel 10...'";
5331 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005332 }
5333}
Mike Stroyan43909d82015-09-25 13:39:21 -06005334
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005335TEST_F(VkLayerTest, InvalidImageViewAspect)
5336{
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005337 VkResult err;
5338
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005340 "vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set");
5341
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005342 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005343
5344 // Create an image and try to create a view with an invalid aspectMask
5345 VkImage image;
5346
5347 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5348 const int32_t tex_width = 32;
5349 const int32_t tex_height = 32;
5350
5351 VkImageCreateInfo image_create_info = {};
5352 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5353 image_create_info.pNext = NULL;
5354 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5355 image_create_info.format = tex_format;
5356 image_create_info.extent.width = tex_width;
5357 image_create_info.extent.height = tex_height;
5358 image_create_info.extent.depth = 1;
5359 image_create_info.mipLevels = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005360 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005361 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5362 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5363 image_create_info.flags = 0;
5364
Chia-I Wu69f40122015-10-26 21:10:41 +08005365 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005366 ASSERT_VK_SUCCESS(err);
5367
5368 VkImageViewCreateInfo image_view_create_info = {};
5369 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5370 image_view_create_info.image = image;
5371 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5372 image_view_create_info.format = tex_format;
5373 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005374 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005375 // Cause an error by setting an invalid image aspect
5376 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
5377
5378 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08005379 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005380
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005381 if (!m_errorMonitor->DesiredMsgFound()) {
5382 FAIL() << "Did not receive Error 'VkCreateImageView: Color image formats must have ...'";
5383 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005384 }
5385}
5386
Mike Stroyan43909d82015-09-25 13:39:21 -06005387TEST_F(VkLayerTest, CopyImageTypeMismatch)
5388{
Mike Stroyan43909d82015-09-25 13:39:21 -06005389 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005390 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005391
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005393 "vkCmdCopyImage called with unmatched source and dest image types");
5394
Mike Stroyan43909d82015-09-25 13:39:21 -06005395 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005396
5397 // Create two images of different types and try to copy between them
5398 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005399 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005400 VkDeviceMemory srcMem;
5401 VkDeviceMemory destMem;
5402 VkMemoryRequirements memReqs;
5403
5404 VkImageCreateInfo image_create_info = {};
5405 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5406 image_create_info.pNext = NULL;
5407 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5408 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5409 image_create_info.extent.width = 32;
5410 image_create_info.extent.height = 32;
5411 image_create_info.extent.depth = 1;
5412 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005413 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005414 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005415 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005416 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005417 image_create_info.flags = 0;
5418
Chia-I Wu69f40122015-10-26 21:10:41 +08005419 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005420 ASSERT_VK_SUCCESS(err);
5421
5422 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005423 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005424
Chia-I Wu1f851912015-10-27 18:04:07 +08005425 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005426 ASSERT_VK_SUCCESS(err);
5427
5428 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005429 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005430 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005431 memAlloc.pNext = NULL;
5432 memAlloc.allocationSize = 0;
5433 memAlloc.memoryTypeIndex = 0;
5434
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005435 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005436 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005437 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5438 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005439 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005440 ASSERT_VK_SUCCESS(err);
5441
Chia-I Wu1f851912015-10-27 18:04:07 +08005442 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005443 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005444 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005445 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005446 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005447 ASSERT_VK_SUCCESS(err);
5448
5449 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5450 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005451 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005452 ASSERT_VK_SUCCESS(err);
5453
5454 BeginCommandBuffer();
5455 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005456 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005457 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005458 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005459 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005460 copyRegion.srcOffset.x = 0;
5461 copyRegion.srcOffset.y = 0;
5462 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005463 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005464 copyRegion.dstSubresource.mipLevel = 0;
5465 copyRegion.dstSubresource.baseArrayLayer = 0;
5466 copyRegion.dstSubresource.layerCount = 0;
5467 copyRegion.dstOffset.x = 0;
5468 copyRegion.dstOffset.y = 0;
5469 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005470 copyRegion.extent.width = 1;
5471 copyRegion.extent.height = 1;
5472 copyRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005473 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005474 EndCommandBuffer();
5475
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005476 if (!m_errorMonitor->DesiredMsgFound()) {
5477 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5478 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005479 }
5480
Chia-I Wu69f40122015-10-26 21:10:41 +08005481 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005482 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005483 vkFreeMemory(m_device->device(), srcMem, NULL);
5484 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005485}
5486
5487TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
5488{
5489 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
5490}
5491
5492TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
5493{
Mike Stroyan43909d82015-09-25 13:39:21 -06005494 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005495 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005496
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005498 "vkCmdCopyImage called with unmatched source and dest image types");
5499
Mike Stroyan43909d82015-09-25 13:39:21 -06005500 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005501
5502 // Create two images of different types and try to copy between them
5503 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005504 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005505 VkDeviceMemory srcMem;
5506 VkDeviceMemory destMem;
5507 VkMemoryRequirements memReqs;
5508
5509 VkImageCreateInfo image_create_info = {};
5510 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5511 image_create_info.pNext = NULL;
5512 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5513 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5514 image_create_info.extent.width = 32;
5515 image_create_info.extent.height = 32;
5516 image_create_info.extent.depth = 1;
5517 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005518 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005519 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005520 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005521 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005522 image_create_info.flags = 0;
5523
Chia-I Wu69f40122015-10-26 21:10:41 +08005524 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005525 ASSERT_VK_SUCCESS(err);
5526
5527 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005528 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005529
Chia-I Wu1f851912015-10-27 18:04:07 +08005530 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005531 ASSERT_VK_SUCCESS(err);
5532
5533 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005534 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005535 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005536 memAlloc.pNext = NULL;
5537 memAlloc.allocationSize = 0;
5538 memAlloc.memoryTypeIndex = 0;
5539
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005540 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005541 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005542 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5543 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005544 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005545 ASSERT_VK_SUCCESS(err);
5546
Chia-I Wu1f851912015-10-27 18:04:07 +08005547 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005548 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005549 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5550 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005551 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005552 ASSERT_VK_SUCCESS(err);
5553
5554 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5555 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005556 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005557 ASSERT_VK_SUCCESS(err);
5558
5559 BeginCommandBuffer();
5560 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005561 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005562 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005563 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005564 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005565 copyRegion.srcOffset.x = 0;
5566 copyRegion.srcOffset.y = 0;
5567 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005568 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005569 copyRegion.dstSubresource.mipLevel = 0;
5570 copyRegion.dstSubresource.baseArrayLayer = 0;
5571 copyRegion.dstSubresource.layerCount = 0;
5572 copyRegion.dstOffset.x = 0;
5573 copyRegion.dstOffset.y = 0;
5574 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005575 copyRegion.extent.width = 1;
5576 copyRegion.extent.height = 1;
5577 copyRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005578 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005579 EndCommandBuffer();
5580
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005581 if (!m_errorMonitor->DesiredMsgFound()) {
5582 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5583 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005584 }
5585
Chia-I Wu69f40122015-10-26 21:10:41 +08005586 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005587 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005588 vkFreeMemory(m_device->device(), srcMem, NULL);
5589 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005590}
5591
5592TEST_F(VkLayerTest, ResolveImageLowSampleCount)
5593{
Mike Stroyan43909d82015-09-25 13:39:21 -06005594 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005595 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005596
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005598 "vkCmdResolveImage called with source sample count less than 2.");
5599
Mike Stroyan43909d82015-09-25 13:39:21 -06005600 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005601
5602 // Create two images of sample count 1 and try to Resolve between them
5603 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005604 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005605 VkDeviceMemory srcMem;
5606 VkDeviceMemory destMem;
5607 VkMemoryRequirements memReqs;
5608
5609 VkImageCreateInfo image_create_info = {};
5610 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5611 image_create_info.pNext = NULL;
5612 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5613 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5614 image_create_info.extent.width = 32;
5615 image_create_info.extent.height = 1;
5616 image_create_info.extent.depth = 1;
5617 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005618 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005619 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005620 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005621 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005622 image_create_info.flags = 0;
5623
Chia-I Wu69f40122015-10-26 21:10:41 +08005624 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005625 ASSERT_VK_SUCCESS(err);
5626
5627 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005628 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005629
Chia-I Wu1f851912015-10-27 18:04:07 +08005630 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005631 ASSERT_VK_SUCCESS(err);
5632
5633 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005634 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005635 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005636 memAlloc.pNext = NULL;
5637 memAlloc.allocationSize = 0;
5638 memAlloc.memoryTypeIndex = 0;
5639
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005640 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005641 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005642 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5643 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005644 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005645 ASSERT_VK_SUCCESS(err);
5646
Chia-I Wu1f851912015-10-27 18:04:07 +08005647 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005648 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005649 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5650 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005651 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005652 ASSERT_VK_SUCCESS(err);
5653
5654 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5655 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005656 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005657 ASSERT_VK_SUCCESS(err);
5658
5659 BeginCommandBuffer();
5660 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5661 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5662 //VK_IMAGE_LAYOUT_GENERAL = 1,
5663 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005664 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005665 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005666 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005667 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005668 resolveRegion.srcOffset.x = 0;
5669 resolveRegion.srcOffset.y = 0;
5670 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005671 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005672 resolveRegion.dstSubresource.mipLevel = 0;
5673 resolveRegion.dstSubresource.baseArrayLayer = 0;
5674 resolveRegion.dstSubresource.layerCount = 0;
5675 resolveRegion.dstOffset.x = 0;
5676 resolveRegion.dstOffset.y = 0;
5677 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005678 resolveRegion.extent.width = 1;
5679 resolveRegion.extent.height = 1;
5680 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005681 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005682 EndCommandBuffer();
5683
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005684 if (!m_errorMonitor->DesiredMsgFound()) {
5685 FAIL() << "Did not receive Error 'vkCmdResolveImage called with source sample count less than 2.'";
5686 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005687 }
5688
Chia-I Wu69f40122015-10-26 21:10:41 +08005689 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005690 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005691 vkFreeMemory(m_device->device(), srcMem, NULL);
5692 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005693}
5694
5695TEST_F(VkLayerTest, ResolveImageHighSampleCount)
5696{
Mike Stroyan43909d82015-09-25 13:39:21 -06005697 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005698 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005699
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005701 "vkCmdResolveImage called with dest sample count greater than 1.");
5702
Mike Stroyan43909d82015-09-25 13:39:21 -06005703 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005704
5705 // Create two images of sample count 2 and try to Resolve between them
5706 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005707 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005708 VkDeviceMemory srcMem;
5709 VkDeviceMemory destMem;
5710 VkMemoryRequirements memReqs;
5711
5712 VkImageCreateInfo image_create_info = {};
5713 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5714 image_create_info.pNext = NULL;
5715 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5716 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5717 image_create_info.extent.width = 32;
5718 image_create_info.extent.height = 1;
5719 image_create_info.extent.depth = 1;
5720 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005721 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005722 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005723 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005724 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005725 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005726 image_create_info.flags = 0;
5727
Chia-I Wu69f40122015-10-26 21:10:41 +08005728 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005729 ASSERT_VK_SUCCESS(err);
5730
5731 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005732 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005733 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005734
Chia-I Wu1f851912015-10-27 18:04:07 +08005735 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005736 ASSERT_VK_SUCCESS(err);
5737
5738 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005739 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005740 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005741 memAlloc.pNext = NULL;
5742 memAlloc.allocationSize = 0;
5743 memAlloc.memoryTypeIndex = 0;
5744
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005745 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005746 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005747 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5748 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005749 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005750 ASSERT_VK_SUCCESS(err);
5751
Chia-I Wu1f851912015-10-27 18:04:07 +08005752 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005753 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005754 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5755 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005756 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005757 ASSERT_VK_SUCCESS(err);
5758
5759 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5760 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005761 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005762 ASSERT_VK_SUCCESS(err);
5763
5764 BeginCommandBuffer();
5765 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5766 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5767 //VK_IMAGE_LAYOUT_GENERAL = 1,
5768 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005769 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005770 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005771 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005772 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005773 resolveRegion.srcOffset.x = 0;
5774 resolveRegion.srcOffset.y = 0;
5775 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005776 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005777 resolveRegion.dstSubresource.mipLevel = 0;
5778 resolveRegion.dstSubresource.baseArrayLayer = 0;
5779 resolveRegion.dstSubresource.layerCount = 0;
5780 resolveRegion.dstOffset.x = 0;
5781 resolveRegion.dstOffset.y = 0;
5782 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005783 resolveRegion.extent.width = 1;
5784 resolveRegion.extent.height = 1;
5785 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005786 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005787 EndCommandBuffer();
5788
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005789 if (!m_errorMonitor->DesiredMsgFound()) {
5790 FAIL() << "Did not receive Error 'vkCmdResolveImage called with dest sample count greater than 1.'";
5791 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005792 }
5793
Chia-I Wu69f40122015-10-26 21:10:41 +08005794 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005795 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005796 vkFreeMemory(m_device->device(), srcMem, NULL);
5797 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005798}
5799
5800TEST_F(VkLayerTest, ResolveImageFormatMismatch)
5801{
Mike Stroyan43909d82015-09-25 13:39:21 -06005802 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005803 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005804
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005806 "vkCmdResolveImage called with unmatched source and dest formats.");
5807
Mike Stroyan43909d82015-09-25 13:39:21 -06005808 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005809
5810 // Create two images of different types and try to copy between them
5811 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005812 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005813 VkDeviceMemory srcMem;
5814 VkDeviceMemory destMem;
5815 VkMemoryRequirements memReqs;
5816
5817 VkImageCreateInfo image_create_info = {};
5818 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5819 image_create_info.pNext = NULL;
5820 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5821 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5822 image_create_info.extent.width = 32;
5823 image_create_info.extent.height = 1;
5824 image_create_info.extent.depth = 1;
5825 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005826 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005827 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005828 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005829 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005830 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005831 image_create_info.flags = 0;
5832
Chia-I Wu69f40122015-10-26 21:10:41 +08005833 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005834 ASSERT_VK_SUCCESS(err);
5835
Cody Northropb3bf94f2015-10-27 13:50:04 -06005836 // Set format to something other than source image
5837 image_create_info.format = VK_FORMAT_R32_SFLOAT;
5838 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005839 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005840 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005841
Chia-I Wu1f851912015-10-27 18:04:07 +08005842 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005843 ASSERT_VK_SUCCESS(err);
5844
5845 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005846 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005847 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005848 memAlloc.pNext = NULL;
5849 memAlloc.allocationSize = 0;
5850 memAlloc.memoryTypeIndex = 0;
5851
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005852 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005853 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005854 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5855 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005856 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005857 ASSERT_VK_SUCCESS(err);
5858
Chia-I Wu1f851912015-10-27 18:04:07 +08005859 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005860 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005861 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5862 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005863 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005864 ASSERT_VK_SUCCESS(err);
5865
5866 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5867 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005868 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005869 ASSERT_VK_SUCCESS(err);
5870
5871 BeginCommandBuffer();
5872 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5873 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5874 //VK_IMAGE_LAYOUT_GENERAL = 1,
5875 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005876 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005877 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005878 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005879 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005880 resolveRegion.srcOffset.x = 0;
5881 resolveRegion.srcOffset.y = 0;
5882 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005883 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005884 resolveRegion.dstSubresource.mipLevel = 0;
5885 resolveRegion.dstSubresource.baseArrayLayer = 0;
5886 resolveRegion.dstSubresource.layerCount = 0;
5887 resolveRegion.dstOffset.x = 0;
5888 resolveRegion.dstOffset.y = 0;
5889 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005890 resolveRegion.extent.width = 1;
5891 resolveRegion.extent.height = 1;
5892 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005893 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005894 EndCommandBuffer();
5895
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005896 if (!m_errorMonitor->DesiredMsgFound()) {
5897 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest formats.'";
5898 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005899 }
5900
Chia-I Wu69f40122015-10-26 21:10:41 +08005901 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005902 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005903 vkFreeMemory(m_device->device(), srcMem, NULL);
5904 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005905}
5906
5907TEST_F(VkLayerTest, ResolveImageTypeMismatch)
5908{
Mike Stroyan43909d82015-09-25 13:39:21 -06005909 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005910 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005911
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005913 "vkCmdResolveImage called with unmatched source and dest image types.");
5914
Mike Stroyan43909d82015-09-25 13:39:21 -06005915 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005916
5917 // Create two images of different types and try to copy between them
5918 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005919 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005920 VkDeviceMemory srcMem;
5921 VkDeviceMemory destMem;
5922 VkMemoryRequirements memReqs;
5923
5924 VkImageCreateInfo image_create_info = {};
5925 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5926 image_create_info.pNext = NULL;
5927 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5928 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5929 image_create_info.extent.width = 32;
5930 image_create_info.extent.height = 1;
5931 image_create_info.extent.depth = 1;
5932 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005933 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005934 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005935 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005936 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005937 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005938 image_create_info.flags = 0;
5939
Chia-I Wu69f40122015-10-26 21:10:41 +08005940 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005941 ASSERT_VK_SUCCESS(err);
5942
5943 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005944 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005945 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005946 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005947
Chia-I Wu1f851912015-10-27 18:04:07 +08005948 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005949 ASSERT_VK_SUCCESS(err);
5950
5951 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005952 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005953 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005954 memAlloc.pNext = NULL;
5955 memAlloc.allocationSize = 0;
5956 memAlloc.memoryTypeIndex = 0;
5957
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005958 vkGetImageMemoryRequirements(m_device->device(), srcImage, &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, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005963 ASSERT_VK_SUCCESS(err);
5964
Chia-I Wu1f851912015-10-27 18:04:07 +08005965 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005966 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005967 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5968 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005969 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005970 ASSERT_VK_SUCCESS(err);
5971
5972 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5973 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005974 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005975 ASSERT_VK_SUCCESS(err);
5976
5977 BeginCommandBuffer();
5978 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5979 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5980 //VK_IMAGE_LAYOUT_GENERAL = 1,
5981 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005982 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005983 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005984 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005985 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005986 resolveRegion.srcOffset.x = 0;
5987 resolveRegion.srcOffset.y = 0;
5988 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005989 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005990 resolveRegion.dstSubresource.mipLevel = 0;
5991 resolveRegion.dstSubresource.baseArrayLayer = 0;
5992 resolveRegion.dstSubresource.layerCount = 0;
5993 resolveRegion.dstOffset.x = 0;
5994 resolveRegion.dstOffset.y = 0;
5995 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005996 resolveRegion.extent.width = 1;
5997 resolveRegion.extent.height = 1;
5998 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005999 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06006000 EndCommandBuffer();
6001
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006002 if (!m_errorMonitor->DesiredMsgFound()) {
6003 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest image types.'";
6004 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06006005 }
6006
Chia-I Wu69f40122015-10-26 21:10:41 +08006007 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08006008 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08006009 vkFreeMemory(m_device->device(), srcMem, NULL);
6010 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06006011}
Tobin Ehlisb46be812015-10-23 16:00:08 -06006012
6013TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError)
6014{
6015 // Create a single Image descriptor and cause it to first hit an error due
6016 // to using a DS format, then cause it to hit error due to COLOR_BIT not set in aspect
6017 // The image format check comes 2nd in validation so we trigger it first,
6018 // then when we cause aspect fail next, bad format check will be preempted
Tobin Ehlisb46be812015-10-23 16:00:08 -06006019 VkResult err;
6020
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07006021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006022 "Combination depth/stencil image formats can have only the ");
6023
Tobin Ehlisb46be812015-10-23 16:00:08 -06006024 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006025
Chia-I Wuc51b1212015-10-27 19:25:11 +08006026 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06006027 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu763a7492015-10-26 20:48:51 +08006028 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006029
6030 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6031 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6032 ds_pool_ci.pNext = NULL;
6033 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08006034 ds_pool_ci.poolSizeCount = 1;
6035 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006036
6037 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08006038 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006039 ASSERT_VK_SUCCESS(err);
6040
6041 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08006042 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006043 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu045654f2015-11-06 06:42:02 +08006044 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006045 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6046 dsl_binding.pImmutableSamplers = NULL;
6047
6048 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6049 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6050 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08006051 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08006052 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006053 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08006054 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006055 ASSERT_VK_SUCCESS(err);
6056
6057 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08006058 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08006059 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08006060 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006061 alloc_info.descriptorPool = ds_pool;
6062 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08006063 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006064 ASSERT_VK_SUCCESS(err);
6065
6066 VkImage image_bad;
6067 VkImage image_good;
6068 // One bad format and one good format for Color attachment
6069 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
6070 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
6071 const int32_t tex_width = 32;
6072 const int32_t tex_height = 32;
6073
6074 VkImageCreateInfo image_create_info = {};
6075 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6076 image_create_info.pNext = NULL;
6077 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6078 image_create_info.format = tex_format_bad;
6079 image_create_info.extent.width = tex_width;
6080 image_create_info.extent.height = tex_height;
6081 image_create_info.extent.depth = 1;
6082 image_create_info.mipLevels = 1;
6083 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08006084 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006085 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6086 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
6087 image_create_info.flags = 0;
6088
Chia-I Wu69f40122015-10-26 21:10:41 +08006089 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006090 ASSERT_VK_SUCCESS(err);
6091 image_create_info.format = tex_format_good;
6092 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu69f40122015-10-26 21:10:41 +08006093 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006094 ASSERT_VK_SUCCESS(err);
6095
6096 VkImageViewCreateInfo image_view_create_info = {};
6097 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6098 image_view_create_info.image = image_bad;
6099 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6100 image_view_create_info.format = tex_format_bad;
6101 image_view_create_info.subresourceRange.baseArrayLayer = 0;
6102 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08006103 image_view_create_info.subresourceRange.layerCount = 1;
6104 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006105 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6106
6107 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08006108 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006109
6110 if (!m_errorMonitor->DesiredMsgFound()) {
6111 FAIL() << "Did not receive Error 'Combination depth-stencil image formats can have only the....'";
6112 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06006113 }
6114
Chia-I Wu69f40122015-10-26 21:10:41 +08006115 vkDestroyImage(m_device->device(), image_bad, NULL);
6116 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08006117 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6118 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006119}
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06006120#endif // IMAGE_TESTS
6121
Tony Barbour30486ea2015-04-07 13:44:53 -06006122int main(int argc, char **argv) {
6123 int result;
6124
6125 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06006126 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06006127
6128 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
6129
6130 result = RUN_ALL_TESTS();
6131
Tony Barbour01999182015-04-09 12:58:51 -06006132 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06006133 return result;
6134}