blob: f79e58d91db28d8fa06f0e14e07a2310d02b3f86 [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>
David Pinedoa31fe0b2015-11-24 09:00:24 -070033#include "vulkan/vk_lunarg_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,
104 VkDbgObjectType objType,
105 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600106 size_t location,
107 int32_t msgCode,
108 const char* pLayerPrefix,
109 const char* pMsg,
110 void* pUserData);
Tony Barbour30486ea2015-04-07 13:44:53 -0600111
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600112// ********************************************************
113// ErrorMonitor Usage:
114//
115// Call SetDesiredFailureMsg with a string to be compared against all
116// encountered log messages. Passing NULL will match all log messages.
117// logMsg will return true for skipCall only if msg is matched or NULL.
118//
119// Call DesiredMsgFound to determine if the desired failure message
120// was encountered.
121
Tony Barbour30486ea2015-04-07 13:44:53 -0600122class ErrorMonitor {
123public:
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600124 ErrorMonitor()
Tony Barbour30486ea2015-04-07 13:44:53 -0600125 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600126 test_platform_thread_create_mutex(&m_mutex);
127 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600128 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600129 m_bailout = NULL;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600130 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -0600131 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600132
133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -0600134 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600135 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600136 m_desiredMsg.clear();
137 m_failureMsg.clear();
138 m_otherMsgs.clear();
139 m_desiredMsg = msgString;
140 m_msgFound = VK_FALSE;
141 m_msgFlags = msgFlags;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600142 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -0600143 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600144
145 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -0600146 {
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600147 VkBool32 result = VK_FALSE;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600148 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600149 if (m_bailout != NULL) {
150 *m_bailout = true;
151 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600152 string errorString(msgString);
153 if (msgFlags & m_msgFlags) {
154 if (errorString.find(m_desiredMsg) != string::npos) {
155 m_failureMsg = errorString;
156 m_msgFound = VK_TRUE;
157 result = VK_TRUE;
158 } else {
159 m_otherMsgs.push_back(errorString);
160 }
161 }
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600162 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600163 return result;
Mike Stroyan09aae812015-05-12 16:00:45 -0600164 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600165
166 vector<string> GetOtherFailureMsgs(void)
167 {
168 return m_otherMsgs;
169 }
170
171 string GetFailureMsg(void)
172 {
173 return m_failureMsg;
174 }
175
176 VkBool32 DesiredMsgFound(void)
177 {
178 return m_msgFound;
179 }
180
Mike Stroyan09aae812015-05-12 16:00:45 -0600181 void SetBailout(bool *bailout)
182 {
183 m_bailout = bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600184 }
185
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600186 void DumpFailureMsgs(void)
187 {
188 vector<string> otherMsgs = GetOtherFailureMsgs();
189 cout << "Other error messages logged for this test were:" << endl;
190 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
191 cout << " " << *iter << endl;
192 }
193 }
194
Tony Barbour30486ea2015-04-07 13:44:53 -0600195private:
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600196 VkFlags m_msgFlags;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600197 string m_desiredMsg;
198 string m_failureMsg;
199 vector<string> m_otherMsgs;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600200 test_platform_thread_mutex m_mutex;
201 bool* m_bailout;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600202 VkBool32 m_msgFound;
Tony Barbour30486ea2015-04-07 13:44:53 -0600203};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500204
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600205static VkBool32 myDbgFunc(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600206 VkFlags msgFlags,
Tony Barboure84a8d62015-07-10 14:10:27 -0600207 VkDbgObjectType objType,
208 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600209 size_t location,
210 int32_t msgCode,
211 const char* pLayerPrefix,
212 const char* pMsg,
213 void* pUserData)
Tony Barbour30486ea2015-04-07 13:44:53 -0600214{
Tony Barbour192f02b2015-11-06 14:21:31 -0700215 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_PERF_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour8508b8e2015-04-09 10:48:04 -0600216 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600217 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour8508b8e2015-04-09 10:48:04 -0600218 }
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600219 return false;
Tony Barbour30486ea2015-04-07 13:44:53 -0600220}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500221
Tony Barbour01999182015-04-09 12:58:51 -0600222class VkLayerTest : public VkRenderFramework
Tony Barbour30486ea2015-04-07 13:44:53 -0600223{
224public:
Chia-I Wu1f851912015-10-27 18:04:07 +0800225 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
226 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500227 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
Chia-I Wu1f851912015-10-27 18:04:07 +0800228 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbour1490c912015-07-28 10:17:20 -0600229 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
Chia-I Wu1f851912015-10-27 18:04:07 +0800230 { GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600231
Tony Barbour1490c912015-07-28 10:17:20 -0600232 /* Convenience functions that use built-in command buffer */
Chia-I Wu1f851912015-10-27 18:04:07 +0800233 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
234 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600235 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
Chia-I Wu1f851912015-10-27 18:04:07 +0800236 { m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance); }
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600237 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
Chia-I Wu1f851912015-10-27 18:04:07 +0800238 { m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); }
239 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
240 void QueueCommandBuffer(const VkFence& fence) { m_commandBuffer->QueueCommandBuffer(fence); }
Tony Barbour1490c912015-07-28 10:17:20 -0600241 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
Chia-I Wu1f851912015-10-27 18:04:07 +0800242 { m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
Tony Barbour1490c912015-07-28 10:17:20 -0600243 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
Chia-I Wu1f851912015-10-27 18:04:07 +0800244 { m_commandBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600245protected:
Tony Barbour01999182015-04-09 12:58:51 -0600246 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600247
248 virtual void SetUp() {
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600249 std::vector<const char *> instance_layer_names;
250 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600251 std::vector<const char *> instance_extension_names;
252 std::vector<const char *> device_extension_names;
Tony Barbour950ebc02015-04-23 12:55:36 -0600253
Courtney Goeltzenleuchter846298c2015-07-30 11:32:46 -0600254 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600255 /*
256 * Since CreateDbgMsgCallback is an instance level extension call
257 * any extension / layer that utilizes that feature also needs
258 * to be enabled at create instance time.
259 */
Chia-I Wu1f851912015-10-27 18:04:07 +0800260 // Use Threading layer first to protect others from ThreadCommandBufferCollision test
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
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600473 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Resetting CB");
474
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
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600519 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Calling vkBeginCommandBuffer() on active CB");
520
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
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600572 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
573 "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//
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600649// m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
650// "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
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600718 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
719 "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
794 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
795 "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
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600838 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
839 "submitted to VkResetFences in UNSIGNALED STATE");
840
Tony Barbour8508b8e2015-04-09 10:48:04 -0600841 ASSERT_NO_FATAL_FAILURE(InitState());
842 testFence.init(*m_device, fenceInfo);
Chia-I Wua4992342015-07-03 11:45:55 +0800843 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600844 vkResetFences(m_device->device(), 1, fences);
Tony Barbour30486ea2015-04-07 13:44:53 -0600845
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600846 if (!m_errorMonitor->DesiredMsgFound()) {
847 FAIL() << "Did not receive Error 'VkResetFences with fence in UNSIGNALED_STATE'";
848 m_errorMonitor->DumpFailureMsgs();
849 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600850}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600851
Chia-I Wuc278df82015-07-07 11:50:03 +0800852/* TODO: Update for changes due to bug-14075 tiling across render passes */
853#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600854TEST_F(VkLayerTest, InvalidUsageBits)
855{
856 // Initiate Draw w/o a PSO bound
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600857
858 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
859 "Invalid usage flag for image ");
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600860
861 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +0800862 VkCommandBufferObj commandBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600863 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600864
865 const VkExtent3D e3d = {
866 .width = 128,
867 .height = 128,
868 .depth = 1,
869 };
870 const VkImageCreateInfo ici = {
871 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
872 .pNext = NULL,
873 .imageType = VK_IMAGE_TYPE_2D,
874 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
875 .extent = e3d,
876 .mipLevels = 1,
877 .arraySize = 1,
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800878 .samples = VK_SAMPLE_COUNT_1_BIT,
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600879 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchterc3b8eea2015-09-10 14:14:11 -0600880 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600881 .flags = 0,
882 };
883
884 VkImage dsi;
Chia-I Wu69f40122015-10-26 21:10:41 +0800885 vkCreateImage(m_device->device(), &ici, NULL, &dsi);
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600886 VkDepthStencilView dsv;
887 const VkDepthStencilViewCreateInfo dsvci = {
888 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
889 .pNext = NULL,
890 .image = dsi,
891 .mipLevel = 0,
Courtney Goeltzenleuchter3dee8082015-09-10 16:38:41 -0600892 .baseArrayLayer = 0,
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600893 .arraySize = 1,
894 .flags = 0,
895 };
Chia-I Wu69f40122015-10-26 21:10:41 +0800896 vkCreateDepthStencilView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600897
898 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600899 FAIL() << "Error received was not 'Invalid usage flag for image...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600900 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600901 }
902}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600903#endif // 0
904#endif // MEM_TRACKER_TESTS
905
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600906#if OBJ_TRACKER_TESTS
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600907TEST_F(VkLayerTest, PipelineNotBound)
908{
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600909 VkResult err;
910
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600911 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
912 "Invalid VkPipeline Object ");
913
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600914 ASSERT_NO_FATAL_FAILURE(InitState());
915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600916
Chia-I Wuc51b1212015-10-27 19:25:11 +0800917 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600918 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +0800919 ds_type_count.descriptorCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600920
921 VkDescriptorPoolCreateInfo ds_pool_ci = {};
922 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
923 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600924 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +0800925 ds_pool_ci.poolSizeCount = 1;
926 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600927
928 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +0800929 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600930 ASSERT_VK_SUCCESS(err);
931
932 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +0800933 dsl_binding.binding = 0;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600934 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +0800935 dsl_binding.descriptorCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600936 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
937 dsl_binding.pImmutableSamplers = NULL;
938
939 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
940 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
941 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800942 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +0800943 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600944
945 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +0800946 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600947 ASSERT_VK_SUCCESS(err);
948
949 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +0800950 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +0800951 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +0800952 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -0600953 alloc_info.descriptorPool = ds_pool;
954 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +0800955 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600956 ASSERT_VK_SUCCESS(err);
957
958 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
959 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
960 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800961 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600962 pipeline_layout_ci.pSetLayouts = &ds_layout;
963
964 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +0800965 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600966 ASSERT_VK_SUCCESS(err);
967
968 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
969
970 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800971 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600972
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600973 if (!m_errorMonitor->DesiredMsgFound()) {
974 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be'" << endl;
975 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600976 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600977
Chia-I Wu69f40122015-10-26 21:10:41 +0800978 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
979 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
980 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600981}
982
983TEST_F(VkLayerTest, BindInvalidMemory)
984{
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600985 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600986 bool pass;
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600987
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600988 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
989 "Invalid VkDeviceMemory Object ");
990
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600991 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600992
993 // Create an image, allocate memory, free it, and then try to bind it
994 VkImage image;
995 VkDeviceMemory mem;
996 VkMemoryRequirements mem_reqs;
997
998 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
999 const int32_t tex_width = 32;
1000 const int32_t tex_height = 32;
1001
1002 VkImageCreateInfo image_create_info = {};
1003 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1004 image_create_info.pNext = NULL;
1005 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1006 image_create_info.format = tex_format;
1007 image_create_info.extent.width = tex_width;
1008 image_create_info.extent.height = tex_height;
1009 image_create_info.extent.depth = 1;
1010 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06001011 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001012 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001013 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1014 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1015 image_create_info.flags = 0;
1016
Chia-I Wu1f851912015-10-27 18:04:07 +08001017 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001018 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001019 mem_alloc.pNext = NULL;
1020 mem_alloc.allocationSize = 0;
1021 mem_alloc.memoryTypeIndex = 0;
1022
Chia-I Wu69f40122015-10-26 21:10:41 +08001023 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001024 ASSERT_VK_SUCCESS(err);
1025
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06001026 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001027 image,
1028 &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001029
1030 mem_alloc.allocationSize = mem_reqs.size;
1031
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001032 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1033 ASSERT_TRUE(pass);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001034
1035 // allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08001036 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001037 ASSERT_VK_SUCCESS(err);
1038
1039 // Introduce validation failure, free memory before binding
Chia-I Wu69f40122015-10-26 21:10:41 +08001040 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001041
1042 // Try to bind free memory that has been freed
1043 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1044 // This may very well return an error.
1045 (void)err;
1046
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001047 if (!m_errorMonitor->DesiredMsgFound()) {
1048 FAIL() << "Did not receive Error 'Invalid VkDeviceMemory Object 0x<handle>'";
1049 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001050 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001051
Chia-I Wu69f40122015-10-26 21:10:41 +08001052 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001053}
1054
1055TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
1056{
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001057 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001058 bool pass;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001059
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001060 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Invalid VkImage Object ");
1061
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001062 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001063
1064 // Create an image object, allocate memory, destroy the object and then try to bind it
1065 VkImage image;
1066 VkDeviceMemory mem;
1067 VkMemoryRequirements mem_reqs;
1068
1069 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1070 const int32_t tex_width = 32;
1071 const int32_t tex_height = 32;
1072
1073 VkImageCreateInfo image_create_info = {};
1074 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1075 image_create_info.pNext = NULL;
1076 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1077 image_create_info.format = tex_format;
1078 image_create_info.extent.width = tex_width;
1079 image_create_info.extent.height = tex_height;
1080 image_create_info.extent.depth = 1;
1081 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06001082 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001083 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001084 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1085 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1086 image_create_info.flags = 0;
1087
Chia-I Wu1f851912015-10-27 18:04:07 +08001088 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001089 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001090 mem_alloc.pNext = NULL;
1091 mem_alloc.allocationSize = 0;
1092 mem_alloc.memoryTypeIndex = 0;
1093
Chia-I Wu69f40122015-10-26 21:10:41 +08001094 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001095 ASSERT_VK_SUCCESS(err);
1096
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06001097 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001098 image,
1099 &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001100
1101 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001102 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1103 ASSERT_TRUE(pass);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001104
1105 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08001106 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001107 ASSERT_VK_SUCCESS(err);
1108
1109 // Introduce validation failure, destroy Image object before binding
Chia-I Wu69f40122015-10-26 21:10:41 +08001110 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001111 ASSERT_VK_SUCCESS(err);
1112
1113 // Now Try to bind memory to this destroyed object
1114 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1115 // This may very well return an error.
1116 (void) err;
1117
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001118 if (!m_errorMonitor->DesiredMsgFound()) {
1119 FAIL() << "Did not receive Error 'Invalid VkImage Object 0x<handle>'";
1120 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001121 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001122
Chia-I Wu69f40122015-10-26 21:10:41 +08001123 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001124}
Tobin Ehlisb46be812015-10-23 16:00:08 -06001125
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001126#endif // OBJ_TRACKER_TESTS
1127
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001128#if DRAW_STATE_TESTS
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001129TEST_F(VkLayerTest, LineWidthStateNotBound)
1130{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001131 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1132 "Dynamic line width state not set for this command buffer");
1133
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001134 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
1135
1136 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
1137
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001138 if (!m_errorMonitor->DesiredMsgFound()) {
1139 FAIL() << "Did not receive Error 'Dynamic line width state not set for this command buffer'";
1140 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001141 }
1142}
1143
1144TEST_F(VkLayerTest, DepthBiasStateNotBound)
1145{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001146 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1147 "Dynamic depth bias state not set for this command buffer");
1148
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001149 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
1150
1151 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
1152
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001153 if (!m_errorMonitor->DesiredMsgFound()) {
1154 FAIL() << "Did not receive Error 'Dynamic depth bias state not set for this command buffer'";
1155 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001156 }
1157}
1158
Cody Northropbca3bcd2015-10-27 16:54:28 -06001159// Disable these two tests until we can sort out how to track multiple layer errors
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001160TEST_F(VkLayerTest, ViewportStateNotBound)
1161{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001162 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1163 "Dynamic viewport state not set for this command buffer");
1164
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001165 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1166
1167 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1168
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001169 if (!m_errorMonitor->DesiredMsgFound()) {
1170 FAIL() << "Did not recieve Error 'Dynamic scissor state not set for this command buffer'";
1171 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001172 }
1173}
1174
1175TEST_F(VkLayerTest, ScissorStateNotBound)
1176{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001177 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1178 "Dynamic scissor state not set for this command buffer");
1179
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001180 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1181
1182 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1183
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001184 if (!m_errorMonitor->DesiredMsgFound()) {
1185 FAIL() << "Did not recieve Error ' Expected: 'Dynamic scissor state not set for this command buffer'";
1186 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001187 }
1188}
1189
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001190TEST_F(VkLayerTest, BlendStateNotBound)
1191{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001192 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1193 "Dynamic blend object state not set for this command buffer");
1194
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001195 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1196
1197 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1198
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001199 if (!m_errorMonitor->DesiredMsgFound()) {
1200 FAIL() << "Did not recieve Error 'Dynamic blend object state not set for this command buffer'";
1201 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001202 }
1203}
1204
1205TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1206{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001207 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1208 "Dynamic depth bounds state not set for this command buffer");
1209
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001210 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1211
1212 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1213
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001214 if (!m_errorMonitor->DesiredMsgFound()) {
1215 FAIL() << "Did not receive Error 'Dynamic depth bounds state not set for this command buffer'";
1216 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001217 }
1218}
1219
1220TEST_F(VkLayerTest, StencilReadMaskNotSet)
1221{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001222 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1223 "Dynamic stencil read mask state not set for this command buffer");
1224
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001225 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001226
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001227 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1228
1229 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1230
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001231 if (!m_errorMonitor->DesiredMsgFound()) {
1232 FAIL() << "Did not receive Error 'Dynamic stencil read mask state not set for this command buffer'";
1233 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001234 }
1235}
1236
1237TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1238{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001239 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1240 "Dynamic stencil write mask state not set for this command buffer");
1241
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001242 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001243
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001244 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1245
1246 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1247
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001248 if (!m_errorMonitor->DesiredMsgFound()) {
1249 FAIL() << "Did not receive Error 'Dynamic stencil write mask state not set for this command buffer'";
1250 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001251 }
1252}
1253
1254TEST_F(VkLayerTest, StencilReferenceNotSet)
1255{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001256 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1257 "Dynamic stencil reference state not set for this command buffer");
1258
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001259 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1260
1261 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1262
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001263 if (!m_errorMonitor->DesiredMsgFound()) {
1264 FAIL() << "Did not receive Error 'Dynamic stencil reference state not set for this command buffer'";
1265 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001266 }
1267}
1268
Chia-I Wu1f851912015-10-27 18:04:07 +08001269TEST_F(VkLayerTest, CommandBufferTwoSubmits)
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001270{
1271 vk_testing::Fence testFence;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001272
1273 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1274 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted");
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001275
1276 VkFenceCreateInfo fenceInfo = {};
1277 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1278 fenceInfo.pNext = NULL;
1279 fenceInfo.flags = 0;
1280
1281 ASSERT_NO_FATAL_FAILURE(InitState());
1282 ASSERT_NO_FATAL_FAILURE(InitViewport());
1283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1284
Chia-I Wu1f851912015-10-27 18:04:07 +08001285 // 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 -06001286 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08001287 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001288 EndCommandBuffer();
1289
1290 testFence.init(*m_device, fenceInfo);
1291
1292 // Bypass framework since it does the waits automatically
1293 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001294 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +08001295 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1296 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001297 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001298 submit_info.pWaitSemaphores = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001299 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08001300 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +08001301 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001302 submit_info.pSignalSemaphores = NULL;
1303
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06001304 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001305 ASSERT_VK_SUCCESS( err );
1306
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001307 // Cause validation error by re-submitting cmd buffer that should only be submitted once
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06001308 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001309
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001310 if (!m_errorMonitor->DesiredMsgFound()) {
1311 FAIL() << "Did not receive Error 'CB (0xaddress) was created w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set...'";
1312 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001313 }
1314}
1315
Tobin Ehlise4076782015-06-24 15:53:07 -06001316TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001317{
1318 // Initiate Draw w/o a PSO bound
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001319 VkResult err;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001320
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001321 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1322 "Incorrectly binding graphics pipeline ");
1323
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001324 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001325 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001326
Chia-I Wuc51b1212015-10-27 19:25:11 +08001327 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001328 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001329 ds_type_count.descriptorCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001330
1331 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1332 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1333 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001334 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001335 ds_pool_ci.poolSizeCount = 1;
1336 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001337
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001338 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001339 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001340 ASSERT_VK_SUCCESS(err);
1341
1342 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001343 dsl_binding.binding = 0;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001344 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001345 dsl_binding.descriptorCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001346 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1347 dsl_binding.pImmutableSamplers = NULL;
1348
1349 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1350 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1351 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001352 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001353 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001354
1355 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001356 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001357 ASSERT_VK_SUCCESS(err);
1358
1359 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001360 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001361 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001362 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001363 alloc_info.descriptorPool = ds_pool;
1364 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001365 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001366 ASSERT_VK_SUCCESS(err);
1367 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1368 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1369 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001370 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001371 pipe_ms_state_ci.sampleShadingEnable = 0;
1372 pipe_ms_state_ci.minSampleShading = 1.0;
1373 pipe_ms_state_ci.pSampleMask = NULL;
1374
1375 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1376 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1377 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001378 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001379 pipeline_layout_ci.pSetLayouts = &ds_layout;
1380 VkPipelineLayout pipeline_layout;
1381
Chia-I Wu69f40122015-10-26 21:10:41 +08001382 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001383 ASSERT_VK_SUCCESS(err);
1384
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001385 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1386 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001387 // but add it to be able to run on more devices
1388 VkPipelineObj pipe(m_device);
1389 pipe.AddShader(&vs);
1390 pipe.AddShader(&fs);
1391 pipe.SetMSAA(&pipe_ms_state_ci);
1392 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001393
Chia-I Wu1f851912015-10-27 18:04:07 +08001394 // Calls AllocateCommandBuffers
1395 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
1396 VkCommandBufferBeginInfo cmd_buf_info = {};
1397 memset(&cmd_buf_info, 0, sizeof(VkCommandBufferBeginInfo));
1398 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001399 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08001400 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001401
Chia-I Wu1f851912015-10-27 18:04:07 +08001402 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
1403 vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001404
1405 if (!m_errorMonitor->DesiredMsgFound()) {
1406 FAIL() << "Did not receive Error 'Incorrectly binding graphics pipeline (0x<handle>) without an active RenderPass'";
1407 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001408 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001409
Chia-I Wu69f40122015-10-26 21:10:41 +08001410 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1411 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1412 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001413}
1414
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001415TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1416{
1417 // Initiate Draw w/o a PSO bound
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001418 VkResult err;
1419
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001420 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1421 "Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
1422
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001423 ASSERT_NO_FATAL_FAILURE(InitState());
1424 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001425
1426 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
Chia-I Wuc51b1212015-10-27 19:25:11 +08001427 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001428 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001429 ds_type_count.descriptorCount = 1;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001430
1431 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1432 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1433 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001434 ds_pool_ci.flags = 0;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001435 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001436 ds_pool_ci.poolSizeCount = 1;
1437 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001438
1439 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001440 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001441 ASSERT_VK_SUCCESS(err);
1442
1443 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001444 dsl_binding.binding = 0;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001445 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001446 dsl_binding.descriptorCount = 1;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001447 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1448 dsl_binding.pImmutableSamplers = NULL;
1449
1450 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1451 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1452 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001453 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001454 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001455
1456 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001457 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001458 ASSERT_VK_SUCCESS(err);
1459
1460 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001461 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001462 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001463 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001464 alloc_info.descriptorPool = ds_pool;
1465 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001466 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001467
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001468 if (!m_errorMonitor->DesiredMsgFound()) {
1469 FAIL() << "Did not receive Error 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...'";
1470 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001471 }
1472
Chia-I Wu69f40122015-10-26 21:10:41 +08001473 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1474 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001475}
1476
Tobin Ehlis3c543112015-10-08 13:13:50 -06001477TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1478{
Tobin Ehlis3c543112015-10-08 13:13:50 -06001479 VkResult err;
1480
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001481 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1482 "It is invalid to call vkFreeDescriptorSets() with a pool created without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
1483
Tobin Ehlis3c543112015-10-08 13:13:50 -06001484 ASSERT_NO_FATAL_FAILURE(InitState());
1485 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis3c543112015-10-08 13:13:50 -06001486
Chia-I Wuc51b1212015-10-27 19:25:11 +08001487 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis3c543112015-10-08 13:13:50 -06001488 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001489 ds_type_count.descriptorCount = 1;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001490
1491 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1492 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1493 ds_pool_ci.pNext = NULL;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001494 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001495 ds_pool_ci.poolSizeCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001496 ds_pool_ci.flags = 0;
1497 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
1498 // app can only call vkResetDescriptorPool on this pool.;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001499 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001500
1501 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001502 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001503 ASSERT_VK_SUCCESS(err);
1504
1505 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001506 dsl_binding.binding = 0;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001507 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001508 dsl_binding.descriptorCount = 1;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001509 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1510 dsl_binding.pImmutableSamplers = NULL;
1511
1512 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1513 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1514 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001515 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001516 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001517
1518 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001519 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001520 ASSERT_VK_SUCCESS(err);
1521
1522 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001523 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001524 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001525 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001526 alloc_info.descriptorPool = ds_pool;
1527 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001528 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001529 ASSERT_VK_SUCCESS(err);
1530
1531 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001532 if (!m_errorMonitor->DesiredMsgFound()) {
1533 FAIL() << "Did not receive Error 'It is invalid to call vkFreeDescriptorSets() with a pool created with...'";
1534 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3c543112015-10-08 13:13:50 -06001535 }
1536
Chia-I Wu69f40122015-10-26 21:10:41 +08001537 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1538 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001539}
1540
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001541TEST_F(VkLayerTest, InvalidDescriptorPool)
1542{
1543 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1544 // The DS check for this is after driver has been called to validate DS internal data struct
1545 // Attempt to clear DS Pool with bad object
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001546/*
1547 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1548 "Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call");
1549
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001550 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1551 vkResetDescriptorPool(device(), badPool);
1552
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001553 if (!m_errorMonitor->DesiredMsgFound()) {
1554 FAIL() << "Did not receive Error 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1555 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001556 }*/
1557}
1558
1559TEST_F(VkLayerTest, InvalidDescriptorSet)
1560{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001561 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1562 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001563 // Create a valid cmd buffer
1564 // call vkCmdBindDescriptorSets w/ false DS
1565}
1566
1567TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1568{
1569 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1570 // The DS check for this is after driver has been called to validate DS internal data struct
1571}
1572
1573TEST_F(VkLayerTest, InvalidPipeline)
1574{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001575 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1576 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001577 // Create a valid cmd buffer
1578 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001579//
1580// m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1581// "Attempt to bind Pipeline ");
Tobin Ehlise4076782015-06-24 15:53:07 -06001582//
1583// ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +08001584// VkCommandBufferObj commandBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001585// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001586// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Chia-I Wu1f851912015-10-27 18:04:07 +08001587// vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001588//
1589// if (!m_errorMonitor->DesiredMsgFound()) {
1590// FAIL() << "Did not receive Error 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1591// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise4076782015-06-24 15:53:07 -06001592// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001593}
1594
Tobin Ehlis254eca02015-06-25 15:46:59 -06001595TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001596{
Chia-I Wu1f851912015-10-27 18:04:07 +08001597 // Create and update CommandBuffer then call QueueSubmit w/o calling End on CommandBuffer
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001598 VkResult err;
1599
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001600 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
1601 " bound but it was never updated. ");
1602
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001603 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001604 ASSERT_NO_FATAL_FAILURE(InitViewport());
1605 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wuc51b1212015-10-27 19:25:11 +08001606 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001607 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001608 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001609
1610 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1611 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1612 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001613 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001614 ds_pool_ci.poolSizeCount = 1;
1615 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001616
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001617 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001618 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001619 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001620
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001621 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001622 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001623 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001624 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001625 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1626 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001627
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001628 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1629 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1630 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001631 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001632 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001633 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001634 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001635 ASSERT_VK_SUCCESS(err);
1636
1637 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001638 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001639 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001640 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001641 alloc_info.descriptorPool = ds_pool;
1642 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001643 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001644 ASSERT_VK_SUCCESS(err);
1645
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001646 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1647 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1648 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001649 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001650 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001651
1652 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001653 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001654 ASSERT_VK_SUCCESS(err);
1655
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001656 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001657 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
1658 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001659
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001660 VkPipelineObj pipe(m_device);
1661 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001662 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001663 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001664
1665 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08001666 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1667 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001668
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001669 if (!m_errorMonitor->DesiredMsgFound()) {
1670 FAIL() << "Did not recieve Warning 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1671 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001672 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001673
Chia-I Wu69f40122015-10-26 21:10:41 +08001674 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1675 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1676 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001677}
1678
Tobin Ehlis093ef922015-11-02 15:24:32 -07001679TEST_F(VkLayerTest, InvalidBufferViewObject)
1680{
1681 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
1682 VkResult err;
1683
1684 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1685 "Attempt to update descriptor with invalid bufferView ");
1686
1687 ASSERT_NO_FATAL_FAILURE(InitState());
1688 VkDescriptorPoolSize ds_type_count = {};
1689 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1690 ds_type_count.descriptorCount = 1;
1691
1692 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1693 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1694 ds_pool_ci.pNext = NULL;
1695 ds_pool_ci.maxSets = 1;
1696 ds_pool_ci.poolSizeCount = 1;
1697 ds_pool_ci.pPoolSizes = &ds_type_count;
1698
1699 VkDescriptorPool ds_pool;
1700 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1701 ASSERT_VK_SUCCESS(err);
1702
1703 VkDescriptorSetLayoutBinding dsl_binding = {};
1704 dsl_binding.binding = 0;
1705 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001706 dsl_binding.descriptorCount = 1;
Tobin Ehlis093ef922015-11-02 15:24:32 -07001707 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1708 dsl_binding.pImmutableSamplers = NULL;
1709
1710 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1711 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1712 ds_layout_ci.pNext = NULL;
1713 ds_layout_ci.bindingCount = 1;
1714 ds_layout_ci.pBinding = &dsl_binding;
1715 VkDescriptorSetLayout ds_layout;
1716 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1717 ASSERT_VK_SUCCESS(err);
1718
1719 VkDescriptorSet descriptorSet;
1720 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001721 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Tobin Ehlis093ef922015-11-02 15:24:32 -07001722 alloc_info.setLayoutCount = 1;
1723 alloc_info.descriptorPool = ds_pool;
1724 alloc_info.pSetLayouts = &ds_layout;
1725 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1726 ASSERT_VK_SUCCESS(err);
1727
1728 VkBufferView view = (VkBufferView) 0xbaadbeef; // invalid bufferView object
Tobin Ehlis093ef922015-11-02 15:24:32 -07001729 VkWriteDescriptorSet descriptor_write;
1730 memset(&descriptor_write, 0, sizeof(descriptor_write));
1731 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1732 descriptor_write.dstSet = descriptorSet;
1733 descriptor_write.dstBinding = 0;
1734 descriptor_write.descriptorCount = 1;
1735 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1736 descriptor_write.pTexelBufferView = &view;
1737
1738 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1739
1740 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlisd9491452015-11-05 10:27:49 -07001741 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid bufferView'";
Tobin Ehlis093ef922015-11-02 15:24:32 -07001742 m_errorMonitor->DumpFailureMsgs();
1743 }
1744
1745 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1746 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1747}
1748
Tobin Ehlise2194862015-11-04 13:30:34 -07001749TEST_F(VkLayerTest, InvalidDynamicOffsetCount)
1750{
1751 // Create a descriptorSet w/ some dynamic descriptors and then don't send offsets when binding
1752 VkResult err;
1753 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1754 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but dynamicOffsetCount is 0. ");
1755
1756 ASSERT_NO_FATAL_FAILURE(InitState());
1757 ASSERT_NO_FATAL_FAILURE(InitViewport());
1758 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1759
1760 VkDescriptorPoolSize ds_type_count = {};
1761 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1762 ds_type_count.descriptorCount = 1;
1763
1764 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1765 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1766 ds_pool_ci.pNext = NULL;
1767 ds_pool_ci.maxSets = 1;
1768 ds_pool_ci.poolSizeCount = 1;
1769 ds_pool_ci.pPoolSizes = &ds_type_count;
1770
1771 VkDescriptorPool ds_pool;
1772 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1773 ASSERT_VK_SUCCESS(err);
1774
1775 VkDescriptorSetLayoutBinding dsl_binding = {};
1776 dsl_binding.binding = 0;
1777 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
Jon Ashburn96b714a2015-11-06 15:31:44 -07001778 dsl_binding.descriptorCount = 1;
Tobin Ehlise2194862015-11-04 13:30:34 -07001779 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1780 dsl_binding.pImmutableSamplers = NULL;
1781
1782 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1783 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1784 ds_layout_ci.pNext = NULL;
1785 ds_layout_ci.bindingCount = 1;
1786 ds_layout_ci.pBinding = &dsl_binding;
1787 VkDescriptorSetLayout ds_layout;
1788 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1789 ASSERT_VK_SUCCESS(err);
1790
1791 VkDescriptorSet descriptorSet;
1792 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001793 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Tobin Ehlise2194862015-11-04 13:30:34 -07001794 alloc_info.setLayoutCount = 1;
1795 alloc_info.descriptorPool = ds_pool;
1796 alloc_info.pSetLayouts = &ds_layout;
1797 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1798 ASSERT_VK_SUCCESS(err);
1799
1800 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1801 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1802 pipeline_layout_ci.pNext = NULL;
1803 pipeline_layout_ci.setLayoutCount = 1;
1804 pipeline_layout_ci.pSetLayouts = &ds_layout;
1805
1806 VkPipelineLayout pipeline_layout;
1807 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
1808 ASSERT_VK_SUCCESS(err);
1809
1810 // Create a buffer to update the descriptor with
1811 uint32_t qfi = 0;
1812 VkBufferCreateInfo buffCI = {};
1813 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1814 buffCI.size = 1024;
1815 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1816 buffCI.queueFamilyIndexCount = 1;
1817 buffCI.pQueueFamilyIndices = &qfi;
1818
1819 VkBuffer dyub;
1820 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
1821 ASSERT_VK_SUCCESS(err);
1822 // Correctly update descriptor to avoid "NOT_UPDATED" error
1823 VkDescriptorBufferInfo buffInfo = {};
1824 buffInfo.buffer = dyub;
1825 buffInfo.offset = 0;
1826 buffInfo.range = 1024;
1827
1828 VkWriteDescriptorSet descriptor_write;
1829 memset(&descriptor_write, 0, sizeof(descriptor_write));
1830 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1831 descriptor_write.dstSet = descriptorSet;
1832 descriptor_write.dstBinding = 0;
1833 descriptor_write.descriptorCount = 1;
1834 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1835 descriptor_write.pBufferInfo = &buffInfo;
1836
1837 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1838
1839 BeginCommandBuffer();
1840 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
1841
1842 if (!m_errorMonitor->DesiredMsgFound()) {
1843 FAIL() << "Error received was not 'Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but dynamicOffsetCount is 0...'";
1844 m_errorMonitor->DumpFailureMsgs();
1845 }
1846
1847 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1848 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1849}
1850
Tobin Ehlis982099b2015-11-05 09:52:49 -07001851TEST_F(VkLayerTest, DescriptorSetCompatibility)
1852{
1853 // Test various desriptorSet errors with bad binding combinations
1854 VkResult err;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001855
1856 ASSERT_NO_FATAL_FAILURE(InitState());
1857 ASSERT_NO_FATAL_FAILURE(InitViewport());
1858 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1859
1860 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
1861 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
1862 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Tobin Ehliscb085292015-12-01 09:57:09 -07001863 ds_type_count[0].descriptorCount = 10;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001864 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1865 ds_type_count[1].descriptorCount = 2;
1866 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
1867 ds_type_count[2].descriptorCount = 2;
1868 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
1869 ds_type_count[3].descriptorCount = 5;
1870 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT type
1871 //ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
1872 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1873 ds_type_count[4].descriptorCount = 2;
1874
1875 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1876 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1877 ds_pool_ci.pNext = NULL;
1878 ds_pool_ci.maxSets = 1;
1879 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
1880 ds_pool_ci.pPoolSizes = ds_type_count;
1881
1882 VkDescriptorPool ds_pool;
1883 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1884 ASSERT_VK_SUCCESS(err);
1885
1886 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
1887 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
1888 dsl_binding[0].binding = 0;
1889 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Tobin Ehliscb085292015-12-01 09:57:09 -07001890 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001891 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
1892 dsl_binding[0].pImmutableSamplers = NULL;
1893
Tobin Ehliscb085292015-12-01 09:57:09 -07001894 // Create layout identical to set0 layout but w/ different stageFlags
1895 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
1896 dsl_fs_stage_only.binding = 0;
1897 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1898 dsl_fs_stage_only.descriptorCount = 5;
1899 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at bind time
1900 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001901 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1902 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1903 ds_layout_ci.pNext = NULL;
1904 ds_layout_ci.bindingCount = 1;
1905 ds_layout_ci.pBinding = dsl_binding;
1906 static const uint32_t NUM_LAYOUTS = 4;
1907 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehliscb085292015-12-01 09:57:09 -07001908 VkDescriptorSetLayout ds_layout_fs_only = {};
1909 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only layout for error case
Tobin Ehlis982099b2015-11-05 09:52:49 -07001910 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
1911 ASSERT_VK_SUCCESS(err);
Tobin Ehliscb085292015-12-01 09:57:09 -07001912 ds_layout_ci.pBinding = &dsl_fs_stage_only;
1913 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
1914 ASSERT_VK_SUCCESS(err);
Tobin Ehlis982099b2015-11-05 09:52:49 -07001915 dsl_binding[0].binding = 0;
1916 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehliscb085292015-12-01 09:57:09 -07001917 dsl_binding[0].descriptorCount = 2;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001918 dsl_binding[0].binding = 1;
1919 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehliscb085292015-12-01 09:57:09 -07001920 dsl_binding[0].descriptorCount = 2;
1921 ds_layout_ci.pBinding = dsl_binding;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001922 ds_layout_ci.bindingCount = 2;
1923 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
1924 ASSERT_VK_SUCCESS(err);
1925 dsl_binding[0].binding = 0;
1926 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehliscb085292015-12-01 09:57:09 -07001927 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001928 ds_layout_ci.bindingCount = 1;
1929 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
1930 ASSERT_VK_SUCCESS(err);
1931 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehliscb085292015-12-01 09:57:09 -07001932 dsl_binding[0].descriptorCount = 2;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001933 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
1934 ASSERT_VK_SUCCESS(err);
1935
1936 static const uint32_t NUM_SETS = 4;
1937 VkDescriptorSet descriptorSet[NUM_SETS] = {};
1938 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehliscb085292015-12-01 09:57:09 -07001939 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Tobin Ehlis982099b2015-11-05 09:52:49 -07001940 alloc_info.setLayoutCount = NUM_LAYOUTS;
1941 alloc_info.descriptorPool = ds_pool;
1942 alloc_info.pSetLayouts = ds_layout;
1943 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
1944 ASSERT_VK_SUCCESS(err);
Tobin Ehliscb085292015-12-01 09:57:09 -07001945 VkDescriptorSet ds0_fs_only = {};
1946 alloc_info.setLayoutCount = 1;
1947 alloc_info.pSetLayouts = &ds_layout_fs_only;
1948 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
1949 ASSERT_VK_SUCCESS(err);
Tobin Ehlis982099b2015-11-05 09:52:49 -07001950
1951 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1952 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1953 pipeline_layout_ci.pNext = NULL;
1954 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
1955 pipeline_layout_ci.pSetLayouts = ds_layout;
1956
1957 VkPipelineLayout pipeline_layout;
1958 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
1959 ASSERT_VK_SUCCESS(err);
Tobin Ehliscb085292015-12-01 09:57:09 -07001960 // Create pipelineLayout with only one setLayout
1961 pipeline_layout_ci.setLayoutCount = 1;
1962 VkPipelineLayout single_pipe_layout;
1963 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
1964 ASSERT_VK_SUCCESS(err);
1965 // Create pipelineLayout with 2 descriptor setLayout at index 0
1966 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
1967 VkPipelineLayout pipe_layout_one_desc;
1968 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
1969 ASSERT_VK_SUCCESS(err);
1970 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
1971 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
1972 VkPipelineLayout pipe_layout_five_samp;
1973 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
1974 ASSERT_VK_SUCCESS(err);
1975 // Create pipelineLayout with UB type, but stageFlags for FS only
1976 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
1977 VkPipelineLayout pipe_layout_fs_only;
1978 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
1979 ASSERT_VK_SUCCESS(err);
1980 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
1981 VkDescriptorSetLayout pl_bad_s0[2] = {};
1982 pl_bad_s0[0] = ds_layout_fs_only;
1983 pl_bad_s0[1] = ds_layout[1];
1984 pipeline_layout_ci.setLayoutCount = 2;
1985 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
1986 VkPipelineLayout pipe_layout_bad_set0;
1987 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
1988 ASSERT_VK_SUCCESS(err);
Tobin Ehlis982099b2015-11-05 09:52:49 -07001989
1990 // Create a buffer to update the descriptor with
1991 uint32_t qfi = 0;
1992 VkBufferCreateInfo buffCI = {};
1993 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1994 buffCI.size = 1024;
1995 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1996 buffCI.queueFamilyIndexCount = 1;
1997 buffCI.pQueueFamilyIndices = &qfi;
1998
1999 VkBuffer dyub;
2000 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
2001 ASSERT_VK_SUCCESS(err);
2002 // Correctly update descriptor to avoid "NOT_UPDATED" error
2003 static const uint32_t NUM_BUFFS = 5;
2004 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
2005 for (uint32_t i=0; i<NUM_BUFFS; ++i) {
2006 buffInfo[i].buffer = dyub;
2007 buffInfo[i].offset = 0;
2008 buffInfo[i].range = 1024;
2009 }
Tobin Ehliscb085292015-12-01 09:57:09 -07002010 VkImage image;
2011 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2012 const int32_t tex_width = 32;
2013 const int32_t tex_height = 32;
2014 VkImageCreateInfo image_create_info = {};
2015 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2016 image_create_info.pNext = NULL;
2017 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2018 image_create_info.format = tex_format;
2019 image_create_info.extent.width = tex_width;
2020 image_create_info.extent.height = tex_height;
2021 image_create_info.extent.depth = 1;
2022 image_create_info.mipLevels = 1;
2023 image_create_info.arrayLayers = 1;
2024 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2025 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2026 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2027 image_create_info.flags = 0;
2028 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2029 ASSERT_VK_SUCCESS(err);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002030
Tobin Ehliscb085292015-12-01 09:57:09 -07002031 VkImageViewCreateInfo image_view_create_info = {};
2032 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2033 image_view_create_info.image = image;
2034 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
2035 image_view_create_info.format = tex_format;
2036 image_view_create_info.subresourceRange.layerCount = 1;
2037 image_view_create_info.subresourceRange.baseMipLevel = 0;
2038 image_view_create_info.subresourceRange.levelCount = 1;
2039 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis982099b2015-11-05 09:52:49 -07002040
Tobin Ehliscb085292015-12-01 09:57:09 -07002041 VkImageView view;
2042 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
2043 ASSERT_VK_SUCCESS(err);
2044 VkDescriptorImageInfo imageInfo[2] = {};
2045 imageInfo[0].imageView = view;
2046 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2047 imageInfo[1].imageView = view;
2048 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2049
2050 static const uint32_t NUM_SET_UPDATES = 3;
2051 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
2052 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2053 descriptor_write[0].dstSet = descriptorSet[0];
2054 descriptor_write[0].dstBinding = 0;
2055 descriptor_write[0].descriptorCount = 5;
2056 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2057 descriptor_write[0].pBufferInfo = buffInfo;
2058 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2059 descriptor_write[1].dstSet = descriptorSet[1];
2060 descriptor_write[1].dstBinding = 0;
2061 descriptor_write[1].descriptorCount = 2;
2062 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
2063 descriptor_write[1].pImageInfo = imageInfo;
2064 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2065 descriptor_write[2].dstSet = descriptorSet[1];
2066 descriptor_write[2].dstBinding = 1;
2067 descriptor_write[2].descriptorCount = 2;
2068 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
2069 descriptor_write[2].pImageInfo = imageInfo;
2070
2071 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002072
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002073 // Create PSO to be used for draw-time errors below
2074 char const *vsSource =
2075 "#version 140\n"
2076 "#extension GL_ARB_separate_shader_objects: require\n"
2077 "#extension GL_ARB_shading_language_420pack: require\n"
2078 "\n"
2079 "void main(){\n"
2080 " gl_Position = vec4(1);\n"
2081 "}\n";
2082 char const *fsSource =
2083 "#version 140\n"
2084 "#extension GL_ARB_separate_shader_objects: require\n"
2085 "#extension GL_ARB_shading_language_420pack: require\n"
2086 "\n"
2087 "layout(location=0) out vec4 x;\n"
2088 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
2089 "void main(){\n"
2090 " x = vec4(bar.y);\n"
2091 "}\n";
2092 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2093 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002094 VkPipelineObj pipe(m_device);
2095 pipe.AddShader(&vs);
2096 pipe.AddShader(&fs);
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002097 pipe.AddColorAttachment();
2098 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis982099b2015-11-05 09:52:49 -07002099
2100 BeginCommandBuffer();
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002101
Tobin Ehlis982099b2015-11-05 09:52:49 -07002102 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2103 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding of PSO
2104 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of cmd_pipeline.c
2105 // due to the fact that cmd_alloc_dset_data() has not been called in cmd_bind_graphics_pipeline()
2106 // TODO : Want to cause various binding incompatibility issues here to test DrawState
2107 // First cause various verify_layout_compatibility() fails
2108 // Second disturb early and late sets and verify INFO msgs
Tobin Ehliscb085292015-12-01 09:57:09 -07002109 // verify_set_layout_compatibility fail cases:
2110 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
2111 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, " due to: invalid VkPipelineLayout ");
2112 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, (VkPipelineLayout)0xbaadb1be, 0, 1, &descriptorSet[0], 0, NULL);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002113 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehliscb085292015-12-01 09:57:09 -07002114 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSets with invalid VkPipelineLayout.";
Tobin Ehlis982099b2015-11-05 09:52:49 -07002115 m_errorMonitor->DumpFailureMsgs();
2116 }
Tobin Ehliscb085292015-12-01 09:57:09 -07002117 // 2. layoutIndex exceeds # of layouts in layout
2118 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, " attempting to bind set to index 1");
2119 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2, &descriptorSet[0], 0, NULL);
2120 if (!m_errorMonitor->DesiredMsgFound()) {
2121 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSet to index 1 when pipelineLayout only has index 0.";
2122 m_errorMonitor->DumpFailureMsgs();
2123 }
2124 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
2125 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 descriptors
2126 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, ", but corresponding set being bound has 5 descriptors.");
2127 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
2128 if (!m_errorMonitor->DesiredMsgFound()) {
2129 FAIL() << "Did not receive correct error msg when attempting to bind descriptorSet w/ 5 descriptors to pipelineLayout with only 2 descriptors.";
2130 m_errorMonitor->DumpFailureMsgs();
2131 }
2132 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
2133 // 4. same # of descriptors but mismatch in type
2134 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, " descriptor from pipelineLayout is type 'VK_DESCRIPTOR_TYPE_SAMPLER'");
2135 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
2136 if (!m_errorMonitor->DesiredMsgFound()) {
2137 FAIL() << "Did not receive correct error msg when attempting to bind UNIFORM_BUFFER descriptorSet to pipelineLayout with overlapping SAMPLER type.";
2138 m_errorMonitor->DumpFailureMsgs();
2139 }
2140 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
2141 // 5. same # of descriptors but mismatch in stageFlags
2142 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, " descriptor from pipelineLayout has stageFlags ");
2143 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
2144 if (!m_errorMonitor->DesiredMsgFound()) {
2145 FAIL() << "Did not receive correct error msg when attempting to bind UNIFORM_BUFFER descriptorSet with ALL stageFlags to pipelineLayout with FS-only stageFlags.";
2146 m_errorMonitor->DumpFailureMsgs();
2147 }
2148 // Cause INFO messages due to disturbing previously bound Sets
2149 // First bind sets 0 & 1
2150 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2151 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
2152 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_PERF_WARN_BIT, " previously bound as set #0 was disturbed ");
2153 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
2154 if (!m_errorMonitor->DesiredMsgFound()) {
2155 FAIL() << "Did not receive correct info msg when binding Set1 w/ pipelineLayout that should disturb Set0.";
2156 m_errorMonitor->DumpFailureMsgs();
2157 }
2158 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
2159 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2160 // 2. Disturb set after last bound set
2161 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_PERF_WARN_BIT, " newly bound as set #0 so set #1 and any subsequent sets were disturbed ");
2162 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
2163 if (!m_errorMonitor->DesiredMsgFound()) {
2164 FAIL() << "Did not receive correct info msg when re-binding Set0 w/ pipelineLayout that should disturb Set1.";
2165 m_errorMonitor->DumpFailureMsgs();
2166 }
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002167
2168 // Cause draw-time errors due to PSO incompatibilities
2169 // 1. Error due to not binding required set (we actually use same code as above to disturb set0)
2170 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2171 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
2172 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, " uses set #0 but that set is not bound.");
2173 Draw(1, 0, 0, 0);
2174 if (!m_errorMonitor->DesiredMsgFound()) {
2175 FAIL() << "Did not receive correct error msg when attempting draw requiring Set0 but Set0 is not bound.";
2176 m_errorMonitor->DumpFailureMsgs();
2177 }
2178 // 2. Error due to bound set not being compatible with PSO's VkPipelineLayout (diff stageFlags in this case)
2179 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2, &descriptorSet[0], 0, NULL);
2180 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, " bound as set #0 is not compatible with ");
2181 Draw(1, 0, 0, 0);
2182 if (!m_errorMonitor->DesiredMsgFound()) {
2183 FAIL() << "Did not receive correct error msg when attempted draw where bound Set0 layout is not compatible PSO Set0 layout.";
2184 m_errorMonitor->DumpFailureMsgs();
2185 }
Tobin Ehliscb085292015-12-01 09:57:09 -07002186 // Remaining clean-up
2187 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
2188 for (uint32_t i=0; i<NUM_LAYOUTS; ++i) {
2189 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
2190 }
2191 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
2192 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, descriptorSet);
2193 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002194 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2195 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
2196}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002197
Chia-I Wu1f851912015-10-27 18:04:07 +08002198TEST_F(VkLayerTest, NoBeginCommandBuffer)
Tobin Ehlis254eca02015-06-25 15:46:59 -06002199{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002200
2201 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2202 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlis254eca02015-06-25 15:46:59 -06002203
2204 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +08002205 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002206 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu1f851912015-10-27 18:04:07 +08002207 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002208
2209 if (!m_errorMonitor->DesiredMsgFound()) {
2210 FAIL() << "Did not recieve Error 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
2211 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06002212 }
2213}
2214
Chia-I Wu1f851912015-10-27 18:04:07 +08002215TEST_F(VkLayerTest, PrimaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002216{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002217
2218 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2219 "may not specify framebuffer or renderpass parameters");
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002220
2221 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002222
Chia-I Wu1f851912015-10-27 18:04:07 +08002223 // Calls AllocateCommandBuffers
2224 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002225
2226 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Chia-I Wu1f851912015-10-27 18:04:07 +08002227 VkCommandBufferBeginInfo cmd_buf_info = {};
2228 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06002229 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002230 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Cody Northrop10d8f982015-08-04 17:35:57 -06002231 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
2232 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
2233
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002234
2235 // The error should be caught by validation of the BeginCommandBuffer call
Chia-I Wu1f851912015-10-27 18:04:07 +08002236 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002237
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002238 if (!m_errorMonitor->DesiredMsgFound()) {
2239 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
2240 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002241 }
2242}
2243
Chia-I Wu1f851912015-10-27 18:04:07 +08002244TEST_F(VkLayerTest, SecondaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002245{
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002246 VkResult err;
Chia-I Wu1f851912015-10-27 18:04:07 +08002247 VkCommandBuffer draw_cmd;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002248
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002249 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2250 "must specify framebuffer and renderpass parameters");
2251
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002252 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002253
Chia-I Wu1f851912015-10-27 18:04:07 +08002254 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002255 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06002256 cmd.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002257 cmd.commandPool = m_commandPool;
2258 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Chia-I Wu763a7492015-10-26 20:48:51 +08002259 cmd.bufferCount = 1;
Cody Northrop10d8f982015-08-04 17:35:57 -06002260
Chia-I Wu1f851912015-10-27 18:04:07 +08002261 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyan2237f522015-08-18 14:40:24 -06002262 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002263
2264 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu1f851912015-10-27 18:04:07 +08002265 VkCommandBufferBeginInfo cmd_buf_info = {};
2266 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06002267 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002268 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002269
2270 // The error should be caught by validation of the BeginCommandBuffer call
2271 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
2272
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002273 if (!m_errorMonitor->DesiredMsgFound()) {
2274 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
2275 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002276 }
Chia-I Wu1f851912015-10-27 18:04:07 +08002277 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002278}
2279
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002280TEST_F(VkLayerTest, CommandBufferResetErrors)
2281{
2282 // Cause error due to Begin while recording CB
2283 // Then cause 2 errors for attempting to reset CB w/o having
2284 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
2285 // which CBs were allocated. Note that this bit is off by default.
2286 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2287 "Cannot call Begin on CB");
2288
2289 ASSERT_NO_FATAL_FAILURE(InitState());
2290
2291 // Calls AllocateCommandBuffers
2292 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
2293
2294 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
2295 VkCommandBufferBeginInfo cmd_buf_info = {};
2296 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2297 cmd_buf_info.pNext = NULL;
2298 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
2299
2300 // Begin CB to transition to recording state
2301 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2302 // Can't re-begin. This should trigger error
2303 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2304 if (!m_errorMonitor->DesiredMsgFound()) {
2305 FAIL() << "Did not receive Error 'Cannot call Begin on CB (0x<ADDR>) in the RECORDING state...'";
2306 m_errorMonitor->DumpFailureMsgs();
2307 }
2308 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Attempt to reset command buffer ");
2309 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
2310 // Reset attempt will trigger error due to incorrect CommandPool state
2311 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
2312 if (!m_errorMonitor->DesiredMsgFound()) {
2313 FAIL() << "Did not receive Error 'Attempt to reset command buffer (0x<ADDR>) created from command pool...'";
2314 m_errorMonitor->DumpFailureMsgs();
2315 }
2316 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, " attempts to implicitly reset cmdBuffer created from ");
2317 // Transition CB to RECORDED state
2318 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
2319 // Now attempting to Begin will implicitly reset, which triggers error
2320 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2321 if (!m_errorMonitor->DesiredMsgFound()) {
2322 FAIL() << "Did not receive Error 'Call to vkBeginCommandBuffer() on command buffer (0x<ADDR>) attempts to implicitly reset...'";
2323 m_errorMonitor->DumpFailureMsgs();
2324 }
2325}
2326
Tobin Ehlis254eca02015-06-25 15:46:59 -06002327TEST_F(VkLayerTest, InvalidPipelineCreateState)
2328{
2329 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis254eca02015-06-25 15:46:59 -06002330 VkResult err;
2331
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002332 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2333 "Invalid Pipeline CreateInfo State: Vtx Shader required");
2334
Tobin Ehlis254eca02015-06-25 15:46:59 -06002335 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002336 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002337
Chia-I Wuc51b1212015-10-27 19:25:11 +08002338 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002339 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002340 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002341
2342 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2343 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2344 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002345 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002346 ds_pool_ci.poolSizeCount = 1;
2347 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002348
Tobin Ehlis254eca02015-06-25 15:46:59 -06002349 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002350 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002351 ASSERT_VK_SUCCESS(err);
2352
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002353 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002354 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002355 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002356 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002357 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2358 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002359
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002360 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2361 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2362 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002363 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002364 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002365
Tobin Ehlis254eca02015-06-25 15:46:59 -06002366 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002367 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002368 ASSERT_VK_SUCCESS(err);
2369
2370 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002371 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002372 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002373 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002374 alloc_info.descriptorPool = ds_pool;
2375 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002376 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002377 ASSERT_VK_SUCCESS(err);
2378
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002379 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2380 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002381 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002382 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002383
2384 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002385 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002386 ASSERT_VK_SUCCESS(err);
2387
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002388 VkViewport vp = {}; // Just need dummy vp to point to
2389 VkRect2D sc = {}; // dummy scissor to point to
2390
2391 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2392 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2393 vp_state_ci.scissorCount = 1;
2394 vp_state_ci.pScissors = &sc;
2395 vp_state_ci.viewportCount = 1;
2396 vp_state_ci.pViewports = &vp;
2397
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002398 VkGraphicsPipelineCreateInfo gp_ci = {};
2399 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002400 gp_ci.pViewportState = &vp_state_ci;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002401 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2402 gp_ci.layout = pipeline_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002403 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002404
2405 VkPipelineCacheCreateInfo pc_ci = {};
2406 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Chia-I Wu7e470702015-10-26 17:24:52 +08002407 pc_ci.initialDataSize = 0;
2408 pc_ci.pInitialData = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002409
2410 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06002411 VkPipelineCache pipelineCache;
2412
Chia-I Wu69f40122015-10-26 21:10:41 +08002413 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06002414 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002415 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002416
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002417 if (!m_errorMonitor->DesiredMsgFound()) {
2418 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
2419 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06002420 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002421
Chia-I Wu69f40122015-10-26 21:10:41 +08002422 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2423 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2424 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2425 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002426}
Tobin Ehlis20693172015-09-17 08:46:18 -06002427/*// TODO : This test should be good, but needs Tess support in compiler to run
2428TEST_F(VkLayerTest, InvalidPatchControlPoints)
2429{
2430 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis20693172015-09-17 08:46:18 -06002431 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002432
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002433 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2434 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ");
2435
Tobin Ehlis20693172015-09-17 08:46:18 -06002436 ASSERT_NO_FATAL_FAILURE(InitState());
2437 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis20693172015-09-17 08:46:18 -06002438
Chia-I Wuc51b1212015-10-27 19:25:11 +08002439 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis20693172015-09-17 08:46:18 -06002440 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002441 ds_type_count.descriptorCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002442
2443 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2444 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2445 ds_pool_ci.pNext = NULL;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002446 ds_pool_ci.poolSizeCount = 1;
2447 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis20693172015-09-17 08:46:18 -06002448
2449 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002450 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 -06002451 ASSERT_VK_SUCCESS(err);
2452
2453 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002454 dsl_binding.binding = 0;
Tobin Ehlis20693172015-09-17 08:46:18 -06002455 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002456 dsl_binding.descriptorCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002457 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2458 dsl_binding.pImmutableSamplers = NULL;
2459
2460 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2461 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2462 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002463 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002464 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis20693172015-09-17 08:46:18 -06002465
2466 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002467 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis20693172015-09-17 08:46:18 -06002468 ASSERT_VK_SUCCESS(err);
2469
2470 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002471 err = vkAllocateDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis20693172015-09-17 08:46:18 -06002472 ASSERT_VK_SUCCESS(err);
2473
2474 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2475 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2476 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002477 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002478 pipeline_layout_ci.pSetLayouts = &ds_layout;
2479
2480 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002481 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis20693172015-09-17 08:46:18 -06002482 ASSERT_VK_SUCCESS(err);
2483
2484 VkPipelineShaderStageCreateInfo shaderStages[3];
2485 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
2486
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002487 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06002488 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002489 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
2490 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06002491
2492 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002493 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002494 shaderStages[0].shader = vs.handle();
2495 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002496 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002497 shaderStages[1].shader = tc.handle();
2498 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002499 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002500 shaderStages[2].shader = te.handle();
2501
2502 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
2503 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08002504 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis20693172015-09-17 08:46:18 -06002505
2506 VkPipelineTessellationStateCreateInfo tsCI = {};
2507 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
2508 tsCI.patchControlPoints = 0; // This will cause an error
2509
2510 VkGraphicsPipelineCreateInfo gp_ci = {};
2511 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2512 gp_ci.pNext = NULL;
2513 gp_ci.stageCount = 3;
2514 gp_ci.pStages = shaderStages;
2515 gp_ci.pVertexInputState = NULL;
2516 gp_ci.pInputAssemblyState = &iaCI;
2517 gp_ci.pTessellationState = &tsCI;
2518 gp_ci.pViewportState = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002519 gp_ci.pRasterizationState = NULL;
Tobin Ehlis20693172015-09-17 08:46:18 -06002520 gp_ci.pMultisampleState = NULL;
2521 gp_ci.pDepthStencilState = NULL;
2522 gp_ci.pColorBlendState = NULL;
2523 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2524 gp_ci.layout = pipeline_layout;
2525 gp_ci.renderPass = renderPass();
2526
2527 VkPipelineCacheCreateInfo pc_ci = {};
2528 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2529 pc_ci.pNext = NULL;
2530 pc_ci.initialSize = 0;
2531 pc_ci.initialData = 0;
2532 pc_ci.maxSize = 0;
2533
2534 VkPipeline pipeline;
2535 VkPipelineCache pipelineCache;
2536
Chia-I Wu69f40122015-10-26 21:10:41 +08002537 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis20693172015-09-17 08:46:18 -06002538 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002539 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis20693172015-09-17 08:46:18 -06002540
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002541 if (!m_errorMonitor->DesiredMsgFound()) {
2542 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...'";
2543 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis20693172015-09-17 08:46:18 -06002544 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002545
Chia-I Wu69f40122015-10-26 21:10:41 +08002546 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2547 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2548 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2549 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis20693172015-09-17 08:46:18 -06002550}
2551*/
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002552// Set scissor and viewport counts to different numbers
2553TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
2554{
2555 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002556 VkResult err;
2557
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002558 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2559 "Gfx Pipeline viewport count (1) must match scissor count (0).");
2560
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002561 ASSERT_NO_FATAL_FAILURE(InitState());
2562 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002563
Chia-I Wuc51b1212015-10-27 19:25:11 +08002564 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002565 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002566 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002567
2568 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2569 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002570 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002571 ds_pool_ci.poolSizeCount = 1;
2572 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002573
2574 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002575 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002576 ASSERT_VK_SUCCESS(err);
2577
2578 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002579 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002580 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002581 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002582 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2583
2584 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2585 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002586 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002587 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002588
2589 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002590 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002591 ASSERT_VK_SUCCESS(err);
2592
2593 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002594 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002595 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002596 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002597 alloc_info.descriptorPool = ds_pool;
2598 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002599 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002600 ASSERT_VK_SUCCESS(err);
2601
2602 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2603 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002604 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002605 pipeline_layout_ci.pSetLayouts = &ds_layout;
2606
2607 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002608 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002609 ASSERT_VK_SUCCESS(err);
2610
2611 VkViewport vp = {}; // Just need dummy vp to point to
2612
2613 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2614 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2615 vp_state_ci.scissorCount = 0;
2616 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2617 vp_state_ci.pViewports = &vp;
2618
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002619 VkPipelineShaderStageCreateInfo shaderStages[2];
2620 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002621
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002622 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2623 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 -06002624 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002625 shaderStages[0] = vs.GetStageCreateInfo();
2626 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002627
2628 VkGraphicsPipelineCreateInfo gp_ci = {};
2629 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002630 gp_ci.stageCount = 2;
2631 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002632 gp_ci.pViewportState = &vp_state_ci;
2633 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2634 gp_ci.layout = pipeline_layout;
2635 gp_ci.renderPass = renderPass();
2636
2637 VkPipelineCacheCreateInfo pc_ci = {};
2638 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2639
2640 VkPipeline pipeline;
2641 VkPipelineCache pipelineCache;
2642
Chia-I Wu69f40122015-10-26 21:10:41 +08002643 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002644 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002645 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002646
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002647 if (!m_errorMonitor->DesiredMsgFound()) {
2648 FAIL() << "Did not receive Error 'Gfx Pipeline viewport count (1) must match scissor count (0).'";
2649 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002650 }
2651
Chia-I Wu69f40122015-10-26 21:10:41 +08002652 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2653 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2654 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2655 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002656}
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002657// Don't set viewport state in PSO. This is an error b/c we always need this state
2658// for the counts even if the data is going to be set dynamically.
2659TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002660{
2661 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002662 VkResult err;
2663
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002664 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2665 "Gfx Pipeline pViewportState is null. Even if ");
2666
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002667 ASSERT_NO_FATAL_FAILURE(InitState());
2668 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002669
Chia-I Wuc51b1212015-10-27 19:25:11 +08002670 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002671 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002672 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002673
2674 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2675 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002676 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002677 ds_pool_ci.poolSizeCount = 1;
2678 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002679
2680 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002681 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002682 ASSERT_VK_SUCCESS(err);
2683
2684 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002685 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002686 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002687 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002688 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2689
2690 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2691 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002692 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002693 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002694
2695 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002696 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002697 ASSERT_VK_SUCCESS(err);
2698
2699 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002700 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002701 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002702 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002703 alloc_info.descriptorPool = ds_pool;
2704 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002705 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002706 ASSERT_VK_SUCCESS(err);
2707
2708 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2709 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002710 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002711 pipeline_layout_ci.pSetLayouts = &ds_layout;
2712
2713 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002714 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002715 ASSERT_VK_SUCCESS(err);
2716
2717 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2718 // Set scissor as dynamic to avoid second error
2719 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2720 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2721 dyn_state_ci.dynamicStateCount = 1;
2722 dyn_state_ci.pDynamicStates = &sc_state;
2723
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002724 VkPipelineShaderStageCreateInfo shaderStages[2];
2725 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002726
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002727 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2728 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 -06002729 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002730 shaderStages[0] = vs.GetStageCreateInfo();
2731 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002732
2733 VkGraphicsPipelineCreateInfo gp_ci = {};
2734 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002735 gp_ci.stageCount = 2;
2736 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002737 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2738 gp_ci.pDynamicState = &dyn_state_ci;
2739 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2740 gp_ci.layout = pipeline_layout;
2741 gp_ci.renderPass = renderPass();
2742
2743 VkPipelineCacheCreateInfo pc_ci = {};
2744 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2745
2746 VkPipeline pipeline;
2747 VkPipelineCache pipelineCache;
2748
Chia-I Wu69f40122015-10-26 21:10:41 +08002749 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002750 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002751 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002752
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002753 if (!m_errorMonitor->DesiredMsgFound()) {
2754 FAIL() << "Did not receive Error 'Gfx Pipeline pViewportState is null. Even if...'";
2755 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002756 }
2757
Chia-I Wu69f40122015-10-26 21:10:41 +08002758 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2759 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2760 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2761 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002762}
2763// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002764// Then run second test where dynamic scissor count doesn't match PSO scissor count
2765TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002766{
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002767 VkResult err;
2768
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002769 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2770 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
2771
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002772 ASSERT_NO_FATAL_FAILURE(InitState());
2773 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002774
Chia-I Wuc51b1212015-10-27 19:25:11 +08002775 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002776 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002777 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002778
2779 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2780 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002781 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002782 ds_pool_ci.poolSizeCount = 1;
2783 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002784
2785 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002786 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002787 ASSERT_VK_SUCCESS(err);
2788
2789 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002790 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002791 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002792 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002793 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2794
2795 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2796 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002797 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002798 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002799
2800 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002801 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002802 ASSERT_VK_SUCCESS(err);
2803
2804 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002805 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002806 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002807 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002808 alloc_info.descriptorPool = ds_pool;
2809 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002810 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002811 ASSERT_VK_SUCCESS(err);
2812
2813 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2814 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002815 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002816 pipeline_layout_ci.pSetLayouts = &ds_layout;
2817
2818 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002819 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002820 ASSERT_VK_SUCCESS(err);
2821
2822 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2823 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2824 vp_state_ci.viewportCount = 1;
2825 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2826 vp_state_ci.scissorCount = 1;
2827 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2828
2829 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2830 // Set scissor as dynamic to avoid that error
2831 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2832 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2833 dyn_state_ci.dynamicStateCount = 1;
2834 dyn_state_ci.pDynamicStates = &sc_state;
2835
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002836 VkPipelineShaderStageCreateInfo shaderStages[2];
2837 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002838
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002839 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2840 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 -06002841 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002842 shaderStages[0] = vs.GetStageCreateInfo();
2843 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002844
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002845 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2846 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2847 vi_ci.pNext = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002848 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002849 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002850 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002851 vi_ci.pVertexAttributeDescriptions = nullptr;
2852
2853 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2854 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2855 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2856
Chia-I Wu1f851912015-10-27 18:04:07 +08002857 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +08002858 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002859 rs_ci.pNext = nullptr;
2860
2861 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2862 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2863 cb_ci.pNext = nullptr;
2864
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002865 VkGraphicsPipelineCreateInfo gp_ci = {};
2866 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002867 gp_ci.stageCount = 2;
2868 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002869 gp_ci.pVertexInputState = &vi_ci;
2870 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002871 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu1f851912015-10-27 18:04:07 +08002872 gp_ci.pRasterizationState = &rs_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002873 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002874 gp_ci.pDynamicState = &dyn_state_ci;
2875 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2876 gp_ci.layout = pipeline_layout;
2877 gp_ci.renderPass = renderPass();
2878
2879 VkPipelineCacheCreateInfo pc_ci = {};
2880 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2881
2882 VkPipeline pipeline;
2883 VkPipelineCache pipelineCache;
2884
Chia-I Wu69f40122015-10-26 21:10:41 +08002885 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002886 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002887 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002888
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002889 if (!m_errorMonitor->DesiredMsgFound()) {
2890 FAIL() << "Did not recieve Error 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...'";
2891 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002892 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002893
2894
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002895 // Now hit second fail case where we set scissor w/ different count than PSO
2896 // First need to successfully create the PSO from above by setting pViewports
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002897 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2898 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.");
2899
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002900 VkViewport vp = {}; // Just need dummy vp to point to
2901 vp_state_ci.pViewports = &vp;
Chia-I Wu69f40122015-10-26 21:10:41 +08002902 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002903 ASSERT_VK_SUCCESS(err);
2904 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08002905 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002906 VkRect2D scissors[2] = {}; // don't care about data
2907 // Count of 2 doesn't match PSO count of 1
Chia-I Wu1f851912015-10-27 18:04:07 +08002908 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 2, scissors);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002909 Draw(1, 0, 0, 0);
2910
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002911 if (!m_errorMonitor->DesiredMsgFound()) {
2912 FAIL() << "Did not receive Error 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...'";
2913 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002914 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002915
Chia-I Wu69f40122015-10-26 21:10:41 +08002916 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2917 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2918 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2919 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002920}
2921// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002922// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2923TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002924{
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002925 VkResult err;
2926
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002927 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2928 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
2929
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002930 ASSERT_NO_FATAL_FAILURE(InitState());
2931 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002932
Chia-I Wuc51b1212015-10-27 19:25:11 +08002933 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002934 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002935 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002936
2937 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2938 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002939 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002940 ds_pool_ci.poolSizeCount = 1;
2941 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002942
2943 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002944 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002945 ASSERT_VK_SUCCESS(err);
2946
2947 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002948 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002949 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002950 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002951 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2952
2953 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2954 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002955 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002956 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002957
2958 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002959 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002960 ASSERT_VK_SUCCESS(err);
2961
2962 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002963 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002964 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002965 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002966 alloc_info.descriptorPool = ds_pool;
2967 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002968 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002969 ASSERT_VK_SUCCESS(err);
2970
2971 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2972 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002973 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002974 pipeline_layout_ci.pSetLayouts = &ds_layout;
2975
2976 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002977 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002978 ASSERT_VK_SUCCESS(err);
2979
2980 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2981 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2982 vp_state_ci.scissorCount = 1;
2983 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2984 vp_state_ci.viewportCount = 1;
2985 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2986
2987 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2988 // Set scissor as dynamic to avoid that error
2989 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2990 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2991 dyn_state_ci.dynamicStateCount = 1;
2992 dyn_state_ci.pDynamicStates = &vp_state;
2993
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002994 VkPipelineShaderStageCreateInfo shaderStages[2];
2995 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002996
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002997 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2998 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 -06002999 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08003000 shaderStages[0] = vs.GetStageCreateInfo();
3001 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003002
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003003 VkPipelineVertexInputStateCreateInfo vi_ci = {};
3004 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
3005 vi_ci.pNext = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08003006 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003007 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08003008 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003009 vi_ci.pVertexAttributeDescriptions = nullptr;
3010
3011 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
3012 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
3013 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
3014
Chia-I Wu1f851912015-10-27 18:04:07 +08003015 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +08003016 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003017 rs_ci.pNext = nullptr;
3018
3019 VkPipelineColorBlendStateCreateInfo cb_ci = {};
3020 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
3021 cb_ci.pNext = nullptr;
3022
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003023 VkGraphicsPipelineCreateInfo gp_ci = {};
3024 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06003025 gp_ci.stageCount = 2;
3026 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003027 gp_ci.pVertexInputState = &vi_ci;
3028 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003029 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu1f851912015-10-27 18:04:07 +08003030 gp_ci.pRasterizationState = &rs_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003031 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003032 gp_ci.pDynamicState = &dyn_state_ci;
3033 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
3034 gp_ci.layout = pipeline_layout;
3035 gp_ci.renderPass = renderPass();
3036
3037 VkPipelineCacheCreateInfo pc_ci = {};
3038 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
3039
3040 VkPipeline pipeline;
3041 VkPipelineCache pipelineCache;
3042
Chia-I Wu69f40122015-10-26 21:10:41 +08003043 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003044 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08003045 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003046
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003047 if (!m_errorMonitor->DesiredMsgFound()) {
3048 FAIL() << "Did not recieve Error 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...'";
3049 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003050 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003051
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003052 // Now hit second fail case where we set scissor w/ different count than PSO
3053 // First need to successfully create the PSO from above by setting pViewports
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003054 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3055 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.");
3056
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003057 VkRect2D sc = {}; // Just need dummy vp to point to
3058 vp_state_ci.pScissors = &sc;
Chia-I Wu69f40122015-10-26 21:10:41 +08003059 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003060 ASSERT_VK_SUCCESS(err);
3061 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08003062 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003063 VkViewport viewports[2] = {}; // don't care about data
3064 // Count of 2 doesn't match PSO count of 1
Chia-I Wu1f851912015-10-27 18:04:07 +08003065 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 2, viewports);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003066 Draw(1, 0, 0, 0);
3067
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003068 if (!m_errorMonitor->DesiredMsgFound()) {
3069 FAIL() << "Did not receive Error 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...'";
3070 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003071 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003072
Chia-I Wu69f40122015-10-26 21:10:41 +08003073 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
3074 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3075 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3076 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003077}
3078
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003079TEST_F(VkLayerTest, NullRenderPass)
3080{
3081 // Bind a NULL RenderPass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003082 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3083 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003084
3085 ASSERT_NO_FATAL_FAILURE(InitState());
3086 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003087
Tony Barbour1490c912015-07-28 10:17:20 -06003088 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003089 // Don't care about RenderPass handle b/c error should be flagged before that
Chia-I Wuc51b1212015-10-27 19:25:11 +08003090 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003091
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003092 if (!m_errorMonitor->DesiredMsgFound()) {
3093 FAIL() << "Did not receive Error 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
3094 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003095 }
3096}
3097
Tobin Ehlis254eca02015-06-25 15:46:59 -06003098TEST_F(VkLayerTest, RenderPassWithinRenderPass)
3099{
3100 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003101 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3102 "It is invalid to issue this call inside an active render pass");
Tobin Ehlis254eca02015-06-25 15:46:59 -06003103
3104 ASSERT_NO_FATAL_FAILURE(InitState());
3105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis254eca02015-06-25 15:46:59 -06003106
Tony Barbour1490c912015-07-28 10:17:20 -06003107 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003108 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003109 VkRenderPassBeginInfo rp_begin = {};
3110 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
3111 rp_begin.pNext = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003112 rp_begin.renderPass = renderPass();
3113 rp_begin.framebuffer = framebuffer();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003114
Chia-I Wuc51b1212015-10-27 19:25:11 +08003115 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06003116
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003117 if (!m_errorMonitor->DesiredMsgFound()) {
3118 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3119 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06003120 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003121}
3122
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003123TEST_F(VkLayerTest, FillBufferWithinRenderPass)
3124{
3125 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003126 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3127 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003128
3129 ASSERT_NO_FATAL_FAILURE(InitState());
3130 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003131
3132 // Renderpass is started here
3133 BeginCommandBuffer();
3134
3135 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08003136 vk_testing::Buffer dstBuffer;
3137 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003138
Chia-I Wu1f851912015-10-27 18:04:07 +08003139 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003140
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003141 if (!m_errorMonitor->DesiredMsgFound()) {
3142 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3143 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003144 }
3145}
3146
3147TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
3148{
3149 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003150 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3151 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003152
3153 ASSERT_NO_FATAL_FAILURE(InitState());
3154 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003155
3156 // Renderpass is started here
3157 BeginCommandBuffer();
3158
3159 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08003160 vk_testing::Buffer dstBuffer;
3161 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003162
Chia-I Wu1f851912015-10-27 18:04:07 +08003163 VkDeviceSize dstOffset = 0;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003164 VkDeviceSize dataSize = 1024;
3165 const uint32_t *pData = NULL;
3166
Chia-I Wu1f851912015-10-27 18:04:07 +08003167 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003168
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003169 if (!m_errorMonitor->DesiredMsgFound()) {
3170 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3171 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003172 }
3173}
3174
3175TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
3176{
3177 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003178 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3179 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003180
3181 ASSERT_NO_FATAL_FAILURE(InitState());
3182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003183
3184 // Renderpass is started here
3185 BeginCommandBuffer();
3186
3187 VkClearColorValue clear_color = {0};
3188 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3189 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3190 const int32_t tex_width = 32;
3191 const int32_t tex_height = 32;
3192 VkImageCreateInfo image_create_info = {};
3193 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3194 image_create_info.pNext = NULL;
3195 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3196 image_create_info.format = tex_format;
3197 image_create_info.extent.width = tex_width;
3198 image_create_info.extent.height = tex_height;
3199 image_create_info.extent.depth = 1;
3200 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06003201 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08003202 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003203 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3204 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3205
Chia-I Wu1f851912015-10-27 18:04:07 +08003206 vk_testing::Image dstImage;
3207 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003208
3209 const VkImageSubresourceRange range =
3210 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
3211
Chia-I Wu1f851912015-10-27 18:04:07 +08003212 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(),
3213 dstImage.handle(),
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003214 VK_IMAGE_LAYOUT_GENERAL,
3215 &clear_color,
3216 1,
3217 &range);
3218
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003219 if (!m_errorMonitor->DesiredMsgFound()) {
3220 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3221 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003222 }
3223}
3224
3225TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
3226{
3227 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003228 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3229 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003230
3231 ASSERT_NO_FATAL_FAILURE(InitState());
3232 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003233
3234 // Renderpass is started here
3235 BeginCommandBuffer();
3236
3237 VkClearDepthStencilValue clear_value = {0};
3238 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3239 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
3240 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3241 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
3242 image_create_info.extent.width = 64;
3243 image_create_info.extent.height = 64;
3244 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3245 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
3246
Chia-I Wu1f851912015-10-27 18:04:07 +08003247 vk_testing::Image dstImage;
3248 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003249
3250 const VkImageSubresourceRange range =
3251 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
3252
Chia-I Wu1f851912015-10-27 18:04:07 +08003253 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(),
3254 dstImage.handle(),
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003255 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
3256 &clear_value,
3257 1,
3258 &range);
3259
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003260 if (!m_errorMonitor->DesiredMsgFound()) {
3261 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
3262 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003263 }
3264}
3265
3266TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
3267{
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003268 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003269 VkResult err;
3270
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003271 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3272 "vkCmdClearAttachments: This call must be issued inside an active render pass");
3273
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003274 ASSERT_NO_FATAL_FAILURE(InitState());
3275 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003276
3277 // Start no RenderPass
Chia-I Wu1f851912015-10-27 18:04:07 +08003278 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003279 ASSERT_VK_SUCCESS(err);
3280
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003281 VkClearAttachment color_attachment;
3282 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3283 color_attachment.clearValue.color.float32[0] = 0;
3284 color_attachment.clearValue.color.float32[1] = 0;
3285 color_attachment.clearValue.color.float32[2] = 0;
3286 color_attachment.clearValue.color.float32[3] = 0;
3287 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06003288 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Chia-I Wu1f851912015-10-27 18:04:07 +08003289 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(),
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003290 1, &color_attachment,
3291 1, &clear_rect);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003292
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003293 if (!m_errorMonitor->DesiredMsgFound()) {
3294 FAIL() << "Did not receive Error 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
3295 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003296 }
3297}
3298
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003299TEST_F(VkLayerTest, InvalidDynamicStateObject)
3300{
3301 // Create a valid cmd buffer
3302 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06003303 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
3304 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003305}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06003306
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003307TEST_F(VkLayerTest, IdxBufferAlignmentError)
3308{
3309 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003310 VkResult err;
3311
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003312 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3313 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
3314
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003315 ASSERT_NO_FATAL_FAILURE(InitState());
3316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003317 uint32_t qfi = 0;
3318 VkBufferCreateInfo buffCI = {};
3319 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3320 buffCI.size = 1024;
3321 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
Chia-I Wu763a7492015-10-26 20:48:51 +08003322 buffCI.queueFamilyIndexCount = 1;
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003323 buffCI.pQueueFamilyIndices = &qfi;
3324
3325 VkBuffer ib;
Chia-I Wu69f40122015-10-26 21:10:41 +08003326 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003327 ASSERT_VK_SUCCESS(err);
3328
3329 BeginCommandBuffer();
3330 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08003331 //vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003332 // Should error before calling to driver so don't care about actual data
Chia-I Wu1f851912015-10-27 18:04:07 +08003333 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003334
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003335 if (!m_errorMonitor->DesiredMsgFound()) {
3336 FAIL() << "Did not receive Error 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...'";
3337 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003338 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003339
Chia-I Wu69f40122015-10-26 21:10:41 +08003340 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003341}
3342
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003343TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
3344{
3345 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003346
3347 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3348 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003349
3350 ASSERT_NO_FATAL_FAILURE(InitState());
3351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003352
3353 BeginCommandBuffer();
3354 //ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08003355 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
3356 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003357
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003358 if (!m_errorMonitor->DesiredMsgFound()) {
3359 FAIL() << "Did not receive Error 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer '";
3360 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003361 }
3362}
3363
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003364TEST_F(VkLayerTest, DSTypeMismatch)
3365{
3366 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003367 VkResult err;
3368
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003369 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3370 "Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match ");
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);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003388 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003389 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003390 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003391 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003392 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3393 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003394
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003395 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3396 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3397 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003398 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003399 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003400
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003401 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003402 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003403 ASSERT_VK_SUCCESS(err);
3404
3405 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003406 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003407 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003408 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003409 alloc_info.descriptorPool = ds_pool;
3410 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003411 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003412 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003413
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003414 VkSamplerCreateInfo sampler_ci = {};
3415 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3416 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003417 sampler_ci.magFilter = VK_FILTER_NEAREST;
3418 sampler_ci.minFilter = VK_FILTER_NEAREST;
3419 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003420 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3421 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3422 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003423 sampler_ci.mipLodBias = 1.0;
3424 sampler_ci.maxAnisotropy = 1;
3425 sampler_ci.compareEnable = VK_FALSE;
3426 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3427 sampler_ci.minLod = 1.0;
3428 sampler_ci.maxLod = 1.0;
3429 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003430 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3431
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003432 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003433 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003434 ASSERT_VK_SUCCESS(err);
3435
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003436 VkDescriptorImageInfo info = {};
3437 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003438
3439 VkWriteDescriptorSet descriptor_write;
3440 memset(&descriptor_write, 0, sizeof(descriptor_write));
3441 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003442 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08003443 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003444 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003445 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003446 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003447
3448 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3449
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003450 if (!m_errorMonitor->DesiredMsgFound()) {
3451 FAIL() << "Did not receive Error 'Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...'";
3452 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003453 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003454
Chia-I Wu69f40122015-10-26 21:10:41 +08003455 vkDestroySampler(m_device->device(), sampler, NULL);
3456 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3457 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003458}
3459
3460TEST_F(VkLayerTest, DSUpdateOutOfBounds)
3461{
3462 // For overlapping Update, have arrayIndex exceed that of layout
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003463 VkResult err;
3464
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003465 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3466 "Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding");
3467
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003468 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003469 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003470 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003471 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003472 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003473
3474 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3475 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3476 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003477 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003478 ds_pool_ci.poolSizeCount = 1;
3479 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003480
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003481 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003482 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003483 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003484
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003485 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003486 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003487 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003488 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003489 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3490 dsl_binding.pImmutableSamplers = NULL;
3491
3492 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3493 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3494 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003495 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003496 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003497
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003498 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003499 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003500 ASSERT_VK_SUCCESS(err);
3501
3502 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003503 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003504 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003505 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003506 alloc_info.descriptorPool = ds_pool;
3507 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003508 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003509 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003510
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003511 VkSamplerCreateInfo sampler_ci = {};
3512 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3513 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003514 sampler_ci.magFilter = VK_FILTER_NEAREST;
3515 sampler_ci.minFilter = VK_FILTER_NEAREST;
3516 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003517 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3518 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3519 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003520 sampler_ci.mipLodBias = 1.0;
3521 sampler_ci.maxAnisotropy = 1;
3522 sampler_ci.compareEnable = VK_FALSE;
3523 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3524 sampler_ci.minLod = 1.0;
3525 sampler_ci.maxLod = 1.0;
3526 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003527 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003528
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003529 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003530 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003531 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003532
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003533 VkDescriptorImageInfo info = {};
3534 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003535
3536 VkWriteDescriptorSet descriptor_write;
3537 memset(&descriptor_write, 0, sizeof(descriptor_write));
3538 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003539 descriptor_write.dstSet = descriptorSet;
3540 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wu763a7492015-10-26 20:48:51 +08003541 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003542 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003543 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003544 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003545
3546 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3547
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003548 if (!m_errorMonitor->DesiredMsgFound()) {
3549 FAIL() << "Did not receive Error 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
3550 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003551 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003552
Chia-I Wu69f40122015-10-26 21:10:41 +08003553 vkDestroySampler(m_device->device(), sampler, NULL);
3554 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3555 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003556}
3557
3558TEST_F(VkLayerTest, InvalidDSUpdateIndex)
3559{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003560 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003561 VkResult err;
3562
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003563 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3564 " does not have binding to match update binding ");
3565
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003566 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003567 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003568 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003569 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003570 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003571
3572 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3573 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3574 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003575 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003576 ds_pool_ci.poolSizeCount = 1;
3577 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003578
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003579 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003580 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003581 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003582
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003583 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003584 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003585 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003586 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003587 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3588 dsl_binding.pImmutableSamplers = NULL;
3589
3590 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3591 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3592 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003593 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003594 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003595 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003596 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003597 ASSERT_VK_SUCCESS(err);
3598
3599 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003600 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003601 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003602 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003603 alloc_info.descriptorPool = ds_pool;
3604 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003605 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003606 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003607
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003608 VkSamplerCreateInfo sampler_ci = {};
3609 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3610 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003611 sampler_ci.magFilter = VK_FILTER_NEAREST;
3612 sampler_ci.minFilter = VK_FILTER_NEAREST;
3613 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003614 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3615 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3616 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003617 sampler_ci.mipLodBias = 1.0;
3618 sampler_ci.maxAnisotropy = 1;
3619 sampler_ci.compareEnable = VK_FALSE;
3620 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3621 sampler_ci.minLod = 1.0;
3622 sampler_ci.maxLod = 1.0;
3623 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003624 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003625
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003626 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003627 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003628 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003629
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003630 VkDescriptorImageInfo info = {};
3631 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003632
3633 VkWriteDescriptorSet descriptor_write;
3634 memset(&descriptor_write, 0, sizeof(descriptor_write));
3635 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003636 descriptor_write.dstSet = descriptorSet;
3637 descriptor_write.dstBinding = 2;
Chia-I Wu763a7492015-10-26 20:48:51 +08003638 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003639 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003640 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003641 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003642
3643 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3644
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003645 if (!m_errorMonitor->DesiredMsgFound()) {
3646 FAIL() << "Did not receive Error 'Descriptor Set <blah> does not have binding to match update binding '";
3647 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003648 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003649
Chia-I Wu69f40122015-10-26 21:10:41 +08003650 vkDestroySampler(m_device->device(), sampler, NULL);
3651 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3652 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003653}
3654
3655TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3656{
3657 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003658 VkResult err;
3659
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003660 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3661 "Unexpected UPDATE struct of type ");
3662
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003663 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003664
Chia-I Wuc51b1212015-10-27 19:25:11 +08003665 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003666 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003667 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003668
3669 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3670 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3671 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003672 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003673 ds_pool_ci.poolSizeCount = 1;
3674 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003675
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003676 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003677 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003678 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003679 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003680 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003681 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003682 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003683 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3684 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003685
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003686 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3687 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3688 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003689 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003690 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003691
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003692 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003693 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003694 ASSERT_VK_SUCCESS(err);
3695
3696 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003697 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003698 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003699 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003700 alloc_info.descriptorPool = ds_pool;
3701 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003702 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003703 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003704
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003705 VkSamplerCreateInfo sampler_ci = {};
3706 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3707 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003708 sampler_ci.magFilter = VK_FILTER_NEAREST;
3709 sampler_ci.minFilter = VK_FILTER_NEAREST;
3710 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003711 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3712 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3713 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003714 sampler_ci.mipLodBias = 1.0;
3715 sampler_ci.maxAnisotropy = 1;
3716 sampler_ci.compareEnable = VK_FALSE;
3717 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3718 sampler_ci.minLod = 1.0;
3719 sampler_ci.maxLod = 1.0;
3720 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003721 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003722 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003723 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003724 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003725
3726
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003727 VkDescriptorImageInfo info = {};
3728 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003729
3730 VkWriteDescriptorSet descriptor_write;
3731 memset(&descriptor_write, 0, sizeof(descriptor_write));
3732 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu1f851912015-10-27 18:04:07 +08003733 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08003734 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003735 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003736 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003737 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003738
3739 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3740
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003741 if (!m_errorMonitor->DesiredMsgFound()) {
3742 FAIL() << "Did not receive Error 'Unexpected UPDATE struct of type '";
3743 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003744 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003745
Chia-I Wu69f40122015-10-26 21:10:41 +08003746 vkDestroySampler(m_device->device(), sampler, NULL);
3747 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3748 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003749}
3750
Tobin Ehlisb46be812015-10-23 16:00:08 -06003751TEST_F(VkLayerTest, SampleDescriptorUpdateError)
3752{
3753 // Create a single Sampler descriptor and send it an invalid Sampler
Tobin Ehlisb46be812015-10-23 16:00:08 -06003754 VkResult err;
3755
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003756 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3757 "Attempt to update descriptor with invalid sampler 0xbaadbeef");
3758
Tobin Ehlisb46be812015-10-23 16:00:08 -06003759 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb46be812015-10-23 16:00:08 -06003760 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied code
Chia-I Wuc51b1212015-10-27 19:25:11 +08003761 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003762 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003763 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003764
3765 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3766 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3767 ds_pool_ci.pNext = NULL;
3768 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003769 ds_pool_ci.poolSizeCount = 1;
3770 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003771
3772 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003773 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003774 ASSERT_VK_SUCCESS(err);
3775
3776 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003777 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003778 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003779 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003780 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3781 dsl_binding.pImmutableSamplers = NULL;
3782
3783 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3784 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3785 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003786 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003787 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003788 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003789 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003790 ASSERT_VK_SUCCESS(err);
3791
3792 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003793 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003794 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003795 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003796 alloc_info.descriptorPool = ds_pool;
3797 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003798 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003799 ASSERT_VK_SUCCESS(err);
3800
Chia-I Wue420a332015-10-26 20:04:44 +08003801 VkSampler sampler = (VkSampler) 0xbaadbeef; // Sampler with invalid handle
Tobin Ehlisb46be812015-10-23 16:00:08 -06003802
3803 VkDescriptorImageInfo descriptor_info;
3804 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3805 descriptor_info.sampler = sampler;
3806
3807 VkWriteDescriptorSet descriptor_write;
3808 memset(&descriptor_write, 0, sizeof(descriptor_write));
3809 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003810 descriptor_write.dstSet = descriptorSet;
3811 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003812 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003813 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3814 descriptor_write.pImageInfo = &descriptor_info;
3815
3816 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3817
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003818 if (!m_errorMonitor->DesiredMsgFound()) {
3819 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid sampler...'";
3820 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06003821 }
3822
Chia-I Wu69f40122015-10-26 21:10:41 +08003823 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3824 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003825}
3826
3827TEST_F(VkLayerTest, ImageViewDescriptorUpdateError)
3828{
3829 // Create a single combined Image/Sampler descriptor and send it an invalid imageView
Tobin Ehlisb46be812015-10-23 16:00:08 -06003830 VkResult err;
3831
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003832 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3833 "Attempt to update descriptor with invalid imageView 0xbaadbeef");
3834
Tobin Ehlisb46be812015-10-23 16:00:08 -06003835 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wuc51b1212015-10-27 19:25:11 +08003836 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003837 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003838 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003839
3840 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3841 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3842 ds_pool_ci.pNext = NULL;
3843 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003844 ds_pool_ci.poolSizeCount = 1;
3845 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003846
3847 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003848 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003849 ASSERT_VK_SUCCESS(err);
3850
3851 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003852 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003853 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003854 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003855 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3856 dsl_binding.pImmutableSamplers = NULL;
3857
3858 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3859 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3860 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003861 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003862 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003863 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003864 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003865 ASSERT_VK_SUCCESS(err);
3866
3867 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003868 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003869 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003870 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003871 alloc_info.descriptorPool = ds_pool;
3872 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003873 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003874 ASSERT_VK_SUCCESS(err);
3875
3876 VkSamplerCreateInfo sampler_ci = {};
3877 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3878 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003879 sampler_ci.magFilter = VK_FILTER_NEAREST;
3880 sampler_ci.minFilter = VK_FILTER_NEAREST;
3881 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003882 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3883 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3884 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003885 sampler_ci.mipLodBias = 1.0;
3886 sampler_ci.maxAnisotropy = 1;
3887 sampler_ci.compareEnable = VK_FALSE;
3888 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3889 sampler_ci.minLod = 1.0;
3890 sampler_ci.maxLod = 1.0;
3891 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3892 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3893
3894 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003895 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003896 ASSERT_VK_SUCCESS(err);
3897
Chia-I Wue420a332015-10-26 20:04:44 +08003898 VkImageView view = (VkImageView) 0xbaadbeef; // invalid imageView object
Tobin Ehlisb46be812015-10-23 16:00:08 -06003899
3900 VkDescriptorImageInfo descriptor_info;
3901 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3902 descriptor_info.sampler = sampler;
3903 descriptor_info.imageView = view;
3904
3905 VkWriteDescriptorSet descriptor_write;
3906 memset(&descriptor_write, 0, sizeof(descriptor_write));
3907 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003908 descriptor_write.dstSet = descriptorSet;
3909 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003910 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003911 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3912 descriptor_write.pImageInfo = &descriptor_info;
3913
3914 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3915
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003916 if (!m_errorMonitor->DesiredMsgFound()) {
3917 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid imageView...'";
3918 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06003919 }
3920
Chia-I Wu69f40122015-10-26 21:10:41 +08003921 vkDestroySampler(m_device->device(), sampler, NULL);
3922 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3923 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003924}
3925
Tobin Ehlis3e676262015-10-27 16:35:27 -06003926TEST_F(VkLayerTest, CopyDescriptorUpdateErrors)
3927{
3928 // 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 -06003929 VkResult err;
3930
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003931 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3932 "Copy descriptor update index 0, update count #1, has src update descriptor type VK_DESCRIPTOR_TYPE_SAMPLER ");
3933
Tobin Ehlis3e676262015-10-27 16:35:27 -06003934 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3e676262015-10-27 16:35:27 -06003935 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003936 VkDescriptorPoolSize ds_type_count[2] = {};
Tobin Ehlis3e676262015-10-27 16:35:27 -06003937 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003938 ds_type_count[0].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003939 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003940 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003941
3942 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3943 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3944 ds_pool_ci.pNext = NULL;
3945 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003946 ds_pool_ci.poolSizeCount = 2;
3947 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003948
3949 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003950 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003951 ASSERT_VK_SUCCESS(err);
3952 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003953 dsl_binding[0].binding = 0;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003954 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003955 dsl_binding[0].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003956 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3957 dsl_binding[0].pImmutableSamplers = NULL;
Chia-I Wub5689ee2015-10-31 00:31:16 +08003958 dsl_binding[1].binding = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003959 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003960 dsl_binding[1].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003961 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
3962 dsl_binding[1].pImmutableSamplers = NULL;
3963
3964 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3965 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3966 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003967 ds_layout_ci.bindingCount = 2;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003968 ds_layout_ci.pBinding = dsl_binding;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003969
3970 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003971 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003972 ASSERT_VK_SUCCESS(err);
3973
3974 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003975 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003976 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003977 alloc_info.setLayoutCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003978 alloc_info.descriptorPool = ds_pool;
3979 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003980 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003981 ASSERT_VK_SUCCESS(err);
3982
3983 VkSamplerCreateInfo sampler_ci = {};
3984 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3985 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003986 sampler_ci.magFilter = VK_FILTER_NEAREST;
3987 sampler_ci.minFilter = VK_FILTER_NEAREST;
3988 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003989 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3990 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3991 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003992 sampler_ci.mipLodBias = 1.0;
3993 sampler_ci.maxAnisotropy = 1;
3994 sampler_ci.compareEnable = VK_FALSE;
3995 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3996 sampler_ci.minLod = 1.0;
3997 sampler_ci.maxLod = 1.0;
3998 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3999 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4000
4001 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08004002 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3e676262015-10-27 16:35:27 -06004003 ASSERT_VK_SUCCESS(err);
4004
4005 VkDescriptorImageInfo info = {};
4006 info.sampler = sampler;
4007
4008 VkWriteDescriptorSet descriptor_write;
4009 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
4010 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08004011 descriptor_write.dstSet = descriptorSet;
4012 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wu763a7492015-10-26 20:48:51 +08004013 descriptor_write.descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06004014 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4015 descriptor_write.pImageInfo = &info;
4016 // This write update should succeed
4017 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4018 // Now perform a copy update that fails due to type mismatch
4019 VkCopyDescriptorSet copy_ds_update;
4020 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4021 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4022 copy_ds_update.srcSet = descriptorSet;
4023 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
Chia-I Wu1f851912015-10-27 18:04:07 +08004024 copy_ds_update.dstSet = descriptorSet;
4025 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wu763a7492015-10-26 20:48:51 +08004026 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06004027 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4028
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004029 if (!m_errorMonitor->DesiredMsgFound()) {
4030 FAIL() << "Did not receive Error 'Copy descriptor update index 0, update count #1, has src update descriptor type_DESCRIPTOR_TYPE_SAMPLER'";
4031 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06004032 }
4033 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004034 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4035 "Copy descriptor update 0 has srcBinding 3 which is out of bounds ");
Tobin Ehlis3e676262015-10-27 16:35:27 -06004036 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4037 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4038 copy_ds_update.srcSet = descriptorSet;
4039 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu1f851912015-10-27 18:04:07 +08004040 copy_ds_update.dstSet = descriptorSet;
4041 copy_ds_update.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08004042 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06004043 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4044
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004045 if (!m_errorMonitor->DesiredMsgFound()) {
4046 FAIL() << "Did not receive Error 'Copy descriptor update 0 has srcBinding 3 which is out of bounds...'";
4047 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06004048 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004049
Tobin Ehlis3e676262015-10-27 16:35:27 -06004050 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004051 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4052 "Copy descriptor src update is out of bounds for matching binding 1 ");
4053
Tobin Ehlis3e676262015-10-27 16:35:27 -06004054 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4055 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4056 copy_ds_update.srcSet = descriptorSet;
4057 copy_ds_update.srcBinding = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08004058 copy_ds_update.dstSet = descriptorSet;
4059 copy_ds_update.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08004060 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis3e676262015-10-27 16:35:27 -06004061 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4062
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004063 if (!m_errorMonitor->DesiredMsgFound()) {
4064 FAIL() << "Did not receive Error 'Copy descriptor src update is out of bounds for matching binding 1...'";
4065 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06004066 }
4067
Chia-I Wu69f40122015-10-26 21:10:41 +08004068 vkDestroySampler(m_device->device(), sampler, NULL);
4069 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4070 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis3e676262015-10-27 16:35:27 -06004071}
4072
Tobin Ehlis138b7f12015-05-22 12:38:55 -06004073TEST_F(VkLayerTest, NumSamplesMismatch)
4074{
Chia-I Wu1f851912015-10-27 18:04:07 +08004075 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004076 VkResult err;
4077
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004078 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4079 "Num samples mismatch! ");
4080
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004081 ASSERT_NO_FATAL_FAILURE(InitState());
4082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wuc51b1212015-10-27 19:25:11 +08004083 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004084 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08004085 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004086
4087 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004088 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4089 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004090 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08004091 ds_pool_ci.poolSizeCount = 1;
4092 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004093
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004094 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08004095 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004096 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004097
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004098 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08004099 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004100 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08004101 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004102 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4103 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004104
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004105 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4106 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4107 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004108 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08004109 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004110
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004111 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004112 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004113 ASSERT_VK_SUCCESS(err);
4114
4115 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004116 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004117 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08004118 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004119 alloc_info.descriptorPool = ds_pool;
4120 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08004121 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004122 ASSERT_VK_SUCCESS(err);
4123
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004124 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4125 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4126 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004127 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004128 pipe_ms_state_ci.sampleShadingEnable = 0;
4129 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06004130 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004131
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004132 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4133 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4134 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004135 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004136 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004137
4138 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004139 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004140 ASSERT_VK_SUCCESS(err);
4141
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004142 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4143 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 -06004144 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06004145 VkPipelineObj pipe(m_device);
4146 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004147 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004148 pipe.SetMSAA(&pipe_ms_state_ci);
4149 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004150
Tony Barbour1490c912015-07-28 10:17:20 -06004151 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08004152 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004153
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004154 if (!m_errorMonitor->DesiredMsgFound()) {
4155 FAIL() << "Did not recieve Error 'Num samples mismatch!...'";
4156 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004157 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004158
Chia-I Wu69f40122015-10-26 21:10:41 +08004159 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4160 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4161 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06004162}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004163
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004164TEST_F(VkLayerTest, ClearCmdNoDraw)
4165{
Chia-I Wu1f851912015-10-27 18:04:07 +08004166 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004167 VkResult err;
4168
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004169 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
4170 "vkCmdClearAttachments() issued on CB object ");
4171
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004172 ASSERT_NO_FATAL_FAILURE(InitState());
4173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004174
Chia-I Wuc51b1212015-10-27 19:25:11 +08004175 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004176 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08004177 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004178
4179 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4180 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4181 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004182 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08004183 ds_pool_ci.poolSizeCount = 1;
4184 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004185
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004186 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08004187 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004188 ASSERT_VK_SUCCESS(err);
4189
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004190 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08004191 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004192 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08004193 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004194 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4195 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004196
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004197 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4198 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4199 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004200 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08004201 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004202
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004203 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004204 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004205 ASSERT_VK_SUCCESS(err);
4206
4207 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004208 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004209 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08004210 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004211 alloc_info.descriptorPool = ds_pool;
4212 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08004213 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004214 ASSERT_VK_SUCCESS(err);
4215
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004216 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4217 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4218 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004219 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004220 pipe_ms_state_ci.sampleShadingEnable = 0;
4221 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06004222 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004223
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004224 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4225 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4226 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004227 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004228 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004229
4230 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004231 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004232 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004233
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004234 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004235 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
4236 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4237
Tony Barbourd7d828b2015-08-06 10:16:07 -06004238 VkPipelineObj pipe(m_device);
4239 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004240 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004241 pipe.SetMSAA(&pipe_ms_state_ci);
4242 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06004243
4244 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004245
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004246 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
4247 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004248 VkClearAttachment color_attachment;
4249 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4250 color_attachment.clearValue.color.float32[0] = 1.0;
4251 color_attachment.clearValue.color.float32[1] = 1.0;
4252 color_attachment.clearValue.color.float32[2] = 1.0;
4253 color_attachment.clearValue.color.float32[3] = 1.0;
4254 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004255 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004256
Chia-I Wu1f851912015-10-27 18:04:07 +08004257 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004258
4259 if (!m_errorMonitor->DesiredMsgFound()) {
4260 FAIL() << "Did not receive Error 'vkCommandClearAttachments() issued on CB object...'";
4261 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004262 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004263
Chia-I Wu69f40122015-10-26 21:10:41 +08004264 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4265 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4266 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004267}
4268
Tobin Ehlise4076782015-06-24 15:53:07 -06004269TEST_F(VkLayerTest, VtxBufferBadIndex)
4270{
Chia-I Wu1f851912015-10-27 18:04:07 +08004271 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlise4076782015-06-24 15:53:07 -06004272 VkResult err;
4273
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004274 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4275 "Vtx Buffer Index 1 was bound, but no vtx buffers are attached to PSO.");
4276
Tobin Ehlise4076782015-06-24 15:53:07 -06004277 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06004278 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlise4076782015-06-24 15:53:07 -06004279 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004280
Chia-I Wuc51b1212015-10-27 19:25:11 +08004281 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004282 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08004283 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004284
4285 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4286 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4287 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004288 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08004289 ds_pool_ci.poolSizeCount = 1;
4290 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004291
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004292 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08004293 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06004294 ASSERT_VK_SUCCESS(err);
4295
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004296 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08004297 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004298 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08004299 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004300 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4301 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06004302
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004303 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4304 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4305 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004306 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08004307 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004308
Tobin Ehlise4076782015-06-24 15:53:07 -06004309 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004310 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06004311 ASSERT_VK_SUCCESS(err);
4312
4313 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004314 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004315 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08004316 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004317 alloc_info.descriptorPool = ds_pool;
4318 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08004319 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06004320 ASSERT_VK_SUCCESS(err);
4321
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004322 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4323 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4324 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004325 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004326 pipe_ms_state_ci.sampleShadingEnable = 0;
4327 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06004328 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06004329
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004330 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4331 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4332 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004333 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004334 pipeline_layout_ci.pSetLayouts = &ds_layout;
4335 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06004336
Chia-I Wu69f40122015-10-26 21:10:41 +08004337 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06004338 ASSERT_VK_SUCCESS(err);
4339
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004340 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4341 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 -06004342 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06004343 VkPipelineObj pipe(m_device);
4344 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004345 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004346 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06004347 pipe.SetViewport(m_viewports);
4348 pipe.SetScissor(m_scissors);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004349 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06004350
4351 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08004352 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06004353 // Don't care about actual data, just need to get to draw to flag error
4354 static const float vbo_data[3] = {1.f, 0.f, 1.f};
4355 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
4356 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06004357 Draw(1, 0, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06004358
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004359 if (!m_errorMonitor->DesiredMsgFound()) {
4360 FAIL() << "Did not receive Error 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
4361 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise4076782015-06-24 15:53:07 -06004362 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004363
Chia-I Wu69f40122015-10-26 21:10:41 +08004364 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4365 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4366 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise4076782015-06-24 15:53:07 -06004367}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004368#endif // DRAW_STATE_TESTS
4369
Tobin Ehlis57e6a612015-05-26 16:11:58 -06004370#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06004371#if GTEST_IS_THREADSAFE
4372struct thread_data_struct {
Chia-I Wu1f851912015-10-27 18:04:07 +08004373 VkCommandBuffer commandBuffer;
Mike Stroyan09aae812015-05-12 16:00:45 -06004374 VkEvent event;
4375 bool bailout;
4376};
4377
4378extern "C" void *AddToCommandBuffer(void *arg)
4379{
4380 struct thread_data_struct *data = (struct thread_data_struct *) arg;
Mike Stroyan09aae812015-05-12 16:00:45 -06004381
4382 for (int i = 0; i<10000; i++) {
Chia-I Wucba6cea2015-10-31 00:31:16 +08004383 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyan09aae812015-05-12 16:00:45 -06004384 if (data->bailout) {
4385 break;
4386 }
4387 }
4388 return NULL;
4389}
4390
Chia-I Wu1f851912015-10-27 18:04:07 +08004391TEST_F(VkLayerTest, ThreadCommandBufferCollision)
Mike Stroyan09aae812015-05-12 16:00:45 -06004392{
Mike Stroyan7016f4f2015-07-13 14:45:35 -06004393 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06004394
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004395 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "THREADING ERROR");
4396
Mike Stroyan09aae812015-05-12 16:00:45 -06004397 ASSERT_NO_FATAL_FAILURE(InitState());
4398 ASSERT_NO_FATAL_FAILURE(InitViewport());
4399 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4400
Chia-I Wu1f851912015-10-27 18:04:07 +08004401 // Calls AllocateCommandBuffers
4402 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004403
4404 // Avoid creating RenderPass
Chia-I Wu1f851912015-10-27 18:04:07 +08004405 commandBuffer.BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06004406
4407 VkEventCreateInfo event_info;
4408 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06004409 VkResult err;
4410
4411 memset(&event_info, 0, sizeof(event_info));
4412 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4413
Chia-I Wu69f40122015-10-26 21:10:41 +08004414 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyan09aae812015-05-12 16:00:45 -06004415 ASSERT_VK_SUCCESS(err);
4416
Mike Stroyan09aae812015-05-12 16:00:45 -06004417 err = vkResetEvent(device(), event);
4418 ASSERT_VK_SUCCESS(err);
4419
4420 struct thread_data_struct data;
Chia-I Wu1f851912015-10-27 18:04:07 +08004421 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyan09aae812015-05-12 16:00:45 -06004422 data.event = event;
4423 data.bailout = false;
4424 m_errorMonitor->SetBailout(&data.bailout);
4425 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06004426 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06004427 // Add many entries to command buffer from this thread at the same time.
4428 AddToCommandBuffer(&data);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004429
Mike Stroyan7016f4f2015-07-13 14:45:35 -06004430 test_platform_thread_join(thread, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08004431 commandBuffer.EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06004432
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004433 if (!m_errorMonitor->DesiredMsgFound()) {
4434 FAIL() << "Did not receive Error 'THREADING ERROR' from using one VkCommandBufferObj in two threads";
4435 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan09aae812015-05-12 16:00:45 -06004436 }
4437
Chia-I Wu69f40122015-10-26 21:10:41 +08004438 vkDestroyEvent(device(), event, NULL);
Mike Stroyan09aae812015-05-12 16:00:45 -06004439}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004440#endif // GTEST_IS_THREADSAFE
4441#endif // THREADING_TESTS
4442
Chris Forbes5af3bf22015-05-25 11:13:08 +12004443#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004444TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
4445{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004446 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4447 "Shader is not SPIR-V");
4448
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004449 ASSERT_NO_FATAL_FAILURE(InitState());
4450 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4451
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004452 VkShaderModule module;
4453 VkShaderModuleCreateInfo moduleCreateInfo;
4454 struct icd_spv_header spv;
4455
4456 spv.magic = ICD_SPV_MAGIC;
4457 spv.version = ICD_SPV_VERSION;
4458 spv.gen_magic = 0;
4459
4460 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4461 moduleCreateInfo.pNext = NULL;
Chia-I Wu036b1612015-10-26 19:22:06 +08004462 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004463 moduleCreateInfo.codeSize = 4;
4464 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004465 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004466
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004467 if (!m_errorMonitor->DesiredMsgFound()) {
4468 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4469 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004470 }
4471}
4472
4473TEST_F(VkLayerTest, InvalidSPIRVMagic)
4474{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004475 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4476 "Shader is not SPIR-V");
4477
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004478 ASSERT_NO_FATAL_FAILURE(InitState());
4479 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4480
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004481 VkShaderModule module;
4482 VkShaderModuleCreateInfo moduleCreateInfo;
4483 struct icd_spv_header spv;
4484
4485 spv.magic = ~ICD_SPV_MAGIC;
4486 spv.version = ICD_SPV_VERSION;
4487 spv.gen_magic = 0;
4488
4489 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4490 moduleCreateInfo.pNext = NULL;
Chia-I Wu036b1612015-10-26 19:22:06 +08004491 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004492 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4493 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004494 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004495
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004496 if (!m_errorMonitor->DesiredMsgFound()) {
4497 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4498 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004499 }
4500}
4501
4502TEST_F(VkLayerTest, InvalidSPIRVVersion)
4503{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004504 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4505 "Shader is not SPIR-V");
4506
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004507 ASSERT_NO_FATAL_FAILURE(InitState());
4508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4509
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004510 VkShaderModule module;
4511 VkShaderModuleCreateInfo moduleCreateInfo;
4512 struct icd_spv_header spv;
4513
4514 spv.magic = ICD_SPV_MAGIC;
4515 spv.version = ~ICD_SPV_VERSION;
4516 spv.gen_magic = 0;
4517
4518 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4519 moduleCreateInfo.pNext = NULL;
4520
Chia-I Wu036b1612015-10-26 19:22:06 +08004521 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004522 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4523 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004524 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004525
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004526 if (!m_errorMonitor->DesiredMsgFound()) {
4527 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4528 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004529 }
4530}
4531
Chris Forbes5af3bf22015-05-25 11:13:08 +12004532TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
4533{
Tony Barbour192f02b2015-11-06 14:21:31 -07004534 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_PERF_WARN_BIT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004535 "not consumed by fragment shader");
4536
Chris Forbes5af3bf22015-05-25 11:13:08 +12004537 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12004539
4540 char const *vsSource =
4541 "#version 140\n"
4542 "#extension GL_ARB_separate_shader_objects: require\n"
4543 "#extension GL_ARB_shading_language_420pack: require\n"
4544 "\n"
4545 "layout(location=0) out float x;\n"
4546 "void main(){\n"
4547 " gl_Position = vec4(1);\n"
4548 " x = 0;\n"
4549 "}\n";
4550 char const *fsSource =
4551 "#version 140\n"
4552 "#extension GL_ARB_separate_shader_objects: require\n"
4553 "#extension GL_ARB_shading_language_420pack: require\n"
4554 "\n"
4555 "layout(location=0) out vec4 color;\n"
4556 "void main(){\n"
4557 " color = vec4(1);\n"
4558 "}\n";
4559
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004560 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4561 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5af3bf22015-05-25 11:13:08 +12004562
4563 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004564 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12004565 pipe.AddShader(&vs);
4566 pipe.AddShader(&fs);
4567
Chris Forbes5af3bf22015-05-25 11:13:08 +12004568 VkDescriptorSetObj descriptorSet(m_device);
4569 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004570 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12004571
Tony Barboured132432015-08-04 16:23:11 -06004572 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12004573
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004574 if (!m_errorMonitor->DesiredMsgFound()) {
4575 FAIL() << "Did not receive Warning 'not consumed by fragment shader'";
4576 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5af3bf22015-05-25 11:13:08 +12004577 }
4578}
Chris Forbes5af3bf22015-05-25 11:13:08 +12004579
Chris Forbes3c10b852015-05-25 11:13:13 +12004580TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
4581{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004582 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4583 "not written by vertex shader");
4584
Chris Forbes3c10b852015-05-25 11:13:13 +12004585 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004586 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12004587
4588 char const *vsSource =
4589 "#version 140\n"
4590 "#extension GL_ARB_separate_shader_objects: require\n"
4591 "#extension GL_ARB_shading_language_420pack: require\n"
4592 "\n"
4593 "void main(){\n"
4594 " gl_Position = vec4(1);\n"
4595 "}\n";
4596 char const *fsSource =
4597 "#version 140\n"
4598 "#extension GL_ARB_separate_shader_objects: require\n"
4599 "#extension GL_ARB_shading_language_420pack: require\n"
4600 "\n"
4601 "layout(location=0) in float x;\n"
4602 "layout(location=0) out vec4 color;\n"
4603 "void main(){\n"
4604 " color = vec4(x);\n"
4605 "}\n";
4606
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004607 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4608 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes3c10b852015-05-25 11:13:13 +12004609
4610 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004611 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12004612 pipe.AddShader(&vs);
4613 pipe.AddShader(&fs);
4614
Chris Forbes3c10b852015-05-25 11:13:13 +12004615 VkDescriptorSetObj descriptorSet(m_device);
4616 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004617 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12004618
Tony Barboured132432015-08-04 16:23:11 -06004619 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12004620
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004621 if (!m_errorMonitor->DesiredMsgFound()) {
4622 FAIL() << "Did not receive Error 'not written by vertex shader'";
4623 m_errorMonitor->DumpFailureMsgs();
Chris Forbes3c10b852015-05-25 11:13:13 +12004624 }
4625}
4626
Chris Forbescc281692015-05-25 11:13:17 +12004627TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
4628{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004629 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4630 "Type mismatch on location 0");
4631
Chris Forbescc281692015-05-25 11:13:17 +12004632 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004633 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12004634
4635 char const *vsSource =
4636 "#version 140\n"
4637 "#extension GL_ARB_separate_shader_objects: require\n"
4638 "#extension GL_ARB_shading_language_420pack: require\n"
4639 "\n"
4640 "layout(location=0) out int x;\n"
4641 "void main(){\n"
4642 " x = 0;\n"
4643 " gl_Position = vec4(1);\n"
4644 "}\n";
4645 char const *fsSource =
4646 "#version 140\n"
4647 "#extension GL_ARB_separate_shader_objects: require\n"
4648 "#extension GL_ARB_shading_language_420pack: require\n"
4649 "\n"
4650 "layout(location=0) in float x;\n" /* VS writes int */
4651 "layout(location=0) out vec4 color;\n"
4652 "void main(){\n"
4653 " color = vec4(x);\n"
4654 "}\n";
4655
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004656 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4657 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbescc281692015-05-25 11:13:17 +12004658
4659 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004660 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12004661 pipe.AddShader(&vs);
4662 pipe.AddShader(&fs);
4663
Chris Forbescc281692015-05-25 11:13:17 +12004664 VkDescriptorSetObj descriptorSet(m_device);
4665 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004666 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12004667
Tony Barboured132432015-08-04 16:23:11 -06004668 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12004669
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004670 if (!m_errorMonitor->DesiredMsgFound()) {
4671 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
4672 m_errorMonitor->DumpFailureMsgs();
Chris Forbescc281692015-05-25 11:13:17 +12004673 }
4674}
4675
Chris Forbes8291c052015-05-25 11:13:28 +12004676TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
4677{
Tony Barbour192f02b2015-11-06 14:21:31 -07004678 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_PERF_WARN_BIT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004679 "location 0 not consumed by VS");
4680
Chris Forbes8291c052015-05-25 11:13:28 +12004681 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12004683
4684 VkVertexInputBindingDescription input_binding;
4685 memset(&input_binding, 0, sizeof(input_binding));
4686
4687 VkVertexInputAttributeDescription input_attrib;
4688 memset(&input_attrib, 0, sizeof(input_attrib));
4689 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4690
4691 char const *vsSource =
4692 "#version 140\n"
4693 "#extension GL_ARB_separate_shader_objects: require\n"
4694 "#extension GL_ARB_shading_language_420pack: require\n"
4695 "\n"
4696 "void main(){\n"
4697 " gl_Position = vec4(1);\n"
4698 "}\n";
4699 char const *fsSource =
4700 "#version 140\n"
4701 "#extension GL_ARB_separate_shader_objects: require\n"
4702 "#extension GL_ARB_shading_language_420pack: require\n"
4703 "\n"
4704 "layout(location=0) out vec4 color;\n"
4705 "void main(){\n"
4706 " color = vec4(1);\n"
4707 "}\n";
4708
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004709 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4710 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes8291c052015-05-25 11:13:28 +12004711
4712 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004713 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12004714 pipe.AddShader(&vs);
4715 pipe.AddShader(&fs);
4716
4717 pipe.AddVertexInputBindings(&input_binding, 1);
4718 pipe.AddVertexInputAttribs(&input_attrib, 1);
4719
Chris Forbes8291c052015-05-25 11:13:28 +12004720 VkDescriptorSetObj descriptorSet(m_device);
4721 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004722 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12004723
Tony Barboured132432015-08-04 16:23:11 -06004724 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12004725
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004726 if (!m_errorMonitor->DesiredMsgFound()) {
4727 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
4728 m_errorMonitor->DumpFailureMsgs();
Chris Forbes8291c052015-05-25 11:13:28 +12004729 }
4730}
4731
Chris Forbes37367e62015-05-25 11:13:29 +12004732TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
4733{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004734 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4735 "VS consumes input at location 0 but not provided");
4736
Chris Forbes37367e62015-05-25 11:13:29 +12004737 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004738 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12004739
4740 char const *vsSource =
4741 "#version 140\n"
4742 "#extension GL_ARB_separate_shader_objects: require\n"
4743 "#extension GL_ARB_shading_language_420pack: require\n"
4744 "\n"
4745 "layout(location=0) in vec4 x;\n" /* not provided */
4746 "void main(){\n"
4747 " gl_Position = x;\n"
4748 "}\n";
4749 char const *fsSource =
4750 "#version 140\n"
4751 "#extension GL_ARB_separate_shader_objects: require\n"
4752 "#extension GL_ARB_shading_language_420pack: require\n"
4753 "\n"
4754 "layout(location=0) out vec4 color;\n"
4755 "void main(){\n"
4756 " color = vec4(1);\n"
4757 "}\n";
4758
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004759 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4760 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes37367e62015-05-25 11:13:29 +12004761
4762 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004763 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12004764 pipe.AddShader(&vs);
4765 pipe.AddShader(&fs);
4766
Chris Forbes37367e62015-05-25 11:13:29 +12004767 VkDescriptorSetObj descriptorSet(m_device);
4768 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004769 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12004770
Tony Barboured132432015-08-04 16:23:11 -06004771 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12004772
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004773 if (!m_errorMonitor->DesiredMsgFound()) {
4774 FAIL() << "Did not receive Error 'VS consumes input at location 0 but not provided'";
4775 m_errorMonitor->DumpFailureMsgs();
Chris Forbes37367e62015-05-25 11:13:29 +12004776 }
4777}
4778
Chris Forbesa4b02322015-05-25 11:13:31 +12004779TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
4780{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004781 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4782 "location 0 does not match VS input type");
4783
Chris Forbesa4b02322015-05-25 11:13:31 +12004784 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004785 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12004786
4787 VkVertexInputBindingDescription input_binding;
4788 memset(&input_binding, 0, sizeof(input_binding));
4789
4790 VkVertexInputAttributeDescription input_attrib;
4791 memset(&input_attrib, 0, sizeof(input_attrib));
4792 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4793
4794 char const *vsSource =
4795 "#version 140\n"
4796 "#extension GL_ARB_separate_shader_objects: require\n"
4797 "#extension GL_ARB_shading_language_420pack: require\n"
4798 "\n"
4799 "layout(location=0) in int x;\n" /* attrib provided float */
4800 "void main(){\n"
4801 " gl_Position = vec4(x);\n"
4802 "}\n";
4803 char const *fsSource =
4804 "#version 140\n"
4805 "#extension GL_ARB_separate_shader_objects: require\n"
4806 "#extension GL_ARB_shading_language_420pack: require\n"
4807 "\n"
4808 "layout(location=0) out vec4 color;\n"
4809 "void main(){\n"
4810 " color = vec4(1);\n"
4811 "}\n";
4812
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004813 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4814 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa4b02322015-05-25 11:13:31 +12004815
4816 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004817 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12004818 pipe.AddShader(&vs);
4819 pipe.AddShader(&fs);
4820
4821 pipe.AddVertexInputBindings(&input_binding, 1);
4822 pipe.AddVertexInputAttribs(&input_attrib, 1);
4823
Chris Forbesa4b02322015-05-25 11:13:31 +12004824 VkDescriptorSetObj descriptorSet(m_device);
4825 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004826 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12004827
Tony Barboured132432015-08-04 16:23:11 -06004828 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12004829
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004830 if (!m_errorMonitor->DesiredMsgFound()) {
4831 FAIL() << "Did not receive Error 'location 0 does not match VS input type'";
4832 m_errorMonitor->DumpFailureMsgs();
Chris Forbesa4b02322015-05-25 11:13:31 +12004833 }
4834}
4835
Chris Forbes03e6d762015-11-24 11:13:14 +13004836TEST_F(VkLayerTest, CreatePipelineAttribMatrixType)
4837{
4838 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
4839
4840 ASSERT_NO_FATAL_FAILURE(InitState());
4841 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4842
4843 VkVertexInputBindingDescription input_binding;
4844 memset(&input_binding, 0, sizeof(input_binding));
4845
4846 VkVertexInputAttributeDescription input_attribs[2];
4847 memset(input_attribs, 0, sizeof(input_attribs));
4848
4849 for (int i = 0; i < 2; i++) {
4850 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
4851 input_attribs[i].location = i;
4852 }
4853
4854 char const *vsSource =
4855 "#version 140\n"
4856 "#extension GL_ARB_separate_shader_objects: require\n"
4857 "#extension GL_ARB_shading_language_420pack: require\n"
4858 "\n"
4859 "layout(location=0) in mat2x4 x;\n"
4860 "void main(){\n"
4861 " gl_Position = x[0] + x[1];\n"
4862 "}\n";
4863 char const *fsSource =
4864 "#version 140\n"
4865 "#extension GL_ARB_separate_shader_objects: require\n"
4866 "#extension GL_ARB_shading_language_420pack: require\n"
4867 "\n"
4868 "layout(location=0) out vec4 color;\n"
4869 "void main(){\n"
4870 " color = vec4(1);\n"
4871 "}\n";
4872
4873 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4874 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4875
4876 VkPipelineObj pipe(m_device);
4877 pipe.AddColorAttachment();
4878 pipe.AddShader(&vs);
4879 pipe.AddShader(&fs);
4880
4881 pipe.AddVertexInputBindings(&input_binding, 1);
4882 pipe.AddVertexInputAttribs(input_attribs, 2);
4883
4884 VkDescriptorSetObj descriptorSet(m_device);
4885 descriptorSet.AppendDummy();
4886 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
4887
4888 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4889
4890 /* expect success */
4891 if (m_errorMonitor->DesiredMsgFound()) {
4892 FAIL() << "Expected to succeed but: " << m_errorMonitor->GetFailureMsg();
4893 m_errorMonitor->DumpFailureMsgs();
4894 }
4895}
4896
4897/*
4898 * Would work, but not supported by glslang! This is similar to the matrix case above.
4899 *
4900TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
4901{
4902 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
4903
4904 ASSERT_NO_FATAL_FAILURE(InitState());
4905 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4906
4907 VkVertexInputBindingDescription input_binding;
4908 memset(&input_binding, 0, sizeof(input_binding));
4909
4910 VkVertexInputAttributeDescription input_attribs[2];
4911 memset(input_attribs, 0, sizeof(input_attribs));
4912
4913 for (int i = 0; i < 2; i++) {
4914 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
4915 input_attribs[i].location = i;
4916 }
4917
4918 char const *vsSource =
4919 "#version 140\n"
4920 "#extension GL_ARB_separate_shader_objects: require\n"
4921 "#extension GL_ARB_shading_language_420pack: require\n"
4922 "\n"
4923 "layout(location=0) in vec4 x[2];\n"
4924 "void main(){\n"
4925 " gl_Position = x[0] + x[1];\n"
4926 "}\n";
4927 char const *fsSource =
4928 "#version 140\n"
4929 "#extension GL_ARB_separate_shader_objects: require\n"
4930 "#extension GL_ARB_shading_language_420pack: require\n"
4931 "\n"
4932 "layout(location=0) out vec4 color;\n"
4933 "void main(){\n"
4934 " color = vec4(1);\n"
4935 "}\n";
4936
4937 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4938 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4939
4940 VkPipelineObj pipe(m_device);
4941 pipe.AddColorAttachment();
4942 pipe.AddShader(&vs);
4943 pipe.AddShader(&fs);
4944
4945 pipe.AddVertexInputBindings(&input_binding, 1);
4946 pipe.AddVertexInputAttribs(input_attribs, 2);
4947
4948 VkDescriptorSetObj descriptorSet(m_device);
4949 descriptorSet.AppendDummy();
4950 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
4951
4952 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4953
4954 if (m_errorMonitor->DesiredMsgFound()) {
4955 FAIL() << "Expected to succeed but: " << m_errorMonitor->GetFailureMsg();
4956 m_errorMonitor->DumpFailureMsgs();
4957 }
4958}
4959*/
4960
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004961TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
4962{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004963 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4964 "Duplicate vertex input binding descriptions for binding 0");
4965
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004966 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004967 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004968
4969 /* Two binding descriptions for binding 0 */
4970 VkVertexInputBindingDescription input_bindings[2];
4971 memset(input_bindings, 0, sizeof(input_bindings));
4972
4973 VkVertexInputAttributeDescription input_attrib;
4974 memset(&input_attrib, 0, sizeof(input_attrib));
4975 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4976
4977 char const *vsSource =
4978 "#version 140\n"
4979 "#extension GL_ARB_separate_shader_objects: require\n"
4980 "#extension GL_ARB_shading_language_420pack: require\n"
4981 "\n"
4982 "layout(location=0) in float x;\n" /* attrib provided float */
4983 "void main(){\n"
4984 " gl_Position = vec4(x);\n"
4985 "}\n";
4986 char const *fsSource =
4987 "#version 140\n"
4988 "#extension GL_ARB_separate_shader_objects: require\n"
4989 "#extension GL_ARB_shading_language_420pack: require\n"
4990 "\n"
4991 "layout(location=0) out vec4 color;\n"
4992 "void main(){\n"
4993 " color = vec4(1);\n"
4994 "}\n";
4995
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004996 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4997 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004998
4999 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08005000 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12005001 pipe.AddShader(&vs);
5002 pipe.AddShader(&fs);
5003
5004 pipe.AddVertexInputBindings(input_bindings, 2);
5005 pipe.AddVertexInputAttribs(&input_attrib, 1);
5006
Chris Forbes0bf8fe12015-06-12 11:16:41 +12005007 VkDescriptorSetObj descriptorSet(m_device);
5008 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005009 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12005010
Tony Barboured132432015-08-04 16:23:11 -06005011 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12005012
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005013 if (!m_errorMonitor->DesiredMsgFound()) {
5014 FAIL() << "Did not receive Error 'Duplicate vertex input binding descriptions for binding 0'";
5015 m_errorMonitor->DumpFailureMsgs();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12005016 }
5017}
Chris Forbes4c948702015-05-25 11:13:32 +12005018
Chris Forbesc12ef122015-05-25 11:13:40 +12005019TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
5020{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005021 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5022 "Attachment 0 not written by FS");
5023
Chris Forbesc12ef122015-05-25 11:13:40 +12005024 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12005025
5026 char const *vsSource =
5027 "#version 140\n"
5028 "#extension GL_ARB_separate_shader_objects: require\n"
5029 "#extension GL_ARB_shading_language_420pack: require\n"
5030 "\n"
5031 "void main(){\n"
5032 " gl_Position = vec4(1);\n"
5033 "}\n";
5034 char const *fsSource =
5035 "#version 140\n"
5036 "#extension GL_ARB_separate_shader_objects: require\n"
5037 "#extension GL_ARB_shading_language_420pack: require\n"
5038 "\n"
5039 "void main(){\n"
5040 "}\n";
5041
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005042 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5043 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc12ef122015-05-25 11:13:40 +12005044
5045 VkPipelineObj pipe(m_device);
5046 pipe.AddShader(&vs);
5047 pipe.AddShader(&fs);
5048
Chia-I Wuc278df82015-07-07 11:50:03 +08005049 /* set up CB 0, not written */
5050 pipe.AddColorAttachment();
5051 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12005052
Chris Forbesc12ef122015-05-25 11:13:40 +12005053 VkDescriptorSetObj descriptorSet(m_device);
5054 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005055 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12005056
Tony Barboured132432015-08-04 16:23:11 -06005057 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12005058
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005059 if (!m_errorMonitor->DesiredMsgFound()) {
5060 FAIL() << "Did not receive Error 'Attachment 0 not written by FS'";
5061 m_errorMonitor->DumpFailureMsgs();
Chris Forbesc12ef122015-05-25 11:13:40 +12005062 }
5063}
5064
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005065TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
5066{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005067 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
5068 "FS writes to output location 1 with no matching attachment");
5069
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005070 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005071
5072 char const *vsSource =
5073 "#version 140\n"
5074 "#extension GL_ARB_separate_shader_objects: require\n"
5075 "#extension GL_ARB_shading_language_420pack: require\n"
5076 "\n"
5077 "void main(){\n"
5078 " gl_Position = vec4(1);\n"
5079 "}\n";
5080 char const *fsSource =
5081 "#version 140\n"
5082 "#extension GL_ARB_separate_shader_objects: require\n"
5083 "#extension GL_ARB_shading_language_420pack: require\n"
5084 "\n"
5085 "layout(location=0) out vec4 x;\n"
5086 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
5087 "void main(){\n"
5088 " x = vec4(1);\n"
5089 " y = vec4(1);\n"
5090 "}\n";
5091
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005092 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5093 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005094
5095 VkPipelineObj pipe(m_device);
5096 pipe.AddShader(&vs);
5097 pipe.AddShader(&fs);
5098
Chia-I Wuc278df82015-07-07 11:50:03 +08005099 /* set up CB 0, not written */
5100 pipe.AddColorAttachment();
5101 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005102 /* FS writes CB 1, but we don't configure it */
5103
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005104 VkDescriptorSetObj descriptorSet(m_device);
5105 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005106 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005107
Tony Barboured132432015-08-04 16:23:11 -06005108 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005109
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005110 if (!m_errorMonitor->DesiredMsgFound()) {
5111 FAIL() << "Did not receive Error 'FS writes to output location 1 with no matching attachment'";
5112 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005113 }
5114}
5115
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005116TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
5117{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005118 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5119 "does not match FS output type");
5120
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005121 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005122
5123 char const *vsSource =
5124 "#version 140\n"
5125 "#extension GL_ARB_separate_shader_objects: require\n"
5126 "#extension GL_ARB_shading_language_420pack: require\n"
5127 "\n"
5128 "void main(){\n"
5129 " gl_Position = vec4(1);\n"
5130 "}\n";
5131 char const *fsSource =
5132 "#version 140\n"
5133 "#extension GL_ARB_separate_shader_objects: require\n"
5134 "#extension GL_ARB_shading_language_420pack: require\n"
5135 "\n"
5136 "layout(location=0) out ivec4 x;\n" /* not UNORM */
5137 "void main(){\n"
5138 " x = ivec4(1);\n"
5139 "}\n";
5140
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005141 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5142 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005143
5144 VkPipelineObj pipe(m_device);
5145 pipe.AddShader(&vs);
5146 pipe.AddShader(&fs);
5147
Chia-I Wuc278df82015-07-07 11:50:03 +08005148 /* set up CB 0; type is UNORM by default */
5149 pipe.AddColorAttachment();
5150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005151
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005152 VkDescriptorSetObj descriptorSet(m_device);
5153 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005154 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005155
Tony Barboured132432015-08-04 16:23:11 -06005156 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005157
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005158 if (!m_errorMonitor->DesiredMsgFound()) {
5159 FAIL() << "Did not receive Error 'does not match FS output type'";
5160 m_errorMonitor->DumpFailureMsgs();
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005161 }
5162}
Chris Forbesc2050732015-06-05 14:43:36 +12005163
Chris Forbes76ce7882015-08-14 12:04:59 +12005164TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
5165{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005166 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5167 "not declared in pipeline layout");
5168
Chris Forbes76ce7882015-08-14 12:04:59 +12005169 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +12005170
5171 char const *vsSource =
5172 "#version 140\n"
5173 "#extension GL_ARB_separate_shader_objects: require\n"
5174 "#extension GL_ARB_shading_language_420pack: require\n"
5175 "\n"
5176 "void main(){\n"
5177 " gl_Position = vec4(1);\n"
5178 "}\n";
5179 char const *fsSource =
5180 "#version 140\n"
5181 "#extension GL_ARB_separate_shader_objects: require\n"
5182 "#extension GL_ARB_shading_language_420pack: require\n"
5183 "\n"
5184 "layout(location=0) out vec4 x;\n"
5185 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5186 "void main(){\n"
5187 " x = vec4(bar.y);\n"
5188 "}\n";
5189
Chris Forbes76ce7882015-08-14 12:04:59 +12005190
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005191 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5192 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes76ce7882015-08-14 12:04:59 +12005193
Chris Forbes76ce7882015-08-14 12:04:59 +12005194 VkPipelineObj pipe(m_device);
5195 pipe.AddShader(&vs);
5196 pipe.AddShader(&fs);
5197
5198 /* set up CB 0; type is UNORM by default */
5199 pipe.AddColorAttachment();
5200 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5201
5202 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1f851912015-10-27 18:04:07 +08005203 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes76ce7882015-08-14 12:04:59 +12005204
5205 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5206
5207 /* should have generated an error -- pipeline layout does not
5208 * provide a uniform buffer in 0.0
5209 */
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005210 if (!m_errorMonitor->DesiredMsgFound()) {
5211 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
5212 m_errorMonitor->DumpFailureMsgs();
Chris Forbes76ce7882015-08-14 12:04:59 +12005213 }
5214}
5215
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06005216#endif // SHADER_CHECKER_TESTS
5217
5218#if DEVICE_LIMITS_TESTS
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005219TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
5220{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005221 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5222 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005223
5224 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005225
5226 // Create an image
5227 VkImage image;
5228
5229 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5230 const int32_t tex_width = 32;
5231 const int32_t tex_height = 32;
5232
5233 VkImageCreateInfo image_create_info = {};
5234 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5235 image_create_info.pNext = NULL;
5236 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5237 image_create_info.format = tex_format;
5238 image_create_info.extent.width = tex_width;
5239 image_create_info.extent.height = tex_height;
5240 image_create_info.extent.depth = 1;
5241 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005242 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005243 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005244 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5245 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5246 image_create_info.flags = 0;
5247
5248 // Introduce error by sending down a bogus width extent
5249 image_create_info.extent.width = 65536;
Chia-I Wu69f40122015-10-26 21:10:41 +08005250 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005251
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005252 if (!m_errorMonitor->DesiredMsgFound()) {
5253 FAIL() << "Did not receive Error 'CreateImage extents exceed allowable limits for format'";
5254 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005255 }
5256}
5257
5258TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
5259{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005260 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5261 "CreateImage resource size exceeds allowable maximum");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005262
5263 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005264
5265 // Create an image
5266 VkImage image;
5267
5268 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5269 const int32_t tex_width = 32;
5270 const int32_t tex_height = 32;
5271
5272 VkImageCreateInfo image_create_info = {};
5273 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5274 image_create_info.pNext = NULL;
5275 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5276 image_create_info.format = tex_format;
5277 image_create_info.extent.width = tex_width;
5278 image_create_info.extent.height = tex_height;
5279 image_create_info.extent.depth = 1;
5280 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005281 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005282 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005283 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5284 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5285 image_create_info.flags = 0;
5286
5287 // Introduce error by sending down individually allowable values that result in a surface size
5288 // exceeding the device maximum
5289 image_create_info.extent.width = 8192;
5290 image_create_info.extent.height = 8192;
5291 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005292 image_create_info.arrayLayers = 4;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005293 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005294 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
Chia-I Wu69f40122015-10-26 21:10:41 +08005295 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005296
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005297 if (!m_errorMonitor->DesiredMsgFound()) {
5298 FAIL() << "Did not receive Error 'CreateImage resource size exceeds allowable maximum'";
5299 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005300 }
5301}
5302
Mike Stroyan43909d82015-09-25 13:39:21 -06005303TEST_F(VkLayerTest, UpdateBufferAlignment)
5304{
Mike Stroyan43909d82015-09-25 13:39:21 -06005305 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
5306
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005307 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5308 "dstOffset, is not a multiple of 4");
5309
Mike Stroyan43909d82015-09-25 13:39:21 -06005310 ASSERT_NO_FATAL_FAILURE(InitState());
5311
5312 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5313 vk_testing::Buffer buffer;
5314 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
5315
5316 BeginCommandBuffer();
5317 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08005318 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005319 if (!m_errorMonitor->DesiredMsgFound()) {
5320 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
5321 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005322 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005323
Mike Stroyan43909d82015-09-25 13:39:21 -06005324 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005325 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5326 "dataSize, is not a multiple of 4");
5327
Chia-I Wu1f851912015-10-27 18:04:07 +08005328 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005329
5330 if (!m_errorMonitor->DesiredMsgFound()) {
5331 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
5332 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005333 }
5334 EndCommandBuffer();
5335}
5336
5337TEST_F(VkLayerTest, FillBufferAlignment)
5338{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005339 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5340 "dstOffset, is not a multiple of 4");
Mike Stroyan43909d82015-09-25 13:39:21 -06005341
5342 ASSERT_NO_FATAL_FAILURE(InitState());
5343
5344 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5345 vk_testing::Buffer buffer;
5346 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
5347
5348 BeginCommandBuffer();
5349 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08005350 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005351 if (!m_errorMonitor->DesiredMsgFound()) {
5352 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
5353 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005354 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005355
Mike Stroyan43909d82015-09-25 13:39:21 -06005356 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005357 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5358 "size, is not a multiple of 4");
5359
Chia-I Wu1f851912015-10-27 18:04:07 +08005360 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005361
5362 if (!m_errorMonitor->DesiredMsgFound()) {
5363 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize size, is not a multiple of 4'";
5364 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005365 }
5366 EndCommandBuffer();
5367}
5368
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06005369#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005370
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005371#if IMAGE_TESTS
5372TEST_F(VkLayerTest, InvalidImageView)
5373{
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005374 VkResult err;
5375
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005376 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5377 "vkCreateImageView called with baseMipLevel 10 ");
5378
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005379 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005380
Mike Stroyan43909d82015-09-25 13:39:21 -06005381 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005382 VkImage image;
5383
5384 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5385 const int32_t tex_width = 32;
5386 const int32_t tex_height = 32;
5387
5388 VkImageCreateInfo image_create_info = {};
5389 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5390 image_create_info.pNext = NULL;
5391 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5392 image_create_info.format = tex_format;
5393 image_create_info.extent.width = tex_width;
5394 image_create_info.extent.height = tex_height;
5395 image_create_info.extent.depth = 1;
5396 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005397 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005398 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005399 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5400 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5401 image_create_info.flags = 0;
5402
Chia-I Wu69f40122015-10-26 21:10:41 +08005403 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005404 ASSERT_VK_SUCCESS(err);
5405
5406 VkImageViewCreateInfo image_view_create_info = {};
5407 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5408 image_view_create_info.image = image;
5409 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5410 image_view_create_info.format = tex_format;
Chia-I Wu1f851912015-10-27 18:04:07 +08005411 image_view_create_info.subresourceRange.layerCount = 1;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005412 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Chia-I Wu1f851912015-10-27 18:04:07 +08005413 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005414 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005415
5416 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08005417 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005418
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005419 if (!m_errorMonitor->DesiredMsgFound()) {
5420 FAIL() << "Did not receive Error 'vkCreateImageView called with baseMipLevel 10...'";
5421 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005422 }
5423}
Mike Stroyan43909d82015-09-25 13:39:21 -06005424
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005425TEST_F(VkLayerTest, InvalidImageViewAspect)
5426{
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005427 VkResult err;
5428
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005429 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5430 "vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set");
5431
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005432 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005433
5434 // Create an image and try to create a view with an invalid aspectMask
5435 VkImage image;
5436
5437 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5438 const int32_t tex_width = 32;
5439 const int32_t tex_height = 32;
5440
5441 VkImageCreateInfo image_create_info = {};
5442 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5443 image_create_info.pNext = NULL;
5444 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5445 image_create_info.format = tex_format;
5446 image_create_info.extent.width = tex_width;
5447 image_create_info.extent.height = tex_height;
5448 image_create_info.extent.depth = 1;
5449 image_create_info.mipLevels = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005450 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005451 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5452 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5453 image_create_info.flags = 0;
5454
Chia-I Wu69f40122015-10-26 21:10:41 +08005455 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005456 ASSERT_VK_SUCCESS(err);
5457
5458 VkImageViewCreateInfo image_view_create_info = {};
5459 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5460 image_view_create_info.image = image;
5461 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5462 image_view_create_info.format = tex_format;
5463 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005464 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005465 // Cause an error by setting an invalid image aspect
5466 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
5467
5468 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08005469 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005470
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005471 if (!m_errorMonitor->DesiredMsgFound()) {
5472 FAIL() << "Did not receive Error 'VkCreateImageView: Color image formats must have ...'";
5473 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005474 }
5475}
5476
Mike Stroyan43909d82015-09-25 13:39:21 -06005477TEST_F(VkLayerTest, CopyImageTypeMismatch)
5478{
Mike Stroyan43909d82015-09-25 13:39:21 -06005479 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005480 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005481
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005482 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5483 "vkCmdCopyImage called with unmatched source and dest image types");
5484
Mike Stroyan43909d82015-09-25 13:39:21 -06005485 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005486
5487 // Create two images of different types and try to copy between them
5488 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005489 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005490 VkDeviceMemory srcMem;
5491 VkDeviceMemory destMem;
5492 VkMemoryRequirements memReqs;
5493
5494 VkImageCreateInfo image_create_info = {};
5495 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5496 image_create_info.pNext = NULL;
5497 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5498 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5499 image_create_info.extent.width = 32;
5500 image_create_info.extent.height = 32;
5501 image_create_info.extent.depth = 1;
5502 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005503 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005504 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005505 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005506 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005507 image_create_info.flags = 0;
5508
Chia-I Wu69f40122015-10-26 21:10:41 +08005509 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005510 ASSERT_VK_SUCCESS(err);
5511
5512 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005513 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005514
Chia-I Wu1f851912015-10-27 18:04:07 +08005515 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005516 ASSERT_VK_SUCCESS(err);
5517
5518 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005519 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005520 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005521 memAlloc.pNext = NULL;
5522 memAlloc.allocationSize = 0;
5523 memAlloc.memoryTypeIndex = 0;
5524
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005525 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005526 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005527 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5528 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005529 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005530 ASSERT_VK_SUCCESS(err);
5531
Chia-I Wu1f851912015-10-27 18:04:07 +08005532 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005533 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005534 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005535 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005536 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005537 ASSERT_VK_SUCCESS(err);
5538
5539 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5540 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005541 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005542 ASSERT_VK_SUCCESS(err);
5543
5544 BeginCommandBuffer();
5545 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005546 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005547 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005548 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005549 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005550 copyRegion.srcOffset.x = 0;
5551 copyRegion.srcOffset.y = 0;
5552 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005553 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005554 copyRegion.dstSubresource.mipLevel = 0;
5555 copyRegion.dstSubresource.baseArrayLayer = 0;
5556 copyRegion.dstSubresource.layerCount = 0;
5557 copyRegion.dstOffset.x = 0;
5558 copyRegion.dstOffset.y = 0;
5559 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005560 copyRegion.extent.width = 1;
5561 copyRegion.extent.height = 1;
5562 copyRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005563 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005564 EndCommandBuffer();
5565
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005566 if (!m_errorMonitor->DesiredMsgFound()) {
5567 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5568 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005569 }
5570
Chia-I Wu69f40122015-10-26 21:10:41 +08005571 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005572 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005573 vkFreeMemory(m_device->device(), srcMem, NULL);
5574 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005575}
5576
5577TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
5578{
5579 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
5580}
5581
5582TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
5583{
Mike Stroyan43909d82015-09-25 13:39:21 -06005584 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005585 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005586
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005587 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5588 "vkCmdCopyImage called with unmatched source and dest image types");
5589
Mike Stroyan43909d82015-09-25 13:39:21 -06005590 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005591
5592 // Create two images of different types and try to copy between them
5593 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005594 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005595 VkDeviceMemory srcMem;
5596 VkDeviceMemory destMem;
5597 VkMemoryRequirements memReqs;
5598
5599 VkImageCreateInfo image_create_info = {};
5600 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5601 image_create_info.pNext = NULL;
5602 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5603 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5604 image_create_info.extent.width = 32;
5605 image_create_info.extent.height = 32;
5606 image_create_info.extent.depth = 1;
5607 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005608 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005609 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005610 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005611 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005612 image_create_info.flags = 0;
5613
Chia-I Wu69f40122015-10-26 21:10:41 +08005614 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005615 ASSERT_VK_SUCCESS(err);
5616
5617 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005618 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005619
Chia-I Wu1f851912015-10-27 18:04:07 +08005620 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005621 ASSERT_VK_SUCCESS(err);
5622
5623 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005624 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005625 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005626 memAlloc.pNext = NULL;
5627 memAlloc.allocationSize = 0;
5628 memAlloc.memoryTypeIndex = 0;
5629
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005630 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005631 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005632 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5633 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005634 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005635 ASSERT_VK_SUCCESS(err);
5636
Chia-I Wu1f851912015-10-27 18:04:07 +08005637 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005638 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005639 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5640 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005641 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005642 ASSERT_VK_SUCCESS(err);
5643
5644 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5645 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005646 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005647 ASSERT_VK_SUCCESS(err);
5648
5649 BeginCommandBuffer();
5650 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005651 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005652 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005653 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005654 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005655 copyRegion.srcOffset.x = 0;
5656 copyRegion.srcOffset.y = 0;
5657 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005658 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005659 copyRegion.dstSubresource.mipLevel = 0;
5660 copyRegion.dstSubresource.baseArrayLayer = 0;
5661 copyRegion.dstSubresource.layerCount = 0;
5662 copyRegion.dstOffset.x = 0;
5663 copyRegion.dstOffset.y = 0;
5664 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005665 copyRegion.extent.width = 1;
5666 copyRegion.extent.height = 1;
5667 copyRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005668 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005669 EndCommandBuffer();
5670
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005671 if (!m_errorMonitor->DesiredMsgFound()) {
5672 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5673 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005674 }
5675
Chia-I Wu69f40122015-10-26 21:10:41 +08005676 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005677 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005678 vkFreeMemory(m_device->device(), srcMem, NULL);
5679 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005680}
5681
5682TEST_F(VkLayerTest, ResolveImageLowSampleCount)
5683{
Mike Stroyan43909d82015-09-25 13:39:21 -06005684 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005685 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005686
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005687 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5688 "vkCmdResolveImage called with source sample count less than 2.");
5689
Mike Stroyan43909d82015-09-25 13:39:21 -06005690 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005691
5692 // Create two images of sample count 1 and try to Resolve between them
5693 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005694 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005695 VkDeviceMemory srcMem;
5696 VkDeviceMemory destMem;
5697 VkMemoryRequirements memReqs;
5698
5699 VkImageCreateInfo image_create_info = {};
5700 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5701 image_create_info.pNext = NULL;
5702 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5703 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5704 image_create_info.extent.width = 32;
5705 image_create_info.extent.height = 1;
5706 image_create_info.extent.depth = 1;
5707 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005708 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005709 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005710 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005711 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005712 image_create_info.flags = 0;
5713
Chia-I Wu69f40122015-10-26 21:10:41 +08005714 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005715 ASSERT_VK_SUCCESS(err);
5716
5717 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005718 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005719
Chia-I Wu1f851912015-10-27 18:04:07 +08005720 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005721 ASSERT_VK_SUCCESS(err);
5722
5723 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005724 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005725 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005726 memAlloc.pNext = NULL;
5727 memAlloc.allocationSize = 0;
5728 memAlloc.memoryTypeIndex = 0;
5729
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005730 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005731 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005732 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5733 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005734 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005735 ASSERT_VK_SUCCESS(err);
5736
Chia-I Wu1f851912015-10-27 18:04:07 +08005737 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005738 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005739 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5740 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005741 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005742 ASSERT_VK_SUCCESS(err);
5743
5744 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5745 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005746 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005747 ASSERT_VK_SUCCESS(err);
5748
5749 BeginCommandBuffer();
5750 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5751 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5752 //VK_IMAGE_LAYOUT_GENERAL = 1,
5753 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005754 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005755 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005756 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005757 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005758 resolveRegion.srcOffset.x = 0;
5759 resolveRegion.srcOffset.y = 0;
5760 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005761 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005762 resolveRegion.dstSubresource.mipLevel = 0;
5763 resolveRegion.dstSubresource.baseArrayLayer = 0;
5764 resolveRegion.dstSubresource.layerCount = 0;
5765 resolveRegion.dstOffset.x = 0;
5766 resolveRegion.dstOffset.y = 0;
5767 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005768 resolveRegion.extent.width = 1;
5769 resolveRegion.extent.height = 1;
5770 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005771 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005772 EndCommandBuffer();
5773
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005774 if (!m_errorMonitor->DesiredMsgFound()) {
5775 FAIL() << "Did not receive Error 'vkCmdResolveImage called with source sample count less than 2.'";
5776 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005777 }
5778
Chia-I Wu69f40122015-10-26 21:10:41 +08005779 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005780 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005781 vkFreeMemory(m_device->device(), srcMem, NULL);
5782 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005783}
5784
5785TEST_F(VkLayerTest, ResolveImageHighSampleCount)
5786{
Mike Stroyan43909d82015-09-25 13:39:21 -06005787 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005788 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005789
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005790 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5791 "vkCmdResolveImage called with dest sample count greater than 1.");
5792
Mike Stroyan43909d82015-09-25 13:39:21 -06005793 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005794
5795 // Create two images of sample count 2 and try to Resolve between them
5796 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005797 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005798 VkDeviceMemory srcMem;
5799 VkDeviceMemory destMem;
5800 VkMemoryRequirements memReqs;
5801
5802 VkImageCreateInfo image_create_info = {};
5803 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5804 image_create_info.pNext = NULL;
5805 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5806 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5807 image_create_info.extent.width = 32;
5808 image_create_info.extent.height = 1;
5809 image_create_info.extent.depth = 1;
5810 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005811 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005812 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005813 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005814 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005815 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005816 image_create_info.flags = 0;
5817
Chia-I Wu69f40122015-10-26 21:10:41 +08005818 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005819 ASSERT_VK_SUCCESS(err);
5820
5821 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005822 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005823 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005824
Chia-I Wu1f851912015-10-27 18:04:07 +08005825 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005826 ASSERT_VK_SUCCESS(err);
5827
5828 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005829 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005830 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005831 memAlloc.pNext = NULL;
5832 memAlloc.allocationSize = 0;
5833 memAlloc.memoryTypeIndex = 0;
5834
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005835 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005836 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005837 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5838 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005839 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005840 ASSERT_VK_SUCCESS(err);
5841
Chia-I Wu1f851912015-10-27 18:04:07 +08005842 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005843 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005844 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5845 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005846 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005847 ASSERT_VK_SUCCESS(err);
5848
5849 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5850 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005851 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005852 ASSERT_VK_SUCCESS(err);
5853
5854 BeginCommandBuffer();
5855 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5856 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5857 //VK_IMAGE_LAYOUT_GENERAL = 1,
5858 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005859 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005860 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005861 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005862 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005863 resolveRegion.srcOffset.x = 0;
5864 resolveRegion.srcOffset.y = 0;
5865 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005866 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005867 resolveRegion.dstSubresource.mipLevel = 0;
5868 resolveRegion.dstSubresource.baseArrayLayer = 0;
5869 resolveRegion.dstSubresource.layerCount = 0;
5870 resolveRegion.dstOffset.x = 0;
5871 resolveRegion.dstOffset.y = 0;
5872 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005873 resolveRegion.extent.width = 1;
5874 resolveRegion.extent.height = 1;
5875 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005876 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005877 EndCommandBuffer();
5878
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005879 if (!m_errorMonitor->DesiredMsgFound()) {
5880 FAIL() << "Did not receive Error 'vkCmdResolveImage called with dest sample count greater than 1.'";
5881 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005882 }
5883
Chia-I Wu69f40122015-10-26 21:10:41 +08005884 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005885 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005886 vkFreeMemory(m_device->device(), srcMem, NULL);
5887 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005888}
5889
5890TEST_F(VkLayerTest, ResolveImageFormatMismatch)
5891{
Mike Stroyan43909d82015-09-25 13:39:21 -06005892 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005893 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005894
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005895 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5896 "vkCmdResolveImage called with unmatched source and dest formats.");
5897
Mike Stroyan43909d82015-09-25 13:39:21 -06005898 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005899
5900 // Create two images of different types and try to copy between them
5901 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005902 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005903 VkDeviceMemory srcMem;
5904 VkDeviceMemory destMem;
5905 VkMemoryRequirements memReqs;
5906
5907 VkImageCreateInfo image_create_info = {};
5908 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5909 image_create_info.pNext = NULL;
5910 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5911 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5912 image_create_info.extent.width = 32;
5913 image_create_info.extent.height = 1;
5914 image_create_info.extent.depth = 1;
5915 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005916 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005917 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005918 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005919 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005920 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005921 image_create_info.flags = 0;
5922
Chia-I Wu69f40122015-10-26 21:10:41 +08005923 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005924 ASSERT_VK_SUCCESS(err);
5925
Cody Northropb3bf94f2015-10-27 13:50:04 -06005926 // Set format to something other than source image
5927 image_create_info.format = VK_FORMAT_R32_SFLOAT;
5928 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005929 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005930 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005931
Chia-I Wu1f851912015-10-27 18:04:07 +08005932 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005933 ASSERT_VK_SUCCESS(err);
5934
5935 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005936 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005937 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005938 memAlloc.pNext = NULL;
5939 memAlloc.allocationSize = 0;
5940 memAlloc.memoryTypeIndex = 0;
5941
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005942 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005943 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005944 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5945 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005946 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005947 ASSERT_VK_SUCCESS(err);
5948
Chia-I Wu1f851912015-10-27 18:04:07 +08005949 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005950 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005951 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5952 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005953 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005954 ASSERT_VK_SUCCESS(err);
5955
5956 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5957 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005958 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005959 ASSERT_VK_SUCCESS(err);
5960
5961 BeginCommandBuffer();
5962 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5963 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5964 //VK_IMAGE_LAYOUT_GENERAL = 1,
5965 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005966 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005967 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005968 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005969 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005970 resolveRegion.srcOffset.x = 0;
5971 resolveRegion.srcOffset.y = 0;
5972 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005973 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005974 resolveRegion.dstSubresource.mipLevel = 0;
5975 resolveRegion.dstSubresource.baseArrayLayer = 0;
5976 resolveRegion.dstSubresource.layerCount = 0;
5977 resolveRegion.dstOffset.x = 0;
5978 resolveRegion.dstOffset.y = 0;
5979 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005980 resolveRegion.extent.width = 1;
5981 resolveRegion.extent.height = 1;
5982 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005983 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005984 EndCommandBuffer();
5985
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005986 if (!m_errorMonitor->DesiredMsgFound()) {
5987 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest formats.'";
5988 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005989 }
5990
Chia-I Wu69f40122015-10-26 21:10:41 +08005991 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005992 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005993 vkFreeMemory(m_device->device(), srcMem, NULL);
5994 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005995}
5996
5997TEST_F(VkLayerTest, ResolveImageTypeMismatch)
5998{
Mike Stroyan43909d82015-09-25 13:39:21 -06005999 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06006000 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06006001
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006002 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
6003 "vkCmdResolveImage called with unmatched source and dest image types.");
6004
Mike Stroyan43909d82015-09-25 13:39:21 -06006005 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06006006
6007 // Create two images of different types and try to copy between them
6008 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08006009 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06006010 VkDeviceMemory srcMem;
6011 VkDeviceMemory destMem;
6012 VkMemoryRequirements memReqs;
6013
6014 VkImageCreateInfo image_create_info = {};
6015 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6016 image_create_info.pNext = NULL;
6017 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6018 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6019 image_create_info.extent.width = 32;
6020 image_create_info.extent.height = 1;
6021 image_create_info.extent.depth = 1;
6022 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06006023 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08006024 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006025 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06006026 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08006027 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006028 image_create_info.flags = 0;
6029
Chia-I Wu69f40122015-10-26 21:10:41 +08006030 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06006031 ASSERT_VK_SUCCESS(err);
6032
6033 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northropb3bf94f2015-10-27 13:50:04 -06006034 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08006035 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08006036 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006037
Chia-I Wu1f851912015-10-27 18:04:07 +08006038 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06006039 ASSERT_VK_SUCCESS(err);
6040
6041 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08006042 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08006043 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06006044 memAlloc.pNext = NULL;
6045 memAlloc.allocationSize = 0;
6046 memAlloc.memoryTypeIndex = 0;
6047
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06006048 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06006049 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06006050 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6051 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08006052 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06006053 ASSERT_VK_SUCCESS(err);
6054
Chia-I Wu1f851912015-10-27 18:04:07 +08006055 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06006056 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06006057 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6058 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08006059 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06006060 ASSERT_VK_SUCCESS(err);
6061
6062 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6063 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08006064 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06006065 ASSERT_VK_SUCCESS(err);
6066
6067 BeginCommandBuffer();
6068 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
6069 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
6070 //VK_IMAGE_LAYOUT_GENERAL = 1,
6071 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08006072 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006073 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06006074 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08006075 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006076 resolveRegion.srcOffset.x = 0;
6077 resolveRegion.srcOffset.y = 0;
6078 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08006079 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08006080 resolveRegion.dstSubresource.mipLevel = 0;
6081 resolveRegion.dstSubresource.baseArrayLayer = 0;
6082 resolveRegion.dstSubresource.layerCount = 0;
6083 resolveRegion.dstOffset.x = 0;
6084 resolveRegion.dstOffset.y = 0;
6085 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006086 resolveRegion.extent.width = 1;
6087 resolveRegion.extent.height = 1;
6088 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08006089 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06006090 EndCommandBuffer();
6091
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006092 if (!m_errorMonitor->DesiredMsgFound()) {
6093 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest image types.'";
6094 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06006095 }
6096
Chia-I Wu69f40122015-10-26 21:10:41 +08006097 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08006098 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08006099 vkFreeMemory(m_device->device(), srcMem, NULL);
6100 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06006101}
Tobin Ehlisb46be812015-10-23 16:00:08 -06006102
6103TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError)
6104{
6105 // Create a single Image descriptor and cause it to first hit an error due
6106 // to using a DS format, then cause it to hit error due to COLOR_BIT not set in aspect
6107 // The image format check comes 2nd in validation so we trigger it first,
6108 // then when we cause aspect fail next, bad format check will be preempted
Tobin Ehlisb46be812015-10-23 16:00:08 -06006109 VkResult err;
6110
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006111 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
6112 "Combination depth/stencil image formats can have only the ");
6113
Tobin Ehlisb46be812015-10-23 16:00:08 -06006114 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006115
Chia-I Wuc51b1212015-10-27 19:25:11 +08006116 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06006117 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu763a7492015-10-26 20:48:51 +08006118 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006119
6120 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6121 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6122 ds_pool_ci.pNext = NULL;
6123 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08006124 ds_pool_ci.poolSizeCount = 1;
6125 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006126
6127 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08006128 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006129 ASSERT_VK_SUCCESS(err);
6130
6131 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08006132 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006133 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu045654f2015-11-06 06:42:02 +08006134 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006135 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6136 dsl_binding.pImmutableSamplers = NULL;
6137
6138 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6139 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6140 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08006141 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08006142 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006143 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08006144 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006145 ASSERT_VK_SUCCESS(err);
6146
6147 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08006148 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08006149 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08006150 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006151 alloc_info.descriptorPool = ds_pool;
6152 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08006153 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006154 ASSERT_VK_SUCCESS(err);
6155
6156 VkImage image_bad;
6157 VkImage image_good;
6158 // One bad format and one good format for Color attachment
6159 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
6160 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
6161 const int32_t tex_width = 32;
6162 const int32_t tex_height = 32;
6163
6164 VkImageCreateInfo image_create_info = {};
6165 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6166 image_create_info.pNext = NULL;
6167 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6168 image_create_info.format = tex_format_bad;
6169 image_create_info.extent.width = tex_width;
6170 image_create_info.extent.height = tex_height;
6171 image_create_info.extent.depth = 1;
6172 image_create_info.mipLevels = 1;
6173 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08006174 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006175 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6176 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
6177 image_create_info.flags = 0;
6178
Chia-I Wu69f40122015-10-26 21:10:41 +08006179 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006180 ASSERT_VK_SUCCESS(err);
6181 image_create_info.format = tex_format_good;
6182 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu69f40122015-10-26 21:10:41 +08006183 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006184 ASSERT_VK_SUCCESS(err);
6185
6186 VkImageViewCreateInfo image_view_create_info = {};
6187 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6188 image_view_create_info.image = image_bad;
6189 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6190 image_view_create_info.format = tex_format_bad;
6191 image_view_create_info.subresourceRange.baseArrayLayer = 0;
6192 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08006193 image_view_create_info.subresourceRange.layerCount = 1;
6194 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006195 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6196
6197 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08006198 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006199
6200 if (!m_errorMonitor->DesiredMsgFound()) {
6201 FAIL() << "Did not receive Error 'Combination depth-stencil image formats can have only the....'";
6202 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06006203 }
6204
Chia-I Wu69f40122015-10-26 21:10:41 +08006205 vkDestroyImage(m_device->device(), image_bad, NULL);
6206 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08006207 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6208 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006209}
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06006210#endif // IMAGE_TESTS
6211
Tony Barbour30486ea2015-04-07 13:44:53 -06006212int main(int argc, char **argv) {
6213 int result;
6214
6215 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06006216 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06006217
6218 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
6219
6220 result = RUN_ALL_TESTS();
6221
Tony Barbour01999182015-04-09 12:58:51 -06006222 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06006223 return result;
6224}