blob: 9b77c86d8ffb69db2b8699301f99017d1d4d1412 [file] [log] [blame]
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine584ccab2016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and/or associated documentation files (the "Materials"), to
9 * deal in the Materials without restriction, including without limitation the
10 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Materials, and to permit persons to whom the Materials are
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice(s) and this permission notice shall be included in
15 * all copies or substantial portions of the Materials.
16 *
Karl Schultz99e9d1d2016-02-02 17:17:23 -070017 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 *
21 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
24 * USE OR OTHER DEALINGS IN THE MATERIALS.
25 *
26 * Author: Chia-I Wu <olvaffe@gmail.com>
27 * Author: Chris Forbes <chrisf@ijw.co.nz>
28 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
29 * Author: Mark Lobodzinski <mark@lunarg.com>
30 * Author: Mike Stroyan <mike@LunarG.com>
31 * Author: Tobin Ehlis <tobine@google.com>
32 * Author: Tony Barbour <tony@LunarG.com>
33 */
Tony Barbourd04e8df2015-11-17 10:02:56 -070034
Cody Northrop50537d02016-03-08 22:25:52 -070035#ifdef ANDROID
36#include "vulkan_wrapper.h"
37#else
David Pinedo329ca9e2015-11-06 12:54:48 -070038#include <vulkan/vulkan.h>
Cody Northrop50537d02016-03-08 22:25:52 -070039#endif
Courtney Goeltzenleuchter0abdb662015-10-07 13:28:58 -060040#include "test_common.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060041#include "vkrenderframework.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060042#include "vk_layer_config.h"
Jon Ashburn3510b192016-02-02 12:08:10 -070043#include "icd-spv.h"
Tony Barbour30486ea2015-04-07 13:44:53 -060044
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050045#define GLM_FORCE_RADIANS
46#include "glm/glm.hpp"
47#include <glm/gtc/matrix_transform.hpp>
48
Tobin Ehlis57e6a612015-05-26 16:11:58 -060049#define MEM_TRACKER_TESTS 1
50#define OBJ_TRACKER_TESTS 1
51#define DRAW_STATE_TESTS 1
52#define THREADING_TESTS 1
Chris Forbes5af3bf22015-05-25 11:13:08 +120053#define SHADER_CHECKER_TESTS 1
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -060054#define DEVICE_LIMITS_TESTS 1
Tobin Ehlis342b9bf2015-09-22 10:11:37 -060055#define IMAGE_TESTS 1
Tobin Ehlis57e6a612015-05-26 16:11:58 -060056
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050057//--------------------------------------------------------------------------------------
58// Mesh and VertexFormat Data
59//--------------------------------------------------------------------------------------
Karl Schultz99e9d1d2016-02-02 17:17:23 -070060struct Vertex {
61 float posX, posY, posZ, posW; // Position data
62 float r, g, b, a; // Color
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050063};
64
Karl Schultz99e9d1d2016-02-02 17:17:23 -070065#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050066
67typedef enum _BsoFailSelect {
Karl Schultz99e9d1d2016-02-02 17:17:23 -070068 BsoFailNone = 0x00000000,
69 BsoFailLineWidth = 0x00000001,
70 BsoFailDepthBias = 0x00000002,
71 BsoFailViewport = 0x00000004,
72 BsoFailScissor = 0x00000008,
73 BsoFailBlend = 0x00000010,
74 BsoFailDepthBounds = 0x00000020,
75 BsoFailStencilReadMask = 0x00000040,
76 BsoFailStencilWriteMask = 0x00000080,
77 BsoFailStencilReference = 0x00000100,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050078} BsoFailSelect;
79
80struct vktriangle_vs_uniform {
81 // Must start with MVP
Karl Schultz99e9d1d2016-02-02 17:17:23 -070082 float mvp[4][4];
83 float position[3][4];
84 float color[3][4];
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050085};
86
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050087static const char bindStateVertShaderText[] =
Karl Schultz99e9d1d2016-02-02 17:17:23 -070088 "#version 400\n"
89 "#extension GL_ARB_separate_shader_objects : require\n"
90 "#extension GL_ARB_shading_language_420pack : require\n"
91 "vec2 vertices[3];\n"
92 "out gl_PerVertex {\n"
93 " vec4 gl_Position;\n"
94 "};\n"
95 "void main() {\n"
96 " vertices[0] = vec2(-1.0, -1.0);\n"
97 " vertices[1] = vec2( 1.0, -1.0);\n"
98 " vertices[2] = vec2( 0.0, 1.0);\n"
99 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
100 "}\n";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500101
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -0500102static const char bindStateFragShaderText[] =
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700103 "#version 400\n"
104 "#extension GL_ARB_separate_shader_objects: require\n"
105 "#extension GL_ARB_shading_language_420pack: require\n"
106 "\n"
107 "layout(location = 0) out vec4 uFragColor;\n"
108 "void main(){\n"
109 " uFragColor = vec4(0,1,0,1);\n"
110 "}\n";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500111
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700112static VKAPI_ATTR VkBool32 VKAPI_CALL
113myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
114 uint64_t srcObject, size_t location, int32_t msgCode,
115 const char *pLayerPrefix, const char *pMsg, void *pUserData);
Tony Barbour30486ea2015-04-07 13:44:53 -0600116
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600117// ********************************************************
118// ErrorMonitor Usage:
119//
120// Call SetDesiredFailureMsg with a string to be compared against all
121// encountered log messages. Passing NULL will match all log messages.
122// logMsg will return true for skipCall only if msg is matched or NULL.
123//
124// Call DesiredMsgFound to determine if the desired failure message
125// was encountered.
126
Tony Barbour30486ea2015-04-07 13:44:53 -0600127class ErrorMonitor {
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700128 public:
129 ErrorMonitor() {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600130 test_platform_thread_create_mutex(&m_mutex);
131 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski5c13d4d2016-02-11 09:26:16 -0700132 m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700133 m_bailout = NULL;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600134 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -0600135 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600136
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700137 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600138 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600139 m_desiredMsg.clear();
140 m_failureMsg.clear();
141 m_otherMsgs.clear();
142 m_desiredMsg = msgString;
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700143 m_msgFound = VK_FALSE;
144 m_msgFlags = msgFlags;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600145 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -0600146 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600147
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700148 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600149 VkBool32 result = VK_FALSE;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600150 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600151 if (m_bailout != NULL) {
152 *m_bailout = true;
153 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600154 string errorString(msgString);
155 if (msgFlags & m_msgFlags) {
156 if (errorString.find(m_desiredMsg) != string::npos) {
Chris Forbese8aa35e2016-04-04 18:50:38 +1200157 if (m_msgFound) { /* if multiple matches, don't lose all but the last! */
158 m_otherMsgs.push_back(m_failureMsg);
159 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600160 m_failureMsg = errorString;
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700161 m_msgFound = VK_TRUE;
162 result = VK_TRUE;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600163 } else {
164 m_otherMsgs.push_back(errorString);
165 }
166 }
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600167 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600168 return result;
Mike Stroyan09aae812015-05-12 16:00:45 -0600169 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600170
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700171 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600172
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700173 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600174
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700175 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600176
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700177 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour30486ea2015-04-07 13:44:53 -0600178
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700179 void DumpFailureMsgs(void) {
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600180 vector<string> otherMsgs = GetOtherFailureMsgs();
181 cout << "Other error messages logged for this test were:" << endl;
182 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
183 cout << " " << *iter << endl;
184 }
185 }
186
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700187 private:
188 VkFlags m_msgFlags;
189 string m_desiredMsg;
190 string m_failureMsg;
191 vector<string> m_otherMsgs;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600192 test_platform_thread_mutex m_mutex;
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700193 bool *m_bailout;
194 VkBool32 m_msgFound;
Tony Barbour30486ea2015-04-07 13:44:53 -0600195};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500196
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700197static VKAPI_ATTR VkBool32 VKAPI_CALL
198myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
199 uint64_t srcObject, size_t location, int32_t msgCode,
200 const char *pLayerPrefix, const char *pMsg, void *pUserData) {
201 if (msgFlags &
Mark Lobodzinski5c13d4d2016-02-11 09:26:16 -0700202 (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700203 VK_DEBUG_REPORT_ERROR_BIT_EXT)) {
Tony Barbour8508b8e2015-04-09 10:48:04 -0600204 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600205 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour8508b8e2015-04-09 10:48:04 -0600206 }
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600207 return false;
Tony Barbour30486ea2015-04-07 13:44:53 -0600208}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500209
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700210class VkLayerTest : public VkRenderFramework {
211 public:
Chia-I Wu1f851912015-10-27 18:04:07 +0800212 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
213 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700214 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText,
215 BsoFailSelect failMask);
216 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
217 VkPipelineObj &pipelineobj,
218 VkDescriptorSetObj &descriptorSet,
219 BsoFailSelect failMask);
220 void GenericDrawPreparation(VkPipelineObj &pipelineobj,
221 VkDescriptorSetObj &descriptorSet,
222 BsoFailSelect failMask) {
223 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet,
224 failMask);
225 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600226
Tony Barbour1490c912015-07-28 10:17:20 -0600227 /* Convenience functions that use built-in command buffer */
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700228 VkResult BeginCommandBuffer() {
229 return BeginCommandBuffer(*m_commandBuffer);
230 }
Chia-I Wu1f851912015-10-27 18:04:07 +0800231 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700232 void Draw(uint32_t vertexCount, uint32_t instanceCount,
233 uint32_t firstVertex, uint32_t firstInstance) {
234 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex,
235 firstInstance);
236 }
237 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount,
238 uint32_t firstIndex, int32_t vertexOffset,
239 uint32_t firstInstance) {
240 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex,
241 vertexOffset, firstInstance);
242 }
Chia-I Wu1f851912015-10-27 18:04:07 +0800243 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700244 void QueueCommandBuffer(const VkFence &fence) {
245 m_commandBuffer->QueueCommandBuffer(fence);
246 }
247 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer,
248 VkDeviceSize offset, uint32_t binding) {
249 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
250 }
251 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
252 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
253 }
254
255 protected:
256 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600257
258 virtual void SetUp() {
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600259 std::vector<const char *> instance_layer_names;
260 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600261 std::vector<const char *> instance_extension_names;
262 std::vector<const char *> device_extension_names;
Tony Barbour950ebc02015-04-23 12:55:36 -0600263
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700264 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600265 /*
266 * Since CreateDbgMsgCallback is an instance level extension call
267 * any extension / layer that utilizes that feature also needs
268 * to be enabled at create instance time.
269 */
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700270 // Use Threading layer first to protect others from
271 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchterc6c611a2016-02-06 17:11:22 -0700272 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis3e093952016-03-24 10:54:18 -0600273 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine5d96e522015-12-11 10:49:51 -0800274 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlis5b5e7bc2016-03-09 16:12:48 -0700275 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine5d96e522015-12-11 10:49:51 -0800276 instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
277 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Dustin Graves73cfdff2016-01-26 16:30:22 -0700278 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600279
Courtney Goeltzenleuchterc6c611a2016-02-06 17:11:22 -0700280 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis3e093952016-03-24 10:54:18 -0600281 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine5d96e522015-12-11 10:49:51 -0800282 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlis5b5e7bc2016-03-09 16:12:48 -0700283 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine5d96e522015-12-11 10:49:51 -0800284 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
285 device_layer_names.push_back("VK_LAYER_LUNARG_image");
Dustin Graves73cfdff2016-01-26 16:30:22 -0700286 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Tony Barbour30486ea2015-04-07 13:44:53 -0600287
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600288 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -0600289 this->app_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +0800290 this->app_info.pApplicationName = "layer_tests";
291 this->app_info.applicationVersion = 1;
Tony Barbour30486ea2015-04-07 13:44:53 -0600292 this->app_info.pEngineName = "unittest";
293 this->app_info.engineVersion = 1;
Jon Ashburnd3995c92016-03-22 13:57:46 -0600294 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour30486ea2015-04-07 13:44:53 -0600295
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600296 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600297 InitFramework(instance_layer_names, device_layer_names,
298 instance_extension_names, device_extension_names,
299 myDbgFunc, m_errorMonitor);
Tony Barbour30486ea2015-04-07 13:44:53 -0600300 }
301
302 virtual void TearDown() {
303 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600304 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600305 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600306 }
307};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500308
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700309VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600310 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600311
Chia-I Wu1f851912015-10-27 18:04:07 +0800312 result = commandBuffer.BeginCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600313
314 /*
315 * For render test all drawing happens in a single render pass
316 * on a single command buffer.
317 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200318 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800319 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour30486ea2015-04-07 13:44:53 -0600320 }
321
322 return result;
323}
324
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700325VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600326 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600327
Chris Forbesfe133ef2015-06-16 14:05:59 +1200328 if (renderPass()) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800329 commandBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200330 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600331
Chia-I Wu1f851912015-10-27 18:04:07 +0800332 result = commandBuffer.EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600333
334 return result;
335}
336
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700337void VkLayerTest::VKTriangleTest(const char *vertShaderText,
338 const char *fragShaderText,
339 BsoFailSelect failMask) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500340 // Create identity matrix
341 int i;
342 struct vktriangle_vs_uniform data;
343
344 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700345 glm::mat4 View = glm::mat4(1.0f);
346 glm::mat4 Model = glm::mat4(1.0f);
347 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500348 const int matrixSize = sizeof(MVP);
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700349 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500350
351 memcpy(&data.mvp, &MVP[0][0], matrixSize);
352
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700353 static const Vertex tri_data[] = {
354 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)},
355 {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)},
356 {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500357 };
358
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700359 for (i = 0; i < 3; i++) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500360 data.position[i][0] = tri_data[i].posX;
361 data.position[i][1] = tri_data[i].posY;
362 data.position[i][2] = tri_data[i].posZ;
363 data.position[i][3] = tri_data[i].posW;
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700364 data.color[i][0] = tri_data[i].r;
365 data.color[i][1] = tri_data[i].g;
366 data.color[i][2] = tri_data[i].b;
367 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500368 }
369
370 ASSERT_NO_FATAL_FAILURE(InitState());
371 ASSERT_NO_FATAL_FAILURE(InitViewport());
372
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700373 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float),
374 (const void *)&data);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500375
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700376 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
377 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
378 this);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500379
380 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800381 pipelineobj.AddColorAttachment();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500382 pipelineobj.AddShader(&vs);
383 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600384 if (failMask & BsoFailLineWidth) {
385 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis3d3e06b2016-03-28 11:18:19 -0600386 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
387 ia_state.sType =
388 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
389 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
390 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600391 }
392 if (failMask & BsoFailDepthBias) {
393 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis3d3e06b2016-03-28 11:18:19 -0600394 VkPipelineRasterizationStateCreateInfo rs_state = {};
395 rs_state.sType =
396 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
397 rs_state.depthBiasEnable = VK_TRUE;
398 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600399 }
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700400 // Viewport and scissors must stay in synch or other errors will occur than
401 // the ones we want
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600402 if (failMask & BsoFailViewport) {
403 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600404 m_viewports.clear();
405 m_scissors.clear();
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600406 }
407 if (failMask & BsoFailScissor) {
408 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600409 m_scissors.clear();
410 m_viewports.clear();
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600411 }
412 if (failMask & BsoFailBlend) {
413 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis3d3e06b2016-03-28 11:18:19 -0600414 VkPipelineColorBlendAttachmentState att_state = {};
415 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
416 att_state.blendEnable = VK_TRUE;
417 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600418 }
419 if (failMask & BsoFailDepthBounds) {
420 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
421 }
422 if (failMask & BsoFailStencilReadMask) {
423 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
424 }
425 if (failMask & BsoFailStencilWriteMask) {
426 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
427 }
428 if (failMask & BsoFailStencilReference) {
429 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
430 }
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500431
432 VkDescriptorSetObj descriptorSet(m_device);
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700433 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
434 constantBuffer);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500435
436 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600437 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500438
Tony Barbour1490c912015-07-28 10:17:20 -0600439 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500440
441 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600442 Draw(3, 1, 0, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500443
444 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600445 EndCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500446
Tony Barbour1490c912015-07-28 10:17:20 -0600447 QueueCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500448}
449
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700450void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
451 VkPipelineObj &pipelineobj,
452 VkDescriptorSetObj &descriptorSet,
453 BsoFailSelect failMask) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500454 if (m_depthStencil->Initialized()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700455 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
456 m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500457 } else {
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700458 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
459 m_stencil_clear_color, NULL);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500460 }
461
Chia-I Wu1f851912015-10-27 18:04:07 +0800462 commandBuffer->PrepareAttachments();
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700463 // Make sure depthWriteEnable is set so that Depth fail test will work
464 // correctly
465 // Make sure stencilTestEnable is set so that Stencil fail test will work
466 // correctly
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600467 VkStencilOpState stencil = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +0800468 stencil.failOp = VK_STENCIL_OP_KEEP;
469 stencil.passOp = VK_STENCIL_OP_KEEP;
470 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
471 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600472
473 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
474 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600475 ds_ci.pNext = NULL;
476 ds_ci.depthTestEnable = VK_FALSE;
477 ds_ci.depthWriteEnable = VK_TRUE;
478 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
479 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis3d3e06b2016-03-28 11:18:19 -0600480 if (failMask & BsoFailDepthBounds) {
481 ds_ci.depthBoundsTestEnable = VK_TRUE;
482 }
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600483 ds_ci.stencilTestEnable = VK_TRUE;
484 ds_ci.front = stencil;
485 ds_ci.back = stencil;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600486
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600487 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600488 pipelineobj.SetViewport(m_viewports);
489 pipelineobj.SetScissor(m_scissors);
Chia-I Wu1f851912015-10-27 18:04:07 +0800490 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700491 VkResult err = pipelineobj.CreateVKPipeline(
492 descriptorSet.GetPipelineLayout(), renderPass());
Cody Northropccfa96d2015-08-27 10:20:35 -0600493 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +0800494 commandBuffer->BindPipeline(pipelineobj);
495 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500496}
497
498// ********************************************************************************************************************
499// ********************************************************************************************************************
500// ********************************************************************************************************************
501// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600502#if MEM_TRACKER_TESTS
Tobin Ehliscb085292015-12-01 09:57:09 -0700503#if 0
Chia-I Wu1f851912015-10-27 18:04:07 +0800504TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinski81078192015-05-19 10:28:29 -0500505{
506 vk_testing::Fence testFence;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500507 VkFenceCreateInfo fenceInfo = {};
508 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
509 fenceInfo.pNext = NULL;
510 fenceInfo.flags = 0;
511
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600513
Mark Lobodzinski81078192015-05-19 10:28:29 -0500514 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barboure389b882015-07-20 13:00:10 -0600515
516 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
517 vk_testing::Buffer buffer;
518 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500519
Tony Barbour1490c912015-07-28 10:17:20 -0600520 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800521 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbour1490c912015-07-28 10:17:20 -0600522 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500523
524 testFence.init(*m_device, fenceInfo);
525
526 // Bypass framework since it does the waits automatically
527 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600528 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +0800529 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
530 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800531 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600532 submit_info.pWaitSemaphores = NULL;
Jon Ashburn98ce7e02015-12-30 16:42:50 -0700533 submit_info.pWaitDstStageMask = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800534 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +0800535 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +0800536 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600537 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600538
539 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500540 ASSERT_VK_SUCCESS( err );
541
Mark Lobodzinski81078192015-05-19 10:28:29 -0500542 // Introduce failure by calling begin again before checking fence
Chia-I Wu1f851912015-10-27 18:04:07 +0800543 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500544
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600545 if (!m_errorMonitor->DesiredMsgFound()) {
546 FAIL() << "Did not receive Error 'Resetting CB (0xaddress) before it has completed. You must check CB flag before.'";
547 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500548 }
549}
550
Chia-I Wu1f851912015-10-27 18:04:07 +0800551TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinski81078192015-05-19 10:28:29 -0500552{
553 vk_testing::Fence testFence;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500554 VkFenceCreateInfo fenceInfo = {};
555 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
556 fenceInfo.pNext = NULL;
557 fenceInfo.flags = 0;
558
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600560
Mark Lobodzinski81078192015-05-19 10:28:29 -0500561 ASSERT_NO_FATAL_FAILURE(InitState());
562 ASSERT_NO_FATAL_FAILURE(InitViewport());
563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
564
Tony Barbour1490c912015-07-28 10:17:20 -0600565 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800566 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -0600567 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500568
569 testFence.init(*m_device, fenceInfo);
570
571 // Bypass framework since it does the waits automatically
572 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600573 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +0800574 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
575 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800576 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600577 submit_info.pWaitSemaphores = NULL;
Jon Ashburn98ce7e02015-12-30 16:42:50 -0700578 submit_info.pWaitDstStageMask = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800579 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +0800580 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +0800581 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600582 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600583
584 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500585 ASSERT_VK_SUCCESS( err );
586
Jon Ashburna4ae48b2016-01-11 13:12:43 -0700587 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu1f851912015-10-27 18:04:07 +0800588 VkCommandBufferBeginInfo info = {};
589 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
590 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600591 info.renderPass = VK_NULL_HANDLE;
592 info.subpass = 0;
593 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wufdc1cd02015-11-11 10:18:12 +0800594 info.occlusionQueryEnable = VK_FALSE;
595 info.queryFlags = 0;
596 info.pipelineStatistics = 0;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600597
598 // Introduce failure by calling BCB again before checking fence
Chia-I Wu1f851912015-10-27 18:04:07 +0800599 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500600
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600601 if (!m_errorMonitor->DesiredMsgFound()) {
602 FAIL() << "Did not receive Error 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
603 m_errorMonitor->DumpFailureMsgs();
604
Mark Lobodzinski81078192015-05-19 10:28:29 -0500605 }
606}
Tobin Ehliscb085292015-12-01 09:57:09 -0700607#endif
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700608TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
609 VkResult err;
610 bool pass;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500611
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700612 m_errorMonitor->SetDesiredFailureMsg(
613 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600614 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
615
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500616 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500617
618 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700619 VkImage image;
620 VkDeviceMemory mem;
621 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500622
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700623 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
624 const int32_t tex_width = 32;
625 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500626
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600627 VkImageCreateInfo image_create_info = {};
628 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700629 image_create_info.pNext = NULL;
630 image_create_info.imageType = VK_IMAGE_TYPE_2D;
631 image_create_info.format = tex_format;
632 image_create_info.extent.width = tex_width;
633 image_create_info.extent.height = tex_height;
634 image_create_info.extent.depth = 1;
635 image_create_info.mipLevels = 1;
636 image_create_info.arrayLayers = 1;
637 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
638 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
639 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
640 image_create_info.flags = 0;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600641
Chia-I Wu1f851912015-10-27 18:04:07 +0800642 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +0800643 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700644 mem_alloc.pNext = NULL;
645 mem_alloc.allocationSize = 0;
646 // Introduce failure, do NOT set memProps to
647 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
648 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500649
Chia-I Wu69f40122015-10-26 21:10:41 +0800650 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500651 ASSERT_VK_SUCCESS(err);
652
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700653 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500654
Mark Lobodzinski23182612015-05-29 09:32:35 -0500655 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500656
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700657 pass =
658 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0,
659 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
660 if (!pass) { // If we can't find any unmappable memory this test doesn't
661 // make sense
Chia-I Wu69f40122015-10-26 21:10:41 +0800662 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour49a3b652015-08-04 16:13:01 -0600663 return;
Mike Stroyan2237f522015-08-18 14:40:24 -0600664 }
Mike Stroyand72da752015-08-04 10:49:29 -0600665
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500666 // allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +0800667 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500668 ASSERT_VK_SUCCESS(err);
669
670 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600671 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500672 ASSERT_VK_SUCCESS(err);
673
674 // Map memory as if to initialize the image
675 void *mappedAddress = NULL;
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700676 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0,
677 &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500678
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600679 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700680 FAIL() << "Did not receive Error 'Error received did not match "
681 "expected error message from vkMapMemory in MemTracker'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600682 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500683 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600684
Chia-I Wu69f40122015-10-26 21:10:41 +0800685 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500686}
687
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700688// TODO : Is this test still valid. Not sure it is with updates to memory
689// binding model
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600690// Verify and delete the test of fix the check
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700691// TEST_F(VkLayerTest, FreeBoundMemory)
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600692//{
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600693// VkResult err;
694//
Mark Lobodzinski5c13d4d2016-02-11 09:26:16 -0700695// m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600696// "Freeing memory object while it still has references");
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600697//
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600698// ASSERT_NO_FATAL_FAILURE(InitState());
699
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600700// // Create an image, allocate memory, free it, and then try to bind it
701// VkImage image;
702// VkDeviceMemory mem;
703// VkMemoryRequirements mem_reqs;
704//
705// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
706// const int32_t tex_width = 32;
707// const int32_t tex_height = 32;
708//
709// const VkImageCreateInfo image_create_info = {
710// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
711// .pNext = NULL,
712// .imageType = VK_IMAGE_TYPE_2D,
713// .format = tex_format,
714// .extent = { tex_width, tex_height, 1 },
715// .mipLevels = 1,
716// .arraySize = 1,
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800717// .samples = VK_SAMPLE_COUNT_1_BIT,
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600718// .tiling = VK_IMAGE_TILING_LINEAR,
719// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
720// .flags = 0,
721// };
Chia-I Wu1f851912015-10-27 18:04:07 +0800722// VkMemoryAllocateInfo mem_alloc = {
Chia-I Wuc1f5e402015-11-10 16:21:09 +0800723// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600724// .pNext = NULL,
725// .allocationSize = 0,
726// .memoryTypeIndex = 0,
727// };
728//
Chia-I Wu69f40122015-10-26 21:10:41 +0800729// err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600730// ASSERT_VK_SUCCESS(err);
731//
732// err = vkGetImageMemoryRequirements(m_device->device(),
733// image,
734// &mem_reqs);
735// ASSERT_VK_SUCCESS(err);
736//
737// mem_alloc.allocationSize = mem_reqs.size;
738//
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700739// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc,
740// 0);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600741// ASSERT_VK_SUCCESS(err);
742//
743// // allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +0800744// err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600745// ASSERT_VK_SUCCESS(err);
746//
747// // Bind memory to Image object
748// err = vkBindImageMemory(m_device->device(), image, mem, 0);
749// ASSERT_VK_SUCCESS(err);
750//
751// // Introduce validation failure, free memory while still bound to object
Chia-I Wu69f40122015-10-26 21:10:41 +0800752// vkFreeMemory(m_device->device(), mem, NULL);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600753//
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600754// if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700755// FAIL() << "Did not receive Warning 'Freeing memory object while it
756// still has references'");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600757// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600758// }
759//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500760
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700761TEST_F(VkLayerTest, RebindMemory) {
762 VkResult err;
763 bool pass;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500764
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700765 m_errorMonitor->SetDesiredFailureMsg(
766 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600767 "which has already been bound to mem object");
768
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500769 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500770
771 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700772 VkImage image;
773 VkDeviceMemory mem1;
774 VkDeviceMemory mem2;
775 VkMemoryRequirements mem_reqs;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500776
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700777 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
778 const int32_t tex_width = 32;
779 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500780
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600781 VkImageCreateInfo image_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700782 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
783 image_create_info.pNext = NULL;
784 image_create_info.imageType = VK_IMAGE_TYPE_2D;
785 image_create_info.format = tex_format;
786 image_create_info.extent.width = tex_width;
787 image_create_info.extent.height = tex_height;
788 image_create_info.extent.depth = 1;
789 image_create_info.mipLevels = 1;
790 image_create_info.arrayLayers = 1;
791 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
792 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
793 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
794 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500795
Chia-I Wu1f851912015-10-27 18:04:07 +0800796 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700797 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
798 mem_alloc.pNext = NULL;
799 mem_alloc.allocationSize = 0;
800 mem_alloc.memoryTypeIndex = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600801
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700802 // Introduce failure, do NOT set memProps to
803 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600804 mem_alloc.memoryTypeIndex = 1;
Chia-I Wu69f40122015-10-26 21:10:41 +0800805 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500806 ASSERT_VK_SUCCESS(err);
807
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700808 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500809
810 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700811 pass =
812 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600813 ASSERT_TRUE(pass);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500814
815 // allocate 2 memory objects
Chia-I Wu1f851912015-10-27 18:04:07 +0800816 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500817 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +0800818 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500819 ASSERT_VK_SUCCESS(err);
820
821 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600822 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500823 ASSERT_VK_SUCCESS(err);
824
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700825 // Introduce validation failure, try to bind a different memory object to
826 // the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600827 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500828
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600829 if (!m_errorMonitor->DesiredMsgFound()) {
830 FAIL() << "Did not receive Error when rebinding memory to an object";
831 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500832 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600833
Chia-I Wu69f40122015-10-26 21:10:41 +0800834 vkDestroyImage(m_device->device(), image, NULL);
835 vkFreeMemory(m_device->device(), mem1, NULL);
836 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500837}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500838
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700839TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600840 vk_testing::Fence testFence;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600841
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700842 m_errorMonitor->SetDesiredFailureMsg(
843 VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
844 "must be reset before being submitted");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600845
846 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600847 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
848 fenceInfo.pNext = NULL;
849 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600850
Tony Barbour30486ea2015-04-07 13:44:53 -0600851 ASSERT_NO_FATAL_FAILURE(InitState());
852 ASSERT_NO_FATAL_FAILURE(InitViewport());
853 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
854
Tony Barbour1490c912015-07-28 10:17:20 -0600855 BeginCommandBuffer();
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700856 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
857 m_stencil_clear_color, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -0600858 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600859
860 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600861
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600862 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +0800863 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
864 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800865 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600866 submit_info.pWaitSemaphores = NULL;
Jon Ashburn98ce7e02015-12-30 16:42:50 -0700867 submit_info.pWaitDstStageMask = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800868 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +0800869 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +0800870 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600871 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600872
873 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700874 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600875
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600876 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700877 FAIL() << "Did not receive Error 'VkQueueSubmit with fence in "
878 "SIGNALED_STATE'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600879 m_errorMonitor->DumpFailureMsgs();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600880 }
Tony Barbour8508b8e2015-04-09 10:48:04 -0600881}
882
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700883TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tony Barbour8508b8e2015-04-09 10:48:04 -0600884 vk_testing::Fence testFence;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600885 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600886 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
887 fenceInfo.pNext = NULL;
888
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700889 // TODO: verify that this matches layer
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700890 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski5c13d4d2016-02-11 09:26:16 -0700891 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600892 "submitted to VkResetFences in UNSIGNALED STATE");
893
Tony Barbour8508b8e2015-04-09 10:48:04 -0600894 ASSERT_NO_FATAL_FAILURE(InitState());
895 testFence.init(*m_device, fenceInfo);
Chia-I Wua4992342015-07-03 11:45:55 +0800896 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600897 vkResetFences(m_device->device(), 1, fences);
Tony Barbour30486ea2015-04-07 13:44:53 -0600898
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600899 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700900 FAIL() << "Did not receive Error 'VkResetFences with fence in "
901 "UNSIGNALED_STATE'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600902 m_errorMonitor->DumpFailureMsgs();
903 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600904}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600905
Chia-I Wuc278df82015-07-07 11:50:03 +0800906/* TODO: Update for changes due to bug-14075 tiling across render passes */
907#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600908TEST_F(VkLayerTest, InvalidUsageBits)
909{
910 // Initiate Draw w/o a PSO bound
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600911
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600913 "Invalid usage flag for image ");
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600914
915 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +0800916 VkCommandBufferObj commandBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600917 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600918
919 const VkExtent3D e3d = {
920 .width = 128,
921 .height = 128,
922 .depth = 1,
923 };
924 const VkImageCreateInfo ici = {
925 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
926 .pNext = NULL,
927 .imageType = VK_IMAGE_TYPE_2D,
928 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
929 .extent = e3d,
930 .mipLevels = 1,
931 .arraySize = 1,
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800932 .samples = VK_SAMPLE_COUNT_1_BIT,
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600933 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchterc3b8eea2015-09-10 14:14:11 -0600934 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600935 .flags = 0,
936 };
937
938 VkImage dsi;
Chia-I Wu69f40122015-10-26 21:10:41 +0800939 vkCreateImage(m_device->device(), &ici, NULL, &dsi);
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600940 VkDepthStencilView dsv;
941 const VkDepthStencilViewCreateInfo dsvci = {
942 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
943 .pNext = NULL,
944 .image = dsi,
945 .mipLevel = 0,
Courtney Goeltzenleuchter3dee8082015-09-10 16:38:41 -0600946 .baseArrayLayer = 0,
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600947 .arraySize = 1,
948 .flags = 0,
949 };
Chia-I Wu69f40122015-10-26 21:10:41 +0800950 vkCreateDepthStencilView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600951
952 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600953 FAIL() << "Error received was not 'Invalid usage flag for image...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600954 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600955 }
956}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600957#endif // 0
958#endif // MEM_TRACKER_TESTS
959
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600960#if OBJ_TRACKER_TESTS
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700961TEST_F(VkLayerTest, PipelineNotBound) {
962 VkResult err;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600963
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700965 "Invalid VkPipeline Object ");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600966
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600967 ASSERT_NO_FATAL_FAILURE(InitState());
968 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600969
Chia-I Wuc51b1212015-10-27 19:25:11 +0800970 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700971 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
972 ds_type_count.descriptorCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600973
974 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700975 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
976 ds_pool_ci.pNext = NULL;
977 ds_pool_ci.maxSets = 1;
978 ds_pool_ci.poolSizeCount = 1;
979 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600980
981 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700982 err =
983 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600984 ASSERT_VK_SUCCESS(err);
985
986 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700987 dsl_binding.binding = 0;
988 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
989 dsl_binding.descriptorCount = 1;
990 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
991 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600992
993 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -0700994 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
995 ds_layout_ci.pNext = NULL;
996 ds_layout_ci.bindingCount = 1;
997 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600998
999 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001000 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
1001 &ds_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001002 ASSERT_VK_SUCCESS(err);
1003
1004 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001005 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001006 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07001007 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001008 alloc_info.descriptorPool = ds_pool;
1009 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001010 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
1011 &descriptorSet);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001012 ASSERT_VK_SUCCESS(err);
1013
1014 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001015 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1016 pipeline_layout_ci.pNext = NULL;
1017 pipeline_layout_ci.setLayoutCount = 1;
1018 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001019
1020 VkPipelineLayout pipeline_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001021 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
1022 &pipeline_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001023 ASSERT_VK_SUCCESS(err);
1024
Mark Youngcbd7c6b2016-01-06 14:26:04 -07001025 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001026
1027 BeginCommandBuffer();
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001028 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
1029 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001030
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001031 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001032 FAIL()
1033 << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be'"
1034 << endl;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001035 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001036 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001037
Chia-I Wu69f40122015-10-26 21:10:41 +08001038 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1039 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1040 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001041}
1042
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001043TEST_F(VkLayerTest, BindInvalidMemory) {
1044 VkResult err;
1045 bool pass;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001046
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001048 "Invalid VkDeviceMemory Object ");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001049
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001050 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001051
1052 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001053 VkImage image;
1054 VkDeviceMemory mem;
1055 VkMemoryRequirements mem_reqs;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001056
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001057 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1058 const int32_t tex_width = 32;
1059 const int32_t tex_height = 32;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001060
1061 VkImageCreateInfo image_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001062 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1063 image_create_info.pNext = NULL;
1064 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1065 image_create_info.format = tex_format;
1066 image_create_info.extent.width = tex_width;
1067 image_create_info.extent.height = tex_height;
1068 image_create_info.extent.depth = 1;
1069 image_create_info.mipLevels = 1;
1070 image_create_info.arrayLayers = 1;
1071 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1072 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1073 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1074 image_create_info.flags = 0;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001075
Chia-I Wu1f851912015-10-27 18:04:07 +08001076 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001077 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1078 mem_alloc.pNext = NULL;
1079 mem_alloc.allocationSize = 0;
1080 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001081
Chia-I Wu69f40122015-10-26 21:10:41 +08001082 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001083 ASSERT_VK_SUCCESS(err);
1084
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001085 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001086
1087 mem_alloc.allocationSize = mem_reqs.size;
1088
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001089 pass =
1090 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001091 ASSERT_TRUE(pass);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001092
1093 // allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08001094 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001095 ASSERT_VK_SUCCESS(err);
1096
1097 // Introduce validation failure, free memory before binding
Chia-I Wu69f40122015-10-26 21:10:41 +08001098 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001099
1100 // Try to bind free memory that has been freed
1101 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1102 // This may very well return an error.
1103 (void)err;
1104
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001105 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001106 FAIL() << "Did not receive Error 'Invalid VkDeviceMemory Object "
1107 "0x<handle>'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001108 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001109 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001110
Chia-I Wu69f40122015-10-26 21:10:41 +08001111 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001112}
1113
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001114TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
1115 VkResult err;
1116 bool pass;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001117
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1119 "Invalid VkImage Object ");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001120
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001121 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001122
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001123 // Create an image object, allocate memory, destroy the object and then try
1124 // to bind it
1125 VkImage image;
1126 VkDeviceMemory mem;
1127 VkMemoryRequirements mem_reqs;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001128
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001129 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1130 const int32_t tex_width = 32;
1131 const int32_t tex_height = 32;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001132
1133 VkImageCreateInfo image_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001134 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1135 image_create_info.pNext = NULL;
1136 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1137 image_create_info.format = tex_format;
1138 image_create_info.extent.width = tex_width;
1139 image_create_info.extent.height = tex_height;
1140 image_create_info.extent.depth = 1;
1141 image_create_info.mipLevels = 1;
1142 image_create_info.arrayLayers = 1;
1143 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1144 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1145 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1146 image_create_info.flags = 0;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001147
Chia-I Wu1f851912015-10-27 18:04:07 +08001148 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001149 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1150 mem_alloc.pNext = NULL;
1151 mem_alloc.allocationSize = 0;
1152 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001153
Chia-I Wu69f40122015-10-26 21:10:41 +08001154 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001155 ASSERT_VK_SUCCESS(err);
1156
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001157 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001158
1159 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001160 pass =
1161 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001162 ASSERT_TRUE(pass);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001163
1164 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08001165 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001166 ASSERT_VK_SUCCESS(err);
1167
1168 // Introduce validation failure, destroy Image object before binding
Chia-I Wu69f40122015-10-26 21:10:41 +08001169 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001170 ASSERT_VK_SUCCESS(err);
1171
1172 // Now Try to bind memory to this destroyed object
1173 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1174 // This may very well return an error.
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001175 (void)err;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001176
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001177 if (!m_errorMonitor->DesiredMsgFound()) {
1178 FAIL() << "Did not receive Error 'Invalid VkImage Object 0x<handle>'";
1179 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001180 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001181
Chia-I Wu69f40122015-10-26 21:10:41 +08001182 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001183}
Tobin Ehlisb46be812015-10-23 16:00:08 -06001184
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001185#endif // OBJ_TRACKER_TESTS
1186
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001187#if DRAW_STATE_TESTS
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001188TEST_F(VkLayerTest, LineWidthStateNotBound) {
1189 m_errorMonitor->SetDesiredFailureMsg(
1190 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001191 "Dynamic line width state not set for this command buffer");
1192
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001193 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line "
1194 "width state object is not bound beforehand");
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001195
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001196 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1197 BsoFailLineWidth);
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001198
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001199 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001200 FAIL() << "Did not receive Error 'Dynamic line width state not set for "
1201 "this command buffer'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001202 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001203 }
1204}
1205
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001206TEST_F(VkLayerTest, DepthBiasStateNotBound) {
1207 m_errorMonitor->SetDesiredFailureMsg(
1208 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001209 "Dynamic depth bias state not set for this command buffer");
1210
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001211 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth "
1212 "bias state object is not bound beforehand");
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001213
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001214 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1215 BsoFailDepthBias);
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001216
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001217 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001218 FAIL() << "Did not receive Error 'Dynamic depth bias state not set for "
1219 "this command buffer'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001220 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001221 }
1222}
1223
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001224// Disable these two tests until we can sort out how to track multiple layer
1225// errors
1226TEST_F(VkLayerTest, ViewportStateNotBound) {
1227 m_errorMonitor->SetDesiredFailureMsg(
1228 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001229 "Dynamic viewport state not set for this command buffer");
1230
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001231 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport "
1232 "state object is not bound beforehand");
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001233
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001234 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1235 BsoFailViewport);
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001236
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001237 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlis3d3e06b2016-03-28 11:18:19 -06001238 FAIL() << "Did not receive Error 'Dynamic scissor state not set for "
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001239 "this command buffer'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001240 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001241 }
1242}
1243
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001244TEST_F(VkLayerTest, ScissorStateNotBound) {
1245 m_errorMonitor->SetDesiredFailureMsg(
1246 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001247 "Dynamic scissor state not set for this command buffer");
1248
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001249 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport "
1250 "state object is not bound beforehand");
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001251
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001252 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1253 BsoFailScissor);
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001254
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001255 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlis3d3e06b2016-03-28 11:18:19 -06001256 FAIL() << "Did not receive Error ' Expected: 'Dynamic scissor state "
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001257 "not set for this command buffer'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001258 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001259 }
1260}
1261
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001262TEST_F(VkLayerTest, BlendStateNotBound) {
1263 m_errorMonitor->SetDesiredFailureMsg(
1264 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis3d3e06b2016-03-28 11:18:19 -06001265 "Dynamic blend constants state not set for this command buffer");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001266
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001267 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend "
1268 "state object is not bound beforehand");
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001269
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001270 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1271 BsoFailBlend);
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001272
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001273 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlis3d3e06b2016-03-28 11:18:19 -06001274 FAIL()
1275 << "Did not receive Error 'Dynamic blend constants state not set "
1276 "for this command buffer'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001277 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001278 }
1279}
1280
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001281TEST_F(VkLayerTest, DepthBoundsStateNotBound) {
1282 m_errorMonitor->SetDesiredFailureMsg(
1283 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001284 "Dynamic depth bounds state not set for this command buffer");
1285
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001286 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth "
1287 "bounds state object is not bound beforehand");
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001288
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001289 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1290 BsoFailDepthBounds);
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001291
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001292 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001293 FAIL() << "Did not receive Error 'Dynamic depth bounds state not set "
1294 "for this command buffer'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001295 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001296 }
1297}
1298
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001299TEST_F(VkLayerTest, StencilReadMaskNotSet) {
1300 m_errorMonitor->SetDesiredFailureMsg(
1301 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001302 "Dynamic stencil read mask state not set for this command buffer");
1303
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001304 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001305
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001306 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil "
1307 "read mask is not set beforehand");
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001308
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001309 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1310 BsoFailStencilReadMask);
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001311
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001312 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001313 FAIL() << "Did not receive Error 'Dynamic stencil read mask state not "
1314 "set for this command buffer'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001315 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001316 }
1317}
1318
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001319TEST_F(VkLayerTest, StencilWriteMaskNotSet) {
1320 m_errorMonitor->SetDesiredFailureMsg(
1321 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001322 "Dynamic stencil write mask state not set for this command buffer");
1323
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001324 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001325
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001326 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil "
1327 "write mask is not set beforehand");
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001328
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001329 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1330 BsoFailStencilWriteMask);
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001331
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001332 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001333 FAIL() << "Did not receive Error 'Dynamic stencil write mask state not "
1334 "set for this command buffer'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001335 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001336 }
1337}
1338
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001339TEST_F(VkLayerTest, StencilReferenceNotSet) {
1340 m_errorMonitor->SetDesiredFailureMsg(
1341 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001342 "Dynamic stencil reference state not set for this command buffer");
1343
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001344 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil "
1345 "reference is not set beforehand");
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001346
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001347 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
1348 BsoFailStencilReference);
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001349
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001350 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001351 FAIL() << "Did not receive Error 'Dynamic stencil reference state not "
1352 "set for this command buffer'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001353 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001354 }
1355}
1356
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001357TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001358 vk_testing::Fence testFence;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001359
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001360 m_errorMonitor->SetDesiredFailureMsg(
1361 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1362 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
1363 "been submitted");
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001364
1365 VkFenceCreateInfo fenceInfo = {};
1366 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1367 fenceInfo.pNext = NULL;
1368 fenceInfo.flags = 0;
1369
1370 ASSERT_NO_FATAL_FAILURE(InitState());
1371 ASSERT_NO_FATAL_FAILURE(InitViewport());
1372 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1373
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001374 // We luck out b/c by default the framework creates CB w/ the
1375 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001376 BeginCommandBuffer();
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001377 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
1378 m_stencil_clear_color, NULL);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001379 EndCommandBuffer();
1380
1381 testFence.init(*m_device, fenceInfo);
1382
1383 // Bypass framework since it does the waits automatically
1384 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001385 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +08001386 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1387 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001388 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001389 submit_info.pWaitSemaphores = NULL;
Jon Ashburn98ce7e02015-12-30 16:42:50 -07001390 submit_info.pWaitDstStageMask = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001391 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08001392 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +08001393 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001394 submit_info.pSignalSemaphores = NULL;
1395
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001396 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
1397 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001398
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001399 // Cause validation error by re-submitting cmd buffer that should only be
1400 // submitted once
1401 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001402
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001403 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001404 FAIL() << "Did not receive Error 'CB (0xaddress) was created w/ "
1405 "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001406 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001407 }
1408}
1409
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001410TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001411 // Initiate Draw w/o a PSO bound
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001412 VkResult err;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001413
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001415 "Unable to allocate 1 descriptors of "
1416 "type "
1417 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001418
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001419 ASSERT_NO_FATAL_FAILURE(InitState());
1420 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001421
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001422 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
1423 // descriptor from it
Chia-I Wuc51b1212015-10-27 19:25:11 +08001424 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001425 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
1426 ds_type_count.descriptorCount = 1;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001427
1428 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001429 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1430 ds_pool_ci.pNext = NULL;
1431 ds_pool_ci.flags = 0;
1432 ds_pool_ci.maxSets = 1;
1433 ds_pool_ci.poolSizeCount = 1;
1434 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001435
1436 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001437 err =
1438 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001439 ASSERT_VK_SUCCESS(err);
1440
1441 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001442 dsl_binding.binding = 0;
1443 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1444 dsl_binding.descriptorCount = 1;
1445 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1446 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001447
1448 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001449 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1450 ds_layout_ci.pNext = NULL;
1451 ds_layout_ci.bindingCount = 1;
1452 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001453
1454 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001455 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
1456 &ds_layout);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001457 ASSERT_VK_SUCCESS(err);
1458
1459 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001460 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001461 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07001462 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001463 alloc_info.descriptorPool = ds_pool;
1464 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001465 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
1466 &descriptorSet);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001467
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001468 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001469 FAIL() << "Did not receive Error 'Unable to allocate 1 descriptors of "
1470 "type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001471 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001472 }
1473
Chia-I Wu69f40122015-10-26 21:10:41 +08001474 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1475 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001476}
1477
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001478TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
1479 VkResult err;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001480
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001481 m_errorMonitor->SetDesiredFailureMsg(
1482 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1483 "It is invalid to call vkFreeDescriptorSets() with a pool created "
1484 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001485
Tobin Ehlis3c543112015-10-08 13:13:50 -06001486 ASSERT_NO_FATAL_FAILURE(InitState());
1487 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis3c543112015-10-08 13:13:50 -06001488
Chia-I Wuc51b1212015-10-27 19:25:11 +08001489 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001490 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1491 ds_type_count.descriptorCount = 1;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001492
1493 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001494 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1495 ds_pool_ci.pNext = NULL;
1496 ds_pool_ci.maxSets = 1;
1497 ds_pool_ci.poolSizeCount = 1;
1498 ds_pool_ci.flags = 0;
1499 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
1500 // app can only call vkResetDescriptorPool on this pool.;
1501 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001502
1503 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001504 err =
1505 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001506 ASSERT_VK_SUCCESS(err);
1507
1508 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001509 dsl_binding.binding = 0;
1510 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1511 dsl_binding.descriptorCount = 1;
1512 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1513 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001514
1515 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001516 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1517 ds_layout_ci.pNext = NULL;
1518 ds_layout_ci.bindingCount = 1;
1519 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001520
1521 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001522 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
1523 &ds_layout);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001524 ASSERT_VK_SUCCESS(err);
1525
1526 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001527 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001528 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07001529 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001530 alloc_info.descriptorPool = ds_pool;
1531 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001532 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
1533 &descriptorSet);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001534 ASSERT_VK_SUCCESS(err);
1535
1536 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001537 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001538 FAIL() << "Did not receive Error 'It is invalid to call "
1539 "vkFreeDescriptorSets() with a pool created with...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001540 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3c543112015-10-08 13:13:50 -06001541 }
1542
Chia-I Wu69f40122015-10-26 21:10:41 +08001543 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1544 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001545}
1546
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001547TEST_F(VkLayerTest, InvalidDescriptorPool) {
1548 // TODO : Simple check for bad object should be added to ObjectTracker to
1549 // catch this case
1550 // The DS check for this is after driver has been called to validate DS
1551 // internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001552 // Attempt to clear DS Pool with bad object
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001553 /*
1554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1555 "Unable to find pool node for pool 0xbaad6001 specified in
1556 vkResetDescriptorPool() call");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001557
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001558 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1559 vkResetDescriptorPool(device(), badPool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001560
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001561 if (!m_errorMonitor->DesiredMsgFound()) {
1562 FAIL() << "Did not receive Error 'Unable to find pool node for pool
1563 0xbaad6001 specified in vkResetDescriptorPool() call'";
1564 m_errorMonitor->DumpFailureMsgs();
1565 }*/
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001566}
1567
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001568TEST_F(VkLayerTest, InvalidDescriptorSet) {
1569 // TODO : Simple check for bad object should be added to ObjectTracker to
1570 // catch this case
1571 // The DS check for this is after driver has been called to validate DS
1572 // internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001573 // Create a valid cmd buffer
1574 // call vkCmdBindDescriptorSets w/ false DS
1575}
1576
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001577TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
1578 // TODO : Simple check for bad object should be added to ObjectTracker to
1579 // catch this case
1580 // The DS check for this is after driver has been called to validate DS
1581 // internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001582}
1583
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001584TEST_F(VkLayerTest, InvalidPipeline) {
1585 // TODO : Simple check for bad object should be added to ObjectTracker to
1586 // catch this case
1587 // The DS check for this is after driver has been called to validate DS
1588 // internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001589 // Create a valid cmd buffer
1590 // call vkCmdBindPipeline w/ false Pipeline
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001591 //
1592 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1593 // "Attempt to bind Pipeline ");
1594 //
1595 // ASSERT_NO_FATAL_FAILURE(InitState());
1596 // VkCommandBufferObj commandBuffer(m_device);
1597 // BeginCommandBuffer();
1598 // VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1599 // vkCmdBindPipeline(commandBuffer.GetBufferHandle(),
1600 // VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1601 //
1602 // if (!m_errorMonitor->DesiredMsgFound()) {
1603 // FAIL() << "Did not receive Error 'Attempt to bind Pipeline
1604 // 0xbaadb1be that doesn't exist!'";
1605 // m_errorMonitor->DumpFailureMsgs();
1606 // }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001607}
1608
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001609TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
1610 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
1611 // CommandBuffer
1612 VkResult err;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001613
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001614 // TODO: verify that this matches layer
Mark Lobodzinski5c13d4d2016-02-11 09:26:16 -07001615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001616 " bound but it was never updated. ");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001617
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001618 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001619 ASSERT_NO_FATAL_FAILURE(InitViewport());
1620 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wuc51b1212015-10-27 19:25:11 +08001621 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001622 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1623 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001624
1625 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001626 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1627 ds_pool_ci.pNext = NULL;
1628 ds_pool_ci.maxSets = 1;
1629 ds_pool_ci.poolSizeCount = 1;
1630 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001631
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001632 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001633 err =
1634 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001635 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001636
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001637 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001638 dsl_binding.binding = 0;
1639 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1640 dsl_binding.descriptorCount = 1;
1641 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1642 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001643
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001644 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001645 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1646 ds_layout_ci.pNext = NULL;
1647 ds_layout_ci.bindingCount = 1;
1648 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001649 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001650 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
1651 &ds_layout);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001652 ASSERT_VK_SUCCESS(err);
1653
1654 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001655 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001656 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07001657 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001658 alloc_info.descriptorPool = ds_pool;
1659 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001660 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
1661 &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001662 ASSERT_VK_SUCCESS(err);
1663
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001664 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001665 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1666 pipeline_layout_ci.pNext = NULL;
1667 pipeline_layout_ci.setLayoutCount = 1;
1668 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001669
1670 VkPipelineLayout pipeline_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001671 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
1672 &pipeline_layout);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001673 ASSERT_VK_SUCCESS(err);
1674
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001675 VkShaderObj vs(m_device, bindStateVertShaderText,
1676 VK_SHADER_STAGE_VERTEX_BIT, this);
1677 // TODO - We shouldn't need a fragment shader but add it to be able to run
1678 // on more devices
1679 VkShaderObj fs(m_device, bindStateFragShaderText,
1680 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001681
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001682 VkPipelineObj pipe(m_device);
1683 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001684 pipe.AddShader(&fs);
Mark Young0292df52016-03-31 16:03:20 -06001685 pipe.AddColorAttachment();
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001686 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001687
1688 BeginCommandBuffer();
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001689 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
1690 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1691 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
1692 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
1693 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001694
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001695 if (!m_errorMonitor->DesiredMsgFound()) {
Eric Engestrom9bdcb232016-04-02 22:08:10 +01001696 FAIL() << "Did not receive Warning 'DS <blah> bound but it was never "
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001697 "updated. You may want to either update it or not bind it.'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001698 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001699 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001700
Chia-I Wu69f40122015-10-26 21:10:41 +08001701 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1702 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1703 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001704}
1705
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001706TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlis093ef922015-11-02 15:24:32 -07001707 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001708 VkResult err;
Tobin Ehlis093ef922015-11-02 15:24:32 -07001709
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001710 m_errorMonitor->SetDesiredFailureMsg(
1711 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis093ef922015-11-02 15:24:32 -07001712 "Attempt to update descriptor with invalid bufferView ");
1713
1714 ASSERT_NO_FATAL_FAILURE(InitState());
1715 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001716 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1717 ds_type_count.descriptorCount = 1;
Tobin Ehlis093ef922015-11-02 15:24:32 -07001718
1719 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001720 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1721 ds_pool_ci.pNext = NULL;
1722 ds_pool_ci.maxSets = 1;
1723 ds_pool_ci.poolSizeCount = 1;
1724 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis093ef922015-11-02 15:24:32 -07001725
1726 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001727 err =
1728 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis093ef922015-11-02 15:24:32 -07001729 ASSERT_VK_SUCCESS(err);
1730
1731 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001732 dsl_binding.binding = 0;
1733 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1734 dsl_binding.descriptorCount = 1;
1735 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1736 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis093ef922015-11-02 15:24:32 -07001737
1738 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001739 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1740 ds_layout_ci.pNext = NULL;
1741 ds_layout_ci.bindingCount = 1;
1742 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis093ef922015-11-02 15:24:32 -07001743 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001744 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
1745 &ds_layout);
Tobin Ehlis093ef922015-11-02 15:24:32 -07001746 ASSERT_VK_SUCCESS(err);
1747
1748 VkDescriptorSet descriptorSet;
1749 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001750 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07001751 alloc_info.descriptorSetCount = 1;
Tobin Ehlis093ef922015-11-02 15:24:32 -07001752 alloc_info.descriptorPool = ds_pool;
1753 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001754 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
1755 &descriptorSet);
Tobin Ehlis093ef922015-11-02 15:24:32 -07001756 ASSERT_VK_SUCCESS(err);
1757
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001758 VkBufferView view =
1759 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlis093ef922015-11-02 15:24:32 -07001760 VkWriteDescriptorSet descriptor_write;
1761 memset(&descriptor_write, 0, sizeof(descriptor_write));
1762 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1763 descriptor_write.dstSet = descriptorSet;
1764 descriptor_write.dstBinding = 0;
1765 descriptor_write.descriptorCount = 1;
1766 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1767 descriptor_write.pTexelBufferView = &view;
1768
1769 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1770
1771 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001772 FAIL() << "Did not receive Error 'Attempt to update descriptor with "
1773 "invalid bufferView'";
Tobin Ehlis093ef922015-11-02 15:24:32 -07001774 m_errorMonitor->DumpFailureMsgs();
1775 }
1776
1777 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1778 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1779}
1780
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001781TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
1782 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
1783 // cases:
Tobin Ehlisea975962015-12-17 11:48:42 -07001784 // 1. No dynamicOffset supplied
1785 // 2. Too many dynamicOffsets supplied
1786 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001787 VkResult err;
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07001788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001789 " requires 1 dynamicOffsets, but only "
1790 "0 dynamicOffsets are left in "
1791 "pDynamicOffsets ");
Tobin Ehlise2194862015-11-04 13:30:34 -07001792
1793 ASSERT_NO_FATAL_FAILURE(InitState());
1794 ASSERT_NO_FATAL_FAILURE(InitViewport());
1795 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1796
1797 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001798 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1799 ds_type_count.descriptorCount = 1;
Tobin Ehlise2194862015-11-04 13:30:34 -07001800
1801 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001802 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1803 ds_pool_ci.pNext = NULL;
1804 ds_pool_ci.maxSets = 1;
1805 ds_pool_ci.poolSizeCount = 1;
1806 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise2194862015-11-04 13:30:34 -07001807
1808 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001809 err =
1810 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise2194862015-11-04 13:30:34 -07001811 ASSERT_VK_SUCCESS(err);
1812
1813 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001814 dsl_binding.binding = 0;
1815 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1816 dsl_binding.descriptorCount = 1;
1817 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1818 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise2194862015-11-04 13:30:34 -07001819
1820 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001821 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1822 ds_layout_ci.pNext = NULL;
1823 ds_layout_ci.bindingCount = 1;
1824 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise2194862015-11-04 13:30:34 -07001825 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001826 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
1827 &ds_layout);
Tobin Ehlise2194862015-11-04 13:30:34 -07001828 ASSERT_VK_SUCCESS(err);
1829
1830 VkDescriptorSet descriptorSet;
1831 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08001832 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07001833 alloc_info.descriptorSetCount = 1;
Tobin Ehlise2194862015-11-04 13:30:34 -07001834 alloc_info.descriptorPool = ds_pool;
1835 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001836 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
1837 &descriptorSet);
Tobin Ehlise2194862015-11-04 13:30:34 -07001838 ASSERT_VK_SUCCESS(err);
1839
1840 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001841 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1842 pipeline_layout_ci.pNext = NULL;
1843 pipeline_layout_ci.setLayoutCount = 1;
1844 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise2194862015-11-04 13:30:34 -07001845
1846 VkPipelineLayout pipeline_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001847 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
1848 &pipeline_layout);
Tobin Ehlise2194862015-11-04 13:30:34 -07001849 ASSERT_VK_SUCCESS(err);
1850
1851 // Create a buffer to update the descriptor with
1852 uint32_t qfi = 0;
1853 VkBufferCreateInfo buffCI = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001854 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1855 buffCI.size = 1024;
1856 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1857 buffCI.queueFamilyIndexCount = 1;
1858 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlise2194862015-11-04 13:30:34 -07001859
1860 VkBuffer dyub;
1861 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
1862 ASSERT_VK_SUCCESS(err);
1863 // Correctly update descriptor to avoid "NOT_UPDATED" error
1864 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001865 buffInfo.buffer = dyub;
1866 buffInfo.offset = 0;
1867 buffInfo.range = 1024;
Tobin Ehlise2194862015-11-04 13:30:34 -07001868
1869 VkWriteDescriptorSet descriptor_write;
1870 memset(&descriptor_write, 0, sizeof(descriptor_write));
1871 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1872 descriptor_write.dstSet = descriptorSet;
1873 descriptor_write.dstBinding = 0;
1874 descriptor_write.descriptorCount = 1;
1875 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1876 descriptor_write.pBufferInfo = &buffInfo;
1877
1878 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1879
1880 BeginCommandBuffer();
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001881 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
1882 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
1883 1, &descriptorSet, 0, NULL);
Tobin Ehlisea975962015-12-17 11:48:42 -07001884 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001885 FAIL() << "Error received was not 'descriptorSet #0 (0x<ADDR>) "
1886 "requires 1 dynamicOffsets, but only 0 dynamicOffsets are "
1887 "left in pDynamicOffsets array...'";
Tobin Ehlisea975962015-12-17 11:48:42 -07001888 m_errorMonitor->DumpFailureMsgs();
1889 }
1890 uint32_t pDynOff[2] = {512, 756};
1891 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001892 m_errorMonitor->SetDesiredFailureMsg(
1893 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisea975962015-12-17 11:48:42 -07001894 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001895 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
1896 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
1897 1, &descriptorSet, 2, pDynOff);
Tobin Ehlise2194862015-11-04 13:30:34 -07001898 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001899 FAIL() << "Error received was not 'Attempting to bind 1 descriptorSets "
1900 "with 1 dynamic descriptors, but dynamicOffsetCount is 0...'";
Tobin Ehlise2194862015-11-04 13:30:34 -07001901 m_errorMonitor->DumpFailureMsgs();
1902 }
Tobin Ehlisea975962015-12-17 11:48:42 -07001903 // Finally cause error due to dynamicOffset being too big
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001904 m_errorMonitor->SetDesiredFailureMsg(
1905 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisea975962015-12-17 11:48:42 -07001906 " from its update, this oversteps its buffer (");
1907 // Create PSO to be used for draw-time errors below
1908 char const *vsSource =
Tony Barbour19b5f922016-01-05 13:37:45 -07001909 "#version 400\n"
Tobin Ehlisea975962015-12-17 11:48:42 -07001910 "#extension GL_ARB_separate_shader_objects: require\n"
1911 "#extension GL_ARB_shading_language_420pack: require\n"
1912 "\n"
Tony Barbour19b5f922016-01-05 13:37:45 -07001913 "out gl_PerVertex { \n"
1914 " vec4 gl_Position;\n"
1915 "};\n"
Tobin Ehlisea975962015-12-17 11:48:42 -07001916 "void main(){\n"
1917 " gl_Position = vec4(1);\n"
1918 "}\n";
1919 char const *fsSource =
Tony Barbour19b5f922016-01-05 13:37:45 -07001920 "#version 400\n"
Tobin Ehlisea975962015-12-17 11:48:42 -07001921 "#extension GL_ARB_separate_shader_objects: require\n"
1922 "#extension GL_ARB_shading_language_420pack: require\n"
1923 "\n"
1924 "layout(location=0) out vec4 x;\n"
1925 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
1926 "void main(){\n"
1927 " x = vec4(bar.y);\n"
1928 "}\n";
1929 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
1930 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
1931 VkPipelineObj pipe(m_device);
1932 pipe.AddShader(&vs);
1933 pipe.AddShader(&fs);
1934 pipe.AddColorAttachment();
1935 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1936
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001937 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
1938 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1939 // This update should succeed, but offset size of 512 will overstep buffer
1940 // /w range 1024 & size 1024
1941 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
1942 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
1943 1, &descriptorSet, 1, pDynOff);
Tobin Ehlisea975962015-12-17 11:48:42 -07001944 Draw(1, 0, 0, 0);
1945 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07001946 FAIL() << "Error received was not 'VkDescriptorSet (0x<ADDR>) bound as "
1947 "set #0 has dynamic offset 512. Combined with offet 0 and "
1948 "range 1024 from its update, this oversteps...'";
Tobin Ehlisea975962015-12-17 11:48:42 -07001949 m_errorMonitor->DumpFailureMsgs();
1950 }
Tobin Ehlise2194862015-11-04 13:30:34 -07001951
1952 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1953 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1954}
1955
Tobin Ehlisb3302332016-02-17 10:35:18 -07001956TEST_F(VkLayerTest, InvalidPushConstants) {
1957 // Hit push constant error cases:
1958 // 1. Create PipelineLayout where push constant overstep maxPushConstantSize
1959 // 2. Incorrectly set push constant size to 0
1960 // 3. Incorrectly set push constant size to non-multiple of 4
1961 // 4. Attempt push constant update that exceeds maxPushConstantSize
1962 VkResult err;
1963 m_errorMonitor->SetDesiredFailureMsg(
1964 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1965 "vkCreatePipelineLayout() call has push constants with offset ");
1966
1967 ASSERT_NO_FATAL_FAILURE(InitState());
1968 ASSERT_NO_FATAL_FAILURE(InitViewport());
1969 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1970
1971 VkPushConstantRange pc_range = {};
1972 pc_range.size = 0xFFFFFFFFu;
1973 pc_range.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
1974 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1975 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1976 pipeline_layout_ci.pushConstantRangeCount = 1;
1977 pipeline_layout_ci.pPushConstantRanges = &pc_range;
1978
1979 VkPipelineLayout pipeline_layout;
1980 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
1981 &pipeline_layout);
1982
1983 if (!m_errorMonitor->DesiredMsgFound()) {
1984 FAIL() << "Error received was not 'vkCreatePipelineLayout() call has "
1985 "push constants with offset 0...'";
1986 m_errorMonitor->DumpFailureMsgs();
1987 }
1988 // Now cause errors due to size 0 and non-4 byte aligned size
1989 pc_range.size = 0;
1990 m_errorMonitor->SetDesiredFailureMsg(
1991 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1992 "vkCreatePipelineLayout() call has push constant index 0 with size 0");
1993 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
1994 &pipeline_layout);
1995 if (!m_errorMonitor->DesiredMsgFound()) {
1996 FAIL() << "Error received was not 'vkCreatePipelineLayout() call has "
1997 "push constant index 0 with size 0...'";
1998 m_errorMonitor->DumpFailureMsgs();
1999 }
2000 pc_range.size = 1;
2001 m_errorMonitor->SetDesiredFailureMsg(
2002 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2003 "vkCreatePipelineLayout() call has push constant index 0 with size 1");
2004 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2005 &pipeline_layout);
2006 if (!m_errorMonitor->DesiredMsgFound()) {
2007 FAIL() << "Error received was not 'vkCreatePipelineLayout() call has "
2008 "push constant index 0 with size 0...'";
2009 m_errorMonitor->DumpFailureMsgs();
2010 }
2011 // Cause error due to bad size in vkCmdPushConstants() call
2012 m_errorMonitor->SetDesiredFailureMsg(
2013 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2014 "vkCmdPushConstants() call has push constants with offset ");
2015 pipeline_layout_ci.pushConstantRangeCount = 0;
2016 pipeline_layout_ci.pPushConstantRanges = NULL;
2017 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2018 &pipeline_layout);
2019 ASSERT_VK_SUCCESS(err);
2020 BeginCommandBuffer();
2021 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
2022 VK_SHADER_STAGE_VERTEX_BIT, 0, 0xFFFFFFFFu, NULL);
2023 if (!m_errorMonitor->DesiredMsgFound()) {
2024 FAIL() << "Error received was not 'vkCmdPushConstants() call has push "
2025 "constants with offset 0...'";
2026 m_errorMonitor->DumpFailureMsgs();
2027 }
2028 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2029}
2030
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002031TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis982099b2015-11-05 09:52:49 -07002032 // Test various desriptorSet errors with bad binding combinations
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002033 VkResult err;
Tobin Ehlis982099b2015-11-05 09:52:49 -07002034
2035 ASSERT_NO_FATAL_FAILURE(InitState());
2036 ASSERT_NO_FATAL_FAILURE(InitViewport());
2037 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2038
2039 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
2040 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002041 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2042 ds_type_count[0].descriptorCount = 10;
2043 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
2044 ds_type_count[1].descriptorCount = 2;
2045 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
2046 ds_type_count[2].descriptorCount = 2;
2047 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
2048 ds_type_count[3].descriptorCount = 5;
2049 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
2050 // type
2051 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
2052 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
2053 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis982099b2015-11-05 09:52:49 -07002054
2055 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002056 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2057 ds_pool_ci.pNext = NULL;
2058 ds_pool_ci.maxSets = 5;
2059 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
2060 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis982099b2015-11-05 09:52:49 -07002061
2062 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002063 err =
2064 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002065 ASSERT_VK_SUCCESS(err);
2066
2067 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
2068 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002069 dsl_binding[0].binding = 0;
2070 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2071 dsl_binding[0].descriptorCount = 5;
2072 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
2073 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis982099b2015-11-05 09:52:49 -07002074
Tobin Ehliscb085292015-12-01 09:57:09 -07002075 // Create layout identical to set0 layout but w/ different stageFlags
2076 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002077 dsl_fs_stage_only.binding = 0;
2078 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2079 dsl_fs_stage_only.descriptorCount = 5;
2080 dsl_fs_stage_only.stageFlags =
2081 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
2082 // bind time
2083 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis982099b2015-11-05 09:52:49 -07002084 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002085 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2086 ds_layout_ci.pNext = NULL;
2087 ds_layout_ci.bindingCount = 1;
2088 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis982099b2015-11-05 09:52:49 -07002089 static const uint32_t NUM_LAYOUTS = 4;
2090 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehliscb085292015-12-01 09:57:09 -07002091 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002092 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
2093 // layout for error case
2094 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2095 &ds_layout[0]);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002096 ASSERT_VK_SUCCESS(err);
Jon Ashburnadb61352015-12-30 18:01:16 -07002097 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002098 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2099 &ds_layout_fs_only);
Tobin Ehliscb085292015-12-01 09:57:09 -07002100 ASSERT_VK_SUCCESS(err);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002101 dsl_binding[0].binding = 0;
2102 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehliscb085292015-12-01 09:57:09 -07002103 dsl_binding[0].descriptorCount = 2;
Mike Stroyand87d28b2016-01-06 14:14:17 -07002104 dsl_binding[1].binding = 1;
2105 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
2106 dsl_binding[1].descriptorCount = 2;
2107 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
2108 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburnadb61352015-12-30 18:01:16 -07002109 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis982099b2015-11-05 09:52:49 -07002110 ds_layout_ci.bindingCount = 2;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002111 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2112 &ds_layout[1]);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002113 ASSERT_VK_SUCCESS(err);
2114 dsl_binding[0].binding = 0;
2115 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehliscb085292015-12-01 09:57:09 -07002116 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis982099b2015-11-05 09:52:49 -07002117 ds_layout_ci.bindingCount = 1;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002118 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2119 &ds_layout[2]);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002120 ASSERT_VK_SUCCESS(err);
2121 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehliscb085292015-12-01 09:57:09 -07002122 dsl_binding[0].descriptorCount = 2;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002123 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2124 &ds_layout[3]);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002125 ASSERT_VK_SUCCESS(err);
2126
2127 static const uint32_t NUM_SETS = 4;
2128 VkDescriptorSet descriptorSet[NUM_SETS] = {};
2129 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehliscb085292015-12-01 09:57:09 -07002130 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07002131 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis982099b2015-11-05 09:52:49 -07002132 alloc_info.descriptorPool = ds_pool;
2133 alloc_info.pSetLayouts = ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002134 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2135 descriptorSet);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002136 ASSERT_VK_SUCCESS(err);
Tobin Ehliscb085292015-12-01 09:57:09 -07002137 VkDescriptorSet ds0_fs_only = {};
Jon Ashburna4ae48b2016-01-11 13:12:43 -07002138 alloc_info.descriptorSetCount = 1;
Tobin Ehliscb085292015-12-01 09:57:09 -07002139 alloc_info.pSetLayouts = &ds_layout_fs_only;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002140 err =
2141 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehliscb085292015-12-01 09:57:09 -07002142 ASSERT_VK_SUCCESS(err);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002143
2144 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002145 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2146 pipeline_layout_ci.pNext = NULL;
2147 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
2148 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis982099b2015-11-05 09:52:49 -07002149
2150 VkPipelineLayout pipeline_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002151 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2152 &pipeline_layout);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002153 ASSERT_VK_SUCCESS(err);
Tobin Ehliscb085292015-12-01 09:57:09 -07002154 // Create pipelineLayout with only one setLayout
2155 pipeline_layout_ci.setLayoutCount = 1;
2156 VkPipelineLayout single_pipe_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002157 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2158 &single_pipe_layout);
Tobin Ehliscb085292015-12-01 09:57:09 -07002159 ASSERT_VK_SUCCESS(err);
2160 // Create pipelineLayout with 2 descriptor setLayout at index 0
2161 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
2162 VkPipelineLayout pipe_layout_one_desc;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002163 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2164 &pipe_layout_one_desc);
Tobin Ehliscb085292015-12-01 09:57:09 -07002165 ASSERT_VK_SUCCESS(err);
2166 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
2167 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
2168 VkPipelineLayout pipe_layout_five_samp;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002169 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2170 &pipe_layout_five_samp);
Tobin Ehliscb085292015-12-01 09:57:09 -07002171 ASSERT_VK_SUCCESS(err);
2172 // Create pipelineLayout with UB type, but stageFlags for FS only
2173 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
2174 VkPipelineLayout pipe_layout_fs_only;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002175 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2176 &pipe_layout_fs_only);
Tobin Ehliscb085292015-12-01 09:57:09 -07002177 ASSERT_VK_SUCCESS(err);
2178 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
2179 VkDescriptorSetLayout pl_bad_s0[2] = {};
2180 pl_bad_s0[0] = ds_layout_fs_only;
2181 pl_bad_s0[1] = ds_layout[1];
2182 pipeline_layout_ci.setLayoutCount = 2;
2183 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
2184 VkPipelineLayout pipe_layout_bad_set0;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002185 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2186 &pipe_layout_bad_set0);
Tobin Ehliscb085292015-12-01 09:57:09 -07002187 ASSERT_VK_SUCCESS(err);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002188
2189 // Create a buffer to update the descriptor with
2190 uint32_t qfi = 0;
2191 VkBufferCreateInfo buffCI = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002192 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2193 buffCI.size = 1024;
2194 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
2195 buffCI.queueFamilyIndexCount = 1;
2196 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis982099b2015-11-05 09:52:49 -07002197
2198 VkBuffer dyub;
2199 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
2200 ASSERT_VK_SUCCESS(err);
2201 // Correctly update descriptor to avoid "NOT_UPDATED" error
2202 static const uint32_t NUM_BUFFS = 5;
2203 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002204 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis982099b2015-11-05 09:52:49 -07002205 buffInfo[i].buffer = dyub;
2206 buffInfo[i].offset = 0;
2207 buffInfo[i].range = 1024;
2208 }
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002209 VkImage image;
2210 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2211 const int32_t tex_width = 32;
2212 const int32_t tex_height = 32;
Tobin Ehliscb085292015-12-01 09:57:09 -07002213 VkImageCreateInfo image_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002214 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2215 image_create_info.pNext = NULL;
2216 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2217 image_create_info.format = tex_format;
2218 image_create_info.extent.width = tex_width;
2219 image_create_info.extent.height = tex_height;
2220 image_create_info.extent.depth = 1;
2221 image_create_info.mipLevels = 1;
2222 image_create_info.arrayLayers = 1;
2223 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2224 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2225 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2226 image_create_info.flags = 0;
Tobin Ehliscb085292015-12-01 09:57:09 -07002227 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2228 ASSERT_VK_SUCCESS(err);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002229
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002230 VkMemoryRequirements memReqs;
2231 VkDeviceMemory imageMem;
2232 bool pass;
Mike Stroyand87d28b2016-01-06 14:14:17 -07002233 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002234 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2235 memAlloc.pNext = NULL;
2236 memAlloc.allocationSize = 0;
2237 memAlloc.memoryTypeIndex = 0;
Mike Stroyand87d28b2016-01-06 14:14:17 -07002238 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
2239 memAlloc.allocationSize = memReqs.size;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002240 pass =
2241 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyand87d28b2016-01-06 14:14:17 -07002242 ASSERT_TRUE(pass);
2243 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
2244 ASSERT_VK_SUCCESS(err);
2245 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
2246 ASSERT_VK_SUCCESS(err);
2247
Tobin Ehliscb085292015-12-01 09:57:09 -07002248 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002249 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2250 image_view_create_info.image = image;
2251 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
2252 image_view_create_info.format = tex_format;
2253 image_view_create_info.subresourceRange.layerCount = 1;
2254 image_view_create_info.subresourceRange.baseMipLevel = 0;
2255 image_view_create_info.subresourceRange.levelCount = 1;
2256 image_view_create_info.subresourceRange.aspectMask =
2257 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis982099b2015-11-05 09:52:49 -07002258
Tobin Ehliscb085292015-12-01 09:57:09 -07002259 VkImageView view;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002260 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
2261 &view);
Tobin Ehliscb085292015-12-01 09:57:09 -07002262 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2280f522016-01-06 08:48:41 -07002263 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehliscb085292015-12-01 09:57:09 -07002264 imageInfo[0].imageView = view;
2265 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2266 imageInfo[1].imageView = view;
2267 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis2280f522016-01-06 08:48:41 -07002268 imageInfo[2].imageView = view;
2269 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
2270 imageInfo[3].imageView = view;
2271 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehliscb085292015-12-01 09:57:09 -07002272
2273 static const uint32_t NUM_SET_UPDATES = 3;
2274 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
2275 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2276 descriptor_write[0].dstSet = descriptorSet[0];
2277 descriptor_write[0].dstBinding = 0;
2278 descriptor_write[0].descriptorCount = 5;
2279 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2280 descriptor_write[0].pBufferInfo = buffInfo;
2281 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2282 descriptor_write[1].dstSet = descriptorSet[1];
2283 descriptor_write[1].dstBinding = 0;
2284 descriptor_write[1].descriptorCount = 2;
2285 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
2286 descriptor_write[1].pImageInfo = imageInfo;
2287 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2288 descriptor_write[2].dstSet = descriptorSet[1];
2289 descriptor_write[2].dstBinding = 1;
2290 descriptor_write[2].descriptorCount = 2;
2291 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis2280f522016-01-06 08:48:41 -07002292 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehliscb085292015-12-01 09:57:09 -07002293
2294 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002295
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002296 // Create PSO to be used for draw-time errors below
2297 char const *vsSource =
Tony Barbour19b5f922016-01-05 13:37:45 -07002298 "#version 400\n"
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002299 "#extension GL_ARB_separate_shader_objects: require\n"
2300 "#extension GL_ARB_shading_language_420pack: require\n"
2301 "\n"
Tony Barbour19b5f922016-01-05 13:37:45 -07002302 "out gl_PerVertex {\n"
2303 " vec4 gl_Position;\n"
2304 "};\n"
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002305 "void main(){\n"
2306 " gl_Position = vec4(1);\n"
2307 "}\n";
2308 char const *fsSource =
Tony Barbour19b5f922016-01-05 13:37:45 -07002309 "#version 400\n"
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002310 "#extension GL_ARB_separate_shader_objects: require\n"
2311 "#extension GL_ARB_shading_language_420pack: require\n"
2312 "\n"
2313 "layout(location=0) out vec4 x;\n"
2314 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
2315 "void main(){\n"
2316 " x = vec4(bar.y);\n"
2317 "}\n";
2318 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2319 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002320 VkPipelineObj pipe(m_device);
2321 pipe.AddShader(&vs);
2322 pipe.AddShader(&fs);
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002323 pipe.AddColorAttachment();
2324 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis982099b2015-11-05 09:52:49 -07002325
2326 BeginCommandBuffer();
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002327
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002328 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2329 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2330 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
2331 // of PSO
2332 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
2333 // cmd_pipeline.c
2334 // due to the fact that cmd_alloc_dset_data() has not been called in
2335 // cmd_bind_graphics_pipeline()
2336 // TODO : Want to cause various binding incompatibility issues here to test
2337 // DrawState
Tobin Ehlis982099b2015-11-05 09:52:49 -07002338 // First cause various verify_layout_compatibility() fails
2339 // Second disturb early and late sets and verify INFO msgs
Tobin Ehliscb085292015-12-01 09:57:09 -07002340 // verify_set_layout_compatibility fail cases:
2341 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2343 " due to: invalid VkPipelineLayout ");
2344 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2345 VK_PIPELINE_BIND_POINT_GRAPHICS,
2346 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
2347 &descriptorSet[0], 0, NULL);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002348 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002349 FAIL() << "Did not receive correct error msg when attempting to bind "
2350 "descriptorSets with invalid VkPipelineLayout.";
Tobin Ehlis982099b2015-11-05 09:52:49 -07002351 m_errorMonitor->DumpFailureMsgs();
2352 }
Tobin Ehliscb085292015-12-01 09:57:09 -07002353 // 2. layoutIndex exceeds # of layouts in layout
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2355 " attempting to bind set to index 1");
2356 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2357 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
2358 0, 2, &descriptorSet[0], 0, NULL);
Tobin Ehliscb085292015-12-01 09:57:09 -07002359 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002360 FAIL() << "Did not receive correct error msg when attempting to bind "
2361 "descriptorSet to index 1 when pipelineLayout only has index "
2362 "0.";
Tobin Ehliscb085292015-12-01 09:57:09 -07002363 m_errorMonitor->DumpFailureMsgs();
2364 }
2365 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002366 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
2367 // descriptors
2368 m_errorMonitor->SetDesiredFailureMsg(
2369 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2370 ", but corresponding set being bound has 5 descriptors.");
2371 vkCmdBindDescriptorSets(
2372 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
2373 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
Tobin Ehliscb085292015-12-01 09:57:09 -07002374 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002375 FAIL() << "Did not receive correct error msg when attempting to bind "
2376 "descriptorSet w/ 5 descriptors to pipelineLayout with only "
2377 "2 descriptors.";
Tobin Ehliscb085292015-12-01 09:57:09 -07002378 m_errorMonitor->DumpFailureMsgs();
2379 }
2380 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
2381 // 4. same # of descriptors but mismatch in type
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002382 m_errorMonitor->SetDesiredFailureMsg(
2383 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2384 " descriptor from pipelineLayout is type 'VK_DESCRIPTOR_TYPE_SAMPLER'");
2385 vkCmdBindDescriptorSets(
2386 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
2387 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
Tobin Ehliscb085292015-12-01 09:57:09 -07002388 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002389 FAIL() << "Did not receive correct error msg when attempting to bind "
2390 "UNIFORM_BUFFER descriptorSet to pipelineLayout with "
2391 "overlapping SAMPLER type.";
Tobin Ehliscb085292015-12-01 09:57:09 -07002392 m_errorMonitor->DumpFailureMsgs();
2393 }
2394 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
2395 // 5. same # of descriptors but mismatch in stageFlags
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002396 m_errorMonitor->SetDesiredFailureMsg(
2397 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2398 " descriptor from pipelineLayout has stageFlags ");
2399 vkCmdBindDescriptorSets(
2400 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
2401 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
Tobin Ehliscb085292015-12-01 09:57:09 -07002402 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002403 FAIL() << "Did not receive correct error msg when attempting to bind "
2404 "UNIFORM_BUFFER descriptorSet with ALL stageFlags to "
2405 "pipelineLayout with FS-only stageFlags.";
Tobin Ehliscb085292015-12-01 09:57:09 -07002406 m_errorMonitor->DumpFailureMsgs();
2407 }
2408 // Cause INFO messages due to disturbing previously bound Sets
2409 // First bind sets 0 & 1
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002410 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2411 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
2412 2, &descriptorSet[0], 0, NULL);
Tobin Ehliscb085292015-12-01 09:57:09 -07002413 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002414 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski5c13d4d2016-02-11 09:26:16 -07002415 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002416 " previously bound as set #0 was disturbed ");
2417 vkCmdBindDescriptorSets(
2418 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
2419 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Tobin Ehliscb085292015-12-01 09:57:09 -07002420 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002421 FAIL() << "Did not receive correct info msg when binding Set1 w/ "
2422 "pipelineLayout that should disturb Set0.";
Tobin Ehliscb085292015-12-01 09:57:09 -07002423 m_errorMonitor->DumpFailureMsgs();
2424 }
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002425 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2426 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
2427 2, &descriptorSet[0], 0, NULL);
Tobin Ehliscb085292015-12-01 09:57:09 -07002428 // 2. Disturb set after last bound set
Mark Lobodzinski5c13d4d2016-02-11 09:26:16 -07002429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002430 " newly bound as set #0 so set #1 and "
2431 "any subsequent sets were disturbed ");
2432 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2433 VK_PIPELINE_BIND_POINT_GRAPHICS,
2434 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
Tobin Ehliscb085292015-12-01 09:57:09 -07002435 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002436 FAIL() << "Did not receive correct info msg when re-binding Set0 w/ "
2437 "pipelineLayout that should disturb Set1.";
Tobin Ehliscb085292015-12-01 09:57:09 -07002438 m_errorMonitor->DumpFailureMsgs();
2439 }
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002440 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002441 // 1. Error due to not binding required set (we actually use same code as
2442 // above to disturb set0)
2443 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2444 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
2445 2, &descriptorSet[0], 0, NULL);
2446 vkCmdBindDescriptorSets(
2447 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
2448 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
2449 m_errorMonitor->SetDesiredFailureMsg(
2450 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2451 " uses set #0 but that set is not bound.");
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002452 Draw(1, 0, 0, 0);
2453 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002454 FAIL() << "Did not receive correct error msg when attempting draw "
2455 "requiring Set0 but Set0 is not bound.";
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002456 m_errorMonitor->DumpFailureMsgs();
2457 }
Tobin Ehlis2280f522016-01-06 08:48:41 -07002458 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002459 // 2. Error due to bound set not being compatible with PSO's
2460 // VkPipelineLayout (diff stageFlags in this case)
2461 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
2462 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
2463 2, &descriptorSet[0], 0, NULL);
2464 m_errorMonitor->SetDesiredFailureMsg(
2465 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2466 " bound as set #0 is not compatible with ");
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002467 Draw(1, 0, 0, 0);
2468 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002469 FAIL() << "Did not receive correct error msg when attempted draw where "
2470 "bound Set0 layout is not compatible PSO Set0 layout.";
Tobin Ehlisd17c28c2015-12-03 09:40:56 -07002471 m_errorMonitor->DumpFailureMsgs();
2472 }
Tobin Ehliscb085292015-12-01 09:57:09 -07002473 // Remaining clean-up
2474 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002475 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehliscb085292015-12-01 09:57:09 -07002476 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
2477 }
2478 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
2479 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, descriptorSet);
2480 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis982099b2015-11-05 09:52:49 -07002481 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2482 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
2483}
Tobin Ehlis982099b2015-11-05 09:52:49 -07002484
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002485TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002486
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002487 m_errorMonitor->SetDesiredFailureMsg(
2488 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002489 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlis254eca02015-06-25 15:46:59 -06002490
2491 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +08002492 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002493 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu1f851912015-10-27 18:04:07 +08002494 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002495
2496 if (!m_errorMonitor->DesiredMsgFound()) {
Eric Engestrom9bdcb232016-04-02 22:08:10 +01002497 FAIL() << "Did not receive Error 'You must call vkBeginCommandBuffer() "
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002498 "before this call to vkEndCommandBuffer()'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002499 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06002500 }
2501}
2502
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002503TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
2504 VkResult err;
2505 VkCommandBuffer draw_cmd;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002506
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002507 m_errorMonitor->SetDesiredFailureMsg(
2508 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisb51cb782015-12-16 08:19:42 -07002509 " must specify a valid renderpass parameter.");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002510
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002511 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002512
Chia-I Wu1f851912015-10-27 18:04:07 +08002513 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002514 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06002515 cmd.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002516 cmd.commandPool = m_commandPool;
2517 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07002518 cmd.commandBufferCount = 1;
Cody Northrop10d8f982015-08-04 17:35:57 -06002519
Chia-I Wu1f851912015-10-27 18:04:07 +08002520 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyan2237f522015-08-18 14:40:24 -06002521 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002522
2523 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu1f851912015-10-27 18:04:07 +08002524 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburna4ae48b2016-01-11 13:12:43 -07002525 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu1f851912015-10-27 18:04:07 +08002526 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06002527 cmd_buf_info.pNext = NULL;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002528 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
2529 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07002530 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002531
2532 // The error should be caught by validation of the BeginCommandBuffer call
2533 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
2534
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002535 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002536 FAIL() << "Did not receive Error 'vkBeginCommandBuffer(): Secondary "
2537 "Command Buffers (0x<ADDR>) must specify a valid renderpass "
2538 "parameter.'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002539 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002540 }
Chia-I Wu1f851912015-10-27 18:04:07 +08002541 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002542}
2543
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002544TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002545 // Cause error due to Begin while recording CB
2546 // Then cause 2 errors for attempting to reset CB w/o having
2547 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
2548 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002550 "Cannot call Begin on CB");
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002551
2552 ASSERT_NO_FATAL_FAILURE(InitState());
2553
2554 // Calls AllocateCommandBuffers
2555 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
2556
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002557 // Force the failure by setting the Renderpass and Framebuffer fields with
2558 // (fake) data
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002559 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburna4ae48b2016-01-11 13:12:43 -07002560 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002561 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2562 cmd_buf_info.pNext = NULL;
2563 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07002564 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002565
2566 // Begin CB to transition to recording state
2567 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2568 // Can't re-begin. This should trigger error
2569 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2570 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002571 FAIL() << "Did not receive Error 'Cannot call Begin on CB (0x<ADDR>) "
2572 "in the RECORDING state...'";
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002573 m_errorMonitor->DumpFailureMsgs();
2574 }
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2576 "Attempt to reset command buffer ");
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002577 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
2578 // Reset attempt will trigger error due to incorrect CommandPool state
2579 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
2580 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002581 FAIL() << "Did not receive Error 'Attempt to reset command buffer "
2582 "(0x<ADDR>) created from command pool...'";
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002583 m_errorMonitor->DumpFailureMsgs();
2584 }
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002585 m_errorMonitor->SetDesiredFailureMsg(
2586 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2587 " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002588 // Transition CB to RECORDED state
2589 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
2590 // Now attempting to Begin will implicitly reset, which triggers error
2591 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
2592 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002593 FAIL() << "Did not receive Error 'Call to vkBeginCommandBuffer() on "
2594 "command buffer (0x<ADDR>) attempts to implicitly reset...'";
Tobin Ehlis4c8381e2015-12-14 13:46:38 -07002595 m_errorMonitor->DumpFailureMsgs();
2596 }
2597}
2598
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002599TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlis254eca02015-06-25 15:46:59 -06002600 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002601 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002602
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002603 m_errorMonitor->SetDesiredFailureMsg(
2604 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002605 "Invalid Pipeline CreateInfo State: Vtx Shader required");
2606
Tobin Ehlis254eca02015-06-25 15:46:59 -06002607 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002608 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002609
Chia-I Wuc51b1212015-10-27 19:25:11 +08002610 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002611 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2612 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002613
2614 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002615 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2616 ds_pool_ci.pNext = NULL;
2617 ds_pool_ci.maxSets = 1;
2618 ds_pool_ci.poolSizeCount = 1;
2619 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002620
Tobin Ehlis254eca02015-06-25 15:46:59 -06002621 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002622 err =
2623 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002624 ASSERT_VK_SUCCESS(err);
2625
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002626 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002627 dsl_binding.binding = 0;
2628 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2629 dsl_binding.descriptorCount = 1;
2630 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2631 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002632
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002633 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002634 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2635 ds_layout_ci.pNext = NULL;
2636 ds_layout_ci.bindingCount = 1;
2637 ds_layout_ci.pBindings = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002638
Tobin Ehlis254eca02015-06-25 15:46:59 -06002639 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002640 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2641 &ds_layout);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002642 ASSERT_VK_SUCCESS(err);
2643
2644 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002645 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002646 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07002647 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002648 alloc_info.descriptorPool = ds_pool;
2649 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002650 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2651 &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002652 ASSERT_VK_SUCCESS(err);
2653
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002654 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002655 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2656 pipeline_layout_ci.setLayoutCount = 1;
2657 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002658
2659 VkPipelineLayout pipeline_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002660 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2661 &pipeline_layout);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002662 ASSERT_VK_SUCCESS(err);
2663
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002664 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002665 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002666
2667 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002668 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2669 vp_state_ci.scissorCount = 1;
2670 vp_state_ci.pScissors = &sc;
2671 vp_state_ci.viewportCount = 1;
2672 vp_state_ci.pViewports = &vp;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002673
Karl Schultzfc86ab72016-03-08 10:30:21 -07002674 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
2675 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
2676 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
2677 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
2678 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
2679 rs_state_ci.depthClampEnable = VK_FALSE;
2680 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
2681 rs_state_ci.depthBiasEnable = VK_FALSE;
2682
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002683 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002684 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2685 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzfc86ab72016-03-08 10:30:21 -07002686 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002687 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2688 gp_ci.layout = pipeline_layout;
2689 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002690
2691 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002692 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2693 pc_ci.initialDataSize = 0;
2694 pc_ci.pInitialData = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002695
2696 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06002697 VkPipelineCache pipelineCache;
2698
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002699 err =
2700 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06002701 ASSERT_VK_SUCCESS(err);
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002702 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
2703 &gp_ci, NULL, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002704
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002705 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002706 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: "
2707 "Vtx Shader required'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002708 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06002709 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002710
Chia-I Wu69f40122015-10-26 21:10:41 +08002711 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2712 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2713 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2714 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002715}
Tobin Ehlis20693172015-09-17 08:46:18 -06002716/*// TODO : This test should be good, but needs Tess support in compiler to run
2717TEST_F(VkLayerTest, InvalidPatchControlPoints)
2718{
2719 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis20693172015-09-17 08:46:18 -06002720 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002721
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07002722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002723 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
2724primitive ");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002725
Tobin Ehlis20693172015-09-17 08:46:18 -06002726 ASSERT_NO_FATAL_FAILURE(InitState());
2727 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis20693172015-09-17 08:46:18 -06002728
Chia-I Wuc51b1212015-10-27 19:25:11 +08002729 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis20693172015-09-17 08:46:18 -06002730 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002731 ds_type_count.descriptorCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002732
2733 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2734 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2735 ds_pool_ci.pNext = NULL;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002736 ds_pool_ci.poolSizeCount = 1;
2737 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis20693172015-09-17 08:46:18 -06002738
2739 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002740 err = vkCreateDescriptorPool(m_device->device(),
2741VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis20693172015-09-17 08:46:18 -06002742 ASSERT_VK_SUCCESS(err);
2743
2744 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002745 dsl_binding.binding = 0;
Tobin Ehlis20693172015-09-17 08:46:18 -06002746 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002747 dsl_binding.descriptorCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002748 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2749 dsl_binding.pImmutableSamplers = NULL;
2750
2751 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002752 ds_layout_ci.sType =
2753VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis20693172015-09-17 08:46:18 -06002754 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002755 ds_layout_ci.bindingCount = 1;
Jon Ashburnadb61352015-12-30 18:01:16 -07002756 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis20693172015-09-17 08:46:18 -06002757
2758 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002759 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2760&ds_layout);
Tobin Ehlis20693172015-09-17 08:46:18 -06002761 ASSERT_VK_SUCCESS(err);
2762
2763 VkDescriptorSet descriptorSet;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002764 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
2765VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis20693172015-09-17 08:46:18 -06002766 ASSERT_VK_SUCCESS(err);
2767
2768 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002769 pipeline_layout_ci.sType =
2770VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis20693172015-09-17 08:46:18 -06002771 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002772 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002773 pipeline_layout_ci.pSetLayouts = &ds_layout;
2774
2775 VkPipelineLayout pipeline_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002776 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2777&pipeline_layout);
Tobin Ehlis20693172015-09-17 08:46:18 -06002778 ASSERT_VK_SUCCESS(err);
2779
2780 VkPipelineShaderStageCreateInfo shaderStages[3];
2781 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
2782
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002783 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
2784this);
Tobin Ehlis20693172015-09-17 08:46:18 -06002785 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002786 VkShaderObj
2787tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
2788this);
2789 VkShaderObj
2790te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
2791this);
Tobin Ehlis20693172015-09-17 08:46:18 -06002792
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002793 shaderStages[0].sType =
2794VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002795 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002796 shaderStages[0].shader = vs.handle();
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002797 shaderStages[1].sType =
2798VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002799 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002800 shaderStages[1].shader = tc.handle();
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002801 shaderStages[2].sType =
2802VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002803 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002804 shaderStages[2].shader = te.handle();
2805
2806 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002807 iaCI.sType =
2808VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08002809 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis20693172015-09-17 08:46:18 -06002810
2811 VkPipelineTessellationStateCreateInfo tsCI = {};
2812 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
2813 tsCI.patchControlPoints = 0; // This will cause an error
2814
2815 VkGraphicsPipelineCreateInfo gp_ci = {};
2816 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2817 gp_ci.pNext = NULL;
2818 gp_ci.stageCount = 3;
2819 gp_ci.pStages = shaderStages;
2820 gp_ci.pVertexInputState = NULL;
2821 gp_ci.pInputAssemblyState = &iaCI;
2822 gp_ci.pTessellationState = &tsCI;
2823 gp_ci.pViewportState = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002824 gp_ci.pRasterizationState = NULL;
Tobin Ehlis20693172015-09-17 08:46:18 -06002825 gp_ci.pMultisampleState = NULL;
2826 gp_ci.pDepthStencilState = NULL;
2827 gp_ci.pColorBlendState = NULL;
2828 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2829 gp_ci.layout = pipeline_layout;
2830 gp_ci.renderPass = renderPass();
2831
2832 VkPipelineCacheCreateInfo pc_ci = {};
2833 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2834 pc_ci.pNext = NULL;
2835 pc_ci.initialSize = 0;
2836 pc_ci.initialData = 0;
2837 pc_ci.maxSize = 0;
2838
2839 VkPipeline pipeline;
2840 VkPipelineCache pipelineCache;
2841
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002842 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
2843&pipelineCache);
Tobin Ehlis20693172015-09-17 08:46:18 -06002844 ASSERT_VK_SUCCESS(err);
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002845 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
2846&gp_ci, NULL, &pipeline);
Tobin Ehlis20693172015-09-17 08:46:18 -06002847
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002848 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002849 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State:
Chris Forbese8aa35e2016-04-04 18:50:38 +12002850VK_PRIMITIVE_TOPOLOGY_PATCHLIST primitive...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002851 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis20693172015-09-17 08:46:18 -06002852 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002853
Chia-I Wu69f40122015-10-26 21:10:41 +08002854 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2855 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2856 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2857 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis20693172015-09-17 08:46:18 -06002858}
2859*/
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002860// Set scissor and viewport counts to different numbers
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002861TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002862 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002863 VkResult err;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002864
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002865 m_errorMonitor->SetDesiredFailureMsg(
2866 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002867 "Gfx Pipeline viewport count (1) must match scissor count (0).");
2868
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002869 ASSERT_NO_FATAL_FAILURE(InitState());
2870 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002871
Chia-I Wuc51b1212015-10-27 19:25:11 +08002872 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002873 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2874 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002875
2876 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002877 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2878 ds_pool_ci.maxSets = 1;
2879 ds_pool_ci.poolSizeCount = 1;
2880 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002881
2882 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002883 err =
2884 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002885 ASSERT_VK_SUCCESS(err);
2886
2887 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002888 dsl_binding.binding = 0;
2889 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2890 dsl_binding.descriptorCount = 1;
2891 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002892
2893 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002894 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2895 ds_layout_ci.bindingCount = 1;
2896 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002897
2898 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002899 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2900 &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002901 ASSERT_VK_SUCCESS(err);
2902
2903 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002904 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08002905 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07002906 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002907 alloc_info.descriptorPool = ds_pool;
2908 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002909 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2910 &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002911 ASSERT_VK_SUCCESS(err);
2912
2913 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002914 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2915 pipeline_layout_ci.setLayoutCount = 1;
2916 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002917
2918 VkPipelineLayout pipeline_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002919 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2920 &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002921 ASSERT_VK_SUCCESS(err);
2922
2923 VkViewport vp = {}; // Just need dummy vp to point to
2924
2925 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002926 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2927 vp_state_ci.scissorCount = 0;
2928 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2929 vp_state_ci.pViewports = &vp;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002930
Karl Schultzfc86ab72016-03-08 10:30:21 -07002931 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
2932 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
2933 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
2934 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
2935 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
2936 rs_state_ci.depthClampEnable = VK_FALSE;
2937 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
2938 rs_state_ci.depthBiasEnable = VK_FALSE;
2939
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002940 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002941 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002942
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002943 VkShaderObj vs(m_device, bindStateVertShaderText,
2944 VK_SHADER_STAGE_VERTEX_BIT, this);
2945 VkShaderObj fs(m_device, bindStateFragShaderText,
2946 VK_SHADER_STAGE_FRAGMENT_BIT,
2947 this); // TODO - We shouldn't need a fragment shader
2948 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002949 shaderStages[0] = vs.GetStageCreateInfo();
2950 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002951
2952 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002953 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2954 gp_ci.stageCount = 2;
2955 gp_ci.pStages = shaderStages;
2956 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzfc86ab72016-03-08 10:30:21 -07002957 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002958 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2959 gp_ci.layout = pipeline_layout;
2960 gp_ci.renderPass = renderPass();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002961
2962 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002963 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002964
2965 VkPipeline pipeline;
2966 VkPipelineCache pipelineCache;
2967
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002968 err =
2969 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002970 ASSERT_VK_SUCCESS(err);
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002971 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
2972 &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002973
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002974 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002975 FAIL() << "Did not receive Error 'Gfx Pipeline viewport count (1) must "
2976 "match scissor count (0).'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002977 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002978 }
2979
Chia-I Wu69f40122015-10-26 21:10:41 +08002980 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2981 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2982 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2983 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002984}
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002985// Don't set viewport state in PSO. This is an error b/c we always need this
2986// state
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002987// for the counts even if the data is going to be set dynamically.
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002988TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002989 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002990 VkResult err;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002991
Karl Schultz99e9d1d2016-02-02 17:17:23 -07002992 m_errorMonitor->SetDesiredFailureMsg(
2993 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002994 "Gfx Pipeline pViewportState is null. Even if ");
2995
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002996 ASSERT_NO_FATAL_FAILURE(InitState());
2997 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002998
Chia-I Wuc51b1212015-10-27 19:25:11 +08002999 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003000 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3001 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003002
3003 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003004 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3005 ds_pool_ci.maxSets = 1;
3006 ds_pool_ci.poolSizeCount = 1;
3007 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003008
3009 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003010 err =
3011 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003012 ASSERT_VK_SUCCESS(err);
3013
3014 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003015 dsl_binding.binding = 0;
3016 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3017 dsl_binding.descriptorCount = 1;
3018 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003019
3020 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003021 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3022 ds_layout_ci.bindingCount = 1;
3023 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003024
3025 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003026 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3027 &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003028 ASSERT_VK_SUCCESS(err);
3029
3030 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003031 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003032 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07003033 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003034 alloc_info.descriptorPool = ds_pool;
3035 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003036 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3037 &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003038 ASSERT_VK_SUCCESS(err);
3039
3040 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003041 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3042 pipeline_layout_ci.setLayoutCount = 1;
3043 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003044
3045 VkPipelineLayout pipeline_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003046 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3047 &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003048 ASSERT_VK_SUCCESS(err);
3049
3050 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
3051 // Set scissor as dynamic to avoid second error
3052 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003053 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
3054 dyn_state_ci.dynamicStateCount = 1;
3055 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003056
Cody Northrop1a0f3e62015-10-05 14:44:45 -06003057 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003058 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003059
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003060 VkShaderObj vs(m_device, bindStateVertShaderText,
3061 VK_SHADER_STAGE_VERTEX_BIT, this);
3062 VkShaderObj fs(m_device, bindStateFragShaderText,
3063 VK_SHADER_STAGE_FRAGMENT_BIT,
3064 this); // TODO - We shouldn't need a fragment shader
3065 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08003066 shaderStages[0] = vs.GetStageCreateInfo();
3067 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003068
Karl Schultzfc86ab72016-03-08 10:30:21 -07003069
3070 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
3071 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
3072 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
3073 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
3074 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
3075 rs_state_ci.depthClampEnable = VK_FALSE;
3076 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
3077 rs_state_ci.depthBiasEnable = VK_FALSE;
3078
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003079 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003080 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
3081 gp_ci.stageCount = 2;
3082 gp_ci.pStages = shaderStages;
Karl Schultzfc86ab72016-03-08 10:30:21 -07003083 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003084 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
3085 // should cause validation error
3086 gp_ci.pDynamicState = &dyn_state_ci;
3087 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
3088 gp_ci.layout = pipeline_layout;
3089 gp_ci.renderPass = renderPass();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003090
3091 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003092 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003093
3094 VkPipeline pipeline;
3095 VkPipelineCache pipelineCache;
3096
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003097 err =
3098 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003099 ASSERT_VK_SUCCESS(err);
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003100 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
3101 &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003102
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003103 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003104 FAIL() << "Did not receive Error 'Gfx Pipeline pViewportState is null. "
3105 "Even if...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003106 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003107 }
3108
Chia-I Wu69f40122015-10-26 21:10:41 +08003109 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
3110 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3111 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3112 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003113}
3114// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003115// Then run second test where dynamic scissor count doesn't match PSO scissor
3116// count
3117TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
3118 VkResult err;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003119
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003120 m_errorMonitor->SetDesiredFailureMsg(
3121 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003122 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
3123
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003124 ASSERT_NO_FATAL_FAILURE(InitState());
3125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003126
Chia-I Wuc51b1212015-10-27 19:25:11 +08003127 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003128 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3129 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003130
3131 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003132 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3133 ds_pool_ci.maxSets = 1;
3134 ds_pool_ci.poolSizeCount = 1;
3135 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003136
3137 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003138 err =
3139 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003140 ASSERT_VK_SUCCESS(err);
3141
3142 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003143 dsl_binding.binding = 0;
3144 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3145 dsl_binding.descriptorCount = 1;
3146 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003147
3148 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003149 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3150 ds_layout_ci.bindingCount = 1;
3151 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003152
3153 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003154 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3155 &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003156 ASSERT_VK_SUCCESS(err);
3157
3158 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003159 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003160 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07003161 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003162 alloc_info.descriptorPool = ds_pool;
3163 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003164 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3165 &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003166 ASSERT_VK_SUCCESS(err);
3167
3168 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003169 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3170 pipeline_layout_ci.setLayoutCount = 1;
3171 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003172
3173 VkPipelineLayout pipeline_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003174 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3175 &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003176 ASSERT_VK_SUCCESS(err);
3177
3178 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003179 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
3180 vp_state_ci.viewportCount = 1;
3181 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
3182 vp_state_ci.scissorCount = 1;
3183 vp_state_ci.pScissors =
3184 NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003185
3186 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
3187 // Set scissor as dynamic to avoid that error
3188 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003189 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
3190 dyn_state_ci.dynamicStateCount = 1;
3191 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003192
Cody Northrop1a0f3e62015-10-05 14:44:45 -06003193 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003194 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003195
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003196 VkShaderObj vs(m_device, bindStateVertShaderText,
3197 VK_SHADER_STAGE_VERTEX_BIT, this);
3198 VkShaderObj fs(m_device, bindStateFragShaderText,
3199 VK_SHADER_STAGE_FRAGMENT_BIT,
3200 this); // TODO - We shouldn't need a fragment shader
3201 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08003202 shaderStages[0] = vs.GetStageCreateInfo();
3203 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003204
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003205 VkPipelineVertexInputStateCreateInfo vi_ci = {};
3206 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
3207 vi_ci.pNext = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08003208 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003209 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08003210 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003211 vi_ci.pVertexAttributeDescriptions = nullptr;
3212
3213 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
3214 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
3215 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
3216
Chia-I Wu1f851912015-10-27 18:04:07 +08003217 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +08003218 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003219 rs_ci.pNext = nullptr;
3220
Mark Young0292df52016-03-31 16:03:20 -06003221 VkPipelineColorBlendAttachmentState att = {};
3222 att.blendEnable = VK_FALSE;
3223 att.colorWriteMask = 0xf;
3224
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003225 VkPipelineColorBlendStateCreateInfo cb_ci = {};
3226 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
3227 cb_ci.pNext = nullptr;
Mark Young0292df52016-03-31 16:03:20 -06003228 cb_ci.attachmentCount = 1;
3229 cb_ci.pAttachments = &att;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06003230
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003231 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003232 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
3233 gp_ci.stageCount = 2;
3234 gp_ci.pStages = shaderStages;
3235 gp_ci.pVertexInputState = &vi_ci;
3236 gp_ci.pInputAssemblyState = &ia_ci;
3237 gp_ci.pViewportState = &vp_state_ci;
3238 gp_ci.pRasterizationState = &rs_ci;
3239 gp_ci.pColorBlendState = &cb_ci;
3240 gp_ci.pDynamicState = &dyn_state_ci;
3241 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
3242 gp_ci.layout = pipeline_layout;
3243 gp_ci.renderPass = renderPass();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003244
3245 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003246 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003247
3248 VkPipeline pipeline;
3249 VkPipelineCache pipelineCache;
3250
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003251 err =
3252 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003253 ASSERT_VK_SUCCESS(err);
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003254 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
3255 &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003256
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003257 if (!m_errorMonitor->DesiredMsgFound()) {
Eric Engestrom9bdcb232016-04-02 22:08:10 +01003258 FAIL() << "Did not receive Error 'Gfx Pipeline viewportCount is 1, but "
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003259 "pViewports is NULL...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003260 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003261 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003262
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003263 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003264 // First need to successfully create the PSO from above by setting
3265 // pViewports
3266 m_errorMonitor->SetDesiredFailureMsg(
3267 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3268 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
3269 "scissorCount is 1. These counts must match.");
3270
3271 VkViewport vp = {}; // Just need dummy vp to point to
3272 vp_state_ci.pViewports = &vp;
3273 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
3274 &gp_ci, NULL, &pipeline);
3275 ASSERT_VK_SUCCESS(err);
3276 BeginCommandBuffer();
3277 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
3278 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
3279 VkRect2D scissors[2] = {}; // don't care about data
3280 // Count of 2 doesn't match PSO count of 1
3281 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
3282 Draw(1, 0, 0, 0);
3283
3284 if (!m_errorMonitor->DesiredMsgFound()) {
3285 FAIL() << "Did not receive Error 'Dynamic scissorCount from "
3286 "vkCmdSetScissor() is 2, but PSO scissorCount is 1...'";
3287 m_errorMonitor->DumpFailureMsgs();
3288 }
3289
3290 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
3291 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3292 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3293 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3294}
3295// Create PSO w/o non-zero scissorCount but no scissor data
3296// Then run second test where dynamic viewportCount doesn't match PSO
3297// viewportCount
3298TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
3299 VkResult err;
3300
3301 m_errorMonitor->SetDesiredFailureMsg(
3302 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3303 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
3304
3305 ASSERT_NO_FATAL_FAILURE(InitState());
3306 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3307
3308 VkDescriptorPoolSize ds_type_count = {};
3309 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3310 ds_type_count.descriptorCount = 1;
3311
3312 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3313 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3314 ds_pool_ci.maxSets = 1;
3315 ds_pool_ci.poolSizeCount = 1;
3316 ds_pool_ci.pPoolSizes = &ds_type_count;
3317
3318 VkDescriptorPool ds_pool;
3319 err =
3320 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3321 ASSERT_VK_SUCCESS(err);
3322
3323 VkDescriptorSetLayoutBinding dsl_binding = {};
3324 dsl_binding.binding = 0;
3325 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3326 dsl_binding.descriptorCount = 1;
3327 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3328
3329 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3330 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3331 ds_layout_ci.bindingCount = 1;
3332 ds_layout_ci.pBindings = &dsl_binding;
3333
3334 VkDescriptorSetLayout ds_layout;
3335 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3336 &ds_layout);
3337 ASSERT_VK_SUCCESS(err);
3338
3339 VkDescriptorSet descriptorSet;
3340 VkDescriptorSetAllocateInfo alloc_info = {};
3341 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3342 alloc_info.descriptorSetCount = 1;
3343 alloc_info.descriptorPool = ds_pool;
3344 alloc_info.pSetLayouts = &ds_layout;
3345 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3346 &descriptorSet);
3347 ASSERT_VK_SUCCESS(err);
3348
3349 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3350 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3351 pipeline_layout_ci.setLayoutCount = 1;
3352 pipeline_layout_ci.pSetLayouts = &ds_layout;
3353
3354 VkPipelineLayout pipeline_layout;
3355 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3356 &pipeline_layout);
3357 ASSERT_VK_SUCCESS(err);
3358
3359 VkPipelineViewportStateCreateInfo vp_state_ci = {};
3360 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
3361 vp_state_ci.scissorCount = 1;
3362 vp_state_ci.pScissors =
3363 NULL; // Null scissor w/ count of 1 should cause error
3364 vp_state_ci.viewportCount = 1;
3365 vp_state_ci.pViewports =
3366 NULL; // vp is dynamic (below) so this won't cause error
3367
3368 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
3369 // Set scissor as dynamic to avoid that error
3370 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
3371 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
3372 dyn_state_ci.dynamicStateCount = 1;
3373 dyn_state_ci.pDynamicStates = &vp_state;
3374
3375 VkPipelineShaderStageCreateInfo shaderStages[2];
3376 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
3377
3378 VkShaderObj vs(m_device, bindStateVertShaderText,
3379 VK_SHADER_STAGE_VERTEX_BIT, this);
3380 VkShaderObj fs(m_device, bindStateFragShaderText,
3381 VK_SHADER_STAGE_FRAGMENT_BIT,
3382 this); // TODO - We shouldn't need a fragment shader
3383 // but add it to be able to run on more devices
3384 shaderStages[0] = vs.GetStageCreateInfo();
3385 shaderStages[1] = fs.GetStageCreateInfo();
3386
3387 VkPipelineVertexInputStateCreateInfo vi_ci = {};
3388 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
3389 vi_ci.pNext = nullptr;
3390 vi_ci.vertexBindingDescriptionCount = 0;
3391 vi_ci.pVertexBindingDescriptions = nullptr;
3392 vi_ci.vertexAttributeDescriptionCount = 0;
3393 vi_ci.pVertexAttributeDescriptions = nullptr;
3394
3395 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
3396 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
3397 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
3398
3399 VkPipelineRasterizationStateCreateInfo rs_ci = {};
3400 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
3401 rs_ci.pNext = nullptr;
3402
Mark Young0292df52016-03-31 16:03:20 -06003403 VkPipelineColorBlendAttachmentState att = {};
3404 att.blendEnable = VK_FALSE;
3405 att.colorWriteMask = 0xf;
3406
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003407 VkPipelineColorBlendStateCreateInfo cb_ci = {};
3408 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
3409 cb_ci.pNext = nullptr;
Mark Young0292df52016-03-31 16:03:20 -06003410 cb_ci.attachmentCount = 1;
3411 cb_ci.pAttachments = &att;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003412
3413 VkGraphicsPipelineCreateInfo gp_ci = {};
3414 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
3415 gp_ci.stageCount = 2;
3416 gp_ci.pStages = shaderStages;
3417 gp_ci.pVertexInputState = &vi_ci;
3418 gp_ci.pInputAssemblyState = &ia_ci;
3419 gp_ci.pViewportState = &vp_state_ci;
3420 gp_ci.pRasterizationState = &rs_ci;
3421 gp_ci.pColorBlendState = &cb_ci;
3422 gp_ci.pDynamicState = &dyn_state_ci;
3423 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
3424 gp_ci.layout = pipeline_layout;
3425 gp_ci.renderPass = renderPass();
3426
3427 VkPipelineCacheCreateInfo pc_ci = {};
3428 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
3429
3430 VkPipeline pipeline;
3431 VkPipelineCache pipelineCache;
3432
3433 err =
3434 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
3435 ASSERT_VK_SUCCESS(err);
3436 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
3437 &gp_ci, NULL, &pipeline);
3438
3439 if (!m_errorMonitor->DesiredMsgFound()) {
Eric Engestrom9bdcb232016-04-02 22:08:10 +01003440 FAIL() << "Did not receive Error 'Gfx Pipeline scissorCount is 1, but "
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003441 "pScissors is NULL...'";
3442 m_errorMonitor->DumpFailureMsgs();
3443 }
3444
3445 // Now hit second fail case where we set scissor w/ different count than PSO
3446 // First need to successfully create the PSO from above by setting
3447 // pViewports
3448 m_errorMonitor->SetDesiredFailureMsg(
3449 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3450 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
3451 "viewportCount is 1. These counts must match.");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003452
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003453 VkRect2D sc = {}; // Just need dummy vp to point to
3454 vp_state_ci.pScissors = &sc;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003455 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
3456 &gp_ci, NULL, &pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003457 ASSERT_VK_SUCCESS(err);
3458 BeginCommandBuffer();
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003459 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
3460 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003461 VkViewport viewports[2] = {}; // don't care about data
3462 // Count of 2 doesn't match PSO count of 1
Jon Ashburnf2516522015-12-30 14:06:55 -07003463 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003464 Draw(1, 0, 0, 0);
3465
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003466 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003467 FAIL() << "Did not receive Error 'Dynamic viewportCount from "
3468 "vkCmdSetViewport() is 2, but PSO viewportCount is 1...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003469 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003470 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003471
Chia-I Wu69f40122015-10-26 21:10:41 +08003472 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
3473 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3474 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3475 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06003476}
3477
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003478TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003479 // Bind a NULL RenderPass
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003480 m_errorMonitor->SetDesiredFailureMsg(
3481 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003482 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003483
3484 ASSERT_NO_FATAL_FAILURE(InitState());
3485 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003486
Tony Barbour1490c912015-07-28 10:17:20 -06003487 BeginCommandBuffer();
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003488 // Don't care about RenderPass handle b/c error should be flagged before
3489 // that
3490 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
3491 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003492
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003493 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003494 FAIL() << "Did not receive Error 'You cannot use a NULL RenderPass "
3495 "object in vkCmdBeginRenderPass()'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003496 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06003497 }
3498}
3499
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003500TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlis254eca02015-06-25 15:46:59 -06003501 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003502 m_errorMonitor->SetDesiredFailureMsg(
3503 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003504 "It is invalid to issue this call inside an active render pass");
Tobin Ehlis254eca02015-06-25 15:46:59 -06003505
3506 ASSERT_NO_FATAL_FAILURE(InitState());
3507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis254eca02015-06-25 15:46:59 -06003508
Tony Barbour1490c912015-07-28 10:17:20 -06003509 BeginCommandBuffer();
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003510 // Just create a dummy Renderpass that's non-NULL so we can get to the
3511 // proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003512 VkRenderPassBeginInfo rp_begin = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003513 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
3514 rp_begin.pNext = NULL;
3515 rp_begin.renderPass = renderPass();
3516 rp_begin.framebuffer = framebuffer();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003517
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003518 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
3519 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06003520
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003521 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003522 FAIL() << "Did not receive Error 'It is invalid to issue this call "
3523 "inside an active render pass...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003524 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06003525 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003526}
3527
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003528TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003529 // Call CmdFillBuffer within an active renderpass
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003530 m_errorMonitor->SetDesiredFailureMsg(
3531 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003532 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003533
3534 ASSERT_NO_FATAL_FAILURE(InitState());
3535 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003536
3537 // Renderpass is started here
3538 BeginCommandBuffer();
3539
3540 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08003541 vk_testing::Buffer dstBuffer;
3542 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003543
Chia-I Wu1f851912015-10-27 18:04:07 +08003544 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003545
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003546 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003547 FAIL() << "Did not receive Error 'It is invalid to issue this call "
3548 "inside an active render pass...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003549 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003550 }
3551}
3552
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003553TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003554 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003555 m_errorMonitor->SetDesiredFailureMsg(
3556 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003557 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003558
3559 ASSERT_NO_FATAL_FAILURE(InitState());
3560 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003561
3562 // Renderpass is started here
3563 BeginCommandBuffer();
3564
3565 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08003566 vk_testing::Buffer dstBuffer;
3567 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003568
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003569 VkDeviceSize dstOffset = 0;
3570 VkDeviceSize dataSize = 1024;
3571 const uint32_t *pData = NULL;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003572
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003573 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
3574 dstOffset, dataSize, pData);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003575
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003576 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003577 FAIL() << "Did not receive Error 'It is invalid to issue this call "
3578 "inside an active render pass...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003579 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003580 }
3581}
3582
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003583TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003584 // Call CmdClearColorImage within an active RenderPass
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003585 m_errorMonitor->SetDesiredFailureMsg(
3586 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003587 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003588
3589 ASSERT_NO_FATAL_FAILURE(InitState());
3590 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003591
3592 // Renderpass is started here
3593 BeginCommandBuffer();
3594
Michael Lentine584ccab2016-02-03 16:51:46 -06003595 VkClearColorValue clear_color;
3596 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003597 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3598 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3599 const int32_t tex_width = 32;
3600 const int32_t tex_height = 32;
3601 VkImageCreateInfo image_create_info = {};
3602 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3603 image_create_info.pNext = NULL;
3604 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3605 image_create_info.format = tex_format;
3606 image_create_info.extent.width = tex_width;
3607 image_create_info.extent.height = tex_height;
3608 image_create_info.extent.depth = 1;
3609 image_create_info.mipLevels = 1;
3610 image_create_info.arrayLayers = 1;
3611 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3612 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3613 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003614
Chia-I Wu1f851912015-10-27 18:04:07 +08003615 vk_testing::Image dstImage;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003616 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
3617 reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003618
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003619 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
3620 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003621
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003622 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
3623 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003624
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003625 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003626 FAIL() << "Did not receive Error 'It is invalid to issue this call "
3627 "inside an active render pass...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003628 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003629 }
3630}
3631
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003632TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003633 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003634 m_errorMonitor->SetDesiredFailureMsg(
3635 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003636 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003637
3638 ASSERT_NO_FATAL_FAILURE(InitState());
3639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003640
3641 // Renderpass is started here
3642 BeginCommandBuffer();
3643
3644 VkClearDepthStencilValue clear_value = {0};
Dustin Graves4bf3f202016-02-11 18:28:06 -07003645 VkMemoryPropertyFlags reqs = 0;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003646 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
3647 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3648 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
3649 image_create_info.extent.width = 64;
3650 image_create_info.extent.height = 64;
3651 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3652 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003653
Chia-I Wu1f851912015-10-27 18:04:07 +08003654 vk_testing::Image dstImage;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003655 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
3656 reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003657
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003658 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
3659 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003660
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003661 vkCmdClearDepthStencilImage(
3662 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
3663 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
3664 &range);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003665
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003666 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003667 FAIL() << "Did not receive Error 'It is invalid to issue this call "
3668 "inside an active render pass...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003669 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003670 }
3671}
3672
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003673TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003674 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003675 VkResult err;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003676
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07003677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003678 "vkCmdClearAttachments: This call "
3679 "must be issued inside an active "
3680 "render pass");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003681
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003682 ASSERT_NO_FATAL_FAILURE(InitState());
3683 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003684
3685 // Start no RenderPass
Chia-I Wu1f851912015-10-27 18:04:07 +08003686 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003687 ASSERT_VK_SUCCESS(err);
3688
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003689 VkClearAttachment color_attachment;
3690 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3691 color_attachment.clearValue.color.float32[0] = 0;
3692 color_attachment.clearValue.color.float32[1] = 0;
3693 color_attachment.clearValue.color.float32[2] = 0;
3694 color_attachment.clearValue.color.float32[3] = 0;
3695 color_attachment.colorAttachment = 0;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003696 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
3697 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
3698 &color_attachment, 1, &clear_rect);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003699
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003700 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003701 FAIL() << "Did not receive Error 'vkCmdClearAttachments: This call "
3702 "must be issued inside an active render pass.'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003703 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06003704 }
3705}
3706
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003707TEST_F(VkLayerTest, InvalidDynamicStateObject) {
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003708 // Create a valid cmd buffer
3709 // call vkCmdBindDynamicStateObject w/ false DS Obj
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003710 // TODO : Simple check for bad object should be added to ObjectTracker to
3711 // catch this case
3712 // The DS check for this is after driver has been called to validate DS
3713 // internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003714}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06003715
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003716TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003717 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003718 VkResult err;
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003719
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003720 m_errorMonitor->SetDesiredFailureMsg(
3721 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003722 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
3723
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003724 ASSERT_NO_FATAL_FAILURE(InitState());
3725 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003726 uint32_t qfi = 0;
3727 VkBufferCreateInfo buffCI = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003728 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3729 buffCI.size = 1024;
3730 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
3731 buffCI.queueFamilyIndexCount = 1;
3732 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003733
3734 VkBuffer ib;
Chia-I Wu69f40122015-10-26 21:10:41 +08003735 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003736 ASSERT_VK_SUCCESS(err);
3737
3738 BeginCommandBuffer();
3739 ASSERT_VK_SUCCESS(err);
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003740 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
3741 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003742 // Should error before calling to driver so don't care about actual data
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003743 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
3744 VK_INDEX_TYPE_UINT16);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003745
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003746 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003747 FAIL() << "Did not receive Error 'vkCmdBindIndexBuffer() offset (0x7) "
3748 "does not fall on ...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003749 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003750 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003751
Chia-I Wu69f40122015-10-26 21:10:41 +08003752 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06003753}
3754
Mark Lobodzinskie25c7542016-02-25 15:09:52 -07003755TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
3756 // Create an out-of-range queueFamilyIndex
3757 m_errorMonitor->SetDesiredFailureMsg(
3758 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis3e093952016-03-24 10:54:18 -06003759 "queueFamilyIndex 777, must have been given when the device was created.");
Mark Lobodzinskie25c7542016-02-25 15:09:52 -07003760
3761 ASSERT_NO_FATAL_FAILURE(InitState());
3762 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3763 VkBufferCreateInfo buffCI = {};
3764 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3765 buffCI.size = 1024;
3766 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
3767 buffCI.queueFamilyIndexCount = 1;
3768 // Introduce failure by specifying invalid queue_family_index
3769 uint32_t qfi = 777;
3770 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis3e093952016-03-24 10:54:18 -06003771 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinskie25c7542016-02-25 15:09:52 -07003772
3773 VkBuffer ib;
3774 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
3775
3776 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlis3e093952016-03-24 10:54:18 -06003777 FAIL() << "Did not receive Error 'queueFamilyIndex %d, must have "
3778 "been given when the device was created.'";
Mark Lobodzinskie25c7542016-02-25 15:09:52 -07003779 m_errorMonitor->DumpFailureMsgs();
3780 }
3781}
3782
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003783TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
3784 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
3785 // secondary)
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003786
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003787 m_errorMonitor->SetDesiredFailureMsg(
3788 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003789 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003790
3791 ASSERT_NO_FATAL_FAILURE(InitState());
3792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003793
3794 BeginCommandBuffer();
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003795 // ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08003796 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
3797 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003798
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003799 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003800 FAIL() << "Did not receive Error 'vkCmdExecuteCommands() called w/ "
3801 "Primary Cmd Buffer '";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003802 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003803 }
3804}
3805
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003806TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003807 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003808 VkResult err;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003809
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003810 m_errorMonitor->SetDesiredFailureMsg(
3811 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Write descriptor update has descriptor "
3812 "type VK_DESCRIPTOR_TYPE_SAMPLER that "
3813 "does not match ");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003814
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003815 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003816 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003817 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003818 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3819 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003820
3821 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003822 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3823 ds_pool_ci.pNext = NULL;
3824 ds_pool_ci.maxSets = 1;
3825 ds_pool_ci.poolSizeCount = 1;
3826 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003827
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003828 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003829 err =
3830 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003831 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003832 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003833 dsl_binding.binding = 0;
3834 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3835 dsl_binding.descriptorCount = 1;
3836 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3837 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003838
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003839 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003840 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3841 ds_layout_ci.pNext = NULL;
3842 ds_layout_ci.bindingCount = 1;
3843 ds_layout_ci.pBindings = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003844
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003845 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003846 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3847 &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003848 ASSERT_VK_SUCCESS(err);
3849
3850 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003851 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003852 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07003853 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003854 alloc_info.descriptorPool = ds_pool;
3855 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003856 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3857 &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003858 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003859
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003860 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003861 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3862 sampler_ci.pNext = NULL;
3863 sampler_ci.magFilter = VK_FILTER_NEAREST;
3864 sampler_ci.minFilter = VK_FILTER_NEAREST;
3865 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3866 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3867 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3868 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3869 sampler_ci.mipLodBias = 1.0;
3870 sampler_ci.anisotropyEnable = VK_FALSE;
3871 sampler_ci.maxAnisotropy = 1;
3872 sampler_ci.compareEnable = VK_FALSE;
3873 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3874 sampler_ci.minLod = 1.0;
3875 sampler_ci.maxLod = 1.0;
3876 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3877 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003878
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003879 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003880 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003881 ASSERT_VK_SUCCESS(err);
3882
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003883 VkDescriptorImageInfo info = {};
3884 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003885
3886 VkWriteDescriptorSet descriptor_write;
3887 memset(&descriptor_write, 0, sizeof(descriptor_write));
3888 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003889 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08003890 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003891 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003892 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003893 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003894
3895 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3896
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003897 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003898 FAIL() << "Did not receive Error 'Write descriptor update has "
3899 "descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not "
3900 "match...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003901 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003902 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003903
Chia-I Wu69f40122015-10-26 21:10:41 +08003904 vkDestroySampler(m_device->device(), sampler, NULL);
3905 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3906 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003907}
3908
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003909TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003910 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003911 VkResult err;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003912
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003913 m_errorMonitor->SetDesiredFailureMsg(
3914 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Descriptor update type of "
3915 "VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET "
3916 "is out of bounds for matching binding");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003917
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003918 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003919 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003920 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003921 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3922 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003923
3924 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003925 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3926 ds_pool_ci.pNext = NULL;
3927 ds_pool_ci.maxSets = 1;
3928 ds_pool_ci.poolSizeCount = 1;
3929 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003930
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003931 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003932 err =
3933 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003934 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003935
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003936 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003937 dsl_binding.binding = 0;
3938 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3939 dsl_binding.descriptorCount = 1;
3940 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3941 dsl_binding.pImmutableSamplers = NULL;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003942
3943 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003944 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3945 ds_layout_ci.pNext = NULL;
3946 ds_layout_ci.bindingCount = 1;
3947 ds_layout_ci.pBindings = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003948
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003949 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003950 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3951 &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003952 ASSERT_VK_SUCCESS(err);
3953
3954 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003955 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08003956 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07003957 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003958 alloc_info.descriptorPool = ds_pool;
3959 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003960 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3961 &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003962 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003963
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003964 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003965 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3966 sampler_ci.pNext = NULL;
3967 sampler_ci.magFilter = VK_FILTER_NEAREST;
3968 sampler_ci.minFilter = VK_FILTER_NEAREST;
3969 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3970 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3971 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3972 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3973 sampler_ci.mipLodBias = 1.0;
3974 sampler_ci.anisotropyEnable = VK_FALSE;
3975 sampler_ci.maxAnisotropy = 1;
3976 sampler_ci.compareEnable = VK_FALSE;
3977 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3978 sampler_ci.minLod = 1.0;
3979 sampler_ci.maxLod = 1.0;
3980 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3981 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003982
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003983 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003984 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003985 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003986
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003987 VkDescriptorImageInfo info = {};
3988 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003989
3990 VkWriteDescriptorSet descriptor_write;
3991 memset(&descriptor_write, 0, sizeof(descriptor_write));
3992 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003993 descriptor_write.dstSet = descriptorSet;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07003994 descriptor_write.dstArrayElement =
3995 1; /* This index out of bounds for the update */
Chia-I Wu763a7492015-10-26 20:48:51 +08003996 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003997 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003998 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003999 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08004000
4001 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4002
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004003 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004004 FAIL() << "Did not receive Error 'Descriptor update type of "
4005 "VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for "
4006 "matching binding...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004007 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004008 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004009
Chia-I Wu69f40122015-10-26 21:10:41 +08004010 vkDestroySampler(m_device->device(), sampler, NULL);
4011 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4012 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06004013}
4014
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004015TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
4016 // Create layout w/ count of 1 and attempt update to that layout w/ binding
4017 // index 2
4018 VkResult err;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004019
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004020 m_errorMonitor->SetDesiredFailureMsg(
4021 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004022 " does not have binding to match update binding ");
4023
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004024 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004025 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08004026 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004027 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4028 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004029
4030 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004031 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4032 ds_pool_ci.pNext = NULL;
4033 ds_pool_ci.maxSets = 1;
4034 ds_pool_ci.poolSizeCount = 1;
4035 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004036
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004037 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004038 err =
4039 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004040 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004041
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004042 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004043 dsl_binding.binding = 0;
4044 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4045 dsl_binding.descriptorCount = 1;
4046 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4047 dsl_binding.pImmutableSamplers = NULL;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004048
4049 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004050 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4051 ds_layout_ci.pNext = NULL;
4052 ds_layout_ci.bindingCount = 1;
4053 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004054 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004055 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4056 &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004057 ASSERT_VK_SUCCESS(err);
4058
4059 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004060 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004061 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07004062 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004063 alloc_info.descriptorPool = ds_pool;
4064 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004065 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4066 &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004067 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004068
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004069 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004070 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4071 sampler_ci.pNext = NULL;
4072 sampler_ci.magFilter = VK_FILTER_NEAREST;
4073 sampler_ci.minFilter = VK_FILTER_NEAREST;
4074 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4075 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4076 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4077 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4078 sampler_ci.mipLodBias = 1.0;
4079 sampler_ci.anisotropyEnable = VK_FALSE;
4080 sampler_ci.maxAnisotropy = 1;
4081 sampler_ci.compareEnable = VK_FALSE;
4082 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4083 sampler_ci.minLod = 1.0;
4084 sampler_ci.maxLod = 1.0;
4085 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4086 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004087
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004088 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08004089 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004090 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08004091
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06004092 VkDescriptorImageInfo info = {};
4093 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08004094
4095 VkWriteDescriptorSet descriptor_write;
4096 memset(&descriptor_write, 0, sizeof(descriptor_write));
4097 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08004098 descriptor_write.dstSet = descriptorSet;
4099 descriptor_write.dstBinding = 2;
Chia-I Wu763a7492015-10-26 20:48:51 +08004100 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004101 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08004102 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06004103 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08004104
4105 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4106
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004107 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004108 FAIL() << "Did not receive Error 'Descriptor Set <blah> does not have "
4109 "binding to match update binding '";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004110 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004111 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004112
Chia-I Wu69f40122015-10-26 21:10:41 +08004113 vkDestroySampler(m_device->device(), sampler, NULL);
4114 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4115 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06004116}
4117
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004118TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
4119 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
4120 // types
4121 VkResult err;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004122
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004124 "Unexpected UPDATE struct of type ");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004125
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004126 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004127
Chia-I Wuc51b1212015-10-27 19:25:11 +08004128 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004129 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4130 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004131
4132 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004133 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4134 ds_pool_ci.pNext = NULL;
4135 ds_pool_ci.maxSets = 1;
4136 ds_pool_ci.poolSizeCount = 1;
4137 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004138
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004139 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004140 err =
4141 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004142 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004143 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004144 dsl_binding.binding = 0;
4145 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4146 dsl_binding.descriptorCount = 1;
4147 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4148 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004149
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004150 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004151 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4152 ds_layout_ci.pNext = NULL;
4153 ds_layout_ci.bindingCount = 1;
4154 ds_layout_ci.pBindings = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004155
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004156 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004157 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4158 &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004159 ASSERT_VK_SUCCESS(err);
4160
4161 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004162 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004163 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07004164 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004165 alloc_info.descriptorPool = ds_pool;
4166 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004167 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4168 &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004169 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004170
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004171 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004172 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4173 sampler_ci.pNext = NULL;
4174 sampler_ci.magFilter = VK_FILTER_NEAREST;
4175 sampler_ci.minFilter = VK_FILTER_NEAREST;
4176 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4177 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4178 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4179 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4180 sampler_ci.mipLodBias = 1.0;
4181 sampler_ci.anisotropyEnable = VK_FALSE;
4182 sampler_ci.maxAnisotropy = 1;
4183 sampler_ci.compareEnable = VK_FALSE;
4184 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4185 sampler_ci.minLod = 1.0;
4186 sampler_ci.maxLod = 1.0;
4187 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4188 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004189 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08004190 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004191 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08004192
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06004193 VkDescriptorImageInfo info = {};
4194 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08004195
4196 VkWriteDescriptorSet descriptor_write;
4197 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004198 descriptor_write.sType =
4199 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu1f851912015-10-27 18:04:07 +08004200 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08004201 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004202 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08004203 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06004204 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08004205
4206 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4207
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004208 if (!m_errorMonitor->DesiredMsgFound()) {
4209 FAIL() << "Did not receive Error 'Unexpected UPDATE struct of type '";
4210 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004211 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004212
Chia-I Wu69f40122015-10-26 21:10:41 +08004213 vkDestroySampler(m_device->device(), sampler, NULL);
4214 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4215 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06004216}
4217
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004218TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06004219 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004220 VkResult err;
Tobin Ehlisb46be812015-10-23 16:00:08 -06004221
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004222 m_errorMonitor->SetDesiredFailureMsg(
4223 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004224 "Attempt to update descriptor with invalid sampler 0xbaadbeef");
4225
Tobin Ehlisb46be812015-10-23 16:00:08 -06004226 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004227 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
4228 // code
Chia-I Wuc51b1212015-10-27 19:25:11 +08004229 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004230 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
4231 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06004232
4233 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004234 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4235 ds_pool_ci.pNext = NULL;
4236 ds_pool_ci.maxSets = 1;
4237 ds_pool_ci.poolSizeCount = 1;
4238 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06004239
4240 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004241 err =
4242 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06004243 ASSERT_VK_SUCCESS(err);
4244
4245 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004246 dsl_binding.binding = 0;
4247 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4248 dsl_binding.descriptorCount = 1;
4249 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4250 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisb46be812015-10-23 16:00:08 -06004251
4252 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004253 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4254 ds_layout_ci.pNext = NULL;
4255 ds_layout_ci.bindingCount = 1;
4256 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06004257 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004258 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4259 &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06004260 ASSERT_VK_SUCCESS(err);
4261
4262 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004263 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004264 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07004265 alloc_info.descriptorSetCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06004266 alloc_info.descriptorPool = ds_pool;
4267 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004268 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4269 &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06004270 ASSERT_VK_SUCCESS(err);
4271
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004272 VkSampler sampler =
4273 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisb46be812015-10-23 16:00:08 -06004274
4275 VkDescriptorImageInfo descriptor_info;
4276 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
4277 descriptor_info.sampler = sampler;
4278
4279 VkWriteDescriptorSet descriptor_write;
4280 memset(&descriptor_write, 0, sizeof(descriptor_write));
4281 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08004282 descriptor_write.dstSet = descriptorSet;
4283 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08004284 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06004285 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4286 descriptor_write.pImageInfo = &descriptor_info;
4287
4288 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4289
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004290 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004291 FAIL() << "Did not receive Error 'Attempt to update descriptor with "
4292 "invalid sampler...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004293 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06004294 }
4295
Chia-I Wu69f40122015-10-26 21:10:41 +08004296 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4297 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06004298}
4299
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004300TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
4301 // Create a single combined Image/Sampler descriptor and send it an invalid
4302 // imageView
4303 VkResult err;
Tobin Ehlisb46be812015-10-23 16:00:08 -06004304
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004305 m_errorMonitor->SetDesiredFailureMsg(
4306 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004307 "Attempt to update descriptor with invalid imageView 0xbaadbeef");
4308
Tobin Ehlisb46be812015-10-23 16:00:08 -06004309 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wuc51b1212015-10-27 19:25:11 +08004310 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004311 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4312 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06004313
4314 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004315 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4316 ds_pool_ci.pNext = NULL;
4317 ds_pool_ci.maxSets = 1;
4318 ds_pool_ci.poolSizeCount = 1;
4319 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06004320
4321 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004322 err =
4323 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06004324 ASSERT_VK_SUCCESS(err);
4325
4326 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004327 dsl_binding.binding = 0;
4328 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4329 dsl_binding.descriptorCount = 1;
4330 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4331 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisb46be812015-10-23 16:00:08 -06004332
4333 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004334 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4335 ds_layout_ci.pNext = NULL;
4336 ds_layout_ci.bindingCount = 1;
4337 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06004338 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004339 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4340 &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06004341 ASSERT_VK_SUCCESS(err);
4342
4343 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004344 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004345 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07004346 alloc_info.descriptorSetCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06004347 alloc_info.descriptorPool = ds_pool;
4348 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004349 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4350 &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06004351 ASSERT_VK_SUCCESS(err);
4352
4353 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004354 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4355 sampler_ci.pNext = NULL;
4356 sampler_ci.magFilter = VK_FILTER_NEAREST;
4357 sampler_ci.minFilter = VK_FILTER_NEAREST;
4358 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4359 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4360 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4361 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4362 sampler_ci.mipLodBias = 1.0;
4363 sampler_ci.anisotropyEnable = VK_FALSE;
4364 sampler_ci.maxAnisotropy = 1;
4365 sampler_ci.compareEnable = VK_FALSE;
4366 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4367 sampler_ci.minLod = 1.0;
4368 sampler_ci.maxLod = 1.0;
4369 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4370 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisb46be812015-10-23 16:00:08 -06004371
4372 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08004373 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06004374 ASSERT_VK_SUCCESS(err);
4375
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004376 VkImageView view =
4377 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisb46be812015-10-23 16:00:08 -06004378
4379 VkDescriptorImageInfo descriptor_info;
4380 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
4381 descriptor_info.sampler = sampler;
4382 descriptor_info.imageView = view;
4383
4384 VkWriteDescriptorSet descriptor_write;
4385 memset(&descriptor_write, 0, sizeof(descriptor_write));
4386 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08004387 descriptor_write.dstSet = descriptorSet;
4388 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08004389 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06004390 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4391 descriptor_write.pImageInfo = &descriptor_info;
4392
4393 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4394
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004395 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004396 FAIL() << "Did not receive Error 'Attempt to update descriptor with "
4397 "invalid imageView...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004398 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06004399 }
4400
Chia-I Wu69f40122015-10-26 21:10:41 +08004401 vkDestroySampler(m_device->device(), sampler, NULL);
4402 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4403 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06004404}
4405
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004406TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
4407 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
4408 // into the other
4409 VkResult err;
Tobin Ehlis3e676262015-10-27 16:35:27 -06004410
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004411 m_errorMonitor->SetDesiredFailureMsg(
4412 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Copy descriptor update index 0, update "
4413 "count #1, has src update descriptor "
4414 "type VK_DESCRIPTOR_TYPE_SAMPLER ");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004415
Tobin Ehlis3e676262015-10-27 16:35:27 -06004416 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004417 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08004418 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004419 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4420 ds_type_count[0].descriptorCount = 1;
4421 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
4422 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06004423
4424 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004425 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4426 ds_pool_ci.pNext = NULL;
4427 ds_pool_ci.maxSets = 1;
4428 ds_pool_ci.poolSizeCount = 2;
4429 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis3e676262015-10-27 16:35:27 -06004430
4431 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004432 err =
4433 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3e676262015-10-27 16:35:27 -06004434 ASSERT_VK_SUCCESS(err);
4435 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004436 dsl_binding[0].binding = 0;
4437 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4438 dsl_binding[0].descriptorCount = 1;
4439 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4440 dsl_binding[0].pImmutableSamplers = NULL;
4441 dsl_binding[1].binding = 1;
4442 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4443 dsl_binding[1].descriptorCount = 1;
4444 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
4445 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis3e676262015-10-27 16:35:27 -06004446
4447 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004448 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4449 ds_layout_ci.pNext = NULL;
4450 ds_layout_ci.bindingCount = 2;
4451 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis3e676262015-10-27 16:35:27 -06004452
4453 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004454 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4455 &ds_layout);
Tobin Ehlis3e676262015-10-27 16:35:27 -06004456 ASSERT_VK_SUCCESS(err);
4457
4458 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004459 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004460 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07004461 alloc_info.descriptorSetCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06004462 alloc_info.descriptorPool = ds_pool;
4463 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004464 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4465 &descriptorSet);
Tobin Ehlis3e676262015-10-27 16:35:27 -06004466 ASSERT_VK_SUCCESS(err);
4467
4468 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004469 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4470 sampler_ci.pNext = NULL;
4471 sampler_ci.magFilter = VK_FILTER_NEAREST;
4472 sampler_ci.minFilter = VK_FILTER_NEAREST;
4473 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4474 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4475 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4476 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4477 sampler_ci.mipLodBias = 1.0;
4478 sampler_ci.anisotropyEnable = VK_FALSE;
4479 sampler_ci.maxAnisotropy = 1;
4480 sampler_ci.compareEnable = VK_FALSE;
4481 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4482 sampler_ci.minLod = 1.0;
4483 sampler_ci.maxLod = 1.0;
4484 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4485 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3e676262015-10-27 16:35:27 -06004486
4487 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08004488 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3e676262015-10-27 16:35:27 -06004489 ASSERT_VK_SUCCESS(err);
4490
4491 VkDescriptorImageInfo info = {};
4492 info.sampler = sampler;
4493
4494 VkWriteDescriptorSet descriptor_write;
4495 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
4496 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08004497 descriptor_write.dstSet = descriptorSet;
4498 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wu763a7492015-10-26 20:48:51 +08004499 descriptor_write.descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06004500 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4501 descriptor_write.pImageInfo = &info;
4502 // This write update should succeed
4503 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4504 // Now perform a copy update that fails due to type mismatch
4505 VkCopyDescriptorSet copy_ds_update;
4506 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4507 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4508 copy_ds_update.srcSet = descriptorSet;
4509 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
Chia-I Wu1f851912015-10-27 18:04:07 +08004510 copy_ds_update.dstSet = descriptorSet;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004511 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wu763a7492015-10-26 20:48:51 +08004512 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06004513 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4514
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004515 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004516 FAIL() << "Did not receive Error 'Copy descriptor update index 0, "
4517 "update count #1, has src update descriptor "
4518 "type_DESCRIPTOR_TYPE_SAMPLER'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004519 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06004520 }
4521 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004522 m_errorMonitor->SetDesiredFailureMsg(
4523 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004524 "Copy descriptor update 0 has srcBinding 3 which is out of bounds ");
Tobin Ehlis3e676262015-10-27 16:35:27 -06004525 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4526 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4527 copy_ds_update.srcSet = descriptorSet;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004528 copy_ds_update.srcBinding =
4529 3; // ERROR : Invalid binding for matching layout
Chia-I Wu1f851912015-10-27 18:04:07 +08004530 copy_ds_update.dstSet = descriptorSet;
4531 copy_ds_update.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08004532 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06004533 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4534
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004535 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004536 FAIL() << "Did not receive Error 'Copy descriptor update 0 has "
4537 "srcBinding 3 which is out of bounds...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004538 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06004539 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004540
Tobin Ehlis3e676262015-10-27 16:35:27 -06004541 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004542 m_errorMonitor->SetDesiredFailureMsg(
4543 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004544 "Copy descriptor src update is out of bounds for matching binding 1 ");
4545
Tobin Ehlis3e676262015-10-27 16:35:27 -06004546 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
4547 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
4548 copy_ds_update.srcSet = descriptorSet;
4549 copy_ds_update.srcBinding = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08004550 copy_ds_update.dstSet = descriptorSet;
4551 copy_ds_update.dstBinding = 0;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004552 copy_ds_update.descriptorCount =
4553 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis3e676262015-10-27 16:35:27 -06004554 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
4555
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004556 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004557 FAIL() << "Did not receive Error 'Copy descriptor src update is out of "
4558 "bounds for matching binding 1...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004559 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06004560 }
4561
Chia-I Wu69f40122015-10-26 21:10:41 +08004562 vkDestroySampler(m_device->device(), sampler, NULL);
4563 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4564 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis3e676262015-10-27 16:35:27 -06004565}
4566
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004567TEST_F(VkLayerTest, NumSamplesMismatch) {
4568 // Create CommandBuffer where MSAA samples doesn't match RenderPass
4569 // sampleCount
4570 VkResult err;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004571
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004573 "Num samples mismatch! ");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004574
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004575 ASSERT_NO_FATAL_FAILURE(InitState());
4576 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wuc51b1212015-10-27 19:25:11 +08004577 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004578 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08004579 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004580
4581 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004582 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4583 ds_pool_ci.pNext = NULL;
4584 ds_pool_ci.maxSets = 1;
4585 ds_pool_ci.poolSizeCount = 1;
4586 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004587
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004588 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004589 err =
4590 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004591 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004592
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004593 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08004594 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004595 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08004596 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004597 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4598 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004599
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004600 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4601 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4602 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08004603 ds_layout_ci.bindingCount = 1;
Jon Ashburnadb61352015-12-30 18:01:16 -07004604 ds_layout_ci.pBindings = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004605
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004606 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004607 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4608 &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004609 ASSERT_VK_SUCCESS(err);
4610
4611 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004612 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004613 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07004614 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004615 alloc_info.descriptorPool = ds_pool;
4616 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004617 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4618 &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004619 ASSERT_VK_SUCCESS(err);
4620
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004621 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004622 pipe_ms_state_ci.sType =
4623 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4624 pipe_ms_state_ci.pNext = NULL;
4625 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
4626 pipe_ms_state_ci.sampleShadingEnable = 0;
4627 pipe_ms_state_ci.minSampleShading = 1.0;
4628 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004629
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004630 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004631 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4632 pipeline_layout_ci.pNext = NULL;
4633 pipeline_layout_ci.setLayoutCount = 1;
4634 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004635
4636 VkPipelineLayout pipeline_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004637 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4638 &pipeline_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004639 ASSERT_VK_SUCCESS(err);
4640
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004641 VkShaderObj vs(m_device, bindStateVertShaderText,
4642 VK_SHADER_STAGE_VERTEX_BIT, this);
4643 VkShaderObj fs(m_device, bindStateFragShaderText,
4644 VK_SHADER_STAGE_FRAGMENT_BIT,
4645 this); // TODO - We shouldn't need a fragment shader
4646 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06004647 VkPipelineObj pipe(m_device);
4648 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004649 pipe.AddShader(&fs);
Mark Young0292df52016-03-31 16:03:20 -06004650 pipe.AddColorAttachment();
Tony Barbourd7d828b2015-08-06 10:16:07 -06004651 pipe.SetMSAA(&pipe_ms_state_ci);
4652 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004653
Tony Barbour1490c912015-07-28 10:17:20 -06004654 BeginCommandBuffer();
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004655 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4656 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004657
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004658 if (!m_errorMonitor->DesiredMsgFound()) {
Eric Engestrom9bdcb232016-04-02 22:08:10 +01004659 FAIL() << "Did not receive Error 'Num samples mismatch!...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004660 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06004661 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004662
Chia-I Wu69f40122015-10-26 21:10:41 +08004663 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4664 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4665 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06004666}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004667
Mark Young0292df52016-03-31 16:03:20 -06004668TEST_F(VkLayerTest, NumBlendAttachMismatch) {
4669 // Create Pipeline where the number of blend attachments doesn't match the
4670 // number of color attachments. In this case, we don't add any color
4671 // blend attachments even though we have a color attachment.
4672 VkResult err;
4673
4674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4675 "Mismatch between blend state attachment");
4676
4677 ASSERT_NO_FATAL_FAILURE(InitState());
4678 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4679 VkDescriptorPoolSize ds_type_count = {};
4680 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4681 ds_type_count.descriptorCount = 1;
4682
4683 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4684 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4685 ds_pool_ci.pNext = NULL;
4686 ds_pool_ci.maxSets = 1;
4687 ds_pool_ci.poolSizeCount = 1;
4688 ds_pool_ci.pPoolSizes = &ds_type_count;
4689
4690 VkDescriptorPool ds_pool;
4691 err =
4692 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4693 ASSERT_VK_SUCCESS(err);
4694
4695 VkDescriptorSetLayoutBinding dsl_binding = {};
4696 dsl_binding.binding = 0;
4697 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4698 dsl_binding.descriptorCount = 1;
4699 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4700 dsl_binding.pImmutableSamplers = NULL;
4701
4702 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4703 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4704 ds_layout_ci.pNext = NULL;
4705 ds_layout_ci.bindingCount = 1;
4706 ds_layout_ci.pBindings = &dsl_binding;
4707
4708 VkDescriptorSetLayout ds_layout;
4709 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4710 &ds_layout);
4711 ASSERT_VK_SUCCESS(err);
4712
4713 VkDescriptorSet descriptorSet;
4714 VkDescriptorSetAllocateInfo alloc_info = {};
4715 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4716 alloc_info.descriptorSetCount = 1;
4717 alloc_info.descriptorPool = ds_pool;
4718 alloc_info.pSetLayouts = &ds_layout;
4719 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4720 &descriptorSet);
4721 ASSERT_VK_SUCCESS(err);
4722
4723 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
4724 pipe_ms_state_ci.sType =
4725 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4726 pipe_ms_state_ci.pNext = NULL;
4727 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
4728 pipe_ms_state_ci.sampleShadingEnable = 0;
4729 pipe_ms_state_ci.minSampleShading = 1.0;
4730 pipe_ms_state_ci.pSampleMask = NULL;
4731
4732 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4733 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4734 pipeline_layout_ci.pNext = NULL;
4735 pipeline_layout_ci.setLayoutCount = 1;
4736 pipeline_layout_ci.pSetLayouts = &ds_layout;
4737
4738 VkPipelineLayout pipeline_layout;
4739 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4740 &pipeline_layout);
4741 ASSERT_VK_SUCCESS(err);
4742
4743 VkShaderObj vs(m_device, bindStateVertShaderText,
4744 VK_SHADER_STAGE_VERTEX_BIT, this);
4745 VkShaderObj fs(m_device, bindStateFragShaderText,
4746 VK_SHADER_STAGE_FRAGMENT_BIT,
4747 this); // TODO - We shouldn't need a fragment shader
4748 // but add it to be able to run on more devices
4749 VkPipelineObj pipe(m_device);
4750 pipe.AddShader(&vs);
4751 pipe.AddShader(&fs);
4752 pipe.SetMSAA(&pipe_ms_state_ci);
4753 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4754
4755 BeginCommandBuffer();
4756 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4757 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4758
4759 if (!m_errorMonitor->DesiredMsgFound()) {
Eric Engestrom9bdcb232016-04-02 22:08:10 +01004760 FAIL() << "Did not receive Error 'Mismatch between blend state attachment...'";
Mark Young0292df52016-03-31 16:03:20 -06004761 m_errorMonitor->DumpFailureMsgs();
4762 }
4763
4764 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4765 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4766 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4767}
4768
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004769TEST_F(VkLayerTest, ClearCmdNoDraw) {
4770 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
4771 // to issuing a Draw
4772 VkResult err;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004773
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07004774 // TODO: verify that this matches layer
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004775 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbourc7dea5e2016-03-02 15:12:01 -07004776 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004777 "vkCmdClearAttachments() issued on CB object ");
4778
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004779 ASSERT_NO_FATAL_FAILURE(InitState());
4780 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004781
Chia-I Wuc51b1212015-10-27 19:25:11 +08004782 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004783 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4784 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004785
4786 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004787 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4788 ds_pool_ci.pNext = NULL;
4789 ds_pool_ci.maxSets = 1;
4790 ds_pool_ci.poolSizeCount = 1;
4791 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004792
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004793 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004794 err =
4795 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004796 ASSERT_VK_SUCCESS(err);
4797
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004798 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004799 dsl_binding.binding = 0;
4800 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4801 dsl_binding.descriptorCount = 1;
4802 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4803 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004804
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004805 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004806 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4807 ds_layout_ci.pNext = NULL;
4808 ds_layout_ci.bindingCount = 1;
4809 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004810
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004811 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004812 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4813 &ds_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004814 ASSERT_VK_SUCCESS(err);
4815
4816 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004817 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004818 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07004819 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004820 alloc_info.descriptorPool = ds_pool;
4821 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004822 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4823 &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004824 ASSERT_VK_SUCCESS(err);
4825
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004826 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004827 pipe_ms_state_ci.sType =
4828 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4829 pipe_ms_state_ci.pNext = NULL;
4830 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
4831 pipe_ms_state_ci.sampleShadingEnable = 0;
4832 pipe_ms_state_ci.minSampleShading = 1.0;
4833 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004834
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004835 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004836 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4837 pipeline_layout_ci.pNext = NULL;
4838 pipeline_layout_ci.setLayoutCount = 1;
4839 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004840
4841 VkPipelineLayout pipeline_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004842 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4843 &pipeline_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004844 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004845
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004846 VkShaderObj vs(m_device, bindStateVertShaderText,
4847 VK_SHADER_STAGE_VERTEX_BIT, this);
4848 // TODO - We shouldn't need a fragment shader but add it to be able to run
4849 // on more devices
4850 VkShaderObj fs(m_device, bindStateFragShaderText,
4851 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004852
Tony Barbourd7d828b2015-08-06 10:16:07 -06004853 VkPipelineObj pipe(m_device);
4854 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004855 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004856 pipe.SetMSAA(&pipe_ms_state_ci);
4857 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06004858
4859 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004860
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004861 // Main thing we care about for this test is that the VkImage obj we're
4862 // clearing matches Color Attachment of FB
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004863 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004864 VkClearAttachment color_attachment;
4865 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4866 color_attachment.clearValue.color.float32[0] = 1.0;
4867 color_attachment.clearValue.color.float32[1] = 1.0;
4868 color_attachment.clearValue.color.float32[2] = 1.0;
4869 color_attachment.clearValue.color.float32[3] = 1.0;
4870 color_attachment.colorAttachment = 0;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004871 VkClearRect clear_rect = {
4872 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004873
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004874 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
4875 &color_attachment, 1, &clear_rect);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004876
4877 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004878 FAIL() << "Did not receive Error 'vkCommandClearAttachments() issued "
4879 "on CB object...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004880 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004881 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004882
Chia-I Wu69f40122015-10-26 21:10:41 +08004883 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4884 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4885 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06004886}
4887
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004888TEST_F(VkLayerTest, VtxBufferBadIndex) {
4889 VkResult err;
Tobin Ehlise4076782015-06-24 15:53:07 -06004890
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004891 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski5c13d4d2016-02-11 09:26:16 -07004892 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski74e84692015-12-14 15:14:10 -07004893 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004894
Tobin Ehlise4076782015-06-24 15:53:07 -06004895 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06004896 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlise4076782015-06-24 15:53:07 -06004897 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004898
Chia-I Wuc51b1212015-10-27 19:25:11 +08004899 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004900 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4901 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004902
4903 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004904 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4905 ds_pool_ci.pNext = NULL;
4906 ds_pool_ci.maxSets = 1;
4907 ds_pool_ci.poolSizeCount = 1;
4908 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004909
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06004910 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004911 err =
4912 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06004913 ASSERT_VK_SUCCESS(err);
4914
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004915 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004916 dsl_binding.binding = 0;
4917 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4918 dsl_binding.descriptorCount = 1;
4919 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4920 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06004921
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004922 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004923 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4924 ds_layout_ci.pNext = NULL;
4925 ds_layout_ci.bindingCount = 1;
4926 ds_layout_ci.pBindings = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004927
Tobin Ehlise4076782015-06-24 15:53:07 -06004928 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004929 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4930 &ds_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06004931 ASSERT_VK_SUCCESS(err);
4932
4933 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08004934 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08004935 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07004936 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06004937 alloc_info.descriptorPool = ds_pool;
4938 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004939 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4940 &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06004941 ASSERT_VK_SUCCESS(err);
4942
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004943 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004944 pipe_ms_state_ci.sType =
4945 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
4946 pipe_ms_state_ci.pNext = NULL;
4947 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
4948 pipe_ms_state_ci.sampleShadingEnable = 0;
4949 pipe_ms_state_ci.minSampleShading = 1.0;
4950 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06004951
Tony Barbourefbe9ca2015-07-15 12:50:33 -06004952 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004953 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4954 pipeline_layout_ci.pNext = NULL;
4955 pipeline_layout_ci.setLayoutCount = 1;
4956 pipeline_layout_ci.pSetLayouts = &ds_layout;
4957 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06004958
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004959 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4960 &pipeline_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06004961 ASSERT_VK_SUCCESS(err);
4962
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004963 VkShaderObj vs(m_device, bindStateVertShaderText,
4964 VK_SHADER_STAGE_VERTEX_BIT, this);
4965 VkShaderObj fs(m_device, bindStateFragShaderText,
4966 VK_SHADER_STAGE_FRAGMENT_BIT,
4967 this); // TODO - We shouldn't need a fragment shader
4968 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06004969 VkPipelineObj pipe(m_device);
4970 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06004971 pipe.AddShader(&fs);
Mark Young0292df52016-03-31 16:03:20 -06004972 pipe.AddColorAttachment();
Tony Barbourd7d828b2015-08-06 10:16:07 -06004973 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06004974 pipe.SetViewport(m_viewports);
4975 pipe.SetScissor(m_scissors);
Tony Barbourd7d828b2015-08-06 10:16:07 -06004976 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06004977
4978 BeginCommandBuffer();
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004979 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4980 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06004981 // Don't care about actual data, just need to get to draw to flag error
4982 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004983 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
4984 (const void *)&vbo_data);
Tobin Ehlisd28acef2015-09-09 15:12:35 -06004985 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06004986 Draw(1, 0, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06004987
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004988 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07004989 FAIL() << "Did not receive Error 'Vtx Buffer Index 0 was bound, but no "
4990 "vtx buffers are attached to PSO.'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004991 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise4076782015-06-24 15:53:07 -06004992 }
Mike Stroyan2237f522015-08-18 14:40:24 -06004993
Chia-I Wu69f40122015-10-26 21:10:41 +08004994 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4995 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4996 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise4076782015-06-24 15:53:07 -06004997}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004998#endif // DRAW_STATE_TESTS
4999
Tobin Ehlis57e6a612015-05-26 16:11:58 -06005000#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06005001#if GTEST_IS_THREADSAFE
5002struct thread_data_struct {
Chia-I Wu1f851912015-10-27 18:04:07 +08005003 VkCommandBuffer commandBuffer;
Mike Stroyan09aae812015-05-12 16:00:45 -06005004 VkEvent event;
5005 bool bailout;
5006};
5007
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005008extern "C" void *AddToCommandBuffer(void *arg) {
5009 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyan09aae812015-05-12 16:00:45 -06005010
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005011 for (int i = 0; i < 10000; i++) {
5012 vkCmdSetEvent(data->commandBuffer, data->event,
5013 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyan09aae812015-05-12 16:00:45 -06005014 if (data->bailout) {
5015 break;
5016 }
5017 }
5018 return NULL;
5019}
5020
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005021TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan7016f4f2015-07-13 14:45:35 -06005022 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06005023
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5025 "THREADING ERROR");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005026
Mike Stroyan09aae812015-05-12 16:00:45 -06005027 ASSERT_NO_FATAL_FAILURE(InitState());
5028 ASSERT_NO_FATAL_FAILURE(InitViewport());
5029 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5030
Chia-I Wu1f851912015-10-27 18:04:07 +08005031 // Calls AllocateCommandBuffers
5032 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005033
5034 // Avoid creating RenderPass
Chia-I Wu1f851912015-10-27 18:04:07 +08005035 commandBuffer.BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06005036
5037 VkEventCreateInfo event_info;
5038 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06005039 VkResult err;
5040
5041 memset(&event_info, 0, sizeof(event_info));
5042 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5043
Chia-I Wu69f40122015-10-26 21:10:41 +08005044 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyan09aae812015-05-12 16:00:45 -06005045 ASSERT_VK_SUCCESS(err);
5046
Mike Stroyan09aae812015-05-12 16:00:45 -06005047 err = vkResetEvent(device(), event);
5048 ASSERT_VK_SUCCESS(err);
5049
5050 struct thread_data_struct data;
Chia-I Wu1f851912015-10-27 18:04:07 +08005051 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyan09aae812015-05-12 16:00:45 -06005052 data.event = event;
5053 data.bailout = false;
5054 m_errorMonitor->SetBailout(&data.bailout);
5055 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06005056 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06005057 // Add many entries to command buffer from this thread at the same time.
5058 AddToCommandBuffer(&data);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06005059
Mike Stroyan7016f4f2015-07-13 14:45:35 -06005060 test_platform_thread_join(thread, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005061 commandBuffer.EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06005062
Mike Stroyan450b0572016-01-22 15:22:03 -07005063 m_errorMonitor->SetBailout(NULL);
5064
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005065 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005066 FAIL() << "Did not receive Error 'THREADING ERROR' from using one "
5067 "VkCommandBufferObj in two threads";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005068 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan09aae812015-05-12 16:00:45 -06005069 }
5070
Chia-I Wu69f40122015-10-26 21:10:41 +08005071 vkDestroyEvent(device(), event, NULL);
Mike Stroyan09aae812015-05-12 16:00:45 -06005072}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06005073#endif // GTEST_IS_THREADSAFE
5074#endif // THREADING_TESTS
5075
Chris Forbes5af3bf22015-05-25 11:13:08 +12005076#if SHADER_CHECKER_TESTS
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005077TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005079 "Shader is not SPIR-V");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005080
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06005081 ASSERT_NO_FATAL_FAILURE(InitState());
5082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5083
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06005084 VkShaderModule module;
5085 VkShaderModuleCreateInfo moduleCreateInfo;
5086 struct icd_spv_header spv;
5087
5088 spv.magic = ICD_SPV_MAGIC;
5089 spv.version = ICD_SPV_VERSION;
5090 spv.gen_magic = 0;
5091
5092 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
5093 moduleCreateInfo.pNext = NULL;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005094 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06005095 moduleCreateInfo.codeSize = 4;
5096 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08005097 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06005098
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005099 if (!m_errorMonitor->DesiredMsgFound()) {
5100 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
5101 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06005102 }
5103}
5104
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005105TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005107 "Shader is not SPIR-V");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005108
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06005109 ASSERT_NO_FATAL_FAILURE(InitState());
5110 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5111
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06005112 VkShaderModule module;
5113 VkShaderModuleCreateInfo moduleCreateInfo;
5114 struct icd_spv_header spv;
5115
5116 spv.magic = ~ICD_SPV_MAGIC;
5117 spv.version = ICD_SPV_VERSION;
5118 spv.gen_magic = 0;
5119
5120 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
5121 moduleCreateInfo.pNext = NULL;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005122 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06005123 moduleCreateInfo.codeSize = sizeof(spv) + 10;
5124 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08005125 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06005126
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005127 if (!m_errorMonitor->DesiredMsgFound()) {
5128 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
5129 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06005130 }
5131}
5132
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005133TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005135 "Shader is not SPIR-V");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005136
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06005137 ASSERT_NO_FATAL_FAILURE(InitState());
5138 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5139
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06005140 VkShaderModule module;
5141 VkShaderModuleCreateInfo moduleCreateInfo;
5142 struct icd_spv_header spv;
5143
5144 spv.magic = ICD_SPV_MAGIC;
5145 spv.version = ~ICD_SPV_VERSION;
5146 spv.gen_magic = 0;
5147
5148 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
5149 moduleCreateInfo.pNext = NULL;
5150
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005151 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06005152 moduleCreateInfo.codeSize = sizeof(spv) + 10;
5153 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08005154 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06005155
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005156 if (!m_errorMonitor->DesiredMsgFound()) {
5157 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
5158 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06005159 }
5160}
5161
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005162TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski5c13d4d2016-02-11 09:26:16 -07005163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005164 "not consumed by fragment shader");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005165
Chris Forbes5af3bf22015-05-25 11:13:08 +12005166 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06005167 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12005168
5169 char const *vsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005170 "#version 450\n"
Chris Forbes5af3bf22015-05-25 11:13:08 +12005171 "\n"
5172 "layout(location=0) out float x;\n"
Tony Barbour19b5f922016-01-05 13:37:45 -07005173 "out gl_PerVertex {\n"
5174 " vec4 gl_Position;\n"
5175 "};\n"
Chris Forbes5af3bf22015-05-25 11:13:08 +12005176 "void main(){\n"
5177 " gl_Position = vec4(1);\n"
5178 " x = 0;\n"
5179 "}\n";
5180 char const *fsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005181 "#version 450\n"
Chris Forbes5af3bf22015-05-25 11:13:08 +12005182 "\n"
5183 "layout(location=0) out vec4 color;\n"
5184 "void main(){\n"
5185 " color = vec4(1);\n"
5186 "}\n";
5187
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005188 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5189 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5af3bf22015-05-25 11:13:08 +12005190
5191 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08005192 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12005193 pipe.AddShader(&vs);
5194 pipe.AddShader(&fs);
5195
Chris Forbes5af3bf22015-05-25 11:13:08 +12005196 VkDescriptorSetObj descriptorSet(m_device);
5197 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005198 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12005199
Tony Barboured132432015-08-04 16:23:11 -06005200 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12005201
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005202 if (!m_errorMonitor->DesiredMsgFound()) {
5203 FAIL() << "Did not receive Warning 'not consumed by fragment shader'";
5204 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5af3bf22015-05-25 11:13:08 +12005205 }
5206}
Chris Forbes5af3bf22015-05-25 11:13:08 +12005207
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005208TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005210 "not written by vertex shader");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005211
Chris Forbes3c10b852015-05-25 11:13:13 +12005212 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06005213 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12005214
5215 char const *vsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005216 "#version 450\n"
Chris Forbes3c10b852015-05-25 11:13:13 +12005217 "\n"
Tony Barbour19b5f922016-01-05 13:37:45 -07005218 "out gl_PerVertex {\n"
5219 " vec4 gl_Position;\n"
5220 "};\n"
Chris Forbes3c10b852015-05-25 11:13:13 +12005221 "void main(){\n"
5222 " gl_Position = vec4(1);\n"
5223 "}\n";
5224 char const *fsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005225 "#version 450\n"
Chris Forbes3c10b852015-05-25 11:13:13 +12005226 "\n"
5227 "layout(location=0) in float x;\n"
5228 "layout(location=0) out vec4 color;\n"
5229 "void main(){\n"
5230 " color = vec4(x);\n"
5231 "}\n";
5232
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005233 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5234 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes3c10b852015-05-25 11:13:13 +12005235
5236 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08005237 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12005238 pipe.AddShader(&vs);
5239 pipe.AddShader(&fs);
5240
Chris Forbes3c10b852015-05-25 11:13:13 +12005241 VkDescriptorSetObj descriptorSet(m_device);
5242 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005243 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12005244
Tony Barboured132432015-08-04 16:23:11 -06005245 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12005246
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005247 if (!m_errorMonitor->DesiredMsgFound()) {
5248 FAIL() << "Did not receive Error 'not written by vertex shader'";
5249 m_errorMonitor->DumpFailureMsgs();
Chris Forbes3c10b852015-05-25 11:13:13 +12005250 }
5251}
5252
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005253TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes780820a2016-01-15 14:53:11 +13005254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005255 "not written by vertex shader");
Chris Forbes780820a2016-01-15 14:53:11 +13005256
5257 ASSERT_NO_FATAL_FAILURE(InitState());
5258 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5259
5260 char const *vsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005261 "#version 450\n"
Chris Forbes780820a2016-01-15 14:53:11 +13005262 "\n"
5263 "out gl_PerVertex {\n"
5264 " vec4 gl_Position;\n"
5265 "};\n"
5266 "void main(){\n"
5267 " gl_Position = vec4(1);\n"
5268 "}\n";
5269 char const *fsSource =
5270 "#version 450\n"
Chris Forbes780820a2016-01-15 14:53:11 +13005271 "\n"
5272 "in block { layout(location=0) float x; } ins;\n"
5273 "layout(location=0) out vec4 color;\n"
5274 "void main(){\n"
5275 " color = vec4(ins.x);\n"
5276 "}\n";
5277
5278 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5279 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5280
5281 VkPipelineObj pipe(m_device);
5282 pipe.AddColorAttachment();
5283 pipe.AddShader(&vs);
5284 pipe.AddShader(&fs);
5285
5286 VkDescriptorSetObj descriptorSet(m_device);
5287 descriptorSet.AppendDummy();
5288 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5289
5290 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5291
5292 if (!m_errorMonitor->DesiredMsgFound()) {
5293 FAIL() << "Did not receive Error 'not written by vertex shader'";
5294 m_errorMonitor->DumpFailureMsgs();
5295 }
5296}
5297
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005298TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbesf14d10d2016-01-26 14:19:49 +13005299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes12c72a42016-02-17 14:44:52 +13005300 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005301 "output arr[2] of float32' vs 'ptr to "
5302 "input arr[3] of float32'");
Chris Forbesf14d10d2016-01-26 14:19:49 +13005303
5304 ASSERT_NO_FATAL_FAILURE(InitState());
5305 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5306
5307 char const *vsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005308 "#version 450\n"
Chris Forbesf14d10d2016-01-26 14:19:49 +13005309 "\n"
5310 "layout(location=0) out float x[2];\n"
5311 "out gl_PerVertex {\n"
5312 " vec4 gl_Position;\n"
5313 "};\n"
5314 "void main(){\n"
5315 " x[0] = 0; x[1] = 0;\n"
5316 " gl_Position = vec4(1);\n"
5317 "}\n";
5318 char const *fsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005319 "#version 450\n"
Chris Forbesf14d10d2016-01-26 14:19:49 +13005320 "\n"
5321 "layout(location=0) in float x[3];\n"
5322 "layout(location=0) out vec4 color;\n"
5323 "void main(){\n"
5324 " color = vec4(x[0] + x[1] + x[2]);\n"
5325 "}\n";
5326
5327 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5328 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5329
5330 VkPipelineObj pipe(m_device);
5331 pipe.AddColorAttachment();
5332 pipe.AddShader(&vs);
5333 pipe.AddShader(&fs);
5334
5335 VkDescriptorSetObj descriptorSet(m_device);
5336 descriptorSet.AppendDummy();
5337 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5338
5339 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5340
5341 if (!m_errorMonitor->DesiredMsgFound()) {
5342 m_errorMonitor->DumpFailureMsgs();
Chris Forbes12c72a42016-02-17 14:44:52 +13005343 FAIL() << "Did not receive Error 'Type mismatch on location 0.0: 'ptr to "
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005344 "output arr[2] of float32' vs 'ptr to input arr[3] of "
5345 "float32''";
Chris Forbesf14d10d2016-01-26 14:19:49 +13005346 }
5347}
5348
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005349TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07005350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005351 "Type mismatch on location 0");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005352
Chris Forbescc281692015-05-25 11:13:17 +12005353 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06005354 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12005355
5356 char const *vsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005357 "#version 450\n"
Chris Forbescc281692015-05-25 11:13:17 +12005358 "\n"
5359 "layout(location=0) out int x;\n"
Tony Barbour19b5f922016-01-05 13:37:45 -07005360 "out gl_PerVertex {\n"
5361 " vec4 gl_Position;\n"
5362 "};\n"
Chris Forbescc281692015-05-25 11:13:17 +12005363 "void main(){\n"
5364 " x = 0;\n"
5365 " gl_Position = vec4(1);\n"
5366 "}\n";
5367 char const *fsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005368 "#version 450\n"
Chris Forbescc281692015-05-25 11:13:17 +12005369 "\n"
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005370 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbescc281692015-05-25 11:13:17 +12005371 "layout(location=0) out vec4 color;\n"
5372 "void main(){\n"
5373 " color = vec4(x);\n"
5374 "}\n";
5375
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005376 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5377 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbescc281692015-05-25 11:13:17 +12005378
5379 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08005380 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12005381 pipe.AddShader(&vs);
5382 pipe.AddShader(&fs);
5383
Chris Forbescc281692015-05-25 11:13:17 +12005384 VkDescriptorSetObj descriptorSet(m_device);
5385 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005386 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12005387
Tony Barboured132432015-08-04 16:23:11 -06005388 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12005389
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005390 if (!m_errorMonitor->DesiredMsgFound()) {
5391 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
5392 m_errorMonitor->DumpFailureMsgs();
Chris Forbescc281692015-05-25 11:13:17 +12005393 }
5394}
5395
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005396TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes780820a2016-01-15 14:53:11 +13005397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005398 "Type mismatch on location 0");
Chris Forbes780820a2016-01-15 14:53:11 +13005399
5400 ASSERT_NO_FATAL_FAILURE(InitState());
5401 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5402
5403 char const *vsSource =
5404 "#version 450\n"
Chris Forbes780820a2016-01-15 14:53:11 +13005405 "\n"
5406 "out block { layout(location=0) int x; } outs;\n"
5407 "out gl_PerVertex {\n"
5408 " vec4 gl_Position;\n"
5409 "};\n"
5410 "void main(){\n"
5411 " outs.x = 0;\n"
5412 " gl_Position = vec4(1);\n"
5413 "}\n";
5414 char const *fsSource =
5415 "#version 450\n"
Chris Forbes780820a2016-01-15 14:53:11 +13005416 "\n"
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005417 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbes780820a2016-01-15 14:53:11 +13005418 "layout(location=0) out vec4 color;\n"
5419 "void main(){\n"
5420 " color = vec4(ins.x);\n"
5421 "}\n";
5422
5423 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5424 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5425
5426 VkPipelineObj pipe(m_device);
5427 pipe.AddColorAttachment();
5428 pipe.AddShader(&vs);
5429 pipe.AddShader(&fs);
5430
5431 VkDescriptorSetObj descriptorSet(m_device);
5432 descriptorSet.AppendDummy();
5433 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5434
5435 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5436
5437 if (!m_errorMonitor->DesiredMsgFound()) {
Chris Forbes780820a2016-01-15 14:53:11 +13005438 m_errorMonitor->DumpFailureMsgs();
Chris Forbes12c72a42016-02-17 14:44:52 +13005439 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
5440 }
5441}
5442
5443TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
5444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5445 "location 0.0 which is not written by vertex shader");
5446
5447 ASSERT_NO_FATAL_FAILURE(InitState());
5448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5449
5450 char const *vsSource =
5451 "#version 450\n"
Chris Forbes12c72a42016-02-17 14:44:52 +13005452 "\n"
5453 "out block { layout(location=1) float x; } outs;\n"
5454 "out gl_PerVertex {\n"
5455 " vec4 gl_Position;\n"
5456 "};\n"
5457 "void main(){\n"
5458 " outs.x = 0;\n"
5459 " gl_Position = vec4(1);\n"
5460 "}\n";
5461 char const *fsSource =
5462 "#version 450\n"
Chris Forbes12c72a42016-02-17 14:44:52 +13005463 "\n"
5464 "in block { layout(location=0) float x; } ins;\n"
5465 "layout(location=0) out vec4 color;\n"
5466 "void main(){\n"
5467 " color = vec4(ins.x);\n"
5468 "}\n";
5469
5470 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5471 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5472
5473 VkPipelineObj pipe(m_device);
5474 pipe.AddColorAttachment();
5475 pipe.AddShader(&vs);
5476 pipe.AddShader(&fs);
5477
5478 VkDescriptorSetObj descriptorSet(m_device);
5479 descriptorSet.AppendDummy();
5480 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5481
5482 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5483
5484 if (!m_errorMonitor->DesiredMsgFound()) {
5485 m_errorMonitor->DumpFailureMsgs();
5486 FAIL() << "Did not receive Error 'location 0.0 which is not written by vertex shader'";
5487 }
5488}
5489
5490TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
5491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5492 "location 0.1 which is not written by vertex shader");
5493
5494 ASSERT_NO_FATAL_FAILURE(InitState());
5495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5496
5497 char const *vsSource =
5498 "#version 450\n"
Chris Forbes12c72a42016-02-17 14:44:52 +13005499 "\n"
5500 "out block { layout(location=0, component=0) float x; } outs;\n"
5501 "out gl_PerVertex {\n"
5502 " vec4 gl_Position;\n"
5503 "};\n"
5504 "void main(){\n"
5505 " outs.x = 0;\n"
5506 " gl_Position = vec4(1);\n"
5507 "}\n";
5508 char const *fsSource =
5509 "#version 450\n"
Chris Forbes12c72a42016-02-17 14:44:52 +13005510 "\n"
5511 "in block { layout(location=0, component=1) float x; } ins;\n"
5512 "layout(location=0) out vec4 color;\n"
5513 "void main(){\n"
5514 " color = vec4(ins.x);\n"
5515 "}\n";
5516
5517 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5518 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5519
5520 VkPipelineObj pipe(m_device);
5521 pipe.AddColorAttachment();
5522 pipe.AddShader(&vs);
5523 pipe.AddShader(&fs);
5524
5525 VkDescriptorSetObj descriptorSet(m_device);
5526 descriptorSet.AppendDummy();
5527 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5528
5529 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5530
5531 if (!m_errorMonitor->DesiredMsgFound()) {
5532 m_errorMonitor->DumpFailureMsgs();
5533 FAIL() << "Did not receive Error 'location 0.1 which is not written by vertex shader'";
Chris Forbes780820a2016-01-15 14:53:11 +13005534 }
5535}
5536
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005537TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski5c13d4d2016-02-11 09:26:16 -07005538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005539 "location 0 not consumed by VS");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005540
Chris Forbes8291c052015-05-25 11:13:28 +12005541 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06005542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12005543
5544 VkVertexInputBindingDescription input_binding;
5545 memset(&input_binding, 0, sizeof(input_binding));
5546
5547 VkVertexInputAttributeDescription input_attrib;
5548 memset(&input_attrib, 0, sizeof(input_attrib));
5549 input_attrib.format = VK_FORMAT_R32_SFLOAT;
5550
5551 char const *vsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005552 "#version 450\n"
Chris Forbes8291c052015-05-25 11:13:28 +12005553 "\n"
Tony Barbour19b5f922016-01-05 13:37:45 -07005554 "out gl_PerVertex {\n"
5555 " vec4 gl_Position;\n"
5556 "};\n"
Chris Forbes8291c052015-05-25 11:13:28 +12005557 "void main(){\n"
5558 " gl_Position = vec4(1);\n"
5559 "}\n";
5560 char const *fsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005561 "#version 450\n"
Chris Forbes8291c052015-05-25 11:13:28 +12005562 "\n"
5563 "layout(location=0) out vec4 color;\n"
5564 "void main(){\n"
5565 " color = vec4(1);\n"
5566 "}\n";
5567
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005568 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5569 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes8291c052015-05-25 11:13:28 +12005570
5571 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08005572 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12005573 pipe.AddShader(&vs);
5574 pipe.AddShader(&fs);
5575
5576 pipe.AddVertexInputBindings(&input_binding, 1);
5577 pipe.AddVertexInputAttribs(&input_attrib, 1);
5578
Chris Forbes8291c052015-05-25 11:13:28 +12005579 VkDescriptorSetObj descriptorSet(m_device);
5580 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005581 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12005582
Tony Barboured132432015-08-04 16:23:11 -06005583 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12005584
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005585 if (!m_errorMonitor->DesiredMsgFound()) {
5586 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
5587 m_errorMonitor->DumpFailureMsgs();
Chris Forbes8291c052015-05-25 11:13:28 +12005588 }
5589}
5590
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005591TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski5c13d4d2016-02-11 09:26:16 -07005592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005593 "location 0 not consumed by VS");
Chris Forbes5e42b882016-01-15 11:32:03 +13005594
5595 ASSERT_NO_FATAL_FAILURE(InitState());
5596 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5597
5598 VkVertexInputBindingDescription input_binding;
5599 memset(&input_binding, 0, sizeof(input_binding));
5600
5601 VkVertexInputAttributeDescription input_attrib;
5602 memset(&input_attrib, 0, sizeof(input_attrib));
5603 input_attrib.format = VK_FORMAT_R32_SFLOAT;
5604
5605 char const *vsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005606 "#version 450\n"
Chris Forbes5e42b882016-01-15 11:32:03 +13005607 "\n"
5608 "layout(location=1) in float x;\n"
5609 "out gl_PerVertex {\n"
5610 " vec4 gl_Position;\n"
5611 "};\n"
5612 "void main(){\n"
5613 " gl_Position = vec4(x);\n"
5614 "}\n";
5615 char const *fsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005616 "#version 450\n"
Chris Forbes5e42b882016-01-15 11:32:03 +13005617 "\n"
5618 "layout(location=0) out vec4 color;\n"
5619 "void main(){\n"
5620 " color = vec4(1);\n"
5621 "}\n";
5622
5623 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5624 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5625
5626 VkPipelineObj pipe(m_device);
5627 pipe.AddColorAttachment();
5628 pipe.AddShader(&vs);
5629 pipe.AddShader(&fs);
5630
5631 pipe.AddVertexInputBindings(&input_binding, 1);
5632 pipe.AddVertexInputAttribs(&input_attrib, 1);
5633
5634 VkDescriptorSetObj descriptorSet(m_device);
5635 descriptorSet.AppendDummy();
5636 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5637
5638 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5639
5640 if (!m_errorMonitor->DesiredMsgFound()) {
5641 m_errorMonitor->DumpFailureMsgs();
5642 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
5643 }
5644}
5645
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005646TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
5647 m_errorMonitor->SetDesiredFailureMsg(
5648 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005649 "VS consumes input at location 0 but not provided");
5650
Chris Forbes37367e62015-05-25 11:13:29 +12005651 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06005652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12005653
5654 char const *vsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005655 "#version 450\n"
Chris Forbes37367e62015-05-25 11:13:29 +12005656 "\n"
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005657 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barbour19b5f922016-01-05 13:37:45 -07005658 "out gl_PerVertex {\n"
5659 " vec4 gl_Position;\n"
5660 "};\n"
Chris Forbes37367e62015-05-25 11:13:29 +12005661 "void main(){\n"
5662 " gl_Position = x;\n"
5663 "}\n";
5664 char const *fsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005665 "#version 450\n"
Chris Forbes37367e62015-05-25 11:13:29 +12005666 "\n"
5667 "layout(location=0) out vec4 color;\n"
5668 "void main(){\n"
5669 " color = vec4(1);\n"
5670 "}\n";
5671
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005672 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5673 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes37367e62015-05-25 11:13:29 +12005674
5675 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08005676 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12005677 pipe.AddShader(&vs);
5678 pipe.AddShader(&fs);
5679
Chris Forbes37367e62015-05-25 11:13:29 +12005680 VkDescriptorSetObj descriptorSet(m_device);
5681 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005682 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12005683
Tony Barboured132432015-08-04 16:23:11 -06005684 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12005685
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005686 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005687 FAIL() << "Did not receive Error 'VS consumes input at location 0 but "
5688 "not provided'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005689 m_errorMonitor->DumpFailureMsgs();
Chris Forbes37367e62015-05-25 11:13:29 +12005690 }
5691}
5692
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005693TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
5694 m_errorMonitor->SetDesiredFailureMsg(
5695 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005696 "location 0 does not match VS input type");
5697
Chris Forbesa4b02322015-05-25 11:13:31 +12005698 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06005699 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12005700
5701 VkVertexInputBindingDescription input_binding;
5702 memset(&input_binding, 0, sizeof(input_binding));
5703
5704 VkVertexInputAttributeDescription input_attrib;
5705 memset(&input_attrib, 0, sizeof(input_attrib));
5706 input_attrib.format = VK_FORMAT_R32_SFLOAT;
5707
5708 char const *vsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005709 "#version 450\n"
Chris Forbesa4b02322015-05-25 11:13:31 +12005710 "\n"
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005711 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barbour19b5f922016-01-05 13:37:45 -07005712 "out gl_PerVertex {\n"
5713 " vec4 gl_Position;\n"
5714 "};\n"
Chris Forbesa4b02322015-05-25 11:13:31 +12005715 "void main(){\n"
5716 " gl_Position = vec4(x);\n"
5717 "}\n";
5718 char const *fsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005719 "#version 450\n"
Chris Forbesa4b02322015-05-25 11:13:31 +12005720 "\n"
5721 "layout(location=0) out vec4 color;\n"
5722 "void main(){\n"
5723 " color = vec4(1);\n"
5724 "}\n";
5725
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06005726 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5727 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa4b02322015-05-25 11:13:31 +12005728
5729 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08005730 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12005731 pipe.AddShader(&vs);
5732 pipe.AddShader(&fs);
5733
5734 pipe.AddVertexInputBindings(&input_binding, 1);
5735 pipe.AddVertexInputAttribs(&input_attrib, 1);
5736
Chris Forbesa4b02322015-05-25 11:13:31 +12005737 VkDescriptorSetObj descriptorSet(m_device);
5738 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08005739 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12005740
Tony Barboured132432015-08-04 16:23:11 -06005741 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12005742
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005743 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005744 FAIL() << "Did not receive Error 'location 0 does not match VS input "
5745 "type'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005746 m_errorMonitor->DumpFailureMsgs();
Chris Forbesa4b02322015-05-25 11:13:31 +12005747 }
5748}
5749
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005750TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes03e6d762015-11-24 11:13:14 +13005751 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
5752
5753 ASSERT_NO_FATAL_FAILURE(InitState());
5754 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5755
5756 VkVertexInputBindingDescription input_binding;
5757 memset(&input_binding, 0, sizeof(input_binding));
5758
5759 VkVertexInputAttributeDescription input_attribs[2];
5760 memset(input_attribs, 0, sizeof(input_attribs));
5761
5762 for (int i = 0; i < 2; i++) {
5763 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
5764 input_attribs[i].location = i;
5765 }
5766
5767 char const *vsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005768 "#version 450\n"
Chris Forbes03e6d762015-11-24 11:13:14 +13005769 "\n"
5770 "layout(location=0) in mat2x4 x;\n"
Tony Barbour19b5f922016-01-05 13:37:45 -07005771 "out gl_PerVertex {\n"
5772 " vec4 gl_Position;\n"
5773 "};\n"
Chris Forbes03e6d762015-11-24 11:13:14 +13005774 "void main(){\n"
5775 " gl_Position = x[0] + x[1];\n"
5776 "}\n";
5777 char const *fsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005778 "#version 450\n"
Chris Forbes03e6d762015-11-24 11:13:14 +13005779 "\n"
5780 "layout(location=0) out vec4 color;\n"
5781 "void main(){\n"
5782 " color = vec4(1);\n"
5783 "}\n";
5784
5785 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5786 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5787
5788 VkPipelineObj pipe(m_device);
5789 pipe.AddColorAttachment();
5790 pipe.AddShader(&vs);
5791 pipe.AddShader(&fs);
5792
5793 pipe.AddVertexInputBindings(&input_binding, 1);
5794 pipe.AddVertexInputAttribs(input_attribs, 2);
5795
5796 VkDescriptorSetObj descriptorSet(m_device);
5797 descriptorSet.AppendDummy();
5798 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5799
5800 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5801
5802 /* expect success */
5803 if (m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005804 FAIL() << "Expected to succeed but: "
5805 << m_errorMonitor->GetFailureMsg();
Chris Forbes03e6d762015-11-24 11:13:14 +13005806 m_errorMonitor->DumpFailureMsgs();
5807 }
5808}
5809
Chris Forbes03e6d762015-11-24 11:13:14 +13005810TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
5811{
5812 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
5813
5814 ASSERT_NO_FATAL_FAILURE(InitState());
5815 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5816
5817 VkVertexInputBindingDescription input_binding;
5818 memset(&input_binding, 0, sizeof(input_binding));
5819
5820 VkVertexInputAttributeDescription input_attribs[2];
5821 memset(input_attribs, 0, sizeof(input_attribs));
5822
5823 for (int i = 0; i < 2; i++) {
5824 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
5825 input_attribs[i].location = i;
5826 }
5827
5828 char const *vsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005829 "#version 450\n"
Chris Forbes03e6d762015-11-24 11:13:14 +13005830 "\n"
5831 "layout(location=0) in vec4 x[2];\n"
Tony Barbour19b5f922016-01-05 13:37:45 -07005832 "out gl_PerVertex {\n"
5833 " vec4 gl_Position;\n"
5834 "};\n"
Chris Forbes03e6d762015-11-24 11:13:14 +13005835 "void main(){\n"
5836 " gl_Position = x[0] + x[1];\n"
5837 "}\n";
5838 char const *fsSource =
Chris Forbes43494042016-04-04 17:28:05 +12005839 "#version 450\n"
Chris Forbes03e6d762015-11-24 11:13:14 +13005840 "\n"
5841 "layout(location=0) out vec4 color;\n"
5842 "void main(){\n"
5843 " color = vec4(1);\n"
5844 "}\n";
5845
5846 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5847 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5848
5849 VkPipelineObj pipe(m_device);
5850 pipe.AddColorAttachment();
5851 pipe.AddShader(&vs);
5852 pipe.AddShader(&fs);
5853
5854 pipe.AddVertexInputBindings(&input_binding, 1);
5855 pipe.AddVertexInputAttribs(input_attribs, 2);
5856
5857 VkDescriptorSetObj descriptorSet(m_device);
5858 descriptorSet.AppendDummy();
5859 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5860
5861 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5862
5863 if (m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07005864 FAIL() << "Expected to succeed but: " <<
5865m_errorMonitor->GetFailureMsg();
Chris Forbes03e6d762015-11-24 11:13:14 +13005866 m_errorMonitor->DumpFailureMsgs();
5867 }
5868}
Chris Forbes03e6d762015-11-24 11:13:14 +13005869
Chris Forbesf7782162016-04-04 18:52:54 +12005870TEST_F(VkLayerTest, CreatePipelineSimplePositive)
5871{
5872 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
5873
5874 ASSERT_NO_FATAL_FAILURE(InitState());
5875 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5876
5877 char const *vsSource =
5878 "#version 450\n"
5879 "out gl_PerVertex {\n"
5880 " vec4 gl_Position;\n"
5881 "};\n"
5882 "void main(){\n"
5883 " gl_Position = vec4(0);\n"
5884 "}\n";
5885 char const *fsSource =
5886 "#version 450\n"
5887 "\n"
5888 "layout(location=0) out vec4 color;\n"
5889 "void main(){\n"
5890 " color = vec4(1);\n"
5891 "}\n";
5892
5893 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5894 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5895
5896 VkPipelineObj pipe(m_device);
5897 pipe.AddColorAttachment();
5898 pipe.AddShader(&vs);
5899 pipe.AddShader(&fs);
5900
5901 VkDescriptorSetObj descriptorSet(m_device);
5902 descriptorSet.AppendDummy();
5903 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5904
5905 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5906
5907 if (m_errorMonitor->DesiredMsgFound()) {
5908 FAIL() << "Expected to succeed but: " <<
5909m_errorMonitor->GetFailureMsg();
5910 m_errorMonitor->DumpFailureMsgs();
5911 }
5912}
5913
5914TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
5915{
5916 m_errorMonitor->SetDesiredFailureMsg(~0u, "");
5917
5918 ASSERT_NO_FATAL_FAILURE(InitState());
5919 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5920
Chris Forbes0ce57ea2016-04-04 19:26:42 +12005921 if (!m_device->phy().features().tessellationShader) {
5922 printf("Device does not support tessellation shaders; skipped.\n");
5923 return;
5924 }
5925
Chris Forbesf7782162016-04-04 18:52:54 +12005926 char const *vsSource =
5927 "#version 450\n"
5928 "void main(){}\n";
5929 char const *tcsSource =
5930 "#version 450\n"
5931 "layout(location=0) out int x[];\n"
5932 "layout(vertices=3) out;\n"
5933 "void main(){\n"
5934 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
5935 " gl_TessLevelInner[0] = 1;\n"
5936 " x[gl_InvocationID] = gl_InvocationID;\n"
5937 "}\n";
5938 char const *tesSource =
5939 "#version 450\n"
5940 "layout(triangles, equal_spacing, cw) in;\n"
5941 "layout(location=0) in int x[];\n"
5942 "out gl_PerVertex { vec4 gl_Position; };\n"
5943 "void main(){\n"
5944 " gl_Position.xyz = gl_TessCoord;\n"
5945 " gl_Position.w = x[0] + x[1] + x[2];\n"
5946 "}\n";
5947 char const *fsSource =
5948 "#version 450\n"
5949 "layout(location=0) out vec4 color;\n"
5950 "void main(){\n"
5951 " color = vec4(1);\n"
5952 "}\n";
5953
5954 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5955 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
5956 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
5957 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5958
5959 VkPipelineInputAssemblyStateCreateInfo iasci{
5960 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
5961 nullptr,
5962 0,
5963 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
5964 VK_FALSE};
5965
Chris Forbes8c13a2e2016-04-04 19:15:00 +12005966 VkPipelineTessellationStateCreateInfo tsci{
5967 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
5968 nullptr,
5969 0,
5970 3};
5971
Chris Forbesf7782162016-04-04 18:52:54 +12005972 VkPipelineObj pipe(m_device);
5973 pipe.SetInputAssembly(&iasci);
Chris Forbes8c13a2e2016-04-04 19:15:00 +12005974 pipe.SetTessellation(&tsci);
Chris Forbesf7782162016-04-04 18:52:54 +12005975 pipe.AddColorAttachment();
5976 pipe.AddShader(&vs);
5977 pipe.AddShader(&tcs);
5978 pipe.AddShader(&tes);
5979 pipe.AddShader(&fs);
5980
5981 VkDescriptorSetObj descriptorSet(m_device);
5982 descriptorSet.AppendDummy();
5983 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
5984
5985 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
5986
5987 if (m_errorMonitor->DesiredMsgFound()) {
5988 m_errorMonitor->DumpFailureMsgs();
5989 FAIL() << "Expected to succeed but: " <<
5990m_errorMonitor->GetFailureMsg();
5991 }
5992}
5993
Chris Forbesf706c502016-04-04 19:19:47 +12005994TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
5995{
5996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5997 "is per-vertex in tessellation control shader stage "
5998 "but per-patch in tessellation evaluation shader stage");
5999
6000 ASSERT_NO_FATAL_FAILURE(InitState());
6001 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6002
Chris Forbes0ce57ea2016-04-04 19:26:42 +12006003 if (!m_device->phy().features().tessellationShader) {
6004 printf("Device does not support tessellation shaders; skipped.\n");
6005 return;
6006 }
6007
Chris Forbesf706c502016-04-04 19:19:47 +12006008 char const *vsSource =
6009 "#version 450\n"
6010 "void main(){}\n";
6011 char const *tcsSource =
6012 "#version 450\n"
6013 "layout(location=0) out int x[];\n"
6014 "layout(vertices=3) out;\n"
6015 "void main(){\n"
6016 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
6017 " gl_TessLevelInner[0] = 1;\n"
6018 " x[gl_InvocationID] = gl_InvocationID;\n"
6019 "}\n";
6020 char const *tesSource =
6021 "#version 450\n"
6022 "layout(triangles, equal_spacing, cw) in;\n"
6023 "layout(location=0) patch in int x;\n"
6024 "out gl_PerVertex { vec4 gl_Position; };\n"
6025 "void main(){\n"
6026 " gl_Position.xyz = gl_TessCoord;\n"
6027 " gl_Position.w = x;\n"
6028 "}\n";
6029 char const *fsSource =
6030 "#version 450\n"
6031 "layout(location=0) out vec4 color;\n"
6032 "void main(){\n"
6033 " color = vec4(1);\n"
6034 "}\n";
6035
6036 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6037 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
6038 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
6039 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6040
6041 VkPipelineInputAssemblyStateCreateInfo iasci{
6042 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
6043 nullptr,
6044 0,
6045 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
6046 VK_FALSE};
6047
6048 VkPipelineTessellationStateCreateInfo tsci{
6049 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
6050 nullptr,
6051 0,
6052 3};
6053
6054 VkPipelineObj pipe(m_device);
6055 pipe.SetInputAssembly(&iasci);
6056 pipe.SetTessellation(&tsci);
6057 pipe.AddColorAttachment();
6058 pipe.AddShader(&vs);
6059 pipe.AddShader(&tcs);
6060 pipe.AddShader(&tes);
6061 pipe.AddShader(&fs);
6062
6063 VkDescriptorSetObj descriptorSet(m_device);
6064 descriptorSet.AppendDummy();
6065 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6066
6067 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6068
6069 if (!m_errorMonitor->DesiredMsgFound()) {
6070 m_errorMonitor->DumpFailureMsgs();
6071 FAIL() << "Did not receive Error 'is per-vertex in tessellation control shader stage...'";
6072 }
6073}
6074
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006075TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
6076 m_errorMonitor->SetDesiredFailureMsg(
6077 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006078 "Duplicate vertex input binding descriptions for binding 0");
6079
Chris Forbes0bf8fe12015-06-12 11:16:41 +12006080 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06006081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12006082
6083 /* Two binding descriptions for binding 0 */
6084 VkVertexInputBindingDescription input_bindings[2];
6085 memset(input_bindings, 0, sizeof(input_bindings));
6086
6087 VkVertexInputAttributeDescription input_attrib;
6088 memset(&input_attrib, 0, sizeof(input_attrib));
6089 input_attrib.format = VK_FORMAT_R32_SFLOAT;
6090
6091 char const *vsSource =
Chris Forbes43494042016-04-04 17:28:05 +12006092 "#version 450\n"
Chris Forbes0bf8fe12015-06-12 11:16:41 +12006093 "\n"
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006094 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barbour19b5f922016-01-05 13:37:45 -07006095 "out gl_PerVertex {\n"
6096 " vec4 gl_Position;\n"
6097 "};\n"
Chris Forbes0bf8fe12015-06-12 11:16:41 +12006098 "void main(){\n"
6099 " gl_Position = vec4(x);\n"
6100 "}\n";
6101 char const *fsSource =
Chris Forbes43494042016-04-04 17:28:05 +12006102 "#version 450\n"
Chris Forbes0bf8fe12015-06-12 11:16:41 +12006103 "\n"
6104 "layout(location=0) out vec4 color;\n"
6105 "void main(){\n"
6106 " color = vec4(1);\n"
6107 "}\n";
6108
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06006109 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6110 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12006111
6112 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08006113 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12006114 pipe.AddShader(&vs);
6115 pipe.AddShader(&fs);
6116
6117 pipe.AddVertexInputBindings(input_bindings, 2);
6118 pipe.AddVertexInputAttribs(&input_attrib, 1);
6119
Chris Forbes0bf8fe12015-06-12 11:16:41 +12006120 VkDescriptorSetObj descriptorSet(m_device);
6121 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08006122 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12006123
Tony Barboured132432015-08-04 16:23:11 -06006124 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12006125
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006126 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006127 FAIL() << "Did not receive Error 'Duplicate vertex input binding "
6128 "descriptions for binding 0'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006129 m_errorMonitor->DumpFailureMsgs();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12006130 }
6131}
Chris Forbes4c948702015-05-25 11:13:32 +12006132
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006133TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07006134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006135 "Attachment 0 not written by FS");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006136
Chris Forbesc12ef122015-05-25 11:13:40 +12006137 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12006138
6139 char const *vsSource =
Chris Forbes43494042016-04-04 17:28:05 +12006140 "#version 450\n"
Chris Forbesc12ef122015-05-25 11:13:40 +12006141 "\n"
Tony Barbour19b5f922016-01-05 13:37:45 -07006142 "out gl_PerVertex {\n"
6143 " vec4 gl_Position;\n"
6144 "};\n"
Chris Forbesc12ef122015-05-25 11:13:40 +12006145 "void main(){\n"
6146 " gl_Position = vec4(1);\n"
6147 "}\n";
6148 char const *fsSource =
Chris Forbes43494042016-04-04 17:28:05 +12006149 "#version 450\n"
Chris Forbesc12ef122015-05-25 11:13:40 +12006150 "\n"
6151 "void main(){\n"
6152 "}\n";
6153
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06006154 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6155 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc12ef122015-05-25 11:13:40 +12006156
6157 VkPipelineObj pipe(m_device);
6158 pipe.AddShader(&vs);
6159 pipe.AddShader(&fs);
6160
Chia-I Wuc278df82015-07-07 11:50:03 +08006161 /* set up CB 0, not written */
6162 pipe.AddColorAttachment();
6163 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12006164
Chris Forbesc12ef122015-05-25 11:13:40 +12006165 VkDescriptorSetObj descriptorSet(m_device);
6166 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08006167 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12006168
Tony Barboured132432015-08-04 16:23:11 -06006169 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12006170
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006171 if (!m_errorMonitor->DesiredMsgFound()) {
6172 FAIL() << "Did not receive Error 'Attachment 0 not written by FS'";
6173 m_errorMonitor->DumpFailureMsgs();
Chris Forbesc12ef122015-05-25 11:13:40 +12006174 }
6175}
6176
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006177TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07006178 // TODO: verify that this matches layer
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006179 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski5c13d4d2016-02-11 09:26:16 -07006180 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006181 "FS writes to output location 1 with no matching attachment");
6182
Chris Forbes5d15a4f2015-05-25 11:13:43 +12006183 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12006184
6185 char const *vsSource =
Chris Forbes43494042016-04-04 17:28:05 +12006186 "#version 450\n"
Chris Forbes5d15a4f2015-05-25 11:13:43 +12006187 "\n"
Tony Barbour19b5f922016-01-05 13:37:45 -07006188 "out gl_PerVertex {\n"
6189 " vec4 gl_Position;\n"
6190 "};\n"
Chris Forbes5d15a4f2015-05-25 11:13:43 +12006191 "void main(){\n"
6192 " gl_Position = vec4(1);\n"
6193 "}\n";
6194 char const *fsSource =
Chris Forbes43494042016-04-04 17:28:05 +12006195 "#version 450\n"
Chris Forbes5d15a4f2015-05-25 11:13:43 +12006196 "\n"
6197 "layout(location=0) out vec4 x;\n"
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006198 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbes5d15a4f2015-05-25 11:13:43 +12006199 "void main(){\n"
6200 " x = vec4(1);\n"
6201 " y = vec4(1);\n"
6202 "}\n";
6203
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06006204 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6205 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12006206
6207 VkPipelineObj pipe(m_device);
6208 pipe.AddShader(&vs);
6209 pipe.AddShader(&fs);
6210
Chia-I Wuc278df82015-07-07 11:50:03 +08006211 /* set up CB 0, not written */
6212 pipe.AddColorAttachment();
6213 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12006214 /* FS writes CB 1, but we don't configure it */
6215
Chris Forbes5d15a4f2015-05-25 11:13:43 +12006216 VkDescriptorSetObj descriptorSet(m_device);
6217 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08006218 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12006219
Tony Barboured132432015-08-04 16:23:11 -06006220 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12006221
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006222 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006223 FAIL() << "Did not receive Error 'FS writes to output location 1 with "
6224 "no matching attachment'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006225 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5d15a4f2015-05-25 11:13:43 +12006226 }
6227}
6228
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006229TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07006230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006231 "does not match FS output type");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006232
Chris Forbes7d64a4f2015-05-25 11:13:44 +12006233 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12006234
6235 char const *vsSource =
Chris Forbes43494042016-04-04 17:28:05 +12006236 "#version 450\n"
Chris Forbes7d64a4f2015-05-25 11:13:44 +12006237 "\n"
Tony Barbour19b5f922016-01-05 13:37:45 -07006238 "out gl_PerVertex {\n"
6239 " vec4 gl_Position;\n"
6240 "};\n"
Chris Forbes7d64a4f2015-05-25 11:13:44 +12006241 "void main(){\n"
6242 " gl_Position = vec4(1);\n"
6243 "}\n";
6244 char const *fsSource =
Chris Forbes43494042016-04-04 17:28:05 +12006245 "#version 450\n"
Chris Forbes7d64a4f2015-05-25 11:13:44 +12006246 "\n"
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006247 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbes7d64a4f2015-05-25 11:13:44 +12006248 "void main(){\n"
6249 " x = ivec4(1);\n"
6250 "}\n";
6251
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06006252 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6253 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12006254
6255 VkPipelineObj pipe(m_device);
6256 pipe.AddShader(&vs);
6257 pipe.AddShader(&fs);
6258
Chia-I Wuc278df82015-07-07 11:50:03 +08006259 /* set up CB 0; type is UNORM by default */
6260 pipe.AddColorAttachment();
6261 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12006262
Chris Forbes7d64a4f2015-05-25 11:13:44 +12006263 VkDescriptorSetObj descriptorSet(m_device);
6264 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08006265 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12006266
Tony Barboured132432015-08-04 16:23:11 -06006267 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12006268
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006269 if (!m_errorMonitor->DesiredMsgFound()) {
6270 FAIL() << "Did not receive Error 'does not match FS output type'";
6271 m_errorMonitor->DumpFailureMsgs();
Chris Forbes7d64a4f2015-05-25 11:13:44 +12006272 }
6273}
Chris Forbesc2050732015-06-05 14:43:36 +12006274
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006275TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07006276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006277 "not declared in pipeline layout");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006278
Chris Forbes76ce7882015-08-14 12:04:59 +12006279 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +12006280
6281 char const *vsSource =
Chris Forbes43494042016-04-04 17:28:05 +12006282 "#version 450\n"
Chris Forbes76ce7882015-08-14 12:04:59 +12006283 "\n"
Tony Barbour19b5f922016-01-05 13:37:45 -07006284 "out gl_PerVertex {\n"
6285 " vec4 gl_Position;\n"
6286 "};\n"
Chris Forbes76ce7882015-08-14 12:04:59 +12006287 "void main(){\n"
6288 " gl_Position = vec4(1);\n"
6289 "}\n";
6290 char const *fsSource =
Chris Forbes43494042016-04-04 17:28:05 +12006291 "#version 450\n"
Chris Forbes76ce7882015-08-14 12:04:59 +12006292 "\n"
6293 "layout(location=0) out vec4 x;\n"
6294 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6295 "void main(){\n"
6296 " x = vec4(bar.y);\n"
6297 "}\n";
6298
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06006299 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6300 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes76ce7882015-08-14 12:04:59 +12006301
Chris Forbes76ce7882015-08-14 12:04:59 +12006302 VkPipelineObj pipe(m_device);
6303 pipe.AddShader(&vs);
6304 pipe.AddShader(&fs);
6305
6306 /* set up CB 0; type is UNORM by default */
6307 pipe.AddColorAttachment();
6308 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6309
6310 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1f851912015-10-27 18:04:07 +08006311 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes76ce7882015-08-14 12:04:59 +12006312
6313 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6314
6315 /* should have generated an error -- pipeline layout does not
6316 * provide a uniform buffer in 0.0
6317 */
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006318 if (!m_errorMonitor->DesiredMsgFound()) {
6319 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
6320 m_errorMonitor->DumpFailureMsgs();
Chris Forbes76ce7882015-08-14 12:04:59 +12006321 }
6322}
6323
Chris Forbes680e9b72016-02-26 16:56:09 +13006324TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
6325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6326 "not declared in layout");
6327
6328 ASSERT_NO_FATAL_FAILURE(InitState());
6329
6330 char const *vsSource =
6331 "#version 450\n"
Chris Forbes680e9b72016-02-26 16:56:09 +13006332 "\n"
6333 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
6334 "out gl_PerVertex {\n"
6335 " vec4 gl_Position;\n"
6336 "};\n"
6337 "void main(){\n"
6338 " gl_Position = vec4(consts.x);\n"
6339 "}\n";
6340 char const *fsSource =
6341 "#version 450\n"
Chris Forbes680e9b72016-02-26 16:56:09 +13006342 "\n"
6343 "layout(location=0) out vec4 x;\n"
6344 "void main(){\n"
6345 " x = vec4(1);\n"
6346 "}\n";
6347
6348 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6349 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6350
6351 VkPipelineObj pipe(m_device);
6352 pipe.AddShader(&vs);
6353 pipe.AddShader(&fs);
6354
6355 /* set up CB 0; type is UNORM by default */
6356 pipe.AddColorAttachment();
6357 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6358
6359 VkDescriptorSetObj descriptorSet(m_device);
6360 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
6361
6362 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
6363
6364 /* should have generated an error -- no push constant ranges provided! */
6365 if (!m_errorMonitor->DesiredMsgFound()) {
6366 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
6367 m_errorMonitor->DumpFailureMsgs();
6368 }
6369}
6370
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06006371#endif // SHADER_CHECKER_TESTS
6372
6373#if DEVICE_LIMITS_TESTS
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006374TEST_F(VkLayerTest, CreateImageLimitsViolationWidth) {
6375 m_errorMonitor->SetDesiredFailureMsg(
6376 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006377 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06006378
6379 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06006380
6381 // Create an image
6382 VkImage image;
6383
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006384 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6385 const int32_t tex_width = 32;
6386 const int32_t tex_height = 32;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06006387
6388 VkImageCreateInfo image_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006389 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6390 image_create_info.pNext = NULL;
6391 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6392 image_create_info.format = tex_format;
6393 image_create_info.extent.width = tex_width;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06006394 image_create_info.extent.height = tex_height;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006395 image_create_info.extent.depth = 1;
6396 image_create_info.mipLevels = 1;
6397 image_create_info.arrayLayers = 1;
6398 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6399 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
6400 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6401 image_create_info.flags = 0;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06006402
6403 // Introduce error by sending down a bogus width extent
6404 image_create_info.extent.width = 65536;
Chia-I Wu69f40122015-10-26 21:10:41 +08006405 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06006406
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006407 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006408 FAIL() << "Did not receive Error 'CreateImage extents exceed allowable "
6409 "limits for format'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006410 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06006411 }
6412}
6413
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006414TEST_F(VkLayerTest, UpdateBufferAlignment) {
6415 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mike Stroyan43909d82015-09-25 13:39:21 -06006416
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07006417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006418 "dstOffset, is not a multiple of 4");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006419
Mike Stroyan43909d82015-09-25 13:39:21 -06006420 ASSERT_NO_FATAL_FAILURE(InitState());
6421
6422 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
6423 vk_testing::Buffer buffer;
6424 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
6425
6426 BeginCommandBuffer();
6427 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08006428 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006429 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006430 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, "
6431 "VkDeviceSize dstOffset, is not a multiple of 4'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006432 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06006433 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006434
Mike Stroyan43909d82015-09-25 13:39:21 -06006435 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07006436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006437 "dataSize, is not a multiple of 4");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006438
Chia-I Wu1f851912015-10-27 18:04:07 +08006439 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006440
6441 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006442 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, "
6443 "VkDeviceSize dataSize, is not a multiple of 4'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006444 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06006445 }
6446 EndCommandBuffer();
6447}
6448
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006449TEST_F(VkLayerTest, FillBufferAlignment) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07006450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006451 "dstOffset, is not a multiple of 4");
Mike Stroyan43909d82015-09-25 13:39:21 -06006452
6453 ASSERT_NO_FATAL_FAILURE(InitState());
6454
6455 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
6456 vk_testing::Buffer buffer;
6457 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
6458
6459 BeginCommandBuffer();
6460 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08006461 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006462 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006463 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, "
6464 "VkDeviceSize dstOffset, is not a multiple of 4'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006465 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06006466 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006467
Mike Stroyan43909d82015-09-25 13:39:21 -06006468 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07006469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006470 "size, is not a multiple of 4");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006471
Chia-I Wu1f851912015-10-27 18:04:07 +08006472 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006473
6474 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006475 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, "
6476 "VkDeviceSize size, is not a multiple of 4'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006477 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06006478 }
6479 EndCommandBuffer();
6480}
6481
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06006482#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12006483
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06006484#if IMAGE_TESTS
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006485TEST_F(VkLayerTest, InvalidImageView) {
6486 VkResult err;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06006487
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006488 m_errorMonitor->SetDesiredFailureMsg(
6489 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006490 "vkCreateImageView called with baseMipLevel 10 ");
6491
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06006492 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06006493
Mike Stroyan43909d82015-09-25 13:39:21 -06006494 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006495 VkImage image;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06006496
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006497 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6498 const int32_t tex_width = 32;
6499 const int32_t tex_height = 32;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06006500
6501 VkImageCreateInfo image_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006502 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6503 image_create_info.pNext = NULL;
6504 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6505 image_create_info.format = tex_format;
6506 image_create_info.extent.width = tex_width;
6507 image_create_info.extent.height = tex_height;
6508 image_create_info.extent.depth = 1;
6509 image_create_info.mipLevels = 1;
6510 image_create_info.arrayLayers = 1;
6511 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6512 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
6513 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6514 image_create_info.flags = 0;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06006515
Chia-I Wu69f40122015-10-26 21:10:41 +08006516 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06006517 ASSERT_VK_SUCCESS(err);
6518
6519 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006520 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6521 image_view_create_info.image = image;
6522 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6523 image_view_create_info.format = tex_format;
6524 image_view_create_info.subresourceRange.layerCount = 1;
6525 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
6526 image_view_create_info.subresourceRange.levelCount = 1;
6527 image_view_create_info.subresourceRange.aspectMask =
6528 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06006529
6530 VkImageView view;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006531 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
6532 &view);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06006533
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006534 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006535 FAIL() << "Did not receive Error 'vkCreateImageView called with "
6536 "baseMipLevel 10...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006537 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06006538 }
6539}
Mike Stroyan43909d82015-09-25 13:39:21 -06006540
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006541TEST_F(VkLayerTest, InvalidImageViewAspect) {
6542 VkResult err;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06006543
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -07006544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006545 "vkCreateImageView: Color image "
6546 "formats must have ONLY the "
6547 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006548
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06006549 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06006550
6551 // Create an image and try to create a view with an invalid aspectMask
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006552 VkImage image;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06006553
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006554 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6555 const int32_t tex_width = 32;
6556 const int32_t tex_height = 32;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06006557
6558 VkImageCreateInfo image_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006559 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6560 image_create_info.pNext = NULL;
6561 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6562 image_create_info.format = tex_format;
6563 image_create_info.extent.width = tex_width;
6564 image_create_info.extent.height = tex_height;
6565 image_create_info.extent.depth = 1;
6566 image_create_info.mipLevels = 1;
6567 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6568 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
6569 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6570 image_create_info.flags = 0;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06006571
Chia-I Wu69f40122015-10-26 21:10:41 +08006572 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06006573 ASSERT_VK_SUCCESS(err);
6574
6575 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006576 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6577 image_view_create_info.image = image;
6578 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6579 image_view_create_info.format = tex_format;
6580 image_view_create_info.subresourceRange.baseMipLevel = 0;
6581 image_view_create_info.subresourceRange.levelCount = 1;
6582 // Cause an error by setting an invalid image aspect
6583 image_view_create_info.subresourceRange.aspectMask =
6584 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06006585
6586 VkImageView view;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006587 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
6588 &view);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06006589
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006590 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006591 FAIL() << "Did not receive Error 'VkCreateImageView: Color image "
6592 "formats must have ...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006593 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06006594 }
6595}
6596
Mark Lobodzinski298f1c12016-03-31 10:45:56 -06006597TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006598 VkResult err;
6599 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06006600
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006601 m_errorMonitor->SetDesiredFailureMsg(
6602 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski298f1c12016-03-31 10:45:56 -06006603 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006604
Mike Stroyan43909d82015-09-25 13:39:21 -06006605 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06006606
6607 // Create two images of different types and try to copy between them
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006608 VkImage srcImage;
6609 VkImage dstImage;
6610 VkDeviceMemory srcMem;
6611 VkDeviceMemory destMem;
6612 VkMemoryRequirements memReqs;
Mike Stroyan43909d82015-09-25 13:39:21 -06006613
6614 VkImageCreateInfo image_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006615 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6616 image_create_info.pNext = NULL;
6617 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6618 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6619 image_create_info.extent.width = 32;
6620 image_create_info.extent.height = 32;
6621 image_create_info.extent.depth = 1;
6622 image_create_info.mipLevels = 1;
Mark Lobodzinski298f1c12016-03-31 10:45:56 -06006623 image_create_info.arrayLayers = 4;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006624 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6625 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6626 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
6627 image_create_info.flags = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006628
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006629 err =
6630 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06006631 ASSERT_VK_SUCCESS(err);
6632
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006633 err =
6634 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06006635 ASSERT_VK_SUCCESS(err);
6636
6637 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08006638 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006639 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6640 memAlloc.pNext = NULL;
6641 memAlloc.allocationSize = 0;
6642 memAlloc.memoryTypeIndex = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006643
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06006644 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06006645 memAlloc.allocationSize = memReqs.size;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006646 pass =
6647 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06006648 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08006649 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06006650 ASSERT_VK_SUCCESS(err);
6651
Chia-I Wu1f851912015-10-27 18:04:07 +08006652 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06006653 memAlloc.allocationSize = memReqs.size;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006654 pass =
6655 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06006656 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08006657 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06006658 ASSERT_VK_SUCCESS(err);
6659
6660 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6661 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08006662 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06006663 ASSERT_VK_SUCCESS(err);
6664
6665 BeginCommandBuffer();
6666 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08006667 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006668 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06006669 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinski298f1c12016-03-31 10:45:56 -06006670 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06006671 copyRegion.srcOffset.x = 0;
6672 copyRegion.srcOffset.y = 0;
6673 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08006674 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08006675 copyRegion.dstSubresource.mipLevel = 0;
6676 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinski298f1c12016-03-31 10:45:56 -06006677 // Introduce failure by forcing the dst layerCount to differ from src
6678 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu1f851912015-10-27 18:04:07 +08006679 copyRegion.dstOffset.x = 0;
6680 copyRegion.dstOffset.y = 0;
6681 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006682 copyRegion.extent.width = 1;
6683 copyRegion.extent.height = 1;
6684 copyRegion.extent.depth = 1;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006685 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
6686 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06006687 EndCommandBuffer();
6688
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006689 if (!m_errorMonitor->DesiredMsgFound()) {
Mark Lobodzinski298f1c12016-03-31 10:45:56 -06006690 FAIL() << "Did not receive Error 'vkCmdCopyImage: number of layers in "
6691 "source and destination subresources for pRegions'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006692 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06006693 }
6694
Chia-I Wu69f40122015-10-26 21:10:41 +08006695 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08006696 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08006697 vkFreeMemory(m_device->device(), srcMem, NULL);
6698 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06006699}
6700
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006701TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
6702 // TODO : Create two images with different format sizes and vkCmdCopyImage
6703 // between them
Mike Stroyan43909d82015-09-25 13:39:21 -06006704}
6705
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006706TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
6707 VkResult err;
6708 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06006709
Mark Lobodzinski298f1c12016-03-31 10:45:56 -06006710 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006711 m_errorMonitor->SetDesiredFailureMsg(
6712 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski298f1c12016-03-31 10:45:56 -06006713 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006714
Mike Stroyan43909d82015-09-25 13:39:21 -06006715 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06006716
6717 // Create two images of different types and try to copy between them
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006718 VkImage srcImage;
6719 VkImage dstImage;
6720 VkDeviceMemory srcMem;
6721 VkDeviceMemory destMem;
6722 VkMemoryRequirements memReqs;
Mike Stroyan43909d82015-09-25 13:39:21 -06006723
6724 VkImageCreateInfo image_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006725 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6726 image_create_info.pNext = NULL;
6727 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6728 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6729 image_create_info.extent.width = 32;
6730 image_create_info.extent.height = 32;
6731 image_create_info.extent.depth = 1;
6732 image_create_info.mipLevels = 1;
6733 image_create_info.arrayLayers = 1;
6734 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6735 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
6736 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
6737 image_create_info.flags = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006738
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006739 err =
6740 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06006741 ASSERT_VK_SUCCESS(err);
6742
Mark Lobodzinski298f1c12016-03-31 10:45:56 -06006743 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006744 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinski298f1c12016-03-31 10:45:56 -06006745 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
6746 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006747
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006748 err =
6749 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06006750 ASSERT_VK_SUCCESS(err);
6751
6752 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08006753 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006754 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6755 memAlloc.pNext = NULL;
6756 memAlloc.allocationSize = 0;
6757 memAlloc.memoryTypeIndex = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006758
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06006759 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06006760 memAlloc.allocationSize = memReqs.size;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006761 pass =
6762 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06006763 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08006764 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06006765 ASSERT_VK_SUCCESS(err);
6766
Chia-I Wu1f851912015-10-27 18:04:07 +08006767 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06006768 memAlloc.allocationSize = memReqs.size;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006769 pass =
6770 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06006771 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08006772 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06006773 ASSERT_VK_SUCCESS(err);
6774
6775 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6776 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08006777 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06006778 ASSERT_VK_SUCCESS(err);
6779
6780 BeginCommandBuffer();
6781 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08006782 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006783 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06006784 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08006785 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006786 copyRegion.srcOffset.x = 0;
6787 copyRegion.srcOffset.y = 0;
6788 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08006789 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08006790 copyRegion.dstSubresource.mipLevel = 0;
6791 copyRegion.dstSubresource.baseArrayLayer = 0;
6792 copyRegion.dstSubresource.layerCount = 0;
6793 copyRegion.dstOffset.x = 0;
6794 copyRegion.dstOffset.y = 0;
6795 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006796 copyRegion.extent.width = 1;
6797 copyRegion.extent.height = 1;
6798 copyRegion.extent.depth = 1;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006799 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
6800 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06006801 EndCommandBuffer();
6802
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006803 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006804 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched "
Mark Lobodzinski298f1c12016-03-31 10:45:56 -06006805 "source and dest image depth/stencil formats'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006806 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06006807 }
6808
Chia-I Wu69f40122015-10-26 21:10:41 +08006809 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08006810 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08006811 vkFreeMemory(m_device->device(), srcMem, NULL);
6812 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06006813}
6814
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006815TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
6816 VkResult err;
6817 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06006818
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006819 m_errorMonitor->SetDesiredFailureMsg(
6820 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006821 "vkCmdResolveImage called with source sample count less than 2.");
6822
Mike Stroyan43909d82015-09-25 13:39:21 -06006823 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06006824
6825 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006826 VkImage srcImage;
6827 VkImage dstImage;
6828 VkDeviceMemory srcMem;
6829 VkDeviceMemory destMem;
6830 VkMemoryRequirements memReqs;
Mike Stroyan43909d82015-09-25 13:39:21 -06006831
6832 VkImageCreateInfo image_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006833 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6834 image_create_info.pNext = NULL;
6835 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6836 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6837 image_create_info.extent.width = 32;
6838 image_create_info.extent.height = 1;
6839 image_create_info.extent.depth = 1;
6840 image_create_info.mipLevels = 1;
6841 image_create_info.arrayLayers = 1;
6842 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6843 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6844 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
6845 image_create_info.flags = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006846
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006847 err =
6848 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06006849 ASSERT_VK_SUCCESS(err);
6850
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006851 image_create_info.imageType = VK_IMAGE_TYPE_1D;
6852 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006853
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006854 err =
6855 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06006856 ASSERT_VK_SUCCESS(err);
6857
6858 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08006859 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006860 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6861 memAlloc.pNext = NULL;
6862 memAlloc.allocationSize = 0;
6863 memAlloc.memoryTypeIndex = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006864
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06006865 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06006866 memAlloc.allocationSize = memReqs.size;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006867 pass =
6868 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06006869 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08006870 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06006871 ASSERT_VK_SUCCESS(err);
6872
Chia-I Wu1f851912015-10-27 18:04:07 +08006873 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06006874 memAlloc.allocationSize = memReqs.size;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006875 pass =
6876 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06006877 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08006878 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06006879 ASSERT_VK_SUCCESS(err);
6880
6881 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6882 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08006883 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06006884 ASSERT_VK_SUCCESS(err);
6885
6886 BeginCommandBuffer();
6887 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006888 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
6889 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyan43909d82015-09-25 13:39:21 -06006890 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08006891 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006892 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06006893 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08006894 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006895 resolveRegion.srcOffset.x = 0;
6896 resolveRegion.srcOffset.y = 0;
6897 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08006898 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08006899 resolveRegion.dstSubresource.mipLevel = 0;
6900 resolveRegion.dstSubresource.baseArrayLayer = 0;
6901 resolveRegion.dstSubresource.layerCount = 0;
6902 resolveRegion.dstOffset.x = 0;
6903 resolveRegion.dstOffset.y = 0;
6904 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006905 resolveRegion.extent.width = 1;
6906 resolveRegion.extent.height = 1;
6907 resolveRegion.extent.depth = 1;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006908 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
6909 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06006910 EndCommandBuffer();
6911
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006912 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006913 FAIL() << "Did not receive Error 'vkCmdResolveImage called with source "
6914 "sample count less than 2.'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006915 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06006916 }
6917
Chia-I Wu69f40122015-10-26 21:10:41 +08006918 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08006919 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08006920 vkFreeMemory(m_device->device(), srcMem, NULL);
6921 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06006922}
6923
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006924TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
6925 VkResult err;
6926 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06006927
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006928 m_errorMonitor->SetDesiredFailureMsg(
6929 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06006930 "vkCmdResolveImage called with dest sample count greater than 1.");
6931
Mike Stroyan43909d82015-09-25 13:39:21 -06006932 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06006933
6934 // Create two images of sample count 2 and try to Resolve between them
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006935 VkImage srcImage;
6936 VkImage dstImage;
6937 VkDeviceMemory srcMem;
6938 VkDeviceMemory destMem;
6939 VkMemoryRequirements memReqs;
Mike Stroyan43909d82015-09-25 13:39:21 -06006940
6941 VkImageCreateInfo image_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006942 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6943 image_create_info.pNext = NULL;
6944 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6945 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
6946 image_create_info.extent.width = 32;
6947 image_create_info.extent.height = 1;
6948 image_create_info.extent.depth = 1;
6949 image_create_info.mipLevels = 1;
6950 image_create_info.arrayLayers = 1;
6951 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
6952 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6953 // Note: Some implementations expect color attachment usage for any
6954 // multisample surface
6955 image_create_info.usage =
6956 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
6957 image_create_info.flags = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006958
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006959 err =
6960 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06006961 ASSERT_VK_SUCCESS(err);
6962
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006963 image_create_info.imageType = VK_IMAGE_TYPE_1D;
6964 // Note: Some implementations expect color attachment usage for any
6965 // multisample surface
6966 image_create_info.usage =
6967 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06006968
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006969 err =
6970 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06006971 ASSERT_VK_SUCCESS(err);
6972
6973 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08006974 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006975 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6976 memAlloc.pNext = NULL;
6977 memAlloc.allocationSize = 0;
6978 memAlloc.memoryTypeIndex = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06006979
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06006980 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06006981 memAlloc.allocationSize = memReqs.size;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006982 pass =
6983 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06006984 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08006985 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06006986 ASSERT_VK_SUCCESS(err);
6987
Chia-I Wu1f851912015-10-27 18:04:07 +08006988 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06006989 memAlloc.allocationSize = memReqs.size;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07006990 pass =
6991 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06006992 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08006993 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06006994 ASSERT_VK_SUCCESS(err);
6995
6996 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
6997 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08006998 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06006999 ASSERT_VK_SUCCESS(err);
7000
7001 BeginCommandBuffer();
7002 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007003 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
7004 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyan43909d82015-09-25 13:39:21 -06007005 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08007006 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06007007 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06007008 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08007009 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06007010 resolveRegion.srcOffset.x = 0;
7011 resolveRegion.srcOffset.y = 0;
7012 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08007013 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08007014 resolveRegion.dstSubresource.mipLevel = 0;
7015 resolveRegion.dstSubresource.baseArrayLayer = 0;
7016 resolveRegion.dstSubresource.layerCount = 0;
7017 resolveRegion.dstOffset.x = 0;
7018 resolveRegion.dstOffset.y = 0;
7019 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06007020 resolveRegion.extent.width = 1;
7021 resolveRegion.extent.height = 1;
7022 resolveRegion.extent.depth = 1;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007023 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
7024 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06007025 EndCommandBuffer();
7026
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06007027 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007028 FAIL() << "Did not receive Error 'vkCmdResolveImage called with dest "
7029 "sample count greater than 1.'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06007030 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06007031 }
7032
Chia-I Wu69f40122015-10-26 21:10:41 +08007033 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08007034 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08007035 vkFreeMemory(m_device->device(), srcMem, NULL);
7036 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06007037}
7038
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007039TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
7040 VkResult err;
7041 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06007042
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007043 m_errorMonitor->SetDesiredFailureMsg(
7044 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06007045 "vkCmdResolveImage called with unmatched source and dest formats.");
7046
Mike Stroyan43909d82015-09-25 13:39:21 -06007047 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06007048
7049 // Create two images of different types and try to copy between them
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007050 VkImage srcImage;
7051 VkImage dstImage;
7052 VkDeviceMemory srcMem;
7053 VkDeviceMemory destMem;
7054 VkMemoryRequirements memReqs;
Mike Stroyan43909d82015-09-25 13:39:21 -06007055
7056 VkImageCreateInfo image_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007057 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7058 image_create_info.pNext = NULL;
7059 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7060 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
7061 image_create_info.extent.width = 32;
7062 image_create_info.extent.height = 1;
7063 image_create_info.extent.depth = 1;
7064 image_create_info.mipLevels = 1;
7065 image_create_info.arrayLayers = 1;
7066 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
7067 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7068 // Note: Some implementations expect color attachment usage for any
7069 // multisample surface
7070 image_create_info.usage =
7071 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
7072 image_create_info.flags = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06007073
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007074 err =
7075 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06007076 ASSERT_VK_SUCCESS(err);
7077
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007078 // Set format to something other than source image
7079 image_create_info.format = VK_FORMAT_R32_SFLOAT;
7080 // Note: Some implementations expect color attachment usage for any
7081 // multisample surface
7082 image_create_info.usage =
7083 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
7084 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06007085
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007086 err =
7087 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06007088 ASSERT_VK_SUCCESS(err);
7089
7090 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08007091 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007092 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7093 memAlloc.pNext = NULL;
7094 memAlloc.allocationSize = 0;
7095 memAlloc.memoryTypeIndex = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06007096
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06007097 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06007098 memAlloc.allocationSize = memReqs.size;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007099 pass =
7100 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06007101 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08007102 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06007103 ASSERT_VK_SUCCESS(err);
7104
Chia-I Wu1f851912015-10-27 18:04:07 +08007105 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06007106 memAlloc.allocationSize = memReqs.size;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007107 pass =
7108 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06007109 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08007110 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06007111 ASSERT_VK_SUCCESS(err);
7112
7113 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
7114 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08007115 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06007116 ASSERT_VK_SUCCESS(err);
7117
7118 BeginCommandBuffer();
7119 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007120 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
7121 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyan43909d82015-09-25 13:39:21 -06007122 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08007123 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06007124 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06007125 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08007126 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06007127 resolveRegion.srcOffset.x = 0;
7128 resolveRegion.srcOffset.y = 0;
7129 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08007130 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08007131 resolveRegion.dstSubresource.mipLevel = 0;
7132 resolveRegion.dstSubresource.baseArrayLayer = 0;
7133 resolveRegion.dstSubresource.layerCount = 0;
7134 resolveRegion.dstOffset.x = 0;
7135 resolveRegion.dstOffset.y = 0;
7136 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06007137 resolveRegion.extent.width = 1;
7138 resolveRegion.extent.height = 1;
7139 resolveRegion.extent.depth = 1;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007140 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
7141 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06007142 EndCommandBuffer();
7143
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06007144 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007145 FAIL() << "Did not receive Error 'vkCmdResolveImage called with "
7146 "unmatched source and dest formats.'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06007147 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06007148 }
7149
Chia-I Wu69f40122015-10-26 21:10:41 +08007150 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08007151 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08007152 vkFreeMemory(m_device->device(), srcMem, NULL);
7153 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06007154}
7155
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007156TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
7157 VkResult err;
7158 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06007159
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007160 m_errorMonitor->SetDesiredFailureMsg(
7161 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06007162 "vkCmdResolveImage called with unmatched source and dest image types.");
7163
Mike Stroyan43909d82015-09-25 13:39:21 -06007164 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06007165
7166 // Create two images of different types and try to copy between them
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007167 VkImage srcImage;
7168 VkImage dstImage;
7169 VkDeviceMemory srcMem;
7170 VkDeviceMemory destMem;
7171 VkMemoryRequirements memReqs;
Mike Stroyan43909d82015-09-25 13:39:21 -06007172
7173 VkImageCreateInfo image_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007174 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7175 image_create_info.pNext = NULL;
7176 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7177 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
7178 image_create_info.extent.width = 32;
7179 image_create_info.extent.height = 1;
7180 image_create_info.extent.depth = 1;
7181 image_create_info.mipLevels = 1;
7182 image_create_info.arrayLayers = 1;
7183 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
7184 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7185 // Note: Some implementations expect color attachment usage for any
7186 // multisample surface
7187 image_create_info.usage =
7188 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
7189 image_create_info.flags = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06007190
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007191 err =
7192 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06007193 ASSERT_VK_SUCCESS(err);
7194
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007195 image_create_info.imageType = VK_IMAGE_TYPE_1D;
7196 // Note: Some implementations expect color attachment usage for any
7197 // multisample surface
7198 image_create_info.usage =
7199 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
7200 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06007201
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007202 err =
7203 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06007204 ASSERT_VK_SUCCESS(err);
7205
7206 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08007207 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007208 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7209 memAlloc.pNext = NULL;
7210 memAlloc.allocationSize = 0;
7211 memAlloc.memoryTypeIndex = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06007212
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06007213 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06007214 memAlloc.allocationSize = memReqs.size;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007215 pass =
7216 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06007217 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08007218 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06007219 ASSERT_VK_SUCCESS(err);
7220
Chia-I Wu1f851912015-10-27 18:04:07 +08007221 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06007222 memAlloc.allocationSize = memReqs.size;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007223 pass =
7224 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06007225 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08007226 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06007227 ASSERT_VK_SUCCESS(err);
7228
7229 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
7230 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08007231 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06007232 ASSERT_VK_SUCCESS(err);
7233
7234 BeginCommandBuffer();
7235 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007236 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
7237 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyan43909d82015-09-25 13:39:21 -06007238 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08007239 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06007240 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06007241 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08007242 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06007243 resolveRegion.srcOffset.x = 0;
7244 resolveRegion.srcOffset.y = 0;
7245 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08007246 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08007247 resolveRegion.dstSubresource.mipLevel = 0;
7248 resolveRegion.dstSubresource.baseArrayLayer = 0;
7249 resolveRegion.dstSubresource.layerCount = 0;
7250 resolveRegion.dstOffset.x = 0;
7251 resolveRegion.dstOffset.y = 0;
7252 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06007253 resolveRegion.extent.width = 1;
7254 resolveRegion.extent.height = 1;
7255 resolveRegion.extent.depth = 1;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007256 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
7257 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06007258 EndCommandBuffer();
7259
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06007260 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007261 FAIL() << "Did not receive Error 'vkCmdResolveImage called with "
7262 "unmatched source and dest image types.'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06007263 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06007264 }
7265
Chia-I Wu69f40122015-10-26 21:10:41 +08007266 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08007267 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08007268 vkFreeMemory(m_device->device(), srcMem, NULL);
7269 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06007270}
Tobin Ehlisb46be812015-10-23 16:00:08 -06007271
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007272TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisb46be812015-10-23 16:00:08 -06007273 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007274 // to using a DS format, then cause it to hit error due to COLOR_BIT not
7275 // set in aspect
Tobin Ehlisb46be812015-10-23 16:00:08 -06007276 // The image format check comes 2nd in validation so we trigger it first,
7277 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007278 VkResult err;
Tobin Ehlisb46be812015-10-23 16:00:08 -06007279
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007280 m_errorMonitor->SetDesiredFailureMsg(
7281 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06007282 "Combination depth/stencil image formats can have only the ");
7283
Tobin Ehlisb46be812015-10-23 16:00:08 -06007284 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06007285
Chia-I Wuc51b1212015-10-27 19:25:11 +08007286 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007287 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7288 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06007289
7290 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007291 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7292 ds_pool_ci.pNext = NULL;
7293 ds_pool_ci.maxSets = 1;
7294 ds_pool_ci.poolSizeCount = 1;
7295 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06007296
7297 VkDescriptorPool ds_pool;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007298 err =
7299 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06007300 ASSERT_VK_SUCCESS(err);
7301
7302 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007303 dsl_binding.binding = 0;
7304 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7305 dsl_binding.descriptorCount = 1;
7306 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7307 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisb46be812015-10-23 16:00:08 -06007308
7309 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007310 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7311 ds_layout_ci.pNext = NULL;
7312 ds_layout_ci.bindingCount = 1;
7313 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06007314 VkDescriptorSetLayout ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007315 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7316 &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06007317 ASSERT_VK_SUCCESS(err);
7318
7319 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08007320 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wuc1f5e402015-11-10 16:21:09 +08007321 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburna4ae48b2016-01-11 13:12:43 -07007322 alloc_info.descriptorSetCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06007323 alloc_info.descriptorPool = ds_pool;
7324 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007325 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7326 &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06007327 ASSERT_VK_SUCCESS(err);
7328
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007329 VkImage image_bad;
7330 VkImage image_good;
Tobin Ehlisb46be812015-10-23 16:00:08 -06007331 // One bad format and one good format for Color attachment
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007332 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
Tobin Ehlisb46be812015-10-23 16:00:08 -06007333 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007334 const int32_t tex_width = 32;
7335 const int32_t tex_height = 32;
Tobin Ehlisb46be812015-10-23 16:00:08 -06007336
7337 VkImageCreateInfo image_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007338 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7339 image_create_info.pNext = NULL;
7340 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7341 image_create_info.format = tex_format_bad;
7342 image_create_info.extent.width = tex_width;
7343 image_create_info.extent.height = tex_height;
7344 image_create_info.extent.depth = 1;
7345 image_create_info.mipLevels = 1;
7346 image_create_info.arrayLayers = 1;
7347 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7348 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7349 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
7350 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
7351 image_create_info.flags = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06007352
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007353 err =
7354 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisb46be812015-10-23 16:00:08 -06007355 ASSERT_VK_SUCCESS(err);
7356 image_create_info.format = tex_format_good;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007357 image_create_info.usage =
7358 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
7359 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
7360 &image_good);
Tobin Ehlisb46be812015-10-23 16:00:08 -06007361 ASSERT_VK_SUCCESS(err);
7362
7363 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007364 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7365 image_view_create_info.image = image_bad;
7366 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7367 image_view_create_info.format = tex_format_bad;
7368 image_view_create_info.subresourceRange.baseArrayLayer = 0;
7369 image_view_create_info.subresourceRange.baseMipLevel = 0;
7370 image_view_create_info.subresourceRange.layerCount = 1;
7371 image_view_create_info.subresourceRange.levelCount = 1;
7372 image_view_create_info.subresourceRange.aspectMask =
7373 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisb46be812015-10-23 16:00:08 -06007374
7375 VkImageView view;
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007376 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
7377 &view);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06007378
7379 if (!m_errorMonitor->DesiredMsgFound()) {
Karl Schultz99e9d1d2016-02-02 17:17:23 -07007380 FAIL() << "Did not receive Error 'Combination depth-stencil image "
7381 "formats can have only the....'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06007382 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06007383 }
7384
Chia-I Wu69f40122015-10-26 21:10:41 +08007385 vkDestroyImage(m_device->device(), image_bad, NULL);
7386 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08007387 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7388 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06007389}
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06007390#endif // IMAGE_TESTS
7391
Tony Barbour30486ea2015-04-07 13:44:53 -06007392int main(int argc, char **argv) {
7393 int result;
7394
Cody Northrop50537d02016-03-08 22:25:52 -07007395#ifdef ANDROID
7396 int vulkanSupport = InitVulkan();
7397 if (vulkanSupport == 0)
7398 return 1;
7399#endif
7400
Tony Barbour30486ea2015-04-07 13:44:53 -06007401 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06007402 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06007403
7404 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
7405
7406 result = RUN_ALL_TESTS();
7407
Tony Barbour01999182015-04-09 12:58:51 -06007408 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06007409 return result;
7410}