blob: f4123e83d8eb296f1bdab9779ae0dbf9437532b6 [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;
Jon Ashburn0717ed52015-12-14 14:59:20 -07003424 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003425 sampler_ci.maxAnisotropy = 1;
3426 sampler_ci.compareEnable = VK_FALSE;
3427 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3428 sampler_ci.minLod = 1.0;
3429 sampler_ci.maxLod = 1.0;
3430 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003431 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3432
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003433 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003434 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003435 ASSERT_VK_SUCCESS(err);
3436
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003437 VkDescriptorImageInfo info = {};
3438 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003439
3440 VkWriteDescriptorSet descriptor_write;
3441 memset(&descriptor_write, 0, sizeof(descriptor_write));
3442 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003443 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08003444 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003445 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003446 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003447 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003448
3449 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3450
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003451 if (!m_errorMonitor->DesiredMsgFound()) {
3452 FAIL() << "Did not receive Error 'Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...'";
3453 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003454 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003455
Chia-I Wu69f40122015-10-26 21:10:41 +08003456 vkDestroySampler(m_device->device(), sampler, NULL);
3457 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3458 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003459}
3460
3461TEST_F(VkLayerTest, DSUpdateOutOfBounds)
3462{
3463 // For overlapping Update, have arrayIndex exceed that of layout
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003464 VkResult err;
3465
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003466 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3467 "Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding");
3468
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003469 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003470 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003471 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003472 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003473 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003474
3475 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3476 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3477 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003478 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003479 ds_pool_ci.poolSizeCount = 1;
3480 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003481
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003482 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003483 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003484 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003485
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003486 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003487 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003488 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003489 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003490 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3491 dsl_binding.pImmutableSamplers = NULL;
3492
3493 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3494 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3495 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003496 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003497 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003498
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003499 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003500 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003501 ASSERT_VK_SUCCESS(err);
3502
3503 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003504 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003505 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003506 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003507 alloc_info.descriptorPool = ds_pool;
3508 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003509 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003510 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003511
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003512 VkSamplerCreateInfo sampler_ci = {};
3513 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3514 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003515 sampler_ci.magFilter = VK_FILTER_NEAREST;
3516 sampler_ci.minFilter = VK_FILTER_NEAREST;
3517 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003518 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3519 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3520 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003521 sampler_ci.mipLodBias = 1.0;
Jon Ashburn0717ed52015-12-14 14:59:20 -07003522 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003523 sampler_ci.maxAnisotropy = 1;
3524 sampler_ci.compareEnable = VK_FALSE;
3525 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3526 sampler_ci.minLod = 1.0;
3527 sampler_ci.maxLod = 1.0;
3528 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003529 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003530
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003531 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003532 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003533 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003534
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003535 VkDescriptorImageInfo info = {};
3536 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003537
3538 VkWriteDescriptorSet descriptor_write;
3539 memset(&descriptor_write, 0, sizeof(descriptor_write));
3540 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003541 descriptor_write.dstSet = descriptorSet;
3542 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wu763a7492015-10-26 20:48:51 +08003543 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003544 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003545 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003546 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003547
3548 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3549
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003550 if (!m_errorMonitor->DesiredMsgFound()) {
3551 FAIL() << "Did not receive Error 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
3552 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003553 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003554
Chia-I Wu69f40122015-10-26 21:10:41 +08003555 vkDestroySampler(m_device->device(), sampler, NULL);
3556 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3557 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003558}
3559
3560TEST_F(VkLayerTest, InvalidDSUpdateIndex)
3561{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003562 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003563 VkResult err;
3564
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003565 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3566 " does not have binding to match update binding ");
3567
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003568 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003569 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003570 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003571 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003572 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003573
3574 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3575 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3576 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003577 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003578 ds_pool_ci.poolSizeCount = 1;
3579 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003580
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003581 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003582 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003583 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003584
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003585 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003586 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003587 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003588 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003589 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3590 dsl_binding.pImmutableSamplers = NULL;
3591
3592 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3593 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3594 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003595 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003596 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003597 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003598 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003599 ASSERT_VK_SUCCESS(err);
3600
3601 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003602 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003603 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003604 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003605 alloc_info.descriptorPool = ds_pool;
3606 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003607 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003608 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003609
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003610 VkSamplerCreateInfo sampler_ci = {};
3611 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3612 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003613 sampler_ci.magFilter = VK_FILTER_NEAREST;
3614 sampler_ci.minFilter = VK_FILTER_NEAREST;
3615 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003616 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3617 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3618 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003619 sampler_ci.mipLodBias = 1.0;
Jon Ashburn0717ed52015-12-14 14:59:20 -07003620 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003621 sampler_ci.maxAnisotropy = 1;
3622 sampler_ci.compareEnable = VK_FALSE;
3623 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3624 sampler_ci.minLod = 1.0;
3625 sampler_ci.maxLod = 1.0;
3626 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003627 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003628
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003629 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003630 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003631 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003632
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003633 VkDescriptorImageInfo info = {};
3634 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003635
3636 VkWriteDescriptorSet descriptor_write;
3637 memset(&descriptor_write, 0, sizeof(descriptor_write));
3638 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003639 descriptor_write.dstSet = descriptorSet;
3640 descriptor_write.dstBinding = 2;
Chia-I Wu763a7492015-10-26 20:48:51 +08003641 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003642 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003643 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003644 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003645
3646 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3647
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003648 if (!m_errorMonitor->DesiredMsgFound()) {
3649 FAIL() << "Did not receive Error 'Descriptor Set <blah> does not have binding to match update binding '";
3650 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003651 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003652
Chia-I Wu69f40122015-10-26 21:10:41 +08003653 vkDestroySampler(m_device->device(), sampler, NULL);
3654 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3655 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003656}
3657
3658TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3659{
3660 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003661 VkResult err;
3662
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003663 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3664 "Unexpected UPDATE struct of type ");
3665
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003666 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003667
Chia-I Wuc51b1212015-10-27 19:25:11 +08003668 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003669 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003670 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003671
3672 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3673 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3674 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003675 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003676 ds_pool_ci.poolSizeCount = 1;
3677 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003678
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003679 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003680 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003681 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003682 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003683 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003684 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003685 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003686 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3687 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003688
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003689 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3690 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3691 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003692 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003693 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003694
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003695 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003696 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003697 ASSERT_VK_SUCCESS(err);
3698
3699 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003700 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003701 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003702 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003703 alloc_info.descriptorPool = ds_pool;
3704 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003705 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003706 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003707
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003708 VkSamplerCreateInfo sampler_ci = {};
3709 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3710 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003711 sampler_ci.magFilter = VK_FILTER_NEAREST;
3712 sampler_ci.minFilter = VK_FILTER_NEAREST;
3713 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003714 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3715 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3716 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003717 sampler_ci.mipLodBias = 1.0;
Jon Ashburn0717ed52015-12-14 14:59:20 -07003718 sampler_ci.anisotropyEnable = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003719 sampler_ci.maxAnisotropy = 1;
3720 sampler_ci.compareEnable = VK_FALSE;
3721 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3722 sampler_ci.minLod = 1.0;
3723 sampler_ci.maxLod = 1.0;
3724 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003725 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003726 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003727 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003728 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003729
3730
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003731 VkDescriptorImageInfo info = {};
3732 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003733
3734 VkWriteDescriptorSet descriptor_write;
3735 memset(&descriptor_write, 0, sizeof(descriptor_write));
3736 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu1f851912015-10-27 18:04:07 +08003737 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08003738 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003739 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003740 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003741 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003742
3743 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3744
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003745 if (!m_errorMonitor->DesiredMsgFound()) {
3746 FAIL() << "Did not receive Error 'Unexpected UPDATE struct of type '";
3747 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003748 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003749
Chia-I Wu69f40122015-10-26 21:10:41 +08003750 vkDestroySampler(m_device->device(), sampler, NULL);
3751 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3752 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003753}
3754
Tobin Ehlisb46be812015-10-23 16:00:08 -06003755TEST_F(VkLayerTest, SampleDescriptorUpdateError)
3756{
3757 // Create a single Sampler descriptor and send it an invalid Sampler
Tobin Ehlisb46be812015-10-23 16:00:08 -06003758 VkResult err;
3759
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003760 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3761 "Attempt to update descriptor with invalid sampler 0xbaadbeef");
3762
Tobin Ehlisb46be812015-10-23 16:00:08 -06003763 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb46be812015-10-23 16:00:08 -06003764 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied code
Chia-I Wuc51b1212015-10-27 19:25:11 +08003765 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003766 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003767 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003768
3769 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3770 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3771 ds_pool_ci.pNext = NULL;
3772 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003773 ds_pool_ci.poolSizeCount = 1;
3774 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003775
3776 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003777 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003778 ASSERT_VK_SUCCESS(err);
3779
3780 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003781 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003782 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003783 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003784 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3785 dsl_binding.pImmutableSamplers = NULL;
3786
3787 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3788 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3789 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003790 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003791 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003792 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003793 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003794 ASSERT_VK_SUCCESS(err);
3795
3796 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003797 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003798 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003799 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003800 alloc_info.descriptorPool = ds_pool;
3801 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003802 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003803 ASSERT_VK_SUCCESS(err);
3804
Chia-I Wue420a332015-10-26 20:04:44 +08003805 VkSampler sampler = (VkSampler) 0xbaadbeef; // Sampler with invalid handle
Tobin Ehlisb46be812015-10-23 16:00:08 -06003806
3807 VkDescriptorImageInfo descriptor_info;
3808 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3809 descriptor_info.sampler = sampler;
3810
3811 VkWriteDescriptorSet descriptor_write;
3812 memset(&descriptor_write, 0, sizeof(descriptor_write));
3813 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003814 descriptor_write.dstSet = descriptorSet;
3815 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003816 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003817 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3818 descriptor_write.pImageInfo = &descriptor_info;
3819
3820 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3821
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003822 if (!m_errorMonitor->DesiredMsgFound()) {
3823 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid sampler...'";
3824 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06003825 }
3826
Chia-I Wu69f40122015-10-26 21:10:41 +08003827 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3828 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003829}
3830
3831TEST_F(VkLayerTest, ImageViewDescriptorUpdateError)
3832{
3833 // Create a single combined Image/Sampler descriptor and send it an invalid imageView
Tobin Ehlisb46be812015-10-23 16:00:08 -06003834 VkResult err;
3835
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003836 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3837 "Attempt to update descriptor with invalid imageView 0xbaadbeef");
3838
Tobin Ehlisb46be812015-10-23 16:00:08 -06003839 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wuc51b1212015-10-27 19:25:11 +08003840 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003841 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003842 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003843
3844 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3845 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3846 ds_pool_ci.pNext = NULL;
3847 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003848 ds_pool_ci.poolSizeCount = 1;
3849 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003850
3851 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003852 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003853 ASSERT_VK_SUCCESS(err);
3854
3855 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003856 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003857 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003858 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003859 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3860 dsl_binding.pImmutableSamplers = NULL;
3861
3862 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3863 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3864 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003865 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003866 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003867 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003868 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003869 ASSERT_VK_SUCCESS(err);
3870
3871 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003872 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003873 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003874 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003875 alloc_info.descriptorPool = ds_pool;
3876 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003877 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003878 ASSERT_VK_SUCCESS(err);
3879
3880 VkSamplerCreateInfo sampler_ci = {};
3881 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3882 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003883 sampler_ci.magFilter = VK_FILTER_NEAREST;
3884 sampler_ci.minFilter = VK_FILTER_NEAREST;
3885 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003886 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3887 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3888 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003889 sampler_ci.mipLodBias = 1.0;
Jon Ashburn0717ed52015-12-14 14:59:20 -07003890 sampler_ci.anisotropyEnable = VK_FALSE;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003891 sampler_ci.maxAnisotropy = 1;
3892 sampler_ci.compareEnable = VK_FALSE;
3893 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3894 sampler_ci.minLod = 1.0;
3895 sampler_ci.maxLod = 1.0;
3896 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3897 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3898
3899 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003900 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003901 ASSERT_VK_SUCCESS(err);
3902
Chia-I Wue420a332015-10-26 20:04:44 +08003903 VkImageView view = (VkImageView) 0xbaadbeef; // invalid imageView object
Tobin Ehlisb46be812015-10-23 16:00:08 -06003904
3905 VkDescriptorImageInfo descriptor_info;
3906 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3907 descriptor_info.sampler = sampler;
3908 descriptor_info.imageView = view;
3909
3910 VkWriteDescriptorSet descriptor_write;
3911 memset(&descriptor_write, 0, sizeof(descriptor_write));
3912 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003913 descriptor_write.dstSet = descriptorSet;
3914 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003915 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003916 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3917 descriptor_write.pImageInfo = &descriptor_info;
3918
3919 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3920
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003921 if (!m_errorMonitor->DesiredMsgFound()) {
3922 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid imageView...'";
3923 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06003924 }
3925
Chia-I Wu69f40122015-10-26 21:10:41 +08003926 vkDestroySampler(m_device->device(), sampler, NULL);
3927 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3928 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003929}
3930
Tobin Ehlis3e676262015-10-27 16:35:27 -06003931TEST_F(VkLayerTest, CopyDescriptorUpdateErrors)
3932{
3933 // 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 -06003934 VkResult err;
3935
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003936 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3937 "Copy descriptor update index 0, update count #1, has src update descriptor type VK_DESCRIPTOR_TYPE_SAMPLER ");
3938
Tobin Ehlis3e676262015-10-27 16:35:27 -06003939 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3e676262015-10-27 16:35:27 -06003940 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003941 VkDescriptorPoolSize ds_type_count[2] = {};
Tobin Ehlis3e676262015-10-27 16:35:27 -06003942 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003943 ds_type_count[0].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003944 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003945 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003946
3947 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3948 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3949 ds_pool_ci.pNext = NULL;
3950 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003951 ds_pool_ci.poolSizeCount = 2;
3952 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003953
3954 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003955 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003956 ASSERT_VK_SUCCESS(err);
3957 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003958 dsl_binding[0].binding = 0;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003959 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003960 dsl_binding[0].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003961 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3962 dsl_binding[0].pImmutableSamplers = NULL;
Chia-I Wub5689ee2015-10-31 00:31:16 +08003963 dsl_binding[1].binding = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003964 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003965 dsl_binding[1].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003966 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
3967 dsl_binding[1].pImmutableSamplers = NULL;
3968
3969 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3970 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3971 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003972 ds_layout_ci.bindingCount = 2;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003973 ds_layout_ci.pBinding = dsl_binding;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003974
3975 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003976 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003977 ASSERT_VK_SUCCESS(err);
3978
3979 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003980 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003981 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003982 alloc_info.setLayoutCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003983 alloc_info.descriptorPool = ds_pool;
3984 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003985 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003986 ASSERT_VK_SUCCESS(err);
3987
3988 VkSamplerCreateInfo sampler_ci = {};
3989 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3990 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003991 sampler_ci.magFilter = VK_FILTER_NEAREST;
3992 sampler_ci.minFilter = VK_FILTER_NEAREST;
3993 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003994 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3995 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3996 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003997 sampler_ci.mipLodBias = 1.0;
Jon Ashburn0717ed52015-12-14 14:59:20 -07003998 sampler_ci.anisotropyEnable = VK_FALSE;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003999 sampler_ci.maxAnisotropy = 1;
4000 sampler_ci.compareEnable = VK_FALSE;
4001 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4002 sampler_ci.minLod = 1.0;
4003 sampler_ci.maxLod = 1.0;
4004 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4005 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4006
4007 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08004008 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3e676262015-10-27 16:35:27 -06004009 ASSERT_VK_SUCCESS(err);
4010
4011 VkDescriptorImageInfo info = {};
4012 info.sampler = sampler;
4013
4014 VkWriteDescriptorSet descriptor_write;
4015 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
4016 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08004017 descriptor_write.dstSet = descriptorSet;
4018 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wu763a7492015-10-26 20:48:51 +08004019 descriptor_write.descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06004020 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4021 descriptor_write.pImageInfo = &info;
4022 // This write update should succeed
4023 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4024 // Now perform a copy update that fails due to type mismatch
4025 VkCopyDescriptorSet copy_ds_update;
4026 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4027 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4028 copy_ds_update.srcSet = descriptorSet;
4029 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
Chia-I Wu1f851912015-10-27 18:04:07 +08004030 copy_ds_update.dstSet = descriptorSet;
4031 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wu763a7492015-10-26 20:48:51 +08004032 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06004033 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4034
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004035 if (!m_errorMonitor->DesiredMsgFound()) {
4036 FAIL() << "Did not receive Error 'Copy descriptor update index 0, update count #1, has src update descriptor type_DESCRIPTOR_TYPE_SAMPLER'";
4037 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06004038 }
4039 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004040 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4041 "Copy descriptor update 0 has srcBinding 3 which is out of bounds ");
Tobin Ehlis3e676262015-10-27 16:35:27 -06004042 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4043 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4044 copy_ds_update.srcSet = descriptorSet;
4045 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu1f851912015-10-27 18:04:07 +08004046 copy_ds_update.dstSet = descriptorSet;
4047 copy_ds_update.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08004048 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06004049 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4050
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004051 if (!m_errorMonitor->DesiredMsgFound()) {
4052 FAIL() << "Did not receive Error 'Copy descriptor update 0 has srcBinding 3 which is out of bounds...'";
4053 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06004054 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004055
Tobin Ehlis3e676262015-10-27 16:35:27 -06004056 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004057 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4058 "Copy descriptor src update is out of bounds for matching binding 1 ");
4059
Tobin Ehlis3e676262015-10-27 16:35:27 -06004060 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4061 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4062 copy_ds_update.srcSet = descriptorSet;
4063 copy_ds_update.srcBinding = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08004064 copy_ds_update.dstSet = descriptorSet;
4065 copy_ds_update.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08004066 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis3e676262015-10-27 16:35:27 -06004067 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4068
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004069 if (!m_errorMonitor->DesiredMsgFound()) {
4070 FAIL() << "Did not receive Error 'Copy descriptor src update is out of bounds for matching binding 1...'";
4071 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06004072 }
4073
Chia-I Wu69f40122015-10-26 21:10:41 +08004074 vkDestroySampler(m_device->device(), sampler, NULL);
4075 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4076 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis3e676262015-10-27 16:35:27 -06004077}
4078
Tobin Ehlis138b7f12015-05-22 12:38:55 -06004079TEST_F(VkLayerTest, NumSamplesMismatch)
4080{
Chia-I Wu1f851912015-10-27 18:04:07 +08004081 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004082 VkResult err;
4083
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004084 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4085 "Num samples mismatch! ");
4086
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004087 ASSERT_NO_FATAL_FAILURE(InitState());
4088 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wuc51b1212015-10-27 19:25:11 +08004089 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004090 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08004091 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004092
4093 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004094 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4095 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004096 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08004097 ds_pool_ci.poolSizeCount = 1;
4098 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004099
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004100 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08004101 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004102 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004103
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004104 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08004105 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004106 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08004107 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004108 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4109 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004110
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004111 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4112 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4113 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004114 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08004115 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004116
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004117 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004118 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004119 ASSERT_VK_SUCCESS(err);
4120
4121 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004122 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004123 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08004124 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004125 alloc_info.descriptorPool = ds_pool;
4126 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08004127 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004128 ASSERT_VK_SUCCESS(err);
4129
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004130 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4131 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4132 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004133 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004134 pipe_ms_state_ci.sampleShadingEnable = 0;
4135 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06004136 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004137
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004138 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4139 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4140 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004141 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004142 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004143
4144 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004145 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004146 ASSERT_VK_SUCCESS(err);
4147
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004148 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4149 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 -06004150 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06004151 VkPipelineObj pipe(m_device);
4152 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004153 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004154 pipe.SetMSAA(&pipe_ms_state_ci);
4155 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004156
Tony Barbour1490c912015-07-28 10:17:20 -06004157 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08004158 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004159
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004160 if (!m_errorMonitor->DesiredMsgFound()) {
4161 FAIL() << "Did not recieve Error 'Num samples mismatch!...'";
4162 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004163 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004164
Chia-I Wu69f40122015-10-26 21:10:41 +08004165 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4166 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4167 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06004168}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004169
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004170TEST_F(VkLayerTest, ClearCmdNoDraw)
4171{
Chia-I Wu1f851912015-10-27 18:04:07 +08004172 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004173 VkResult err;
4174
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004175 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
4176 "vkCmdClearAttachments() issued on CB object ");
4177
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004178 ASSERT_NO_FATAL_FAILURE(InitState());
4179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004180
Chia-I Wuc51b1212015-10-27 19:25:11 +08004181 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004182 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08004183 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004184
4185 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4186 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4187 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004188 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08004189 ds_pool_ci.poolSizeCount = 1;
4190 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004191
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004192 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08004193 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004194 ASSERT_VK_SUCCESS(err);
4195
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004196 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08004197 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004198 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08004199 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004200 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4201 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004202
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004203 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4204 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4205 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004206 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08004207 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004208
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004209 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004210 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004211 ASSERT_VK_SUCCESS(err);
4212
4213 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004214 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004215 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08004216 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004217 alloc_info.descriptorPool = ds_pool;
4218 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08004219 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004220 ASSERT_VK_SUCCESS(err);
4221
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004222 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4223 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4224 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004225 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004226 pipe_ms_state_ci.sampleShadingEnable = 0;
4227 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06004228 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004229
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004230 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4231 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4232 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004233 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004234 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004235
4236 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004237 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004238 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004239
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004240 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004241 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
4242 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4243
Tony Barbourd7d828b2015-08-06 10:16:07 -06004244 VkPipelineObj pipe(m_device);
4245 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004246 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004247 pipe.SetMSAA(&pipe_ms_state_ci);
4248 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06004249
4250 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004251
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004252 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
4253 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004254 VkClearAttachment color_attachment;
4255 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4256 color_attachment.clearValue.color.float32[0] = 1.0;
4257 color_attachment.clearValue.color.float32[1] = 1.0;
4258 color_attachment.clearValue.color.float32[2] = 1.0;
4259 color_attachment.clearValue.color.float32[3] = 1.0;
4260 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004261 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004262
Chia-I Wu1f851912015-10-27 18:04:07 +08004263 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004264
4265 if (!m_errorMonitor->DesiredMsgFound()) {
4266 FAIL() << "Did not receive Error 'vkCommandClearAttachments() issued on CB object...'";
4267 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004268 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004269
Chia-I Wu69f40122015-10-26 21:10:41 +08004270 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4271 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4272 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004273}
4274
Tobin Ehlise4076782015-06-24 15:53:07 -06004275TEST_F(VkLayerTest, VtxBufferBadIndex)
4276{
Chia-I Wu1f851912015-10-27 18:04:07 +08004277 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlise4076782015-06-24 15:53:07 -06004278 VkResult err;
4279
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004280 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4281 "Vtx Buffer Index 1 was bound, but no vtx buffers are attached to PSO.");
4282
Tobin Ehlise4076782015-06-24 15:53:07 -06004283 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06004284 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlise4076782015-06-24 15:53:07 -06004285 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004286
Chia-I Wuc51b1212015-10-27 19:25:11 +08004287 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004288 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08004289 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004290
4291 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4292 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4293 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004294 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08004295 ds_pool_ci.poolSizeCount = 1;
4296 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004297
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004298 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08004299 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06004300 ASSERT_VK_SUCCESS(err);
4301
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004302 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08004303 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004304 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08004305 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004306 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4307 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06004308
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004309 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4310 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4311 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004312 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08004313 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004314
Tobin Ehlise4076782015-06-24 15:53:07 -06004315 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08004316 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06004317 ASSERT_VK_SUCCESS(err);
4318
4319 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004320 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004321 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08004322 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004323 alloc_info.descriptorPool = ds_pool;
4324 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08004325 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06004326 ASSERT_VK_SUCCESS(err);
4327
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004328 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4329 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4330 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004331 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004332 pipe_ms_state_ci.sampleShadingEnable = 0;
4333 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06004334 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06004335
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004336 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4337 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4338 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004339 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004340 pipeline_layout_ci.pSetLayouts = &ds_layout;
4341 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06004342
Chia-I Wu69f40122015-10-26 21:10:41 +08004343 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06004344 ASSERT_VK_SUCCESS(err);
4345
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004346 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4347 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 -06004348 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06004349 VkPipelineObj pipe(m_device);
4350 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004351 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004352 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06004353 pipe.SetViewport(m_viewports);
4354 pipe.SetScissor(m_scissors);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004355 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06004356
4357 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08004358 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06004359 // Don't care about actual data, just need to get to draw to flag error
4360 static const float vbo_data[3] = {1.f, 0.f, 1.f};
4361 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
4362 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06004363 Draw(1, 0, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06004364
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004365 if (!m_errorMonitor->DesiredMsgFound()) {
4366 FAIL() << "Did not receive Error 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
4367 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise4076782015-06-24 15:53:07 -06004368 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004369
Chia-I Wu69f40122015-10-26 21:10:41 +08004370 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4371 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4372 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise4076782015-06-24 15:53:07 -06004373}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004374#endif // DRAW_STATE_TESTS
4375
Tobin Ehlis57e6a612015-05-26 16:11:58 -06004376#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06004377#if GTEST_IS_THREADSAFE
4378struct thread_data_struct {
Chia-I Wu1f851912015-10-27 18:04:07 +08004379 VkCommandBuffer commandBuffer;
Mike Stroyan09aae812015-05-12 16:00:45 -06004380 VkEvent event;
4381 bool bailout;
4382};
4383
4384extern "C" void *AddToCommandBuffer(void *arg)
4385{
4386 struct thread_data_struct *data = (struct thread_data_struct *) arg;
Mike Stroyan09aae812015-05-12 16:00:45 -06004387
4388 for (int i = 0; i<10000; i++) {
Chia-I Wucba6cea2015-10-31 00:31:16 +08004389 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyan09aae812015-05-12 16:00:45 -06004390 if (data->bailout) {
4391 break;
4392 }
4393 }
4394 return NULL;
4395}
4396
Chia-I Wu1f851912015-10-27 18:04:07 +08004397TEST_F(VkLayerTest, ThreadCommandBufferCollision)
Mike Stroyan09aae812015-05-12 16:00:45 -06004398{
Mike Stroyan7016f4f2015-07-13 14:45:35 -06004399 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06004400
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004401 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "THREADING ERROR");
4402
Mike Stroyan09aae812015-05-12 16:00:45 -06004403 ASSERT_NO_FATAL_FAILURE(InitState());
4404 ASSERT_NO_FATAL_FAILURE(InitViewport());
4405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4406
Chia-I Wu1f851912015-10-27 18:04:07 +08004407 // Calls AllocateCommandBuffers
4408 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004409
4410 // Avoid creating RenderPass
Chia-I Wu1f851912015-10-27 18:04:07 +08004411 commandBuffer.BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06004412
4413 VkEventCreateInfo event_info;
4414 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06004415 VkResult err;
4416
4417 memset(&event_info, 0, sizeof(event_info));
4418 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4419
Chia-I Wu69f40122015-10-26 21:10:41 +08004420 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyan09aae812015-05-12 16:00:45 -06004421 ASSERT_VK_SUCCESS(err);
4422
Mike Stroyan09aae812015-05-12 16:00:45 -06004423 err = vkResetEvent(device(), event);
4424 ASSERT_VK_SUCCESS(err);
4425
4426 struct thread_data_struct data;
Chia-I Wu1f851912015-10-27 18:04:07 +08004427 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyan09aae812015-05-12 16:00:45 -06004428 data.event = event;
4429 data.bailout = false;
4430 m_errorMonitor->SetBailout(&data.bailout);
4431 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06004432 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06004433 // Add many entries to command buffer from this thread at the same time.
4434 AddToCommandBuffer(&data);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004435
Mike Stroyan7016f4f2015-07-13 14:45:35 -06004436 test_platform_thread_join(thread, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08004437 commandBuffer.EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06004438
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004439 if (!m_errorMonitor->DesiredMsgFound()) {
4440 FAIL() << "Did not receive Error 'THREADING ERROR' from using one VkCommandBufferObj in two threads";
4441 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan09aae812015-05-12 16:00:45 -06004442 }
4443
Chia-I Wu69f40122015-10-26 21:10:41 +08004444 vkDestroyEvent(device(), event, NULL);
Mike Stroyan09aae812015-05-12 16:00:45 -06004445}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004446#endif // GTEST_IS_THREADSAFE
4447#endif // THREADING_TESTS
4448
Chris Forbes5af3bf22015-05-25 11:13:08 +12004449#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004450TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
4451{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004452 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4453 "Shader is not SPIR-V");
4454
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004455 ASSERT_NO_FATAL_FAILURE(InitState());
4456 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4457
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004458 VkShaderModule module;
4459 VkShaderModuleCreateInfo moduleCreateInfo;
4460 struct icd_spv_header spv;
4461
4462 spv.magic = ICD_SPV_MAGIC;
4463 spv.version = ICD_SPV_VERSION;
4464 spv.gen_magic = 0;
4465
4466 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4467 moduleCreateInfo.pNext = NULL;
Chia-I Wu036b1612015-10-26 19:22:06 +08004468 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004469 moduleCreateInfo.codeSize = 4;
4470 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004471 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004472
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004473 if (!m_errorMonitor->DesiredMsgFound()) {
4474 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4475 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004476 }
4477}
4478
4479TEST_F(VkLayerTest, InvalidSPIRVMagic)
4480{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004481 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4482 "Shader is not SPIR-V");
4483
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004484 ASSERT_NO_FATAL_FAILURE(InitState());
4485 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4486
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004487 VkShaderModule module;
4488 VkShaderModuleCreateInfo moduleCreateInfo;
4489 struct icd_spv_header spv;
4490
4491 spv.magic = ~ICD_SPV_MAGIC;
4492 spv.version = ICD_SPV_VERSION;
4493 spv.gen_magic = 0;
4494
4495 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4496 moduleCreateInfo.pNext = NULL;
Chia-I Wu036b1612015-10-26 19:22:06 +08004497 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004498 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4499 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004500 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004501
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004502 if (!m_errorMonitor->DesiredMsgFound()) {
4503 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4504 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004505 }
4506}
4507
4508TEST_F(VkLayerTest, InvalidSPIRVVersion)
4509{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004510 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4511 "Shader is not SPIR-V");
4512
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004513 ASSERT_NO_FATAL_FAILURE(InitState());
4514 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4515
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004516 VkShaderModule module;
4517 VkShaderModuleCreateInfo moduleCreateInfo;
4518 struct icd_spv_header spv;
4519
4520 spv.magic = ICD_SPV_MAGIC;
4521 spv.version = ~ICD_SPV_VERSION;
4522 spv.gen_magic = 0;
4523
4524 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4525 moduleCreateInfo.pNext = NULL;
4526
Chia-I Wu036b1612015-10-26 19:22:06 +08004527 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004528 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4529 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004530 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004531
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004532 if (!m_errorMonitor->DesiredMsgFound()) {
4533 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4534 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004535 }
4536}
4537
Chris Forbes5af3bf22015-05-25 11:13:08 +12004538TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
4539{
Tony Barbour192f02b2015-11-06 14:21:31 -07004540 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_PERF_WARN_BIT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004541 "not consumed by fragment shader");
4542
Chris Forbes5af3bf22015-05-25 11:13:08 +12004543 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004544 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12004545
4546 char const *vsSource =
4547 "#version 140\n"
4548 "#extension GL_ARB_separate_shader_objects: require\n"
4549 "#extension GL_ARB_shading_language_420pack: require\n"
4550 "\n"
4551 "layout(location=0) out float x;\n"
4552 "void main(){\n"
4553 " gl_Position = vec4(1);\n"
4554 " x = 0;\n"
4555 "}\n";
4556 char const *fsSource =
4557 "#version 140\n"
4558 "#extension GL_ARB_separate_shader_objects: require\n"
4559 "#extension GL_ARB_shading_language_420pack: require\n"
4560 "\n"
4561 "layout(location=0) out vec4 color;\n"
4562 "void main(){\n"
4563 " color = vec4(1);\n"
4564 "}\n";
4565
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004566 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4567 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5af3bf22015-05-25 11:13:08 +12004568
4569 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004570 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12004571 pipe.AddShader(&vs);
4572 pipe.AddShader(&fs);
4573
Chris Forbes5af3bf22015-05-25 11:13:08 +12004574 VkDescriptorSetObj descriptorSet(m_device);
4575 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004576 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12004577
Tony Barboured132432015-08-04 16:23:11 -06004578 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12004579
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004580 if (!m_errorMonitor->DesiredMsgFound()) {
4581 FAIL() << "Did not receive Warning 'not consumed by fragment shader'";
4582 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5af3bf22015-05-25 11:13:08 +12004583 }
4584}
Chris Forbes5af3bf22015-05-25 11:13:08 +12004585
Chris Forbes3c10b852015-05-25 11:13:13 +12004586TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
4587{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004588 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4589 "not written by vertex shader");
4590
Chris Forbes3c10b852015-05-25 11:13:13 +12004591 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004592 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12004593
4594 char const *vsSource =
4595 "#version 140\n"
4596 "#extension GL_ARB_separate_shader_objects: require\n"
4597 "#extension GL_ARB_shading_language_420pack: require\n"
4598 "\n"
4599 "void main(){\n"
4600 " gl_Position = vec4(1);\n"
4601 "}\n";
4602 char const *fsSource =
4603 "#version 140\n"
4604 "#extension GL_ARB_separate_shader_objects: require\n"
4605 "#extension GL_ARB_shading_language_420pack: require\n"
4606 "\n"
4607 "layout(location=0) in float x;\n"
4608 "layout(location=0) out vec4 color;\n"
4609 "void main(){\n"
4610 " color = vec4(x);\n"
4611 "}\n";
4612
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004613 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4614 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes3c10b852015-05-25 11:13:13 +12004615
4616 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004617 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12004618 pipe.AddShader(&vs);
4619 pipe.AddShader(&fs);
4620
Chris Forbes3c10b852015-05-25 11:13:13 +12004621 VkDescriptorSetObj descriptorSet(m_device);
4622 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004623 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12004624
Tony Barboured132432015-08-04 16:23:11 -06004625 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12004626
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004627 if (!m_errorMonitor->DesiredMsgFound()) {
4628 FAIL() << "Did not receive Error 'not written by vertex shader'";
4629 m_errorMonitor->DumpFailureMsgs();
Chris Forbes3c10b852015-05-25 11:13:13 +12004630 }
4631}
4632
Chris Forbescc281692015-05-25 11:13:17 +12004633TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
4634{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004635 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4636 "Type mismatch on location 0");
4637
Chris Forbescc281692015-05-25 11:13:17 +12004638 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12004640
4641 char const *vsSource =
4642 "#version 140\n"
4643 "#extension GL_ARB_separate_shader_objects: require\n"
4644 "#extension GL_ARB_shading_language_420pack: require\n"
4645 "\n"
4646 "layout(location=0) out int x;\n"
4647 "void main(){\n"
4648 " x = 0;\n"
4649 " gl_Position = vec4(1);\n"
4650 "}\n";
4651 char const *fsSource =
4652 "#version 140\n"
4653 "#extension GL_ARB_separate_shader_objects: require\n"
4654 "#extension GL_ARB_shading_language_420pack: require\n"
4655 "\n"
4656 "layout(location=0) in float x;\n" /* VS writes int */
4657 "layout(location=0) out vec4 color;\n"
4658 "void main(){\n"
4659 " color = vec4(x);\n"
4660 "}\n";
4661
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004662 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4663 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbescc281692015-05-25 11:13:17 +12004664
4665 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004666 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12004667 pipe.AddShader(&vs);
4668 pipe.AddShader(&fs);
4669
Chris Forbescc281692015-05-25 11:13:17 +12004670 VkDescriptorSetObj descriptorSet(m_device);
4671 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004672 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12004673
Tony Barboured132432015-08-04 16:23:11 -06004674 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12004675
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004676 if (!m_errorMonitor->DesiredMsgFound()) {
4677 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
4678 m_errorMonitor->DumpFailureMsgs();
Chris Forbescc281692015-05-25 11:13:17 +12004679 }
4680}
4681
Chris Forbes8291c052015-05-25 11:13:28 +12004682TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
4683{
Tony Barbour192f02b2015-11-06 14:21:31 -07004684 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_PERF_WARN_BIT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004685 "location 0 not consumed by VS");
4686
Chris Forbes8291c052015-05-25 11:13:28 +12004687 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004688 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12004689
4690 VkVertexInputBindingDescription input_binding;
4691 memset(&input_binding, 0, sizeof(input_binding));
4692
4693 VkVertexInputAttributeDescription input_attrib;
4694 memset(&input_attrib, 0, sizeof(input_attrib));
4695 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4696
4697 char const *vsSource =
4698 "#version 140\n"
4699 "#extension GL_ARB_separate_shader_objects: require\n"
4700 "#extension GL_ARB_shading_language_420pack: require\n"
4701 "\n"
4702 "void main(){\n"
4703 " gl_Position = vec4(1);\n"
4704 "}\n";
4705 char const *fsSource =
4706 "#version 140\n"
4707 "#extension GL_ARB_separate_shader_objects: require\n"
4708 "#extension GL_ARB_shading_language_420pack: require\n"
4709 "\n"
4710 "layout(location=0) out vec4 color;\n"
4711 "void main(){\n"
4712 " color = vec4(1);\n"
4713 "}\n";
4714
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004715 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4716 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes8291c052015-05-25 11:13:28 +12004717
4718 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004719 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12004720 pipe.AddShader(&vs);
4721 pipe.AddShader(&fs);
4722
4723 pipe.AddVertexInputBindings(&input_binding, 1);
4724 pipe.AddVertexInputAttribs(&input_attrib, 1);
4725
Chris Forbes8291c052015-05-25 11:13:28 +12004726 VkDescriptorSetObj descriptorSet(m_device);
4727 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004728 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12004729
Tony Barboured132432015-08-04 16:23:11 -06004730 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12004731
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004732 if (!m_errorMonitor->DesiredMsgFound()) {
4733 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
4734 m_errorMonitor->DumpFailureMsgs();
Chris Forbes8291c052015-05-25 11:13:28 +12004735 }
4736}
4737
Chris Forbes37367e62015-05-25 11:13:29 +12004738TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
4739{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004740 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4741 "VS consumes input at location 0 but not provided");
4742
Chris Forbes37367e62015-05-25 11:13:29 +12004743 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004744 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12004745
4746 char const *vsSource =
4747 "#version 140\n"
4748 "#extension GL_ARB_separate_shader_objects: require\n"
4749 "#extension GL_ARB_shading_language_420pack: require\n"
4750 "\n"
4751 "layout(location=0) in vec4 x;\n" /* not provided */
4752 "void main(){\n"
4753 " gl_Position = x;\n"
4754 "}\n";
4755 char const *fsSource =
4756 "#version 140\n"
4757 "#extension GL_ARB_separate_shader_objects: require\n"
4758 "#extension GL_ARB_shading_language_420pack: require\n"
4759 "\n"
4760 "layout(location=0) out vec4 color;\n"
4761 "void main(){\n"
4762 " color = vec4(1);\n"
4763 "}\n";
4764
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004765 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4766 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes37367e62015-05-25 11:13:29 +12004767
4768 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004769 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12004770 pipe.AddShader(&vs);
4771 pipe.AddShader(&fs);
4772
Chris Forbes37367e62015-05-25 11:13:29 +12004773 VkDescriptorSetObj descriptorSet(m_device);
4774 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004775 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12004776
Tony Barboured132432015-08-04 16:23:11 -06004777 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12004778
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004779 if (!m_errorMonitor->DesiredMsgFound()) {
4780 FAIL() << "Did not receive Error 'VS consumes input at location 0 but not provided'";
4781 m_errorMonitor->DumpFailureMsgs();
Chris Forbes37367e62015-05-25 11:13:29 +12004782 }
4783}
4784
Chris Forbesa4b02322015-05-25 11:13:31 +12004785TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
4786{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004787 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4788 "location 0 does not match VS input type");
4789
Chris Forbesa4b02322015-05-25 11:13:31 +12004790 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12004792
4793 VkVertexInputBindingDescription input_binding;
4794 memset(&input_binding, 0, sizeof(input_binding));
4795
4796 VkVertexInputAttributeDescription input_attrib;
4797 memset(&input_attrib, 0, sizeof(input_attrib));
4798 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4799
4800 char const *vsSource =
4801 "#version 140\n"
4802 "#extension GL_ARB_separate_shader_objects: require\n"
4803 "#extension GL_ARB_shading_language_420pack: require\n"
4804 "\n"
4805 "layout(location=0) in int x;\n" /* attrib provided float */
4806 "void main(){\n"
4807 " gl_Position = vec4(x);\n"
4808 "}\n";
4809 char const *fsSource =
4810 "#version 140\n"
4811 "#extension GL_ARB_separate_shader_objects: require\n"
4812 "#extension GL_ARB_shading_language_420pack: require\n"
4813 "\n"
4814 "layout(location=0) out vec4 color;\n"
4815 "void main(){\n"
4816 " color = vec4(1);\n"
4817 "}\n";
4818
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004819 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4820 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa4b02322015-05-25 11:13:31 +12004821
4822 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004823 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12004824 pipe.AddShader(&vs);
4825 pipe.AddShader(&fs);
4826
4827 pipe.AddVertexInputBindings(&input_binding, 1);
4828 pipe.AddVertexInputAttribs(&input_attrib, 1);
4829
Chris Forbesa4b02322015-05-25 11:13:31 +12004830 VkDescriptorSetObj descriptorSet(m_device);
4831 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004832 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12004833
Tony Barboured132432015-08-04 16:23:11 -06004834 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12004835
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004836 if (!m_errorMonitor->DesiredMsgFound()) {
4837 FAIL() << "Did not receive Error 'location 0 does not match VS input type'";
4838 m_errorMonitor->DumpFailureMsgs();
Chris Forbesa4b02322015-05-25 11:13:31 +12004839 }
4840}
4841
Chris Forbes03e6d762015-11-24 11:13:14 +13004842TEST_F(VkLayerTest, CreatePipelineAttribMatrixType)
4843{
4844 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
4845
4846 ASSERT_NO_FATAL_FAILURE(InitState());
4847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4848
4849 VkVertexInputBindingDescription input_binding;
4850 memset(&input_binding, 0, sizeof(input_binding));
4851
4852 VkVertexInputAttributeDescription input_attribs[2];
4853 memset(input_attribs, 0, sizeof(input_attribs));
4854
4855 for (int i = 0; i < 2; i++) {
4856 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
4857 input_attribs[i].location = i;
4858 }
4859
4860 char const *vsSource =
4861 "#version 140\n"
4862 "#extension GL_ARB_separate_shader_objects: require\n"
4863 "#extension GL_ARB_shading_language_420pack: require\n"
4864 "\n"
4865 "layout(location=0) in mat2x4 x;\n"
4866 "void main(){\n"
4867 " gl_Position = x[0] + x[1];\n"
4868 "}\n";
4869 char const *fsSource =
4870 "#version 140\n"
4871 "#extension GL_ARB_separate_shader_objects: require\n"
4872 "#extension GL_ARB_shading_language_420pack: require\n"
4873 "\n"
4874 "layout(location=0) out vec4 color;\n"
4875 "void main(){\n"
4876 " color = vec4(1);\n"
4877 "}\n";
4878
4879 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4880 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4881
4882 VkPipelineObj pipe(m_device);
4883 pipe.AddColorAttachment();
4884 pipe.AddShader(&vs);
4885 pipe.AddShader(&fs);
4886
4887 pipe.AddVertexInputBindings(&input_binding, 1);
4888 pipe.AddVertexInputAttribs(input_attribs, 2);
4889
4890 VkDescriptorSetObj descriptorSet(m_device);
4891 descriptorSet.AppendDummy();
4892 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
4893
4894 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4895
4896 /* expect success */
4897 if (m_errorMonitor->DesiredMsgFound()) {
4898 FAIL() << "Expected to succeed but: " << m_errorMonitor->GetFailureMsg();
4899 m_errorMonitor->DumpFailureMsgs();
4900 }
4901}
4902
4903/*
4904 * Would work, but not supported by glslang! This is similar to the matrix case above.
4905 *
4906TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
4907{
4908 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
4909
4910 ASSERT_NO_FATAL_FAILURE(InitState());
4911 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4912
4913 VkVertexInputBindingDescription input_binding;
4914 memset(&input_binding, 0, sizeof(input_binding));
4915
4916 VkVertexInputAttributeDescription input_attribs[2];
4917 memset(input_attribs, 0, sizeof(input_attribs));
4918
4919 for (int i = 0; i < 2; i++) {
4920 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
4921 input_attribs[i].location = i;
4922 }
4923
4924 char const *vsSource =
4925 "#version 140\n"
4926 "#extension GL_ARB_separate_shader_objects: require\n"
4927 "#extension GL_ARB_shading_language_420pack: require\n"
4928 "\n"
4929 "layout(location=0) in vec4 x[2];\n"
4930 "void main(){\n"
4931 " gl_Position = x[0] + x[1];\n"
4932 "}\n";
4933 char const *fsSource =
4934 "#version 140\n"
4935 "#extension GL_ARB_separate_shader_objects: require\n"
4936 "#extension GL_ARB_shading_language_420pack: require\n"
4937 "\n"
4938 "layout(location=0) out vec4 color;\n"
4939 "void main(){\n"
4940 " color = vec4(1);\n"
4941 "}\n";
4942
4943 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4944 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4945
4946 VkPipelineObj pipe(m_device);
4947 pipe.AddColorAttachment();
4948 pipe.AddShader(&vs);
4949 pipe.AddShader(&fs);
4950
4951 pipe.AddVertexInputBindings(&input_binding, 1);
4952 pipe.AddVertexInputAttribs(input_attribs, 2);
4953
4954 VkDescriptorSetObj descriptorSet(m_device);
4955 descriptorSet.AppendDummy();
4956 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
4957
4958 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4959
4960 if (m_errorMonitor->DesiredMsgFound()) {
4961 FAIL() << "Expected to succeed but: " << m_errorMonitor->GetFailureMsg();
4962 m_errorMonitor->DumpFailureMsgs();
4963 }
4964}
4965*/
4966
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004967TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
4968{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004969 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4970 "Duplicate vertex input binding descriptions for binding 0");
4971
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004972 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004973 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004974
4975 /* Two binding descriptions for binding 0 */
4976 VkVertexInputBindingDescription input_bindings[2];
4977 memset(input_bindings, 0, sizeof(input_bindings));
4978
4979 VkVertexInputAttributeDescription input_attrib;
4980 memset(&input_attrib, 0, sizeof(input_attrib));
4981 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4982
4983 char const *vsSource =
4984 "#version 140\n"
4985 "#extension GL_ARB_separate_shader_objects: require\n"
4986 "#extension GL_ARB_shading_language_420pack: require\n"
4987 "\n"
4988 "layout(location=0) in float x;\n" /* attrib provided float */
4989 "void main(){\n"
4990 " gl_Position = vec4(x);\n"
4991 "}\n";
4992 char const *fsSource =
4993 "#version 140\n"
4994 "#extension GL_ARB_separate_shader_objects: require\n"
4995 "#extension GL_ARB_shading_language_420pack: require\n"
4996 "\n"
4997 "layout(location=0) out vec4 color;\n"
4998 "void main(){\n"
4999 " color = vec4(1);\n"
5000 "}\n";
5001
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005002 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5003 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12005004
5005 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08005006 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12005007 pipe.AddShader(&vs);
5008 pipe.AddShader(&fs);
5009
5010 pipe.AddVertexInputBindings(input_bindings, 2);
5011 pipe.AddVertexInputAttribs(&input_attrib, 1);
5012
Chris Forbes0bf8fe12015-06-12 11:16:41 +12005013 VkDescriptorSetObj descriptorSet(m_device);
5014 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005015 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12005016
Tony Barboured132432015-08-04 16:23:11 -06005017 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12005018
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005019 if (!m_errorMonitor->DesiredMsgFound()) {
5020 FAIL() << "Did not receive Error 'Duplicate vertex input binding descriptions for binding 0'";
5021 m_errorMonitor->DumpFailureMsgs();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12005022 }
5023}
Chris Forbes4c948702015-05-25 11:13:32 +12005024
Chris Forbesc12ef122015-05-25 11:13:40 +12005025TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
5026{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005027 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5028 "Attachment 0 not written by FS");
5029
Chris Forbesc12ef122015-05-25 11:13:40 +12005030 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12005031
5032 char const *vsSource =
5033 "#version 140\n"
5034 "#extension GL_ARB_separate_shader_objects: require\n"
5035 "#extension GL_ARB_shading_language_420pack: require\n"
5036 "\n"
5037 "void main(){\n"
5038 " gl_Position = vec4(1);\n"
5039 "}\n";
5040 char const *fsSource =
5041 "#version 140\n"
5042 "#extension GL_ARB_separate_shader_objects: require\n"
5043 "#extension GL_ARB_shading_language_420pack: require\n"
5044 "\n"
5045 "void main(){\n"
5046 "}\n";
5047
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005048 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5049 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc12ef122015-05-25 11:13:40 +12005050
5051 VkPipelineObj pipe(m_device);
5052 pipe.AddShader(&vs);
5053 pipe.AddShader(&fs);
5054
Chia-I Wuc278df82015-07-07 11:50:03 +08005055 /* set up CB 0, not written */
5056 pipe.AddColorAttachment();
5057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12005058
Chris Forbesc12ef122015-05-25 11:13:40 +12005059 VkDescriptorSetObj descriptorSet(m_device);
5060 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005061 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12005062
Tony Barboured132432015-08-04 16:23:11 -06005063 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12005064
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005065 if (!m_errorMonitor->DesiredMsgFound()) {
5066 FAIL() << "Did not receive Error 'Attachment 0 not written by FS'";
5067 m_errorMonitor->DumpFailureMsgs();
Chris Forbesc12ef122015-05-25 11:13:40 +12005068 }
5069}
5070
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005071TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
5072{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005073 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
5074 "FS writes to output location 1 with no matching attachment");
5075
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005076 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005077
5078 char const *vsSource =
5079 "#version 140\n"
5080 "#extension GL_ARB_separate_shader_objects: require\n"
5081 "#extension GL_ARB_shading_language_420pack: require\n"
5082 "\n"
5083 "void main(){\n"
5084 " gl_Position = vec4(1);\n"
5085 "}\n";
5086 char const *fsSource =
5087 "#version 140\n"
5088 "#extension GL_ARB_separate_shader_objects: require\n"
5089 "#extension GL_ARB_shading_language_420pack: require\n"
5090 "\n"
5091 "layout(location=0) out vec4 x;\n"
5092 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
5093 "void main(){\n"
5094 " x = vec4(1);\n"
5095 " y = vec4(1);\n"
5096 "}\n";
5097
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005098 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5099 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005100
5101 VkPipelineObj pipe(m_device);
5102 pipe.AddShader(&vs);
5103 pipe.AddShader(&fs);
5104
Chia-I Wuc278df82015-07-07 11:50:03 +08005105 /* set up CB 0, not written */
5106 pipe.AddColorAttachment();
5107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005108 /* FS writes CB 1, but we don't configure it */
5109
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005110 VkDescriptorSetObj descriptorSet(m_device);
5111 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005112 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005113
Tony Barboured132432015-08-04 16:23:11 -06005114 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005115
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005116 if (!m_errorMonitor->DesiredMsgFound()) {
5117 FAIL() << "Did not receive Error 'FS writes to output location 1 with no matching attachment'";
5118 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5d15a4f2015-05-25 11:13:43 +12005119 }
5120}
5121
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005122TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
5123{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005124 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5125 "does not match FS output type");
5126
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005127 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005128
5129 char const *vsSource =
5130 "#version 140\n"
5131 "#extension GL_ARB_separate_shader_objects: require\n"
5132 "#extension GL_ARB_shading_language_420pack: require\n"
5133 "\n"
5134 "void main(){\n"
5135 " gl_Position = vec4(1);\n"
5136 "}\n";
5137 char const *fsSource =
5138 "#version 140\n"
5139 "#extension GL_ARB_separate_shader_objects: require\n"
5140 "#extension GL_ARB_shading_language_420pack: require\n"
5141 "\n"
5142 "layout(location=0) out ivec4 x;\n" /* not UNORM */
5143 "void main(){\n"
5144 " x = ivec4(1);\n"
5145 "}\n";
5146
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005147 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5148 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005149
5150 VkPipelineObj pipe(m_device);
5151 pipe.AddShader(&vs);
5152 pipe.AddShader(&fs);
5153
Chia-I Wuc278df82015-07-07 11:50:03 +08005154 /* set up CB 0; type is UNORM by default */
5155 pipe.AddColorAttachment();
5156 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005157
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005158 VkDescriptorSetObj descriptorSet(m_device);
5159 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005160 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005161
Tony Barboured132432015-08-04 16:23:11 -06005162 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005163
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005164 if (!m_errorMonitor->DesiredMsgFound()) {
5165 FAIL() << "Did not receive Error 'does not match FS output type'";
5166 m_errorMonitor->DumpFailureMsgs();
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005167 }
5168}
Chris Forbesc2050732015-06-05 14:43:36 +12005169
Chris Forbes76ce7882015-08-14 12:04:59 +12005170TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
5171{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005172 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5173 "not declared in pipeline layout");
5174
Chris Forbes76ce7882015-08-14 12:04:59 +12005175 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +12005176
5177 char const *vsSource =
5178 "#version 140\n"
5179 "#extension GL_ARB_separate_shader_objects: require\n"
5180 "#extension GL_ARB_shading_language_420pack: require\n"
5181 "\n"
5182 "void main(){\n"
5183 " gl_Position = vec4(1);\n"
5184 "}\n";
5185 char const *fsSource =
5186 "#version 140\n"
5187 "#extension GL_ARB_separate_shader_objects: require\n"
5188 "#extension GL_ARB_shading_language_420pack: require\n"
5189 "\n"
5190 "layout(location=0) out vec4 x;\n"
5191 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5192 "void main(){\n"
5193 " x = vec4(bar.y);\n"
5194 "}\n";
5195
Chris Forbes76ce7882015-08-14 12:04:59 +12005196
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005197 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5198 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes76ce7882015-08-14 12:04:59 +12005199
Chris Forbes76ce7882015-08-14 12:04:59 +12005200 VkPipelineObj pipe(m_device);
5201 pipe.AddShader(&vs);
5202 pipe.AddShader(&fs);
5203
5204 /* set up CB 0; type is UNORM by default */
5205 pipe.AddColorAttachment();
5206 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5207
5208 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1f851912015-10-27 18:04:07 +08005209 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes76ce7882015-08-14 12:04:59 +12005210
5211 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5212
5213 /* should have generated an error -- pipeline layout does not
5214 * provide a uniform buffer in 0.0
5215 */
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005216 if (!m_errorMonitor->DesiredMsgFound()) {
5217 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
5218 m_errorMonitor->DumpFailureMsgs();
Chris Forbes76ce7882015-08-14 12:04:59 +12005219 }
5220}
5221
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06005222#endif // SHADER_CHECKER_TESTS
5223
5224#if DEVICE_LIMITS_TESTS
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005225TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
5226{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005227 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5228 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005229
5230 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005231
5232 // Create an image
5233 VkImage image;
5234
5235 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5236 const int32_t tex_width = 32;
5237 const int32_t tex_height = 32;
5238
5239 VkImageCreateInfo image_create_info = {};
5240 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5241 image_create_info.pNext = NULL;
5242 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5243 image_create_info.format = tex_format;
5244 image_create_info.extent.width = tex_width;
5245 image_create_info.extent.height = tex_height;
5246 image_create_info.extent.depth = 1;
5247 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005248 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005249 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005250 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5251 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5252 image_create_info.flags = 0;
5253
5254 // Introduce error by sending down a bogus width extent
5255 image_create_info.extent.width = 65536;
Chia-I Wu69f40122015-10-26 21:10:41 +08005256 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005257
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005258 if (!m_errorMonitor->DesiredMsgFound()) {
5259 FAIL() << "Did not receive Error 'CreateImage extents exceed allowable limits for format'";
5260 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005261 }
5262}
5263
5264TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
5265{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005266 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5267 "CreateImage resource size exceeds allowable maximum");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005268
5269 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005270
5271 // Create an image
5272 VkImage image;
5273
5274 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5275 const int32_t tex_width = 32;
5276 const int32_t tex_height = 32;
5277
5278 VkImageCreateInfo image_create_info = {};
5279 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5280 image_create_info.pNext = NULL;
5281 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5282 image_create_info.format = tex_format;
5283 image_create_info.extent.width = tex_width;
5284 image_create_info.extent.height = tex_height;
5285 image_create_info.extent.depth = 1;
5286 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005287 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005288 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005289 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5290 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5291 image_create_info.flags = 0;
5292
5293 // Introduce error by sending down individually allowable values that result in a surface size
5294 // exceeding the device maximum
5295 image_create_info.extent.width = 8192;
5296 image_create_info.extent.height = 8192;
5297 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005298 image_create_info.arrayLayers = 4;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005299 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005300 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
Chia-I Wu69f40122015-10-26 21:10:41 +08005301 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005302
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005303 if (!m_errorMonitor->DesiredMsgFound()) {
5304 FAIL() << "Did not receive Error 'CreateImage resource size exceeds allowable maximum'";
5305 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06005306 }
5307}
5308
Mike Stroyan43909d82015-09-25 13:39:21 -06005309TEST_F(VkLayerTest, UpdateBufferAlignment)
5310{
Mike Stroyan43909d82015-09-25 13:39:21 -06005311 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
5312
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005313 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5314 "dstOffset, is not a multiple of 4");
5315
Mike Stroyan43909d82015-09-25 13:39:21 -06005316 ASSERT_NO_FATAL_FAILURE(InitState());
5317
5318 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5319 vk_testing::Buffer buffer;
5320 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
5321
5322 BeginCommandBuffer();
5323 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08005324 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005325 if (!m_errorMonitor->DesiredMsgFound()) {
5326 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
5327 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005328 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005329
Mike Stroyan43909d82015-09-25 13:39:21 -06005330 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005331 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5332 "dataSize, is not a multiple of 4");
5333
Chia-I Wu1f851912015-10-27 18:04:07 +08005334 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005335
5336 if (!m_errorMonitor->DesiredMsgFound()) {
5337 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
5338 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005339 }
5340 EndCommandBuffer();
5341}
5342
5343TEST_F(VkLayerTest, FillBufferAlignment)
5344{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005345 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5346 "dstOffset, is not a multiple of 4");
Mike Stroyan43909d82015-09-25 13:39:21 -06005347
5348 ASSERT_NO_FATAL_FAILURE(InitState());
5349
5350 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5351 vk_testing::Buffer buffer;
5352 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
5353
5354 BeginCommandBuffer();
5355 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08005356 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005357 if (!m_errorMonitor->DesiredMsgFound()) {
5358 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
5359 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005360 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005361
Mike Stroyan43909d82015-09-25 13:39:21 -06005362 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005363 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5364 "size, is not a multiple of 4");
5365
Chia-I Wu1f851912015-10-27 18:04:07 +08005366 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005367
5368 if (!m_errorMonitor->DesiredMsgFound()) {
5369 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize size, is not a multiple of 4'";
5370 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005371 }
5372 EndCommandBuffer();
5373}
5374
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06005375#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12005376
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005377#if IMAGE_TESTS
5378TEST_F(VkLayerTest, InvalidImageView)
5379{
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005380 VkResult err;
5381
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005382 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5383 "vkCreateImageView called with baseMipLevel 10 ");
5384
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005385 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005386
Mike Stroyan43909d82015-09-25 13:39:21 -06005387 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005388 VkImage image;
5389
5390 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5391 const int32_t tex_width = 32;
5392 const int32_t tex_height = 32;
5393
5394 VkImageCreateInfo image_create_info = {};
5395 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5396 image_create_info.pNext = NULL;
5397 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5398 image_create_info.format = tex_format;
5399 image_create_info.extent.width = tex_width;
5400 image_create_info.extent.height = tex_height;
5401 image_create_info.extent.depth = 1;
5402 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005403 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005404 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005405 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5406 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5407 image_create_info.flags = 0;
5408
Chia-I Wu69f40122015-10-26 21:10:41 +08005409 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005410 ASSERT_VK_SUCCESS(err);
5411
5412 VkImageViewCreateInfo image_view_create_info = {};
5413 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5414 image_view_create_info.image = image;
5415 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5416 image_view_create_info.format = tex_format;
Chia-I Wu1f851912015-10-27 18:04:07 +08005417 image_view_create_info.subresourceRange.layerCount = 1;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005418 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Chia-I Wu1f851912015-10-27 18:04:07 +08005419 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005420 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005421
5422 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08005423 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005424
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005425 if (!m_errorMonitor->DesiredMsgFound()) {
5426 FAIL() << "Did not receive Error 'vkCreateImageView called with baseMipLevel 10...'";
5427 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005428 }
5429}
Mike Stroyan43909d82015-09-25 13:39:21 -06005430
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005431TEST_F(VkLayerTest, InvalidImageViewAspect)
5432{
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005433 VkResult err;
5434
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005435 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5436 "vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set");
5437
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005438 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005439
5440 // Create an image and try to create a view with an invalid aspectMask
5441 VkImage image;
5442
5443 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5444 const int32_t tex_width = 32;
5445 const int32_t tex_height = 32;
5446
5447 VkImageCreateInfo image_create_info = {};
5448 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5449 image_create_info.pNext = NULL;
5450 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5451 image_create_info.format = tex_format;
5452 image_create_info.extent.width = tex_width;
5453 image_create_info.extent.height = tex_height;
5454 image_create_info.extent.depth = 1;
5455 image_create_info.mipLevels = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005456 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005457 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5458 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5459 image_create_info.flags = 0;
5460
Chia-I Wu69f40122015-10-26 21:10:41 +08005461 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005462 ASSERT_VK_SUCCESS(err);
5463
5464 VkImageViewCreateInfo image_view_create_info = {};
5465 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5466 image_view_create_info.image = image;
5467 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5468 image_view_create_info.format = tex_format;
5469 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005470 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005471 // Cause an error by setting an invalid image aspect
5472 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
5473
5474 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08005475 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005476
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005477 if (!m_errorMonitor->DesiredMsgFound()) {
5478 FAIL() << "Did not receive Error 'VkCreateImageView: Color image formats must have ...'";
5479 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06005480 }
5481}
5482
Mike Stroyan43909d82015-09-25 13:39:21 -06005483TEST_F(VkLayerTest, CopyImageTypeMismatch)
5484{
Mike Stroyan43909d82015-09-25 13:39:21 -06005485 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005486 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005487
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005488 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5489 "vkCmdCopyImage called with unmatched source and dest image types");
5490
Mike Stroyan43909d82015-09-25 13:39:21 -06005491 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005492
5493 // Create two images of different types and try to copy between them
5494 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005495 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005496 VkDeviceMemory srcMem;
5497 VkDeviceMemory destMem;
5498 VkMemoryRequirements memReqs;
5499
5500 VkImageCreateInfo image_create_info = {};
5501 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5502 image_create_info.pNext = NULL;
5503 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5504 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5505 image_create_info.extent.width = 32;
5506 image_create_info.extent.height = 32;
5507 image_create_info.extent.depth = 1;
5508 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005509 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005510 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005511 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005512 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005513 image_create_info.flags = 0;
5514
Chia-I Wu69f40122015-10-26 21:10:41 +08005515 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005516 ASSERT_VK_SUCCESS(err);
5517
5518 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005519 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005520
Chia-I Wu1f851912015-10-27 18:04:07 +08005521 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005522 ASSERT_VK_SUCCESS(err);
5523
5524 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005525 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005526 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005527 memAlloc.pNext = NULL;
5528 memAlloc.allocationSize = 0;
5529 memAlloc.memoryTypeIndex = 0;
5530
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005531 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005532 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005533 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5534 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005535 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005536 ASSERT_VK_SUCCESS(err);
5537
Chia-I Wu1f851912015-10-27 18:04:07 +08005538 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005539 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005540 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005541 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005542 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005543 ASSERT_VK_SUCCESS(err);
5544
5545 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5546 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005547 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005548 ASSERT_VK_SUCCESS(err);
5549
5550 BeginCommandBuffer();
5551 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005552 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005553 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005554 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005555 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005556 copyRegion.srcOffset.x = 0;
5557 copyRegion.srcOffset.y = 0;
5558 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005559 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005560 copyRegion.dstSubresource.mipLevel = 0;
5561 copyRegion.dstSubresource.baseArrayLayer = 0;
5562 copyRegion.dstSubresource.layerCount = 0;
5563 copyRegion.dstOffset.x = 0;
5564 copyRegion.dstOffset.y = 0;
5565 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005566 copyRegion.extent.width = 1;
5567 copyRegion.extent.height = 1;
5568 copyRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005569 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005570 EndCommandBuffer();
5571
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005572 if (!m_errorMonitor->DesiredMsgFound()) {
5573 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5574 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005575 }
5576
Chia-I Wu69f40122015-10-26 21:10:41 +08005577 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005578 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005579 vkFreeMemory(m_device->device(), srcMem, NULL);
5580 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005581}
5582
5583TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
5584{
5585 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
5586}
5587
5588TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
5589{
Mike Stroyan43909d82015-09-25 13:39:21 -06005590 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005591 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005592
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005593 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5594 "vkCmdCopyImage called with unmatched source and dest image types");
5595
Mike Stroyan43909d82015-09-25 13:39:21 -06005596 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005597
5598 // Create two images of different types and try to copy between them
5599 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005600 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005601 VkDeviceMemory srcMem;
5602 VkDeviceMemory destMem;
5603 VkMemoryRequirements memReqs;
5604
5605 VkImageCreateInfo image_create_info = {};
5606 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5607 image_create_info.pNext = NULL;
5608 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5609 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5610 image_create_info.extent.width = 32;
5611 image_create_info.extent.height = 32;
5612 image_create_info.extent.depth = 1;
5613 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005614 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005615 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005616 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005617 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005618 image_create_info.flags = 0;
5619
Chia-I Wu69f40122015-10-26 21:10:41 +08005620 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005621 ASSERT_VK_SUCCESS(err);
5622
5623 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005624 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005625
Chia-I Wu1f851912015-10-27 18:04:07 +08005626 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005627 ASSERT_VK_SUCCESS(err);
5628
5629 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005630 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005631 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005632 memAlloc.pNext = NULL;
5633 memAlloc.allocationSize = 0;
5634 memAlloc.memoryTypeIndex = 0;
5635
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005636 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005637 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005638 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5639 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005640 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005641 ASSERT_VK_SUCCESS(err);
5642
Chia-I Wu1f851912015-10-27 18:04:07 +08005643 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005644 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005645 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5646 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005647 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005648 ASSERT_VK_SUCCESS(err);
5649
5650 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5651 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005652 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005653 ASSERT_VK_SUCCESS(err);
5654
5655 BeginCommandBuffer();
5656 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005657 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005658 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005659 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005660 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005661 copyRegion.srcOffset.x = 0;
5662 copyRegion.srcOffset.y = 0;
5663 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005664 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005665 copyRegion.dstSubresource.mipLevel = 0;
5666 copyRegion.dstSubresource.baseArrayLayer = 0;
5667 copyRegion.dstSubresource.layerCount = 0;
5668 copyRegion.dstOffset.x = 0;
5669 copyRegion.dstOffset.y = 0;
5670 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005671 copyRegion.extent.width = 1;
5672 copyRegion.extent.height = 1;
5673 copyRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005674 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005675 EndCommandBuffer();
5676
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005677 if (!m_errorMonitor->DesiredMsgFound()) {
5678 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5679 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005680 }
5681
Chia-I Wu69f40122015-10-26 21:10:41 +08005682 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005683 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005684 vkFreeMemory(m_device->device(), srcMem, NULL);
5685 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005686}
5687
5688TEST_F(VkLayerTest, ResolveImageLowSampleCount)
5689{
Mike Stroyan43909d82015-09-25 13:39:21 -06005690 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005691 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005692
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005693 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5694 "vkCmdResolveImage called with source sample count less than 2.");
5695
Mike Stroyan43909d82015-09-25 13:39:21 -06005696 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005697
5698 // Create two images of sample count 1 and try to Resolve between them
5699 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005700 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005701 VkDeviceMemory srcMem;
5702 VkDeviceMemory destMem;
5703 VkMemoryRequirements memReqs;
5704
5705 VkImageCreateInfo image_create_info = {};
5706 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5707 image_create_info.pNext = NULL;
5708 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5709 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5710 image_create_info.extent.width = 32;
5711 image_create_info.extent.height = 1;
5712 image_create_info.extent.depth = 1;
5713 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005714 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005715 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005716 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005717 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005718 image_create_info.flags = 0;
5719
Chia-I Wu69f40122015-10-26 21:10:41 +08005720 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005721 ASSERT_VK_SUCCESS(err);
5722
5723 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005724 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005725
Chia-I Wu1f851912015-10-27 18:04:07 +08005726 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005727 ASSERT_VK_SUCCESS(err);
5728
5729 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005730 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005731 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005732 memAlloc.pNext = NULL;
5733 memAlloc.allocationSize = 0;
5734 memAlloc.memoryTypeIndex = 0;
5735
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005736 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005737 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005738 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5739 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005740 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005741 ASSERT_VK_SUCCESS(err);
5742
Chia-I Wu1f851912015-10-27 18:04:07 +08005743 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005744 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005745 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5746 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005747 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005748 ASSERT_VK_SUCCESS(err);
5749
5750 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5751 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005752 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005753 ASSERT_VK_SUCCESS(err);
5754
5755 BeginCommandBuffer();
5756 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5757 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5758 //VK_IMAGE_LAYOUT_GENERAL = 1,
5759 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005760 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005761 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005762 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005763 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005764 resolveRegion.srcOffset.x = 0;
5765 resolveRegion.srcOffset.y = 0;
5766 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005767 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005768 resolveRegion.dstSubresource.mipLevel = 0;
5769 resolveRegion.dstSubresource.baseArrayLayer = 0;
5770 resolveRegion.dstSubresource.layerCount = 0;
5771 resolveRegion.dstOffset.x = 0;
5772 resolveRegion.dstOffset.y = 0;
5773 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005774 resolveRegion.extent.width = 1;
5775 resolveRegion.extent.height = 1;
5776 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005777 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005778 EndCommandBuffer();
5779
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005780 if (!m_errorMonitor->DesiredMsgFound()) {
5781 FAIL() << "Did not receive Error 'vkCmdResolveImage called with source sample count less than 2.'";
5782 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005783 }
5784
Chia-I Wu69f40122015-10-26 21:10:41 +08005785 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005786 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005787 vkFreeMemory(m_device->device(), srcMem, NULL);
5788 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005789}
5790
5791TEST_F(VkLayerTest, ResolveImageHighSampleCount)
5792{
Mike Stroyan43909d82015-09-25 13:39:21 -06005793 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005794 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005795
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005796 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5797 "vkCmdResolveImage called with dest sample count greater than 1.");
5798
Mike Stroyan43909d82015-09-25 13:39:21 -06005799 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005800
5801 // Create two images of sample count 2 and try to Resolve between them
5802 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005803 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005804 VkDeviceMemory srcMem;
5805 VkDeviceMemory destMem;
5806 VkMemoryRequirements memReqs;
5807
5808 VkImageCreateInfo image_create_info = {};
5809 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5810 image_create_info.pNext = NULL;
5811 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5812 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5813 image_create_info.extent.width = 32;
5814 image_create_info.extent.height = 1;
5815 image_create_info.extent.depth = 1;
5816 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005817 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005818 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005819 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005820 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005821 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005822 image_create_info.flags = 0;
5823
Chia-I Wu69f40122015-10-26 21:10:41 +08005824 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005825 ASSERT_VK_SUCCESS(err);
5826
5827 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005828 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005829 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005830
Chia-I Wu1f851912015-10-27 18:04:07 +08005831 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005832 ASSERT_VK_SUCCESS(err);
5833
5834 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005835 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005836 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005837 memAlloc.pNext = NULL;
5838 memAlloc.allocationSize = 0;
5839 memAlloc.memoryTypeIndex = 0;
5840
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005841 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005842 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005843 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5844 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005845 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005846 ASSERT_VK_SUCCESS(err);
5847
Chia-I Wu1f851912015-10-27 18:04:07 +08005848 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005849 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005850 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5851 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005852 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005853 ASSERT_VK_SUCCESS(err);
5854
5855 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5856 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005857 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005858 ASSERT_VK_SUCCESS(err);
5859
5860 BeginCommandBuffer();
5861 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5862 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5863 //VK_IMAGE_LAYOUT_GENERAL = 1,
5864 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005865 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005866 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005867 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005868 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005869 resolveRegion.srcOffset.x = 0;
5870 resolveRegion.srcOffset.y = 0;
5871 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005872 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005873 resolveRegion.dstSubresource.mipLevel = 0;
5874 resolveRegion.dstSubresource.baseArrayLayer = 0;
5875 resolveRegion.dstSubresource.layerCount = 0;
5876 resolveRegion.dstOffset.x = 0;
5877 resolveRegion.dstOffset.y = 0;
5878 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005879 resolveRegion.extent.width = 1;
5880 resolveRegion.extent.height = 1;
5881 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005882 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005883 EndCommandBuffer();
5884
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005885 if (!m_errorMonitor->DesiredMsgFound()) {
5886 FAIL() << "Did not receive Error 'vkCmdResolveImage called with dest sample count greater than 1.'";
5887 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005888 }
5889
Chia-I Wu69f40122015-10-26 21:10:41 +08005890 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005891 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005892 vkFreeMemory(m_device->device(), srcMem, NULL);
5893 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005894}
5895
5896TEST_F(VkLayerTest, ResolveImageFormatMismatch)
5897{
Mike Stroyan43909d82015-09-25 13:39:21 -06005898 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005899 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005900
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005901 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5902 "vkCmdResolveImage called with unmatched source and dest formats.");
5903
Mike Stroyan43909d82015-09-25 13:39:21 -06005904 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005905
5906 // Create two images of different types and try to copy between them
5907 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005908 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005909 VkDeviceMemory srcMem;
5910 VkDeviceMemory destMem;
5911 VkMemoryRequirements memReqs;
5912
5913 VkImageCreateInfo image_create_info = {};
5914 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5915 image_create_info.pNext = NULL;
5916 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5917 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5918 image_create_info.extent.width = 32;
5919 image_create_info.extent.height = 1;
5920 image_create_info.extent.depth = 1;
5921 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005922 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005923 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005924 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005925 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005926 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005927 image_create_info.flags = 0;
5928
Chia-I Wu69f40122015-10-26 21:10:41 +08005929 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005930 ASSERT_VK_SUCCESS(err);
5931
Cody Northropb3bf94f2015-10-27 13:50:04 -06005932 // Set format to something other than source image
5933 image_create_info.format = VK_FORMAT_R32_SFLOAT;
5934 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005935 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005936 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005937
Chia-I Wu1f851912015-10-27 18:04:07 +08005938 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005939 ASSERT_VK_SUCCESS(err);
5940
5941 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005942 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08005943 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06005944 memAlloc.pNext = NULL;
5945 memAlloc.allocationSize = 0;
5946 memAlloc.memoryTypeIndex = 0;
5947
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005948 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005949 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005950 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5951 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005952 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005953 ASSERT_VK_SUCCESS(err);
5954
Chia-I Wu1f851912015-10-27 18:04:07 +08005955 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005956 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005957 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5958 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005959 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005960 ASSERT_VK_SUCCESS(err);
5961
5962 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5963 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005964 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005965 ASSERT_VK_SUCCESS(err);
5966
5967 BeginCommandBuffer();
5968 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5969 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5970 //VK_IMAGE_LAYOUT_GENERAL = 1,
5971 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005972 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005973 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005974 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005975 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005976 resolveRegion.srcOffset.x = 0;
5977 resolveRegion.srcOffset.y = 0;
5978 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005979 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005980 resolveRegion.dstSubresource.mipLevel = 0;
5981 resolveRegion.dstSubresource.baseArrayLayer = 0;
5982 resolveRegion.dstSubresource.layerCount = 0;
5983 resolveRegion.dstOffset.x = 0;
5984 resolveRegion.dstOffset.y = 0;
5985 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005986 resolveRegion.extent.width = 1;
5987 resolveRegion.extent.height = 1;
5988 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005989 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005990 EndCommandBuffer();
5991
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005992 if (!m_errorMonitor->DesiredMsgFound()) {
5993 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest formats.'";
5994 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005995 }
5996
Chia-I Wu69f40122015-10-26 21:10:41 +08005997 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005998 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005999 vkFreeMemory(m_device->device(), srcMem, NULL);
6000 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06006001}
6002
6003TEST_F(VkLayerTest, ResolveImageTypeMismatch)
6004{
Mike Stroyan43909d82015-09-25 13:39:21 -06006005 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06006006 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06006007
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006008 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
6009 "vkCmdResolveImage called with unmatched source and dest image types.");
6010
Mike Stroyan43909d82015-09-25 13:39:21 -06006011 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06006012
6013 // Create two images of different types and try to copy between them
6014 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08006015 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06006016 VkDeviceMemory srcMem;
6017 VkDeviceMemory destMem;
6018 VkMemoryRequirements memReqs;
6019
6020 VkImageCreateInfo image_create_info = {};
6021 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6022 image_create_info.pNext = NULL;
6023 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6024 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6025 image_create_info.extent.width = 32;
6026 image_create_info.extent.height = 1;
6027 image_create_info.extent.depth = 1;
6028 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06006029 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08006030 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006031 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06006032 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08006033 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006034 image_create_info.flags = 0;
6035
Chia-I Wu69f40122015-10-26 21:10:41 +08006036 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06006037 ASSERT_VK_SUCCESS(err);
6038
6039 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northropb3bf94f2015-10-27 13:50:04 -06006040 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08006041 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08006042 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006043
Chia-I Wu1f851912015-10-27 18:04:07 +08006044 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06006045 ASSERT_VK_SUCCESS(err);
6046
6047 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08006048 VkMemoryAllocateInfo memAlloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08006049 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mike Stroyan43909d82015-09-25 13:39:21 -06006050 memAlloc.pNext = NULL;
6051 memAlloc.allocationSize = 0;
6052 memAlloc.memoryTypeIndex = 0;
6053
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06006054 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06006055 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06006056 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6057 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08006058 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06006059 ASSERT_VK_SUCCESS(err);
6060
Chia-I Wu1f851912015-10-27 18:04:07 +08006061 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06006062 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06006063 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
6064 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08006065 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06006066 ASSERT_VK_SUCCESS(err);
6067
6068 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6069 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08006070 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06006071 ASSERT_VK_SUCCESS(err);
6072
6073 BeginCommandBuffer();
6074 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
6075 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
6076 //VK_IMAGE_LAYOUT_GENERAL = 1,
6077 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08006078 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006079 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06006080 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08006081 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006082 resolveRegion.srcOffset.x = 0;
6083 resolveRegion.srcOffset.y = 0;
6084 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08006085 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08006086 resolveRegion.dstSubresource.mipLevel = 0;
6087 resolveRegion.dstSubresource.baseArrayLayer = 0;
6088 resolveRegion.dstSubresource.layerCount = 0;
6089 resolveRegion.dstOffset.x = 0;
6090 resolveRegion.dstOffset.y = 0;
6091 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006092 resolveRegion.extent.width = 1;
6093 resolveRegion.extent.height = 1;
6094 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08006095 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06006096 EndCommandBuffer();
6097
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006098 if (!m_errorMonitor->DesiredMsgFound()) {
6099 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest image types.'";
6100 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06006101 }
6102
Chia-I Wu69f40122015-10-26 21:10:41 +08006103 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08006104 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08006105 vkFreeMemory(m_device->device(), srcMem, NULL);
6106 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06006107}
Tobin Ehlisb46be812015-10-23 16:00:08 -06006108
6109TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError)
6110{
6111 // Create a single Image descriptor and cause it to first hit an error due
6112 // to using a DS format, then cause it to hit error due to COLOR_BIT not set in aspect
6113 // The image format check comes 2nd in validation so we trigger it first,
6114 // then when we cause aspect fail next, bad format check will be preempted
Tobin Ehlisb46be812015-10-23 16:00:08 -06006115 VkResult err;
6116
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006117 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
6118 "Combination depth/stencil image formats can have only the ");
6119
Tobin Ehlisb46be812015-10-23 16:00:08 -06006120 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006121
Chia-I Wuc51b1212015-10-27 19:25:11 +08006122 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06006123 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu763a7492015-10-26 20:48:51 +08006124 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006125
6126 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6127 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6128 ds_pool_ci.pNext = NULL;
6129 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08006130 ds_pool_ci.poolSizeCount = 1;
6131 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006132
6133 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08006134 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006135 ASSERT_VK_SUCCESS(err);
6136
6137 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08006138 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006139 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu045654f2015-11-06 06:42:02 +08006140 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006141 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6142 dsl_binding.pImmutableSamplers = NULL;
6143
6144 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6145 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6146 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08006147 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08006148 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006149 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08006150 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006151 ASSERT_VK_SUCCESS(err);
6152
6153 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08006154 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08006155 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08006156 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006157 alloc_info.descriptorPool = ds_pool;
6158 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08006159 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006160 ASSERT_VK_SUCCESS(err);
6161
6162 VkImage image_bad;
6163 VkImage image_good;
6164 // One bad format and one good format for Color attachment
6165 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
6166 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
6167 const int32_t tex_width = 32;
6168 const int32_t tex_height = 32;
6169
6170 VkImageCreateInfo image_create_info = {};
6171 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6172 image_create_info.pNext = NULL;
6173 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6174 image_create_info.format = tex_format_bad;
6175 image_create_info.extent.width = tex_width;
6176 image_create_info.extent.height = tex_height;
6177 image_create_info.extent.depth = 1;
6178 image_create_info.mipLevels = 1;
6179 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08006180 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006181 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6182 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
6183 image_create_info.flags = 0;
6184
Chia-I Wu69f40122015-10-26 21:10:41 +08006185 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006186 ASSERT_VK_SUCCESS(err);
6187 image_create_info.format = tex_format_good;
6188 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu69f40122015-10-26 21:10:41 +08006189 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006190 ASSERT_VK_SUCCESS(err);
6191
6192 VkImageViewCreateInfo image_view_create_info = {};
6193 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6194 image_view_create_info.image = image_bad;
6195 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6196 image_view_create_info.format = tex_format_bad;
6197 image_view_create_info.subresourceRange.baseArrayLayer = 0;
6198 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08006199 image_view_create_info.subresourceRange.layerCount = 1;
6200 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06006201 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6202
6203 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08006204 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006205
6206 if (!m_errorMonitor->DesiredMsgFound()) {
6207 FAIL() << "Did not receive Error 'Combination depth-stencil image formats can have only the....'";
6208 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06006209 }
6210
Chia-I Wu69f40122015-10-26 21:10:41 +08006211 vkDestroyImage(m_device->device(), image_bad, NULL);
6212 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08006213 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6214 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06006215}
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06006216#endif // IMAGE_TESTS
6217
Tony Barbour30486ea2015-04-07 13:44:53 -06006218int main(int argc, char **argv) {
6219 int result;
6220
6221 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06006222 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06006223
6224 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
6225
6226 result = RUN_ALL_TESTS();
6227
Tony Barbour01999182015-04-09 12:58:51 -06006228 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06006229 return result;
6230}