blob: 16b0fa916ac1e953bc8cc3d67f87cb1c34306aae [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");
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600162 instance_extension_names.push_back("ObjectTracker");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600163 instance_extension_names.push_back("MemTracker");
Courtney Goeltzenleuchtereb518dc2015-06-13 21:41:00 -0600164 instance_extension_names.push_back("DrawState");
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");
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600168 device_extension_names.push_back("ObjectTracker");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600169 device_extension_names.push_back("MemTracker");
Jon Ashburn64716542015-06-15 12:21:02 -0600170 device_extension_names.push_back("DrawState");
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 }
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600308 // Make sure depthWriteEnable is set so that DepthStencil fail test will work correctly
309 VkStencilOpState stencil = {
310 .stencilFailOp = VK_STENCIL_OP_KEEP,
311 .stencilPassOp = VK_STENCIL_OP_KEEP,
312 .stencilDepthFailOp = VK_STENCIL_OP_KEEP,
313 .stencilCompareOp = VK_COMPARE_OP_NEVER
314 };
315 VkPipelineDsStateCreateInfo ds_ci = {
316 .sType = VK_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO,
317 .pNext = NULL,
318 .format = VK_FORMAT_D24_UNORM_S8_UINT,
319 .depthTestEnable = VK_FALSE,
320 .depthWriteEnable = VK_TRUE,
321 .depthCompareOp = VK_COMPARE_OP_NEVER,
322 .depthBoundsEnable = VK_FALSE,
323 .stencilTestEnable = VK_FALSE,
324 .front = stencil,
325 .back = stencil
326 };
327 pipelineobj.SetDepthStencil(&ds_ci);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500328 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
329 pipelineobj.CreateVKPipeline(descriptorSet);
330 cmdBuffer->BindPipeline(pipelineobj);
331 cmdBuffer->BindDescriptorSet(descriptorSet);
332}
333
334// ********************************************************************************************************************
335// ********************************************************************************************************************
336// ********************************************************************************************************************
337// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600338#if MEM_TRACKER_TESTS
Mark Lobodzinski81078192015-05-19 10:28:29 -0500339TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
340{
341 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600342 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500343 std::string msgString;
344
345 VkFenceCreateInfo fenceInfo = {};
346 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
347 fenceInfo.pNext = NULL;
348 fenceInfo.flags = 0;
349
350 ASSERT_NO_FATAL_FAILURE(InitState());
351 ASSERT_NO_FATAL_FAILURE(InitViewport());
352 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
353
354 VkCommandBufferObj cmdBuffer(m_device);
355 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
356
357 BeginCommandBuffer(cmdBuffer);
358 cmdBuffer.ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
359 EndCommandBuffer(cmdBuffer);
360
361 testFence.init(*m_device, fenceInfo);
362
363 // Bypass framework since it does the waits automatically
364 VkResult err = VK_SUCCESS;
365 err = vkQueueSubmit( m_device->m_queue, 1, &cmdBuffer.obj(), testFence.obj());
366 ASSERT_VK_SUCCESS( err );
367
368 m_errorMonitor->ClearState();
369 // Introduce failure by calling begin again before checking fence
370 vkResetCommandBuffer(cmdBuffer.obj());
371
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600372 msgFlags = m_errorMonitor->GetState(&msgString);
373 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 -0500374 if (!strstr(msgString.c_str(),"Resetting CB")) {
375 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
376 }
377}
378
379TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion)
380{
381 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600382 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500383 std::string msgString;
384
385 VkFenceCreateInfo fenceInfo = {};
386 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
387 fenceInfo.pNext = NULL;
388 fenceInfo.flags = 0;
389
390 ASSERT_NO_FATAL_FAILURE(InitState());
391 ASSERT_NO_FATAL_FAILURE(InitViewport());
392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
393
394 VkCommandBufferObj cmdBuffer(m_device);
395 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
396
397 BeginCommandBuffer(cmdBuffer);
398 cmdBuffer.ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
399 EndCommandBuffer(cmdBuffer);
400
401 testFence.init(*m_device, fenceInfo);
402
403 // Bypass framework since it does the waits automatically
404 VkResult err = VK_SUCCESS;
405 err = vkQueueSubmit( m_device->m_queue, 1, &cmdBuffer.obj(), testFence.obj());
406 ASSERT_VK_SUCCESS( err );
407
408 m_errorMonitor->ClearState();
409 // Introduce failure by calling begin again before checking fence
410 BeginCommandBuffer(cmdBuffer);
411
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600412 msgFlags = m_errorMonitor->GetState(&msgString);
413 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 -0500414 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
415 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
416 }
417}
418
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500419TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
420{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600421 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500422 std::string msgString;
423 VkResult err;
424
425 ASSERT_NO_FATAL_FAILURE(InitState());
426 m_errorMonitor->ClearState();
427
428 // Create an image, allocate memory, free it, and then try to bind it
429 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500430 VkDeviceMemory mem;
431 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500432
433 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
434 const int32_t tex_width = 32;
435 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500436
437 const VkImageCreateInfo image_create_info = {
438 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
439 .pNext = NULL,
440 .imageType = VK_IMAGE_TYPE_2D,
441 .format = tex_format,
442 .extent = { tex_width, tex_height, 1 },
443 .mipLevels = 1,
444 .arraySize = 1,
445 .samples = 1,
446 .tiling = VK_IMAGE_TILING_LINEAR,
447 .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
448 .flags = 0,
449 };
450 VkMemoryAllocInfo mem_alloc = {
451 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
452 .pNext = NULL,
453 .allocationSize = 0,
454 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
455 .memProps = 0,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500456 };
457
458 err = vkCreateImage(m_device->device(), &image_create_info, &image);
459 ASSERT_VK_SUCCESS(err);
460
Tony Barbour426b9052015-06-24 16:06:58 -0600461 err = vkGetObjectMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500462 VK_OBJECT_TYPE_IMAGE,
463 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500464 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500465 ASSERT_VK_SUCCESS(err);
466
Mark Lobodzinski23182612015-05-29 09:32:35 -0500467 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500468
469 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500470 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500471 ASSERT_VK_SUCCESS(err);
472
473 // Try to bind free memory that has been freed
Mark Lobodzinski23182612015-05-29 09:32:35 -0500474 err = vkBindObjectMemory(m_device->device(), VK_OBJECT_TYPE_IMAGE, image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500475 ASSERT_VK_SUCCESS(err);
476
477 // Map memory as if to initialize the image
478 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500479 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500480
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600481 msgFlags = m_errorMonitor->GetState(&msgString);
482 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 -0500483 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
484 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
485 }
486}
487
488TEST_F(VkLayerTest, BindInvalidMemory)
489{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600490 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500491 std::string msgString;
492 VkResult err;
493
494 ASSERT_NO_FATAL_FAILURE(InitState());
495 m_errorMonitor->ClearState();
496
497 // Create an image, allocate memory, free it, and then try to bind it
498 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500499 VkDeviceMemory mem;
500 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500501
502 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
503 const int32_t tex_width = 32;
504 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500505
506 const VkImageCreateInfo image_create_info = {
507 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
508 .pNext = NULL,
509 .imageType = VK_IMAGE_TYPE_2D,
510 .format = tex_format,
511 .extent = { tex_width, tex_height, 1 },
512 .mipLevels = 1,
513 .arraySize = 1,
514 .samples = 1,
515 .tiling = VK_IMAGE_TILING_LINEAR,
516 .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
517 .flags = 0,
518 };
519 VkMemoryAllocInfo mem_alloc = {
520 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
521 .pNext = NULL,
522 .allocationSize = 0,
523 .memProps = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500524 };
525
526 err = vkCreateImage(m_device->device(), &image_create_info, &image);
527 ASSERT_VK_SUCCESS(err);
528
Tony Barbour426b9052015-06-24 16:06:58 -0600529 err = vkGetObjectMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500530 VK_OBJECT_TYPE_IMAGE,
531 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500532 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500533 ASSERT_VK_SUCCESS(err);
534
Mark Lobodzinski23182612015-05-29 09:32:35 -0500535 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500536
537 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500538 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500539 ASSERT_VK_SUCCESS(err);
540
541 // Introduce validation failure, free memory before binding
Mark Lobodzinski23182612015-05-29 09:32:35 -0500542 vkFreeMemory(m_device->device(), mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500543 ASSERT_VK_SUCCESS(err);
544
545 // Try to bind free memory that has been freed
Mark Lobodzinski23182612015-05-29 09:32:35 -0500546 err = vkBindObjectMemory(m_device->device(), VK_OBJECT_TYPE_IMAGE, image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500547 ASSERT_VK_SUCCESS(err);
548
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600549 msgFlags = m_errorMonitor->GetState(&msgString);
550 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 -0500551 if (!strstr(msgString.c_str(),"couldn't find info for mem obj")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500552 FAIL() << "Error received did not match expected error message from BindObjectMemory in MemTracker";
553 }
554}
555
556TEST_F(VkLayerTest, FreeBoundMemory)
557{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600558 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500559 std::string msgString;
560 VkResult err;
561
562 ASSERT_NO_FATAL_FAILURE(InitState());
563 m_errorMonitor->ClearState();
564
565 // Create an image, allocate memory, free it, and then try to bind it
566 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500567 VkDeviceMemory mem;
568 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500569
570 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
571 const int32_t tex_width = 32;
572 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500573
574 const VkImageCreateInfo image_create_info = {
575 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
576 .pNext = NULL,
577 .imageType = VK_IMAGE_TYPE_2D,
578 .format = tex_format,
579 .extent = { tex_width, tex_height, 1 },
580 .mipLevels = 1,
581 .arraySize = 1,
582 .samples = 1,
583 .tiling = VK_IMAGE_TILING_LINEAR,
584 .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
585 .flags = 0,
586 };
587 VkMemoryAllocInfo mem_alloc = {
588 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
589 .pNext = NULL,
590 .allocationSize = 0,
591 .memProps = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500592 };
593
594 err = vkCreateImage(m_device->device(), &image_create_info, &image);
595 ASSERT_VK_SUCCESS(err);
596
Tony Barbour426b9052015-06-24 16:06:58 -0600597 err = vkGetObjectMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500598 VK_OBJECT_TYPE_IMAGE,
599 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500600 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500601 ASSERT_VK_SUCCESS(err);
602
Mark Lobodzinski23182612015-05-29 09:32:35 -0500603 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500604
605 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500606 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500607 ASSERT_VK_SUCCESS(err);
608
609 // Bind memory to Image object
Mark Lobodzinski23182612015-05-29 09:32:35 -0500610 err = vkBindObjectMemory(m_device->device(), VK_OBJECT_TYPE_IMAGE, image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500611 ASSERT_VK_SUCCESS(err);
612
613 // Introduce validation failure, free memory while still bound to object
Mark Lobodzinski23182612015-05-29 09:32:35 -0500614 vkFreeMemory(m_device->device(), mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500615 ASSERT_VK_SUCCESS(err);
616
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600617 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter7dc4c8b2015-06-13 21:48:47 -0600618 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 -0500619 if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
620 FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
621 }
622}
623
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500624TEST_F(VkLayerTest, RebindMemory)
625{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600626 VkFlags msgFlags;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500627 std::string msgString;
628 VkResult err;
629
630 ASSERT_NO_FATAL_FAILURE(InitState());
631 m_errorMonitor->ClearState();
632
633 // Create an image, allocate memory, free it, and then try to bind it
634 VkImage image;
635 VkDeviceMemory mem1;
636 VkDeviceMemory mem2;
637 VkMemoryRequirements mem_reqs;
638
639 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
640 const int32_t tex_width = 32;
641 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500642
643 const VkImageCreateInfo image_create_info = {
644 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
645 .pNext = NULL,
646 .imageType = VK_IMAGE_TYPE_2D,
647 .format = tex_format,
648 .extent = { tex_width, tex_height, 1 },
649 .mipLevels = 1,
650 .arraySize = 1,
651 .samples = 1,
652 .tiling = VK_IMAGE_TILING_LINEAR,
653 .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
654 .flags = 0,
655 };
656 VkMemoryAllocInfo mem_alloc = {
657 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
658 .pNext = NULL,
659 .allocationSize = 0,
660 .memProps = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500661 };
662
663 err = vkCreateImage(m_device->device(), &image_create_info, &image);
664 ASSERT_VK_SUCCESS(err);
665
Tony Barbour426b9052015-06-24 16:06:58 -0600666 err = vkGetObjectMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500667 VK_OBJECT_TYPE_IMAGE,
668 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500669 &mem_reqs);
670 ASSERT_VK_SUCCESS(err);
671
672 mem_alloc.allocationSize = mem_reqs.size;
673
674 // allocate 2 memory objects
675 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
676 ASSERT_VK_SUCCESS(err);
677 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
678 ASSERT_VK_SUCCESS(err);
679
680 // Bind first memory object to Image object
681 err = vkBindObjectMemory(m_device->device(), VK_OBJECT_TYPE_IMAGE, image, mem1, 0);
682 ASSERT_VK_SUCCESS(err);
683
684 // Introduce validation failure, try to bind a different memory object to the same image object
685 err = vkBindObjectMemory(m_device->device(), VK_OBJECT_TYPE_IMAGE, image, mem2, 0);
686 ASSERT_VK_SUCCESS(err);
687
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600688 msgFlags = m_errorMonitor->GetState(&msgString);
689 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 -0500690 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
691 FAIL() << "Error received did not match expected message when rebinding memory to an object";
692 }
693}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500694
695TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
696{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600697 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500698 std::string msgString;
699 VkResult err;
700
701 ASSERT_NO_FATAL_FAILURE(InitState());
702 m_errorMonitor->ClearState();
703
704 // Create an image object, allocate memory, destroy the object and then try to bind it
705 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500706 VkDeviceMemory mem;
707 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500708
709 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
710 const int32_t tex_width = 32;
711 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500712
713 const VkImageCreateInfo image_create_info = {
714 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
715 .pNext = NULL,
716 .imageType = VK_IMAGE_TYPE_2D,
717 .format = tex_format,
718 .extent = { tex_width, tex_height, 1 },
719 .mipLevels = 1,
720 .arraySize = 1,
721 .samples = 1,
722 .tiling = VK_IMAGE_TILING_LINEAR,
723 .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
724 .flags = 0,
725 };
726 VkMemoryAllocInfo mem_alloc = {
727 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
728 .pNext = NULL,
729 .allocationSize = 0,
730 .memProps = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500731 };
732
733 err = vkCreateImage(m_device->device(), &image_create_info, &image);
734 ASSERT_VK_SUCCESS(err);
735
Tony Barbour426b9052015-06-24 16:06:58 -0600736 err = vkGetObjectMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500737 VK_OBJECT_TYPE_IMAGE,
738 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500739 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500740 ASSERT_VK_SUCCESS(err);
741
Mark Lobodzinski23182612015-05-29 09:32:35 -0500742 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500743
744 // Allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500745 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500746 ASSERT_VK_SUCCESS(err);
747
748 // Introduce validation failure, destroy Image object before binding
749 vkDestroyObject(m_device->device(), VK_OBJECT_TYPE_IMAGE, image);
750 ASSERT_VK_SUCCESS(err);
751
752 // Now Try to bind memory to this destroyted object
Mark Lobodzinski23182612015-05-29 09:32:35 -0500753 err = vkBindObjectMemory(m_device->device(), VK_OBJECT_TYPE_IMAGE, image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500754 ASSERT_VK_SUCCESS(err);
755
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600756 msgFlags = m_errorMonitor->GetState(&msgString);
757 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 -0500758 if (!strstr(msgString.c_str(),"that's not in global list")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500759 FAIL() << "Error received did not match expected error message from updateObjectBinding in MemTracker";
760 }
761}
762
Tony Barbour8508b8e2015-04-09 10:48:04 -0600763TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600764{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600765 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600766 VkFlags msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600767 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600768
769 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600770 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
771 fenceInfo.pNext = NULL;
772 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600773
Tony Barbour30486ea2015-04-07 13:44:53 -0600774 ASSERT_NO_FATAL_FAILURE(InitState());
775 ASSERT_NO_FATAL_FAILURE(InitViewport());
776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
777
Tony Barbour01999182015-04-09 12:58:51 -0600778 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour30486ea2015-04-07 13:44:53 -0600779 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
780
Tony Barbour8508b8e2015-04-09 10:48:04 -0600781 BeginCommandBuffer(cmdBuffer);
Tony Barbour30486ea2015-04-07 13:44:53 -0600782 cmdBuffer.ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour8508b8e2015-04-09 10:48:04 -0600783 EndCommandBuffer(cmdBuffer);
Tony Barbour30486ea2015-04-07 13:44:53 -0600784
785 testFence.init(*m_device, fenceInfo);
786 m_errorMonitor->ClearState();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600787 cmdBuffer.QueueCommandBuffer(testFence.obj());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600788 msgFlags = m_errorMonitor->GetState(&msgString);
789 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 -0600790 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500791 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600792 }
793
794}
795
796TEST_F(VkLayerTest, ResetUnsignaledFence)
797{
798 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600799 VkFlags msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600800 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600801 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600802 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
803 fenceInfo.pNext = NULL;
804
Tony Barbour8508b8e2015-04-09 10:48:04 -0600805 ASSERT_NO_FATAL_FAILURE(InitState());
806 testFence.init(*m_device, fenceInfo);
807 m_errorMonitor->ClearState();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600808 VkFence fences[1] = {testFence.obj()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600809 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600810 msgFlags = m_errorMonitor->GetState(&msgString);
811 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 -0600812 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500813 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600814 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600815
816}
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600817#endif
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600818#if OBJ_TRACKER_TESTS
Tony Barbour54cdd192015-04-22 15:12:07 -0600819
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500820TEST_F(VkLayerTest, RasterStateNotBound)
821{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600822 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500823 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600824 ASSERT_NO_FATAL_FAILURE(InitState());
825 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500826 TEST_DESCRIPTION("Simple Draw Call that validates failure when a raster state object is not bound beforehand");
827
828 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailRaster);
829
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600830 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600831 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error from Not Binding a Raster State Object";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500832 if (!strstr(msgString.c_str(),"Raster object not bound to this command buffer")) {
833 FAIL() << "Error received was not 'Raster object not bound to this command buffer'";
834 }
835}
836
837TEST_F(VkLayerTest, ViewportStateNotBound)
838{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600839 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500840 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600841 ASSERT_NO_FATAL_FAILURE(InitState());
842 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500843 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
844
845 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
846
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600847 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600848 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error from Not Binding a Viewport State Object";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500849 if (!strstr(msgString.c_str(),"Viewport object not bound to this command buffer")) {
850 FAIL() << "Error received was not 'Viewport object not bound to this command buffer'";
851 }
852}
853
854TEST_F(VkLayerTest, ColorBlendStateNotBound)
855{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600856 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500857 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600858 ASSERT_NO_FATAL_FAILURE(InitState());
859 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500860 TEST_DESCRIPTION("Simple Draw Call that validates failure when a color-blend state object is not bound beforehand");
861
862 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailColorBlend);
863
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600864 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600865 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error from Not Binding a ColorBlend State Object";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500866 if (!strstr(msgString.c_str(),"Color-blend object not bound to this command buffer")) {
867 FAIL() << "Error received was not 'Color-blend object not bound to this command buffer'";
868 }
869}
870
871TEST_F(VkLayerTest, DepthStencilStateNotBound)
872{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600873 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500874 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600875 ASSERT_NO_FATAL_FAILURE(InitState());
876 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500877 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth-stencil state object is not bound beforehand");
878
879 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthStencil);
880
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600881 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600882 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error from Not Binding a DepthStencil State Object";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500883 if (!strstr(msgString.c_str(),"Depth-stencil object not bound to this command buffer")) {
884 FAIL() << "Error received was not 'Depth-stencil object not bound to this command buffer'";
885 }
Tony Barbourdb686622015-05-06 09:35:56 -0600886}
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600887#endif
888#if DRAW_STATE_TESTS
Tobin Ehlise4076782015-06-24 15:53:07 -0600889TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600890{
891 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600892 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600893 std::string msgString;
894
895 ASSERT_NO_FATAL_FAILURE(InitState());
896 m_errorMonitor->ClearState();
897 VkCommandBufferObj cmdBuffer(m_device);
898 BeginCommandBuffer(cmdBuffer);
899 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
900 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600901 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlise4076782015-06-24 15:53:07 -0600902 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding pipeline to CmdBuffer w/o active RenderPass";
903 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
904 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0xbaadb1be) without an active RenderPass'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600905 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600906}
907
908TEST_F(VkLayerTest, InvalidDescriptorPool)
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 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600913/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600914 std::string msgString;
915 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
916 vkResetDescriptorPool(device(), badPool);
917
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600918 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600919 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error from Resetting an invalid DescriptorPool Object";
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600920 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
921 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
922 }*/
923}
924
925TEST_F(VkLayerTest, InvalidDescriptorSet)
926{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600927 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
928 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600929 // Create a valid cmd buffer
930 // call vkCmdBindDescriptorSets w/ false DS
931}
932
933TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
934{
935 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
936 // The DS check for this is after driver has been called to validate DS internal data struct
937}
938
939TEST_F(VkLayerTest, InvalidPipeline)
940{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600941 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
942 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600943 // Create a valid cmd buffer
944 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -0600945// VkFlags msgFlags;
946// std::string msgString;
947//
948// ASSERT_NO_FATAL_FAILURE(InitState());
949// m_errorMonitor->ClearState();
950// VkCommandBufferObj cmdBuffer(m_device);
951// BeginCommandBuffer(cmdBuffer);
952// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
953// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
954// msgFlags = m_errorMonitor->GetState(&msgString);
955// ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding invalid pipeline to CmdBuffer";
956// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
957// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
958// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600959}
960
Tobin Ehlis254eca02015-06-25 15:46:59 -0600961TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600962{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600963 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600964 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600965 std::string msgString;
966 VkResult err;
967
968 ASSERT_NO_FATAL_FAILURE(InitState());
969 m_errorMonitor->ClearState();
970 VkCommandBufferObj cmdBuffer(m_device);
971 const VkDescriptorTypeCount ds_type_count = {
972 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
973 .count = 1,
974 };
975 const VkDescriptorPoolCreateInfo ds_pool_ci = {
976 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
977 .pNext = NULL,
978 .count = 1,
979 .pTypeCount = &ds_type_count,
980 };
981 VkDescriptorPool ds_pool;
982 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
983 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600984
985 const VkDescriptorSetLayoutBinding dsl_binding = {
986 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
Chia-I Wud3114a22015-05-25 16:22:52 +0800987 .arraySize = 1,
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600988 .stageFlags = VK_SHADER_STAGE_ALL,
989 .pImmutableSamplers = NULL,
990 };
991
992 const VkDescriptorSetLayoutCreateInfo ds_layout_ci = {
993 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
994 .pNext = NULL,
995 .count = 1,
996 .pBinding = &dsl_binding,
997 };
998 VkDescriptorSetLayout ds_layout;
999 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1000 ASSERT_VK_SUCCESS(err);
1001
1002 VkDescriptorSet descriptorSet;
1003 uint32_t ds_count = 0;
1004 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1005 ASSERT_VK_SUCCESS(err);
1006
1007 const VkPipelineLayoutCreateInfo pipeline_layout_ci = {
1008 .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
1009 .pNext = NULL,
1010 .descriptorSetCount = 1,
1011 .pSetLayouts = &ds_layout,
1012 };
1013
1014 VkPipelineLayout pipeline_layout;
1015 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1016 ASSERT_VK_SUCCESS(err);
1017
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001018 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001019
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001020 const VkPipelineShaderStageCreateInfo pipe_vs_ci = {
1021 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
1022 .pNext = NULL,
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001023 .stage = VK_SHADER_STAGE_VERTEX,
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001024 .shader = vs.obj(),
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001025 .linkConstBufferCount = 0,
1026 .pLinkConstBufferInfo = NULL,
1027 .pSpecializationInfo = NULL,
1028 };
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001029 const VkGraphicsPipelineCreateInfo gp_ci = {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001030 .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
1031 .pNext = NULL,
1032 .stageCount = 1,
1033 .pStages = &pipe_vs_ci,
1034 .pVertexInputState = NULL,
1035 .pIaState = NULL,
1036 .pTessState = NULL,
1037 .pVpState = NULL,
1038 .pRsState = NULL,
1039 .pMsState = NULL,
1040 .pDsState = NULL,
1041 .pCbState = NULL,
1042 .flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT,
1043 .layout = pipeline_layout,
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001044 };
1045
1046 VkPipeline pipeline;
1047 err = vkCreateGraphicsPipeline(m_device->device(), &gp_ci, &pipeline);
1048 ASSERT_VK_SUCCESS(err);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001049 ASSERT_NO_FATAL_FAILURE(InitState());
1050 ASSERT_NO_FATAL_FAILURE(InitViewport());
1051 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1052 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1053 BeginCommandBuffer(cmdBuffer);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001054 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06001055 vkCmdBindDescriptorSets(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001056
Tobin Ehlis254eca02015-06-25 15:46:59 -06001057 msgFlags = m_errorMonitor->GetState(&msgString);
1058 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not warn after binding a DescriptorSet that was never updated.";
1059 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1060 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1061 }
1062}
1063
1064TEST_F(VkLayerTest, NoBeginCmdBuffer)
1065{
1066 VkFlags msgFlags;
1067 std::string msgString;
1068
1069 ASSERT_NO_FATAL_FAILURE(InitState());
1070 m_errorMonitor->ClearState();
1071 VkCommandBufferObj cmdBuffer(m_device);
1072 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1073 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1074 msgFlags = m_errorMonitor->GetState(&msgString);
1075 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after ending a CmdBuffer w/o calling BeginCommandBuffer()";
1076 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1077 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1078 }
1079}
1080
1081TEST_F(VkLayerTest, InvalidPipelineCreateState)
1082{
1083 // Attempt to Create Gfx Pipeline w/o a VS
1084 VkFlags msgFlags;
1085 std::string msgString;
1086 VkResult err;
1087
1088 ASSERT_NO_FATAL_FAILURE(InitState());
1089 m_errorMonitor->ClearState();
1090 VkCommandBufferObj cmdBuffer(m_device);
1091 const VkDescriptorTypeCount ds_type_count = {
1092 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1093 .count = 1,
1094 };
1095 const VkDescriptorPoolCreateInfo ds_pool_ci = {
1096 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
1097 .pNext = NULL,
1098 .count = 1,
1099 .pTypeCount = &ds_type_count,
1100 };
1101 VkDescriptorPool ds_pool;
1102 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1103 ASSERT_VK_SUCCESS(err);
1104
1105 const VkDescriptorSetLayoutBinding dsl_binding = {
1106 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1107 .arraySize = 1,
1108 .stageFlags = VK_SHADER_STAGE_ALL,
1109 .pImmutableSamplers = NULL,
1110 };
1111
1112 const VkDescriptorSetLayoutCreateInfo ds_layout_ci = {
1113 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
1114 .pNext = NULL,
1115 .count = 1,
1116 .pBinding = &dsl_binding,
1117 };
1118 VkDescriptorSetLayout ds_layout;
1119 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1120 ASSERT_VK_SUCCESS(err);
1121
1122 VkDescriptorSet descriptorSet;
1123 uint32_t ds_count = 0;
1124 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1125 ASSERT_VK_SUCCESS(err);
1126
1127 const VkPipelineLayoutCreateInfo pipeline_layout_ci = {
1128 .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
1129 .pNext = NULL,
1130 .descriptorSetCount = 1,
1131 .pSetLayouts = &ds_layout,
1132 };
1133
1134 VkPipelineLayout pipeline_layout;
1135 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1136 ASSERT_VK_SUCCESS(err);
1137
1138 const VkGraphicsPipelineCreateInfo gp_ci = {
1139 .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
1140 .pNext = NULL,
1141 .stageCount = 0,
1142 .pStages = NULL, // Creating Gfx Pipeline w/o VS is a violation
1143 .pVertexInputState = NULL,
1144 .pIaState = NULL,
1145 .pTessState = NULL,
1146 .pVpState = NULL,
1147 .pRsState = NULL,
1148 .pMsState = NULL,
1149 .pDsState = NULL,
1150 .pCbState = NULL,
1151 .flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT,
1152 .layout = pipeline_layout,
1153 };
1154
1155 VkPipeline pipeline;
1156 err = vkCreateGraphicsPipeline(m_device->device(), &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001157
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001158 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001159 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after creating Gfx Pipeline w/o VS.";
1160 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1161 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1162 }
1163}
1164
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001165TEST_F(VkLayerTest, NullRenderPass)
1166{
1167 // Bind a NULL RenderPass
1168 VkFlags msgFlags;
1169 std::string msgString;
1170
1171 ASSERT_NO_FATAL_FAILURE(InitState());
1172 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1173 m_errorMonitor->ClearState();
1174 VkCommandBufferObj cmdBuffer(m_device);
1175
1176 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1177 BeginCommandBuffer(cmdBuffer);
1178 // Don't care about RenderPass handle b/c error should be flagged before that
1179 vkCmdBeginRenderPass(cmdBuffer.GetBufferHandle(), NULL);
1180
1181 msgFlags = m_errorMonitor->GetState(&msgString);
1182 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding NULL RenderPass.";
1183 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
1184 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
1185 }
1186}
1187
Tobin Ehlis254eca02015-06-25 15:46:59 -06001188TEST_F(VkLayerTest, RenderPassWithinRenderPass)
1189{
1190 // Bind a BeginRenderPass within an active RenderPass
1191 VkFlags msgFlags;
1192 std::string msgString;
1193
1194 ASSERT_NO_FATAL_FAILURE(InitState());
1195 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1196 m_errorMonitor->ClearState();
1197 VkCommandBufferObj cmdBuffer(m_device);
1198
1199 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1200 BeginCommandBuffer(cmdBuffer);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001201 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
1202 const VkRenderPassBegin rp_begin = {
1203 .renderPass = (VkRenderPass) 0xc001d00d,
1204 .framebuffer = NULL
1205 };
1206 vkCmdBeginRenderPass(cmdBuffer.GetBufferHandle(), &rp_begin);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001207
1208 msgFlags = m_errorMonitor->GetState(&msgString);
1209 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding RenderPass w/i an active RenderPass.";
1210 if (!strstr(msgString.c_str(),"Cannot call vkCmdBeginRenderPass() during an active RenderPass ")) {
1211 FAIL() << "Error received was not 'Cannot call vkCmdBeginRenderPass() during an active RenderPass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001212 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001213}
1214
1215TEST_F(VkLayerTest, InvalidDynamicStateObject)
1216{
1217 // Create a valid cmd buffer
1218 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001219 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1220 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001221}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06001222
Tobin Ehlise4076782015-06-24 15:53:07 -06001223TEST_F(VkLayerTest, VtxBufferNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001224{
1225 // Bind VBO out-of-bounds for given PSO
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001226 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001227 std::string msgString;
1228 VkResult err;
1229
1230 ASSERT_NO_FATAL_FAILURE(InitState());
1231 m_errorMonitor->ClearState();
1232 VkCommandBufferObj cmdBuffer(m_device);
1233 const VkDescriptorTypeCount ds_type_count = {
1234 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1235 .count = 1,
1236 };
1237 const VkDescriptorPoolCreateInfo ds_pool_ci = {
1238 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
1239 .pNext = NULL,
1240 .count = 1,
1241 .pTypeCount = &ds_type_count,
1242 };
1243 VkDescriptorPool ds_pool;
1244 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1245 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001246
1247 const VkDescriptorSetLayoutBinding dsl_binding = {
1248 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
Chia-I Wud3114a22015-05-25 16:22:52 +08001249 .arraySize = 1,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001250 .stageFlags = VK_SHADER_STAGE_ALL,
1251 .pImmutableSamplers = NULL,
1252 };
1253
1254 const VkDescriptorSetLayoutCreateInfo ds_layout_ci = {
1255 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
1256 .pNext = NULL,
1257 .count = 1,
1258 .pBinding = &dsl_binding,
1259 };
1260 VkDescriptorSetLayout ds_layout;
1261 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1262 ASSERT_VK_SUCCESS(err);
1263
1264 VkDescriptorSet descriptorSet;
1265 uint32_t ds_count = 0;
1266 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1267 ASSERT_VK_SUCCESS(err);
1268
1269 const VkPipelineLayoutCreateInfo pipeline_layout_ci = {
1270 .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
1271 .pNext = NULL,
1272 .descriptorSetCount = 1,
1273 .pSetLayouts = &ds_layout,
1274 };
1275
1276 VkPipelineLayout pipeline_layout;
1277 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1278 ASSERT_VK_SUCCESS(err);
1279
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001280 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001281
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001282 const VkPipelineShaderStageCreateInfo pipe_vs_ci = {
1283 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
1284 .pNext = NULL,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001285 .stage = VK_SHADER_STAGE_VERTEX,
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001286 .shader = vs.obj(),
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001287 .linkConstBufferCount = 0,
1288 .pLinkConstBufferInfo = NULL,
1289 .pSpecializationInfo = NULL,
1290 };
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001291 const VkGraphicsPipelineCreateInfo gp_ci = {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001292 .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
1293 .pNext = NULL,
1294 .stageCount = 1,
1295 .pStages = &pipe_vs_ci,
1296 .pVertexInputState = NULL,
1297 .pIaState = NULL,
1298 .pTessState = NULL,
1299 .pVpState = NULL,
1300 .pRsState = NULL,
1301 .pMsState = NULL,
1302 .pDsState = NULL,
1303 .pCbState = NULL,
1304 .flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT,
1305 .layout = pipeline_layout,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001306 };
1307
1308 VkPipeline pipeline;
1309 err = vkCreateGraphicsPipeline(m_device->device(), &gp_ci, &pipeline);
1310 ASSERT_VK_SUCCESS(err);
1311
1312 err= cmdBuffer.BeginCommandBuffer();
1313 ASSERT_VK_SUCCESS(err);
1314 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1315 // Should error before calling to driver so don't care about actual data
1316 vkCmdBindVertexBuffers(cmdBuffer.GetBufferHandle(), 0, 1, NULL, NULL);
1317
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001318 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlise4076782015-06-24 15:53:07 -06001319 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
1320 if (!strstr(msgString.c_str(),"Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.")) {
1321 FAIL() << "Error received was not 'Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001322 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001323}
1324
1325TEST_F(VkLayerTest, DSTypeMismatch)
1326{
1327 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001328 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001329 std::string msgString;
1330 VkResult err;
1331
1332 ASSERT_NO_FATAL_FAILURE(InitState());
1333 m_errorMonitor->ClearState();
1334 //VkDescriptorSetObj descriptorSet(m_device);
1335 const VkDescriptorTypeCount ds_type_count = {
1336 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1337 .count = 1,
1338 };
1339 const VkDescriptorPoolCreateInfo ds_pool_ci = {
1340 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
1341 .pNext = NULL,
1342 .count = 1,
1343 .pTypeCount = &ds_type_count,
1344 };
1345 VkDescriptorPool ds_pool;
1346 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1347 ASSERT_VK_SUCCESS(err);
1348 const VkDescriptorSetLayoutBinding dsl_binding = {
1349 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
Chia-I Wud3114a22015-05-25 16:22:52 +08001350 .arraySize = 1,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001351 .stageFlags = VK_SHADER_STAGE_ALL,
1352 .pImmutableSamplers = NULL,
1353 };
1354
1355 const VkDescriptorSetLayoutCreateInfo ds_layout_ci = {
1356 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
1357 .pNext = NULL,
1358 .count = 1,
1359 .pBinding = &dsl_binding,
1360 };
1361 VkDescriptorSetLayout ds_layout;
1362 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1363 ASSERT_VK_SUCCESS(err);
1364
1365 VkDescriptorSet descriptorSet;
1366 uint32_t ds_count = 0;
1367 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1368 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001369
1370 const VkSamplerCreateInfo sampler_ci = {
1371 .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
1372 .pNext = NULL,
1373 .magFilter = VK_TEX_FILTER_NEAREST,
1374 .minFilter = VK_TEX_FILTER_NEAREST,
1375 .mipMode = VK_TEX_MIPMAP_MODE_BASE,
1376 .addressU = VK_TEX_ADDRESS_CLAMP,
1377 .addressV = VK_TEX_ADDRESS_CLAMP,
1378 .addressW = VK_TEX_ADDRESS_CLAMP,
1379 .mipLodBias = 1.0,
1380 .maxAnisotropy = 1,
1381 .compareOp = VK_COMPARE_OP_NEVER,
1382 .minLod = 1.0,
1383 .maxLod = 1.0,
Tony Barbour2c4e7c72015-06-25 16:56:44 -06001384 .borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001385 };
1386 VkSampler sampler;
1387 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1388 ASSERT_VK_SUCCESS(err);
1389
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001390 VkDescriptorInfo descriptor_info;
1391 memset(&descriptor_info, 0, sizeof(descriptor_info));
1392 descriptor_info.sampler = sampler;
1393
1394 VkWriteDescriptorSet descriptor_write;
1395 memset(&descriptor_write, 0, sizeof(descriptor_write));
1396 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1397 descriptor_write.destSet = descriptorSet;
1398 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001399 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001400 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1401 descriptor_write.pDescriptors = &descriptor_info;
1402
1403 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1404
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001405 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001406 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 +08001407 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) {
1408 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 -06001409 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001410}
1411
1412TEST_F(VkLayerTest, DSUpdateOutOfBounds)
1413{
1414 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001415 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001416 std::string msgString;
1417 VkResult err;
1418
1419 ASSERT_NO_FATAL_FAILURE(InitState());
1420 m_errorMonitor->ClearState();
1421 //VkDescriptorSetObj descriptorSet(m_device);
1422 const VkDescriptorTypeCount ds_type_count = {
1423 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1424 .count = 1,
1425 };
1426 const VkDescriptorPoolCreateInfo ds_pool_ci = {
1427 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
1428 .pNext = NULL,
1429 .count = 1,
1430 .pTypeCount = &ds_type_count,
1431 };
1432 VkDescriptorPool ds_pool;
1433 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1434 ASSERT_VK_SUCCESS(err);
1435 const VkDescriptorSetLayoutBinding dsl_binding = {
1436 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
Chia-I Wud3114a22015-05-25 16:22:52 +08001437 .arraySize = 1,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001438 .stageFlags = VK_SHADER_STAGE_ALL,
1439 .pImmutableSamplers = NULL,
1440 };
1441
1442 const VkDescriptorSetLayoutCreateInfo ds_layout_ci = {
1443 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
1444 .pNext = NULL,
1445 .count = 1,
1446 .pBinding = &dsl_binding,
1447 };
1448 VkDescriptorSetLayout ds_layout;
1449 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1450 ASSERT_VK_SUCCESS(err);
1451
1452 VkDescriptorSet descriptorSet;
1453 uint32_t ds_count = 0;
1454 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1455 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001456
1457 const VkSamplerCreateInfo sampler_ci = {
1458 .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
1459 .pNext = NULL,
1460 .magFilter = VK_TEX_FILTER_NEAREST,
1461 .minFilter = VK_TEX_FILTER_NEAREST,
1462 .mipMode = VK_TEX_MIPMAP_MODE_BASE,
1463 .addressU = VK_TEX_ADDRESS_CLAMP,
1464 .addressV = VK_TEX_ADDRESS_CLAMP,
1465 .addressW = VK_TEX_ADDRESS_CLAMP,
1466 .mipLodBias = 1.0,
1467 .maxAnisotropy = 1,
1468 .compareOp = VK_COMPARE_OP_NEVER,
1469 .minLod = 1.0,
1470 .maxLod = 1.0,
Tony Barbour2c4e7c72015-06-25 16:56:44 -06001471 .borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001472 };
1473 VkSampler sampler;
1474 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1475 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001476
1477 VkDescriptorInfo descriptor_info;
1478 memset(&descriptor_info, 0, sizeof(descriptor_info));
1479 descriptor_info.sampler = sampler;
1480
1481 VkWriteDescriptorSet descriptor_write;
1482 memset(&descriptor_write, 0, sizeof(descriptor_write));
1483 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1484 descriptor_write.destSet = descriptorSet;
1485 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
1486 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001487 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001488 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1489 descriptor_write.pDescriptors = &descriptor_info;
1490
1491 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1492
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001493 msgFlags = m_errorMonitor->GetState(&msgString);
1494 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 +08001495 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
1496 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 -06001497 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001498}
1499
1500TEST_F(VkLayerTest, InvalidDSUpdateIndex)
1501{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001502 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001503 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001504 std::string msgString;
1505 VkResult err;
1506
1507 ASSERT_NO_FATAL_FAILURE(InitState());
1508 m_errorMonitor->ClearState();
1509 //VkDescriptorSetObj descriptorSet(m_device);
1510 const VkDescriptorTypeCount ds_type_count = {
1511 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1512 .count = 1,
1513 };
1514 const VkDescriptorPoolCreateInfo ds_pool_ci = {
1515 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
1516 .pNext = NULL,
1517 .count = 1,
1518 .pTypeCount = &ds_type_count,
1519 };
1520 VkDescriptorPool ds_pool;
1521 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1522 ASSERT_VK_SUCCESS(err);
1523 const VkDescriptorSetLayoutBinding dsl_binding = {
1524 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
Chia-I Wud3114a22015-05-25 16:22:52 +08001525 .arraySize = 1,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001526 .stageFlags = VK_SHADER_STAGE_ALL,
1527 .pImmutableSamplers = NULL,
1528 };
1529
1530 const VkDescriptorSetLayoutCreateInfo ds_layout_ci = {
1531 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
1532 .pNext = NULL,
1533 .count = 1,
1534 .pBinding = &dsl_binding,
1535 };
1536 VkDescriptorSetLayout ds_layout;
1537 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1538 ASSERT_VK_SUCCESS(err);
1539
1540 VkDescriptorSet descriptorSet;
1541 uint32_t ds_count = 0;
1542 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1543 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001544
1545 const VkSamplerCreateInfo sampler_ci = {
1546 .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
1547 .pNext = NULL,
1548 .magFilter = VK_TEX_FILTER_NEAREST,
1549 .minFilter = VK_TEX_FILTER_NEAREST,
1550 .mipMode = VK_TEX_MIPMAP_MODE_BASE,
1551 .addressU = VK_TEX_ADDRESS_CLAMP,
1552 .addressV = VK_TEX_ADDRESS_CLAMP,
1553 .addressW = VK_TEX_ADDRESS_CLAMP,
1554 .mipLodBias = 1.0,
1555 .maxAnisotropy = 1,
1556 .compareOp = VK_COMPARE_OP_NEVER,
1557 .minLod = 1.0,
1558 .maxLod = 1.0,
Tony Barbour2c4e7c72015-06-25 16:56:44 -06001559 .borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001560 };
1561 VkSampler sampler;
1562 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1563 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001564
1565 VkDescriptorInfo descriptor_info;
1566 memset(&descriptor_info, 0, sizeof(descriptor_info));
1567 descriptor_info.sampler = sampler;
1568
1569 VkWriteDescriptorSet descriptor_write;
1570 memset(&descriptor_write, 0, sizeof(descriptor_write));
1571 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1572 descriptor_write.destSet = descriptorSet;
1573 descriptor_write.destBinding = 2;
1574 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001575 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001576 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1577 descriptor_write.pDescriptors = &descriptor_info;
1578
1579 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1580
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001581 msgFlags = m_errorMonitor->GetState(&msgString);
1582 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 -06001583 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
1584 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
1585 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001586}
1587
1588TEST_F(VkLayerTest, InvalidDSUpdateStruct)
1589{
1590 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001591 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001592 std::string msgString;
1593 VkResult err;
1594
1595 ASSERT_NO_FATAL_FAILURE(InitState());
1596 m_errorMonitor->ClearState();
1597 //VkDescriptorSetObj descriptorSet(m_device);
1598 const VkDescriptorTypeCount ds_type_count = {
1599 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1600 .count = 1,
1601 };
1602 const VkDescriptorPoolCreateInfo ds_pool_ci = {
1603 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
1604 .pNext = NULL,
1605 .count = 1,
1606 .pTypeCount = &ds_type_count,
1607 };
1608 VkDescriptorPool ds_pool;
1609 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1610 ASSERT_VK_SUCCESS(err);
1611 const VkDescriptorSetLayoutBinding dsl_binding = {
1612 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
Chia-I Wud3114a22015-05-25 16:22:52 +08001613 .arraySize = 1,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001614 .stageFlags = VK_SHADER_STAGE_ALL,
1615 .pImmutableSamplers = NULL,
1616 };
1617
1618 const VkDescriptorSetLayoutCreateInfo ds_layout_ci = {
1619 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
1620 .pNext = NULL,
1621 .count = 1,
1622 .pBinding = &dsl_binding,
1623 };
1624 VkDescriptorSetLayout ds_layout;
1625 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1626 ASSERT_VK_SUCCESS(err);
1627
1628 VkDescriptorSet descriptorSet;
1629 uint32_t ds_count = 0;
1630 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1631 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001632
1633 const VkSamplerCreateInfo sampler_ci = {
1634 .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
1635 .pNext = NULL,
1636 .magFilter = VK_TEX_FILTER_NEAREST,
1637 .minFilter = VK_TEX_FILTER_NEAREST,
1638 .mipMode = VK_TEX_MIPMAP_MODE_BASE,
1639 .addressU = VK_TEX_ADDRESS_CLAMP,
1640 .addressV = VK_TEX_ADDRESS_CLAMP,
1641 .addressW = VK_TEX_ADDRESS_CLAMP,
1642 .mipLodBias = 1.0,
1643 .maxAnisotropy = 1,
1644 .compareOp = VK_COMPARE_OP_NEVER,
1645 .minLod = 1.0,
1646 .maxLod = 1.0,
Tony Barbour2c4e7c72015-06-25 16:56:44 -06001647 .borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001648 };
1649 VkSampler sampler;
1650 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1651 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001652
1653
1654 VkDescriptorInfo descriptor_info;
1655 memset(&descriptor_info, 0, sizeof(descriptor_info));
1656 descriptor_info.sampler = sampler;
1657
1658 VkWriteDescriptorSet descriptor_write;
1659 memset(&descriptor_write, 0, sizeof(descriptor_write));
1660 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
1661 descriptor_write.destSet = descriptorSet;
1662 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001663 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001664 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1665 descriptor_write.pDescriptors = &descriptor_info;
1666
1667 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1668
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001669 msgFlags = m_errorMonitor->GetState(&msgString);
1670 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 -06001671 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
1672 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
1673 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001674}
1675
1676TEST_F(VkLayerTest, NumSamplesMismatch)
1677{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001678 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001679 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001680 std::string msgString;
1681 VkResult err;
1682
1683 ASSERT_NO_FATAL_FAILURE(InitState());
1684 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1685 m_errorMonitor->ClearState();
1686 VkCommandBufferObj cmdBuffer(m_device);
1687 const VkDescriptorTypeCount ds_type_count = {
1688 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1689 .count = 1,
1690 };
1691 const VkDescriptorPoolCreateInfo ds_pool_ci = {
1692 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
1693 .pNext = NULL,
1694 .count = 1,
1695 .pTypeCount = &ds_type_count,
1696 };
1697 VkDescriptorPool ds_pool;
1698 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1699 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001700
1701 const VkDescriptorSetLayoutBinding dsl_binding = {
1702 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
Chia-I Wud3114a22015-05-25 16:22:52 +08001703 .arraySize = 1,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001704 .stageFlags = VK_SHADER_STAGE_ALL,
1705 .pImmutableSamplers = NULL,
1706 };
1707
1708 const VkDescriptorSetLayoutCreateInfo ds_layout_ci = {
1709 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
1710 .pNext = NULL,
1711 .count = 1,
1712 .pBinding = &dsl_binding,
1713 };
1714 VkDescriptorSetLayout ds_layout;
1715 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1716 ASSERT_VK_SUCCESS(err);
1717
1718 VkDescriptorSet descriptorSet;
1719 uint32_t ds_count = 0;
1720 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1721 ASSERT_VK_SUCCESS(err);
1722
1723 const VkPipelineMsStateCreateInfo pipe_ms_state_ci = {
1724 .sType = VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO,
1725 .pNext = NULL,
Tony Barboure094edf2015-06-26 10:18:34 -06001726 .rasterSamples = 4,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001727 .multisampleEnable = 1,
1728 .sampleShadingEnable = 0,
1729 .minSampleShading = 1.0,
1730 .sampleMask = 15,
1731 };
1732
1733 const VkPipelineLayoutCreateInfo pipeline_layout_ci = {
1734 .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
1735 .pNext = NULL,
1736 .descriptorSetCount = 1,
1737 .pSetLayouts = &ds_layout,
1738 };
1739
1740 VkPipelineLayout pipeline_layout;
1741 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1742 ASSERT_VK_SUCCESS(err);
1743
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001744 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001745
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001746 const VkPipelineShaderStageCreateInfo pipe_vs_ci = {
1747 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
1748 .pNext = NULL,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001749 .stage = VK_SHADER_STAGE_VERTEX,
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001750 .shader = vs.obj(),
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001751 .linkConstBufferCount = 0,
1752 .pLinkConstBufferInfo = NULL,
1753 .pSpecializationInfo = NULL,
1754 };
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001755 const VkGraphicsPipelineCreateInfo gp_ci = {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001756 .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
1757 .pNext = NULL,
1758 .stageCount = 1,
1759 .pStages = &pipe_vs_ci,
1760 .pVertexInputState = NULL,
1761 .pIaState = NULL,
1762 .pTessState = NULL,
1763 .pVpState = NULL,
1764 .pRsState = NULL,
1765 .pMsState = &pipe_ms_state_ci,
1766 .pDsState = NULL,
1767 .pCbState = NULL,
1768 .flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT,
1769 .layout = pipeline_layout,
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001770 };
1771
1772 VkPipeline pipeline;
1773 err = vkCreateGraphicsPipeline(m_device->device(), &gp_ci, &pipeline);
1774 ASSERT_VK_SUCCESS(err);
1775
1776 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1777 BeginCommandBuffer(cmdBuffer);
1778 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1779
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001780 msgFlags = m_errorMonitor->GetState(&msgString);
1781 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 -06001782 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
1783 FAIL() << "Error received was not 'Num samples mismatch!...'";
1784 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001785}
Tobin Ehlise4076782015-06-24 15:53:07 -06001786TEST_F(VkLayerTest, PipelineNotBound)
1787{
1788 VkFlags msgFlags;
1789 std::string msgString;
1790 VkResult err;
1791
1792 ASSERT_NO_FATAL_FAILURE(InitState());
1793 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1794 m_errorMonitor->ClearState();
1795 VkCommandBufferObj cmdBuffer(m_device);
1796 const VkDescriptorTypeCount ds_type_count = {
1797 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1798 .count = 1,
1799 };
1800 const VkDescriptorPoolCreateInfo ds_pool_ci = {
1801 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
1802 .pNext = NULL,
1803 .count = 1,
1804 .pTypeCount = &ds_type_count,
1805 };
1806 VkDescriptorPool ds_pool;
1807 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1808 ASSERT_VK_SUCCESS(err);
1809
1810 const VkDescriptorSetLayoutBinding dsl_binding = {
1811 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1812 .arraySize = 1,
1813 .stageFlags = VK_SHADER_STAGE_ALL,
1814 .pImmutableSamplers = NULL,
1815 };
1816
1817 const VkDescriptorSetLayoutCreateInfo ds_layout_ci = {
1818 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
1819 .pNext = NULL,
1820 .count = 1,
1821 .pBinding = &dsl_binding,
1822 };
1823 VkDescriptorSetLayout ds_layout;
1824 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1825 ASSERT_VK_SUCCESS(err);
1826
1827 VkDescriptorSet descriptorSet;
1828 uint32_t ds_count = 0;
1829 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1830 ASSERT_VK_SUCCESS(err);
1831
1832 const VkPipelineLayoutCreateInfo pipeline_layout_ci = {
1833 .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
1834 .pNext = NULL,
1835 .descriptorSetCount = 1,
1836 .pSetLayouts = &ds_layout,
1837 };
1838
1839 VkPipelineLayout pipeline_layout;
1840 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1841 ASSERT_VK_SUCCESS(err);
1842
Tobin Ehlise4076782015-06-24 15:53:07 -06001843 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1844 //err = vkCreateGraphicsPipeline(m_device->device(), &gp_ci, &pipeline);
1845 ASSERT_VK_SUCCESS(err);
1846
1847 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1848 BeginCommandBuffer(cmdBuffer);
1849 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1850
1851 msgFlags = m_errorMonitor->GetState(&msgString);
1852 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding invalid pipeline to CmdBuffer";
1853 if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1854 FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1855 }
1856}
1857TEST_F(VkLayerTest, VtxBufferBadIndex)
1858{
1859 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
1860 VkFlags msgFlags;
1861 std::string msgString;
1862 VkResult err;
1863
1864 ASSERT_NO_FATAL_FAILURE(InitState());
1865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1866 m_errorMonitor->ClearState();
1867 VkCommandBufferObj cmdBuffer(m_device);
1868 const VkDescriptorTypeCount ds_type_count = {
1869 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1870 .count = 1,
1871 };
1872 const VkDescriptorPoolCreateInfo ds_pool_ci = {
1873 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
1874 .pNext = NULL,
1875 .count = 1,
1876 .pTypeCount = &ds_type_count,
1877 };
1878 VkDescriptorPool ds_pool;
1879 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1880 ASSERT_VK_SUCCESS(err);
1881
1882 const VkDescriptorSetLayoutBinding dsl_binding = {
1883 .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1884 .arraySize = 1,
1885 .stageFlags = VK_SHADER_STAGE_ALL,
1886 .pImmutableSamplers = NULL,
1887 };
1888
1889 const VkDescriptorSetLayoutCreateInfo ds_layout_ci = {
1890 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
1891 .pNext = NULL,
1892 .count = 1,
1893 .pBinding = &dsl_binding,
1894 };
1895 VkDescriptorSetLayout ds_layout;
1896 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1897 ASSERT_VK_SUCCESS(err);
1898
1899 VkDescriptorSet descriptorSet;
1900 uint32_t ds_count = 0;
1901 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1902 ASSERT_VK_SUCCESS(err);
1903
1904 const VkPipelineMsStateCreateInfo pipe_ms_state_ci = {
1905 .sType = VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO,
1906 .pNext = NULL,
Tony Barboure094edf2015-06-26 10:18:34 -06001907 .rasterSamples = 1,
Tobin Ehlise4076782015-06-24 15:53:07 -06001908 .multisampleEnable = 1,
1909 .sampleShadingEnable = 0,
1910 .minSampleShading = 1.0,
1911 .sampleMask = 15,
1912 };
1913
1914 const VkPipelineLayoutCreateInfo pipeline_layout_ci = {
1915 .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
1916 .pNext = NULL,
1917 .descriptorSetCount = 1,
1918 .pSetLayouts = &ds_layout,
1919 };
1920
1921 VkPipelineLayout pipeline_layout;
1922 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1923 ASSERT_VK_SUCCESS(err);
1924
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001925 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tobin Ehlise4076782015-06-24 15:53:07 -06001926
1927 const VkPipelineShaderStageCreateInfo pipe_vs_ci = {
1928 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
1929 .pNext = NULL,
1930 .stage = VK_SHADER_STAGE_VERTEX,
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001931 .shader = vs.obj(),
Tobin Ehlise4076782015-06-24 15:53:07 -06001932 .linkConstBufferCount = 0,
1933 .pLinkConstBufferInfo = NULL,
1934 .pSpecializationInfo = NULL,
1935 };
1936 const VkGraphicsPipelineCreateInfo gp_ci = {
1937 .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
1938 .pNext = NULL,
1939 .stageCount = 1,
1940 .pStages = &pipe_vs_ci,
1941 .pVertexInputState = NULL,
1942 .pIaState = NULL,
1943 .pTessState = NULL,
1944 .pVpState = NULL,
1945 .pRsState = NULL,
1946 .pMsState = &pipe_ms_state_ci,
1947 .pDsState = NULL,
1948 .pCbState = NULL,
1949 .flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT,
1950 .layout = pipeline_layout,
1951 };
1952
1953 VkPipeline pipeline;
1954 err = vkCreateGraphicsPipeline(m_device->device(), &gp_ci, &pipeline);
1955 ASSERT_VK_SUCCESS(err);
1956
1957 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1958 BeginCommandBuffer(cmdBuffer);
1959 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1960 // Should error before calling to driver so don't care about actual data
1961 vkCmdBindVertexBuffers(cmdBuffer.GetBufferHandle(), 0, 1, NULL, NULL);
1962
1963 msgFlags = m_errorMonitor->GetState(&msgString);
1964 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding Vtx Buffer w/o VBO attached to PSO.";
1965 if (!strstr(msgString.c_str(),"Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.")) {
1966 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
1967 }
1968}
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001969#endif
1970#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06001971#if GTEST_IS_THREADSAFE
1972struct thread_data_struct {
1973 VkCmdBuffer cmdBuffer;
1974 VkEvent event;
1975 bool bailout;
1976};
1977
1978extern "C" void *AddToCommandBuffer(void *arg)
1979{
1980 struct thread_data_struct *data = (struct thread_data_struct *) arg;
1981 std::string msgString;
1982
1983 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06001984 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06001985 if (data->bailout) {
1986 break;
1987 }
1988 }
1989 return NULL;
1990}
1991
1992TEST_F(VkLayerTest, ThreadCmdBufferCollision)
1993{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001994 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06001995 std::string msgString;
1996 pthread_t thread;
1997 pthread_attr_t thread_attr;
1998
1999 ASSERT_NO_FATAL_FAILURE(InitState());
2000 ASSERT_NO_FATAL_FAILURE(InitViewport());
2001 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2002
2003 VkCommandBufferObj cmdBuffer(m_device);
2004
2005 m_errorMonitor->ClearState();
2006 pthread_attr_init(&thread_attr);
2007 BeginCommandBuffer(cmdBuffer);
2008
2009 VkEventCreateInfo event_info;
2010 VkEvent event;
2011 VkMemoryRequirements mem_req;
Mike Stroyan09aae812015-05-12 16:00:45 -06002012 VkResult err;
2013
2014 memset(&event_info, 0, sizeof(event_info));
2015 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2016
2017 err = vkCreateEvent(device(), &event_info, &event);
2018 ASSERT_VK_SUCCESS(err);
2019
Tony Barbour426b9052015-06-24 16:06:58 -06002020 err = vkGetObjectMemoryRequirements(device(), VK_OBJECT_TYPE_EVENT, event, &mem_req);
Mike Stroyan09aae812015-05-12 16:00:45 -06002021 ASSERT_VK_SUCCESS(err);
2022
2023 VkMemoryAllocInfo mem_info;
2024 VkDeviceMemory event_mem;
2025
Mike Stroyan09aae812015-05-12 16:00:45 -06002026 memset(&mem_info, 0, sizeof(mem_info));
2027 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
2028 mem_info.allocationSize = mem_req.size;
Courtney Goeltzenleuchterb25c9b92015-06-18 17:01:41 -06002029 mem_info.memProps = 0;
Mike Stroyan09aae812015-05-12 16:00:45 -06002030 err = vkAllocMemory(device(), &mem_info, &event_mem);
2031 ASSERT_VK_SUCCESS(err);
2032
Mark Lobodzinski23182612015-05-29 09:32:35 -05002033 err = vkBindObjectMemory(device(), VK_OBJECT_TYPE_EVENT, event, event_mem, 0);
Mike Stroyan09aae812015-05-12 16:00:45 -06002034 ASSERT_VK_SUCCESS(err);
2035
2036 err = vkResetEvent(device(), event);
2037 ASSERT_VK_SUCCESS(err);
2038
2039 struct thread_data_struct data;
2040 data.cmdBuffer = cmdBuffer.obj();
2041 data.event = event;
2042 data.bailout = false;
2043 m_errorMonitor->SetBailout(&data.bailout);
2044 // Add many entries to command buffer from another thread.
2045 pthread_create(&thread, &thread_attr, AddToCommandBuffer, (void *)&data);
2046 // Add many entries to command buffer from this thread at the same time.
2047 AddToCommandBuffer(&data);
2048 pthread_join(thread, NULL);
2049 EndCommandBuffer(cmdBuffer);
2050
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002051 msgFlags = m_errorMonitor->GetState(&msgString);
Mike Stroyaned254572015-06-17 16:32:06 -06002052 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 -06002053 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05002054 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06002055 }
2056
2057}
2058#endif
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002059#endif
Chris Forbes5af3bf22015-05-25 11:13:08 +12002060
2061#if SHADER_CHECKER_TESTS
2062TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
2063{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002064 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12002065 std::string msgString;
2066 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002067 ScopedUseGlsl useGlsl(false);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002068
2069 char const *vsSource =
2070 "#version 140\n"
2071 "#extension GL_ARB_separate_shader_objects: require\n"
2072 "#extension GL_ARB_shading_language_420pack: require\n"
2073 "\n"
2074 "layout(location=0) out float x;\n"
2075 "void main(){\n"
2076 " gl_Position = vec4(1);\n"
2077 " x = 0;\n"
2078 "}\n";
2079 char const *fsSource =
2080 "#version 140\n"
2081 "#extension GL_ARB_separate_shader_objects: require\n"
2082 "#extension GL_ARB_shading_language_420pack: require\n"
2083 "\n"
2084 "layout(location=0) out vec4 color;\n"
2085 "void main(){\n"
2086 " color = vec4(1);\n"
2087 "}\n";
2088
2089 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2090 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2091
2092 VkPipelineObj pipe(m_device);
2093 pipe.AddShader(&vs);
2094 pipe.AddShader(&fs);
2095
2096 VkCommandBufferObj dummyCmd(m_device);
2097 VkDescriptorSetObj descriptorSet(m_device);
2098 descriptorSet.AppendDummy();
2099 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2100
2101 m_errorMonitor->ClearState();
2102 pipe.CreateVKPipeline(descriptorSet);
2103
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002104 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002105
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002106 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002107 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
2108 FAIL() << "Incorrect warning: " << msgString;
2109 }
2110}
Chris Forbes5af3bf22015-05-25 11:13:08 +12002111
Chris Forbes3c10b852015-05-25 11:13:13 +12002112TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
2113{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002114 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12002115 std::string msgString;
2116 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002117 ScopedUseGlsl useGlsl(false);
Chris Forbes3c10b852015-05-25 11:13:13 +12002118
2119 char const *vsSource =
2120 "#version 140\n"
2121 "#extension GL_ARB_separate_shader_objects: require\n"
2122 "#extension GL_ARB_shading_language_420pack: require\n"
2123 "\n"
2124 "void main(){\n"
2125 " gl_Position = vec4(1);\n"
2126 "}\n";
2127 char const *fsSource =
2128 "#version 140\n"
2129 "#extension GL_ARB_separate_shader_objects: require\n"
2130 "#extension GL_ARB_shading_language_420pack: require\n"
2131 "\n"
2132 "layout(location=0) in float x;\n"
2133 "layout(location=0) out vec4 color;\n"
2134 "void main(){\n"
2135 " color = vec4(x);\n"
2136 "}\n";
2137
2138 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2139 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2140
2141 VkPipelineObj pipe(m_device);
2142 pipe.AddShader(&vs);
2143 pipe.AddShader(&fs);
2144
2145 VkCommandBufferObj dummyCmd(m_device);
2146 VkDescriptorSetObj descriptorSet(m_device);
2147 descriptorSet.AppendDummy();
2148 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2149
2150 m_errorMonitor->ClearState();
2151 pipe.CreateVKPipeline(descriptorSet);
2152
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002153 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12002154
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002155 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes3c10b852015-05-25 11:13:13 +12002156 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
2157 FAIL() << "Incorrect error: " << msgString;
2158 }
2159}
2160
Chris Forbescc281692015-05-25 11:13:17 +12002161TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
2162{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002163 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12002164 std::string msgString;
2165 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002166 ScopedUseGlsl useGlsl(false);
Chris Forbescc281692015-05-25 11:13:17 +12002167
2168 char const *vsSource =
2169 "#version 140\n"
2170 "#extension GL_ARB_separate_shader_objects: require\n"
2171 "#extension GL_ARB_shading_language_420pack: require\n"
2172 "\n"
2173 "layout(location=0) out int x;\n"
2174 "void main(){\n"
2175 " x = 0;\n"
2176 " gl_Position = vec4(1);\n"
2177 "}\n";
2178 char const *fsSource =
2179 "#version 140\n"
2180 "#extension GL_ARB_separate_shader_objects: require\n"
2181 "#extension GL_ARB_shading_language_420pack: require\n"
2182 "\n"
2183 "layout(location=0) in float x;\n" /* VS writes int */
2184 "layout(location=0) out vec4 color;\n"
2185 "void main(){\n"
2186 " color = vec4(x);\n"
2187 "}\n";
2188
2189 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2190 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2191
2192 VkPipelineObj pipe(m_device);
2193 pipe.AddShader(&vs);
2194 pipe.AddShader(&fs);
2195
2196 VkCommandBufferObj dummyCmd(m_device);
2197 VkDescriptorSetObj descriptorSet(m_device);
2198 descriptorSet.AppendDummy();
2199 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2200
2201 m_errorMonitor->ClearState();
2202 pipe.CreateVKPipeline(descriptorSet);
2203
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002204 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12002205
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002206 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbescc281692015-05-25 11:13:17 +12002207 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
2208 FAIL() << "Incorrect error: " << msgString;
2209 }
2210}
2211
Chris Forbes8291c052015-05-25 11:13:28 +12002212TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
2213{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002214 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12002215 std::string msgString;
2216 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002217 ScopedUseGlsl useGlsl(false);
Chris Forbes8291c052015-05-25 11:13:28 +12002218
2219 VkVertexInputBindingDescription input_binding;
2220 memset(&input_binding, 0, sizeof(input_binding));
2221
2222 VkVertexInputAttributeDescription input_attrib;
2223 memset(&input_attrib, 0, sizeof(input_attrib));
2224 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2225
2226 char const *vsSource =
2227 "#version 140\n"
2228 "#extension GL_ARB_separate_shader_objects: require\n"
2229 "#extension GL_ARB_shading_language_420pack: require\n"
2230 "\n"
2231 "void main(){\n"
2232 " gl_Position = vec4(1);\n"
2233 "}\n";
2234 char const *fsSource =
2235 "#version 140\n"
2236 "#extension GL_ARB_separate_shader_objects: require\n"
2237 "#extension GL_ARB_shading_language_420pack: require\n"
2238 "\n"
2239 "layout(location=0) out vec4 color;\n"
2240 "void main(){\n"
2241 " color = vec4(1);\n"
2242 "}\n";
2243
2244 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2245 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2246
2247 VkPipelineObj pipe(m_device);
2248 pipe.AddShader(&vs);
2249 pipe.AddShader(&fs);
2250
2251 pipe.AddVertexInputBindings(&input_binding, 1);
2252 pipe.AddVertexInputAttribs(&input_attrib, 1);
2253
2254 VkCommandBufferObj dummyCmd(m_device);
2255 VkDescriptorSetObj descriptorSet(m_device);
2256 descriptorSet.AppendDummy();
2257 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2258
2259 m_errorMonitor->ClearState();
2260 pipe.CreateVKPipeline(descriptorSet);
2261
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002262 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12002263
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002264 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12002265 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
2266 FAIL() << "Incorrect warning: " << msgString;
2267 }
2268}
2269
Chris Forbes37367e62015-05-25 11:13:29 +12002270TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
2271{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002272 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12002273 std::string msgString;
2274 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002275 ScopedUseGlsl useGlsl(false);
Chris Forbes37367e62015-05-25 11:13:29 +12002276
2277 char const *vsSource =
2278 "#version 140\n"
2279 "#extension GL_ARB_separate_shader_objects: require\n"
2280 "#extension GL_ARB_shading_language_420pack: require\n"
2281 "\n"
2282 "layout(location=0) in vec4 x;\n" /* not provided */
2283 "void main(){\n"
2284 " gl_Position = x;\n"
2285 "}\n";
2286 char const *fsSource =
2287 "#version 140\n"
2288 "#extension GL_ARB_separate_shader_objects: require\n"
2289 "#extension GL_ARB_shading_language_420pack: require\n"
2290 "\n"
2291 "layout(location=0) out vec4 color;\n"
2292 "void main(){\n"
2293 " color = vec4(1);\n"
2294 "}\n";
2295
2296 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2297 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2298
2299 VkPipelineObj pipe(m_device);
2300 pipe.AddShader(&vs);
2301 pipe.AddShader(&fs);
2302
2303 VkCommandBufferObj dummyCmd(m_device);
2304 VkDescriptorSetObj descriptorSet(m_device);
2305 descriptorSet.AppendDummy();
2306 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2307
2308 m_errorMonitor->ClearState();
2309 pipe.CreateVKPipeline(descriptorSet);
2310
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002311 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12002312
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002313 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes37367e62015-05-25 11:13:29 +12002314 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
2315 FAIL() << "Incorrect warning: " << msgString;
2316 }
2317}
2318
Chris Forbesa4b02322015-05-25 11:13:31 +12002319TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
2320{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002321 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12002322 std::string msgString;
2323 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002324 ScopedUseGlsl useGlsl(false);
Chris Forbesa4b02322015-05-25 11:13:31 +12002325
2326 VkVertexInputBindingDescription input_binding;
2327 memset(&input_binding, 0, sizeof(input_binding));
2328
2329 VkVertexInputAttributeDescription input_attrib;
2330 memset(&input_attrib, 0, sizeof(input_attrib));
2331 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2332
2333 char const *vsSource =
2334 "#version 140\n"
2335 "#extension GL_ARB_separate_shader_objects: require\n"
2336 "#extension GL_ARB_shading_language_420pack: require\n"
2337 "\n"
2338 "layout(location=0) in int x;\n" /* attrib provided float */
2339 "void main(){\n"
2340 " gl_Position = vec4(x);\n"
2341 "}\n";
2342 char const *fsSource =
2343 "#version 140\n"
2344 "#extension GL_ARB_separate_shader_objects: require\n"
2345 "#extension GL_ARB_shading_language_420pack: require\n"
2346 "\n"
2347 "layout(location=0) out vec4 color;\n"
2348 "void main(){\n"
2349 " color = vec4(1);\n"
2350 "}\n";
2351
2352 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2353 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2354
2355 VkPipelineObj pipe(m_device);
2356 pipe.AddShader(&vs);
2357 pipe.AddShader(&fs);
2358
2359 pipe.AddVertexInputBindings(&input_binding, 1);
2360 pipe.AddVertexInputAttribs(&input_attrib, 1);
2361
2362 VkCommandBufferObj dummyCmd(m_device);
2363 VkDescriptorSetObj descriptorSet(m_device);
2364 descriptorSet.AppendDummy();
2365 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2366
2367 m_errorMonitor->ClearState();
2368 pipe.CreateVKPipeline(descriptorSet);
2369
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002370 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12002371
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002372 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbesa4b02322015-05-25 11:13:31 +12002373 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
2374 FAIL() << "Incorrect error: " << msgString;
2375 }
2376}
2377
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002378TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
2379{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002380 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002381 std::string msgString;
2382 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002383 ScopedUseGlsl useGlsl(false);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002384
2385 /* Two binding descriptions for binding 0 */
2386 VkVertexInputBindingDescription input_bindings[2];
2387 memset(input_bindings, 0, sizeof(input_bindings));
2388
2389 VkVertexInputAttributeDescription input_attrib;
2390 memset(&input_attrib, 0, sizeof(input_attrib));
2391 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2392
2393 char const *vsSource =
2394 "#version 140\n"
2395 "#extension GL_ARB_separate_shader_objects: require\n"
2396 "#extension GL_ARB_shading_language_420pack: require\n"
2397 "\n"
2398 "layout(location=0) in float x;\n" /* attrib provided float */
2399 "void main(){\n"
2400 " gl_Position = vec4(x);\n"
2401 "}\n";
2402 char const *fsSource =
2403 "#version 140\n"
2404 "#extension GL_ARB_separate_shader_objects: require\n"
2405 "#extension GL_ARB_shading_language_420pack: require\n"
2406 "\n"
2407 "layout(location=0) out vec4 color;\n"
2408 "void main(){\n"
2409 " color = vec4(1);\n"
2410 "}\n";
2411
2412 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2413 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2414
2415 VkPipelineObj pipe(m_device);
2416 pipe.AddShader(&vs);
2417 pipe.AddShader(&fs);
2418
2419 pipe.AddVertexInputBindings(input_bindings, 2);
2420 pipe.AddVertexInputAttribs(&input_attrib, 1);
2421
2422 VkCommandBufferObj dummyCmd(m_device);
2423 VkDescriptorSetObj descriptorSet(m_device);
2424 descriptorSet.AppendDummy();
2425 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2426
2427 m_errorMonitor->ClearState();
2428 pipe.CreateVKPipeline(descriptorSet);
2429
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002430 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002431
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002432 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002433 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
2434 FAIL() << "Incorrect error: " << msgString;
2435 }
2436}
Chris Forbes4c948702015-05-25 11:13:32 +12002437
Chris Forbesc12ef122015-05-25 11:13:40 +12002438/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
2439 * rejects it. */
2440
2441TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
2442{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002443 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12002444 std::string msgString;
2445 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002446 ScopedUseGlsl useGlsl(false);
Chris Forbesc12ef122015-05-25 11:13:40 +12002447
2448 char const *vsSource =
2449 "#version 140\n"
2450 "#extension GL_ARB_separate_shader_objects: require\n"
2451 "#extension GL_ARB_shading_language_420pack: require\n"
2452 "\n"
2453 "void main(){\n"
2454 " gl_Position = vec4(1);\n"
2455 "}\n";
2456 char const *fsSource =
2457 "#version 140\n"
2458 "#extension GL_ARB_separate_shader_objects: require\n"
2459 "#extension GL_ARB_shading_language_420pack: require\n"
2460 "\n"
2461 "void main(){\n"
2462 "}\n";
2463
2464 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2465 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2466
2467 VkPipelineObj pipe(m_device);
2468 pipe.AddShader(&vs);
2469 pipe.AddShader(&fs);
2470
2471 /* implicit CB 0 set up by the test framework, not written */
2472
2473 VkCommandBufferObj dummyCmd(m_device);
2474 VkDescriptorSetObj descriptorSet(m_device);
2475 descriptorSet.AppendDummy();
2476 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2477
2478 m_errorMonitor->ClearState();
2479 pipe.CreateVKPipeline(descriptorSet);
2480
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002481 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12002482
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002483 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbesc12ef122015-05-25 11:13:40 +12002484 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
2485 FAIL() << "Incorrect error: " << msgString;
2486 }
2487}
2488
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002489TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
2490{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002491 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002492 std::string msgString;
2493 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002494 ScopedUseGlsl useGlsl(false);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002495
2496 char const *vsSource =
2497 "#version 140\n"
2498 "#extension GL_ARB_separate_shader_objects: require\n"
2499 "#extension GL_ARB_shading_language_420pack: require\n"
2500 "\n"
2501 "void main(){\n"
2502 " gl_Position = vec4(1);\n"
2503 "}\n";
2504 char const *fsSource =
2505 "#version 140\n"
2506 "#extension GL_ARB_separate_shader_objects: require\n"
2507 "#extension GL_ARB_shading_language_420pack: require\n"
2508 "\n"
2509 "layout(location=0) out vec4 x;\n"
2510 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
2511 "void main(){\n"
2512 " x = vec4(1);\n"
2513 " y = vec4(1);\n"
2514 "}\n";
2515
2516 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2517 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2518
2519 VkPipelineObj pipe(m_device);
2520 pipe.AddShader(&vs);
2521 pipe.AddShader(&fs);
2522
2523 /* implicit CB 0 set up by the test framework */
2524 /* FS writes CB 1, but we don't configure it */
2525
2526 VkCommandBufferObj dummyCmd(m_device);
2527 VkDescriptorSetObj descriptorSet(m_device);
2528 descriptorSet.AppendDummy();
2529 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2530
2531 m_errorMonitor->ClearState();
2532 pipe.CreateVKPipeline(descriptorSet);
2533
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002534 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002535
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002536 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002537 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
2538 FAIL() << "Incorrect warning: " << msgString;
2539 }
2540}
2541
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002542TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
2543{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002544 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002545 std::string msgString;
2546 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002547 ScopedUseGlsl useGlsl(false);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002548
2549 char const *vsSource =
2550 "#version 140\n"
2551 "#extension GL_ARB_separate_shader_objects: require\n"
2552 "#extension GL_ARB_shading_language_420pack: require\n"
2553 "\n"
2554 "void main(){\n"
2555 " gl_Position = vec4(1);\n"
2556 "}\n";
2557 char const *fsSource =
2558 "#version 140\n"
2559 "#extension GL_ARB_separate_shader_objects: require\n"
2560 "#extension GL_ARB_shading_language_420pack: require\n"
2561 "\n"
2562 "layout(location=0) out ivec4 x;\n" /* not UNORM */
2563 "void main(){\n"
2564 " x = ivec4(1);\n"
2565 "}\n";
2566
2567 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2568 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2569
2570 VkPipelineObj pipe(m_device);
2571 pipe.AddShader(&vs);
2572 pipe.AddShader(&fs);
2573
2574 /* implicit CB 0 set up by test framework, is UNORM. */
2575
2576 VkCommandBufferObj dummyCmd(m_device);
2577 VkDescriptorSetObj descriptorSet(m_device);
2578 descriptorSet.AppendDummy();
2579 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2580
2581 m_errorMonitor->ClearState();
2582 pipe.CreateVKPipeline(descriptorSet);
2583
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002584 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002585
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002586 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002587 if (!strstr(msgString.c_str(),"does not match FS output type")) {
2588 FAIL() << "Incorrect error: " << msgString;
2589 }
2590}
Chris Forbesc2050732015-06-05 14:43:36 +12002591
2592TEST_F(VkLayerTest, CreatePipelineNonSpirvShader)
2593{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002594 VkFlags msgFlags;
Chris Forbesc2050732015-06-05 14:43:36 +12002595 std::string msgString;
2596 ASSERT_NO_FATAL_FAILURE(InitState());
2597 /* Intentionally provided GLSL rather than compiling to SPIRV first */
Cody Northrop1cfbd172015-06-03 16:49:20 -06002598 ScopedUseGlsl useGlsl(true);
Chris Forbesc2050732015-06-05 14:43:36 +12002599
2600 char const *vsSource =
2601 "#version 140\n"
2602 "#extension GL_ARB_separate_shader_objects: require\n"
2603 "#extension GL_ARB_shading_language_420pack: require\n"
2604 "\n"
2605 "void main(){\n"
2606 " gl_Position = vec4(1);\n"
2607 "}\n";
2608 char const *fsSource =
2609 "#version 140\n"
2610 "#extension GL_ARB_separate_shader_objects: require\n"
2611 "#extension GL_ARB_shading_language_420pack: require\n"
2612 "\n"
2613 "layout(location=0) out vec4 x;\n"
2614 "void main(){\n"
2615 " x = vec4(1);\n"
2616 "}\n";
2617
2618 m_errorMonitor->ClearState();
2619
2620 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2621 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2622
2623
2624 VkPipelineObj pipe(m_device);
2625 pipe.AddShader(&vs);
2626 pipe.AddShader(&fs);
2627
2628 /* implicit CB 0 set up by test framework, is UNORM. */
2629
2630 VkCommandBufferObj dummyCmd(m_device);
2631 VkDescriptorSetObj descriptorSet(m_device);
2632 descriptorSet.AppendDummy();
2633 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2634
2635 VkResult res = pipe.CreateVKPipeline(descriptorSet);
2636 /* pipeline creation should have succeeded */
2637 ASSERT_EQ(VK_SUCCESS, res);
2638
2639 /* should have emitted a warning: the shader is not SPIRV, so we're
2640 * not going to be able to analyze it */
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002641 msgFlags = m_errorMonitor->GetState(&msgString);
2642 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesc2050732015-06-05 14:43:36 +12002643 if (!strstr(msgString.c_str(),"is not SPIR-V")) {
2644 FAIL() << "Incorrect warning: " << msgString;
2645 }
2646}
Chris Forbes01c9db72015-06-04 09:25:25 +12002647#endif
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002648
Tony Barbour30486ea2015-04-07 13:44:53 -06002649int main(int argc, char **argv) {
2650 int result;
2651
2652 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06002653 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06002654
2655 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
2656
2657 result = RUN_ALL_TESTS();
2658
Tony Barbour01999182015-04-09 12:58:51 -06002659 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06002660 return result;
2661}