blob: c39559ebdb66f414d5acf918a690e1eb9a669b38 [file] [log] [blame]
David Pinedo329ca9e2015-11-06 12:54:48 -07001#include <vulkan/vulkan.h>
2#include "vulkan/vk_debug_report_lunarg.h"
Courtney Goeltzenleuchter0abdb662015-10-07 13:28:58 -06003#include "test_common.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06004#include "vkrenderframework.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -06005#include "vk_layer_config.h"
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06006#include "../icd/common/icd-spv.h"
Tony Barbour30486ea2015-04-07 13:44:53 -06007
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05008#define GLM_FORCE_RADIANS
9#include "glm/glm.hpp"
10#include <glm/gtc/matrix_transform.hpp>
11
Tobin Ehlis57e6a612015-05-26 16:11:58 -060012#define MEM_TRACKER_TESTS 1
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -060013
Tobin Ehlis57e6a612015-05-26 16:11:58 -060014#define OBJ_TRACKER_TESTS 1
15#define DRAW_STATE_TESTS 1
16#define THREADING_TESTS 1
Chris Forbes5af3bf22015-05-25 11:13:08 +120017#define SHADER_CHECKER_TESTS 1
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -060018#define DEVICE_LIMITS_TESTS 1
Tobin Ehlis342b9bf2015-09-22 10:11:37 -060019#define IMAGE_TESTS 1
Tobin Ehlis57e6a612015-05-26 16:11:58 -060020
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050021//--------------------------------------------------------------------------------------
22// Mesh and VertexFormat Data
23//--------------------------------------------------------------------------------------
24struct Vertex
25{
26 float posX, posY, posZ, posW; // Position data
27 float r, g, b, a; // Color
28};
29
30#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
31
32typedef enum _BsoFailSelect {
33 BsoFailNone = 0x00000000,
Cody Northrope4bc6942015-08-26 10:01:32 -060034 BsoFailLineWidth = 0x00000001,
35 BsoFailDepthBias = 0x00000002,
Cody Northropf5bd2252015-08-17 11:10:49 -060036 BsoFailViewport = 0x00000004,
Tobin Ehlisf6cb4672015-09-29 08:18:34 -060037 BsoFailScissor = 0x00000008,
38 BsoFailBlend = 0x00000010,
39 BsoFailDepthBounds = 0x00000020,
40 BsoFailStencilReadMask = 0x00000040,
41 BsoFailStencilWriteMask = 0x00000080,
42 BsoFailStencilReference = 0x00000100,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050043} BsoFailSelect;
44
45struct vktriangle_vs_uniform {
46 // Must start with MVP
47 float mvp[4][4];
48 float position[3][4];
49 float color[3][4];
50};
51
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050052static const char bindStateVertShaderText[] =
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050053 "#version 130\n"
54 "vec2 vertices[3];\n"
55 "void main() {\n"
56 " vertices[0] = vec2(-1.0, -1.0);\n"
57 " vertices[1] = vec2( 1.0, -1.0);\n"
58 " vertices[2] = vec2( 0.0, 1.0);\n"
59 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
60 "}\n";
61
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050062static const char bindStateFragShaderText[] =
Cody Northrop74a2d2c2015-06-16 17:32:04 -060063 "#version 140\n"
64 "#extension GL_ARB_separate_shader_objects: require\n"
65 "#extension GL_ARB_shading_language_420pack: require\n"
66 "\n"
67 "layout(location = 0) out vec4 uFragColor;\n"
68 "void main(){\n"
69 " uFragColor = vec4(0,1,0,1);\n"
70 "}\n";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050071
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -060072static VkBool32 myDbgFunc(
Tony Barboure84a8d62015-07-10 14:10:27 -060073 VkFlags msgFlags,
74 VkDbgObjectType objType,
75 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060076 size_t location,
77 int32_t msgCode,
78 const char* pLayerPrefix,
79 const char* pMsg,
80 void* pUserData);
Tony Barbour30486ea2015-04-07 13:44:53 -060081
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -060082// ********************************************************
83// ErrorMonitor Usage:
84//
85// Call SetDesiredFailureMsg with a string to be compared against all
86// encountered log messages. Passing NULL will match all log messages.
87// logMsg will return true for skipCall only if msg is matched or NULL.
88//
89// Call DesiredMsgFound to determine if the desired failure message
90// was encountered.
91
Tony Barbour30486ea2015-04-07 13:44:53 -060092class ErrorMonitor {
93public:
Tony Barbour0c1bdc62015-04-29 17:34:29 -060094 ErrorMonitor()
Tony Barbour30486ea2015-04-07 13:44:53 -060095 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060096 test_platform_thread_create_mutex(&m_mutex);
97 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060098 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -060099 m_bailout = NULL;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600100 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -0600101 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600102
103 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -0600104 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600105 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600106 m_desiredMsg.clear();
107 m_failureMsg.clear();
108 m_otherMsgs.clear();
109 m_desiredMsg = msgString;
110 m_msgFound = VK_FALSE;
111 m_msgFlags = msgFlags;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600112 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -0600113 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600114
115 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -0600116 {
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600117 VkBool32 result = VK_FALSE;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600118 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600119 if (m_bailout != NULL) {
120 *m_bailout = true;
121 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600122 string errorString(msgString);
123 if (msgFlags & m_msgFlags) {
124 if (errorString.find(m_desiredMsg) != string::npos) {
125 m_failureMsg = errorString;
126 m_msgFound = VK_TRUE;
127 result = VK_TRUE;
128 } else {
129 m_otherMsgs.push_back(errorString);
130 }
131 }
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600132 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600133 return result;
Mike Stroyan09aae812015-05-12 16:00:45 -0600134 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600135
136 vector<string> GetOtherFailureMsgs(void)
137 {
138 return m_otherMsgs;
139 }
140
141 string GetFailureMsg(void)
142 {
143 return m_failureMsg;
144 }
145
146 VkBool32 DesiredMsgFound(void)
147 {
148 return m_msgFound;
149 }
150
Mike Stroyan09aae812015-05-12 16:00:45 -0600151 void SetBailout(bool *bailout)
152 {
153 m_bailout = bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600154 }
155
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600156 void DumpFailureMsgs(void)
157 {
158 vector<string> otherMsgs = GetOtherFailureMsgs();
159 cout << "Other error messages logged for this test were:" << endl;
160 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
161 cout << " " << *iter << endl;
162 }
163 }
164
Tony Barbour30486ea2015-04-07 13:44:53 -0600165private:
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600166 VkFlags m_msgFlags;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600167 string m_desiredMsg;
168 string m_failureMsg;
169 vector<string> m_otherMsgs;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600170 test_platform_thread_mutex m_mutex;
171 bool* m_bailout;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600172 VkBool32 m_msgFound;
Tony Barbour30486ea2015-04-07 13:44:53 -0600173};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500174
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600175static VkBool32 myDbgFunc(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600176 VkFlags msgFlags,
Tony Barboure84a8d62015-07-10 14:10:27 -0600177 VkDbgObjectType objType,
178 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600179 size_t location,
180 int32_t msgCode,
181 const char* pLayerPrefix,
182 const char* pMsg,
183 void* pUserData)
Tony Barbour30486ea2015-04-07 13:44:53 -0600184{
Tony Barbour192f02b2015-11-06 14:21:31 -0700185 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_PERF_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour8508b8e2015-04-09 10:48:04 -0600186 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600187 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour8508b8e2015-04-09 10:48:04 -0600188 }
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600189 return false;
Tony Barbour30486ea2015-04-07 13:44:53 -0600190}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500191
Tony Barbour01999182015-04-09 12:58:51 -0600192class VkLayerTest : public VkRenderFramework
Tony Barbour30486ea2015-04-07 13:44:53 -0600193{
194public:
Chia-I Wu1f851912015-10-27 18:04:07 +0800195 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
196 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500197 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
Chia-I Wu1f851912015-10-27 18:04:07 +0800198 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbour1490c912015-07-28 10:17:20 -0600199 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
Chia-I Wu1f851912015-10-27 18:04:07 +0800200 { GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600201
Tony Barbour1490c912015-07-28 10:17:20 -0600202 /* Convenience functions that use built-in command buffer */
Chia-I Wu1f851912015-10-27 18:04:07 +0800203 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
204 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600205 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
Chia-I Wu1f851912015-10-27 18:04:07 +0800206 { m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance); }
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600207 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
Chia-I Wu1f851912015-10-27 18:04:07 +0800208 { m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); }
209 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
210 void QueueCommandBuffer(const VkFence& fence) { m_commandBuffer->QueueCommandBuffer(fence); }
Tony Barbour1490c912015-07-28 10:17:20 -0600211 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
Chia-I Wu1f851912015-10-27 18:04:07 +0800212 { m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
Tony Barbour1490c912015-07-28 10:17:20 -0600213 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
Chia-I Wu1f851912015-10-27 18:04:07 +0800214 { m_commandBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600215protected:
Tony Barbour01999182015-04-09 12:58:51 -0600216 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600217
218 virtual void SetUp() {
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600219 std::vector<const char *> instance_layer_names;
220 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600221 std::vector<const char *> instance_extension_names;
222 std::vector<const char *> device_extension_names;
Tony Barbour950ebc02015-04-23 12:55:36 -0600223
Courtney Goeltzenleuchter846298c2015-07-30 11:32:46 -0600224 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600225 /*
226 * Since CreateDbgMsgCallback is an instance level extension call
227 * any extension / layer that utilizes that feature also needs
228 * to be enabled at create instance time.
229 */
Chia-I Wu1f851912015-10-27 18:04:07 +0800230 // Use Threading layer first to protect others from ThreadCommandBufferCollision test
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600231 instance_layer_names.push_back("Threading");
232 instance_layer_names.push_back("ObjectTracker");
233 instance_layer_names.push_back("MemTracker");
234 instance_layer_names.push_back("DrawState");
235 instance_layer_names.push_back("ShaderChecker");
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600236 instance_layer_names.push_back("DeviceLimits");
Tobin Ehlis342b9bf2015-09-22 10:11:37 -0600237 instance_layer_names.push_back("Image");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600238
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600239 device_layer_names.push_back("Threading");
240 device_layer_names.push_back("ObjectTracker");
241 device_layer_names.push_back("MemTracker");
242 device_layer_names.push_back("DrawState");
243 device_layer_names.push_back("ShaderChecker");
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600244 device_layer_names.push_back("DeviceLimits");
Tobin Ehlis342b9bf2015-09-22 10:11:37 -0600245 device_layer_names.push_back("Image");
Tony Barbour30486ea2015-04-07 13:44:53 -0600246
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600247 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -0600248 this->app_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +0800249 this->app_info.pApplicationName = "layer_tests";
250 this->app_info.applicationVersion = 1;
Tony Barbour30486ea2015-04-07 13:44:53 -0600251 this->app_info.pEngineName = "unittest";
252 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600253 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -0600254
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600255 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600256 InitFramework(instance_layer_names, device_layer_names,
257 instance_extension_names, device_extension_names,
258 myDbgFunc, m_errorMonitor);
Tony Barbour30486ea2015-04-07 13:44:53 -0600259 }
260
261 virtual void TearDown() {
262 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600263 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600264 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600265 }
266};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500267
Chia-I Wu1f851912015-10-27 18:04:07 +0800268VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600269{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600270 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600271
Chia-I Wu1f851912015-10-27 18:04:07 +0800272 result = commandBuffer.BeginCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600273
274 /*
275 * For render test all drawing happens in a single render pass
276 * on a single command buffer.
277 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200278 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800279 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour30486ea2015-04-07 13:44:53 -0600280 }
281
282 return result;
283}
284
Chia-I Wu1f851912015-10-27 18:04:07 +0800285VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600286{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600287 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600288
Chris Forbesfe133ef2015-06-16 14:05:59 +1200289 if (renderPass()) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800290 commandBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200291 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600292
Chia-I Wu1f851912015-10-27 18:04:07 +0800293 result = commandBuffer.EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600294
295 return result;
296}
297
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500298void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
299{
300 // Create identity matrix
301 int i;
302 struct vktriangle_vs_uniform data;
303
304 glm::mat4 Projection = glm::mat4(1.0f);
305 glm::mat4 View = glm::mat4(1.0f);
306 glm::mat4 Model = glm::mat4(1.0f);
307 glm::mat4 MVP = Projection * View * Model;
308 const int matrixSize = sizeof(MVP);
309 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
310
311 memcpy(&data.mvp, &MVP[0][0], matrixSize);
312
313 static const Vertex tri_data[] =
314 {
315 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
316 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
317 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
318 };
319
320 for (i=0; i<3; i++) {
321 data.position[i][0] = tri_data[i].posX;
322 data.position[i][1] = tri_data[i].posY;
323 data.position[i][2] = tri_data[i].posZ;
324 data.position[i][3] = tri_data[i].posW;
325 data.color[i][0] = tri_data[i].r;
326 data.color[i][1] = tri_data[i].g;
327 data.color[i][2] = tri_data[i].b;
328 data.color[i][3] = tri_data[i].a;
329 }
330
331 ASSERT_NO_FATAL_FAILURE(InitState());
332 ASSERT_NO_FATAL_FAILURE(InitViewport());
333
334 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
335
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600336 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
337 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500338
339 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800340 pipelineobj.AddColorAttachment();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500341 pipelineobj.AddShader(&vs);
342 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600343 if (failMask & BsoFailLineWidth) {
344 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
345 }
346 if (failMask & BsoFailDepthBias) {
347 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
348 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600349 // Viewport and scissors must stay in synch or other errors will occur than the ones we want
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600350 if (failMask & BsoFailViewport) {
351 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600352 m_viewports.clear();
353 m_scissors.clear();
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600354 }
355 if (failMask & BsoFailScissor) {
356 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600357 m_scissors.clear();
358 m_viewports.clear();
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600359 }
360 if (failMask & BsoFailBlend) {
361 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
362 }
363 if (failMask & BsoFailDepthBounds) {
364 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
365 }
366 if (failMask & BsoFailStencilReadMask) {
367 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
368 }
369 if (failMask & BsoFailStencilWriteMask) {
370 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
371 }
372 if (failMask & BsoFailStencilReference) {
373 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
374 }
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500375
376 VkDescriptorSetObj descriptorSet(m_device);
377 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
378
379 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600380 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500381
Tony Barbour1490c912015-07-28 10:17:20 -0600382 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500383
384 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600385 Draw(3, 1, 0, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500386
387 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600388 EndCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500389
Tony Barbour1490c912015-07-28 10:17:20 -0600390 QueueCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500391}
392
Chia-I Wu1f851912015-10-27 18:04:07 +0800393void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500394{
395 if (m_depthStencil->Initialized()) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800396 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500397 } else {
Chia-I Wu1f851912015-10-27 18:04:07 +0800398 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500399 }
400
Chia-I Wu1f851912015-10-27 18:04:07 +0800401 commandBuffer->PrepareAttachments();
Cody Northrop2605cb02015-08-18 15:21:16 -0600402 // Make sure depthWriteEnable is set so that Depth fail test will work correctly
403 // Make sure stencilTestEnable is set so that Stencil fail test will work correctly
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600404 VkStencilOpState stencil = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +0800405 stencil.failOp = VK_STENCIL_OP_KEEP;
406 stencil.passOp = VK_STENCIL_OP_KEEP;
407 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
408 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600409
410 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
411 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600412 ds_ci.pNext = NULL;
413 ds_ci.depthTestEnable = VK_FALSE;
414 ds_ci.depthWriteEnable = VK_TRUE;
415 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
416 ds_ci.depthBoundsTestEnable = VK_FALSE;
417 ds_ci.stencilTestEnable = VK_TRUE;
418 ds_ci.front = stencil;
419 ds_ci.back = stencil;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600420
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600421 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600422 pipelineobj.SetViewport(m_viewports);
423 pipelineobj.SetScissor(m_scissors);
Chia-I Wu1f851912015-10-27 18:04:07 +0800424 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Cody Northropccfa96d2015-08-27 10:20:35 -0600425 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
426 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +0800427 commandBuffer->BindPipeline(pipelineobj);
428 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500429}
430
431// ********************************************************************************************************************
432// ********************************************************************************************************************
433// ********************************************************************************************************************
434// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600435#if MEM_TRACKER_TESTS
Chia-I Wu1f851912015-10-27 18:04:07 +0800436TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinski81078192015-05-19 10:28:29 -0500437{
438 vk_testing::Fence testFence;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500439 VkFenceCreateInfo fenceInfo = {};
440 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
441 fenceInfo.pNext = NULL;
442 fenceInfo.flags = 0;
443
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600444 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Resetting CB");
445
Mark Lobodzinski81078192015-05-19 10:28:29 -0500446 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barboure389b882015-07-20 13:00:10 -0600447
448 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
449 vk_testing::Buffer buffer;
450 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500451
Tony Barbour1490c912015-07-28 10:17:20 -0600452 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800453 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbour1490c912015-07-28 10:17:20 -0600454 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500455
456 testFence.init(*m_device, fenceInfo);
457
458 // Bypass framework since it does the waits automatically
459 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600460 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +0800461 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
462 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800463 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600464 submit_info.pWaitSemaphores = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800465 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +0800466 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +0800467 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600468 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600469
470 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500471 ASSERT_VK_SUCCESS( err );
472
Mark Lobodzinski81078192015-05-19 10:28:29 -0500473 // Introduce failure by calling begin again before checking fence
Chia-I Wu1f851912015-10-27 18:04:07 +0800474 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500475
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600476 if (!m_errorMonitor->DesiredMsgFound()) {
477 FAIL() << "Did not receive Error 'Resetting CB (0xaddress) before it has completed. You must check CB flag before.'";
478 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500479 }
480}
481
Chia-I Wu1f851912015-10-27 18:04:07 +0800482TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinski81078192015-05-19 10:28:29 -0500483{
484 vk_testing::Fence testFence;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500485 VkFenceCreateInfo fenceInfo = {};
486 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
487 fenceInfo.pNext = NULL;
488 fenceInfo.flags = 0;
489
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600490 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Calling vkBeginCommandBuffer() on active CB");
491
Mark Lobodzinski81078192015-05-19 10:28:29 -0500492 ASSERT_NO_FATAL_FAILURE(InitState());
493 ASSERT_NO_FATAL_FAILURE(InitViewport());
494 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
495
Tony Barbour1490c912015-07-28 10:17:20 -0600496 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800497 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -0600498 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500499
500 testFence.init(*m_device, fenceInfo);
501
502 // Bypass framework since it does the waits automatically
503 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600504 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +0800505 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
506 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800507 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600508 submit_info.pWaitSemaphores = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800509 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +0800510 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +0800511 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600512 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600513
514 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500515 ASSERT_VK_SUCCESS( err );
516
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600517
Chia-I Wu1f851912015-10-27 18:04:07 +0800518 VkCommandBufferBeginInfo info = {};
519 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
520 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600521 info.renderPass = VK_NULL_HANDLE;
522 info.subpass = 0;
523 info.framebuffer = VK_NULL_HANDLE;
524
525 // Introduce failure by calling BCB again before checking fence
Chia-I Wu1f851912015-10-27 18:04:07 +0800526 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500527
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600528 if (!m_errorMonitor->DesiredMsgFound()) {
529 FAIL() << "Did not receive Error 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
530 m_errorMonitor->DumpFailureMsgs();
531
Mark Lobodzinski81078192015-05-19 10:28:29 -0500532 }
533}
534
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500535TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
536{
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500537 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600538 bool pass;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500539
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600540 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
541 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
542
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500543 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500544
545 // Create an image, allocate memory, free it, and then try to bind it
546 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500547 VkDeviceMemory mem;
548 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500549
550 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
551 const int32_t tex_width = 32;
552 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500553
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600554 VkImageCreateInfo image_create_info = {};
555 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
556 image_create_info.pNext = NULL;
557 image_create_info.imageType = VK_IMAGE_TYPE_2D;
558 image_create_info.format = tex_format;
559 image_create_info.extent.width = tex_width;
560 image_create_info.extent.height = tex_height;
561 image_create_info.extent.depth = 1;
562 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600563 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800564 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600565 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
566 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
567 image_create_info.flags = 0;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600568
Chia-I Wu1f851912015-10-27 18:04:07 +0800569 VkMemoryAllocateInfo mem_alloc = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600570 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
571 mem_alloc.pNext = NULL;
572 mem_alloc.allocationSize = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500573 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600574 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500575
Chia-I Wu69f40122015-10-26 21:10:41 +0800576 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500577 ASSERT_VK_SUCCESS(err);
578
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600579 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500580 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500581 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500582
Mark Lobodzinski23182612015-05-29 09:32:35 -0500583 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500584
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600585 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
586 if(!pass) { // If we can't find any unmappable memory this test doesn't make sense
Chia-I Wu69f40122015-10-26 21:10:41 +0800587 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour49a3b652015-08-04 16:13:01 -0600588 return;
Mike Stroyan2237f522015-08-18 14:40:24 -0600589 }
Mike Stroyand72da752015-08-04 10:49:29 -0600590
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500591 // allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +0800592 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500593 ASSERT_VK_SUCCESS(err);
594
595 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600596 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500597 ASSERT_VK_SUCCESS(err);
598
599 // Map memory as if to initialize the image
600 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500601 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500602
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600603 if (!m_errorMonitor->DesiredMsgFound()) {
604 FAIL() << "Did not receive Error 'Error received did not match expected error message from vkMapMemory in MemTracker'";
605 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500606 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600607
Chia-I Wu69f40122015-10-26 21:10:41 +0800608 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500609}
610
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600611// TODO : Is this test still valid. Not sure it is with updates to memory binding model
612// Verify and delete the test of fix the check
613//TEST_F(VkLayerTest, FreeBoundMemory)
614//{
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600615// VkResult err;
616//
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600617// m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
618// "Freeing memory object while it still has references");
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600619//
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600620// ASSERT_NO_FATAL_FAILURE(InitState());
621
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600622// // Create an image, allocate memory, free it, and then try to bind it
623// VkImage image;
624// VkDeviceMemory mem;
625// VkMemoryRequirements mem_reqs;
626//
627// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
628// const int32_t tex_width = 32;
629// const int32_t tex_height = 32;
630//
631// const VkImageCreateInfo image_create_info = {
632// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
633// .pNext = NULL,
634// .imageType = VK_IMAGE_TYPE_2D,
635// .format = tex_format,
636// .extent = { tex_width, tex_height, 1 },
637// .mipLevels = 1,
638// .arraySize = 1,
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800639// .samples = VK_SAMPLE_COUNT_1_BIT,
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600640// .tiling = VK_IMAGE_TILING_LINEAR,
641// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
642// .flags = 0,
643// };
Chia-I Wu1f851912015-10-27 18:04:07 +0800644// VkMemoryAllocateInfo mem_alloc = {
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600645// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
646// .pNext = NULL,
647// .allocationSize = 0,
648// .memoryTypeIndex = 0,
649// };
650//
Chia-I Wu69f40122015-10-26 21:10:41 +0800651// err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600652// ASSERT_VK_SUCCESS(err);
653//
654// err = vkGetImageMemoryRequirements(m_device->device(),
655// image,
656// &mem_reqs);
657// ASSERT_VK_SUCCESS(err);
658//
659// mem_alloc.allocationSize = mem_reqs.size;
660//
661// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
662// ASSERT_VK_SUCCESS(err);
663//
664// // allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +0800665// err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600666// ASSERT_VK_SUCCESS(err);
667//
668// // Bind memory to Image object
669// err = vkBindImageMemory(m_device->device(), image, mem, 0);
670// ASSERT_VK_SUCCESS(err);
671//
672// // Introduce validation failure, free memory while still bound to object
Chia-I Wu69f40122015-10-26 21:10:41 +0800673// vkFreeMemory(m_device->device(), mem, NULL);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600674//
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600675// if (!m_errorMonitor->DesiredMsgFound()) {
676// FAIL() << "Did not receive Warning 'Freeing memory object while it still has references'");
677// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600678// }
679//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500680
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500681TEST_F(VkLayerTest, RebindMemory)
682{
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500683 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600684 bool pass;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500685
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600686 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
687 "which has already been bound to mem object");
688
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500689 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500690
691 // Create an image, allocate memory, free it, and then try to bind it
692 VkImage image;
693 VkDeviceMemory mem1;
694 VkDeviceMemory mem2;
695 VkMemoryRequirements mem_reqs;
696
697 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
698 const int32_t tex_width = 32;
699 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500700
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600701 VkImageCreateInfo image_create_info = {};
702 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
703 image_create_info.pNext = NULL;
704 image_create_info.imageType = VK_IMAGE_TYPE_2D;
705 image_create_info.format = tex_format;
706 image_create_info.extent.width = tex_width;
707 image_create_info.extent.height = tex_height;
708 image_create_info.extent.depth = 1;
709 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600710 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800711 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600712 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
713 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
714 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500715
Chia-I Wu1f851912015-10-27 18:04:07 +0800716 VkMemoryAllocateInfo mem_alloc = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600717 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
718 mem_alloc.pNext = NULL;
719 mem_alloc.allocationSize = 0;
720 mem_alloc.memoryTypeIndex = 0;
721
722 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
723 mem_alloc.memoryTypeIndex = 1;
Chia-I Wu69f40122015-10-26 21:10:41 +0800724 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500725 ASSERT_VK_SUCCESS(err);
726
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600727 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500728 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500729 &mem_reqs);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500730
731 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600732 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
733 ASSERT_TRUE(pass);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500734
735 // allocate 2 memory objects
Chia-I Wu1f851912015-10-27 18:04:07 +0800736 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500737 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +0800738 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500739 ASSERT_VK_SUCCESS(err);
740
741 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600742 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500743 ASSERT_VK_SUCCESS(err);
744
745 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600746 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500747
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600748 if (!m_errorMonitor->DesiredMsgFound()) {
749 FAIL() << "Did not receive Error when rebinding memory to an object";
750 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500751 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600752
Chia-I Wu69f40122015-10-26 21:10:41 +0800753 vkDestroyImage(m_device->device(), image, NULL);
754 vkFreeMemory(m_device->device(), mem1, NULL);
755 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500756}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500757
Tony Barbour8508b8e2015-04-09 10:48:04 -0600758TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600759{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600760 vk_testing::Fence testFence;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600761
762 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
763 "submitted in SIGNALED state. Fences must be reset before being submitted");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600764
765 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600766 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
767 fenceInfo.pNext = NULL;
768 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600769
Tony Barbour30486ea2015-04-07 13:44:53 -0600770 ASSERT_NO_FATAL_FAILURE(InitState());
771 ASSERT_NO_FATAL_FAILURE(InitViewport());
772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
773
Tony Barbour1490c912015-07-28 10:17:20 -0600774 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800775 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -0600776 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600777
778 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600779
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600780 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +0800781 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
782 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800783 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600784 submit_info.pWaitSemaphores = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800785 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +0800786 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +0800787 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600788 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600789
790 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600791 vkQueueWaitIdle(m_device->m_queue );
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600792
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600793 if (!m_errorMonitor->DesiredMsgFound()) {
794 FAIL() << "Did not receive Error 'VkQueueSubmit with fence in SIGNALED_STATE'";
795 m_errorMonitor->DumpFailureMsgs();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600796 }
Tony Barbour8508b8e2015-04-09 10:48:04 -0600797}
798
799TEST_F(VkLayerTest, ResetUnsignaledFence)
800{
801 vk_testing::Fence testFence;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600802 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600803 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
804 fenceInfo.pNext = NULL;
805
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600806 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
807 "submitted to VkResetFences in UNSIGNALED STATE");
808
Tony Barbour8508b8e2015-04-09 10:48:04 -0600809 ASSERT_NO_FATAL_FAILURE(InitState());
810 testFence.init(*m_device, fenceInfo);
Chia-I Wua4992342015-07-03 11:45:55 +0800811 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600812 vkResetFences(m_device->device(), 1, fences);
Tony Barbour30486ea2015-04-07 13:44:53 -0600813
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600814 if (!m_errorMonitor->DesiredMsgFound()) {
815 FAIL() << "Did not receive Error 'VkResetFences with fence in UNSIGNALED_STATE'";
816 m_errorMonitor->DumpFailureMsgs();
817 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600818}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600819
Chia-I Wuc278df82015-07-07 11:50:03 +0800820/* TODO: Update for changes due to bug-14075 tiling across render passes */
821#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600822TEST_F(VkLayerTest, InvalidUsageBits)
823{
824 // Initiate Draw w/o a PSO bound
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600825
826 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
827 "Invalid usage flag for image ");
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600828
829 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +0800830 VkCommandBufferObj commandBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600831 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600832
833 const VkExtent3D e3d = {
834 .width = 128,
835 .height = 128,
836 .depth = 1,
837 };
838 const VkImageCreateInfo ici = {
839 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
840 .pNext = NULL,
841 .imageType = VK_IMAGE_TYPE_2D,
842 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
843 .extent = e3d,
844 .mipLevels = 1,
845 .arraySize = 1,
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800846 .samples = VK_SAMPLE_COUNT_1_BIT,
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600847 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchterc3b8eea2015-09-10 14:14:11 -0600848 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600849 .flags = 0,
850 };
851
852 VkImage dsi;
Chia-I Wu69f40122015-10-26 21:10:41 +0800853 vkCreateImage(m_device->device(), &ici, NULL, &dsi);
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600854 VkDepthStencilView dsv;
855 const VkDepthStencilViewCreateInfo dsvci = {
856 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
857 .pNext = NULL,
858 .image = dsi,
859 .mipLevel = 0,
Courtney Goeltzenleuchter3dee8082015-09-10 16:38:41 -0600860 .baseArrayLayer = 0,
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600861 .arraySize = 1,
862 .flags = 0,
863 };
Chia-I Wu69f40122015-10-26 21:10:41 +0800864 vkCreateDepthStencilView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600865
866 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600867 FAIL() << "Error received was not 'Invalid usage flag for image...'";
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600868 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600869 }
870}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600871#endif // 0
872#endif // MEM_TRACKER_TESTS
873
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600874#if OBJ_TRACKER_TESTS
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600875TEST_F(VkLayerTest, PipelineNotBound)
876{
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600877 VkResult err;
878
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600879 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
880 "Invalid VkPipeline Object ");
881
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600882 ASSERT_NO_FATAL_FAILURE(InitState());
883 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600884
Chia-I Wuc51b1212015-10-27 19:25:11 +0800885 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600886 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +0800887 ds_type_count.descriptorCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600888
889 VkDescriptorPoolCreateInfo ds_pool_ci = {};
890 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
891 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600892 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +0800893 ds_pool_ci.poolSizeCount = 1;
894 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600895
896 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +0800897 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600898 ASSERT_VK_SUCCESS(err);
899
900 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +0800901 dsl_binding.binding = 0;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600902 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +0800903 dsl_binding.descriptorCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600904 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
905 dsl_binding.pImmutableSamplers = NULL;
906
907 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
908 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
909 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800910 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +0800911 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600912
913 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +0800914 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600915 ASSERT_VK_SUCCESS(err);
916
917 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +0800918 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -0600919 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +0800920 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -0600921 alloc_info.descriptorPool = ds_pool;
922 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +0800923 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600924 ASSERT_VK_SUCCESS(err);
925
926 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
927 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
928 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +0800929 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600930 pipeline_layout_ci.pSetLayouts = &ds_layout;
931
932 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +0800933 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600934 ASSERT_VK_SUCCESS(err);
935
936 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
937
938 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +0800939 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600940
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600941 if (!m_errorMonitor->DesiredMsgFound()) {
942 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be'" << endl;
943 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600944 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600945
Chia-I Wu69f40122015-10-26 21:10:41 +0800946 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
947 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
948 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600949}
950
951TEST_F(VkLayerTest, BindInvalidMemory)
952{
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600953 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600954 bool pass;
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600955
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -0600956 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
957 "Invalid VkDeviceMemory Object ");
958
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600959 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600960
961 // Create an image, allocate memory, free it, and then try to bind it
962 VkImage image;
963 VkDeviceMemory mem;
964 VkMemoryRequirements mem_reqs;
965
966 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
967 const int32_t tex_width = 32;
968 const int32_t tex_height = 32;
969
970 VkImageCreateInfo image_create_info = {};
971 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
972 image_create_info.pNext = NULL;
973 image_create_info.imageType = VK_IMAGE_TYPE_2D;
974 image_create_info.format = tex_format;
975 image_create_info.extent.width = tex_width;
976 image_create_info.extent.height = tex_height;
977 image_create_info.extent.depth = 1;
978 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600979 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800980 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600981 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
982 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
983 image_create_info.flags = 0;
984
Chia-I Wu1f851912015-10-27 18:04:07 +0800985 VkMemoryAllocateInfo mem_alloc = {};
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600986 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
987 mem_alloc.pNext = NULL;
988 mem_alloc.allocationSize = 0;
989 mem_alloc.memoryTypeIndex = 0;
990
Chia-I Wu69f40122015-10-26 21:10:41 +0800991 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600992 ASSERT_VK_SUCCESS(err);
993
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600994 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600995 image,
996 &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600997
998 mem_alloc.allocationSize = mem_reqs.size;
999
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001000 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1001 ASSERT_TRUE(pass);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001002
1003 // allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08001004 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001005 ASSERT_VK_SUCCESS(err);
1006
1007 // Introduce validation failure, free memory before binding
Chia-I Wu69f40122015-10-26 21:10:41 +08001008 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001009
1010 // Try to bind free memory that has been freed
1011 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1012 // This may very well return an error.
1013 (void)err;
1014
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001015 if (!m_errorMonitor->DesiredMsgFound()) {
1016 FAIL() << "Did not receive Error 'Invalid VkDeviceMemory Object 0x<handle>'";
1017 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001018 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001019
Chia-I Wu69f40122015-10-26 21:10:41 +08001020 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001021}
1022
1023TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
1024{
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001025 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001026 bool pass;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001027
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001028 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "Invalid VkImage Object ");
1029
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001030 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001031
1032 // Create an image object, allocate memory, destroy the object and then try to bind it
1033 VkImage image;
1034 VkDeviceMemory mem;
1035 VkMemoryRequirements mem_reqs;
1036
1037 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1038 const int32_t tex_width = 32;
1039 const int32_t tex_height = 32;
1040
1041 VkImageCreateInfo image_create_info = {};
1042 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1043 image_create_info.pNext = NULL;
1044 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1045 image_create_info.format = tex_format;
1046 image_create_info.extent.width = tex_width;
1047 image_create_info.extent.height = tex_height;
1048 image_create_info.extent.depth = 1;
1049 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06001050 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001051 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001052 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1053 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1054 image_create_info.flags = 0;
1055
Chia-I Wu1f851912015-10-27 18:04:07 +08001056 VkMemoryAllocateInfo mem_alloc = {};
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001057 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
1058 mem_alloc.pNext = NULL;
1059 mem_alloc.allocationSize = 0;
1060 mem_alloc.memoryTypeIndex = 0;
1061
Chia-I Wu69f40122015-10-26 21:10:41 +08001062 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001063 ASSERT_VK_SUCCESS(err);
1064
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06001065 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001066 image,
1067 &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001068
1069 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001070 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1071 ASSERT_TRUE(pass);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001072
1073 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08001074 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001075 ASSERT_VK_SUCCESS(err);
1076
1077 // Introduce validation failure, destroy Image object before binding
Chia-I Wu69f40122015-10-26 21:10:41 +08001078 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001079 ASSERT_VK_SUCCESS(err);
1080
1081 // Now Try to bind memory to this destroyed object
1082 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1083 // This may very well return an error.
1084 (void) err;
1085
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001086 if (!m_errorMonitor->DesiredMsgFound()) {
1087 FAIL() << "Did not receive Error 'Invalid VkImage Object 0x<handle>'";
1088 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001089 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001090
Chia-I Wu69f40122015-10-26 21:10:41 +08001091 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001092}
Tobin Ehlisb46be812015-10-23 16:00:08 -06001093
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001094#endif // OBJ_TRACKER_TESTS
1095
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001096#if DRAW_STATE_TESTS
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001097TEST_F(VkLayerTest, LineWidthStateNotBound)
1098{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001099 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1100 "Dynamic line width state not set for this command buffer");
1101
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001102 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
1103
1104 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
1105
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001106 if (!m_errorMonitor->DesiredMsgFound()) {
1107 FAIL() << "Did not receive Error 'Dynamic line width state not set for this command buffer'";
1108 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001109 }
1110}
1111
1112TEST_F(VkLayerTest, DepthBiasStateNotBound)
1113{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001114 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1115 "Dynamic depth bias state not set for this command buffer");
1116
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001117 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
1118
1119 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
1120
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001121 if (!m_errorMonitor->DesiredMsgFound()) {
1122 FAIL() << "Did not receive Error 'Dynamic depth bias state not set for this command buffer'";
1123 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001124 }
1125}
1126
Cody Northropbca3bcd2015-10-27 16:54:28 -06001127// Disable these two tests until we can sort out how to track multiple layer errors
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001128TEST_F(VkLayerTest, ViewportStateNotBound)
1129{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001130 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1131 "Dynamic viewport state not set for this command buffer");
1132
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001133 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1134
1135 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1136
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001137 if (!m_errorMonitor->DesiredMsgFound()) {
1138 FAIL() << "Did not recieve Error 'Dynamic scissor state not set for this command buffer'";
1139 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001140 }
1141}
1142
1143TEST_F(VkLayerTest, ScissorStateNotBound)
1144{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001145 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1146 "Dynamic scissor state not set for this command buffer");
1147
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001148 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1149
1150 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1151
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001152 if (!m_errorMonitor->DesiredMsgFound()) {
1153 FAIL() << "Did not recieve Error ' Expected: 'Dynamic scissor state not set for this command buffer'";
1154 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001155 }
1156}
1157
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001158TEST_F(VkLayerTest, BlendStateNotBound)
1159{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001160 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1161 "Dynamic blend object state not set for this command buffer");
1162
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001163 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1164
1165 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1166
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001167 if (!m_errorMonitor->DesiredMsgFound()) {
1168 FAIL() << "Did not recieve Error 'Dynamic blend object state not set for this command buffer'";
1169 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001170 }
1171}
1172
1173TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1174{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001175 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1176 "Dynamic depth bounds state not set for this command buffer");
1177
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001178 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1179
1180 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1181
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001182 if (!m_errorMonitor->DesiredMsgFound()) {
1183 FAIL() << "Did not receive Error 'Dynamic depth bounds state not set for this command buffer'";
1184 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001185 }
1186}
1187
1188TEST_F(VkLayerTest, StencilReadMaskNotSet)
1189{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001190 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1191 "Dynamic stencil read mask state not set for this command buffer");
1192
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001193 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001194
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001195 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1196
1197 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1198
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001199 if (!m_errorMonitor->DesiredMsgFound()) {
1200 FAIL() << "Did not receive Error 'Dynamic stencil read mask state not set for this command buffer'";
1201 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001202 }
1203}
1204
1205TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1206{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001207 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1208 "Dynamic stencil write mask state not set for this command buffer");
1209
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001210 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001211
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001212 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1213
1214 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1215
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001216 if (!m_errorMonitor->DesiredMsgFound()) {
1217 FAIL() << "Did not receive Error 'Dynamic stencil write mask state not set for this command buffer'";
1218 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001219 }
1220}
1221
1222TEST_F(VkLayerTest, StencilReferenceNotSet)
1223{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001224 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1225 "Dynamic stencil reference state not set for this command buffer");
1226
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001227 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1228
1229 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1230
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001231 if (!m_errorMonitor->DesiredMsgFound()) {
1232 FAIL() << "Did not receive Error 'Dynamic stencil reference state not set for this command buffer'";
1233 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001234 }
1235}
1236
Chia-I Wu1f851912015-10-27 18:04:07 +08001237TEST_F(VkLayerTest, CommandBufferTwoSubmits)
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001238{
1239 vk_testing::Fence testFence;
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001240
1241 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1242 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted");
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001243
1244 VkFenceCreateInfo fenceInfo = {};
1245 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1246 fenceInfo.pNext = NULL;
1247 fenceInfo.flags = 0;
1248
1249 ASSERT_NO_FATAL_FAILURE(InitState());
1250 ASSERT_NO_FATAL_FAILURE(InitViewport());
1251 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1252
Chia-I Wu1f851912015-10-27 18:04:07 +08001253 // We luck out b/c by default the framework creates CB w/ the VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001254 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08001255 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001256 EndCommandBuffer();
1257
1258 testFence.init(*m_device, fenceInfo);
1259
1260 // Bypass framework since it does the waits automatically
1261 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001262 VkSubmitInfo submit_info;
Chia-I Wu6ec33a02015-10-26 20:37:06 +08001263 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1264 submit_info.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001265 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001266 submit_info.pWaitSemaphores = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001267 submit_info.commandBufferCount = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08001268 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wu763a7492015-10-26 20:48:51 +08001269 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001270 submit_info.pSignalSemaphores = NULL;
1271
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06001272 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001273 ASSERT_VK_SUCCESS( err );
1274
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001275 // Cause validation error by re-submitting cmd buffer that should only be submitted once
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06001276 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001277
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001278 if (!m_errorMonitor->DesiredMsgFound()) {
1279 FAIL() << "Did not receive Error 'CB (0xaddress) was created w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set...'";
1280 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001281 }
1282}
1283
Tobin Ehlise4076782015-06-24 15:53:07 -06001284TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001285{
1286 // Initiate Draw w/o a PSO bound
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001287 VkResult err;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001288
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001289 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1290 "Incorrectly binding graphics pipeline ");
1291
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001292 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001293 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001294
Chia-I Wuc51b1212015-10-27 19:25:11 +08001295 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001296 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001297 ds_type_count.descriptorCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001298
1299 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1300 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1301 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001302 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001303 ds_pool_ci.poolSizeCount = 1;
1304 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001305
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001306 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001307 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001308 ASSERT_VK_SUCCESS(err);
1309
1310 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001311 dsl_binding.binding = 0;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001312 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001313 dsl_binding.descriptorCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001314 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1315 dsl_binding.pImmutableSamplers = NULL;
1316
1317 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1318 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1319 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001320 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001321 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001322
1323 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001324 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001325 ASSERT_VK_SUCCESS(err);
1326
1327 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001328 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001329 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001330 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001331 alloc_info.descriptorPool = ds_pool;
1332 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001333 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001334 ASSERT_VK_SUCCESS(err);
1335 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1336 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1337 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08001338 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001339 pipe_ms_state_ci.sampleShadingEnable = 0;
1340 pipe_ms_state_ci.minSampleShading = 1.0;
1341 pipe_ms_state_ci.pSampleMask = NULL;
1342
1343 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1344 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1345 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001346 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001347 pipeline_layout_ci.pSetLayouts = &ds_layout;
1348 VkPipelineLayout pipeline_layout;
1349
Chia-I Wu69f40122015-10-26 21:10:41 +08001350 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001351 ASSERT_VK_SUCCESS(err);
1352
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001353 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1354 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001355 // but add it to be able to run on more devices
1356 VkPipelineObj pipe(m_device);
1357 pipe.AddShader(&vs);
1358 pipe.AddShader(&fs);
1359 pipe.SetMSAA(&pipe_ms_state_ci);
1360 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001361
Chia-I Wu1f851912015-10-27 18:04:07 +08001362 // Calls AllocateCommandBuffers
1363 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
1364 VkCommandBufferBeginInfo cmd_buf_info = {};
1365 memset(&cmd_buf_info, 0, sizeof(VkCommandBufferBeginInfo));
1366 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001367 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08001368 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001369
Chia-I Wu1f851912015-10-27 18:04:07 +08001370 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
1371 vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001372
1373 if (!m_errorMonitor->DesiredMsgFound()) {
1374 FAIL() << "Did not receive Error 'Incorrectly binding graphics pipeline (0x<handle>) without an active RenderPass'";
1375 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001376 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001377
Chia-I Wu69f40122015-10-26 21:10:41 +08001378 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1379 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1380 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001381}
1382
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001383TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1384{
1385 // Initiate Draw w/o a PSO bound
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001386 VkResult err;
1387
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001388 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1389 "Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
1390
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001391 ASSERT_NO_FATAL_FAILURE(InitState());
1392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001393
1394 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
Chia-I Wuc51b1212015-10-27 19:25:11 +08001395 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001396 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001397 ds_type_count.descriptorCount = 1;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001398
1399 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1400 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1401 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001402 ds_pool_ci.flags = 0;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001403 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001404 ds_pool_ci.poolSizeCount = 1;
1405 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001406
1407 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001408 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001409 ASSERT_VK_SUCCESS(err);
1410
1411 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001412 dsl_binding.binding = 0;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001413 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001414 dsl_binding.descriptorCount = 1;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001415 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1416 dsl_binding.pImmutableSamplers = NULL;
1417
1418 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1419 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1420 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001421 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001422 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001423
1424 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001425 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001426 ASSERT_VK_SUCCESS(err);
1427
1428 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001429 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001430 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001431 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001432 alloc_info.descriptorPool = ds_pool;
1433 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001434 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001435
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001436 if (!m_errorMonitor->DesiredMsgFound()) {
1437 FAIL() << "Did not receive Error 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...'";
1438 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001439 }
1440
Chia-I Wu69f40122015-10-26 21:10:41 +08001441 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1442 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001443}
1444
Tobin Ehlis3c543112015-10-08 13:13:50 -06001445TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1446{
Tobin Ehlis3c543112015-10-08 13:13:50 -06001447 VkResult err;
1448
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001449 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1450 "It is invalid to call vkFreeDescriptorSets() with a pool created without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
1451
Tobin Ehlis3c543112015-10-08 13:13:50 -06001452 ASSERT_NO_FATAL_FAILURE(InitState());
1453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis3c543112015-10-08 13:13:50 -06001454
Chia-I Wuc51b1212015-10-27 19:25:11 +08001455 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis3c543112015-10-08 13:13:50 -06001456 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001457 ds_type_count.descriptorCount = 1;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001458
1459 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1460 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1461 ds_pool_ci.pNext = NULL;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001462 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001463 ds_pool_ci.poolSizeCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001464 ds_pool_ci.flags = 0;
1465 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
1466 // app can only call vkResetDescriptorPool on this pool.;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001467 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001468
1469 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001470 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001471 ASSERT_VK_SUCCESS(err);
1472
1473 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001474 dsl_binding.binding = 0;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001475 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001476 dsl_binding.descriptorCount = 1;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001477 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1478 dsl_binding.pImmutableSamplers = NULL;
1479
1480 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1481 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1482 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001483 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001484 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001485
1486 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001487 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001488 ASSERT_VK_SUCCESS(err);
1489
1490 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001491 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001492 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001493 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001494 alloc_info.descriptorPool = ds_pool;
1495 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001496 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001497 ASSERT_VK_SUCCESS(err);
1498
1499 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001500 if (!m_errorMonitor->DesiredMsgFound()) {
1501 FAIL() << "Did not receive Error 'It is invalid to call vkFreeDescriptorSets() with a pool created with...'";
1502 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3c543112015-10-08 13:13:50 -06001503 }
1504
Chia-I Wu69f40122015-10-26 21:10:41 +08001505 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1506 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001507}
1508
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001509TEST_F(VkLayerTest, InvalidDescriptorPool)
1510{
1511 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1512 // The DS check for this is after driver has been called to validate DS internal data struct
1513 // Attempt to clear DS Pool with bad object
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001514/*
1515 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1516 "Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call");
1517
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001518 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1519 vkResetDescriptorPool(device(), badPool);
1520
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001521 if (!m_errorMonitor->DesiredMsgFound()) {
1522 FAIL() << "Did not receive Error 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1523 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001524 }*/
1525}
1526
1527TEST_F(VkLayerTest, InvalidDescriptorSet)
1528{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001529 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1530 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001531 // Create a valid cmd buffer
1532 // call vkCmdBindDescriptorSets w/ false DS
1533}
1534
1535TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1536{
1537 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1538 // The DS check for this is after driver has been called to validate DS internal data struct
1539}
1540
1541TEST_F(VkLayerTest, InvalidPipeline)
1542{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001543 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1544 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001545 // Create a valid cmd buffer
1546 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001547//
1548// m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1549// "Attempt to bind Pipeline ");
Tobin Ehlise4076782015-06-24 15:53:07 -06001550//
1551// ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +08001552// VkCommandBufferObj commandBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001553// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001554// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Chia-I Wu1f851912015-10-27 18:04:07 +08001555// vkCmdBindPipeline(commandBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001556//
1557// if (!m_errorMonitor->DesiredMsgFound()) {
1558// FAIL() << "Did not receive Error 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1559// m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise4076782015-06-24 15:53:07 -06001560// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001561}
1562
Tobin Ehlis254eca02015-06-25 15:46:59 -06001563TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001564{
Chia-I Wu1f851912015-10-27 18:04:07 +08001565 // Create and update CommandBuffer then call QueueSubmit w/o calling End on CommandBuffer
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001566 VkResult err;
1567
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001568 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
1569 " bound but it was never updated. ");
1570
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001571 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001572 ASSERT_NO_FATAL_FAILURE(InitViewport());
1573 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wuc51b1212015-10-27 19:25:11 +08001574 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001575 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001576 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001577
1578 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1579 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1580 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001581 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001582 ds_pool_ci.poolSizeCount = 1;
1583 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001584
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001585 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001586 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001587 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001588
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001589 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001590 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001591 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001592 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001593 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1594 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001595
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001596 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1597 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1598 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001599 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001600 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001601 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001602 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001603 ASSERT_VK_SUCCESS(err);
1604
1605 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001606 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001607 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001608 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001609 alloc_info.descriptorPool = ds_pool;
1610 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001611 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001612 ASSERT_VK_SUCCESS(err);
1613
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001614 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1615 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1616 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001617 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001618 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001619
1620 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001621 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001622 ASSERT_VK_SUCCESS(err);
1623
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001624 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001625 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
1626 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001627
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001628 VkPipelineObj pipe(m_device);
1629 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001630 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001631 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001632
1633 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08001634 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1635 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001636
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001637 if (!m_errorMonitor->DesiredMsgFound()) {
1638 FAIL() << "Did not recieve Warning 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1639 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001640 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001641
Chia-I Wu69f40122015-10-26 21:10:41 +08001642 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1643 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1644 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001645}
1646
Tobin Ehlis093ef922015-11-02 15:24:32 -07001647TEST_F(VkLayerTest, InvalidBufferViewObject)
1648{
1649 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
1650 VkResult err;
1651
1652 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1653 "Attempt to update descriptor with invalid bufferView ");
1654
1655 ASSERT_NO_FATAL_FAILURE(InitState());
1656 VkDescriptorPoolSize ds_type_count = {};
1657 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1658 ds_type_count.descriptorCount = 1;
1659
1660 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1661 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1662 ds_pool_ci.pNext = NULL;
1663 ds_pool_ci.maxSets = 1;
1664 ds_pool_ci.poolSizeCount = 1;
1665 ds_pool_ci.pPoolSizes = &ds_type_count;
1666
1667 VkDescriptorPool ds_pool;
1668 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1669 ASSERT_VK_SUCCESS(err);
1670
1671 VkDescriptorSetLayoutBinding dsl_binding = {};
1672 dsl_binding.binding = 0;
1673 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001674 dsl_binding.descriptorCount = 1;
Tobin Ehlis093ef922015-11-02 15:24:32 -07001675 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1676 dsl_binding.pImmutableSamplers = NULL;
1677
1678 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1679 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1680 ds_layout_ci.pNext = NULL;
1681 ds_layout_ci.bindingCount = 1;
1682 ds_layout_ci.pBinding = &dsl_binding;
1683 VkDescriptorSetLayout ds_layout;
1684 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1685 ASSERT_VK_SUCCESS(err);
1686
1687 VkDescriptorSet descriptorSet;
1688 VkDescriptorSetAllocateInfo alloc_info = {};
1689 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1690 alloc_info.setLayoutCount = 1;
1691 alloc_info.descriptorPool = ds_pool;
1692 alloc_info.pSetLayouts = &ds_layout;
1693 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1694 ASSERT_VK_SUCCESS(err);
1695
1696 VkBufferView view = (VkBufferView) 0xbaadbeef; // invalid bufferView object
Tobin Ehlis093ef922015-11-02 15:24:32 -07001697 VkWriteDescriptorSet descriptor_write;
1698 memset(&descriptor_write, 0, sizeof(descriptor_write));
1699 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1700 descriptor_write.dstSet = descriptorSet;
1701 descriptor_write.dstBinding = 0;
1702 descriptor_write.descriptorCount = 1;
1703 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1704 descriptor_write.pTexelBufferView = &view;
1705
1706 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1707
1708 if (!m_errorMonitor->DesiredMsgFound()) {
Tobin Ehlisd9491452015-11-05 10:27:49 -07001709 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid bufferView'";
Tobin Ehlis093ef922015-11-02 15:24:32 -07001710 m_errorMonitor->DumpFailureMsgs();
1711 }
1712
1713 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1714 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1715}
1716
Tobin Ehlise2194862015-11-04 13:30:34 -07001717TEST_F(VkLayerTest, InvalidDynamicOffsetCount)
1718{
1719 // Create a descriptorSet w/ some dynamic descriptors and then don't send offsets when binding
1720 VkResult err;
1721 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1722 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but dynamicOffsetCount is 0. ");
1723
1724 ASSERT_NO_FATAL_FAILURE(InitState());
1725 ASSERT_NO_FATAL_FAILURE(InitViewport());
1726 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1727
1728 VkDescriptorPoolSize ds_type_count = {};
1729 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1730 ds_type_count.descriptorCount = 1;
1731
1732 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1733 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1734 ds_pool_ci.pNext = NULL;
1735 ds_pool_ci.maxSets = 1;
1736 ds_pool_ci.poolSizeCount = 1;
1737 ds_pool_ci.pPoolSizes = &ds_type_count;
1738
1739 VkDescriptorPool ds_pool;
1740 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
1741 ASSERT_VK_SUCCESS(err);
1742
1743 VkDescriptorSetLayoutBinding dsl_binding = {};
1744 dsl_binding.binding = 0;
1745 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
Jon Ashburn96b714a2015-11-06 15:31:44 -07001746 dsl_binding.descriptorCount = 1;
Tobin Ehlise2194862015-11-04 13:30:34 -07001747 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1748 dsl_binding.pImmutableSamplers = NULL;
1749
1750 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1751 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1752 ds_layout_ci.pNext = NULL;
1753 ds_layout_ci.bindingCount = 1;
1754 ds_layout_ci.pBinding = &dsl_binding;
1755 VkDescriptorSetLayout ds_layout;
1756 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
1757 ASSERT_VK_SUCCESS(err);
1758
1759 VkDescriptorSet descriptorSet;
1760 VkDescriptorSetAllocateInfo alloc_info = {};
1761 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1762 alloc_info.setLayoutCount = 1;
1763 alloc_info.descriptorPool = ds_pool;
1764 alloc_info.pSetLayouts = &ds_layout;
1765 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1766 ASSERT_VK_SUCCESS(err);
1767
1768 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1769 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1770 pipeline_layout_ci.pNext = NULL;
1771 pipeline_layout_ci.setLayoutCount = 1;
1772 pipeline_layout_ci.pSetLayouts = &ds_layout;
1773
1774 VkPipelineLayout pipeline_layout;
1775 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
1776 ASSERT_VK_SUCCESS(err);
1777
1778 // Create a buffer to update the descriptor with
1779 uint32_t qfi = 0;
1780 VkBufferCreateInfo buffCI = {};
1781 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1782 buffCI.size = 1024;
1783 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1784 buffCI.queueFamilyIndexCount = 1;
1785 buffCI.pQueueFamilyIndices = &qfi;
1786
1787 VkBuffer dyub;
1788 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
1789 ASSERT_VK_SUCCESS(err);
1790 // Correctly update descriptor to avoid "NOT_UPDATED" error
1791 VkDescriptorBufferInfo buffInfo = {};
1792 buffInfo.buffer = dyub;
1793 buffInfo.offset = 0;
1794 buffInfo.range = 1024;
1795
1796 VkWriteDescriptorSet descriptor_write;
1797 memset(&descriptor_write, 0, sizeof(descriptor_write));
1798 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1799 descriptor_write.dstSet = descriptorSet;
1800 descriptor_write.dstBinding = 0;
1801 descriptor_write.descriptorCount = 1;
1802 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
1803 descriptor_write.pBufferInfo = &buffInfo;
1804
1805 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1806
1807 BeginCommandBuffer();
1808 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
1809
1810 if (!m_errorMonitor->DesiredMsgFound()) {
1811 FAIL() << "Error received was not 'Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but dynamicOffsetCount is 0...'";
1812 m_errorMonitor->DumpFailureMsgs();
1813 }
1814
1815 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1816 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1817}
1818
Chia-I Wu1f851912015-10-27 18:04:07 +08001819TEST_F(VkLayerTest, NoBeginCommandBuffer)
Tobin Ehlis254eca02015-06-25 15:46:59 -06001820{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001821
1822 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1823 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlis254eca02015-06-25 15:46:59 -06001824
1825 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1f851912015-10-27 18:04:07 +08001826 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001827 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu1f851912015-10-27 18:04:07 +08001828 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001829
1830 if (!m_errorMonitor->DesiredMsgFound()) {
1831 FAIL() << "Did not recieve Error 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1832 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001833 }
1834}
1835
Chia-I Wu1f851912015-10-27 18:04:07 +08001836TEST_F(VkLayerTest, PrimaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001837{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001838
1839 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1840 "may not specify framebuffer or renderpass parameters");
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001841
1842 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001843
Chia-I Wu1f851912015-10-27 18:04:07 +08001844 // Calls AllocateCommandBuffers
1845 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001846
1847 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Chia-I Wu1f851912015-10-27 18:04:07 +08001848 VkCommandBufferBeginInfo cmd_buf_info = {};
1849 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06001850 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08001851 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Cody Northrop10d8f982015-08-04 17:35:57 -06001852 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1853 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1854
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001855
1856 // The error should be caught by validation of the BeginCommandBuffer call
Chia-I Wu1f851912015-10-27 18:04:07 +08001857 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001858
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001859 if (!m_errorMonitor->DesiredMsgFound()) {
1860 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1861 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001862 }
1863}
1864
Chia-I Wu1f851912015-10-27 18:04:07 +08001865TEST_F(VkLayerTest, SecondaryCommandBufferFramebufferAndRenderpass)
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001866{
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001867 VkResult err;
Chia-I Wu1f851912015-10-27 18:04:07 +08001868 VkCommandBuffer draw_cmd;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001869
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001870 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1871 "must specify framebuffer and renderpass parameters");
1872
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001873 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001874
Chia-I Wu1f851912015-10-27 18:04:07 +08001875 VkCommandBufferAllocateInfo cmd = {};
1876 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOC_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06001877 cmd.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08001878 cmd.commandPool = m_commandPool;
1879 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Chia-I Wu763a7492015-10-26 20:48:51 +08001880 cmd.bufferCount = 1;
Cody Northrop10d8f982015-08-04 17:35:57 -06001881
Chia-I Wu1f851912015-10-27 18:04:07 +08001882 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyan2237f522015-08-18 14:40:24 -06001883 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001884
1885 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu1f851912015-10-27 18:04:07 +08001886 VkCommandBufferBeginInfo cmd_buf_info = {};
1887 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06001888 cmd_buf_info.pNext = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08001889 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001890
1891 // The error should be caught by validation of the BeginCommandBuffer call
1892 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1893
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001894 if (!m_errorMonitor->DesiredMsgFound()) {
1895 FAIL() << "Did not receive Error 'vkAllocateCommandBuffers(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1896 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001897 }
Chia-I Wu1f851912015-10-27 18:04:07 +08001898 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001899}
1900
Tobin Ehlis254eca02015-06-25 15:46:59 -06001901TEST_F(VkLayerTest, InvalidPipelineCreateState)
1902{
1903 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis254eca02015-06-25 15:46:59 -06001904 VkResult err;
1905
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001906 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
1907 "Invalid Pipeline CreateInfo State: Vtx Shader required");
1908
Tobin Ehlis254eca02015-06-25 15:46:59 -06001909 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001910 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001911
Chia-I Wuc51b1212015-10-27 19:25:11 +08001912 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001913 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08001914 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001915
1916 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1917 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1918 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001919 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08001920 ds_pool_ci.poolSizeCount = 1;
1921 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001922
Tobin Ehlis254eca02015-06-25 15:46:59 -06001923 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08001924 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001925 ASSERT_VK_SUCCESS(err);
1926
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001927 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08001928 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001929 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08001930 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001931 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1932 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001933
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001934 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1935 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1936 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08001937 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08001938 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001939
Tobin Ehlis254eca02015-06-25 15:46:59 -06001940 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001941 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001942 ASSERT_VK_SUCCESS(err);
1943
1944 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08001945 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001946 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001947 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001948 alloc_info.descriptorPool = ds_pool;
1949 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08001950 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001951 ASSERT_VK_SUCCESS(err);
1952
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001953 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1954 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08001955 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001956 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001957
1958 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08001959 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001960 ASSERT_VK_SUCCESS(err);
1961
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001962 VkViewport vp = {}; // Just need dummy vp to point to
1963 VkRect2D sc = {}; // dummy scissor to point to
1964
1965 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1966 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1967 vp_state_ci.scissorCount = 1;
1968 vp_state_ci.pScissors = &sc;
1969 vp_state_ci.viewportCount = 1;
1970 vp_state_ci.pViewports = &vp;
1971
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001972 VkGraphicsPipelineCreateInfo gp_ci = {};
1973 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001974 gp_ci.pViewportState = &vp_state_ci;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001975 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1976 gp_ci.layout = pipeline_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001977 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001978
1979 VkPipelineCacheCreateInfo pc_ci = {};
1980 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Chia-I Wu7e470702015-10-26 17:24:52 +08001981 pc_ci.initialDataSize = 0;
1982 pc_ci.pInitialData = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001983
1984 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001985 VkPipelineCache pipelineCache;
1986
Chia-I Wu69f40122015-10-26 21:10:41 +08001987 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001988 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08001989 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001990
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06001991 if (!m_errorMonitor->DesiredMsgFound()) {
1992 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1993 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001994 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001995
Chia-I Wu69f40122015-10-26 21:10:41 +08001996 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
1997 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1998 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1999 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002000}
Tobin Ehlis20693172015-09-17 08:46:18 -06002001/*// TODO : This test should be good, but needs Tess support in compiler to run
2002TEST_F(VkLayerTest, InvalidPatchControlPoints)
2003{
2004 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis20693172015-09-17 08:46:18 -06002005 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06002006
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002007 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2008 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ");
2009
Tobin Ehlis20693172015-09-17 08:46:18 -06002010 ASSERT_NO_FATAL_FAILURE(InitState());
2011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis20693172015-09-17 08:46:18 -06002012
Chia-I Wuc51b1212015-10-27 19:25:11 +08002013 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis20693172015-09-17 08:46:18 -06002014 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002015 ds_type_count.descriptorCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002016
2017 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2018 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2019 ds_pool_ci.pNext = NULL;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002020 ds_pool_ci.poolSizeCount = 1;
2021 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis20693172015-09-17 08:46:18 -06002022
2023 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002024 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis20693172015-09-17 08:46:18 -06002025 ASSERT_VK_SUCCESS(err);
2026
2027 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002028 dsl_binding.binding = 0;
Tobin Ehlis20693172015-09-17 08:46:18 -06002029 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002030 dsl_binding.descriptorCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002031 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2032 dsl_binding.pImmutableSamplers = NULL;
2033
2034 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2035 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2036 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002037 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002038 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis20693172015-09-17 08:46:18 -06002039
2040 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002041 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis20693172015-09-17 08:46:18 -06002042 ASSERT_VK_SUCCESS(err);
2043
2044 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002045 err = vkAllocateDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis20693172015-09-17 08:46:18 -06002046 ASSERT_VK_SUCCESS(err);
2047
2048 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2049 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2050 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002051 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis20693172015-09-17 08:46:18 -06002052 pipeline_layout_ci.pSetLayouts = &ds_layout;
2053
2054 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002055 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis20693172015-09-17 08:46:18 -06002056 ASSERT_VK_SUCCESS(err);
2057
2058 VkPipelineShaderStageCreateInfo shaderStages[3];
2059 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
2060
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002061 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06002062 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002063 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
2064 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06002065
2066 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002067 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002068 shaderStages[0].shader = vs.handle();
2069 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002070 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002071 shaderStages[1].shader = tc.handle();
2072 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002073 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06002074 shaderStages[2].shader = te.handle();
2075
2076 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
2077 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu99ba2bb2015-10-31 00:31:16 +08002078 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis20693172015-09-17 08:46:18 -06002079
2080 VkPipelineTessellationStateCreateInfo tsCI = {};
2081 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
2082 tsCI.patchControlPoints = 0; // This will cause an error
2083
2084 VkGraphicsPipelineCreateInfo gp_ci = {};
2085 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2086 gp_ci.pNext = NULL;
2087 gp_ci.stageCount = 3;
2088 gp_ci.pStages = shaderStages;
2089 gp_ci.pVertexInputState = NULL;
2090 gp_ci.pInputAssemblyState = &iaCI;
2091 gp_ci.pTessellationState = &tsCI;
2092 gp_ci.pViewportState = NULL;
Chia-I Wu1f851912015-10-27 18:04:07 +08002093 gp_ci.pRasterizationState = NULL;
Tobin Ehlis20693172015-09-17 08:46:18 -06002094 gp_ci.pMultisampleState = NULL;
2095 gp_ci.pDepthStencilState = NULL;
2096 gp_ci.pColorBlendState = NULL;
2097 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2098 gp_ci.layout = pipeline_layout;
2099 gp_ci.renderPass = renderPass();
2100
2101 VkPipelineCacheCreateInfo pc_ci = {};
2102 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2103 pc_ci.pNext = NULL;
2104 pc_ci.initialSize = 0;
2105 pc_ci.initialData = 0;
2106 pc_ci.maxSize = 0;
2107
2108 VkPipeline pipeline;
2109 VkPipelineCache pipelineCache;
2110
Chia-I Wu69f40122015-10-26 21:10:41 +08002111 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis20693172015-09-17 08:46:18 -06002112 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002113 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis20693172015-09-17 08:46:18 -06002114
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002115 if (!m_errorMonitor->DesiredMsgFound()) {
2116 FAIL() << "Did not receive Error 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...'";
2117 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis20693172015-09-17 08:46:18 -06002118 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002119
Chia-I Wu69f40122015-10-26 21:10:41 +08002120 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2121 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2122 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2123 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis20693172015-09-17 08:46:18 -06002124}
2125*/
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002126// Set scissor and viewport counts to different numbers
2127TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
2128{
2129 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002130 VkResult err;
2131
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002132 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2133 "Gfx Pipeline viewport count (1) must match scissor count (0).");
2134
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002135 ASSERT_NO_FATAL_FAILURE(InitState());
2136 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002137
Chia-I Wuc51b1212015-10-27 19:25:11 +08002138 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002139 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002140 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002141
2142 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2143 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002144 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002145 ds_pool_ci.poolSizeCount = 1;
2146 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002147
2148 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002149 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002150 ASSERT_VK_SUCCESS(err);
2151
2152 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002153 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002154 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002155 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002156 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2157
2158 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2159 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002160 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002161 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002162
2163 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002164 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002165 ASSERT_VK_SUCCESS(err);
2166
2167 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002168 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002169 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002170 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002171 alloc_info.descriptorPool = ds_pool;
2172 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002173 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002174 ASSERT_VK_SUCCESS(err);
2175
2176 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2177 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002178 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002179 pipeline_layout_ci.pSetLayouts = &ds_layout;
2180
2181 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002182 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002183 ASSERT_VK_SUCCESS(err);
2184
2185 VkViewport vp = {}; // Just need dummy vp to point to
2186
2187 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2188 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2189 vp_state_ci.scissorCount = 0;
2190 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2191 vp_state_ci.pViewports = &vp;
2192
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002193 VkPipelineShaderStageCreateInfo shaderStages[2];
2194 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002195
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002196 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2197 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002198 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002199 shaderStages[0] = vs.GetStageCreateInfo();
2200 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002201
2202 VkGraphicsPipelineCreateInfo gp_ci = {};
2203 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002204 gp_ci.stageCount = 2;
2205 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002206 gp_ci.pViewportState = &vp_state_ci;
2207 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2208 gp_ci.layout = pipeline_layout;
2209 gp_ci.renderPass = renderPass();
2210
2211 VkPipelineCacheCreateInfo pc_ci = {};
2212 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2213
2214 VkPipeline pipeline;
2215 VkPipelineCache pipelineCache;
2216
Chia-I Wu69f40122015-10-26 21:10:41 +08002217 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002218 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002219 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002220
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002221 if (!m_errorMonitor->DesiredMsgFound()) {
2222 FAIL() << "Did not receive Error 'Gfx Pipeline viewport count (1) must match scissor count (0).'";
2223 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002224 }
2225
Chia-I Wu69f40122015-10-26 21:10:41 +08002226 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2227 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2228 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2229 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002230}
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002231// Don't set viewport state in PSO. This is an error b/c we always need this state
2232// for the counts even if the data is going to be set dynamically.
2233TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002234{
2235 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002236 VkResult err;
2237
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002238 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2239 "Gfx Pipeline pViewportState is null. Even if ");
2240
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002241 ASSERT_NO_FATAL_FAILURE(InitState());
2242 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002243
Chia-I Wuc51b1212015-10-27 19:25:11 +08002244 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002245 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002246 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002247
2248 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2249 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002250 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002251 ds_pool_ci.poolSizeCount = 1;
2252 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002253
2254 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002255 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002256 ASSERT_VK_SUCCESS(err);
2257
2258 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002259 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002260 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002261 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002262 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2263
2264 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2265 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002266 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002267 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002268
2269 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002270 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002271 ASSERT_VK_SUCCESS(err);
2272
2273 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002274 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002275 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002276 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002277 alloc_info.descriptorPool = ds_pool;
2278 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002279 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002280 ASSERT_VK_SUCCESS(err);
2281
2282 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2283 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002284 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002285 pipeline_layout_ci.pSetLayouts = &ds_layout;
2286
2287 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002288 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002289 ASSERT_VK_SUCCESS(err);
2290
2291 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2292 // Set scissor as dynamic to avoid second error
2293 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2294 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2295 dyn_state_ci.dynamicStateCount = 1;
2296 dyn_state_ci.pDynamicStates = &sc_state;
2297
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002298 VkPipelineShaderStageCreateInfo shaderStages[2];
2299 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002300
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002301 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2302 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002303 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002304 shaderStages[0] = vs.GetStageCreateInfo();
2305 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002306
2307 VkGraphicsPipelineCreateInfo gp_ci = {};
2308 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002309 gp_ci.stageCount = 2;
2310 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002311 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2312 gp_ci.pDynamicState = &dyn_state_ci;
2313 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2314 gp_ci.layout = pipeline_layout;
2315 gp_ci.renderPass = renderPass();
2316
2317 VkPipelineCacheCreateInfo pc_ci = {};
2318 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2319
2320 VkPipeline pipeline;
2321 VkPipelineCache pipelineCache;
2322
Chia-I Wu69f40122015-10-26 21:10:41 +08002323 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002324 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002325 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002326
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002327 if (!m_errorMonitor->DesiredMsgFound()) {
2328 FAIL() << "Did not receive Error 'Gfx Pipeline pViewportState is null. Even if...'";
2329 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002330 }
2331
Chia-I Wu69f40122015-10-26 21:10:41 +08002332 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2333 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2334 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2335 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002336}
2337// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002338// Then run second test where dynamic scissor count doesn't match PSO scissor count
2339TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002340{
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002341 VkResult err;
2342
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002343 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2344 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
2345
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002346 ASSERT_NO_FATAL_FAILURE(InitState());
2347 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002348
Chia-I Wuc51b1212015-10-27 19:25:11 +08002349 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002350 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002351 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002352
2353 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2354 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002355 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002356 ds_pool_ci.poolSizeCount = 1;
2357 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002358
2359 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002360 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002361 ASSERT_VK_SUCCESS(err);
2362
2363 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002364 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002365 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002366 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002367 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2368
2369 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2370 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002371 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002372 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002373
2374 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002375 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002376 ASSERT_VK_SUCCESS(err);
2377
2378 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002379 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002380 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002381 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002382 alloc_info.descriptorPool = ds_pool;
2383 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002384 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002385 ASSERT_VK_SUCCESS(err);
2386
2387 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2388 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002389 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002390 pipeline_layout_ci.pSetLayouts = &ds_layout;
2391
2392 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002393 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002394 ASSERT_VK_SUCCESS(err);
2395
2396 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2397 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2398 vp_state_ci.viewportCount = 1;
2399 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2400 vp_state_ci.scissorCount = 1;
2401 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2402
2403 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2404 // Set scissor as dynamic to avoid that error
2405 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2406 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2407 dyn_state_ci.dynamicStateCount = 1;
2408 dyn_state_ci.pDynamicStates = &sc_state;
2409
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002410 VkPipelineShaderStageCreateInfo shaderStages[2];
2411 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002412
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002413 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2414 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002415 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002416 shaderStages[0] = vs.GetStageCreateInfo();
2417 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002418
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002419 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2420 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2421 vi_ci.pNext = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002422 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002423 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002424 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002425 vi_ci.pVertexAttributeDescriptions = nullptr;
2426
2427 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2428 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2429 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2430
Chia-I Wu1f851912015-10-27 18:04:07 +08002431 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +08002432 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002433 rs_ci.pNext = nullptr;
2434
2435 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2436 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2437 cb_ci.pNext = nullptr;
2438
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002439 VkGraphicsPipelineCreateInfo gp_ci = {};
2440 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002441 gp_ci.stageCount = 2;
2442 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002443 gp_ci.pVertexInputState = &vi_ci;
2444 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002445 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu1f851912015-10-27 18:04:07 +08002446 gp_ci.pRasterizationState = &rs_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002447 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002448 gp_ci.pDynamicState = &dyn_state_ci;
2449 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2450 gp_ci.layout = pipeline_layout;
2451 gp_ci.renderPass = renderPass();
2452
2453 VkPipelineCacheCreateInfo pc_ci = {};
2454 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2455
2456 VkPipeline pipeline;
2457 VkPipelineCache pipelineCache;
2458
Chia-I Wu69f40122015-10-26 21:10:41 +08002459 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002460 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002461 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002462
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002463 if (!m_errorMonitor->DesiredMsgFound()) {
2464 FAIL() << "Did not recieve Error 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...'";
2465 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002466 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002467
2468
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002469 // Now hit second fail case where we set scissor w/ different count than PSO
2470 // First need to successfully create the PSO from above by setting pViewports
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002471 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2472 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.");
2473
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002474 VkViewport vp = {}; // Just need dummy vp to point to
2475 vp_state_ci.pViewports = &vp;
Chia-I Wu69f40122015-10-26 21:10:41 +08002476 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002477 ASSERT_VK_SUCCESS(err);
2478 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08002479 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002480 VkRect2D scissors[2] = {}; // don't care about data
2481 // Count of 2 doesn't match PSO count of 1
Chia-I Wu1f851912015-10-27 18:04:07 +08002482 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 2, scissors);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002483 Draw(1, 0, 0, 0);
2484
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002485 if (!m_errorMonitor->DesiredMsgFound()) {
2486 FAIL() << "Did not receive Error 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...'";
2487 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002488 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002489
Chia-I Wu69f40122015-10-26 21:10:41 +08002490 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2491 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2492 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2493 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002494}
2495// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002496// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2497TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002498{
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002499 VkResult err;
2500
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002501 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2502 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
2503
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002504 ASSERT_NO_FATAL_FAILURE(InitState());
2505 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002506
Chia-I Wuc51b1212015-10-27 19:25:11 +08002507 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002508 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002509 ds_type_count.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002510
2511 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2512 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002513 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002514 ds_pool_ci.poolSizeCount = 1;
2515 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002516
2517 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002518 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002519 ASSERT_VK_SUCCESS(err);
2520
2521 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002522 dsl_binding.binding = 0;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002523 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002524 dsl_binding.descriptorCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002525 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2526
2527 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2528 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002529 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002530 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002531
2532 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002533 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002534 ASSERT_VK_SUCCESS(err);
2535
2536 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002537 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002538 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002539 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002540 alloc_info.descriptorPool = ds_pool;
2541 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002542 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002543 ASSERT_VK_SUCCESS(err);
2544
2545 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2546 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002547 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002548 pipeline_layout_ci.pSetLayouts = &ds_layout;
2549
2550 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002551 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002552 ASSERT_VK_SUCCESS(err);
2553
2554 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2555 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2556 vp_state_ci.scissorCount = 1;
2557 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2558 vp_state_ci.viewportCount = 1;
2559 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2560
2561 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2562 // Set scissor as dynamic to avoid that error
2563 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2564 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2565 dyn_state_ci.dynamicStateCount = 1;
2566 dyn_state_ci.pDynamicStates = &vp_state;
2567
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002568 VkPipelineShaderStageCreateInfo shaderStages[2];
2569 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002570
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002571 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2572 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002573 // but add it to be able to run on more devices
Chia-I Wu062ad152015-10-31 00:31:16 +08002574 shaderStages[0] = vs.GetStageCreateInfo();
2575 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002576
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002577 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2578 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2579 vi_ci.pNext = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002580 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002581 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wu763a7492015-10-26 20:48:51 +08002582 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002583 vi_ci.pVertexAttributeDescriptions = nullptr;
2584
2585 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2586 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2587 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2588
Chia-I Wu1f851912015-10-27 18:04:07 +08002589 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wuc51b1212015-10-27 19:25:11 +08002590 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002591 rs_ci.pNext = nullptr;
2592
2593 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2594 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2595 cb_ci.pNext = nullptr;
2596
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002597 VkGraphicsPipelineCreateInfo gp_ci = {};
2598 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002599 gp_ci.stageCount = 2;
2600 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002601 gp_ci.pVertexInputState = &vi_ci;
2602 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002603 gp_ci.pViewportState = &vp_state_ci;
Chia-I Wu1f851912015-10-27 18:04:07 +08002604 gp_ci.pRasterizationState = &rs_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002605 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002606 gp_ci.pDynamicState = &dyn_state_ci;
2607 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2608 gp_ci.layout = pipeline_layout;
2609 gp_ci.renderPass = renderPass();
2610
2611 VkPipelineCacheCreateInfo pc_ci = {};
2612 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2613
2614 VkPipeline pipeline;
2615 VkPipelineCache pipelineCache;
2616
Chia-I Wu69f40122015-10-26 21:10:41 +08002617 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002618 ASSERT_VK_SUCCESS(err);
Chia-I Wu69f40122015-10-26 21:10:41 +08002619 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002620
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002621 if (!m_errorMonitor->DesiredMsgFound()) {
2622 FAIL() << "Did not recieve Error 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...'";
2623 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002624 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002625
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002626 // Now hit second fail case where we set scissor w/ different count than PSO
2627 // First need to successfully create the PSO from above by setting pViewports
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002628 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2629 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.");
2630
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002631 VkRect2D sc = {}; // Just need dummy vp to point to
2632 vp_state_ci.pScissors = &sc;
Chia-I Wu69f40122015-10-26 21:10:41 +08002633 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002634 ASSERT_VK_SUCCESS(err);
2635 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08002636 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002637 VkViewport viewports[2] = {}; // don't care about data
2638 // Count of 2 doesn't match PSO count of 1
Chia-I Wu1f851912015-10-27 18:04:07 +08002639 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 2, viewports);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002640 Draw(1, 0, 0, 0);
2641
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002642 if (!m_errorMonitor->DesiredMsgFound()) {
2643 FAIL() << "Did not receive Error 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...'";
2644 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002645 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002646
Chia-I Wu69f40122015-10-26 21:10:41 +08002647 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
2648 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2649 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2650 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002651}
2652
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002653TEST_F(VkLayerTest, NullRenderPass)
2654{
2655 // Bind a NULL RenderPass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002656 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2657 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002658
2659 ASSERT_NO_FATAL_FAILURE(InitState());
2660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002661
Tony Barbour1490c912015-07-28 10:17:20 -06002662 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002663 // Don't care about RenderPass handle b/c error should be flagged before that
Chia-I Wuc51b1212015-10-27 19:25:11 +08002664 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002665
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002666 if (!m_errorMonitor->DesiredMsgFound()) {
2667 FAIL() << "Did not receive Error 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
2668 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002669 }
2670}
2671
Tobin Ehlis254eca02015-06-25 15:46:59 -06002672TEST_F(VkLayerTest, RenderPassWithinRenderPass)
2673{
2674 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002675 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2676 "It is invalid to issue this call inside an active render pass");
Tobin Ehlis254eca02015-06-25 15:46:59 -06002677
2678 ASSERT_NO_FATAL_FAILURE(InitState());
2679 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis254eca02015-06-25 15:46:59 -06002680
Tony Barbour1490c912015-07-28 10:17:20 -06002681 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002682 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002683 VkRenderPassBeginInfo rp_begin = {};
2684 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
2685 rp_begin.pNext = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002686 rp_begin.renderPass = renderPass();
2687 rp_begin.framebuffer = framebuffer();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002688
Chia-I Wuc51b1212015-10-27 19:25:11 +08002689 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002690
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002691 if (!m_errorMonitor->DesiredMsgFound()) {
2692 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2693 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002694 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002695}
2696
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002697TEST_F(VkLayerTest, FillBufferWithinRenderPass)
2698{
2699 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002700 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2701 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002702
2703 ASSERT_NO_FATAL_FAILURE(InitState());
2704 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002705
2706 // Renderpass is started here
2707 BeginCommandBuffer();
2708
2709 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08002710 vk_testing::Buffer dstBuffer;
2711 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002712
Chia-I Wu1f851912015-10-27 18:04:07 +08002713 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002714
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002715 if (!m_errorMonitor->DesiredMsgFound()) {
2716 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2717 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002718 }
2719}
2720
2721TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
2722{
2723 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002724 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2725 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002726
2727 ASSERT_NO_FATAL_FAILURE(InitState());
2728 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002729
2730 // Renderpass is started here
2731 BeginCommandBuffer();
2732
2733 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08002734 vk_testing::Buffer dstBuffer;
2735 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002736
Chia-I Wu1f851912015-10-27 18:04:07 +08002737 VkDeviceSize dstOffset = 0;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002738 VkDeviceSize dataSize = 1024;
2739 const uint32_t *pData = NULL;
2740
Chia-I Wu1f851912015-10-27 18:04:07 +08002741 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002742
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002743 if (!m_errorMonitor->DesiredMsgFound()) {
2744 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2745 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002746 }
2747}
2748
2749TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
2750{
2751 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002752 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2753 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002754
2755 ASSERT_NO_FATAL_FAILURE(InitState());
2756 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002757
2758 // Renderpass is started here
2759 BeginCommandBuffer();
2760
2761 VkClearColorValue clear_color = {0};
2762 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2763 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2764 const int32_t tex_width = 32;
2765 const int32_t tex_height = 32;
2766 VkImageCreateInfo image_create_info = {};
2767 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2768 image_create_info.pNext = NULL;
2769 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2770 image_create_info.format = tex_format;
2771 image_create_info.extent.width = tex_width;
2772 image_create_info.extent.height = tex_height;
2773 image_create_info.extent.depth = 1;
2774 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06002775 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08002776 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002777 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2778 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2779
Chia-I Wu1f851912015-10-27 18:04:07 +08002780 vk_testing::Image dstImage;
2781 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002782
2783 const VkImageSubresourceRange range =
2784 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
2785
Chia-I Wu1f851912015-10-27 18:04:07 +08002786 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(),
2787 dstImage.handle(),
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002788 VK_IMAGE_LAYOUT_GENERAL,
2789 &clear_color,
2790 1,
2791 &range);
2792
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002793 if (!m_errorMonitor->DesiredMsgFound()) {
2794 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2795 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002796 }
2797}
2798
2799TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
2800{
2801 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002802 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2803 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002804
2805 ASSERT_NO_FATAL_FAILURE(InitState());
2806 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002807
2808 // Renderpass is started here
2809 BeginCommandBuffer();
2810
2811 VkClearDepthStencilValue clear_value = {0};
2812 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2813 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
2814 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2815 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
2816 image_create_info.extent.width = 64;
2817 image_create_info.extent.height = 64;
2818 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2819 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
2820
Chia-I Wu1f851912015-10-27 18:04:07 +08002821 vk_testing::Image dstImage;
2822 dstImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002823
2824 const VkImageSubresourceRange range =
2825 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
2826
Chia-I Wu1f851912015-10-27 18:04:07 +08002827 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(),
2828 dstImage.handle(),
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002829 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2830 &clear_value,
2831 1,
2832 &range);
2833
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002834 if (!m_errorMonitor->DesiredMsgFound()) {
2835 FAIL() << "Did not receive Error 'It is invalid to issue this call inside an active render pass...'";
2836 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002837 }
2838}
2839
2840TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
2841{
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002842 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002843 VkResult err;
2844
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002845 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2846 "vkCmdClearAttachments: This call must be issued inside an active render pass");
2847
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002848 ASSERT_NO_FATAL_FAILURE(InitState());
2849 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002850
2851 // Start no RenderPass
Chia-I Wu1f851912015-10-27 18:04:07 +08002852 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002853 ASSERT_VK_SUCCESS(err);
2854
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002855 VkClearAttachment color_attachment;
2856 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2857 color_attachment.clearValue.color.float32[0] = 0;
2858 color_attachment.clearValue.color.float32[1] = 0;
2859 color_attachment.clearValue.color.float32[2] = 0;
2860 color_attachment.clearValue.color.float32[3] = 0;
2861 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06002862 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Chia-I Wu1f851912015-10-27 18:04:07 +08002863 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(),
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002864 1, &color_attachment,
2865 1, &clear_rect);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002866
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002867 if (!m_errorMonitor->DesiredMsgFound()) {
2868 FAIL() << "Did not receive Error 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
2869 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002870 }
2871}
2872
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002873TEST_F(VkLayerTest, InvalidDynamicStateObject)
2874{
2875 // Create a valid cmd buffer
2876 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002877 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
2878 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002879}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06002880
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002881TEST_F(VkLayerTest, IdxBufferAlignmentError)
2882{
2883 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002884 VkResult err;
2885
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002886 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2887 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
2888
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002889 ASSERT_NO_FATAL_FAILURE(InitState());
2890 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002891 uint32_t qfi = 0;
2892 VkBufferCreateInfo buffCI = {};
2893 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2894 buffCI.size = 1024;
2895 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
Chia-I Wu763a7492015-10-26 20:48:51 +08002896 buffCI.queueFamilyIndexCount = 1;
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002897 buffCI.pQueueFamilyIndices = &qfi;
2898
2899 VkBuffer ib;
Chia-I Wu69f40122015-10-26 21:10:41 +08002900 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002901 ASSERT_VK_SUCCESS(err);
2902
2903 BeginCommandBuffer();
2904 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08002905 //vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002906 // Should error before calling to driver so don't care about actual data
Chia-I Wu1f851912015-10-27 18:04:07 +08002907 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002908
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002909 if (!m_errorMonitor->DesiredMsgFound()) {
2910 FAIL() << "Did not receive Error 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...'";
2911 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002912 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002913
Chia-I Wu69f40122015-10-26 21:10:41 +08002914 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002915}
2916
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002917TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
2918{
2919 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002920
2921 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2922 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002923
2924 ASSERT_NO_FATAL_FAILURE(InitState());
2925 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002926
2927 BeginCommandBuffer();
2928 //ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08002929 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
2930 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002931
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002932 if (!m_errorMonitor->DesiredMsgFound()) {
2933 FAIL() << "Did not receive Error 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer '";
2934 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002935 }
2936}
2937
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002938TEST_F(VkLayerTest, DSTypeMismatch)
2939{
2940 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002941 VkResult err;
2942
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06002943 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
2944 "Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match ");
2945
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002946 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002947 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08002948 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002949 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08002950 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002951
2952 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2953 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2954 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002955 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08002956 ds_pool_ci.poolSizeCount = 1;
2957 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002958
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002959 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08002960 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002961 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002962 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08002963 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002964 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08002965 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002966 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2967 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002968
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002969 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2970 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2971 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08002972 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08002973 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002974
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002975 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08002976 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002977 ASSERT_VK_SUCCESS(err);
2978
2979 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08002980 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002981 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08002982 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002983 alloc_info.descriptorPool = ds_pool;
2984 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08002985 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002986 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002987
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002988 VkSamplerCreateInfo sampler_ci = {};
2989 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2990 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08002991 sampler_ci.magFilter = VK_FILTER_NEAREST;
2992 sampler_ci.minFilter = VK_FILTER_NEAREST;
2993 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08002994 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2995 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2996 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002997 sampler_ci.mipLodBias = 1.0;
2998 sampler_ci.maxAnisotropy = 1;
2999 sampler_ci.compareEnable = VK_FALSE;
3000 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3001 sampler_ci.minLod = 1.0;
3002 sampler_ci.maxLod = 1.0;
3003 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003004 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3005
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003006 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003007 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003008 ASSERT_VK_SUCCESS(err);
3009
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003010 VkDescriptorImageInfo info = {};
3011 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003012
3013 VkWriteDescriptorSet descriptor_write;
3014 memset(&descriptor_write, 0, sizeof(descriptor_write));
3015 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003016 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08003017 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003018 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003019 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003020 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003021
3022 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3023
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003024 if (!m_errorMonitor->DesiredMsgFound()) {
3025 FAIL() << "Did not receive Error 'Write descriptor update has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...'";
3026 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003027 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003028
Chia-I Wu69f40122015-10-26 21:10:41 +08003029 vkDestroySampler(m_device->device(), sampler, NULL);
3030 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3031 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003032}
3033
3034TEST_F(VkLayerTest, DSUpdateOutOfBounds)
3035{
3036 // For overlapping Update, have arrayIndex exceed that of layout
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003037 VkResult err;
3038
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003039 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3040 "Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding");
3041
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003042 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003043 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003044 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003045 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003046 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003047
3048 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3049 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3050 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003051 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003052 ds_pool_ci.poolSizeCount = 1;
3053 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003054
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003055 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003056 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003057 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003058
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003059 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003060 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003061 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003062 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003063 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3064 dsl_binding.pImmutableSamplers = NULL;
3065
3066 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3067 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3068 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003069 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003070 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003071
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003072 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003073 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003074 ASSERT_VK_SUCCESS(err);
3075
3076 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003077 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003078 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003079 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003080 alloc_info.descriptorPool = ds_pool;
3081 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003082 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003083 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003084
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003085 VkSamplerCreateInfo sampler_ci = {};
3086 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3087 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003088 sampler_ci.magFilter = VK_FILTER_NEAREST;
3089 sampler_ci.minFilter = VK_FILTER_NEAREST;
3090 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003091 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3092 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3093 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003094 sampler_ci.mipLodBias = 1.0;
3095 sampler_ci.maxAnisotropy = 1;
3096 sampler_ci.compareEnable = VK_FALSE;
3097 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3098 sampler_ci.minLod = 1.0;
3099 sampler_ci.maxLod = 1.0;
3100 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003101 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003102
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003103 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003104 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003105 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003106
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003107 VkDescriptorImageInfo info = {};
3108 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003109
3110 VkWriteDescriptorSet descriptor_write;
3111 memset(&descriptor_write, 0, sizeof(descriptor_write));
3112 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003113 descriptor_write.dstSet = descriptorSet;
3114 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wu763a7492015-10-26 20:48:51 +08003115 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003116 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003117 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003118 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003119
3120 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3121
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003122 if (!m_errorMonitor->DesiredMsgFound()) {
3123 FAIL() << "Did not receive Error 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
3124 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003125 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003126
Chia-I Wu69f40122015-10-26 21:10:41 +08003127 vkDestroySampler(m_device->device(), sampler, NULL);
3128 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3129 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003130}
3131
3132TEST_F(VkLayerTest, InvalidDSUpdateIndex)
3133{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003134 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003135 VkResult err;
3136
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003137 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3138 " does not have binding to match update binding ");
3139
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003140 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003141 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003142 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003143 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003144 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003145
3146 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3147 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3148 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003149 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003150 ds_pool_ci.poolSizeCount = 1;
3151 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003152
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003153 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003154 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003155 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003156
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003157 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003158 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003159 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003160 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003161 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3162 dsl_binding.pImmutableSamplers = NULL;
3163
3164 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3165 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3166 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003167 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003168 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003169 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003170 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003171 ASSERT_VK_SUCCESS(err);
3172
3173 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003174 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003175 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003176 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003177 alloc_info.descriptorPool = ds_pool;
3178 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003179 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003180 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003181
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003182 VkSamplerCreateInfo sampler_ci = {};
3183 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3184 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003185 sampler_ci.magFilter = VK_FILTER_NEAREST;
3186 sampler_ci.minFilter = VK_FILTER_NEAREST;
3187 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003188 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3189 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3190 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003191 sampler_ci.mipLodBias = 1.0;
3192 sampler_ci.maxAnisotropy = 1;
3193 sampler_ci.compareEnable = VK_FALSE;
3194 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3195 sampler_ci.minLod = 1.0;
3196 sampler_ci.maxLod = 1.0;
3197 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003198 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003199
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003200 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003201 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003202 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003203
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003204 VkDescriptorImageInfo info = {};
3205 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003206
3207 VkWriteDescriptorSet descriptor_write;
3208 memset(&descriptor_write, 0, sizeof(descriptor_write));
3209 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003210 descriptor_write.dstSet = descriptorSet;
3211 descriptor_write.dstBinding = 2;
Chia-I Wu763a7492015-10-26 20:48:51 +08003212 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003213 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003214 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003215 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003216
3217 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3218
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003219 if (!m_errorMonitor->DesiredMsgFound()) {
3220 FAIL() << "Did not receive Error 'Descriptor Set <blah> does not have binding to match update binding '";
3221 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003222 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003223
Chia-I Wu69f40122015-10-26 21:10:41 +08003224 vkDestroySampler(m_device->device(), sampler, NULL);
3225 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3226 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003227}
3228
3229TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3230{
3231 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003232 VkResult err;
3233
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003234 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3235 "Unexpected UPDATE struct of type ");
3236
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003237 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003238
Chia-I Wuc51b1212015-10-27 19:25:11 +08003239 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003240 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003241 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003242
3243 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3244 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3245 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003246 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003247 ds_pool_ci.poolSizeCount = 1;
3248 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003249
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003250 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003251 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003252 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003253 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003254 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003255 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003256 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003257 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3258 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003259
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003260 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3261 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3262 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003263 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003264 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003265
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003266 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003267 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003268 ASSERT_VK_SUCCESS(err);
3269
3270 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003271 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003272 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003273 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003274 alloc_info.descriptorPool = ds_pool;
3275 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003276 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003277 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003278
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003279 VkSamplerCreateInfo sampler_ci = {};
3280 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3281 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003282 sampler_ci.magFilter = VK_FILTER_NEAREST;
3283 sampler_ci.minFilter = VK_FILTER_NEAREST;
3284 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003285 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3286 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3287 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003288 sampler_ci.mipLodBias = 1.0;
3289 sampler_ci.maxAnisotropy = 1;
3290 sampler_ci.compareEnable = VK_FALSE;
3291 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3292 sampler_ci.minLod = 1.0;
3293 sampler_ci.maxLod = 1.0;
3294 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003295 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003296 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003297 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003298 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003299
3300
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003301 VkDescriptorImageInfo info = {};
3302 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003303
3304 VkWriteDescriptorSet descriptor_write;
3305 memset(&descriptor_write, 0, sizeof(descriptor_write));
3306 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu1f851912015-10-27 18:04:07 +08003307 descriptor_write.dstSet = descriptorSet;
Chia-I Wu763a7492015-10-26 20:48:51 +08003308 descriptor_write.descriptorCount = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003309 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003310 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003311 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003312
3313 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3314
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003315 if (!m_errorMonitor->DesiredMsgFound()) {
3316 FAIL() << "Did not receive Error 'Unexpected UPDATE struct of type '";
3317 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003318 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003319
Chia-I Wu69f40122015-10-26 21:10:41 +08003320 vkDestroySampler(m_device->device(), sampler, NULL);
3321 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3322 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003323}
3324
Tobin Ehlisb46be812015-10-23 16:00:08 -06003325TEST_F(VkLayerTest, SampleDescriptorUpdateError)
3326{
3327 // Create a single Sampler descriptor and send it an invalid Sampler
Tobin Ehlisb46be812015-10-23 16:00:08 -06003328 VkResult err;
3329
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003330 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3331 "Attempt to update descriptor with invalid sampler 0xbaadbeef");
3332
Tobin Ehlisb46be812015-10-23 16:00:08 -06003333 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb46be812015-10-23 16:00:08 -06003334 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied code
Chia-I Wuc51b1212015-10-27 19:25:11 +08003335 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003336 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003337 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003338
3339 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3340 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3341 ds_pool_ci.pNext = NULL;
3342 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003343 ds_pool_ci.poolSizeCount = 1;
3344 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003345
3346 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003347 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003348 ASSERT_VK_SUCCESS(err);
3349
3350 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003351 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003352 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003353 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003354 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3355 dsl_binding.pImmutableSamplers = NULL;
3356
3357 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3358 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3359 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003360 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003361 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003362 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003363 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003364 ASSERT_VK_SUCCESS(err);
3365
3366 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003367 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003368 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003369 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003370 alloc_info.descriptorPool = ds_pool;
3371 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003372 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003373 ASSERT_VK_SUCCESS(err);
3374
Chia-I Wue420a332015-10-26 20:04:44 +08003375 VkSampler sampler = (VkSampler) 0xbaadbeef; // Sampler with invalid handle
Tobin Ehlisb46be812015-10-23 16:00:08 -06003376
3377 VkDescriptorImageInfo descriptor_info;
3378 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3379 descriptor_info.sampler = sampler;
3380
3381 VkWriteDescriptorSet descriptor_write;
3382 memset(&descriptor_write, 0, sizeof(descriptor_write));
3383 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003384 descriptor_write.dstSet = descriptorSet;
3385 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003386 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003387 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3388 descriptor_write.pImageInfo = &descriptor_info;
3389
3390 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3391
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003392 if (!m_errorMonitor->DesiredMsgFound()) {
3393 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid sampler...'";
3394 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06003395 }
3396
Chia-I Wu69f40122015-10-26 21:10:41 +08003397 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3398 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003399}
3400
3401TEST_F(VkLayerTest, ImageViewDescriptorUpdateError)
3402{
3403 // Create a single combined Image/Sampler descriptor and send it an invalid imageView
Tobin Ehlisb46be812015-10-23 16:00:08 -06003404 VkResult err;
3405
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003406 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3407 "Attempt to update descriptor with invalid imageView 0xbaadbeef");
3408
Tobin Ehlisb46be812015-10-23 16:00:08 -06003409 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wuc51b1212015-10-27 19:25:11 +08003410 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003411 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003412 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003413
3414 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3415 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3416 ds_pool_ci.pNext = NULL;
3417 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003418 ds_pool_ci.poolSizeCount = 1;
3419 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003420
3421 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003422 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003423 ASSERT_VK_SUCCESS(err);
3424
3425 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003426 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003427 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003428 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003429 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3430 dsl_binding.pImmutableSamplers = NULL;
3431
3432 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3433 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3434 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003435 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003436 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003437 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003438 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003439 ASSERT_VK_SUCCESS(err);
3440
3441 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003442 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06003443 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003444 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003445 alloc_info.descriptorPool = ds_pool;
3446 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003447 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003448 ASSERT_VK_SUCCESS(err);
3449
3450 VkSamplerCreateInfo sampler_ci = {};
3451 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3452 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003453 sampler_ci.magFilter = VK_FILTER_NEAREST;
3454 sampler_ci.minFilter = VK_FILTER_NEAREST;
3455 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003456 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3457 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3458 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003459 sampler_ci.mipLodBias = 1.0;
3460 sampler_ci.maxAnisotropy = 1;
3461 sampler_ci.compareEnable = VK_FALSE;
3462 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3463 sampler_ci.minLod = 1.0;
3464 sampler_ci.maxLod = 1.0;
3465 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3466 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3467
3468 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003469 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003470 ASSERT_VK_SUCCESS(err);
3471
Chia-I Wue420a332015-10-26 20:04:44 +08003472 VkImageView view = (VkImageView) 0xbaadbeef; // invalid imageView object
Tobin Ehlisb46be812015-10-23 16:00:08 -06003473
3474 VkDescriptorImageInfo descriptor_info;
3475 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3476 descriptor_info.sampler = sampler;
3477 descriptor_info.imageView = view;
3478
3479 VkWriteDescriptorSet descriptor_write;
3480 memset(&descriptor_write, 0, sizeof(descriptor_write));
3481 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003482 descriptor_write.dstSet = descriptorSet;
3483 descriptor_write.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003484 descriptor_write.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06003485 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3486 descriptor_write.pImageInfo = &descriptor_info;
3487
3488 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3489
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003490 if (!m_errorMonitor->DesiredMsgFound()) {
3491 FAIL() << "Did not receive Error 'Attempt to update descriptor with invalid imageView...'";
3492 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06003493 }
3494
Chia-I Wu69f40122015-10-26 21:10:41 +08003495 vkDestroySampler(m_device->device(), sampler, NULL);
3496 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3497 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06003498}
3499
Tobin Ehlis3e676262015-10-27 16:35:27 -06003500TEST_F(VkLayerTest, CopyDescriptorUpdateErrors)
3501{
3502 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update into the other
Tobin Ehlis3e676262015-10-27 16:35:27 -06003503 VkResult err;
3504
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003505 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3506 "Copy descriptor update index 0, update count #1, has src update descriptor type VK_DESCRIPTOR_TYPE_SAMPLER ");
3507
Tobin Ehlis3e676262015-10-27 16:35:27 -06003508 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis3e676262015-10-27 16:35:27 -06003509 //VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuc51b1212015-10-27 19:25:11 +08003510 VkDescriptorPoolSize ds_type_count[2] = {};
Tobin Ehlis3e676262015-10-27 16:35:27 -06003511 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003512 ds_type_count[0].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003513 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003514 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003515
3516 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3517 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3518 ds_pool_ci.pNext = NULL;
3519 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003520 ds_pool_ci.poolSizeCount = 2;
3521 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003522
3523 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003524 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003525 ASSERT_VK_SUCCESS(err);
3526 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003527 dsl_binding[0].binding = 0;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003528 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003529 dsl_binding[0].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003530 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3531 dsl_binding[0].pImmutableSamplers = NULL;
Chia-I Wub5689ee2015-10-31 00:31:16 +08003532 dsl_binding[1].binding = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003533 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003534 dsl_binding[1].descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003535 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
3536 dsl_binding[1].pImmutableSamplers = NULL;
3537
3538 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3539 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3540 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003541 ds_layout_ci.bindingCount = 2;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003542 ds_layout_ci.pBinding = dsl_binding;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003543
3544 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003545 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003546 ASSERT_VK_SUCCESS(err);
3547
3548 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003549 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis3e676262015-10-27 16:35:27 -06003550 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003551 alloc_info.setLayoutCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003552 alloc_info.descriptorPool = ds_pool;
3553 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003554 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003555 ASSERT_VK_SUCCESS(err);
3556
3557 VkSamplerCreateInfo sampler_ci = {};
3558 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3559 sampler_ci.pNext = NULL;
Chia-I Wu3603b082015-10-26 16:49:32 +08003560 sampler_ci.magFilter = VK_FILTER_NEAREST;
3561 sampler_ci.minFilter = VK_FILTER_NEAREST;
3562 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_BASE;
Chia-I Wuce532f72015-10-26 17:32:47 +08003563 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3564 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3565 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003566 sampler_ci.mipLodBias = 1.0;
3567 sampler_ci.maxAnisotropy = 1;
3568 sampler_ci.compareEnable = VK_FALSE;
3569 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3570 sampler_ci.minLod = 1.0;
3571 sampler_ci.maxLod = 1.0;
3572 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3573 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3574
3575 VkSampler sampler;
Chia-I Wu69f40122015-10-26 21:10:41 +08003576 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003577 ASSERT_VK_SUCCESS(err);
3578
3579 VkDescriptorImageInfo info = {};
3580 info.sampler = sampler;
3581
3582 VkWriteDescriptorSet descriptor_write;
3583 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
3584 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu1f851912015-10-27 18:04:07 +08003585 descriptor_write.dstSet = descriptorSet;
3586 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wu763a7492015-10-26 20:48:51 +08003587 descriptor_write.descriptorCount = 1;
Tobin Ehlis3e676262015-10-27 16:35:27 -06003588 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3589 descriptor_write.pImageInfo = &info;
3590 // This write update should succeed
3591 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3592 // Now perform a copy update that fails due to type mismatch
3593 VkCopyDescriptorSet copy_ds_update;
3594 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3595 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3596 copy_ds_update.srcSet = descriptorSet;
3597 copy_ds_update.srcBinding = 1; // copy from SAMPLER binding
Chia-I Wu1f851912015-10-27 18:04:07 +08003598 copy_ds_update.dstSet = descriptorSet;
3599 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wu763a7492015-10-26 20:48:51 +08003600 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06003601 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3602
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003603 if (!m_errorMonitor->DesiredMsgFound()) {
3604 FAIL() << "Did not receive Error 'Copy descriptor update index 0, update count #1, has src update descriptor type_DESCRIPTOR_TYPE_SAMPLER'";
3605 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06003606 }
3607 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003608 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3609 "Copy descriptor update 0 has srcBinding 3 which is out of bounds ");
Tobin Ehlis3e676262015-10-27 16:35:27 -06003610 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3611 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3612 copy_ds_update.srcSet = descriptorSet;
3613 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu1f851912015-10-27 18:04:07 +08003614 copy_ds_update.dstSet = descriptorSet;
3615 copy_ds_update.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003616 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis3e676262015-10-27 16:35:27 -06003617 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3618
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003619 if (!m_errorMonitor->DesiredMsgFound()) {
3620 FAIL() << "Did not receive Error 'Copy descriptor update 0 has srcBinding 3 which is out of bounds...'";
3621 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06003622 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003623
Tobin Ehlis3e676262015-10-27 16:35:27 -06003624 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003625 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3626 "Copy descriptor src update is out of bounds for matching binding 1 ");
3627
Tobin Ehlis3e676262015-10-27 16:35:27 -06003628 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
3629 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
3630 copy_ds_update.srcSet = descriptorSet;
3631 copy_ds_update.srcBinding = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08003632 copy_ds_update.dstSet = descriptorSet;
3633 copy_ds_update.dstBinding = 0;
Chia-I Wu763a7492015-10-26 20:48:51 +08003634 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis3e676262015-10-27 16:35:27 -06003635 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
3636
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003637 if (!m_errorMonitor->DesiredMsgFound()) {
3638 FAIL() << "Did not receive Error 'Copy descriptor src update is out of bounds for matching binding 1...'";
3639 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis3e676262015-10-27 16:35:27 -06003640 }
3641
Chia-I Wu69f40122015-10-26 21:10:41 +08003642 vkDestroySampler(m_device->device(), sampler, NULL);
3643 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3644 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis3e676262015-10-27 16:35:27 -06003645}
3646
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003647TEST_F(VkLayerTest, NumSamplesMismatch)
3648{
Chia-I Wu1f851912015-10-27 18:04:07 +08003649 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003650 VkResult err;
3651
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003652 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3653 "Num samples mismatch! ");
3654
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003655 ASSERT_NO_FATAL_FAILURE(InitState());
3656 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wuc51b1212015-10-27 19:25:11 +08003657 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003658 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003659 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003660
3661 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003662 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3663 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003664 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003665 ds_pool_ci.poolSizeCount = 1;
3666 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003667
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003668 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003669 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003670 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003671
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003672 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003673 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003674 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003675 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003676 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3677 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003678
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003679 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3680 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3681 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003682 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003683 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003684
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003685 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003686 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003687 ASSERT_VK_SUCCESS(err);
3688
3689 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003690 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003691 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003692 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003693 alloc_info.descriptorPool = ds_pool;
3694 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003695 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003696 ASSERT_VK_SUCCESS(err);
3697
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003698 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3699 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3700 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08003701 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003702 pipe_ms_state_ci.sampleShadingEnable = 0;
3703 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003704 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003705
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003706 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3707 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3708 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003709 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003710 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003711
3712 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003713 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003714 ASSERT_VK_SUCCESS(err);
3715
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003716 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3717 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003718 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003719 VkPipelineObj pipe(m_device);
3720 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003721 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003722 pipe.SetMSAA(&pipe_ms_state_ci);
3723 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003724
Tony Barbour1490c912015-07-28 10:17:20 -06003725 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08003726 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003727
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003728 if (!m_errorMonitor->DesiredMsgFound()) {
3729 FAIL() << "Did not recieve Error 'Num samples mismatch!...'";
3730 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003731 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003732
Chia-I Wu69f40122015-10-26 21:10:41 +08003733 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3734 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3735 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003736}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003737
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003738TEST_F(VkLayerTest, ClearCmdNoDraw)
3739{
Chia-I Wu1f851912015-10-27 18:04:07 +08003740 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003741 VkResult err;
3742
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003743 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
3744 "vkCmdClearAttachments() issued on CB object ");
3745
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003746 ASSERT_NO_FATAL_FAILURE(InitState());
3747 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003748
Chia-I Wuc51b1212015-10-27 19:25:11 +08003749 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003750 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003751 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003752
3753 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3754 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3755 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003756 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003757 ds_pool_ci.poolSizeCount = 1;
3758 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003759
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003760 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003761 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003762 ASSERT_VK_SUCCESS(err);
3763
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003764 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003765 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003766 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003767 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003768 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3769 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003770
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003771 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3772 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3773 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003774 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003775 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003776
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003777 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003778 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003779 ASSERT_VK_SUCCESS(err);
3780
3781 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003782 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003783 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003784 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003785 alloc_info.descriptorPool = ds_pool;
3786 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003787 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003788 ASSERT_VK_SUCCESS(err);
3789
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003790 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3791 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3792 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08003793 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003794 pipe_ms_state_ci.sampleShadingEnable = 0;
3795 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003796 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003797
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003798 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3799 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3800 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003801 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003802 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003803
3804 VkPipelineLayout pipeline_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003805 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003806 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003807
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003808 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003809 // TODO - We shouldn't need a fragment shader but add it to be able to run on more devices
3810 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3811
Tony Barbourd7d828b2015-08-06 10:16:07 -06003812 VkPipelineObj pipe(m_device);
3813 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003814 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003815 pipe.SetMSAA(&pipe_ms_state_ci);
3816 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003817
3818 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003819
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003820 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
3821 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003822 VkClearAttachment color_attachment;
3823 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3824 color_attachment.clearValue.color.float32[0] = 1.0;
3825 color_attachment.clearValue.color.float32[1] = 1.0;
3826 color_attachment.clearValue.color.float32[2] = 1.0;
3827 color_attachment.clearValue.color.float32[3] = 1.0;
3828 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06003829 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003830
Chia-I Wu1f851912015-10-27 18:04:07 +08003831 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003832
3833 if (!m_errorMonitor->DesiredMsgFound()) {
3834 FAIL() << "Did not receive Error 'vkCommandClearAttachments() issued on CB object...'";
3835 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003836 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003837
Chia-I Wu69f40122015-10-26 21:10:41 +08003838 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3839 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3840 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003841}
3842
Tobin Ehlise4076782015-06-24 15:53:07 -06003843TEST_F(VkLayerTest, VtxBufferBadIndex)
3844{
Chia-I Wu1f851912015-10-27 18:04:07 +08003845 // Create CommandBuffer where MSAA samples doesn't match RenderPass sampleCount
Tobin Ehlise4076782015-06-24 15:53:07 -06003846 VkResult err;
3847
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003848 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
3849 "Vtx Buffer Index 1 was bound, but no vtx buffers are attached to PSO.");
3850
Tobin Ehlise4076782015-06-24 15:53:07 -06003851 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003852 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlise4076782015-06-24 15:53:07 -06003853 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003854
Chia-I Wuc51b1212015-10-27 19:25:11 +08003855 VkDescriptorPoolSize ds_type_count = {};
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003856 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu763a7492015-10-26 20:48:51 +08003857 ds_type_count.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003858
3859 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3860 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3861 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003862 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08003863 ds_pool_ci.poolSizeCount = 1;
3864 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003865
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003866 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08003867 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06003868 ASSERT_VK_SUCCESS(err);
3869
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003870 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08003871 dsl_binding.binding = 0;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003872 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu045654f2015-11-06 06:42:02 +08003873 dsl_binding.descriptorCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003874 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3875 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003876
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003877 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3878 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3879 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003880 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08003881 ds_layout_ci.pBinding = &dsl_binding;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003882
Tobin Ehlise4076782015-06-24 15:53:07 -06003883 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08003884 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06003885 ASSERT_VK_SUCCESS(err);
3886
3887 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08003888 VkDescriptorSetAllocateInfo alloc_info = {};
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003889 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08003890 alloc_info.setLayoutCount = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003891 alloc_info.descriptorPool = ds_pool;
3892 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08003893 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06003894 ASSERT_VK_SUCCESS(err);
3895
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003896 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3897 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3898 pipe_ms_state_ci.pNext = NULL;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08003899 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003900 pipe_ms_state_ci.sampleShadingEnable = 0;
3901 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003902 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003903
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003904 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3905 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3906 pipeline_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08003907 pipeline_layout_ci.setLayoutCount = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003908 pipeline_layout_ci.pSetLayouts = &ds_layout;
3909 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06003910
Chia-I Wu69f40122015-10-26 21:10:41 +08003911 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise4076782015-06-24 15:53:07 -06003912 ASSERT_VK_SUCCESS(err);
3913
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003914 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3915 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003916 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003917 VkPipelineObj pipe(m_device);
3918 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003919 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003920 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003921 pipe.SetViewport(m_viewports);
3922 pipe.SetScissor(m_scissors);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003923 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003924
3925 BeginCommandBuffer();
Chia-I Wu1f851912015-10-27 18:04:07 +08003926 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06003927 // Don't care about actual data, just need to get to draw to flag error
3928 static const float vbo_data[3] = {1.f, 0.f, 1.f};
3929 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
3930 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003931 Draw(1, 0, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06003932
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003933 if (!m_errorMonitor->DesiredMsgFound()) {
3934 FAIL() << "Did not receive Error 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
3935 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlise4076782015-06-24 15:53:07 -06003936 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003937
Chia-I Wu69f40122015-10-26 21:10:41 +08003938 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3939 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3940 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise4076782015-06-24 15:53:07 -06003941}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003942#endif // DRAW_STATE_TESTS
3943
Tobin Ehlis57e6a612015-05-26 16:11:58 -06003944#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06003945#if GTEST_IS_THREADSAFE
3946struct thread_data_struct {
Chia-I Wu1f851912015-10-27 18:04:07 +08003947 VkCommandBuffer commandBuffer;
Mike Stroyan09aae812015-05-12 16:00:45 -06003948 VkEvent event;
3949 bool bailout;
3950};
3951
3952extern "C" void *AddToCommandBuffer(void *arg)
3953{
3954 struct thread_data_struct *data = (struct thread_data_struct *) arg;
Mike Stroyan09aae812015-05-12 16:00:45 -06003955
3956 for (int i = 0; i<10000; i++) {
Chia-I Wucba6cea2015-10-31 00:31:16 +08003957 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyan09aae812015-05-12 16:00:45 -06003958 if (data->bailout) {
3959 break;
3960 }
3961 }
3962 return NULL;
3963}
3964
Chia-I Wu1f851912015-10-27 18:04:07 +08003965TEST_F(VkLayerTest, ThreadCommandBufferCollision)
Mike Stroyan09aae812015-05-12 16:00:45 -06003966{
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003967 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06003968
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06003969 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT, "THREADING ERROR");
3970
Mike Stroyan09aae812015-05-12 16:00:45 -06003971 ASSERT_NO_FATAL_FAILURE(InitState());
3972 ASSERT_NO_FATAL_FAILURE(InitViewport());
3973 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3974
Chia-I Wu1f851912015-10-27 18:04:07 +08003975 // Calls AllocateCommandBuffers
3976 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003977
3978 // Avoid creating RenderPass
Chia-I Wu1f851912015-10-27 18:04:07 +08003979 commandBuffer.BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06003980
3981 VkEventCreateInfo event_info;
3982 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06003983 VkResult err;
3984
3985 memset(&event_info, 0, sizeof(event_info));
3986 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3987
Chia-I Wu69f40122015-10-26 21:10:41 +08003988 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyan09aae812015-05-12 16:00:45 -06003989 ASSERT_VK_SUCCESS(err);
3990
Mike Stroyan09aae812015-05-12 16:00:45 -06003991 err = vkResetEvent(device(), event);
3992 ASSERT_VK_SUCCESS(err);
3993
3994 struct thread_data_struct data;
Chia-I Wu1f851912015-10-27 18:04:07 +08003995 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyan09aae812015-05-12 16:00:45 -06003996 data.event = event;
3997 data.bailout = false;
3998 m_errorMonitor->SetBailout(&data.bailout);
3999 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06004000 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06004001 // Add many entries to command buffer from this thread at the same time.
4002 AddToCommandBuffer(&data);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06004003
Mike Stroyan7016f4f2015-07-13 14:45:35 -06004004 test_platform_thread_join(thread, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08004005 commandBuffer.EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06004006
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004007 if (!m_errorMonitor->DesiredMsgFound()) {
4008 FAIL() << "Did not receive Error 'THREADING ERROR' from using one VkCommandBufferObj in two threads";
4009 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan09aae812015-05-12 16:00:45 -06004010 }
4011
Chia-I Wu69f40122015-10-26 21:10:41 +08004012 vkDestroyEvent(device(), event, NULL);
Mike Stroyan09aae812015-05-12 16:00:45 -06004013}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004014#endif // GTEST_IS_THREADSAFE
4015#endif // THREADING_TESTS
4016
Chris Forbes5af3bf22015-05-25 11:13:08 +12004017#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004018TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
4019{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004020 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4021 "Shader is not SPIR-V");
4022
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004023 ASSERT_NO_FATAL_FAILURE(InitState());
4024 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4025
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004026 VkShaderModule module;
4027 VkShaderModuleCreateInfo moduleCreateInfo;
4028 struct icd_spv_header spv;
4029
4030 spv.magic = ICD_SPV_MAGIC;
4031 spv.version = ICD_SPV_VERSION;
4032 spv.gen_magic = 0;
4033
4034 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4035 moduleCreateInfo.pNext = NULL;
Chia-I Wu036b1612015-10-26 19:22:06 +08004036 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004037 moduleCreateInfo.codeSize = 4;
4038 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004039 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004040
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004041 if (!m_errorMonitor->DesiredMsgFound()) {
4042 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4043 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004044 }
4045}
4046
4047TEST_F(VkLayerTest, InvalidSPIRVMagic)
4048{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004049 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4050 "Shader is not SPIR-V");
4051
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004052 ASSERT_NO_FATAL_FAILURE(InitState());
4053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4054
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004055 VkShaderModule module;
4056 VkShaderModuleCreateInfo moduleCreateInfo;
4057 struct icd_spv_header spv;
4058
4059 spv.magic = ~ICD_SPV_MAGIC;
4060 spv.version = ICD_SPV_VERSION;
4061 spv.gen_magic = 0;
4062
4063 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4064 moduleCreateInfo.pNext = NULL;
Chia-I Wu036b1612015-10-26 19:22:06 +08004065 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004066 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4067 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004068 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004069
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004070 if (!m_errorMonitor->DesiredMsgFound()) {
4071 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4072 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004073 }
4074}
4075
4076TEST_F(VkLayerTest, InvalidSPIRVVersion)
4077{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004078 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4079 "Shader is not SPIR-V");
4080
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004081 ASSERT_NO_FATAL_FAILURE(InitState());
4082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4083
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004084 VkShaderModule module;
4085 VkShaderModuleCreateInfo moduleCreateInfo;
4086 struct icd_spv_header spv;
4087
4088 spv.magic = ICD_SPV_MAGIC;
4089 spv.version = ~ICD_SPV_VERSION;
4090 spv.gen_magic = 0;
4091
4092 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
4093 moduleCreateInfo.pNext = NULL;
4094
Chia-I Wu036b1612015-10-26 19:22:06 +08004095 moduleCreateInfo.pCode = (const uint32_t *) &spv;
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004096 moduleCreateInfo.codeSize = sizeof(spv) + 10;
4097 moduleCreateInfo.flags = 0;
Chia-I Wu69f40122015-10-26 21:10:41 +08004098 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004099
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004100 if (!m_errorMonitor->DesiredMsgFound()) {
4101 FAIL() << "Did not recieive Error 'Shader is not SPIR-V'";
4102 m_errorMonitor->DumpFailureMsgs();
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06004103 }
4104}
4105
Chris Forbes5af3bf22015-05-25 11:13:08 +12004106TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
4107{
Tony Barbour192f02b2015-11-06 14:21:31 -07004108 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_PERF_WARN_BIT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004109 "not consumed by fragment shader");
4110
Chris Forbes5af3bf22015-05-25 11:13:08 +12004111 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004112 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12004113
4114 char const *vsSource =
4115 "#version 140\n"
4116 "#extension GL_ARB_separate_shader_objects: require\n"
4117 "#extension GL_ARB_shading_language_420pack: require\n"
4118 "\n"
4119 "layout(location=0) out float x;\n"
4120 "void main(){\n"
4121 " gl_Position = vec4(1);\n"
4122 " x = 0;\n"
4123 "}\n";
4124 char const *fsSource =
4125 "#version 140\n"
4126 "#extension GL_ARB_separate_shader_objects: require\n"
4127 "#extension GL_ARB_shading_language_420pack: require\n"
4128 "\n"
4129 "layout(location=0) out vec4 color;\n"
4130 "void main(){\n"
4131 " color = vec4(1);\n"
4132 "}\n";
4133
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004134 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4135 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5af3bf22015-05-25 11:13:08 +12004136
4137 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004138 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12004139 pipe.AddShader(&vs);
4140 pipe.AddShader(&fs);
4141
Chris Forbes5af3bf22015-05-25 11:13:08 +12004142 VkDescriptorSetObj descriptorSet(m_device);
4143 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004144 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12004145
Tony Barboured132432015-08-04 16:23:11 -06004146 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12004147
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004148 if (!m_errorMonitor->DesiredMsgFound()) {
4149 FAIL() << "Did not receive Warning 'not consumed by fragment shader'";
4150 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5af3bf22015-05-25 11:13:08 +12004151 }
4152}
Chris Forbes5af3bf22015-05-25 11:13:08 +12004153
Chris Forbes3c10b852015-05-25 11:13:13 +12004154TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
4155{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004156 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4157 "not written by vertex shader");
4158
Chris Forbes3c10b852015-05-25 11:13:13 +12004159 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12004161
4162 char const *vsSource =
4163 "#version 140\n"
4164 "#extension GL_ARB_separate_shader_objects: require\n"
4165 "#extension GL_ARB_shading_language_420pack: require\n"
4166 "\n"
4167 "void main(){\n"
4168 " gl_Position = vec4(1);\n"
4169 "}\n";
4170 char const *fsSource =
4171 "#version 140\n"
4172 "#extension GL_ARB_separate_shader_objects: require\n"
4173 "#extension GL_ARB_shading_language_420pack: require\n"
4174 "\n"
4175 "layout(location=0) in float x;\n"
4176 "layout(location=0) out vec4 color;\n"
4177 "void main(){\n"
4178 " color = vec4(x);\n"
4179 "}\n";
4180
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004181 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4182 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes3c10b852015-05-25 11:13:13 +12004183
4184 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004185 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12004186 pipe.AddShader(&vs);
4187 pipe.AddShader(&fs);
4188
Chris Forbes3c10b852015-05-25 11:13:13 +12004189 VkDescriptorSetObj descriptorSet(m_device);
4190 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004191 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12004192
Tony Barboured132432015-08-04 16:23:11 -06004193 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12004194
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004195 if (!m_errorMonitor->DesiredMsgFound()) {
4196 FAIL() << "Did not receive Error 'not written by vertex shader'";
4197 m_errorMonitor->DumpFailureMsgs();
Chris Forbes3c10b852015-05-25 11:13:13 +12004198 }
4199}
4200
Chris Forbescc281692015-05-25 11:13:17 +12004201TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
4202{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004203 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4204 "Type mismatch on location 0");
4205
Chris Forbescc281692015-05-25 11:13:17 +12004206 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004207 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12004208
4209 char const *vsSource =
4210 "#version 140\n"
4211 "#extension GL_ARB_separate_shader_objects: require\n"
4212 "#extension GL_ARB_shading_language_420pack: require\n"
4213 "\n"
4214 "layout(location=0) out int x;\n"
4215 "void main(){\n"
4216 " x = 0;\n"
4217 " gl_Position = vec4(1);\n"
4218 "}\n";
4219 char const *fsSource =
4220 "#version 140\n"
4221 "#extension GL_ARB_separate_shader_objects: require\n"
4222 "#extension GL_ARB_shading_language_420pack: require\n"
4223 "\n"
4224 "layout(location=0) in float x;\n" /* VS writes int */
4225 "layout(location=0) out vec4 color;\n"
4226 "void main(){\n"
4227 " color = vec4(x);\n"
4228 "}\n";
4229
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004230 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4231 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbescc281692015-05-25 11:13:17 +12004232
4233 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004234 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12004235 pipe.AddShader(&vs);
4236 pipe.AddShader(&fs);
4237
Chris Forbescc281692015-05-25 11:13:17 +12004238 VkDescriptorSetObj descriptorSet(m_device);
4239 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004240 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12004241
Tony Barboured132432015-08-04 16:23:11 -06004242 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12004243
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004244 if (!m_errorMonitor->DesiredMsgFound()) {
4245 FAIL() << "Did not receive Error 'Type mismatch on location 0'";
4246 m_errorMonitor->DumpFailureMsgs();
Chris Forbescc281692015-05-25 11:13:17 +12004247 }
4248}
4249
Chris Forbes8291c052015-05-25 11:13:28 +12004250TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
4251{
Tony Barbour192f02b2015-11-06 14:21:31 -07004252 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_PERF_WARN_BIT,
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004253 "location 0 not consumed by VS");
4254
Chris Forbes8291c052015-05-25 11:13:28 +12004255 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004256 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12004257
4258 VkVertexInputBindingDescription input_binding;
4259 memset(&input_binding, 0, sizeof(input_binding));
4260
4261 VkVertexInputAttributeDescription input_attrib;
4262 memset(&input_attrib, 0, sizeof(input_attrib));
4263 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4264
4265 char const *vsSource =
4266 "#version 140\n"
4267 "#extension GL_ARB_separate_shader_objects: require\n"
4268 "#extension GL_ARB_shading_language_420pack: require\n"
4269 "\n"
4270 "void main(){\n"
4271 " gl_Position = vec4(1);\n"
4272 "}\n";
4273 char const *fsSource =
4274 "#version 140\n"
4275 "#extension GL_ARB_separate_shader_objects: require\n"
4276 "#extension GL_ARB_shading_language_420pack: require\n"
4277 "\n"
4278 "layout(location=0) out vec4 color;\n"
4279 "void main(){\n"
4280 " color = vec4(1);\n"
4281 "}\n";
4282
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004283 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4284 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes8291c052015-05-25 11:13:28 +12004285
4286 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004287 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12004288 pipe.AddShader(&vs);
4289 pipe.AddShader(&fs);
4290
4291 pipe.AddVertexInputBindings(&input_binding, 1);
4292 pipe.AddVertexInputAttribs(&input_attrib, 1);
4293
Chris Forbes8291c052015-05-25 11:13:28 +12004294 VkDescriptorSetObj descriptorSet(m_device);
4295 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004296 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12004297
Tony Barboured132432015-08-04 16:23:11 -06004298 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12004299
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004300 if (!m_errorMonitor->DesiredMsgFound()) {
4301 FAIL() << "Did not receive Warning 'location 0 not consumed by VS'";
4302 m_errorMonitor->DumpFailureMsgs();
Chris Forbes8291c052015-05-25 11:13:28 +12004303 }
4304}
4305
Chris Forbes37367e62015-05-25 11:13:29 +12004306TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
4307{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004308 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4309 "VS consumes input at location 0 but not provided");
4310
Chris Forbes37367e62015-05-25 11:13:29 +12004311 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004312 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12004313
4314 char const *vsSource =
4315 "#version 140\n"
4316 "#extension GL_ARB_separate_shader_objects: require\n"
4317 "#extension GL_ARB_shading_language_420pack: require\n"
4318 "\n"
4319 "layout(location=0) in vec4 x;\n" /* not provided */
4320 "void main(){\n"
4321 " gl_Position = x;\n"
4322 "}\n";
4323 char const *fsSource =
4324 "#version 140\n"
4325 "#extension GL_ARB_separate_shader_objects: require\n"
4326 "#extension GL_ARB_shading_language_420pack: require\n"
4327 "\n"
4328 "layout(location=0) out vec4 color;\n"
4329 "void main(){\n"
4330 " color = vec4(1);\n"
4331 "}\n";
4332
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004333 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4334 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes37367e62015-05-25 11:13:29 +12004335
4336 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004337 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12004338 pipe.AddShader(&vs);
4339 pipe.AddShader(&fs);
4340
Chris Forbes37367e62015-05-25 11:13:29 +12004341 VkDescriptorSetObj descriptorSet(m_device);
4342 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004343 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12004344
Tony Barboured132432015-08-04 16:23:11 -06004345 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12004346
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004347 if (!m_errorMonitor->DesiredMsgFound()) {
4348 FAIL() << "Did not receive Error 'VS consumes input at location 0 but not provided'";
4349 m_errorMonitor->DumpFailureMsgs();
Chris Forbes37367e62015-05-25 11:13:29 +12004350 }
4351}
4352
Chris Forbesa4b02322015-05-25 11:13:31 +12004353TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
4354{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004355 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4356 "location 0 does not match VS input type");
4357
Chris Forbesa4b02322015-05-25 11:13:31 +12004358 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004359 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12004360
4361 VkVertexInputBindingDescription input_binding;
4362 memset(&input_binding, 0, sizeof(input_binding));
4363
4364 VkVertexInputAttributeDescription input_attrib;
4365 memset(&input_attrib, 0, sizeof(input_attrib));
4366 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4367
4368 char const *vsSource =
4369 "#version 140\n"
4370 "#extension GL_ARB_separate_shader_objects: require\n"
4371 "#extension GL_ARB_shading_language_420pack: require\n"
4372 "\n"
4373 "layout(location=0) in int x;\n" /* attrib provided float */
4374 "void main(){\n"
4375 " gl_Position = vec4(x);\n"
4376 "}\n";
4377 char const *fsSource =
4378 "#version 140\n"
4379 "#extension GL_ARB_separate_shader_objects: require\n"
4380 "#extension GL_ARB_shading_language_420pack: require\n"
4381 "\n"
4382 "layout(location=0) out vec4 color;\n"
4383 "void main(){\n"
4384 " color = vec4(1);\n"
4385 "}\n";
4386
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004387 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4388 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa4b02322015-05-25 11:13:31 +12004389
4390 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004391 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12004392 pipe.AddShader(&vs);
4393 pipe.AddShader(&fs);
4394
4395 pipe.AddVertexInputBindings(&input_binding, 1);
4396 pipe.AddVertexInputAttribs(&input_attrib, 1);
4397
Chris Forbesa4b02322015-05-25 11:13:31 +12004398 VkDescriptorSetObj descriptorSet(m_device);
4399 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004400 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12004401
Tony Barboured132432015-08-04 16:23:11 -06004402 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12004403
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004404 if (!m_errorMonitor->DesiredMsgFound()) {
4405 FAIL() << "Did not receive Error 'location 0 does not match VS input type'";
4406 m_errorMonitor->DumpFailureMsgs();
Chris Forbesa4b02322015-05-25 11:13:31 +12004407 }
4408}
4409
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004410TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
4411{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004412 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4413 "Duplicate vertex input binding descriptions for binding 0");
4414
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004415 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004416 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004417
4418 /* Two binding descriptions for binding 0 */
4419 VkVertexInputBindingDescription input_bindings[2];
4420 memset(input_bindings, 0, sizeof(input_bindings));
4421
4422 VkVertexInputAttributeDescription input_attrib;
4423 memset(&input_attrib, 0, sizeof(input_attrib));
4424 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4425
4426 char const *vsSource =
4427 "#version 140\n"
4428 "#extension GL_ARB_separate_shader_objects: require\n"
4429 "#extension GL_ARB_shading_language_420pack: require\n"
4430 "\n"
4431 "layout(location=0) in float x;\n" /* attrib provided float */
4432 "void main(){\n"
4433 " gl_Position = vec4(x);\n"
4434 "}\n";
4435 char const *fsSource =
4436 "#version 140\n"
4437 "#extension GL_ARB_separate_shader_objects: require\n"
4438 "#extension GL_ARB_shading_language_420pack: require\n"
4439 "\n"
4440 "layout(location=0) out vec4 color;\n"
4441 "void main(){\n"
4442 " color = vec4(1);\n"
4443 "}\n";
4444
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004445 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4446 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004447
4448 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004449 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004450 pipe.AddShader(&vs);
4451 pipe.AddShader(&fs);
4452
4453 pipe.AddVertexInputBindings(input_bindings, 2);
4454 pipe.AddVertexInputAttribs(&input_attrib, 1);
4455
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004456 VkDescriptorSetObj descriptorSet(m_device);
4457 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004458 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004459
Tony Barboured132432015-08-04 16:23:11 -06004460 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004461
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004462 if (!m_errorMonitor->DesiredMsgFound()) {
4463 FAIL() << "Did not receive Error 'Duplicate vertex input binding descriptions for binding 0'";
4464 m_errorMonitor->DumpFailureMsgs();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004465 }
4466}
Chris Forbes4c948702015-05-25 11:13:32 +12004467
Chris Forbesc12ef122015-05-25 11:13:40 +12004468/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
4469 * rejects it. */
4470
4471TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
4472{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004473 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4474 "Attachment 0 not written by FS");
4475
Chris Forbesc12ef122015-05-25 11:13:40 +12004476 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12004477
4478 char const *vsSource =
4479 "#version 140\n"
4480 "#extension GL_ARB_separate_shader_objects: require\n"
4481 "#extension GL_ARB_shading_language_420pack: require\n"
4482 "\n"
4483 "void main(){\n"
4484 " gl_Position = vec4(1);\n"
4485 "}\n";
4486 char const *fsSource =
4487 "#version 140\n"
4488 "#extension GL_ARB_separate_shader_objects: require\n"
4489 "#extension GL_ARB_shading_language_420pack: require\n"
4490 "\n"
4491 "void main(){\n"
4492 "}\n";
4493
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004494 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4495 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc12ef122015-05-25 11:13:40 +12004496
4497 VkPipelineObj pipe(m_device);
4498 pipe.AddShader(&vs);
4499 pipe.AddShader(&fs);
4500
Chia-I Wuc278df82015-07-07 11:50:03 +08004501 /* set up CB 0, not written */
4502 pipe.AddColorAttachment();
4503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12004504
Chris Forbesc12ef122015-05-25 11:13:40 +12004505 VkDescriptorSetObj descriptorSet(m_device);
4506 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004507 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12004508
Tony Barboured132432015-08-04 16:23:11 -06004509 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12004510
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004511 if (!m_errorMonitor->DesiredMsgFound()) {
4512 FAIL() << "Did not receive Error 'Attachment 0 not written by FS'";
4513 m_errorMonitor->DumpFailureMsgs();
Chris Forbesc12ef122015-05-25 11:13:40 +12004514 }
4515}
4516
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004517TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
4518{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004519 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_WARN_BIT,
4520 "FS writes to output location 1 with no matching attachment");
4521
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004522 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004523
4524 char const *vsSource =
4525 "#version 140\n"
4526 "#extension GL_ARB_separate_shader_objects: require\n"
4527 "#extension GL_ARB_shading_language_420pack: require\n"
4528 "\n"
4529 "void main(){\n"
4530 " gl_Position = vec4(1);\n"
4531 "}\n";
4532 char const *fsSource =
4533 "#version 140\n"
4534 "#extension GL_ARB_separate_shader_objects: require\n"
4535 "#extension GL_ARB_shading_language_420pack: require\n"
4536 "\n"
4537 "layout(location=0) out vec4 x;\n"
4538 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
4539 "void main(){\n"
4540 " x = vec4(1);\n"
4541 " y = vec4(1);\n"
4542 "}\n";
4543
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004544 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4545 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004546
4547 VkPipelineObj pipe(m_device);
4548 pipe.AddShader(&vs);
4549 pipe.AddShader(&fs);
4550
Chia-I Wuc278df82015-07-07 11:50:03 +08004551 /* set up CB 0, not written */
4552 pipe.AddColorAttachment();
4553 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004554 /* FS writes CB 1, but we don't configure it */
4555
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004556 VkDescriptorSetObj descriptorSet(m_device);
4557 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004558 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004559
Tony Barboured132432015-08-04 16:23:11 -06004560 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004561
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004562 if (!m_errorMonitor->DesiredMsgFound()) {
4563 FAIL() << "Did not receive Error 'FS writes to output location 1 with no matching attachment'";
4564 m_errorMonitor->DumpFailureMsgs();
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004565 }
4566}
4567
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004568TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
4569{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004570 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4571 "does not match FS output type");
4572
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004573 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004574
4575 char const *vsSource =
4576 "#version 140\n"
4577 "#extension GL_ARB_separate_shader_objects: require\n"
4578 "#extension GL_ARB_shading_language_420pack: require\n"
4579 "\n"
4580 "void main(){\n"
4581 " gl_Position = vec4(1);\n"
4582 "}\n";
4583 char const *fsSource =
4584 "#version 140\n"
4585 "#extension GL_ARB_separate_shader_objects: require\n"
4586 "#extension GL_ARB_shading_language_420pack: require\n"
4587 "\n"
4588 "layout(location=0) out ivec4 x;\n" /* not UNORM */
4589 "void main(){\n"
4590 " x = ivec4(1);\n"
4591 "}\n";
4592
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004593 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4594 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004595
4596 VkPipelineObj pipe(m_device);
4597 pipe.AddShader(&vs);
4598 pipe.AddShader(&fs);
4599
Chia-I Wuc278df82015-07-07 11:50:03 +08004600 /* set up CB 0; type is UNORM by default */
4601 pipe.AddColorAttachment();
4602 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004603
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004604 VkDescriptorSetObj descriptorSet(m_device);
4605 descriptorSet.AppendDummy();
Chia-I Wu1f851912015-10-27 18:04:07 +08004606 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004607
Tony Barboured132432015-08-04 16:23:11 -06004608 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004609
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004610 if (!m_errorMonitor->DesiredMsgFound()) {
4611 FAIL() << "Did not receive Error 'does not match FS output type'";
4612 m_errorMonitor->DumpFailureMsgs();
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004613 }
4614}
Chris Forbesc2050732015-06-05 14:43:36 +12004615
Chris Forbes76ce7882015-08-14 12:04:59 +12004616TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
4617{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004618 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4619 "not declared in pipeline layout");
4620
Chris Forbes76ce7882015-08-14 12:04:59 +12004621 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +12004622
4623 char const *vsSource =
4624 "#version 140\n"
4625 "#extension GL_ARB_separate_shader_objects: require\n"
4626 "#extension GL_ARB_shading_language_420pack: require\n"
4627 "\n"
4628 "void main(){\n"
4629 " gl_Position = vec4(1);\n"
4630 "}\n";
4631 char const *fsSource =
4632 "#version 140\n"
4633 "#extension GL_ARB_separate_shader_objects: require\n"
4634 "#extension GL_ARB_shading_language_420pack: require\n"
4635 "\n"
4636 "layout(location=0) out vec4 x;\n"
4637 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4638 "void main(){\n"
4639 " x = vec4(bar.y);\n"
4640 "}\n";
4641
Chris Forbes76ce7882015-08-14 12:04:59 +12004642
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004643 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4644 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes76ce7882015-08-14 12:04:59 +12004645
Chris Forbes76ce7882015-08-14 12:04:59 +12004646 VkPipelineObj pipe(m_device);
4647 pipe.AddShader(&vs);
4648 pipe.AddShader(&fs);
4649
4650 /* set up CB 0; type is UNORM by default */
4651 pipe.AddColorAttachment();
4652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4653
4654 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1f851912015-10-27 18:04:07 +08004655 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes76ce7882015-08-14 12:04:59 +12004656
4657 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4658
4659 /* should have generated an error -- pipeline layout does not
4660 * provide a uniform buffer in 0.0
4661 */
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004662 if (!m_errorMonitor->DesiredMsgFound()) {
4663 FAIL() << "Did not receive Error 'not declared in pipeline layout'";
4664 m_errorMonitor->DumpFailureMsgs();
Chris Forbes76ce7882015-08-14 12:04:59 +12004665 }
4666}
4667
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004668#endif // SHADER_CHECKER_TESTS
4669
4670#if DEVICE_LIMITS_TESTS
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004671TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
4672{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004673 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4674 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004675
4676 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004677
4678 // Create an image
4679 VkImage image;
4680
4681 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4682 const int32_t tex_width = 32;
4683 const int32_t tex_height = 32;
4684
4685 VkImageCreateInfo image_create_info = {};
4686 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4687 image_create_info.pNext = NULL;
4688 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4689 image_create_info.format = tex_format;
4690 image_create_info.extent.width = tex_width;
4691 image_create_info.extent.height = tex_height;
4692 image_create_info.extent.depth = 1;
4693 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004694 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004695 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004696 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4697 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4698 image_create_info.flags = 0;
4699
4700 // Introduce error by sending down a bogus width extent
4701 image_create_info.extent.width = 65536;
Chia-I Wu69f40122015-10-26 21:10:41 +08004702 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004703
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004704 if (!m_errorMonitor->DesiredMsgFound()) {
4705 FAIL() << "Did not receive Error 'CreateImage extents exceed allowable limits for format'";
4706 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004707 }
4708}
4709
4710TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
4711{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004712 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4713 "CreateImage resource size exceeds allowable maximum");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004714
4715 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004716
4717 // Create an image
4718 VkImage image;
4719
4720 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4721 const int32_t tex_width = 32;
4722 const int32_t tex_height = 32;
4723
4724 VkImageCreateInfo image_create_info = {};
4725 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4726 image_create_info.pNext = NULL;
4727 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4728 image_create_info.format = tex_format;
4729 image_create_info.extent.width = tex_width;
4730 image_create_info.extent.height = tex_height;
4731 image_create_info.extent.depth = 1;
4732 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004733 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004734 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004735 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4736 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4737 image_create_info.flags = 0;
4738
4739 // Introduce error by sending down individually allowable values that result in a surface size
4740 // exceeding the device maximum
4741 image_create_info.extent.width = 8192;
4742 image_create_info.extent.height = 8192;
4743 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004744 image_create_info.arrayLayers = 4;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004745 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004746 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
Chia-I Wu69f40122015-10-26 21:10:41 +08004747 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004748
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004749 if (!m_errorMonitor->DesiredMsgFound()) {
4750 FAIL() << "Did not receive Error 'CreateImage resource size exceeds allowable maximum'";
4751 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004752 }
4753}
4754
Mike Stroyan43909d82015-09-25 13:39:21 -06004755TEST_F(VkLayerTest, UpdateBufferAlignment)
4756{
Mike Stroyan43909d82015-09-25 13:39:21 -06004757 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
4758
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004759 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4760 "dstOffset, is not a multiple of 4");
4761
Mike Stroyan43909d82015-09-25 13:39:21 -06004762 ASSERT_NO_FATAL_FAILURE(InitState());
4763
4764 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4765 vk_testing::Buffer buffer;
4766 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4767
4768 BeginCommandBuffer();
4769 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08004770 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004771 if (!m_errorMonitor->DesiredMsgFound()) {
4772 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
4773 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06004774 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004775
Mike Stroyan43909d82015-09-25 13:39:21 -06004776 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004777 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4778 "dataSize, is not a multiple of 4");
4779
Chia-I Wu1f851912015-10-27 18:04:07 +08004780 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004781
4782 if (!m_errorMonitor->DesiredMsgFound()) {
4783 FAIL() << "Did not receive Error 'vkCommandUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
4784 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06004785 }
4786 EndCommandBuffer();
4787}
4788
4789TEST_F(VkLayerTest, FillBufferAlignment)
4790{
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004791 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4792 "dstOffset, is not a multiple of 4");
Mike Stroyan43909d82015-09-25 13:39:21 -06004793
4794 ASSERT_NO_FATAL_FAILURE(InitState());
4795
4796 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4797 vk_testing::Buffer buffer;
4798 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4799
4800 BeginCommandBuffer();
4801 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu1f851912015-10-27 18:04:07 +08004802 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004803 if (!m_errorMonitor->DesiredMsgFound()) {
4804 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4'";
4805 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06004806 }
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004807
Mike Stroyan43909d82015-09-25 13:39:21 -06004808 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004809 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4810 "size, is not a multiple of 4");
4811
Chia-I Wu1f851912015-10-27 18:04:07 +08004812 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004813
4814 if (!m_errorMonitor->DesiredMsgFound()) {
4815 FAIL() << "Did not receive Error 'vkCommandFillBuffer parameter, VkDeviceSize size, is not a multiple of 4'";
4816 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06004817 }
4818 EndCommandBuffer();
4819}
4820
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004821#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004822
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004823#if IMAGE_TESTS
4824TEST_F(VkLayerTest, InvalidImageView)
4825{
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004826 VkResult err;
4827
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004828 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4829 "vkCreateImageView called with baseMipLevel 10 ");
4830
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004831 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004832
Mike Stroyan43909d82015-09-25 13:39:21 -06004833 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004834 VkImage image;
4835
4836 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4837 const int32_t tex_width = 32;
4838 const int32_t tex_height = 32;
4839
4840 VkImageCreateInfo image_create_info = {};
4841 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4842 image_create_info.pNext = NULL;
4843 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4844 image_create_info.format = tex_format;
4845 image_create_info.extent.width = tex_width;
4846 image_create_info.extent.height = tex_height;
4847 image_create_info.extent.depth = 1;
4848 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004849 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004850 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004851 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4852 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4853 image_create_info.flags = 0;
4854
Chia-I Wu69f40122015-10-26 21:10:41 +08004855 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004856 ASSERT_VK_SUCCESS(err);
4857
4858 VkImageViewCreateInfo image_view_create_info = {};
4859 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4860 image_view_create_info.image = image;
4861 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4862 image_view_create_info.format = tex_format;
Chia-I Wu1f851912015-10-27 18:04:07 +08004863 image_view_create_info.subresourceRange.layerCount = 1;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004864 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Chia-I Wu1f851912015-10-27 18:04:07 +08004865 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004866 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004867
4868 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08004869 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004870
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004871 if (!m_errorMonitor->DesiredMsgFound()) {
4872 FAIL() << "Did not receive Error 'vkCreateImageView called with baseMipLevel 10...'";
4873 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004874 }
4875}
Mike Stroyan43909d82015-09-25 13:39:21 -06004876
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004877TEST_F(VkLayerTest, InvalidImageViewAspect)
4878{
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004879 VkResult err;
4880
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004881 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4882 "vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set");
4883
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004884 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004885
4886 // Create an image and try to create a view with an invalid aspectMask
4887 VkImage image;
4888
4889 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4890 const int32_t tex_width = 32;
4891 const int32_t tex_height = 32;
4892
4893 VkImageCreateInfo image_create_info = {};
4894 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4895 image_create_info.pNext = NULL;
4896 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4897 image_create_info.format = tex_format;
4898 image_create_info.extent.width = tex_width;
4899 image_create_info.extent.height = tex_height;
4900 image_create_info.extent.depth = 1;
4901 image_create_info.mipLevels = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004902 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004903 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4904 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4905 image_create_info.flags = 0;
4906
Chia-I Wu69f40122015-10-26 21:10:41 +08004907 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004908 ASSERT_VK_SUCCESS(err);
4909
4910 VkImageViewCreateInfo image_view_create_info = {};
4911 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4912 image_view_create_info.image = image;
4913 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4914 image_view_create_info.format = tex_format;
4915 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08004916 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004917 // Cause an error by setting an invalid image aspect
4918 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
4919
4920 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08004921 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004922
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004923 if (!m_errorMonitor->DesiredMsgFound()) {
4924 FAIL() << "Did not receive Error 'VkCreateImageView: Color image formats must have ...'";
4925 m_errorMonitor->DumpFailureMsgs();
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004926 }
4927}
4928
Mike Stroyan43909d82015-09-25 13:39:21 -06004929TEST_F(VkLayerTest, CopyImageTypeMismatch)
4930{
Mike Stroyan43909d82015-09-25 13:39:21 -06004931 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004932 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06004933
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06004934 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
4935 "vkCmdCopyImage called with unmatched source and dest image types");
4936
Mike Stroyan43909d82015-09-25 13:39:21 -06004937 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06004938
4939 // Create two images of different types and try to copy between them
4940 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08004941 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06004942 VkDeviceMemory srcMem;
4943 VkDeviceMemory destMem;
4944 VkMemoryRequirements memReqs;
4945
4946 VkImageCreateInfo image_create_info = {};
4947 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4948 image_create_info.pNext = NULL;
4949 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4950 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4951 image_create_info.extent.width = 32;
4952 image_create_info.extent.height = 32;
4953 image_create_info.extent.depth = 1;
4954 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004955 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08004956 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004957 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08004958 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004959 image_create_info.flags = 0;
4960
Chia-I Wu69f40122015-10-26 21:10:41 +08004961 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06004962 ASSERT_VK_SUCCESS(err);
4963
4964 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08004965 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004966
Chia-I Wu1f851912015-10-27 18:04:07 +08004967 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06004968 ASSERT_VK_SUCCESS(err);
4969
4970 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08004971 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06004972 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4973 memAlloc.pNext = NULL;
4974 memAlloc.allocationSize = 0;
4975 memAlloc.memoryTypeIndex = 0;
4976
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004977 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004978 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004979 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4980 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08004981 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06004982 ASSERT_VK_SUCCESS(err);
4983
Chia-I Wu1f851912015-10-27 18:04:07 +08004984 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004985 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004986 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06004987 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08004988 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06004989 ASSERT_VK_SUCCESS(err);
4990
4991 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4992 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08004993 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06004994 ASSERT_VK_SUCCESS(err);
4995
4996 BeginCommandBuffer();
4997 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08004998 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004999 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005000 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005001 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005002 copyRegion.srcOffset.x = 0;
5003 copyRegion.srcOffset.y = 0;
5004 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005005 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005006 copyRegion.dstSubresource.mipLevel = 0;
5007 copyRegion.dstSubresource.baseArrayLayer = 0;
5008 copyRegion.dstSubresource.layerCount = 0;
5009 copyRegion.dstOffset.x = 0;
5010 copyRegion.dstOffset.y = 0;
5011 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005012 copyRegion.extent.width = 1;
5013 copyRegion.extent.height = 1;
5014 copyRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005015 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005016 EndCommandBuffer();
5017
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005018 if (!m_errorMonitor->DesiredMsgFound()) {
5019 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5020 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005021 }
5022
Chia-I Wu69f40122015-10-26 21:10:41 +08005023 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005024 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005025 vkFreeMemory(m_device->device(), srcMem, NULL);
5026 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005027}
5028
5029TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
5030{
5031 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
5032}
5033
5034TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
5035{
Mike Stroyan43909d82015-09-25 13:39:21 -06005036 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005037 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005038
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005039 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5040 "vkCmdCopyImage called with unmatched source and dest image types");
5041
Mike Stroyan43909d82015-09-25 13:39:21 -06005042 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005043
5044 // Create two images of different types and try to copy between them
5045 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005046 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005047 VkDeviceMemory srcMem;
5048 VkDeviceMemory destMem;
5049 VkMemoryRequirements memReqs;
5050
5051 VkImageCreateInfo image_create_info = {};
5052 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5053 image_create_info.pNext = NULL;
5054 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5055 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5056 image_create_info.extent.width = 32;
5057 image_create_info.extent.height = 32;
5058 image_create_info.extent.depth = 1;
5059 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005060 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005061 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005062 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005063 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005064 image_create_info.flags = 0;
5065
Chia-I Wu69f40122015-10-26 21:10:41 +08005066 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005067 ASSERT_VK_SUCCESS(err);
5068
5069 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005070 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005071
Chia-I Wu1f851912015-10-27 18:04:07 +08005072 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005073 ASSERT_VK_SUCCESS(err);
5074
5075 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005076 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06005077 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5078 memAlloc.pNext = NULL;
5079 memAlloc.allocationSize = 0;
5080 memAlloc.memoryTypeIndex = 0;
5081
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005082 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005083 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005084 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5085 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005086 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005087 ASSERT_VK_SUCCESS(err);
5088
Chia-I Wu1f851912015-10-27 18:04:07 +08005089 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005090 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005091 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5092 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005093 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005094 ASSERT_VK_SUCCESS(err);
5095
5096 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5097 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005098 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005099 ASSERT_VK_SUCCESS(err);
5100
5101 BeginCommandBuffer();
5102 VkImageCopy copyRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005103 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005104 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005105 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005106 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005107 copyRegion.srcOffset.x = 0;
5108 copyRegion.srcOffset.y = 0;
5109 copyRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005110 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005111 copyRegion.dstSubresource.mipLevel = 0;
5112 copyRegion.dstSubresource.baseArrayLayer = 0;
5113 copyRegion.dstSubresource.layerCount = 0;
5114 copyRegion.dstOffset.x = 0;
5115 copyRegion.dstOffset.y = 0;
5116 copyRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005117 copyRegion.extent.width = 1;
5118 copyRegion.extent.height = 1;
5119 copyRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005120 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005121 EndCommandBuffer();
5122
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005123 if (!m_errorMonitor->DesiredMsgFound()) {
5124 FAIL() << "Did not receive Error 'vkCmdCopyImage called with unmatched source and dest image types'";
5125 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005126 }
5127
Chia-I Wu69f40122015-10-26 21:10:41 +08005128 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005129 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005130 vkFreeMemory(m_device->device(), srcMem, NULL);
5131 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005132}
5133
5134TEST_F(VkLayerTest, ResolveImageLowSampleCount)
5135{
Mike Stroyan43909d82015-09-25 13:39:21 -06005136 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005137 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005138
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005139 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5140 "vkCmdResolveImage called with source sample count less than 2.");
5141
Mike Stroyan43909d82015-09-25 13:39:21 -06005142 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005143
5144 // Create two images of sample count 1 and try to Resolve between them
5145 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005146 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005147 VkDeviceMemory srcMem;
5148 VkDeviceMemory destMem;
5149 VkMemoryRequirements memReqs;
5150
5151 VkImageCreateInfo image_create_info = {};
5152 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5153 image_create_info.pNext = NULL;
5154 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5155 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5156 image_create_info.extent.width = 32;
5157 image_create_info.extent.height = 1;
5158 image_create_info.extent.depth = 1;
5159 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005160 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005161 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005162 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Chia-I Wu1f851912015-10-27 18:04:07 +08005163 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005164 image_create_info.flags = 0;
5165
Chia-I Wu69f40122015-10-26 21:10:41 +08005166 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005167 ASSERT_VK_SUCCESS(err);
5168
5169 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Chia-I Wu1f851912015-10-27 18:04:07 +08005170 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005171
Chia-I Wu1f851912015-10-27 18:04:07 +08005172 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005173 ASSERT_VK_SUCCESS(err);
5174
5175 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005176 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06005177 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5178 memAlloc.pNext = NULL;
5179 memAlloc.allocationSize = 0;
5180 memAlloc.memoryTypeIndex = 0;
5181
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005182 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005183 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005184 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5185 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005186 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005187 ASSERT_VK_SUCCESS(err);
5188
Chia-I Wu1f851912015-10-27 18:04:07 +08005189 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005190 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005191 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5192 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005193 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005194 ASSERT_VK_SUCCESS(err);
5195
5196 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5197 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005198 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005199 ASSERT_VK_SUCCESS(err);
5200
5201 BeginCommandBuffer();
5202 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5203 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5204 //VK_IMAGE_LAYOUT_GENERAL = 1,
5205 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005206 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005207 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005208 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005209 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005210 resolveRegion.srcOffset.x = 0;
5211 resolveRegion.srcOffset.y = 0;
5212 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005213 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005214 resolveRegion.dstSubresource.mipLevel = 0;
5215 resolveRegion.dstSubresource.baseArrayLayer = 0;
5216 resolveRegion.dstSubresource.layerCount = 0;
5217 resolveRegion.dstOffset.x = 0;
5218 resolveRegion.dstOffset.y = 0;
5219 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005220 resolveRegion.extent.width = 1;
5221 resolveRegion.extent.height = 1;
5222 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005223 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005224 EndCommandBuffer();
5225
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005226 if (!m_errorMonitor->DesiredMsgFound()) {
5227 FAIL() << "Did not receive Error 'vkCmdResolveImage called with source sample count less than 2.'";
5228 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005229 }
5230
Chia-I Wu69f40122015-10-26 21:10:41 +08005231 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005232 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005233 vkFreeMemory(m_device->device(), srcMem, NULL);
5234 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005235}
5236
5237TEST_F(VkLayerTest, ResolveImageHighSampleCount)
5238{
Mike Stroyan43909d82015-09-25 13:39:21 -06005239 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005240 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005241
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005242 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5243 "vkCmdResolveImage called with dest sample count greater than 1.");
5244
Mike Stroyan43909d82015-09-25 13:39:21 -06005245 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005246
5247 // Create two images of sample count 2 and try to Resolve between them
5248 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005249 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005250 VkDeviceMemory srcMem;
5251 VkDeviceMemory destMem;
5252 VkMemoryRequirements memReqs;
5253
5254 VkImageCreateInfo image_create_info = {};
5255 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5256 image_create_info.pNext = NULL;
5257 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5258 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5259 image_create_info.extent.width = 32;
5260 image_create_info.extent.height = 1;
5261 image_create_info.extent.depth = 1;
5262 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005263 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005264 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005265 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005266 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005267 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005268 image_create_info.flags = 0;
5269
Chia-I Wu69f40122015-10-26 21:10:41 +08005270 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005271 ASSERT_VK_SUCCESS(err);
5272
5273 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005274 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005275 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005276
Chia-I Wu1f851912015-10-27 18:04:07 +08005277 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005278 ASSERT_VK_SUCCESS(err);
5279
5280 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005281 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06005282 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5283 memAlloc.pNext = NULL;
5284 memAlloc.allocationSize = 0;
5285 memAlloc.memoryTypeIndex = 0;
5286
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005287 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005288 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005289 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5290 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005291 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005292 ASSERT_VK_SUCCESS(err);
5293
Chia-I Wu1f851912015-10-27 18:04:07 +08005294 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005295 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005296 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5297 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005298 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005299 ASSERT_VK_SUCCESS(err);
5300
5301 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5302 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005303 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005304 ASSERT_VK_SUCCESS(err);
5305
5306 BeginCommandBuffer();
5307 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5308 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5309 //VK_IMAGE_LAYOUT_GENERAL = 1,
5310 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005311 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005312 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005313 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005314 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005315 resolveRegion.srcOffset.x = 0;
5316 resolveRegion.srcOffset.y = 0;
5317 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005318 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005319 resolveRegion.dstSubresource.mipLevel = 0;
5320 resolveRegion.dstSubresource.baseArrayLayer = 0;
5321 resolveRegion.dstSubresource.layerCount = 0;
5322 resolveRegion.dstOffset.x = 0;
5323 resolveRegion.dstOffset.y = 0;
5324 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005325 resolveRegion.extent.width = 1;
5326 resolveRegion.extent.height = 1;
5327 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005328 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005329 EndCommandBuffer();
5330
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005331 if (!m_errorMonitor->DesiredMsgFound()) {
5332 FAIL() << "Did not receive Error 'vkCmdResolveImage called with dest sample count greater than 1.'";
5333 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005334 }
5335
Chia-I Wu69f40122015-10-26 21:10:41 +08005336 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005337 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005338 vkFreeMemory(m_device->device(), srcMem, NULL);
5339 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005340}
5341
5342TEST_F(VkLayerTest, ResolveImageFormatMismatch)
5343{
Mike Stroyan43909d82015-09-25 13:39:21 -06005344 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005345 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005346
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005347 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5348 "vkCmdResolveImage called with unmatched source and dest formats.");
5349
Mike Stroyan43909d82015-09-25 13:39:21 -06005350 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005351
5352 // Create two images of different types and try to copy between them
5353 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005354 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005355 VkDeviceMemory srcMem;
5356 VkDeviceMemory destMem;
5357 VkMemoryRequirements memReqs;
5358
5359 VkImageCreateInfo image_create_info = {};
5360 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5361 image_create_info.pNext = NULL;
5362 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5363 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5364 image_create_info.extent.width = 32;
5365 image_create_info.extent.height = 1;
5366 image_create_info.extent.depth = 1;
5367 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005368 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005369 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005370 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005371 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005372 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005373 image_create_info.flags = 0;
5374
Chia-I Wu69f40122015-10-26 21:10:41 +08005375 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005376 ASSERT_VK_SUCCESS(err);
5377
Cody Northropb3bf94f2015-10-27 13:50:04 -06005378 // Set format to something other than source image
5379 image_create_info.format = VK_FORMAT_R32_SFLOAT;
5380 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005381 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005382 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005383
Chia-I Wu1f851912015-10-27 18:04:07 +08005384 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005385 ASSERT_VK_SUCCESS(err);
5386
5387 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005388 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06005389 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5390 memAlloc.pNext = NULL;
5391 memAlloc.allocationSize = 0;
5392 memAlloc.memoryTypeIndex = 0;
5393
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005394 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005395 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005396 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5397 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005398 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005399 ASSERT_VK_SUCCESS(err);
5400
Chia-I Wu1f851912015-10-27 18:04:07 +08005401 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005402 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005403 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5404 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005405 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005406 ASSERT_VK_SUCCESS(err);
5407
5408 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5409 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005410 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005411 ASSERT_VK_SUCCESS(err);
5412
5413 BeginCommandBuffer();
5414 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5415 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5416 //VK_IMAGE_LAYOUT_GENERAL = 1,
5417 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005418 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005419 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005420 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005421 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005422 resolveRegion.srcOffset.x = 0;
5423 resolveRegion.srcOffset.y = 0;
5424 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005425 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005426 resolveRegion.dstSubresource.mipLevel = 0;
5427 resolveRegion.dstSubresource.baseArrayLayer = 0;
5428 resolveRegion.dstSubresource.layerCount = 0;
5429 resolveRegion.dstOffset.x = 0;
5430 resolveRegion.dstOffset.y = 0;
5431 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005432 resolveRegion.extent.width = 1;
5433 resolveRegion.extent.height = 1;
5434 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005435 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005436 EndCommandBuffer();
5437
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005438 if (!m_errorMonitor->DesiredMsgFound()) {
5439 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest formats.'";
5440 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005441 }
5442
Chia-I Wu69f40122015-10-26 21:10:41 +08005443 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005444 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005445 vkFreeMemory(m_device->device(), srcMem, NULL);
5446 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005447}
5448
5449TEST_F(VkLayerTest, ResolveImageTypeMismatch)
5450{
Mike Stroyan43909d82015-09-25 13:39:21 -06005451 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005452 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005453
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005454 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5455 "vkCmdResolveImage called with unmatched source and dest image types.");
5456
Mike Stroyan43909d82015-09-25 13:39:21 -06005457 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan43909d82015-09-25 13:39:21 -06005458
5459 // Create two images of different types and try to copy between them
5460 VkImage srcImage;
Chia-I Wu1f851912015-10-27 18:04:07 +08005461 VkImage dstImage;
Mike Stroyan43909d82015-09-25 13:39:21 -06005462 VkDeviceMemory srcMem;
5463 VkDeviceMemory destMem;
5464 VkMemoryRequirements memReqs;
5465
5466 VkImageCreateInfo image_create_info = {};
5467 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5468 image_create_info.pNext = NULL;
5469 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5470 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5471 image_create_info.extent.width = 32;
5472 image_create_info.extent.height = 1;
5473 image_create_info.extent.depth = 1;
5474 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005475 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005476 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005477 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005478 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005479 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005480 image_create_info.flags = 0;
5481
Chia-I Wu69f40122015-10-26 21:10:41 +08005482 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005483 ASSERT_VK_SUCCESS(err);
5484
5485 image_create_info.imageType = VK_IMAGE_TYPE_1D;
Cody Northropb3bf94f2015-10-27 13:50:04 -06005486 // Note: Some implementations expect color attachment usage for any multisample surface
Chia-I Wu1f851912015-10-27 18:04:07 +08005487 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005488 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005489
Chia-I Wu1f851912015-10-27 18:04:07 +08005490 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyan43909d82015-09-25 13:39:21 -06005491 ASSERT_VK_SUCCESS(err);
5492
5493 // Allocate memory
Chia-I Wu1f851912015-10-27 18:04:07 +08005494 VkMemoryAllocateInfo memAlloc = {};
Mike Stroyan43909d82015-09-25 13:39:21 -06005495 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5496 memAlloc.pNext = NULL;
5497 memAlloc.allocationSize = 0;
5498 memAlloc.memoryTypeIndex = 0;
5499
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005500 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005501 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005502 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5503 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005504 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005505 ASSERT_VK_SUCCESS(err);
5506
Chia-I Wu1f851912015-10-27 18:04:07 +08005507 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005508 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005509 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5510 ASSERT_TRUE(pass);
Chia-I Wu1f851912015-10-27 18:04:07 +08005511 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyan43909d82015-09-25 13:39:21 -06005512 ASSERT_VK_SUCCESS(err);
5513
5514 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5515 ASSERT_VK_SUCCESS(err);
Chia-I Wu1f851912015-10-27 18:04:07 +08005516 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06005517 ASSERT_VK_SUCCESS(err);
5518
5519 BeginCommandBuffer();
5520 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5521 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5522 //VK_IMAGE_LAYOUT_GENERAL = 1,
5523 VkImageResolve resolveRegion;
Chia-I Wu4291d882015-10-27 19:00:15 +08005524 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005525 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005526 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005527 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005528 resolveRegion.srcOffset.x = 0;
5529 resolveRegion.srcOffset.y = 0;
5530 resolveRegion.srcOffset.z = 0;
Chia-I Wu4291d882015-10-27 19:00:15 +08005531 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu1f851912015-10-27 18:04:07 +08005532 resolveRegion.dstSubresource.mipLevel = 0;
5533 resolveRegion.dstSubresource.baseArrayLayer = 0;
5534 resolveRegion.dstSubresource.layerCount = 0;
5535 resolveRegion.dstOffset.x = 0;
5536 resolveRegion.dstOffset.y = 0;
5537 resolveRegion.dstOffset.z = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005538 resolveRegion.extent.width = 1;
5539 resolveRegion.extent.height = 1;
5540 resolveRegion.extent.depth = 1;
Chia-I Wu1f851912015-10-27 18:04:07 +08005541 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyan43909d82015-09-25 13:39:21 -06005542 EndCommandBuffer();
5543
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005544 if (!m_errorMonitor->DesiredMsgFound()) {
5545 FAIL() << "Did not receive Error 'vkCmdResolveImage called with unmatched source and dest image types.'";
5546 m_errorMonitor->DumpFailureMsgs();
Mike Stroyan43909d82015-09-25 13:39:21 -06005547 }
5548
Chia-I Wu69f40122015-10-26 21:10:41 +08005549 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu1f851912015-10-27 18:04:07 +08005550 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005551 vkFreeMemory(m_device->device(), srcMem, NULL);
5552 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyan43909d82015-09-25 13:39:21 -06005553}
Tobin Ehlisb46be812015-10-23 16:00:08 -06005554
5555TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError)
5556{
5557 // Create a single Image descriptor and cause it to first hit an error due
5558 // to using a DS format, then cause it to hit error due to COLOR_BIT not set in aspect
5559 // The image format check comes 2nd in validation so we trigger it first,
5560 // then when we cause aspect fail next, bad format check will be preempted
Tobin Ehlisb46be812015-10-23 16:00:08 -06005561 VkResult err;
5562
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005563 m_errorMonitor->SetDesiredFailureMsg(VK_DBG_REPORT_ERROR_BIT,
5564 "Combination depth/stencil image formats can have only the ");
5565
Tobin Ehlisb46be812015-10-23 16:00:08 -06005566 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005567
Chia-I Wuc51b1212015-10-27 19:25:11 +08005568 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06005569 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu763a7492015-10-26 20:48:51 +08005570 ds_type_count.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005571
5572 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5573 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5574 ds_pool_ci.pNext = NULL;
5575 ds_pool_ci.maxSets = 1;
Chia-I Wuc51b1212015-10-27 19:25:11 +08005576 ds_pool_ci.poolSizeCount = 1;
5577 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005578
5579 VkDescriptorPool ds_pool;
Chia-I Wu69f40122015-10-26 21:10:41 +08005580 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005581 ASSERT_VK_SUCCESS(err);
5582
5583 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wub5689ee2015-10-31 00:31:16 +08005584 dsl_binding.binding = 0;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005585 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Chia-I Wu045654f2015-11-06 06:42:02 +08005586 dsl_binding.descriptorCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005587 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5588 dsl_binding.pImmutableSamplers = NULL;
5589
5590 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5591 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5592 ds_layout_ci.pNext = NULL;
Chia-I Wu763a7492015-10-26 20:48:51 +08005593 ds_layout_ci.bindingCount = 1;
Chia-I Wuf03cbf72015-10-31 00:31:16 +08005594 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005595 VkDescriptorSetLayout ds_layout;
Chia-I Wu69f40122015-10-26 21:10:41 +08005596 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005597 ASSERT_VK_SUCCESS(err);
5598
5599 VkDescriptorSet descriptorSet;
Chia-I Wu1f851912015-10-27 18:04:07 +08005600 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlisb46be812015-10-23 16:00:08 -06005601 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
Chia-I Wu763a7492015-10-26 20:48:51 +08005602 alloc_info.setLayoutCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005603 alloc_info.descriptorPool = ds_pool;
5604 alloc_info.pSetLayouts = &ds_layout;
Chia-I Wu1f851912015-10-27 18:04:07 +08005605 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005606 ASSERT_VK_SUCCESS(err);
5607
5608 VkImage image_bad;
5609 VkImage image_good;
5610 // One bad format and one good format for Color attachment
5611 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
5612 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
5613 const int32_t tex_width = 32;
5614 const int32_t tex_height = 32;
5615
5616 VkImageCreateInfo image_create_info = {};
5617 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5618 image_create_info.pNext = NULL;
5619 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5620 image_create_info.format = tex_format_bad;
5621 image_create_info.extent.width = tex_width;
5622 image_create_info.extent.height = tex_height;
5623 image_create_info.extent.depth = 1;
5624 image_create_info.mipLevels = 1;
5625 image_create_info.arrayLayers = 1;
Chia-I Wu3138d6a2015-10-31 00:31:16 +08005626 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005627 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5628 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
5629 image_create_info.flags = 0;
5630
Chia-I Wu69f40122015-10-26 21:10:41 +08005631 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005632 ASSERT_VK_SUCCESS(err);
5633 image_create_info.format = tex_format_good;
5634 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Chia-I Wu69f40122015-10-26 21:10:41 +08005635 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005636 ASSERT_VK_SUCCESS(err);
5637
5638 VkImageViewCreateInfo image_view_create_info = {};
5639 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5640 image_view_create_info.image = image_bad;
5641 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5642 image_view_create_info.format = tex_format_bad;
5643 image_view_create_info.subresourceRange.baseArrayLayer = 0;
5644 image_view_create_info.subresourceRange.baseMipLevel = 0;
Chia-I Wu1f851912015-10-27 18:04:07 +08005645 image_view_create_info.subresourceRange.layerCount = 1;
5646 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlisb46be812015-10-23 16:00:08 -06005647 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5648
5649 VkImageView view;
Chia-I Wu69f40122015-10-26 21:10:41 +08005650 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskic4d306c2015-10-29 09:02:49 -06005651
5652 if (!m_errorMonitor->DesiredMsgFound()) {
5653 FAIL() << "Did not receive Error 'Combination depth-stencil image formats can have only the....'";
5654 m_errorMonitor->DumpFailureMsgs();
Tobin Ehlisb46be812015-10-23 16:00:08 -06005655 }
5656
Chia-I Wu69f40122015-10-26 21:10:41 +08005657 vkDestroyImage(m_device->device(), image_bad, NULL);
5658 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wu69f40122015-10-26 21:10:41 +08005659 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5660 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisb46be812015-10-23 16:00:08 -06005661}
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005662#endif // IMAGE_TESTS
5663
Tony Barbour30486ea2015-04-07 13:44:53 -06005664int main(int argc, char **argv) {
5665 int result;
5666
5667 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06005668 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06005669
5670 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
5671
5672 result = RUN_ALL_TESTS();
5673
Tony Barbour01999182015-04-09 12:58:51 -06005674 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06005675 return result;
5676}