blob: 1d943154c0abe908129cc23e05b7355c16634ef9 [file] [log] [blame]
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001#include <vulkan.h>
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002#include "vk_debug_report_lunarg.h"
Tony Barbour30486ea2015-04-07 13:44:53 -06003#include "gtest-1.7.0/include/gtest/gtest.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06004#include "vkrenderframework.h"
Mark Lobodzinskia910dc82015-05-14 14:30:48 -05005#include "layers_config.h"
Tony Barbour30486ea2015-04-07 13:44:53 -06006
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05007#define GLM_FORCE_RADIANS
8#include "glm/glm.hpp"
9#include <glm/gtc/matrix_transform.hpp>
10
Tobin Ehlis57e6a612015-05-26 16:11:58 -060011#define MEM_TRACKER_TESTS 1
12#define OBJ_TRACKER_TESTS 1
13#define DRAW_STATE_TESTS 1
14#define THREADING_TESTS 1
Chris Forbes5af3bf22015-05-25 11:13:08 +120015#define SHADER_CHECKER_TESTS 1
Tobin Ehlis57e6a612015-05-26 16:11:58 -060016
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050017//--------------------------------------------------------------------------------------
18// Mesh and VertexFormat Data
19//--------------------------------------------------------------------------------------
20struct Vertex
21{
22 float posX, posY, posZ, posW; // Position data
23 float r, g, b, a; // Color
24};
25
26#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
27
28typedef enum _BsoFailSelect {
29 BsoFailNone = 0x00000000,
30 BsoFailRaster = 0x00000001,
31 BsoFailViewport = 0x00000002,
32 BsoFailColorBlend = 0x00000004,
33 BsoFailDepthStencil = 0x00000008,
34} BsoFailSelect;
35
36struct vktriangle_vs_uniform {
37 // Must start with MVP
38 float mvp[4][4];
39 float position[3][4];
40 float color[3][4];
41};
42
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050043static const char bindStateVertShaderText[] =
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050044 "#version 130\n"
45 "vec2 vertices[3];\n"
46 "void main() {\n"
47 " vertices[0] = vec2(-1.0, -1.0);\n"
48 " vertices[1] = vec2( 1.0, -1.0);\n"
49 " vertices[2] = vec2( 0.0, 1.0);\n"
50 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
51 "}\n";
52
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050053static const char bindStateFragShaderText[] =
Cody Northrop74a2d2c2015-06-16 17:32:04 -060054 "#version 140\n"
55 "#extension GL_ARB_separate_shader_objects: require\n"
56 "#extension GL_ARB_shading_language_420pack: require\n"
57 "\n"
58 "layout(location = 0) out vec4 uFragColor;\n"
59 "void main(){\n"
60 " uFragColor = vec4(0,1,0,1);\n"
61 "}\n";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050062
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060063static void myDbgFunc(
64 VkFlags msgFlags,
65 VkObjectType objType,
66 VkObject srcObject,
67 size_t location,
68 int32_t msgCode,
69 const char* pLayerPrefix,
70 const char* pMsg,
71 void* pUserData);
Tony Barbour30486ea2015-04-07 13:44:53 -060072
73class ErrorMonitor {
74public:
Tony Barbour0c1bdc62015-04-29 17:34:29 -060075 ErrorMonitor()
Tony Barbour30486ea2015-04-07 13:44:53 -060076 {
Mike Stroyan09aae812015-05-12 16:00:45 -060077 pthread_mutexattr_t attr;
78 pthread_mutexattr_init(&attr);
79 pthread_mutex_init(&m_mutex, &attr);
80 pthread_mutex_lock(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060081 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mike Stroyan09aae812015-05-12 16:00:45 -060082 m_bailout = NULL;
83 pthread_mutex_unlock(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060084 }
85 void ClearState()
86 {
Mike Stroyan09aae812015-05-12 16:00:45 -060087 pthread_mutex_lock(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060088 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -060089 m_msgString.clear();
Mike Stroyan09aae812015-05-12 16:00:45 -060090 pthread_mutex_unlock(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060091 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060092 VkFlags GetState(std::string *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -060093 {
Mike Stroyan09aae812015-05-12 16:00:45 -060094 pthread_mutex_lock(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060095 *msgString = m_msgString;
Mike Stroyan09aae812015-05-12 16:00:45 -060096 pthread_mutex_unlock(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060097 return m_msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -060098 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060099 void SetState(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -0600100 {
Mike Stroyan09aae812015-05-12 16:00:45 -0600101 pthread_mutex_lock(&m_mutex);
102 if (m_bailout != NULL) {
103 *m_bailout = true;
104 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600105 m_msgFlags = msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600106 m_msgString.reserve(strlen(msgString));
107 m_msgString = msgString;
Mike Stroyan09aae812015-05-12 16:00:45 -0600108 pthread_mutex_unlock(&m_mutex);
109 }
110 void SetBailout(bool *bailout)
111 {
112 m_bailout = bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600113 }
114
115private:
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600116 VkFlags m_msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -0600117 std::string m_msgString;
118 pthread_mutex_t m_mutex;
119 bool* m_bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600120};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500121
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600122static void myDbgFunc(
123 VkFlags msgFlags,
124 VkObjectType objType,
125 VkObject srcObject,
126 size_t location,
127 int32_t msgCode,
128 const char* pLayerPrefix,
129 const char* pMsg,
130 void* pUserData)
Tony Barbour30486ea2015-04-07 13:44:53 -0600131{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600132 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour8508b8e2015-04-09 10:48:04 -0600133 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600134 errMonitor->SetState(msgFlags, pMsg);
Tony Barbour8508b8e2015-04-09 10:48:04 -0600135 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600136}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500137
Tony Barbour01999182015-04-09 12:58:51 -0600138class VkLayerTest : public VkRenderFramework
Tony Barbour30486ea2015-04-07 13:44:53 -0600139{
140public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600141 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
142 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500143 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
144 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbour30486ea2015-04-07 13:44:53 -0600145
146protected:
Tony Barbour01999182015-04-09 12:58:51 -0600147 VkMemoryRefManager m_memoryRefManager;
148 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600149
150 virtual void SetUp() {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600151 std::vector<const char *> instance_extension_names;
152 std::vector<const char *> device_extension_names;
Tony Barbour950ebc02015-04-23 12:55:36 -0600153
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600154 instance_extension_names.push_back(DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600155 /*
156 * Since CreateDbgMsgCallback is an instance level extension call
157 * any extension / layer that utilizes that feature also needs
158 * to be enabled at create instance time.
159 */
Mike Stroyaned254572015-06-17 16:32:06 -0600160 // Use Threading layer first to protect others from ThreadCmdBufferCollision test
161 instance_extension_names.push_back("Threading");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600162 instance_extension_names.push_back("MemTracker");
Courtney Goeltzenleuchtereb518dc2015-06-13 21:41:00 -0600163 instance_extension_names.push_back("DrawState");
164 instance_extension_names.push_back("ObjectTracker");
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600165 instance_extension_names.push_back("ShaderChecker");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600166
Mike Stroyaned254572015-06-17 16:32:06 -0600167 device_extension_names.push_back("Threading");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600168 device_extension_names.push_back("MemTracker");
Jon Ashburn64716542015-06-15 12:21:02 -0600169 device_extension_names.push_back("DrawState");
Courtney Goeltzenleuchtereb518dc2015-06-13 21:41:00 -0600170 device_extension_names.push_back("ObjectTracker");
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600171 device_extension_names.push_back("ShaderChecker");
Tony Barbour30486ea2015-04-07 13:44:53 -0600172
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600173 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -0600174 this->app_info.pNext = NULL;
175 this->app_info.pAppName = "layer_tests";
176 this->app_info.appVersion = 1;
177 this->app_info.pEngineName = "unittest";
178 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600179 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -0600180
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600181 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600182 InitFramework(instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour30486ea2015-04-07 13:44:53 -0600183 }
184
185 virtual void TearDown() {
186 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600187 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600188 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600189 }
190};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500191
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600192VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600193{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600194 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600195
196 result = cmdBuffer.BeginCommandBuffer();
197
198 /*
199 * For render test all drawing happens in a single render pass
200 * on a single command buffer.
201 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200202 if (VK_SUCCESS == result && renderPass()) {
Tony Barbour30486ea2015-04-07 13:44:53 -0600203 cmdBuffer.BeginRenderPass(renderPass(), framebuffer());
204 }
205
206 return result;
207}
208
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600209VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600210{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600211 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600212
Chris Forbesfe133ef2015-06-16 14:05:59 +1200213 if (renderPass()) {
214 cmdBuffer.EndRenderPass(renderPass());
215 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600216
217 result = cmdBuffer.EndCommandBuffer();
218
219 return result;
220}
221
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500222void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
223{
224 // Create identity matrix
225 int i;
226 struct vktriangle_vs_uniform data;
227
228 glm::mat4 Projection = glm::mat4(1.0f);
229 glm::mat4 View = glm::mat4(1.0f);
230 glm::mat4 Model = glm::mat4(1.0f);
231 glm::mat4 MVP = Projection * View * Model;
232 const int matrixSize = sizeof(MVP);
233 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
234
235 memcpy(&data.mvp, &MVP[0][0], matrixSize);
236
237 static const Vertex tri_data[] =
238 {
239 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
240 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
241 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
242 };
243
244 for (i=0; i<3; i++) {
245 data.position[i][0] = tri_data[i].posX;
246 data.position[i][1] = tri_data[i].posY;
247 data.position[i][2] = tri_data[i].posZ;
248 data.position[i][3] = tri_data[i].posW;
249 data.color[i][0] = tri_data[i].r;
250 data.color[i][1] = tri_data[i].g;
251 data.color[i][2] = tri_data[i].b;
252 data.color[i][3] = tri_data[i].a;
253 }
254
255 ASSERT_NO_FATAL_FAILURE(InitState());
256 ASSERT_NO_FATAL_FAILURE(InitViewport());
257
258 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
259
260 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
261 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
262
263 VkPipelineObj pipelineobj(m_device);
264 pipelineobj.AddShader(&vs);
265 pipelineobj.AddShader(&ps);
266
267 VkDescriptorSetObj descriptorSet(m_device);
268 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
269
270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
271 VkCommandBufferObj cmdBuffer(m_device);
272 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
273
274 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
275
276 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet, failMask);
277
278 // render triangle
279 cmdBuffer.Draw(0, 3, 0, 1);
280
281 // finalize recording of the command buffer
282 EndCommandBuffer(cmdBuffer);
283
284 cmdBuffer.QueueCommandBuffer();
285}
286
287void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
288{
289 if (m_depthStencil->Initialized()) {
290 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
291 } else {
292 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
293 }
294
295 cmdBuffer->PrepareAttachments();
296 if ((failMask & BsoFailRaster) != BsoFailRaster) {
297 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_RASTER, m_stateRaster);
298 }
299 if ((failMask & BsoFailViewport) != BsoFailViewport) {
300 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_VIEWPORT, m_stateViewport);
301 }
302 if ((failMask & BsoFailColorBlend) != BsoFailColorBlend) {
303 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_COLOR_BLEND, m_colorBlend);
304 }
305 if ((failMask & BsoFailDepthStencil) != BsoFailDepthStencil) {
306 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_DEPTH_STENCIL, m_stateDepthStencil);
307 }
308 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
309 pipelineobj.CreateVKPipeline(descriptorSet);
310 cmdBuffer->BindPipeline(pipelineobj);
311 cmdBuffer->BindDescriptorSet(descriptorSet);
312}
313
314// ********************************************************************************************************************
315// ********************************************************************************************************************
316// ********************************************************************************************************************
317// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600318#if MEM_TRACKER_TESTS
Mark Lobodzinski81078192015-05-19 10:28:29 -0500319TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
320{
321 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600322 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500323 std::string msgString;
324
325 VkFenceCreateInfo fenceInfo = {};
326 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
327 fenceInfo.pNext = NULL;
328 fenceInfo.flags = 0;
329
330 ASSERT_NO_FATAL_FAILURE(InitState());
331 ASSERT_NO_FATAL_FAILURE(InitViewport());
332 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
333
334 VkCommandBufferObj cmdBuffer(m_device);
335 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
336
337 BeginCommandBuffer(cmdBuffer);
338 cmdBuffer.ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
339 EndCommandBuffer(cmdBuffer);
340
341 testFence.init(*m_device, fenceInfo);
342
343 // Bypass framework since it does the waits automatically
344 VkResult err = VK_SUCCESS;
345 err = vkQueueSubmit( m_device->m_queue, 1, &cmdBuffer.obj(), testFence.obj());
346 ASSERT_VK_SUCCESS( err );
347
348 m_errorMonitor->ClearState();
349 // Introduce failure by calling begin again before checking fence
350 vkResetCommandBuffer(cmdBuffer.obj());
351
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600352 msgFlags = m_errorMonitor->GetState(&msgString);
353 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an err after calling ResetCommandBuffer on an active Command Buffer";
Mark Lobodzinski81078192015-05-19 10:28:29 -0500354 if (!strstr(msgString.c_str(),"Resetting CB")) {
355 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
356 }
357}
358
359TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion)
360{
361 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600362 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500363 std::string msgString;
364
365 VkFenceCreateInfo fenceInfo = {};
366 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
367 fenceInfo.pNext = NULL;
368 fenceInfo.flags = 0;
369
370 ASSERT_NO_FATAL_FAILURE(InitState());
371 ASSERT_NO_FATAL_FAILURE(InitViewport());
372 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
373
374 VkCommandBufferObj cmdBuffer(m_device);
375 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
376
377 BeginCommandBuffer(cmdBuffer);
378 cmdBuffer.ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
379 EndCommandBuffer(cmdBuffer);
380
381 testFence.init(*m_device, fenceInfo);
382
383 // Bypass framework since it does the waits automatically
384 VkResult err = VK_SUCCESS;
385 err = vkQueueSubmit( m_device->m_queue, 1, &cmdBuffer.obj(), testFence.obj());
386 ASSERT_VK_SUCCESS( err );
387
388 m_errorMonitor->ClearState();
389 // Introduce failure by calling begin again before checking fence
390 BeginCommandBuffer(cmdBuffer);
391
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600392 msgFlags = m_errorMonitor->GetState(&msgString);
393 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an err after calling BeginCommandBuffer on an active Command Buffer";
Mark Lobodzinski81078192015-05-19 10:28:29 -0500394 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
395 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
396 }
397}
398
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500399TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
400{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600401 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500402 std::string msgString;
403 VkResult err;
404
405 ASSERT_NO_FATAL_FAILURE(InitState());
406 m_errorMonitor->ClearState();
407
408 // Create an image, allocate memory, free it, and then try to bind it
409 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500410 VkDeviceMemory mem;
411 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500412
413 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
414 const int32_t tex_width = 32;
415 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500416
417 const VkImageCreateInfo image_create_info = {
418 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
419 .pNext = NULL,
420 .imageType = VK_IMAGE_TYPE_2D,
421 .format = tex_format,
422 .extent = { tex_width, tex_height, 1 },
423 .mipLevels = 1,
424 .arraySize = 1,
425 .samples = 1,
426 .tiling = VK_IMAGE_TILING_LINEAR,
427 .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
428 .flags = 0,
429 };
430 VkMemoryAllocInfo mem_alloc = {
431 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
432 .pNext = NULL,
433 .allocationSize = 0,
434 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
435 .memProps = 0,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500436 };
437
438 err = vkCreateImage(m_device->device(), &image_create_info, &image);
439 ASSERT_VK_SUCCESS(err);
440
Tony Barbour426b9052015-06-24 16:06:58 -0600441 err = vkGetObjectMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500442 VK_OBJECT_TYPE_IMAGE,
443 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500444 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500445 ASSERT_VK_SUCCESS(err);
446
Mark Lobodzinski23182612015-05-29 09:32:35 -0500447 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500448
449 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500450 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500451 ASSERT_VK_SUCCESS(err);
452
453 // Try to bind free memory that has been freed
Mark Lobodzinski23182612015-05-29 09:32:35 -0500454 err = vkBindObjectMemory(m_device->device(), VK_OBJECT_TYPE_IMAGE, image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500455 ASSERT_VK_SUCCESS(err);
456
457 // Map memory as if to initialize the image
458 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500459 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500460
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600461 msgFlags = m_errorMonitor->GetState(&msgString);
462 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error while tring to map memory not visible to CPU";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500463 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
464 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
465 }
466}
467
468TEST_F(VkLayerTest, BindInvalidMemory)
469{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600470 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500471 std::string msgString;
472 VkResult err;
473
474 ASSERT_NO_FATAL_FAILURE(InitState());
475 m_errorMonitor->ClearState();
476
477 // Create an image, allocate memory, free it, and then try to bind it
478 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500479 VkDeviceMemory mem;
480 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500481
482 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
483 const int32_t tex_width = 32;
484 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500485
486 const VkImageCreateInfo image_create_info = {
487 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
488 .pNext = NULL,
489 .imageType = VK_IMAGE_TYPE_2D,
490 .format = tex_format,
491 .extent = { tex_width, tex_height, 1 },
492 .mipLevels = 1,
493 .arraySize = 1,
494 .samples = 1,
495 .tiling = VK_IMAGE_TILING_LINEAR,
496 .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
497 .flags = 0,
498 };
499 VkMemoryAllocInfo mem_alloc = {
500 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
501 .pNext = NULL,
502 .allocationSize = 0,
503 .memProps = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500504 };
505
506 err = vkCreateImage(m_device->device(), &image_create_info, &image);
507 ASSERT_VK_SUCCESS(err);
508
Tony Barbour426b9052015-06-24 16:06:58 -0600509 err = vkGetObjectMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500510 VK_OBJECT_TYPE_IMAGE,
511 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500512 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500513 ASSERT_VK_SUCCESS(err);
514
Mark Lobodzinski23182612015-05-29 09:32:35 -0500515 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500516
517 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500518 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500519 ASSERT_VK_SUCCESS(err);
520
521 // Introduce validation failure, free memory before binding
Mark Lobodzinski23182612015-05-29 09:32:35 -0500522 vkFreeMemory(m_device->device(), mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500523 ASSERT_VK_SUCCESS(err);
524
525 // Try to bind free memory that has been freed
Mark Lobodzinski23182612015-05-29 09:32:35 -0500526 err = vkBindObjectMemory(m_device->device(), VK_OBJECT_TYPE_IMAGE, image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500527 ASSERT_VK_SUCCESS(err);
528
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600529 msgFlags = m_errorMonitor->GetState(&msgString);
530 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error while tring to bind a freed memory object";
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500531 if (!strstr(msgString.c_str(),"couldn't find info for mem obj")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500532 FAIL() << "Error received did not match expected error message from BindObjectMemory in MemTracker";
533 }
534}
535
536TEST_F(VkLayerTest, FreeBoundMemory)
537{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600538 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500539 std::string msgString;
540 VkResult err;
541
542 ASSERT_NO_FATAL_FAILURE(InitState());
543 m_errorMonitor->ClearState();
544
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
554 const VkImageCreateInfo image_create_info = {
555 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
556 .pNext = NULL,
557 .imageType = VK_IMAGE_TYPE_2D,
558 .format = tex_format,
559 .extent = { tex_width, tex_height, 1 },
560 .mipLevels = 1,
561 .arraySize = 1,
562 .samples = 1,
563 .tiling = VK_IMAGE_TILING_LINEAR,
564 .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
565 .flags = 0,
566 };
567 VkMemoryAllocInfo mem_alloc = {
568 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
569 .pNext = NULL,
570 .allocationSize = 0,
571 .memProps = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500572 };
573
574 err = vkCreateImage(m_device->device(), &image_create_info, &image);
575 ASSERT_VK_SUCCESS(err);
576
Tony Barbour426b9052015-06-24 16:06:58 -0600577 err = vkGetObjectMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500578 VK_OBJECT_TYPE_IMAGE,
579 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500580 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500581 ASSERT_VK_SUCCESS(err);
582
Mark Lobodzinski23182612015-05-29 09:32:35 -0500583 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500584
585 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500586 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500587 ASSERT_VK_SUCCESS(err);
588
589 // Bind memory to Image object
Mark Lobodzinski23182612015-05-29 09:32:35 -0500590 err = vkBindObjectMemory(m_device->device(), VK_OBJECT_TYPE_IMAGE, image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500591 ASSERT_VK_SUCCESS(err);
592
593 // Introduce validation failure, free memory while still bound to object
Mark Lobodzinski23182612015-05-29 09:32:35 -0500594 vkFreeMemory(m_device->device(), mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500595 ASSERT_VK_SUCCESS(err);
596
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600597 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter7dc4c8b2015-06-13 21:48:47 -0600598 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an warning while tring to free bound memory";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500599 if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
600 FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
601 }
602}
603
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500604TEST_F(VkLayerTest, RebindMemory)
605{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600606 VkFlags msgFlags;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500607 std::string msgString;
608 VkResult err;
609
610 ASSERT_NO_FATAL_FAILURE(InitState());
611 m_errorMonitor->ClearState();
612
613 // Create an image, allocate memory, free it, and then try to bind it
614 VkImage image;
615 VkDeviceMemory mem1;
616 VkDeviceMemory mem2;
617 VkMemoryRequirements mem_reqs;
618
619 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
620 const int32_t tex_width = 32;
621 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500622
623 const VkImageCreateInfo image_create_info = {
624 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
625 .pNext = NULL,
626 .imageType = VK_IMAGE_TYPE_2D,
627 .format = tex_format,
628 .extent = { tex_width, tex_height, 1 },
629 .mipLevels = 1,
630 .arraySize = 1,
631 .samples = 1,
632 .tiling = VK_IMAGE_TILING_LINEAR,
633 .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
634 .flags = 0,
635 };
636 VkMemoryAllocInfo mem_alloc = {
637 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
638 .pNext = NULL,
639 .allocationSize = 0,
640 .memProps = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500641 };
642
643 err = vkCreateImage(m_device->device(), &image_create_info, &image);
644 ASSERT_VK_SUCCESS(err);
645
Tony Barbour426b9052015-06-24 16:06:58 -0600646 err = vkGetObjectMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500647 VK_OBJECT_TYPE_IMAGE,
648 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500649 &mem_reqs);
650 ASSERT_VK_SUCCESS(err);
651
652 mem_alloc.allocationSize = mem_reqs.size;
653
654 // allocate 2 memory objects
655 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
656 ASSERT_VK_SUCCESS(err);
657 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
658 ASSERT_VK_SUCCESS(err);
659
660 // Bind first memory object to Image object
661 err = vkBindObjectMemory(m_device->device(), VK_OBJECT_TYPE_IMAGE, image, mem1, 0);
662 ASSERT_VK_SUCCESS(err);
663
664 // Introduce validation failure, try to bind a different memory object to the same image object
665 err = vkBindObjectMemory(m_device->device(), VK_OBJECT_TYPE_IMAGE, image, mem2, 0);
666 ASSERT_VK_SUCCESS(err);
667
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600668 msgFlags = m_errorMonitor->GetState(&msgString);
669 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error while tring to rebind an object";
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500670 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
671 FAIL() << "Error received did not match expected message when rebinding memory to an object";
672 }
673}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500674
675TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
676{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600677 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500678 std::string msgString;
679 VkResult err;
680
681 ASSERT_NO_FATAL_FAILURE(InitState());
682 m_errorMonitor->ClearState();
683
684 // Create an image object, allocate memory, destroy the object and then try to bind it
685 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500686 VkDeviceMemory mem;
687 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500688
689 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
690 const int32_t tex_width = 32;
691 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500692
693 const VkImageCreateInfo image_create_info = {
694 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
695 .pNext = NULL,
696 .imageType = VK_IMAGE_TYPE_2D,
697 .format = tex_format,
698 .extent = { tex_width, tex_height, 1 },
699 .mipLevels = 1,
700 .arraySize = 1,
701 .samples = 1,
702 .tiling = VK_IMAGE_TILING_LINEAR,
703 .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
704 .flags = 0,
705 };
706 VkMemoryAllocInfo mem_alloc = {
707 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
708 .pNext = NULL,
709 .allocationSize = 0,
710 .memProps = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500711 };
712
713 err = vkCreateImage(m_device->device(), &image_create_info, &image);
714 ASSERT_VK_SUCCESS(err);
715
Tony Barbour426b9052015-06-24 16:06:58 -0600716 err = vkGetObjectMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500717 VK_OBJECT_TYPE_IMAGE,
718 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500719 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500720 ASSERT_VK_SUCCESS(err);
721
Mark Lobodzinski23182612015-05-29 09:32:35 -0500722 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500723
724 // Allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500725 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500726 ASSERT_VK_SUCCESS(err);
727
728 // Introduce validation failure, destroy Image object before binding
729 vkDestroyObject(m_device->device(), VK_OBJECT_TYPE_IMAGE, image);
730 ASSERT_VK_SUCCESS(err);
731
732 // Now Try to bind memory to this destroyted object
Mark Lobodzinski23182612015-05-29 09:32:35 -0500733 err = vkBindObjectMemory(m_device->device(), VK_OBJECT_TYPE_IMAGE, image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500734 ASSERT_VK_SUCCESS(err);
735
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600736 msgFlags = m_errorMonitor->GetState(&msgString);
737 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error while binding memory to a destroyed object";
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500738 if (!strstr(msgString.c_str(),"that's not in global list")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500739 FAIL() << "Error received did not match expected error message from updateObjectBinding in MemTracker";
740 }
741}
742
Tony Barbour8508b8e2015-04-09 10:48:04 -0600743TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600744{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600745 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600746 VkFlags msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600747 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600748
749 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600750 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
751 fenceInfo.pNext = NULL;
752 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600753
Tony Barbour30486ea2015-04-07 13:44:53 -0600754 ASSERT_NO_FATAL_FAILURE(InitState());
755 ASSERT_NO_FATAL_FAILURE(InitViewport());
756 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
757
Tony Barbour01999182015-04-09 12:58:51 -0600758 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour30486ea2015-04-07 13:44:53 -0600759 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
760
Tony Barbour8508b8e2015-04-09 10:48:04 -0600761 BeginCommandBuffer(cmdBuffer);
Tony Barbour30486ea2015-04-07 13:44:53 -0600762 cmdBuffer.ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour8508b8e2015-04-09 10:48:04 -0600763 EndCommandBuffer(cmdBuffer);
Tony Barbour30486ea2015-04-07 13:44:53 -0600764
765 testFence.init(*m_device, fenceInfo);
766 m_errorMonitor->ClearState();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600767 cmdBuffer.QueueCommandBuffer(testFence.obj());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600768 msgFlags = m_errorMonitor->GetState(&msgString);
769 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an err from using a fence in SIGNALED state in call to vkQueueSubmit";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600770 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500771 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600772 }
773
774}
775
776TEST_F(VkLayerTest, ResetUnsignaledFence)
777{
778 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600779 VkFlags msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600780 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600781 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600782 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
783 fenceInfo.pNext = NULL;
784
Tony Barbour8508b8e2015-04-09 10:48:04 -0600785 ASSERT_NO_FATAL_FAILURE(InitState());
786 testFence.init(*m_device, fenceInfo);
787 m_errorMonitor->ClearState();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600788 VkFence fences[1] = {testFence.obj()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600789 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600790 msgFlags = m_errorMonitor->GetState(&msgString);
791 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error from submitting fence with UNSIGNALED state to vkResetFences";
Tony Barbour01999182015-04-09 12:58:51 -0600792 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500793 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600794 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600795
796}
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600797#endif
798#if OBJECT_TRACKER_TESTS
Tony Barbour54cdd192015-04-22 15:12:07 -0600799
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500800TEST_F(VkLayerTest, RasterStateNotBound)
801{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600802 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500803 std::string msgString;
804
805 TEST_DESCRIPTION("Simple Draw Call that validates failure when a raster state object is not bound beforehand");
806
807 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailRaster);
808
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600809 msgFlags = m_errorMonitor->GetState(&msgString);
810 ASSERT_EQ(msgFlags, VK_DBG_MSG_ERROR) << "Did not receive an error from Not Binding a Raster State Object";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500811 if (!strstr(msgString.c_str(),"Raster object not bound to this command buffer")) {
812 FAIL() << "Error received was not 'Raster object not bound to this command buffer'";
813 }
814}
815
816TEST_F(VkLayerTest, ViewportStateNotBound)
817{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600818 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500819 std::string msgString;
820 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
821
822 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
823
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600824 msgFlags = m_errorMonitor->GetState(&msgString);
825 ASSERT_EQ(msgFlags, VK_DBG_MSG_ERROR) << "Did not receive an error from Not Binding a Viewport State Object";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500826 if (!strstr(msgString.c_str(),"Viewport object not bound to this command buffer")) {
827 FAIL() << "Error received was not 'Viewport object not bound to this command buffer'";
828 }
829}
830
831TEST_F(VkLayerTest, ColorBlendStateNotBound)
832{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600833 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500834 std::string msgString;
835
836 TEST_DESCRIPTION("Simple Draw Call that validates failure when a color-blend state object is not bound beforehand");
837
838 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailColorBlend);
839
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600840 msgFlags = m_errorMonitor->GetState(&msgString);
841 ASSERT_EQ(msgFlags, VK_DBG_MSG_ERROR) << "Did not receive an error from Not Binding a ColorBlend State Object";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500842 if (!strstr(msgString.c_str(),"Color-blend object not bound to this command buffer")) {
843 FAIL() << "Error received was not 'Color-blend object not bound to this command buffer'";
844 }
845}
846
847TEST_F(VkLayerTest, DepthStencilStateNotBound)
848{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600849 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500850 std::string msgString;
851
852 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth-stencil state object is not bound beforehand");
853
854 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthStencil);
855
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600856 msgFlags = m_errorMonitor->GetState(&msgString);
857 ASSERT_EQ(msgFlags, VK_DBG_MSG_ERROR) << "Did not receive an error from Not Binding a DepthStencil State Object";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500858 if (!strstr(msgString.c_str(),"Depth-stencil object not bound to this command buffer")) {
859 FAIL() << "Error received was not 'Depth-stencil object not bound to this command buffer'";
860 }
Tony Barbourdb686622015-05-06 09:35:56 -0600861}
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600862#endif
863#if DRAW_STATE_TESTS
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600864TEST_F(VkLayerTest, PipelineNotBound)
865{
866 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600867 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600868 std::string msgString;
869
870 ASSERT_NO_FATAL_FAILURE(InitState());
871 m_errorMonitor->ClearState();
872 VkCommandBufferObj cmdBuffer(m_device);
873 BeginCommandBuffer(cmdBuffer);
874 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
875 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600876 msgFlags = m_errorMonitor->GetState(&msgString);
877 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600878 if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
879 FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
880 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600881}
882
883TEST_F(VkLayerTest, InvalidDescriptorPool)
884{
885 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
886 // The DS check for this is after driver has been called to validate DS internal data struct
887 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600888/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600889 std::string msgString;
890 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
891 vkResetDescriptorPool(device(), badPool);
892
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600893 msgFlags = m_errorMonitor->GetState(&msgString);
894 ASSERT_EQ(msgFlags, VK_DBG_MSG_ERROR) << "Did not receive an error from Resetting an invalid DescriptorPool Object";
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600895 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
896 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
897 }*/
898}
899
900TEST_F(VkLayerTest, InvalidDescriptorSet)
901{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600902 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
903 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600904 // Create a valid cmd buffer
905 // call vkCmdBindDescriptorSets w/ false DS
906}
907
908TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
909{
910 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
911 // The DS check for this is after driver has been called to validate DS internal data struct
912}
913
914TEST_F(VkLayerTest, InvalidPipeline)
915{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600916 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
917 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600918 // Create a valid cmd buffer
919 // call vkCmdBindPipeline w/ false Pipeline
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600920 VkFlags msgFlags;
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600921 std::string msgString;
922
923 ASSERT_NO_FATAL_FAILURE(InitState());
924 m_errorMonitor->ClearState();
925 VkCommandBufferObj cmdBuffer(m_device);
926 BeginCommandBuffer(cmdBuffer);
927 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
928 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600929 msgFlags = m_errorMonitor->GetState(&msgString);
930 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600931 if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
932 FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
933 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600934}
935
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600936TEST_F(VkLayerTest, NoEndCmdBuffer)
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600937{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600938 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600939 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600940 std::string msgString;
941 VkResult err;
942
943 ASSERT_NO_FATAL_FAILURE(InitState());
944 m_errorMonitor->ClearState();
945 VkCommandBufferObj cmdBuffer(m_device);
946 const VkDescriptorTypeCount ds_type_count = {
947 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
948 .count = 1,
949 };
950 const VkDescriptorPoolCreateInfo ds_pool_ci = {
951 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
952 .pNext = NULL,
953 .count = 1,
954 .pTypeCount = &ds_type_count,
955 };
956 VkDescriptorPool ds_pool;
957 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
958 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600959
960 const VkDescriptorSetLayoutBinding dsl_binding = {
961 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
Chia-I Wud3114a22015-05-25 16:22:52 +0800962 .arraySize = 1,
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600963 .stageFlags = VK_SHADER_STAGE_ALL,
964 .pImmutableSamplers = NULL,
965 };
966
967 const VkDescriptorSetLayoutCreateInfo ds_layout_ci = {
968 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
969 .pNext = NULL,
970 .count = 1,
971 .pBinding = &dsl_binding,
972 };
973 VkDescriptorSetLayout ds_layout;
974 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
975 ASSERT_VK_SUCCESS(err);
976
977 VkDescriptorSet descriptorSet;
978 uint32_t ds_count = 0;
979 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
980 ASSERT_VK_SUCCESS(err);
981
982 const VkPipelineLayoutCreateInfo pipeline_layout_ci = {
983 .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
984 .pNext = NULL,
985 .descriptorSetCount = 1,
986 .pSetLayouts = &ds_layout,
987 };
988
989 VkPipelineLayout pipeline_layout;
990 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
991 ASSERT_VK_SUCCESS(err);
992
993 size_t shader_len = strlen(bindStateVertShaderText);
994 size_t codeSize = 3 * sizeof(uint32_t) + shader_len + 1;
995 void* pCode = malloc(codeSize);
996
997 /* try version 0 first: VkShaderStage followed by GLSL */
998 ((uint32_t *) pCode)[0] = ICD_SPV_MAGIC;
999 ((uint32_t *) pCode)[1] = 0;
1000 ((uint32_t *) pCode)[2] = VK_SHADER_STAGE_VERTEX;
1001 memcpy(((uint32_t *) pCode + 3), bindStateVertShaderText, shader_len + 1);
1002
1003 const VkShaderCreateInfo vs_ci = {
1004 .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO,
1005 .pNext = NULL,
Courtney Goeltzenleuchter1d723102015-06-18 21:49:59 -06001006 .module = VK_NULL_HANDLE,
1007 .name = "main",
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001008 .codeSize = codeSize,
1009 .pCode = pCode,
1010 .flags = 0,
1011 };
1012 VkShader vs;
1013 err = vkCreateShader(m_device->device(), &vs_ci, &vs);
1014 ASSERT_VK_SUCCESS(err);
1015
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001016 const VkPipelineShaderStageCreateInfo pipe_vs_ci = {
1017 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
1018 .pNext = NULL,
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001019 .stage = VK_SHADER_STAGE_VERTEX,
1020 .shader = vs,
1021 .linkConstBufferCount = 0,
1022 .pLinkConstBufferInfo = NULL,
1023 .pSpecializationInfo = NULL,
1024 };
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001025 const VkGraphicsPipelineCreateInfo gp_ci = {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001026 .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
1027 .pNext = NULL,
1028 .stageCount = 1,
1029 .pStages = &pipe_vs_ci,
1030 .pVertexInputState = NULL,
1031 .pIaState = NULL,
1032 .pTessState = NULL,
1033 .pVpState = NULL,
1034 .pRsState = NULL,
1035 .pMsState = NULL,
1036 .pDsState = NULL,
1037 .pCbState = NULL,
1038 .flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT,
1039 .layout = pipeline_layout,
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001040 };
1041
1042 VkPipeline pipeline;
1043 err = vkCreateGraphicsPipeline(m_device->device(), &gp_ci, &pipeline);
1044 ASSERT_VK_SUCCESS(err);
1045
1046 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06001047 vkCmdBindDescriptorSets(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001048
1049 VkCmdBuffer localCmdBuffer = cmdBuffer.GetBufferHandle();
1050 m_device->get_device_queue();
1051 vkQueueSubmit(m_device->m_queue, 1, &localCmdBuffer, NULL);
1052
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001053 msgFlags = m_errorMonitor->GetState(&msgString);
1054 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after vkEndDescriptorPoolUpdate() w/o first calling vkBeginDescriptorPoolUpdate().";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001055 if (!strstr(msgString.c_str(),"You must call vkEndCommandBuffer() on CB ")) {
1056 FAIL() << "Error received was not 'You must call vkEndCommandBuffer() on CB <0xblah> before this call to vkQueueSubmit()!'";
1057 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001058}
1059
1060TEST_F(VkLayerTest, InvalidDynamicStateObject)
1061{
1062 // Create a valid cmd buffer
1063 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001064 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1065 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001066}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06001067
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001068TEST_F(VkLayerTest, VtxBufferBadIndex)
1069{
1070 // Bind VBO out-of-bounds for given PSO
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001071 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001072 std::string msgString;
1073 VkResult err;
1074
1075 ASSERT_NO_FATAL_FAILURE(InitState());
1076 m_errorMonitor->ClearState();
1077 VkCommandBufferObj cmdBuffer(m_device);
1078 const VkDescriptorTypeCount ds_type_count = {
1079 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1080 .count = 1,
1081 };
1082 const VkDescriptorPoolCreateInfo ds_pool_ci = {
1083 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
1084 .pNext = NULL,
1085 .count = 1,
1086 .pTypeCount = &ds_type_count,
1087 };
1088 VkDescriptorPool ds_pool;
1089 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1090 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001091
1092 const VkDescriptorSetLayoutBinding dsl_binding = {
1093 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
Chia-I Wud3114a22015-05-25 16:22:52 +08001094 .arraySize = 1,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001095 .stageFlags = VK_SHADER_STAGE_ALL,
1096 .pImmutableSamplers = NULL,
1097 };
1098
1099 const VkDescriptorSetLayoutCreateInfo ds_layout_ci = {
1100 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
1101 .pNext = NULL,
1102 .count = 1,
1103 .pBinding = &dsl_binding,
1104 };
1105 VkDescriptorSetLayout ds_layout;
1106 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1107 ASSERT_VK_SUCCESS(err);
1108
1109 VkDescriptorSet descriptorSet;
1110 uint32_t ds_count = 0;
1111 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1112 ASSERT_VK_SUCCESS(err);
1113
1114 const VkPipelineLayoutCreateInfo pipeline_layout_ci = {
1115 .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
1116 .pNext = NULL,
1117 .descriptorSetCount = 1,
1118 .pSetLayouts = &ds_layout,
1119 };
1120
1121 VkPipelineLayout pipeline_layout;
1122 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1123 ASSERT_VK_SUCCESS(err);
1124
1125 size_t shader_len = strlen(bindStateVertShaderText);
1126 size_t codeSize = 3 * sizeof(uint32_t) + shader_len + 1;
1127 void* pCode = malloc(codeSize);
1128
1129 /* try version 0 first: VkShaderStage followed by GLSL */
1130 ((uint32_t *) pCode)[0] = ICD_SPV_MAGIC;
1131 ((uint32_t *) pCode)[1] = 0;
1132 ((uint32_t *) pCode)[2] = VK_SHADER_STAGE_VERTEX;
1133 memcpy(((uint32_t *) pCode + 3), bindStateVertShaderText, shader_len + 1);
1134
1135 const VkShaderCreateInfo vs_ci = {
1136 .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO,
1137 .pNext = NULL,
Courtney Goeltzenleuchter1d723102015-06-18 21:49:59 -06001138 .module = VK_NULL_HANDLE,
1139 .name = "main",
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001140 .codeSize = codeSize,
1141 .pCode = pCode,
1142 .flags = 0,
1143 };
1144 VkShader vs;
1145 err = vkCreateShader(m_device->device(), &vs_ci, &vs);
1146
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001147 const VkPipelineShaderStageCreateInfo pipe_vs_ci = {
1148 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
1149 .pNext = NULL,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001150 .stage = VK_SHADER_STAGE_VERTEX,
1151 .shader = vs,
1152 .linkConstBufferCount = 0,
1153 .pLinkConstBufferInfo = NULL,
1154 .pSpecializationInfo = NULL,
1155 };
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001156 const VkGraphicsPipelineCreateInfo gp_ci = {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001157 .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
1158 .pNext = NULL,
1159 .stageCount = 1,
1160 .pStages = &pipe_vs_ci,
1161 .pVertexInputState = NULL,
1162 .pIaState = NULL,
1163 .pTessState = NULL,
1164 .pVpState = NULL,
1165 .pRsState = NULL,
1166 .pMsState = NULL,
1167 .pDsState = NULL,
1168 .pCbState = NULL,
1169 .flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT,
1170 .layout = pipeline_layout,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001171 };
1172
1173 VkPipeline pipeline;
1174 err = vkCreateGraphicsPipeline(m_device->device(), &gp_ci, &pipeline);
1175 ASSERT_VK_SUCCESS(err);
1176
1177 err= cmdBuffer.BeginCommandBuffer();
1178 ASSERT_VK_SUCCESS(err);
1179 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1180 // Should error before calling to driver so don't care about actual data
1181 vkCmdBindVertexBuffers(cmdBuffer.GetBufferHandle(), 0, 1, NULL, NULL);
1182
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001183 msgFlags = m_errorMonitor->GetState(&msgString);
1184 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after vkCmdBindVertexBuffers() w/o any Vtx Inputs in PSO.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001185 if (!strstr(msgString.c_str(),"Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.")) {
1186 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
1187 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001188}
1189
1190TEST_F(VkLayerTest, DSTypeMismatch)
1191{
1192 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001193 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001194 std::string msgString;
1195 VkResult err;
1196
1197 ASSERT_NO_FATAL_FAILURE(InitState());
1198 m_errorMonitor->ClearState();
1199 //VkDescriptorSetObj descriptorSet(m_device);
1200 const VkDescriptorTypeCount ds_type_count = {
1201 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1202 .count = 1,
1203 };
1204 const VkDescriptorPoolCreateInfo ds_pool_ci = {
1205 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
1206 .pNext = NULL,
1207 .count = 1,
1208 .pTypeCount = &ds_type_count,
1209 };
1210 VkDescriptorPool ds_pool;
1211 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1212 ASSERT_VK_SUCCESS(err);
1213 const VkDescriptorSetLayoutBinding dsl_binding = {
1214 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
Chia-I Wud3114a22015-05-25 16:22:52 +08001215 .arraySize = 1,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001216 .stageFlags = VK_SHADER_STAGE_ALL,
1217 .pImmutableSamplers = NULL,
1218 };
1219
1220 const VkDescriptorSetLayoutCreateInfo ds_layout_ci = {
1221 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
1222 .pNext = NULL,
1223 .count = 1,
1224 .pBinding = &dsl_binding,
1225 };
1226 VkDescriptorSetLayout ds_layout;
1227 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1228 ASSERT_VK_SUCCESS(err);
1229
1230 VkDescriptorSet descriptorSet;
1231 uint32_t ds_count = 0;
1232 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1233 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001234
1235 const VkSamplerCreateInfo sampler_ci = {
1236 .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
1237 .pNext = NULL,
1238 .magFilter = VK_TEX_FILTER_NEAREST,
1239 .minFilter = VK_TEX_FILTER_NEAREST,
1240 .mipMode = VK_TEX_MIPMAP_MODE_BASE,
1241 .addressU = VK_TEX_ADDRESS_CLAMP,
1242 .addressV = VK_TEX_ADDRESS_CLAMP,
1243 .addressW = VK_TEX_ADDRESS_CLAMP,
1244 .mipLodBias = 1.0,
1245 .maxAnisotropy = 1,
1246 .compareOp = VK_COMPARE_OP_NEVER,
1247 .minLod = 1.0,
1248 .maxLod = 1.0,
1249 .borderColor = VK_BORDER_COLOR_OPAQUE_WHITE,
1250 };
1251 VkSampler sampler;
1252 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1253 ASSERT_VK_SUCCESS(err);
1254
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001255 VkDescriptorInfo descriptor_info;
1256 memset(&descriptor_info, 0, sizeof(descriptor_info));
1257 descriptor_info.sampler = sampler;
1258
1259 VkWriteDescriptorSet descriptor_write;
1260 memset(&descriptor_write, 0, sizeof(descriptor_write));
1261 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1262 descriptor_write.destSet = descriptorSet;
1263 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001264 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001265 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1266 descriptor_write.pDescriptors = &descriptor_info;
1267
1268 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1269
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001270 msgFlags = m_errorMonitor->GetState(&msgString);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001271 std::cout << msgString << "\n";
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001272 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after updating BUFFER Descriptor w/ incorrect type of SAMPLER.";
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001273 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) {
1274 FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match overlapping binding type!'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001275 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001276}
1277
1278TEST_F(VkLayerTest, DSUpdateOutOfBounds)
1279{
1280 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001281 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001282 std::string msgString;
1283 VkResult err;
1284
1285 ASSERT_NO_FATAL_FAILURE(InitState());
1286 m_errorMonitor->ClearState();
1287 //VkDescriptorSetObj descriptorSet(m_device);
1288 const VkDescriptorTypeCount ds_type_count = {
1289 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1290 .count = 1,
1291 };
1292 const VkDescriptorPoolCreateInfo ds_pool_ci = {
1293 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
1294 .pNext = NULL,
1295 .count = 1,
1296 .pTypeCount = &ds_type_count,
1297 };
1298 VkDescriptorPool ds_pool;
1299 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1300 ASSERT_VK_SUCCESS(err);
1301 const VkDescriptorSetLayoutBinding dsl_binding = {
1302 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
Chia-I Wud3114a22015-05-25 16:22:52 +08001303 .arraySize = 1,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001304 .stageFlags = VK_SHADER_STAGE_ALL,
1305 .pImmutableSamplers = NULL,
1306 };
1307
1308 const VkDescriptorSetLayoutCreateInfo ds_layout_ci = {
1309 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
1310 .pNext = NULL,
1311 .count = 1,
1312 .pBinding = &dsl_binding,
1313 };
1314 VkDescriptorSetLayout ds_layout;
1315 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1316 ASSERT_VK_SUCCESS(err);
1317
1318 VkDescriptorSet descriptorSet;
1319 uint32_t ds_count = 0;
1320 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1321 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001322
1323 const VkSamplerCreateInfo sampler_ci = {
1324 .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
1325 .pNext = NULL,
1326 .magFilter = VK_TEX_FILTER_NEAREST,
1327 .minFilter = VK_TEX_FILTER_NEAREST,
1328 .mipMode = VK_TEX_MIPMAP_MODE_BASE,
1329 .addressU = VK_TEX_ADDRESS_CLAMP,
1330 .addressV = VK_TEX_ADDRESS_CLAMP,
1331 .addressW = VK_TEX_ADDRESS_CLAMP,
1332 .mipLodBias = 1.0,
1333 .maxAnisotropy = 1,
1334 .compareOp = VK_COMPARE_OP_NEVER,
1335 .minLod = 1.0,
1336 .maxLod = 1.0,
1337 .borderColor = VK_BORDER_COLOR_OPAQUE_WHITE,
1338 };
1339 VkSampler sampler;
1340 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1341 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001342
1343 VkDescriptorInfo descriptor_info;
1344 memset(&descriptor_info, 0, sizeof(descriptor_info));
1345 descriptor_info.sampler = sampler;
1346
1347 VkWriteDescriptorSet descriptor_write;
1348 memset(&descriptor_write, 0, sizeof(descriptor_write));
1349 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1350 descriptor_write.destSet = descriptorSet;
1351 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
1352 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001353 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001354 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1355 descriptor_write.pDescriptors = &descriptor_info;
1356
1357 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1358
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001359 msgFlags = m_errorMonitor->GetState(&msgString);
1360 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after updating Descriptor w/ index out of bounds.";
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001361 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
1362 FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001363 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001364}
1365
1366TEST_F(VkLayerTest, InvalidDSUpdateIndex)
1367{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001368 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001369 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001370 std::string msgString;
1371 VkResult err;
1372
1373 ASSERT_NO_FATAL_FAILURE(InitState());
1374 m_errorMonitor->ClearState();
1375 //VkDescriptorSetObj descriptorSet(m_device);
1376 const VkDescriptorTypeCount ds_type_count = {
1377 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1378 .count = 1,
1379 };
1380 const VkDescriptorPoolCreateInfo ds_pool_ci = {
1381 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
1382 .pNext = NULL,
1383 .count = 1,
1384 .pTypeCount = &ds_type_count,
1385 };
1386 VkDescriptorPool ds_pool;
1387 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1388 ASSERT_VK_SUCCESS(err);
1389 const VkDescriptorSetLayoutBinding dsl_binding = {
1390 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
Chia-I Wud3114a22015-05-25 16:22:52 +08001391 .arraySize = 1,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001392 .stageFlags = VK_SHADER_STAGE_ALL,
1393 .pImmutableSamplers = NULL,
1394 };
1395
1396 const VkDescriptorSetLayoutCreateInfo ds_layout_ci = {
1397 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
1398 .pNext = NULL,
1399 .count = 1,
1400 .pBinding = &dsl_binding,
1401 };
1402 VkDescriptorSetLayout ds_layout;
1403 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1404 ASSERT_VK_SUCCESS(err);
1405
1406 VkDescriptorSet descriptorSet;
1407 uint32_t ds_count = 0;
1408 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1409 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001410
1411 const VkSamplerCreateInfo sampler_ci = {
1412 .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
1413 .pNext = NULL,
1414 .magFilter = VK_TEX_FILTER_NEAREST,
1415 .minFilter = VK_TEX_FILTER_NEAREST,
1416 .mipMode = VK_TEX_MIPMAP_MODE_BASE,
1417 .addressU = VK_TEX_ADDRESS_CLAMP,
1418 .addressV = VK_TEX_ADDRESS_CLAMP,
1419 .addressW = VK_TEX_ADDRESS_CLAMP,
1420 .mipLodBias = 1.0,
1421 .maxAnisotropy = 1,
1422 .compareOp = VK_COMPARE_OP_NEVER,
1423 .minLod = 1.0,
1424 .maxLod = 1.0,
1425 .borderColor = VK_BORDER_COLOR_OPAQUE_WHITE,
1426 };
1427 VkSampler sampler;
1428 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1429 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001430
1431 VkDescriptorInfo descriptor_info;
1432 memset(&descriptor_info, 0, sizeof(descriptor_info));
1433 descriptor_info.sampler = sampler;
1434
1435 VkWriteDescriptorSet descriptor_write;
1436 memset(&descriptor_write, 0, sizeof(descriptor_write));
1437 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1438 descriptor_write.destSet = descriptorSet;
1439 descriptor_write.destBinding = 2;
1440 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001441 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001442 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1443 descriptor_write.pDescriptors = &descriptor_info;
1444
1445 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1446
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001447 msgFlags = m_errorMonitor->GetState(&msgString);
1448 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after updating Descriptor w/ count too large for layout.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001449 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
1450 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
1451 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001452}
1453
1454TEST_F(VkLayerTest, InvalidDSUpdateStruct)
1455{
1456 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001457 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001458 std::string msgString;
1459 VkResult err;
1460
1461 ASSERT_NO_FATAL_FAILURE(InitState());
1462 m_errorMonitor->ClearState();
1463 //VkDescriptorSetObj descriptorSet(m_device);
1464 const VkDescriptorTypeCount ds_type_count = {
1465 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1466 .count = 1,
1467 };
1468 const VkDescriptorPoolCreateInfo ds_pool_ci = {
1469 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
1470 .pNext = NULL,
1471 .count = 1,
1472 .pTypeCount = &ds_type_count,
1473 };
1474 VkDescriptorPool ds_pool;
1475 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1476 ASSERT_VK_SUCCESS(err);
1477 const VkDescriptorSetLayoutBinding dsl_binding = {
1478 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
Chia-I Wud3114a22015-05-25 16:22:52 +08001479 .arraySize = 1,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001480 .stageFlags = VK_SHADER_STAGE_ALL,
1481 .pImmutableSamplers = NULL,
1482 };
1483
1484 const VkDescriptorSetLayoutCreateInfo ds_layout_ci = {
1485 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
1486 .pNext = NULL,
1487 .count = 1,
1488 .pBinding = &dsl_binding,
1489 };
1490 VkDescriptorSetLayout ds_layout;
1491 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1492 ASSERT_VK_SUCCESS(err);
1493
1494 VkDescriptorSet descriptorSet;
1495 uint32_t ds_count = 0;
1496 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1497 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001498
1499 const VkSamplerCreateInfo sampler_ci = {
1500 .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
1501 .pNext = NULL,
1502 .magFilter = VK_TEX_FILTER_NEAREST,
1503 .minFilter = VK_TEX_FILTER_NEAREST,
1504 .mipMode = VK_TEX_MIPMAP_MODE_BASE,
1505 .addressU = VK_TEX_ADDRESS_CLAMP,
1506 .addressV = VK_TEX_ADDRESS_CLAMP,
1507 .addressW = VK_TEX_ADDRESS_CLAMP,
1508 .mipLodBias = 1.0,
1509 .maxAnisotropy = 1,
1510 .compareOp = VK_COMPARE_OP_NEVER,
1511 .minLod = 1.0,
1512 .maxLod = 1.0,
1513 .borderColor = VK_BORDER_COLOR_OPAQUE_WHITE,
1514 };
1515 VkSampler sampler;
1516 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1517 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001518
1519
1520 VkDescriptorInfo descriptor_info;
1521 memset(&descriptor_info, 0, sizeof(descriptor_info));
1522 descriptor_info.sampler = sampler;
1523
1524 VkWriteDescriptorSet descriptor_write;
1525 memset(&descriptor_write, 0, sizeof(descriptor_write));
1526 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
1527 descriptor_write.destSet = descriptorSet;
1528 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001529 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001530 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1531 descriptor_write.pDescriptors = &descriptor_info;
1532
1533 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1534
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001535 msgFlags = m_errorMonitor->GetState(&msgString);
1536 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after updating Descriptor w/ invalid struct type.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001537 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
1538 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
1539 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001540}
1541
1542TEST_F(VkLayerTest, NumSamplesMismatch)
1543{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001544 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001545 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001546 std::string msgString;
1547 VkResult err;
1548
1549 ASSERT_NO_FATAL_FAILURE(InitState());
1550 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1551 m_errorMonitor->ClearState();
1552 VkCommandBufferObj cmdBuffer(m_device);
1553 const VkDescriptorTypeCount ds_type_count = {
1554 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1555 .count = 1,
1556 };
1557 const VkDescriptorPoolCreateInfo ds_pool_ci = {
1558 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
1559 .pNext = NULL,
1560 .count = 1,
1561 .pTypeCount = &ds_type_count,
1562 };
1563 VkDescriptorPool ds_pool;
1564 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1565 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001566
1567 const VkDescriptorSetLayoutBinding dsl_binding = {
1568 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
Chia-I Wud3114a22015-05-25 16:22:52 +08001569 .arraySize = 1,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001570 .stageFlags = VK_SHADER_STAGE_ALL,
1571 .pImmutableSamplers = NULL,
1572 };
1573
1574 const VkDescriptorSetLayoutCreateInfo ds_layout_ci = {
1575 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
1576 .pNext = NULL,
1577 .count = 1,
1578 .pBinding = &dsl_binding,
1579 };
1580 VkDescriptorSetLayout ds_layout;
1581 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1582 ASSERT_VK_SUCCESS(err);
1583
1584 VkDescriptorSet descriptorSet;
1585 uint32_t ds_count = 0;
1586 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1587 ASSERT_VK_SUCCESS(err);
1588
1589 const VkPipelineMsStateCreateInfo pipe_ms_state_ci = {
1590 .sType = VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO,
1591 .pNext = NULL,
Tony Barbourd1e95582015-06-03 12:30:49 -06001592 .samples = 4,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001593 .multisampleEnable = 1,
1594 .sampleShadingEnable = 0,
1595 .minSampleShading = 1.0,
1596 .sampleMask = 15,
1597 };
1598
1599 const VkPipelineLayoutCreateInfo pipeline_layout_ci = {
1600 .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
1601 .pNext = NULL,
1602 .descriptorSetCount = 1,
1603 .pSetLayouts = &ds_layout,
1604 };
1605
1606 VkPipelineLayout pipeline_layout;
1607 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1608 ASSERT_VK_SUCCESS(err);
1609
1610 size_t shader_len = strlen(bindStateVertShaderText);
1611 size_t codeSize = 3 * sizeof(uint32_t) + shader_len + 1;
1612 void* pCode = malloc(codeSize);
1613
1614 /* try version 0 first: VkShaderStage followed by GLSL */
1615 ((uint32_t *) pCode)[0] = ICD_SPV_MAGIC;
1616 ((uint32_t *) pCode)[1] = 0;
1617 ((uint32_t *) pCode)[2] = VK_SHADER_STAGE_VERTEX;
1618 memcpy(((uint32_t *) pCode + 3), bindStateVertShaderText, shader_len + 1);
1619
1620 const VkShaderCreateInfo vs_ci = {
1621 .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO,
1622 .pNext = NULL,
Courtney Goeltzenleuchter1d723102015-06-18 21:49:59 -06001623 .module = VK_NULL_HANDLE,
1624 .name = "main",
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001625 .codeSize = codeSize,
1626 .pCode = pCode,
1627 .flags = 0,
1628 };
1629 VkShader vs;
1630 err = vkCreateShader(m_device->device(), &vs_ci, &vs);
1631 ASSERT_VK_SUCCESS(err);
1632
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001633 const VkPipelineShaderStageCreateInfo pipe_vs_ci = {
1634 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
1635 .pNext = NULL,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001636 .stage = VK_SHADER_STAGE_VERTEX,
1637 .shader = vs,
1638 .linkConstBufferCount = 0,
1639 .pLinkConstBufferInfo = NULL,
1640 .pSpecializationInfo = NULL,
1641 };
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001642 const VkGraphicsPipelineCreateInfo gp_ci = {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001643 .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
1644 .pNext = NULL,
1645 .stageCount = 1,
1646 .pStages = &pipe_vs_ci,
1647 .pVertexInputState = NULL,
1648 .pIaState = NULL,
1649 .pTessState = NULL,
1650 .pVpState = NULL,
1651 .pRsState = NULL,
1652 .pMsState = &pipe_ms_state_ci,
1653 .pDsState = NULL,
1654 .pCbState = NULL,
1655 .flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT,
1656 .layout = pipeline_layout,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001657 };
1658
1659 VkPipeline pipeline;
1660 err = vkCreateGraphicsPipeline(m_device->device(), &gp_ci, &pipeline);
1661 ASSERT_VK_SUCCESS(err);
1662
1663 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1664 BeginCommandBuffer(cmdBuffer);
1665 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1666
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001667 msgFlags = m_errorMonitor->GetState(&msgString);
1668 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding RenderPass w/ mismatched MSAA from PSO.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001669 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
1670 FAIL() << "Error received was not 'Num samples mismatch!...'";
1671 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001672}
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001673#endif
1674#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06001675#if GTEST_IS_THREADSAFE
1676struct thread_data_struct {
1677 VkCmdBuffer cmdBuffer;
1678 VkEvent event;
1679 bool bailout;
1680};
1681
1682extern "C" void *AddToCommandBuffer(void *arg)
1683{
1684 struct thread_data_struct *data = (struct thread_data_struct *) arg;
1685 std::string msgString;
1686
1687 for (int i = 0; i<10000; i++) {
1688 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPE_EVENT_COMMANDS_COMPLETE);
1689 if (data->bailout) {
1690 break;
1691 }
1692 }
1693 return NULL;
1694}
1695
1696TEST_F(VkLayerTest, ThreadCmdBufferCollision)
1697{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001698 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06001699 std::string msgString;
1700 pthread_t thread;
1701 pthread_attr_t thread_attr;
1702
1703 ASSERT_NO_FATAL_FAILURE(InitState());
1704 ASSERT_NO_FATAL_FAILURE(InitViewport());
1705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1706
1707 VkCommandBufferObj cmdBuffer(m_device);
1708
1709 m_errorMonitor->ClearState();
1710 pthread_attr_init(&thread_attr);
1711 BeginCommandBuffer(cmdBuffer);
1712
1713 VkEventCreateInfo event_info;
1714 VkEvent event;
1715 VkMemoryRequirements mem_req;
Mike Stroyan09aae812015-05-12 16:00:45 -06001716 VkResult err;
1717
1718 memset(&event_info, 0, sizeof(event_info));
1719 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
1720
1721 err = vkCreateEvent(device(), &event_info, &event);
1722 ASSERT_VK_SUCCESS(err);
1723
Tony Barbour426b9052015-06-24 16:06:58 -06001724 err = vkGetObjectMemoryRequirements(device(), VK_OBJECT_TYPE_EVENT, event, &mem_req);
Mike Stroyan09aae812015-05-12 16:00:45 -06001725 ASSERT_VK_SUCCESS(err);
1726
1727 VkMemoryAllocInfo mem_info;
1728 VkDeviceMemory event_mem;
1729
Mike Stroyan09aae812015-05-12 16:00:45 -06001730 memset(&mem_info, 0, sizeof(mem_info));
1731 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
1732 mem_info.allocationSize = mem_req.size;
Courtney Goeltzenleuchterb25c9b92015-06-18 17:01:41 -06001733 mem_info.memProps = 0;
Mike Stroyan09aae812015-05-12 16:00:45 -06001734 err = vkAllocMemory(device(), &mem_info, &event_mem);
1735 ASSERT_VK_SUCCESS(err);
1736
Mark Lobodzinski23182612015-05-29 09:32:35 -05001737 err = vkBindObjectMemory(device(), VK_OBJECT_TYPE_EVENT, event, event_mem, 0);
Mike Stroyan09aae812015-05-12 16:00:45 -06001738 ASSERT_VK_SUCCESS(err);
1739
1740 err = vkResetEvent(device(), event);
1741 ASSERT_VK_SUCCESS(err);
1742
1743 struct thread_data_struct data;
1744 data.cmdBuffer = cmdBuffer.obj();
1745 data.event = event;
1746 data.bailout = false;
1747 m_errorMonitor->SetBailout(&data.bailout);
1748 // Add many entries to command buffer from another thread.
1749 pthread_create(&thread, &thread_attr, AddToCommandBuffer, (void *)&data);
1750 // Add many entries to command buffer from this thread at the same time.
1751 AddToCommandBuffer(&data);
1752 pthread_join(thread, NULL);
1753 EndCommandBuffer(cmdBuffer);
1754
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001755 msgFlags = m_errorMonitor->GetState(&msgString);
Mike Stroyaned254572015-06-17 16:32:06 -06001756 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an err from using one VkCommandBufferObj in two threads";
Mike Stroyan09aae812015-05-12 16:00:45 -06001757 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05001758 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06001759 }
1760
1761}
1762#endif
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001763#endif
Chris Forbes5af3bf22015-05-25 11:13:08 +12001764
1765#if SHADER_CHECKER_TESTS
1766TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
1767{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001768 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12001769 std::string msgString;
1770 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06001771 ScopedUseGlsl useGlsl(false);
Chris Forbes5af3bf22015-05-25 11:13:08 +12001772
1773 char const *vsSource =
1774 "#version 140\n"
1775 "#extension GL_ARB_separate_shader_objects: require\n"
1776 "#extension GL_ARB_shading_language_420pack: require\n"
1777 "\n"
1778 "layout(location=0) out float x;\n"
1779 "void main(){\n"
1780 " gl_Position = vec4(1);\n"
1781 " x = 0;\n"
1782 "}\n";
1783 char const *fsSource =
1784 "#version 140\n"
1785 "#extension GL_ARB_separate_shader_objects: require\n"
1786 "#extension GL_ARB_shading_language_420pack: require\n"
1787 "\n"
1788 "layout(location=0) out vec4 color;\n"
1789 "void main(){\n"
1790 " color = vec4(1);\n"
1791 "}\n";
1792
1793 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
1794 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
1795
1796 VkPipelineObj pipe(m_device);
1797 pipe.AddShader(&vs);
1798 pipe.AddShader(&fs);
1799
1800 VkCommandBufferObj dummyCmd(m_device);
1801 VkDescriptorSetObj descriptorSet(m_device);
1802 descriptorSet.AppendDummy();
1803 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
1804
1805 m_errorMonitor->ClearState();
1806 pipe.CreateVKPipeline(descriptorSet);
1807
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001808 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12001809
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001810 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12001811 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
1812 FAIL() << "Incorrect warning: " << msgString;
1813 }
1814}
Chris Forbes5af3bf22015-05-25 11:13:08 +12001815
Chris Forbes3c10b852015-05-25 11:13:13 +12001816TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
1817{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001818 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12001819 std::string msgString;
1820 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06001821 ScopedUseGlsl useGlsl(false);
Chris Forbes3c10b852015-05-25 11:13:13 +12001822
1823 char const *vsSource =
1824 "#version 140\n"
1825 "#extension GL_ARB_separate_shader_objects: require\n"
1826 "#extension GL_ARB_shading_language_420pack: require\n"
1827 "\n"
1828 "void main(){\n"
1829 " gl_Position = vec4(1);\n"
1830 "}\n";
1831 char const *fsSource =
1832 "#version 140\n"
1833 "#extension GL_ARB_separate_shader_objects: require\n"
1834 "#extension GL_ARB_shading_language_420pack: require\n"
1835 "\n"
1836 "layout(location=0) in float x;\n"
1837 "layout(location=0) out vec4 color;\n"
1838 "void main(){\n"
1839 " color = vec4(x);\n"
1840 "}\n";
1841
1842 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
1843 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
1844
1845 VkPipelineObj pipe(m_device);
1846 pipe.AddShader(&vs);
1847 pipe.AddShader(&fs);
1848
1849 VkCommandBufferObj dummyCmd(m_device);
1850 VkDescriptorSetObj descriptorSet(m_device);
1851 descriptorSet.AppendDummy();
1852 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
1853
1854 m_errorMonitor->ClearState();
1855 pipe.CreateVKPipeline(descriptorSet);
1856
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001857 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12001858
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001859 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes3c10b852015-05-25 11:13:13 +12001860 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
1861 FAIL() << "Incorrect error: " << msgString;
1862 }
1863}
1864
Chris Forbescc281692015-05-25 11:13:17 +12001865TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
1866{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001867 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12001868 std::string msgString;
1869 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06001870 ScopedUseGlsl useGlsl(false);
Chris Forbescc281692015-05-25 11:13:17 +12001871
1872 char const *vsSource =
1873 "#version 140\n"
1874 "#extension GL_ARB_separate_shader_objects: require\n"
1875 "#extension GL_ARB_shading_language_420pack: require\n"
1876 "\n"
1877 "layout(location=0) out int x;\n"
1878 "void main(){\n"
1879 " x = 0;\n"
1880 " gl_Position = vec4(1);\n"
1881 "}\n";
1882 char const *fsSource =
1883 "#version 140\n"
1884 "#extension GL_ARB_separate_shader_objects: require\n"
1885 "#extension GL_ARB_shading_language_420pack: require\n"
1886 "\n"
1887 "layout(location=0) in float x;\n" /* VS writes int */
1888 "layout(location=0) out vec4 color;\n"
1889 "void main(){\n"
1890 " color = vec4(x);\n"
1891 "}\n";
1892
1893 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
1894 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
1895
1896 VkPipelineObj pipe(m_device);
1897 pipe.AddShader(&vs);
1898 pipe.AddShader(&fs);
1899
1900 VkCommandBufferObj dummyCmd(m_device);
1901 VkDescriptorSetObj descriptorSet(m_device);
1902 descriptorSet.AppendDummy();
1903 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
1904
1905 m_errorMonitor->ClearState();
1906 pipe.CreateVKPipeline(descriptorSet);
1907
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001908 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12001909
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001910 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbescc281692015-05-25 11:13:17 +12001911 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
1912 FAIL() << "Incorrect error: " << msgString;
1913 }
1914}
1915
Chris Forbes8291c052015-05-25 11:13:28 +12001916TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
1917{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001918 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12001919 std::string msgString;
1920 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06001921 ScopedUseGlsl useGlsl(false);
Chris Forbes8291c052015-05-25 11:13:28 +12001922
1923 VkVertexInputBindingDescription input_binding;
1924 memset(&input_binding, 0, sizeof(input_binding));
1925
1926 VkVertexInputAttributeDescription input_attrib;
1927 memset(&input_attrib, 0, sizeof(input_attrib));
1928 input_attrib.format = VK_FORMAT_R32_SFLOAT;
1929
1930 char const *vsSource =
1931 "#version 140\n"
1932 "#extension GL_ARB_separate_shader_objects: require\n"
1933 "#extension GL_ARB_shading_language_420pack: require\n"
1934 "\n"
1935 "void main(){\n"
1936 " gl_Position = vec4(1);\n"
1937 "}\n";
1938 char const *fsSource =
1939 "#version 140\n"
1940 "#extension GL_ARB_separate_shader_objects: require\n"
1941 "#extension GL_ARB_shading_language_420pack: require\n"
1942 "\n"
1943 "layout(location=0) out vec4 color;\n"
1944 "void main(){\n"
1945 " color = vec4(1);\n"
1946 "}\n";
1947
1948 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
1949 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
1950
1951 VkPipelineObj pipe(m_device);
1952 pipe.AddShader(&vs);
1953 pipe.AddShader(&fs);
1954
1955 pipe.AddVertexInputBindings(&input_binding, 1);
1956 pipe.AddVertexInputAttribs(&input_attrib, 1);
1957
1958 VkCommandBufferObj dummyCmd(m_device);
1959 VkDescriptorSetObj descriptorSet(m_device);
1960 descriptorSet.AppendDummy();
1961 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
1962
1963 m_errorMonitor->ClearState();
1964 pipe.CreateVKPipeline(descriptorSet);
1965
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001966 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12001967
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001968 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12001969 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
1970 FAIL() << "Incorrect warning: " << msgString;
1971 }
1972}
1973
Chris Forbes37367e62015-05-25 11:13:29 +12001974TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
1975{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001976 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12001977 std::string msgString;
1978 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06001979 ScopedUseGlsl useGlsl(false);
Chris Forbes37367e62015-05-25 11:13:29 +12001980
1981 char const *vsSource =
1982 "#version 140\n"
1983 "#extension GL_ARB_separate_shader_objects: require\n"
1984 "#extension GL_ARB_shading_language_420pack: require\n"
1985 "\n"
1986 "layout(location=0) in vec4 x;\n" /* not provided */
1987 "void main(){\n"
1988 " gl_Position = x;\n"
1989 "}\n";
1990 char const *fsSource =
1991 "#version 140\n"
1992 "#extension GL_ARB_separate_shader_objects: require\n"
1993 "#extension GL_ARB_shading_language_420pack: require\n"
1994 "\n"
1995 "layout(location=0) out vec4 color;\n"
1996 "void main(){\n"
1997 " color = vec4(1);\n"
1998 "}\n";
1999
2000 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2001 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2002
2003 VkPipelineObj pipe(m_device);
2004 pipe.AddShader(&vs);
2005 pipe.AddShader(&fs);
2006
2007 VkCommandBufferObj dummyCmd(m_device);
2008 VkDescriptorSetObj descriptorSet(m_device);
2009 descriptorSet.AppendDummy();
2010 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2011
2012 m_errorMonitor->ClearState();
2013 pipe.CreateVKPipeline(descriptorSet);
2014
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002015 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12002016
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002017 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes37367e62015-05-25 11:13:29 +12002018 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
2019 FAIL() << "Incorrect warning: " << msgString;
2020 }
2021}
2022
Chris Forbesa4b02322015-05-25 11:13:31 +12002023TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
2024{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002025 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12002026 std::string msgString;
2027 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002028 ScopedUseGlsl useGlsl(false);
Chris Forbesa4b02322015-05-25 11:13:31 +12002029
2030 VkVertexInputBindingDescription input_binding;
2031 memset(&input_binding, 0, sizeof(input_binding));
2032
2033 VkVertexInputAttributeDescription input_attrib;
2034 memset(&input_attrib, 0, sizeof(input_attrib));
2035 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2036
2037 char const *vsSource =
2038 "#version 140\n"
2039 "#extension GL_ARB_separate_shader_objects: require\n"
2040 "#extension GL_ARB_shading_language_420pack: require\n"
2041 "\n"
2042 "layout(location=0) in int x;\n" /* attrib provided float */
2043 "void main(){\n"
2044 " gl_Position = vec4(x);\n"
2045 "}\n";
2046 char const *fsSource =
2047 "#version 140\n"
2048 "#extension GL_ARB_separate_shader_objects: require\n"
2049 "#extension GL_ARB_shading_language_420pack: require\n"
2050 "\n"
2051 "layout(location=0) out vec4 color;\n"
2052 "void main(){\n"
2053 " color = vec4(1);\n"
2054 "}\n";
2055
2056 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2057 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2058
2059 VkPipelineObj pipe(m_device);
2060 pipe.AddShader(&vs);
2061 pipe.AddShader(&fs);
2062
2063 pipe.AddVertexInputBindings(&input_binding, 1);
2064 pipe.AddVertexInputAttribs(&input_attrib, 1);
2065
2066 VkCommandBufferObj dummyCmd(m_device);
2067 VkDescriptorSetObj descriptorSet(m_device);
2068 descriptorSet.AppendDummy();
2069 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2070
2071 m_errorMonitor->ClearState();
2072 pipe.CreateVKPipeline(descriptorSet);
2073
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002074 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12002075
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002076 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbesa4b02322015-05-25 11:13:31 +12002077 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
2078 FAIL() << "Incorrect error: " << msgString;
2079 }
2080}
2081
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002082TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
2083{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002084 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002085 std::string msgString;
2086 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002087 ScopedUseGlsl useGlsl(false);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002088
2089 /* Two binding descriptions for binding 0 */
2090 VkVertexInputBindingDescription input_bindings[2];
2091 memset(input_bindings, 0, sizeof(input_bindings));
2092
2093 VkVertexInputAttributeDescription input_attrib;
2094 memset(&input_attrib, 0, sizeof(input_attrib));
2095 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2096
2097 char const *vsSource =
2098 "#version 140\n"
2099 "#extension GL_ARB_separate_shader_objects: require\n"
2100 "#extension GL_ARB_shading_language_420pack: require\n"
2101 "\n"
2102 "layout(location=0) in float x;\n" /* attrib provided float */
2103 "void main(){\n"
2104 " gl_Position = vec4(x);\n"
2105 "}\n";
2106 char const *fsSource =
2107 "#version 140\n"
2108 "#extension GL_ARB_separate_shader_objects: require\n"
2109 "#extension GL_ARB_shading_language_420pack: require\n"
2110 "\n"
2111 "layout(location=0) out vec4 color;\n"
2112 "void main(){\n"
2113 " color = vec4(1);\n"
2114 "}\n";
2115
2116 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2117 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2118
2119 VkPipelineObj pipe(m_device);
2120 pipe.AddShader(&vs);
2121 pipe.AddShader(&fs);
2122
2123 pipe.AddVertexInputBindings(input_bindings, 2);
2124 pipe.AddVertexInputAttribs(&input_attrib, 1);
2125
2126 VkCommandBufferObj dummyCmd(m_device);
2127 VkDescriptorSetObj descriptorSet(m_device);
2128 descriptorSet.AppendDummy();
2129 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2130
2131 m_errorMonitor->ClearState();
2132 pipe.CreateVKPipeline(descriptorSet);
2133
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002134 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002135
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002136 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002137 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
2138 FAIL() << "Incorrect error: " << msgString;
2139 }
2140}
Chris Forbes4c948702015-05-25 11:13:32 +12002141
Chris Forbesc12ef122015-05-25 11:13:40 +12002142/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
2143 * rejects it. */
2144
2145TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
2146{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002147 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12002148 std::string msgString;
2149 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002150 ScopedUseGlsl useGlsl(false);
Chris Forbesc12ef122015-05-25 11:13:40 +12002151
2152 char const *vsSource =
2153 "#version 140\n"
2154 "#extension GL_ARB_separate_shader_objects: require\n"
2155 "#extension GL_ARB_shading_language_420pack: require\n"
2156 "\n"
2157 "void main(){\n"
2158 " gl_Position = vec4(1);\n"
2159 "}\n";
2160 char const *fsSource =
2161 "#version 140\n"
2162 "#extension GL_ARB_separate_shader_objects: require\n"
2163 "#extension GL_ARB_shading_language_420pack: require\n"
2164 "\n"
2165 "void main(){\n"
2166 "}\n";
2167
2168 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2169 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2170
2171 VkPipelineObj pipe(m_device);
2172 pipe.AddShader(&vs);
2173 pipe.AddShader(&fs);
2174
2175 /* implicit CB 0 set up by the test framework, not written */
2176
2177 VkCommandBufferObj dummyCmd(m_device);
2178 VkDescriptorSetObj descriptorSet(m_device);
2179 descriptorSet.AppendDummy();
2180 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2181
2182 m_errorMonitor->ClearState();
2183 pipe.CreateVKPipeline(descriptorSet);
2184
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002185 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12002186
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002187 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbesc12ef122015-05-25 11:13:40 +12002188 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
2189 FAIL() << "Incorrect error: " << msgString;
2190 }
2191}
2192
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002193TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
2194{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002195 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002196 std::string msgString;
2197 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002198 ScopedUseGlsl useGlsl(false);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002199
2200 char const *vsSource =
2201 "#version 140\n"
2202 "#extension GL_ARB_separate_shader_objects: require\n"
2203 "#extension GL_ARB_shading_language_420pack: require\n"
2204 "\n"
2205 "void main(){\n"
2206 " gl_Position = vec4(1);\n"
2207 "}\n";
2208 char const *fsSource =
2209 "#version 140\n"
2210 "#extension GL_ARB_separate_shader_objects: require\n"
2211 "#extension GL_ARB_shading_language_420pack: require\n"
2212 "\n"
2213 "layout(location=0) out vec4 x;\n"
2214 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
2215 "void main(){\n"
2216 " x = vec4(1);\n"
2217 " y = vec4(1);\n"
2218 "}\n";
2219
2220 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2221 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2222
2223 VkPipelineObj pipe(m_device);
2224 pipe.AddShader(&vs);
2225 pipe.AddShader(&fs);
2226
2227 /* implicit CB 0 set up by the test framework */
2228 /* FS writes CB 1, but we don't configure it */
2229
2230 VkCommandBufferObj dummyCmd(m_device);
2231 VkDescriptorSetObj descriptorSet(m_device);
2232 descriptorSet.AppendDummy();
2233 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2234
2235 m_errorMonitor->ClearState();
2236 pipe.CreateVKPipeline(descriptorSet);
2237
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002238 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002239
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002240 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002241 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
2242 FAIL() << "Incorrect warning: " << msgString;
2243 }
2244}
2245
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002246TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
2247{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002248 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002249 std::string msgString;
2250 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002251 ScopedUseGlsl useGlsl(false);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002252
2253 char const *vsSource =
2254 "#version 140\n"
2255 "#extension GL_ARB_separate_shader_objects: require\n"
2256 "#extension GL_ARB_shading_language_420pack: require\n"
2257 "\n"
2258 "void main(){\n"
2259 " gl_Position = vec4(1);\n"
2260 "}\n";
2261 char const *fsSource =
2262 "#version 140\n"
2263 "#extension GL_ARB_separate_shader_objects: require\n"
2264 "#extension GL_ARB_shading_language_420pack: require\n"
2265 "\n"
2266 "layout(location=0) out ivec4 x;\n" /* not UNORM */
2267 "void main(){\n"
2268 " x = ivec4(1);\n"
2269 "}\n";
2270
2271 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2272 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2273
2274 VkPipelineObj pipe(m_device);
2275 pipe.AddShader(&vs);
2276 pipe.AddShader(&fs);
2277
2278 /* implicit CB 0 set up by test framework, is UNORM. */
2279
2280 VkCommandBufferObj dummyCmd(m_device);
2281 VkDescriptorSetObj descriptorSet(m_device);
2282 descriptorSet.AppendDummy();
2283 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2284
2285 m_errorMonitor->ClearState();
2286 pipe.CreateVKPipeline(descriptorSet);
2287
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002288 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002289
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002290 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002291 if (!strstr(msgString.c_str(),"does not match FS output type")) {
2292 FAIL() << "Incorrect error: " << msgString;
2293 }
2294}
Chris Forbesc2050732015-06-05 14:43:36 +12002295
2296TEST_F(VkLayerTest, CreatePipelineNonSpirvShader)
2297{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002298 VkFlags msgFlags;
Chris Forbesc2050732015-06-05 14:43:36 +12002299 std::string msgString;
2300 ASSERT_NO_FATAL_FAILURE(InitState());
2301 /* Intentionally provided GLSL rather than compiling to SPIRV first */
Cody Northrop1cfbd172015-06-03 16:49:20 -06002302 ScopedUseGlsl useGlsl(true);
Chris Forbesc2050732015-06-05 14:43:36 +12002303
2304 char const *vsSource =
2305 "#version 140\n"
2306 "#extension GL_ARB_separate_shader_objects: require\n"
2307 "#extension GL_ARB_shading_language_420pack: require\n"
2308 "\n"
2309 "void main(){\n"
2310 " gl_Position = vec4(1);\n"
2311 "}\n";
2312 char const *fsSource =
2313 "#version 140\n"
2314 "#extension GL_ARB_separate_shader_objects: require\n"
2315 "#extension GL_ARB_shading_language_420pack: require\n"
2316 "\n"
2317 "layout(location=0) out vec4 x;\n"
2318 "void main(){\n"
2319 " x = vec4(1);\n"
2320 "}\n";
2321
2322 m_errorMonitor->ClearState();
2323
2324 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2325 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2326
2327
2328 VkPipelineObj pipe(m_device);
2329 pipe.AddShader(&vs);
2330 pipe.AddShader(&fs);
2331
2332 /* implicit CB 0 set up by test framework, is UNORM. */
2333
2334 VkCommandBufferObj dummyCmd(m_device);
2335 VkDescriptorSetObj descriptorSet(m_device);
2336 descriptorSet.AppendDummy();
2337 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2338
2339 VkResult res = pipe.CreateVKPipeline(descriptorSet);
2340 /* pipeline creation should have succeeded */
2341 ASSERT_EQ(VK_SUCCESS, res);
2342
2343 /* should have emitted a warning: the shader is not SPIRV, so we're
2344 * not going to be able to analyze it */
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002345 msgFlags = m_errorMonitor->GetState(&msgString);
2346 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesc2050732015-06-05 14:43:36 +12002347 if (!strstr(msgString.c_str(),"is not SPIR-V")) {
2348 FAIL() << "Incorrect warning: " << msgString;
2349 }
2350}
Chris Forbes01c9db72015-06-04 09:25:25 +12002351#endif
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002352
Tony Barbour30486ea2015-04-07 13:44:53 -06002353int main(int argc, char **argv) {
2354 int result;
2355
2356 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06002357 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06002358
2359 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
2360
2361 result = RUN_ALL_TESTS();
2362
Tony Barbour01999182015-04-09 12:58:51 -06002363 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06002364 return result;
2365}