blob: 84dc7b4c9b788caf67b52547c233c74cebad09c4 [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"
Tobin Ehlis56d204a2015-07-03 10:15:26 -06005#include "vk_layer_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(
Tony Barboure84a8d62015-07-10 14:10:27 -060064 VkFlags msgFlags,
65 VkDbgObjectType objType,
66 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060067 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 Stroyan7016f4f2015-07-13 14:45:35 -060077 test_platform_thread_create_mutex(&m_mutex);
78 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060079 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mike Stroyan09aae812015-05-12 16:00:45 -060080 m_bailout = NULL;
Mike Stroyan7016f4f2015-07-13 14:45:35 -060081 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060082 }
83 void ClearState()
84 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060085 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060086 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -060087 m_msgString.clear();
Mike Stroyan7016f4f2015-07-13 14:45:35 -060088 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060089 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060090 VkFlags GetState(std::string *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -060091 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060092 test_platform_thread_lock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060093 *msgString = m_msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -060094 test_platform_thread_unlock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060095 return m_msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -060096 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060097 void SetState(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -060098 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060099 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600100 if (m_bailout != NULL) {
101 *m_bailout = true;
102 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600103 m_msgFlags = msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600104 m_msgString.reserve(strlen(msgString));
105 m_msgString = msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600106 test_platform_thread_unlock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600107 }
108 void SetBailout(bool *bailout)
109 {
110 m_bailout = bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600111 }
112
113private:
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600114 VkFlags m_msgFlags;
115 std::string m_msgString;
116 test_platform_thread_mutex m_mutex;
117 bool* m_bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600118};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500119
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600120static void myDbgFunc(
121 VkFlags msgFlags,
Tony Barboure84a8d62015-07-10 14:10:27 -0600122 VkDbgObjectType objType,
123 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600124 size_t location,
125 int32_t msgCode,
126 const char* pLayerPrefix,
127 const char* pMsg,
128 void* pUserData)
Tony Barbour30486ea2015-04-07 13:44:53 -0600129{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600130 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour8508b8e2015-04-09 10:48:04 -0600131 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600132 errMonitor->SetState(msgFlags, pMsg);
Tony Barbour8508b8e2015-04-09 10:48:04 -0600133 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600134}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500135
Tony Barbour01999182015-04-09 12:58:51 -0600136class VkLayerTest : public VkRenderFramework
Tony Barbour30486ea2015-04-07 13:44:53 -0600137{
138public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600139 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
140 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500141 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
142 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbour30486ea2015-04-07 13:44:53 -0600143
144protected:
Tony Barbour01999182015-04-09 12:58:51 -0600145 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600146
147 virtual void SetUp() {
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600148 std::vector<const char *> instance_layer_names;
149 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600150 std::vector<const char *> instance_extension_names;
151 std::vector<const char *> device_extension_names;
Tony Barbour950ebc02015-04-23 12:55:36 -0600152
Courtney Goeltzenleuchter846298c2015-07-30 11:32:46 -0600153 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600154 /*
155 * Since CreateDbgMsgCallback is an instance level extension call
156 * any extension / layer that utilizes that feature also needs
157 * to be enabled at create instance time.
158 */
Mike Stroyaned254572015-06-17 16:32:06 -0600159 // Use Threading layer first to protect others from ThreadCmdBufferCollision test
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600160 instance_layer_names.push_back("Threading");
161 instance_layer_names.push_back("ObjectTracker");
162 instance_layer_names.push_back("MemTracker");
163 instance_layer_names.push_back("DrawState");
164 instance_layer_names.push_back("ShaderChecker");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600165
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600166 device_layer_names.push_back("Threading");
167 device_layer_names.push_back("ObjectTracker");
168 device_layer_names.push_back("MemTracker");
169 device_layer_names.push_back("DrawState");
170 device_layer_names.push_back("ShaderChecker");
Tony Barbour30486ea2015-04-07 13:44:53 -0600171
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600172 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -0600173 this->app_info.pNext = NULL;
174 this->app_info.pAppName = "layer_tests";
175 this->app_info.appVersion = 1;
176 this->app_info.pEngineName = "unittest";
177 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600178 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -0600179
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600180 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600181 InitFramework(instance_layer_names, device_layer_names,
182 instance_extension_names, device_extension_names,
183 myDbgFunc, m_errorMonitor);
Tony Barbour30486ea2015-04-07 13:44:53 -0600184 }
185
186 virtual void TearDown() {
187 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600188 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600189 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600190 }
191};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500192
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600193VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600194{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600195 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600196
197 result = cmdBuffer.BeginCommandBuffer();
198
199 /*
200 * For render test all drawing happens in a single render pass
201 * on a single command buffer.
202 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200203 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wuc278df82015-07-07 11:50:03 +0800204 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour30486ea2015-04-07 13:44:53 -0600205 }
206
207 return result;
208}
209
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600210VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600211{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600212 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600213
Chris Forbesfe133ef2015-06-16 14:05:59 +1200214 if (renderPass()) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800215 cmdBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200216 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600217
218 result = cmdBuffer.EndCommandBuffer();
219
220 return result;
221}
222
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500223void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
224{
225 // Create identity matrix
226 int i;
227 struct vktriangle_vs_uniform data;
228
229 glm::mat4 Projection = glm::mat4(1.0f);
230 glm::mat4 View = glm::mat4(1.0f);
231 glm::mat4 Model = glm::mat4(1.0f);
232 glm::mat4 MVP = Projection * View * Model;
233 const int matrixSize = sizeof(MVP);
234 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
235
236 memcpy(&data.mvp, &MVP[0][0], matrixSize);
237
238 static const Vertex tri_data[] =
239 {
240 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
241 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
242 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
243 };
244
245 for (i=0; i<3; i++) {
246 data.position[i][0] = tri_data[i].posX;
247 data.position[i][1] = tri_data[i].posY;
248 data.position[i][2] = tri_data[i].posZ;
249 data.position[i][3] = tri_data[i].posW;
250 data.color[i][0] = tri_data[i].r;
251 data.color[i][1] = tri_data[i].g;
252 data.color[i][2] = tri_data[i].b;
253 data.color[i][3] = tri_data[i].a;
254 }
255
256 ASSERT_NO_FATAL_FAILURE(InitState());
257 ASSERT_NO_FATAL_FAILURE(InitViewport());
258
259 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
260
261 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
262 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
263
264 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800265 pipelineobj.AddColorAttachment();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500266 pipelineobj.AddShader(&vs);
267 pipelineobj.AddShader(&ps);
268
269 VkDescriptorSetObj descriptorSet(m_device);
270 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
271
272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
273 VkCommandBufferObj cmdBuffer(m_device);
274 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
275
276 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
277
278 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet, failMask);
279
280 // render triangle
281 cmdBuffer.Draw(0, 3, 0, 1);
282
283 // finalize recording of the command buffer
284 EndCommandBuffer(cmdBuffer);
285
286 cmdBuffer.QueueCommandBuffer();
287}
288
289void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
290{
291 if (m_depthStencil->Initialized()) {
292 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
293 } else {
294 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
295 }
296
297 cmdBuffer->PrepareAttachments();
298 if ((failMask & BsoFailRaster) != BsoFailRaster) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600299 cmdBuffer->BindDynamicRasterState(m_stateRaster);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500300 }
301 if ((failMask & BsoFailViewport) != BsoFailViewport) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600302 cmdBuffer->BindDynamicViewportState(m_stateViewport);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500303 }
304 if ((failMask & BsoFailColorBlend) != BsoFailColorBlend) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600305 cmdBuffer->BindDynamicColorBlendState(m_colorBlend);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500306 }
307 if ((failMask & BsoFailDepthStencil) != BsoFailDepthStencil) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600308 cmdBuffer->BindDynamicDepthStencilState(m_stateDepthStencil);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500309 }
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600310 // Make sure depthWriteEnable is set so that DepthStencil fail test will work correctly
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600311 VkStencilOpState stencil = {};
312 stencil.stencilFailOp = VK_STENCIL_OP_KEEP;
313 stencil.stencilPassOp = VK_STENCIL_OP_KEEP;
314 stencil.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
315 stencil.stencilCompareOp = VK_COMPARE_OP_NEVER;
316
317 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
318 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
319 ds_ci.pNext = NULL;
320 ds_ci.depthTestEnable = VK_FALSE;
321 ds_ci.depthWriteEnable = VK_TRUE;
322 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
323 ds_ci.depthBoundsEnable = VK_FALSE;
324 ds_ci.stencilTestEnable = VK_FALSE;
325 ds_ci.front = stencil;
326 ds_ci.back = stencil;
327
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600328 pipelineobj.SetDepthStencil(&ds_ci);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500329 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Chia-I Wuc278df82015-07-07 11:50:03 +0800330 pipelineobj.CreateVKPipeline(descriptorSet, renderPass());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500331 cmdBuffer->BindPipeline(pipelineobj);
332 cmdBuffer->BindDescriptorSet(descriptorSet);
333}
334
335// ********************************************************************************************************************
336// ********************************************************************************************************************
337// ********************************************************************************************************************
338// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600339#if MEM_TRACKER_TESTS
Mark Lobodzinski81078192015-05-19 10:28:29 -0500340TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
341{
342 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600343 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500344 std::string msgString;
345
346 VkFenceCreateInfo fenceInfo = {};
347 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
348 fenceInfo.pNext = NULL;
349 fenceInfo.flags = 0;
350
351 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barboure389b882015-07-20 13:00:10 -0600352
353 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
354 vk_testing::Buffer buffer;
355 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500356
357 VkCommandBufferObj cmdBuffer(m_device);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500358 BeginCommandBuffer(cmdBuffer);
Tony Barboure389b882015-07-20 13:00:10 -0600359 cmdBuffer.FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500360 EndCommandBuffer(cmdBuffer);
361
362 testFence.init(*m_device, fenceInfo);
363
364 // Bypass framework since it does the waits automatically
365 VkResult err = VK_SUCCESS;
Chia-I Wu78c2a352015-07-03 11:49:42 +0800366 err = vkQueueSubmit( m_device->m_queue, 1, &cmdBuffer.handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500367 ASSERT_VK_SUCCESS( err );
368
369 m_errorMonitor->ClearState();
370 // Introduce failure by calling begin again before checking fence
Cody Northropf02f9f82015-07-09 18:08:05 -0600371 vkResetCommandBuffer(cmdBuffer.handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500372
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600373 msgFlags = m_errorMonitor->GetState(&msgString);
374 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 -0500375 if (!strstr(msgString.c_str(),"Resetting CB")) {
376 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
377 }
378}
379
380TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion)
381{
382 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600383 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500384 std::string msgString;
385
386 VkFenceCreateInfo fenceInfo = {};
387 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
388 fenceInfo.pNext = NULL;
389 fenceInfo.flags = 0;
390
391 ASSERT_NO_FATAL_FAILURE(InitState());
392 ASSERT_NO_FATAL_FAILURE(InitViewport());
393 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
394
395 VkCommandBufferObj cmdBuffer(m_device);
396 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
397
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600398 cmdBuffer.BeginCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500399 cmdBuffer.ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600400 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500401
402 testFence.init(*m_device, fenceInfo);
403
404 // Bypass framework since it does the waits automatically
405 VkResult err = VK_SUCCESS;
Chia-I Wu78c2a352015-07-03 11:49:42 +0800406 err = vkQueueSubmit( m_device->m_queue, 1, &cmdBuffer.handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500407 ASSERT_VK_SUCCESS( err );
408
409 m_errorMonitor->ClearState();
410 // Introduce failure by calling begin again before checking fence
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600411 cmdBuffer.BeginCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500412
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600413 msgFlags = m_errorMonitor->GetState(&msgString);
414 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 -0500415 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
416 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
417 }
418}
419
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500420TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
421{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600422 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500423 std::string msgString;
424 VkResult err;
425
426 ASSERT_NO_FATAL_FAILURE(InitState());
427 m_errorMonitor->ClearState();
428
429 // Create an image, allocate memory, free it, and then try to bind it
430 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500431 VkDeviceMemory mem;
432 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500433
434 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
435 const int32_t tex_width = 32;
436 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500437
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600438 VkImageCreateInfo image_create_info = {};
439 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
440 image_create_info.pNext = NULL;
441 image_create_info.imageType = VK_IMAGE_TYPE_2D;
442 image_create_info.format = tex_format;
443 image_create_info.extent.width = tex_width;
444 image_create_info.extent.height = tex_height;
445 image_create_info.extent.depth = 1;
446 image_create_info.mipLevels = 1;
447 image_create_info.arraySize = 1;
448 image_create_info.samples = 1;
449 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
450 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
451 image_create_info.flags = 0;
452
453 VkMemoryAllocInfo mem_alloc = {};
454 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
455 mem_alloc.pNext = NULL;
456 mem_alloc.allocationSize = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500457 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600458 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500459
460 err = vkCreateImage(m_device->device(), &image_create_info, &image);
461 ASSERT_VK_SUCCESS(err);
462
Tony Barboure84a8d62015-07-10 14:10:27 -0600463 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500464 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500465 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500466 ASSERT_VK_SUCCESS(err);
467
Mark Lobodzinski23182612015-05-29 09:32:35 -0500468 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500469
470 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500471 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500472 ASSERT_VK_SUCCESS(err);
473
474 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600475 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500476 ASSERT_VK_SUCCESS(err);
477
478 // Map memory as if to initialize the image
479 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500480 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500481
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600482 msgFlags = m_errorMonitor->GetState(&msgString);
483 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 -0500484 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
485 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
486 }
487}
488
489TEST_F(VkLayerTest, BindInvalidMemory)
490{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600491 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500492 std::string msgString;
493 VkResult err;
494
495 ASSERT_NO_FATAL_FAILURE(InitState());
496 m_errorMonitor->ClearState();
497
498 // Create an image, allocate memory, free it, and then try to bind it
499 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500500 VkDeviceMemory mem;
501 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500502
503 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
504 const int32_t tex_width = 32;
505 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500506
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600507 VkImageCreateInfo image_create_info = {};
508 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
509 image_create_info.pNext = NULL;
510 image_create_info.imageType = VK_IMAGE_TYPE_2D;
511 image_create_info.format = tex_format;
512 image_create_info.extent.width = tex_width;
513 image_create_info.extent.height = tex_height;
514 image_create_info.extent.depth = 1;
515 image_create_info.mipLevels = 1;
516 image_create_info.arraySize = 1;
517 image_create_info.samples = 1;
518 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
519 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
520 image_create_info.flags = 0;
521
522 VkMemoryAllocInfo mem_alloc = {};
523 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
524 mem_alloc.pNext = NULL;
525 mem_alloc.allocationSize = 0;
526 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500527
528 err = vkCreateImage(m_device->device(), &image_create_info, &image);
529 ASSERT_VK_SUCCESS(err);
530
Tony Barboure84a8d62015-07-10 14:10:27 -0600531 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500532 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500533 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500534 ASSERT_VK_SUCCESS(err);
535
Mark Lobodzinski23182612015-05-29 09:32:35 -0500536 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500537
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800538 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600539 ASSERT_VK_SUCCESS(err);
540
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500541 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500542 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500543 ASSERT_VK_SUCCESS(err);
544
545 // Introduce validation failure, free memory before binding
Mark Lobodzinski23182612015-05-29 09:32:35 -0500546 vkFreeMemory(m_device->device(), mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500547 ASSERT_VK_SUCCESS(err);
548
549 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600550 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500551 ASSERT_VK_SUCCESS(err);
552
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600553 msgFlags = m_errorMonitor->GetState(&msgString);
554 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 -0500555 if (!strstr(msgString.c_str(),"couldn't find info for mem obj")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500556 FAIL() << "Error received did not match expected error message from BindObjectMemory in MemTracker";
557 }
558}
559
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600560// TODO : Is this test still valid. Not sure it is with updates to memory binding model
561// Verify and delete the test of fix the check
562//TEST_F(VkLayerTest, FreeBoundMemory)
563//{
564// VkFlags msgFlags;
565// std::string msgString;
566// VkResult err;
567//
568// ASSERT_NO_FATAL_FAILURE(InitState());
569// m_errorMonitor->ClearState();
570//
571// // Create an image, allocate memory, free it, and then try to bind it
572// VkImage image;
573// VkDeviceMemory mem;
574// VkMemoryRequirements mem_reqs;
575//
576// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
577// const int32_t tex_width = 32;
578// const int32_t tex_height = 32;
579//
580// const VkImageCreateInfo image_create_info = {
581// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
582// .pNext = NULL,
583// .imageType = VK_IMAGE_TYPE_2D,
584// .format = tex_format,
585// .extent = { tex_width, tex_height, 1 },
586// .mipLevels = 1,
587// .arraySize = 1,
588// .samples = 1,
589// .tiling = VK_IMAGE_TILING_LINEAR,
590// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
591// .flags = 0,
592// };
593// VkMemoryAllocInfo mem_alloc = {
594// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
595// .pNext = NULL,
596// .allocationSize = 0,
597// .memoryTypeIndex = 0,
598// };
599//
600// err = vkCreateImage(m_device->device(), &image_create_info, &image);
601// ASSERT_VK_SUCCESS(err);
602//
603// err = vkGetImageMemoryRequirements(m_device->device(),
604// image,
605// &mem_reqs);
606// ASSERT_VK_SUCCESS(err);
607//
608// mem_alloc.allocationSize = mem_reqs.size;
609//
610// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
611// ASSERT_VK_SUCCESS(err);
612//
613// // allocate memory
614// err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
615// ASSERT_VK_SUCCESS(err);
616//
617// // Bind memory to Image object
618// err = vkBindImageMemory(m_device->device(), image, mem, 0);
619// ASSERT_VK_SUCCESS(err);
620//
621// // Introduce validation failure, free memory while still bound to object
622// vkFreeMemory(m_device->device(), mem);
623// ASSERT_VK_SUCCESS(err);
624//
625// msgFlags = m_errorMonitor->GetState(&msgString);
626// ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an warning while tring to free bound memory";
627// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
628// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
629// }
630//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500631
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500632TEST_F(VkLayerTest, RebindMemory)
633{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600634 VkFlags msgFlags;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500635 std::string msgString;
636 VkResult err;
637
638 ASSERT_NO_FATAL_FAILURE(InitState());
639 m_errorMonitor->ClearState();
640
641 // Create an image, allocate memory, free it, and then try to bind it
642 VkImage image;
643 VkDeviceMemory mem1;
644 VkDeviceMemory mem2;
645 VkMemoryRequirements mem_reqs;
646
647 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
648 const int32_t tex_width = 32;
649 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500650
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600651 VkImageCreateInfo image_create_info = {};
652 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
653 image_create_info.pNext = NULL;
654 image_create_info.imageType = VK_IMAGE_TYPE_2D;
655 image_create_info.format = tex_format;
656 image_create_info.extent.width = tex_width;
657 image_create_info.extent.height = tex_height;
658 image_create_info.extent.depth = 1;
659 image_create_info.mipLevels = 1;
660 image_create_info.arraySize = 1;
661 image_create_info.samples = 1;
662 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
663 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
664 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500665
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600666 VkMemoryAllocInfo mem_alloc = {};
667 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
668 mem_alloc.pNext = NULL;
669 mem_alloc.allocationSize = 0;
670 mem_alloc.memoryTypeIndex = 0;
671
672 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
673 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500674 err = vkCreateImage(m_device->device(), &image_create_info, &image);
675 ASSERT_VK_SUCCESS(err);
676
Tony Barboure84a8d62015-07-10 14:10:27 -0600677 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500678 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500679 &mem_reqs);
680 ASSERT_VK_SUCCESS(err);
681
682 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800683 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600684 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500685
686 // allocate 2 memory objects
687 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
688 ASSERT_VK_SUCCESS(err);
689 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
690 ASSERT_VK_SUCCESS(err);
691
692 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600693 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500694 ASSERT_VK_SUCCESS(err);
695
696 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600697 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500698 ASSERT_VK_SUCCESS(err);
699
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600700 msgFlags = m_errorMonitor->GetState(&msgString);
701 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 -0500702 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
703 FAIL() << "Error received did not match expected message when rebinding memory to an object";
704 }
705}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500706
707TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
708{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600709 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500710 std::string msgString;
711 VkResult err;
712
713 ASSERT_NO_FATAL_FAILURE(InitState());
714 m_errorMonitor->ClearState();
715
716 // Create an image object, allocate memory, destroy the object and then try to bind it
717 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500718 VkDeviceMemory mem;
719 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500720
721 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
722 const int32_t tex_width = 32;
723 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500724
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600725 VkImageCreateInfo image_create_info = {};
726 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
727 image_create_info.pNext = NULL;
728 image_create_info.imageType = VK_IMAGE_TYPE_2D;
729 image_create_info.format = tex_format;
730 image_create_info.extent.width = tex_width;
731 image_create_info.extent.height = tex_height;
732 image_create_info.extent.depth = 1;
733 image_create_info.mipLevels = 1;
734 image_create_info.arraySize = 1;
735 image_create_info.samples = 1;
736 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
737 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
738 image_create_info.flags = 0;
739
740 VkMemoryAllocInfo mem_alloc = {};
741 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
742 mem_alloc.pNext = NULL;
743 mem_alloc.allocationSize = 0;
744 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500745
746 err = vkCreateImage(m_device->device(), &image_create_info, &image);
747 ASSERT_VK_SUCCESS(err);
748
Tony Barboure84a8d62015-07-10 14:10:27 -0600749 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500750 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500751 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500752 ASSERT_VK_SUCCESS(err);
753
Mark Lobodzinski23182612015-05-29 09:32:35 -0500754 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800755 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600756 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500757
758 // Allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500759 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500760 ASSERT_VK_SUCCESS(err);
761
762 // Introduce validation failure, destroy Image object before binding
Tony Barboure84a8d62015-07-10 14:10:27 -0600763 vkDestroyImage(m_device->device(), image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500764 ASSERT_VK_SUCCESS(err);
765
766 // Now Try to bind memory to this destroyted object
Tony Barboure84a8d62015-07-10 14:10:27 -0600767 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500768 ASSERT_VK_SUCCESS(err);
769
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600770 msgFlags = m_errorMonitor->GetState(&msgString);
771 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 -0500772 if (!strstr(msgString.c_str(),"that's not in global list")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500773 FAIL() << "Error received did not match expected error message from updateObjectBinding in MemTracker";
774 }
775}
776
Tony Barbour8508b8e2015-04-09 10:48:04 -0600777TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600778{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600779 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600780 VkFlags msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600781 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600782
783 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600784 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
785 fenceInfo.pNext = NULL;
786 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600787
Tony Barbour30486ea2015-04-07 13:44:53 -0600788 ASSERT_NO_FATAL_FAILURE(InitState());
789 ASSERT_NO_FATAL_FAILURE(InitViewport());
790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
791
Tony Barbour01999182015-04-09 12:58:51 -0600792 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour30486ea2015-04-07 13:44:53 -0600793 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
794
Tony Barbour8508b8e2015-04-09 10:48:04 -0600795 BeginCommandBuffer(cmdBuffer);
Tony Barbour30486ea2015-04-07 13:44:53 -0600796 cmdBuffer.ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour8508b8e2015-04-09 10:48:04 -0600797 EndCommandBuffer(cmdBuffer);
Tony Barbour30486ea2015-04-07 13:44:53 -0600798
799 testFence.init(*m_device, fenceInfo);
800 m_errorMonitor->ClearState();
Chia-I Wua4992342015-07-03 11:45:55 +0800801 cmdBuffer.QueueCommandBuffer(testFence.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600802 msgFlags = m_errorMonitor->GetState(&msgString);
803 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 -0600804 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500805 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600806 }
807
808}
809
810TEST_F(VkLayerTest, ResetUnsignaledFence)
811{
812 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600813 VkFlags msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600814 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600815 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600816 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
817 fenceInfo.pNext = NULL;
818
Tony Barbour8508b8e2015-04-09 10:48:04 -0600819 ASSERT_NO_FATAL_FAILURE(InitState());
820 testFence.init(*m_device, fenceInfo);
821 m_errorMonitor->ClearState();
Chia-I Wua4992342015-07-03 11:45:55 +0800822 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600823 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600824 msgFlags = m_errorMonitor->GetState(&msgString);
825 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 -0600826 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500827 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600828 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600829
830}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600831
Chia-I Wuc278df82015-07-07 11:50:03 +0800832/* TODO: Update for changes due to bug-14075 tiling across render passes */
833#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600834TEST_F(VkLayerTest, InvalidUsageBits)
835{
836 // Initiate Draw w/o a PSO bound
837 VkFlags msgFlags;
838 std::string msgString;
839
840 ASSERT_NO_FATAL_FAILURE(InitState());
841 m_errorMonitor->ClearState();
842 VkCommandBufferObj cmdBuffer(m_device);
843 BeginCommandBuffer(cmdBuffer);
844
845 const VkExtent3D e3d = {
846 .width = 128,
847 .height = 128,
848 .depth = 1,
849 };
850 const VkImageCreateInfo ici = {
851 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
852 .pNext = NULL,
853 .imageType = VK_IMAGE_TYPE_2D,
854 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
855 .extent = e3d,
856 .mipLevels = 1,
857 .arraySize = 1,
858 .samples = 1,
859 .tiling = VK_IMAGE_TILING_LINEAR,
860 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_BIT
861 .flags = 0,
862 };
863
864 VkImage dsi;
865 vkCreateImage(m_device->device(), &ici, &dsi);
866 VkDepthStencilView dsv;
867 const VkDepthStencilViewCreateInfo dsvci = {
868 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
869 .pNext = NULL,
870 .image = dsi,
871 .mipLevel = 0,
872 .baseArraySlice = 0,
873 .arraySize = 1,
874 .flags = 0,
875 };
876 vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv);
877 msgFlags = m_errorMonitor->GetState(&msgString);
878 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after attempting to create DSView w/ image lacking USAGE_DS_BIT flag";
879 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
880 FAIL() << "Error received was not 'Invalid usage flag for image...'";
881 }
882}
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600883#endif
Chia-I Wuc278df82015-07-07 11:50:03 +0800884#endif
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600885#if OBJ_TRACKER_TESTS
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500886TEST_F(VkLayerTest, RasterStateNotBound)
887{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600888 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500889 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600890 ASSERT_NO_FATAL_FAILURE(InitState());
891 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500892 TEST_DESCRIPTION("Simple Draw Call that validates failure when a raster state object is not bound beforehand");
893
894 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailRaster);
895
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600896 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600897 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 -0500898 if (!strstr(msgString.c_str(),"Raster object not bound to this command buffer")) {
899 FAIL() << "Error received was not 'Raster object not bound to this command buffer'";
900 }
901}
902
903TEST_F(VkLayerTest, ViewportStateNotBound)
904{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600905 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500906 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600907 ASSERT_NO_FATAL_FAILURE(InitState());
908 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500909 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
910
911 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
912
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600913 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600914 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 -0500915 if (!strstr(msgString.c_str(),"Viewport object not bound to this command buffer")) {
916 FAIL() << "Error received was not 'Viewport object not bound to this command buffer'";
917 }
918}
919
920TEST_F(VkLayerTest, ColorBlendStateNotBound)
921{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600922 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500923 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600924 ASSERT_NO_FATAL_FAILURE(InitState());
925 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500926 TEST_DESCRIPTION("Simple Draw Call that validates failure when a color-blend state object is not bound beforehand");
927
928 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailColorBlend);
929
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600930 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600931 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 -0500932 if (!strstr(msgString.c_str(),"Color-blend object not bound to this command buffer")) {
933 FAIL() << "Error received was not 'Color-blend object not bound to this command buffer'";
934 }
935}
936
937TEST_F(VkLayerTest, DepthStencilStateNotBound)
938{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600939 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500940 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600941 ASSERT_NO_FATAL_FAILURE(InitState());
942 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500943 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth-stencil state object is not bound beforehand");
944
945 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthStencil);
946
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600947 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600948 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 -0500949 if (!strstr(msgString.c_str(),"Depth-stencil object not bound to this command buffer")) {
950 FAIL() << "Error received was not 'Depth-stencil object not bound to this command buffer'";
951 }
Tony Barbourdb686622015-05-06 09:35:56 -0600952}
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600953#endif
954#if DRAW_STATE_TESTS
Tobin Ehlise4076782015-06-24 15:53:07 -0600955TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600956{
957 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600958 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600959 std::string msgString;
960
961 ASSERT_NO_FATAL_FAILURE(InitState());
962 m_errorMonitor->ClearState();
963 VkCommandBufferObj cmdBuffer(m_device);
964 BeginCommandBuffer(cmdBuffer);
965 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
966 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600967 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlise4076782015-06-24 15:53:07 -0600968 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding pipeline to CmdBuffer w/o active RenderPass";
969 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
970 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0xbaadb1be) without an active RenderPass'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600971 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600972}
973
974TEST_F(VkLayerTest, InvalidDescriptorPool)
975{
976 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
977 // The DS check for this is after driver has been called to validate DS internal data struct
978 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600979/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600980 std::string msgString;
981 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
982 vkResetDescriptorPool(device(), badPool);
983
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600984 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600985 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 -0600986 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
987 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
988 }*/
989}
990
991TEST_F(VkLayerTest, InvalidDescriptorSet)
992{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600993 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
994 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600995 // Create a valid cmd buffer
996 // call vkCmdBindDescriptorSets w/ false DS
997}
998
999TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1000{
1001 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1002 // The DS check for this is after driver has been called to validate DS internal data struct
1003}
1004
1005TEST_F(VkLayerTest, InvalidPipeline)
1006{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001007 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1008 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001009 // Create a valid cmd buffer
1010 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -06001011// VkFlags msgFlags;
1012// std::string msgString;
1013//
1014// ASSERT_NO_FATAL_FAILURE(InitState());
1015// m_errorMonitor->ClearState();
1016// VkCommandBufferObj cmdBuffer(m_device);
1017// BeginCommandBuffer(cmdBuffer);
1018// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1019// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1020// msgFlags = m_errorMonitor->GetState(&msgString);
1021// ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding invalid pipeline to CmdBuffer";
1022// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1023// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1024// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001025}
1026
Tobin Ehlis254eca02015-06-25 15:46:59 -06001027TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001028{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001029 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001030 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001031 std::string msgString;
1032 VkResult err;
1033
1034 ASSERT_NO_FATAL_FAILURE(InitState());
1035 m_errorMonitor->ClearState();
1036 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001037 VkDescriptorTypeCount ds_type_count = {};
1038 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1039 ds_type_count.count = 1;
1040
1041 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1042 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1043 ds_pool_ci.pNext = NULL;
1044 ds_pool_ci.count = 1;
1045 ds_pool_ci.pTypeCount = &ds_type_count;
1046
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001047 VkDescriptorPool ds_pool;
1048 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1049 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001050
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001051 VkDescriptorSetLayoutBinding dsl_binding = {};
1052 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1053 dsl_binding.arraySize = 1;
1054 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1055 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001056
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001057 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1058 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1059 ds_layout_ci.pNext = NULL;
1060 ds_layout_ci.count = 1;
1061 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001062 VkDescriptorSetLayout ds_layout;
1063 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1064 ASSERT_VK_SUCCESS(err);
1065
1066 VkDescriptorSet descriptorSet;
1067 uint32_t ds_count = 0;
1068 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1069 ASSERT_VK_SUCCESS(err);
1070
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001071 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1072 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1073 pipeline_layout_ci.pNext = NULL;
1074 pipeline_layout_ci.descriptorSetCount = 1;
1075 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001076
1077 VkPipelineLayout pipeline_layout;
1078 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1079 ASSERT_VK_SUCCESS(err);
1080
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001081 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001082
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001083 VkPipelineShaderStageCreateInfo pipe_vs_ci = {};
1084 pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1085 pipe_vs_ci.pNext = NULL;
1086 pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX;
1087 pipe_vs_ci.shader = vs.handle();
1088 pipe_vs_ci.pSpecializationInfo = NULL;
1089
1090 VkGraphicsPipelineCreateInfo gp_ci = {};
1091 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1092 gp_ci.pNext = NULL;
1093 gp_ci.stageCount = 1;
1094 gp_ci.pStages = &pipe_vs_ci;
1095 gp_ci.pVertexInputState = NULL;
1096 gp_ci.pInputAssemblyState = NULL;
1097 gp_ci.pTessellationState = NULL;
1098 gp_ci.pViewportState = NULL;
1099 gp_ci.pRasterState = NULL;
1100 gp_ci.pMultisampleState = NULL;
1101 gp_ci.pDepthStencilState = NULL;
1102 gp_ci.pColorBlendState = NULL;
1103 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1104 gp_ci.layout = pipeline_layout;
1105
1106 VkPipelineCacheCreateInfo pc_ci = {};
1107 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1108 pc_ci.pNext = NULL;
1109 pc_ci.initialSize = 0;
1110 pc_ci.initialData = 0;
1111 pc_ci.maxSize = 0;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001112
1113 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001114 VkPipelineCache pipelineCache;
1115
1116 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1117 ASSERT_VK_SUCCESS(err);
1118 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001119 ASSERT_VK_SUCCESS(err);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001120 ASSERT_NO_FATAL_FAILURE(InitState());
1121 ASSERT_NO_FATAL_FAILURE(InitViewport());
1122 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1123 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1124 BeginCommandBuffer(cmdBuffer);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001125 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06001126 vkCmdBindDescriptorSets(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001127
Tobin Ehlis254eca02015-06-25 15:46:59 -06001128 msgFlags = m_errorMonitor->GetState(&msgString);
1129 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not warn after binding a DescriptorSet that was never updated.";
1130 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1131 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1132 }
1133}
1134
1135TEST_F(VkLayerTest, NoBeginCmdBuffer)
1136{
1137 VkFlags msgFlags;
1138 std::string msgString;
1139
1140 ASSERT_NO_FATAL_FAILURE(InitState());
1141 m_errorMonitor->ClearState();
1142 VkCommandBufferObj cmdBuffer(m_device);
1143 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1144 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1145 msgFlags = m_errorMonitor->GetState(&msgString);
1146 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after ending a CmdBuffer w/o calling BeginCommandBuffer()";
1147 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1148 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1149 }
1150}
1151
1152TEST_F(VkLayerTest, InvalidPipelineCreateState)
1153{
1154 // Attempt to Create Gfx Pipeline w/o a VS
1155 VkFlags msgFlags;
1156 std::string msgString;
1157 VkResult err;
1158
1159 ASSERT_NO_FATAL_FAILURE(InitState());
1160 m_errorMonitor->ClearState();
1161 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001162
1163 VkDescriptorTypeCount ds_type_count = {};
1164 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1165 ds_type_count.count = 1;
1166
1167 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1168 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1169 ds_pool_ci.pNext = NULL;
1170 ds_pool_ci.count = 1;
1171 ds_pool_ci.pTypeCount = &ds_type_count;
1172
Tobin Ehlis254eca02015-06-25 15:46:59 -06001173 VkDescriptorPool ds_pool;
1174 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1175 ASSERT_VK_SUCCESS(err);
1176
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001177 VkDescriptorSetLayoutBinding dsl_binding = {};
1178 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1179 dsl_binding.arraySize = 1;
1180 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1181 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001182
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001183 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1184 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1185 ds_layout_ci.pNext = NULL;
1186 ds_layout_ci.count = 1;
1187 ds_layout_ci.pBinding = &dsl_binding;
1188
Tobin Ehlis254eca02015-06-25 15:46:59 -06001189 VkDescriptorSetLayout ds_layout;
1190 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1191 ASSERT_VK_SUCCESS(err);
1192
1193 VkDescriptorSet descriptorSet;
1194 uint32_t ds_count = 0;
1195 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1196 ASSERT_VK_SUCCESS(err);
1197
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001198 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1199 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1200 pipeline_layout_ci.pNext = NULL;
1201 pipeline_layout_ci.descriptorSetCount = 1;
1202 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001203
1204 VkPipelineLayout pipeline_layout;
1205 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1206 ASSERT_VK_SUCCESS(err);
1207
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001208 VkGraphicsPipelineCreateInfo gp_ci = {};
1209 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1210 gp_ci.pNext = NULL;
1211 gp_ci.stageCount = 0;
1212 gp_ci.pStages = NULL;
1213 gp_ci.pVertexInputState = NULL;
1214 gp_ci.pInputAssemblyState = NULL;
1215 gp_ci.pTessellationState = NULL;
1216 gp_ci.pViewportState = NULL;
1217 gp_ci.pRasterState = NULL;
1218 gp_ci.pMultisampleState = NULL;
1219 gp_ci.pDepthStencilState = NULL;
1220 gp_ci.pColorBlendState = NULL;
1221 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1222 gp_ci.layout = pipeline_layout;
1223
1224 VkPipelineCacheCreateInfo pc_ci = {};
1225 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1226 pc_ci.pNext = NULL;
1227 pc_ci.initialSize = 0;
1228 pc_ci.initialData = 0;
1229 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001230
1231 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001232 VkPipelineCache pipelineCache;
1233
1234 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1235 ASSERT_VK_SUCCESS(err);
1236 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001237
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001238 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001239 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after creating Gfx Pipeline w/o VS.";
1240 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1241 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1242 }
1243}
1244
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001245TEST_F(VkLayerTest, NullRenderPass)
1246{
1247 // Bind a NULL RenderPass
1248 VkFlags msgFlags;
1249 std::string msgString;
1250
1251 ASSERT_NO_FATAL_FAILURE(InitState());
1252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1253 m_errorMonitor->ClearState();
1254 VkCommandBufferObj cmdBuffer(m_device);
1255
1256 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1257 BeginCommandBuffer(cmdBuffer);
1258 // Don't care about RenderPass handle b/c error should be flagged before that
Chia-I Wuc278df82015-07-07 11:50:03 +08001259 vkCmdBeginRenderPass(cmdBuffer.GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001260
1261 msgFlags = m_errorMonitor->GetState(&msgString);
1262 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding NULL RenderPass.";
1263 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
1264 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
1265 }
1266}
1267
Tobin Ehlis254eca02015-06-25 15:46:59 -06001268TEST_F(VkLayerTest, RenderPassWithinRenderPass)
1269{
1270 // Bind a BeginRenderPass within an active RenderPass
1271 VkFlags msgFlags;
1272 std::string msgString;
1273
1274 ASSERT_NO_FATAL_FAILURE(InitState());
1275 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1276 m_errorMonitor->ClearState();
1277 VkCommandBufferObj cmdBuffer(m_device);
1278
1279 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1280 BeginCommandBuffer(cmdBuffer);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001281 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001282 VkRenderPassBeginInfo rp_begin = {};
1283 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
1284 rp_begin.pNext = NULL;
1285 rp_begin.renderPass = (VkRenderPass)0xc001d00d;
1286 rp_begin.framebuffer = 0;
1287
Chia-I Wuc278df82015-07-07 11:50:03 +08001288 vkCmdBeginRenderPass(cmdBuffer.GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001289
1290 msgFlags = m_errorMonitor->GetState(&msgString);
1291 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding RenderPass w/i an active RenderPass.";
1292 if (!strstr(msgString.c_str(),"Cannot call vkCmdBeginRenderPass() during an active RenderPass ")) {
1293 FAIL() << "Error received was not 'Cannot call vkCmdBeginRenderPass() during an active RenderPass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001294 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001295}
1296
1297TEST_F(VkLayerTest, InvalidDynamicStateObject)
1298{
1299 // Create a valid cmd buffer
1300 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001301 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1302 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001303}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06001304
Tobin Ehlise4076782015-06-24 15:53:07 -06001305TEST_F(VkLayerTest, VtxBufferNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001306{
1307 // Bind VBO out-of-bounds for given PSO
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001308 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001309 std::string msgString;
1310 VkResult err;
1311
1312 ASSERT_NO_FATAL_FAILURE(InitState());
1313 m_errorMonitor->ClearState();
1314 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001315
1316 VkDescriptorTypeCount ds_type_count = {};
1317 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1318 ds_type_count.count = 1;
1319
1320 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1321 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1322 ds_pool_ci.pNext = NULL;
1323 ds_pool_ci.count = 1;
1324 ds_pool_ci.pTypeCount = &ds_type_count;
1325
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001326 VkDescriptorPool ds_pool;
1327 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1328 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001329
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001330 VkDescriptorSetLayoutBinding dsl_binding = {};
1331 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1332 dsl_binding.arraySize = 1;
1333 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1334 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001335
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001336 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1337 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1338 ds_layout_ci.pNext = NULL;
1339 ds_layout_ci.count = 1;
1340 ds_layout_ci.pBinding = &dsl_binding;
1341
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001342 VkDescriptorSetLayout ds_layout;
1343 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1344 ASSERT_VK_SUCCESS(err);
1345
1346 VkDescriptorSet descriptorSet;
1347 uint32_t ds_count = 0;
1348 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1349 ASSERT_VK_SUCCESS(err);
1350
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001351 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1352 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1353 pipeline_layout_ci.pNext = NULL;
1354 pipeline_layout_ci.descriptorSetCount = 1;
1355 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001356
1357 VkPipelineLayout pipeline_layout;
1358 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1359 ASSERT_VK_SUCCESS(err);
1360
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001361 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001362
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001363 VkPipelineShaderStageCreateInfo pipe_vs_ci = {};
1364 pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1365 pipe_vs_ci.pNext = NULL;
1366 pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX;
1367 pipe_vs_ci.shader = vs.handle();
1368 pipe_vs_ci.pSpecializationInfo = NULL;
1369
1370 VkGraphicsPipelineCreateInfo gp_ci = {};
1371 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1372 gp_ci.pNext = NULL;
1373 gp_ci.stageCount = 1;
1374 gp_ci.pStages = &pipe_vs_ci;
1375 gp_ci.pVertexInputState = NULL;
1376 gp_ci.pInputAssemblyState = NULL;
1377 gp_ci.pTessellationState = NULL;
1378 gp_ci.pViewportState = NULL;
1379 gp_ci.pRasterState = NULL;
1380 gp_ci.pMultisampleState = NULL;
1381 gp_ci.pDepthStencilState = NULL;
1382 gp_ci.pColorBlendState = NULL;
1383 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1384 gp_ci.layout = pipeline_layout;
1385
1386 VkPipelineCacheCreateInfo pc_ci = {};
1387 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1388 pc_ci.pNext = NULL;
1389 pc_ci.initialSize = 0;
1390 pc_ci.initialData = 0;
1391 pc_ci.maxSize = 0;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001392
1393 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001394 VkPipelineCache pipelineCache;
1395
1396 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1397 ASSERT_VK_SUCCESS(err);
1398 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001399 ASSERT_VK_SUCCESS(err);
1400
1401 err= cmdBuffer.BeginCommandBuffer();
1402 ASSERT_VK_SUCCESS(err);
1403 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1404 // Should error before calling to driver so don't care about actual data
1405 vkCmdBindVertexBuffers(cmdBuffer.GetBufferHandle(), 0, 1, NULL, NULL);
1406
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001407 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlise4076782015-06-24 15:53:07 -06001408 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
1409 if (!strstr(msgString.c_str(),"Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.")) {
1410 FAIL() << "Error received was not 'Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001411 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001412}
1413
1414TEST_F(VkLayerTest, DSTypeMismatch)
1415{
1416 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001417 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001418 std::string msgString;
1419 VkResult err;
1420
1421 ASSERT_NO_FATAL_FAILURE(InitState());
1422 m_errorMonitor->ClearState();
1423 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001424 VkDescriptorTypeCount ds_type_count = {};
1425 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1426 ds_type_count.count = 1;
1427
1428 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1429 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1430 ds_pool_ci.pNext = NULL;
1431 ds_pool_ci.count = 1;
1432 ds_pool_ci.pTypeCount = &ds_type_count;
1433
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001434 VkDescriptorPool ds_pool;
1435 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1436 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001437 VkDescriptorSetLayoutBinding dsl_binding = {};
1438 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1439 dsl_binding.arraySize = 1;
1440 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1441 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001442
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001443 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1444 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1445 ds_layout_ci.pNext = NULL;
1446 ds_layout_ci.count = 1;
1447 ds_layout_ci.pBinding = &dsl_binding;
1448
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001449 VkDescriptorSetLayout ds_layout;
1450 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1451 ASSERT_VK_SUCCESS(err);
1452
1453 VkDescriptorSet descriptorSet;
1454 uint32_t ds_count = 0;
1455 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1456 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001457
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001458 VkSamplerCreateInfo sampler_ci = {};
1459 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1460 sampler_ci.pNext = NULL;
1461 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1462 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1463 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1464 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1465 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1466 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1467 sampler_ci.mipLodBias = 1.0;
1468 sampler_ci.maxAnisotropy = 1;
1469 sampler_ci.compareEnable = VK_FALSE;
1470 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1471 sampler_ci.minLod = 1.0;
1472 sampler_ci.maxLod = 1.0;
1473 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1474
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001475 VkSampler sampler;
1476 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1477 ASSERT_VK_SUCCESS(err);
1478
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001479 VkDescriptorInfo descriptor_info;
1480 memset(&descriptor_info, 0, sizeof(descriptor_info));
1481 descriptor_info.sampler = sampler;
1482
1483 VkWriteDescriptorSet descriptor_write;
1484 memset(&descriptor_write, 0, sizeof(descriptor_write));
1485 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1486 descriptor_write.destSet = descriptorSet;
1487 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001488 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001489 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1490 descriptor_write.pDescriptors = &descriptor_info;
1491
1492 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1493
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001494 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001495 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 +08001496 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) {
1497 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 -06001498 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001499}
1500
1501TEST_F(VkLayerTest, DSUpdateOutOfBounds)
1502{
1503 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001504 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001505 std::string msgString;
1506 VkResult err;
1507
1508 ASSERT_NO_FATAL_FAILURE(InitState());
1509 m_errorMonitor->ClearState();
1510 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001511 VkDescriptorTypeCount ds_type_count = {};
1512 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1513 ds_type_count.count = 1;
1514
1515 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1516 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1517 ds_pool_ci.pNext = NULL;
1518 ds_pool_ci.count = 1;
1519 ds_pool_ci.pTypeCount = &ds_type_count;
1520
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001521 VkDescriptorPool ds_pool;
1522 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1523 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001524
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001525 VkDescriptorSetLayoutBinding dsl_binding = {};
1526 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1527 dsl_binding.arraySize = 1;
1528 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1529 dsl_binding.pImmutableSamplers = NULL;
1530
1531 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1532 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1533 ds_layout_ci.pNext = NULL;
1534 ds_layout_ci.count = 1;
1535 ds_layout_ci.pBinding = &dsl_binding;
1536
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001537 VkDescriptorSetLayout ds_layout;
1538 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1539 ASSERT_VK_SUCCESS(err);
1540
1541 VkDescriptorSet descriptorSet;
1542 uint32_t ds_count = 0;
1543 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1544 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001545
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001546 VkSamplerCreateInfo sampler_ci = {};
1547 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1548 sampler_ci.pNext = NULL;
1549 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1550 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1551 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1552 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1553 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1554 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1555 sampler_ci.mipLodBias = 1.0;
1556 sampler_ci.maxAnisotropy = 1;
1557 sampler_ci.compareEnable = VK_FALSE;
1558 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1559 sampler_ci.minLod = 1.0;
1560 sampler_ci.maxLod = 1.0;
1561 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1562
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001563 VkSampler sampler;
1564 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1565 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001566
1567 VkDescriptorInfo descriptor_info;
1568 memset(&descriptor_info, 0, sizeof(descriptor_info));
1569 descriptor_info.sampler = sampler;
1570
1571 VkWriteDescriptorSet descriptor_write;
1572 memset(&descriptor_write, 0, sizeof(descriptor_write));
1573 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1574 descriptor_write.destSet = descriptorSet;
1575 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
1576 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001577 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001578 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1579 descriptor_write.pDescriptors = &descriptor_info;
1580
1581 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1582
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001583 msgFlags = m_errorMonitor->GetState(&msgString);
1584 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 +08001585 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
1586 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 -06001587 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001588}
1589
1590TEST_F(VkLayerTest, InvalidDSUpdateIndex)
1591{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001592 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001593 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001594 std::string msgString;
1595 VkResult err;
1596
1597 ASSERT_NO_FATAL_FAILURE(InitState());
1598 m_errorMonitor->ClearState();
1599 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001600 VkDescriptorTypeCount ds_type_count = {};
1601 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1602 ds_type_count.count = 1;
1603
1604 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1605 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1606 ds_pool_ci.pNext = NULL;
1607 ds_pool_ci.count = 1;
1608 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001609 VkDescriptorPool ds_pool;
1610 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1611 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001612
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001613 VkDescriptorSetLayoutBinding dsl_binding = {};
1614 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1615 dsl_binding.arraySize = 1;
1616 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1617 dsl_binding.pImmutableSamplers = NULL;
1618
1619 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1620 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1621 ds_layout_ci.pNext = NULL;
1622 ds_layout_ci.count = 1;
1623 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001624 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
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001633 VkSamplerCreateInfo sampler_ci = {};
1634 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1635 sampler_ci.pNext = NULL;
1636 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1637 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1638 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1639 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1640 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1641 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1642 sampler_ci.mipLodBias = 1.0;
1643 sampler_ci.maxAnisotropy = 1;
1644 sampler_ci.compareEnable = VK_FALSE;
1645 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1646 sampler_ci.minLod = 1.0;
1647 sampler_ci.maxLod = 1.0;
1648 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1649
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001650 VkSampler sampler;
1651 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1652 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001653
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 = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1661 descriptor_write.destSet = descriptorSet;
1662 descriptor_write.destBinding = 2;
1663 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001664 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001665 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1666 descriptor_write.pDescriptors = &descriptor_info;
1667
1668 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1669
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001670 msgFlags = m_errorMonitor->GetState(&msgString);
1671 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 -06001672 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
1673 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
1674 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001675}
1676
1677TEST_F(VkLayerTest, InvalidDSUpdateStruct)
1678{
1679 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001680 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001681 std::string msgString;
1682 VkResult err;
1683
1684 ASSERT_NO_FATAL_FAILURE(InitState());
1685 m_errorMonitor->ClearState();
1686 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001687
1688 VkDescriptorTypeCount ds_type_count = {};
1689 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1690 ds_type_count.count = 1;
1691
1692 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1693 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1694 ds_pool_ci.pNext = NULL;
1695 ds_pool_ci.count = 1;
1696 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001697 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);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001700 VkDescriptorSetLayoutBinding dsl_binding = {};
1701 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1702 dsl_binding.arraySize = 1;
1703 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1704 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001705
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001706 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1707 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1708 ds_layout_ci.pNext = NULL;
1709 ds_layout_ci.count = 1;
1710 ds_layout_ci.pBinding = &dsl_binding;
1711
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001712 VkDescriptorSetLayout ds_layout;
1713 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1714 ASSERT_VK_SUCCESS(err);
1715
1716 VkDescriptorSet descriptorSet;
1717 uint32_t ds_count = 0;
1718 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1719 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001720
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001721 VkSamplerCreateInfo sampler_ci = {};
1722 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1723 sampler_ci.pNext = NULL;
1724 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1725 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1726 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1727 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1728 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1729 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1730 sampler_ci.mipLodBias = 1.0;
1731 sampler_ci.maxAnisotropy = 1;
1732 sampler_ci.compareEnable = VK_FALSE;
1733 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1734 sampler_ci.minLod = 1.0;
1735 sampler_ci.maxLod = 1.0;
1736 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001737 VkSampler sampler;
1738 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1739 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001740
1741
1742 VkDescriptorInfo descriptor_info;
1743 memset(&descriptor_info, 0, sizeof(descriptor_info));
1744 descriptor_info.sampler = sampler;
1745
1746 VkWriteDescriptorSet descriptor_write;
1747 memset(&descriptor_write, 0, sizeof(descriptor_write));
1748 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
1749 descriptor_write.destSet = descriptorSet;
1750 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001751 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001752 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1753 descriptor_write.pDescriptors = &descriptor_info;
1754
1755 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1756
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001757 msgFlags = m_errorMonitor->GetState(&msgString);
1758 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 -06001759 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
1760 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
1761 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001762}
1763
1764TEST_F(VkLayerTest, NumSamplesMismatch)
1765{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001766 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001767 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001768 std::string msgString;
1769 VkResult err;
1770
1771 ASSERT_NO_FATAL_FAILURE(InitState());
1772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1773 m_errorMonitor->ClearState();
1774 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001775 VkDescriptorTypeCount ds_type_count = {};
1776 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1777 ds_type_count.count = 1;
1778
1779 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1780 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1781 ds_pool_ci.pNext = NULL;
1782 ds_pool_ci.count = 1;
1783 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001784 VkDescriptorPool ds_pool;
1785 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1786 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001787
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001788 VkDescriptorSetLayoutBinding dsl_binding = {};
1789 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1790 dsl_binding.arraySize = 1;
1791 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1792 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001793
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001794 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1795 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1796 ds_layout_ci.pNext = NULL;
1797 ds_layout_ci.count = 1;
1798 ds_layout_ci.pBinding = &dsl_binding;
1799
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001800 VkDescriptorSetLayout ds_layout;
1801 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1802 ASSERT_VK_SUCCESS(err);
1803
1804 VkDescriptorSet descriptorSet;
1805 uint32_t ds_count = 0;
1806 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1807 ASSERT_VK_SUCCESS(err);
1808
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001809 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1810 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1811 pipe_ms_state_ci.pNext = NULL;
1812 pipe_ms_state_ci.rasterSamples = 4;
1813 pipe_ms_state_ci.sampleShadingEnable = 0;
1814 pipe_ms_state_ci.minSampleShading = 1.0;
1815 pipe_ms_state_ci.sampleMask = 15;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001816
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001817 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1818 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1819 pipeline_layout_ci.pNext = NULL;
1820 pipeline_layout_ci.descriptorSetCount = 1;
1821 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001822
1823 VkPipelineLayout pipeline_layout;
1824 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1825 ASSERT_VK_SUCCESS(err);
1826
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001827 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001828 VkPipelineShaderStageCreateInfo pipe_vs_ci = {};
1829 pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1830 pipe_vs_ci.pNext = NULL;
1831 pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX;
1832 pipe_vs_ci.shader = vs.handle();
1833 pipe_vs_ci.pSpecializationInfo = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001834
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001835 VkGraphicsPipelineCreateInfo gp_ci = {};
1836 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1837 gp_ci.pNext = NULL;
1838 gp_ci.stageCount = 1;
1839 gp_ci.pStages = &pipe_vs_ci;
1840 gp_ci.pVertexInputState = NULL;
1841 gp_ci.pInputAssemblyState = NULL;
1842 gp_ci.pTessellationState = NULL;
1843 gp_ci.pViewportState = NULL;
1844 gp_ci.pRasterState = NULL;
1845 gp_ci.pMultisampleState = &pipe_ms_state_ci;
1846 gp_ci.pDepthStencilState = NULL;
1847 gp_ci.pColorBlendState = NULL;
1848 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1849 gp_ci.layout = pipeline_layout;
1850
1851 VkPipelineCacheCreateInfo pc_ci = {};
1852 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1853 pc_ci.pNext = NULL;
1854 pc_ci.initialSize = 0;
1855 pc_ci.initialData = 0;
1856 pc_ci.maxSize = 0;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001857
1858 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001859 VkPipelineCache pipelineCache;
1860
1861 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1862 ASSERT_VK_SUCCESS(err);
1863 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001864 ASSERT_VK_SUCCESS(err);
1865
1866 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1867 BeginCommandBuffer(cmdBuffer);
1868 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1869
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001870 msgFlags = m_errorMonitor->GetState(&msgString);
1871 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 -06001872 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
1873 FAIL() << "Error received was not 'Num samples mismatch!...'";
1874 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001875}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001876
Tobin Ehlise4076782015-06-24 15:53:07 -06001877TEST_F(VkLayerTest, PipelineNotBound)
1878{
1879 VkFlags msgFlags;
1880 std::string msgString;
1881 VkResult err;
1882
1883 ASSERT_NO_FATAL_FAILURE(InitState());
1884 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1885 m_errorMonitor->ClearState();
1886 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001887
1888 VkDescriptorTypeCount ds_type_count = {};
1889 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1890 ds_type_count.count = 1;
1891
1892 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1893 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1894 ds_pool_ci.pNext = NULL;
1895 ds_pool_ci.count = 1;
1896 ds_pool_ci.pTypeCount = &ds_type_count;
1897
Tobin Ehlise4076782015-06-24 15:53:07 -06001898 VkDescriptorPool ds_pool;
1899 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1900 ASSERT_VK_SUCCESS(err);
1901
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001902 VkDescriptorSetLayoutBinding dsl_binding = {};
1903 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1904 dsl_binding.arraySize = 1;
1905 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1906 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06001907
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001908 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1909 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1910 ds_layout_ci.pNext = NULL;
1911 ds_layout_ci.count = 1;
1912 ds_layout_ci.pBinding = &dsl_binding;
1913
Tobin Ehlise4076782015-06-24 15:53:07 -06001914 VkDescriptorSetLayout ds_layout;
1915 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1916 ASSERT_VK_SUCCESS(err);
1917
1918 VkDescriptorSet descriptorSet;
1919 uint32_t ds_count = 0;
1920 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1921 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001922
1923 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1924 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1925 pipeline_layout_ci.pNext = NULL;
1926 pipeline_layout_ci.descriptorSetCount = 1;
1927 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06001928
1929 VkPipelineLayout pipeline_layout;
1930 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1931 ASSERT_VK_SUCCESS(err);
1932
Tobin Ehlise4076782015-06-24 15:53:07 -06001933 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1934 //err = vkCreateGraphicsPipeline(m_device->device(), &gp_ci, &pipeline);
1935 ASSERT_VK_SUCCESS(err);
1936
1937 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1938 BeginCommandBuffer(cmdBuffer);
1939 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1940
1941 msgFlags = m_errorMonitor->GetState(&msgString);
1942 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding invalid pipeline to CmdBuffer";
1943 if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1944 FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1945 }
1946}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001947
1948TEST_F(VkLayerTest, ClearCmdNoDraw)
1949{
1950 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
1951 VkFlags msgFlags;
1952 std::string msgString;
1953 VkResult err;
1954
1955 ASSERT_NO_FATAL_FAILURE(InitState());
1956 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1957 m_errorMonitor->ClearState();
1958 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001959
1960 VkDescriptorTypeCount ds_type_count = {};
1961 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1962 ds_type_count.count = 1;
1963
1964 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1965 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1966 ds_pool_ci.pNext = NULL;
1967 ds_pool_ci.count = 1;
1968 ds_pool_ci.pTypeCount = &ds_type_count;
1969
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001970 VkDescriptorPool ds_pool;
1971 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1972 ASSERT_VK_SUCCESS(err);
1973
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001974 VkDescriptorSetLayoutBinding dsl_binding = {};
1975 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1976 dsl_binding.arraySize = 1;
1977 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1978 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001979
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001980 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1981 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1982 ds_layout_ci.pNext = NULL;
1983 ds_layout_ci.count = 1;
1984 ds_layout_ci.pBinding = &dsl_binding;
1985
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001986 VkDescriptorSetLayout ds_layout;
1987 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1988 ASSERT_VK_SUCCESS(err);
1989
1990 VkDescriptorSet descriptorSet;
1991 uint32_t ds_count = 0;
1992 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1993 ASSERT_VK_SUCCESS(err);
1994
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001995 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1996 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1997 pipe_ms_state_ci.pNext = NULL;
1998 pipe_ms_state_ci.rasterSamples = 4;
1999 pipe_ms_state_ci.sampleShadingEnable = 0;
2000 pipe_ms_state_ci.minSampleShading = 1.0;
2001 pipe_ms_state_ci.sampleMask = 15;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002002
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002003 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2004 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2005 pipeline_layout_ci.pNext = NULL;
2006 pipeline_layout_ci.descriptorSetCount = 1;
2007 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002008
2009 VkPipelineLayout pipeline_layout;
2010 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2011 ASSERT_VK_SUCCESS(err);
2012
2013 size_t shader_len = strlen(bindStateVertShaderText);
2014 size_t codeSize = 3 * sizeof(uint32_t) + shader_len + 1;
2015 void* pCode = malloc(codeSize);
2016
2017 /* try version 0 first: VkShaderStage followed by GLSL */
2018 ((uint32_t *) pCode)[0] = ICD_SPV_MAGIC;
2019 ((uint32_t *) pCode)[1] = 0;
2020 ((uint32_t *) pCode)[2] = VK_SHADER_STAGE_VERTEX;
2021 memcpy(((uint32_t *) pCode + 3), bindStateVertShaderText, shader_len + 1);
2022
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002023 VkShaderModuleCreateInfo smci = {};
2024 smci.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2025 smci.pNext = NULL;
2026 smci.codeSize = codeSize;
2027 smci.pCode = pCode;
2028 smci.flags = 0;
2029
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002030 VkShaderModule vksm;
2031 err = vkCreateShaderModule(m_device->device(), &smci, &vksm);
2032 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002033 VkShaderCreateInfo vs_ci = {};
2034 vs_ci.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
2035 vs_ci.pNext = NULL;
2036 vs_ci.module = vksm;
2037 vs_ci.pName = "main";
2038 vs_ci.flags = 0;
2039
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002040 VkShader vs;
2041 err = vkCreateShader(m_device->device(), &vs_ci, &vs);
2042 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002043 VkPipelineShaderStageCreateInfo pipe_vs_ci = {};
2044 pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2045 pipe_vs_ci.pNext = NULL;
2046 pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX;
2047 pipe_vs_ci.shader = vs;
2048 pipe_vs_ci.pSpecializationInfo = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002049
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002050 VkGraphicsPipelineCreateInfo gp_ci = {};
2051 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2052 gp_ci.pNext = NULL;
2053 gp_ci.stageCount = 1;
2054 gp_ci.pStages = &pipe_vs_ci;
2055 gp_ci.pVertexInputState = NULL;
2056 gp_ci.pInputAssemblyState = NULL;
2057 gp_ci.pTessellationState = NULL;
2058 gp_ci.pViewportState = NULL;
2059 gp_ci.pRasterState = NULL;
2060 gp_ci.pMultisampleState = &pipe_ms_state_ci;
2061 gp_ci.pDepthStencilState = NULL;
2062 gp_ci.pColorBlendState = NULL;
2063 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2064 gp_ci.layout = pipeline_layout;
2065
2066 VkPipelineCacheCreateInfo pc_ci = {};
2067 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2068 pc_ci.pNext = NULL;
2069 pc_ci.initialSize = 0;
2070 pc_ci.initialData = 0;
2071 pc_ci.maxSize = 0;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002072
2073 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06002074 VkPipelineCache pipelineCache;
2075
2076 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2077 ASSERT_VK_SUCCESS(err);
2078 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002079 ASSERT_VK_SUCCESS(err);
2080
2081 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2082 BeginCommandBuffer(cmdBuffer);
2083
2084 m_errorMonitor->ClearState();
2085 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
2086 // Also pass down other dummy params to keep driver and paramchecker happy
2087 VkClearColorValue cCV;
2088 cCV.f32[0] = 1.0;
2089 cCV.f32[1] = 1.0;
2090 cCV.f32[2] = 1.0;
2091 cCV.f32[3] = 1.0;
2092
2093 vkCmdClearColorAttachment(cmdBuffer.GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL);
2094 msgFlags = m_errorMonitor->GetState(&msgString);
2095 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not receive error after issuing Clear Cmd on FB color attachment prior to Draw Cmd.";
2096 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) {
2097 FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'";
2098 }
2099}
2100
Tobin Ehlise4076782015-06-24 15:53:07 -06002101TEST_F(VkLayerTest, VtxBufferBadIndex)
2102{
2103 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
2104 VkFlags msgFlags;
2105 std::string msgString;
2106 VkResult err;
2107
2108 ASSERT_NO_FATAL_FAILURE(InitState());
2109 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2110 m_errorMonitor->ClearState();
2111 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002112
2113 VkDescriptorTypeCount ds_type_count = {};
2114 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2115 ds_type_count.count = 1;
2116
2117 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2118 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2119 ds_pool_ci.pNext = NULL;
2120 ds_pool_ci.count = 1;
2121 ds_pool_ci.pTypeCount = &ds_type_count;
2122
2123 VkDescriptorPool ds_pool;
Tobin Ehlise4076782015-06-24 15:53:07 -06002124 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
2125 ASSERT_VK_SUCCESS(err);
2126
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002127 VkDescriptorSetLayoutBinding dsl_binding = {};
2128 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2129 dsl_binding.arraySize = 1;
2130 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2131 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002132
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002133 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2134 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2135 ds_layout_ci.pNext = NULL;
2136 ds_layout_ci.count = 1;
2137 ds_layout_ci.pBinding = &dsl_binding;
2138
Tobin Ehlise4076782015-06-24 15:53:07 -06002139 VkDescriptorSetLayout ds_layout;
2140 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2141 ASSERT_VK_SUCCESS(err);
2142
2143 VkDescriptorSet descriptorSet;
2144 uint32_t ds_count = 0;
2145 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
2146 ASSERT_VK_SUCCESS(err);
2147
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002148 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2149 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2150 pipe_ms_state_ci.pNext = NULL;
2151 pipe_ms_state_ci.rasterSamples = 1;
2152 pipe_ms_state_ci.sampleShadingEnable = 0;
2153 pipe_ms_state_ci.minSampleShading = 1.0;
2154 pipe_ms_state_ci.sampleMask = 15;
Tobin Ehlise4076782015-06-24 15:53:07 -06002155
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002156 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2157 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2158 pipeline_layout_ci.pNext = NULL;
2159 pipeline_layout_ci.descriptorSetCount = 1;
2160 pipeline_layout_ci.pSetLayouts = &ds_layout;
2161 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06002162
Tobin Ehlise4076782015-06-24 15:53:07 -06002163 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2164 ASSERT_VK_SUCCESS(err);
2165
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002166 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tobin Ehlise4076782015-06-24 15:53:07 -06002167
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002168 VkPipelineShaderStageCreateInfo pipe_vs_ci = {};
2169 pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2170 pipe_vs_ci.pNext = NULL;
2171 pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX;
2172 pipe_vs_ci.shader = vs.handle();
2173 pipe_vs_ci.pSpecializationInfo = NULL;
2174
2175 VkGraphicsPipelineCreateInfo gp_ci = {};
2176 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2177 gp_ci.pNext = NULL;
2178 gp_ci.stageCount = 1;
2179 gp_ci.pStages = &pipe_vs_ci;
2180 gp_ci.pVertexInputState = NULL;
2181 gp_ci.pInputAssemblyState = NULL;
2182 gp_ci.pTessellationState = NULL;
2183 gp_ci.pViewportState = NULL;
2184 gp_ci.pRasterState = NULL;
2185 gp_ci.pMultisampleState = &pipe_ms_state_ci;
2186 gp_ci.pDepthStencilState = NULL;
2187 gp_ci.pColorBlendState = NULL;
2188 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2189 gp_ci.layout = pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06002190
Courtney Goeltzenleuchtercdf5e832015-07-10 09:21:02 -06002191 VkPipelineCacheCreateInfo pipelineCache;
2192 VkPipelineCache pipeline_cache;
2193
2194 memset(&pipelineCache, 0, sizeof(pipelineCache));
2195 pipelineCache.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2196 err = vkCreatePipelineCache(m_device->device(), &pipelineCache, &pipeline_cache);
2197
Tobin Ehlise4076782015-06-24 15:53:07 -06002198 VkPipeline pipeline;
Courtney Goeltzenleuchtercdf5e832015-07-10 09:21:02 -06002199 err = vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &gp_ci, &pipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06002200 ASSERT_VK_SUCCESS(err);
2201
2202 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2203 BeginCommandBuffer(cmdBuffer);
2204 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2205 // Should error before calling to driver so don't care about actual data
2206 vkCmdBindVertexBuffers(cmdBuffer.GetBufferHandle(), 0, 1, NULL, NULL);
2207
2208 msgFlags = m_errorMonitor->GetState(&msgString);
2209 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding Vtx Buffer w/o VBO attached to PSO.";
2210 if (!strstr(msgString.c_str(),"Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.")) {
2211 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
2212 }
2213}
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002214#endif
2215#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06002216#if GTEST_IS_THREADSAFE
2217struct thread_data_struct {
2218 VkCmdBuffer cmdBuffer;
2219 VkEvent event;
2220 bool bailout;
2221};
2222
2223extern "C" void *AddToCommandBuffer(void *arg)
2224{
2225 struct thread_data_struct *data = (struct thread_data_struct *) arg;
2226 std::string msgString;
2227
2228 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06002229 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06002230 if (data->bailout) {
2231 break;
2232 }
2233 }
2234 return NULL;
2235}
2236
2237TEST_F(VkLayerTest, ThreadCmdBufferCollision)
2238{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002239 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06002240 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002241 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06002242
2243 ASSERT_NO_FATAL_FAILURE(InitState());
2244 ASSERT_NO_FATAL_FAILURE(InitViewport());
2245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2246
2247 VkCommandBufferObj cmdBuffer(m_device);
2248
2249 m_errorMonitor->ClearState();
Mike Stroyan09aae812015-05-12 16:00:45 -06002250 BeginCommandBuffer(cmdBuffer);
2251
2252 VkEventCreateInfo event_info;
2253 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06002254 VkResult err;
2255
2256 memset(&event_info, 0, sizeof(event_info));
2257 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2258
2259 err = vkCreateEvent(device(), &event_info, &event);
2260 ASSERT_VK_SUCCESS(err);
2261
Mike Stroyan09aae812015-05-12 16:00:45 -06002262 err = vkResetEvent(device(), event);
2263 ASSERT_VK_SUCCESS(err);
2264
2265 struct thread_data_struct data;
Chia-I Wu78c2a352015-07-03 11:49:42 +08002266 data.cmdBuffer = cmdBuffer.handle();
Mike Stroyan09aae812015-05-12 16:00:45 -06002267 data.event = event;
2268 data.bailout = false;
2269 m_errorMonitor->SetBailout(&data.bailout);
2270 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002271 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06002272 // Add many entries to command buffer from this thread at the same time.
2273 AddToCommandBuffer(&data);
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002274 test_platform_thread_join(thread, NULL);
Mike Stroyan09aae812015-05-12 16:00:45 -06002275 EndCommandBuffer(cmdBuffer);
2276
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002277 msgFlags = m_errorMonitor->GetState(&msgString);
Mike Stroyaned254572015-06-17 16:32:06 -06002278 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 -06002279 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05002280 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06002281 }
2282
2283}
2284#endif
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002285#endif
Chris Forbes5af3bf22015-05-25 11:13:08 +12002286#if SHADER_CHECKER_TESTS
2287TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
2288{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002289 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12002290 std::string msgString;
2291 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002292 ScopedUseGlsl useGlsl(false);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002293
2294 char const *vsSource =
2295 "#version 140\n"
2296 "#extension GL_ARB_separate_shader_objects: require\n"
2297 "#extension GL_ARB_shading_language_420pack: require\n"
2298 "\n"
2299 "layout(location=0) out float x;\n"
2300 "void main(){\n"
2301 " gl_Position = vec4(1);\n"
2302 " x = 0;\n"
2303 "}\n";
2304 char const *fsSource =
2305 "#version 140\n"
2306 "#extension GL_ARB_separate_shader_objects: require\n"
2307 "#extension GL_ARB_shading_language_420pack: require\n"
2308 "\n"
2309 "layout(location=0) out vec4 color;\n"
2310 "void main(){\n"
2311 " color = vec4(1);\n"
2312 "}\n";
2313
2314 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2315 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2316
2317 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002318 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12002319 pipe.AddShader(&vs);
2320 pipe.AddShader(&fs);
2321
2322 VkCommandBufferObj dummyCmd(m_device);
2323 VkDescriptorSetObj descriptorSet(m_device);
2324 descriptorSet.AppendDummy();
2325 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2326
2327 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002328 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12002329
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002330 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002331
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002332 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002333 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
2334 FAIL() << "Incorrect warning: " << msgString;
2335 }
2336}
Chris Forbes5af3bf22015-05-25 11:13:08 +12002337
Chris Forbes3c10b852015-05-25 11:13:13 +12002338TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
2339{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002340 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12002341 std::string msgString;
2342 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002343 ScopedUseGlsl useGlsl(false);
Chris Forbes3c10b852015-05-25 11:13:13 +12002344
2345 char const *vsSource =
2346 "#version 140\n"
2347 "#extension GL_ARB_separate_shader_objects: require\n"
2348 "#extension GL_ARB_shading_language_420pack: require\n"
2349 "\n"
2350 "void main(){\n"
2351 " gl_Position = vec4(1);\n"
2352 "}\n";
2353 char const *fsSource =
2354 "#version 140\n"
2355 "#extension GL_ARB_separate_shader_objects: require\n"
2356 "#extension GL_ARB_shading_language_420pack: require\n"
2357 "\n"
2358 "layout(location=0) in float x;\n"
2359 "layout(location=0) out vec4 color;\n"
2360 "void main(){\n"
2361 " color = vec4(x);\n"
2362 "}\n";
2363
2364 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2365 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2366
2367 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002368 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12002369 pipe.AddShader(&vs);
2370 pipe.AddShader(&fs);
2371
2372 VkCommandBufferObj dummyCmd(m_device);
2373 VkDescriptorSetObj descriptorSet(m_device);
2374 descriptorSet.AppendDummy();
2375 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2376
2377 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002378 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12002379
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002380 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12002381
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002382 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes3c10b852015-05-25 11:13:13 +12002383 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
2384 FAIL() << "Incorrect error: " << msgString;
2385 }
2386}
2387
Chris Forbescc281692015-05-25 11:13:17 +12002388TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
2389{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002390 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12002391 std::string msgString;
2392 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002393 ScopedUseGlsl useGlsl(false);
Chris Forbescc281692015-05-25 11:13:17 +12002394
2395 char const *vsSource =
2396 "#version 140\n"
2397 "#extension GL_ARB_separate_shader_objects: require\n"
2398 "#extension GL_ARB_shading_language_420pack: require\n"
2399 "\n"
2400 "layout(location=0) out int x;\n"
2401 "void main(){\n"
2402 " x = 0;\n"
2403 " gl_Position = vec4(1);\n"
2404 "}\n";
2405 char const *fsSource =
2406 "#version 140\n"
2407 "#extension GL_ARB_separate_shader_objects: require\n"
2408 "#extension GL_ARB_shading_language_420pack: require\n"
2409 "\n"
2410 "layout(location=0) in float x;\n" /* VS writes int */
2411 "layout(location=0) out vec4 color;\n"
2412 "void main(){\n"
2413 " color = vec4(x);\n"
2414 "}\n";
2415
2416 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2417 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2418
2419 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002420 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12002421 pipe.AddShader(&vs);
2422 pipe.AddShader(&fs);
2423
2424 VkCommandBufferObj dummyCmd(m_device);
2425 VkDescriptorSetObj descriptorSet(m_device);
2426 descriptorSet.AppendDummy();
2427 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2428
2429 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002430 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12002431
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002432 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12002433
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002434 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbescc281692015-05-25 11:13:17 +12002435 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
2436 FAIL() << "Incorrect error: " << msgString;
2437 }
2438}
2439
Chris Forbes8291c052015-05-25 11:13:28 +12002440TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
2441{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002442 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12002443 std::string msgString;
2444 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002445 ScopedUseGlsl useGlsl(false);
Chris Forbes8291c052015-05-25 11:13:28 +12002446
2447 VkVertexInputBindingDescription input_binding;
2448 memset(&input_binding, 0, sizeof(input_binding));
2449
2450 VkVertexInputAttributeDescription input_attrib;
2451 memset(&input_attrib, 0, sizeof(input_attrib));
2452 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2453
2454 char const *vsSource =
2455 "#version 140\n"
2456 "#extension GL_ARB_separate_shader_objects: require\n"
2457 "#extension GL_ARB_shading_language_420pack: require\n"
2458 "\n"
2459 "void main(){\n"
2460 " gl_Position = vec4(1);\n"
2461 "}\n";
2462 char const *fsSource =
2463 "#version 140\n"
2464 "#extension GL_ARB_separate_shader_objects: require\n"
2465 "#extension GL_ARB_shading_language_420pack: require\n"
2466 "\n"
2467 "layout(location=0) out vec4 color;\n"
2468 "void main(){\n"
2469 " color = vec4(1);\n"
2470 "}\n";
2471
2472 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2473 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2474
2475 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002476 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12002477 pipe.AddShader(&vs);
2478 pipe.AddShader(&fs);
2479
2480 pipe.AddVertexInputBindings(&input_binding, 1);
2481 pipe.AddVertexInputAttribs(&input_attrib, 1);
2482
2483 VkCommandBufferObj dummyCmd(m_device);
2484 VkDescriptorSetObj descriptorSet(m_device);
2485 descriptorSet.AppendDummy();
2486 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2487
2488 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002489 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12002490
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002491 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12002492
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002493 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12002494 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
2495 FAIL() << "Incorrect warning: " << msgString;
2496 }
2497}
2498
Chris Forbes37367e62015-05-25 11:13:29 +12002499TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
2500{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002501 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12002502 std::string msgString;
2503 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002504 ScopedUseGlsl useGlsl(false);
Chris Forbes37367e62015-05-25 11:13:29 +12002505
2506 char const *vsSource =
2507 "#version 140\n"
2508 "#extension GL_ARB_separate_shader_objects: require\n"
2509 "#extension GL_ARB_shading_language_420pack: require\n"
2510 "\n"
2511 "layout(location=0) in vec4 x;\n" /* not provided */
2512 "void main(){\n"
2513 " gl_Position = x;\n"
2514 "}\n";
2515 char const *fsSource =
2516 "#version 140\n"
2517 "#extension GL_ARB_separate_shader_objects: require\n"
2518 "#extension GL_ARB_shading_language_420pack: require\n"
2519 "\n"
2520 "layout(location=0) out vec4 color;\n"
2521 "void main(){\n"
2522 " color = vec4(1);\n"
2523 "}\n";
2524
2525 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2526 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2527
2528 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002529 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12002530 pipe.AddShader(&vs);
2531 pipe.AddShader(&fs);
2532
2533 VkCommandBufferObj dummyCmd(m_device);
2534 VkDescriptorSetObj descriptorSet(m_device);
2535 descriptorSet.AppendDummy();
2536 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2537
2538 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002539 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12002540
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002541 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12002542
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002543 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes37367e62015-05-25 11:13:29 +12002544 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
2545 FAIL() << "Incorrect warning: " << msgString;
2546 }
2547}
2548
Chris Forbesa4b02322015-05-25 11:13:31 +12002549TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
2550{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002551 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12002552 std::string msgString;
2553 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002554 ScopedUseGlsl useGlsl(false);
Chris Forbesa4b02322015-05-25 11:13:31 +12002555
2556 VkVertexInputBindingDescription input_binding;
2557 memset(&input_binding, 0, sizeof(input_binding));
2558
2559 VkVertexInputAttributeDescription input_attrib;
2560 memset(&input_attrib, 0, sizeof(input_attrib));
2561 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2562
2563 char const *vsSource =
2564 "#version 140\n"
2565 "#extension GL_ARB_separate_shader_objects: require\n"
2566 "#extension GL_ARB_shading_language_420pack: require\n"
2567 "\n"
2568 "layout(location=0) in int x;\n" /* attrib provided float */
2569 "void main(){\n"
2570 " gl_Position = vec4(x);\n"
2571 "}\n";
2572 char const *fsSource =
2573 "#version 140\n"
2574 "#extension GL_ARB_separate_shader_objects: require\n"
2575 "#extension GL_ARB_shading_language_420pack: require\n"
2576 "\n"
2577 "layout(location=0) out vec4 color;\n"
2578 "void main(){\n"
2579 " color = vec4(1);\n"
2580 "}\n";
2581
2582 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2583 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2584
2585 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002586 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12002587 pipe.AddShader(&vs);
2588 pipe.AddShader(&fs);
2589
2590 pipe.AddVertexInputBindings(&input_binding, 1);
2591 pipe.AddVertexInputAttribs(&input_attrib, 1);
2592
2593 VkCommandBufferObj dummyCmd(m_device);
2594 VkDescriptorSetObj descriptorSet(m_device);
2595 descriptorSet.AppendDummy();
2596 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2597
2598 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002599 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12002600
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002601 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12002602
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002603 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbesa4b02322015-05-25 11:13:31 +12002604 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
2605 FAIL() << "Incorrect error: " << msgString;
2606 }
2607}
2608
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002609TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
2610{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002611 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002612 std::string msgString;
2613 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002614 ScopedUseGlsl useGlsl(false);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002615
2616 /* Two binding descriptions for binding 0 */
2617 VkVertexInputBindingDescription input_bindings[2];
2618 memset(input_bindings, 0, sizeof(input_bindings));
2619
2620 VkVertexInputAttributeDescription input_attrib;
2621 memset(&input_attrib, 0, sizeof(input_attrib));
2622 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2623
2624 char const *vsSource =
2625 "#version 140\n"
2626 "#extension GL_ARB_separate_shader_objects: require\n"
2627 "#extension GL_ARB_shading_language_420pack: require\n"
2628 "\n"
2629 "layout(location=0) in float x;\n" /* attrib provided float */
2630 "void main(){\n"
2631 " gl_Position = vec4(x);\n"
2632 "}\n";
2633 char const *fsSource =
2634 "#version 140\n"
2635 "#extension GL_ARB_separate_shader_objects: require\n"
2636 "#extension GL_ARB_shading_language_420pack: require\n"
2637 "\n"
2638 "layout(location=0) out vec4 color;\n"
2639 "void main(){\n"
2640 " color = vec4(1);\n"
2641 "}\n";
2642
2643 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2644 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2645
2646 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002647 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002648 pipe.AddShader(&vs);
2649 pipe.AddShader(&fs);
2650
2651 pipe.AddVertexInputBindings(input_bindings, 2);
2652 pipe.AddVertexInputAttribs(&input_attrib, 1);
2653
2654 VkCommandBufferObj dummyCmd(m_device);
2655 VkDescriptorSetObj descriptorSet(m_device);
2656 descriptorSet.AppendDummy();
2657 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2658
2659 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002660 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002661
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002662 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002663
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002664 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002665 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
2666 FAIL() << "Incorrect error: " << msgString;
2667 }
2668}
Chris Forbes4c948702015-05-25 11:13:32 +12002669
Chris Forbesc12ef122015-05-25 11:13:40 +12002670/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
2671 * rejects it. */
2672
2673TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
2674{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002675 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12002676 std::string msgString;
2677 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002678 ScopedUseGlsl useGlsl(false);
Chris Forbesc12ef122015-05-25 11:13:40 +12002679
2680 char const *vsSource =
2681 "#version 140\n"
2682 "#extension GL_ARB_separate_shader_objects: require\n"
2683 "#extension GL_ARB_shading_language_420pack: require\n"
2684 "\n"
2685 "void main(){\n"
2686 " gl_Position = vec4(1);\n"
2687 "}\n";
2688 char const *fsSource =
2689 "#version 140\n"
2690 "#extension GL_ARB_separate_shader_objects: require\n"
2691 "#extension GL_ARB_shading_language_420pack: require\n"
2692 "\n"
2693 "void main(){\n"
2694 "}\n";
2695
2696 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2697 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2698
2699 VkPipelineObj pipe(m_device);
2700 pipe.AddShader(&vs);
2701 pipe.AddShader(&fs);
2702
Chia-I Wuc278df82015-07-07 11:50:03 +08002703 /* set up CB 0, not written */
2704 pipe.AddColorAttachment();
2705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12002706
2707 VkCommandBufferObj dummyCmd(m_device);
2708 VkDescriptorSetObj descriptorSet(m_device);
2709 descriptorSet.AppendDummy();
2710 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2711
2712 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002713 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12002714
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002715 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12002716
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002717 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbesc12ef122015-05-25 11:13:40 +12002718 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
2719 FAIL() << "Incorrect error: " << msgString;
2720 }
2721}
2722
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002723TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
2724{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002725 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002726 std::string msgString;
2727 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002728 ScopedUseGlsl useGlsl(false);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002729
2730 char const *vsSource =
2731 "#version 140\n"
2732 "#extension GL_ARB_separate_shader_objects: require\n"
2733 "#extension GL_ARB_shading_language_420pack: require\n"
2734 "\n"
2735 "void main(){\n"
2736 " gl_Position = vec4(1);\n"
2737 "}\n";
2738 char const *fsSource =
2739 "#version 140\n"
2740 "#extension GL_ARB_separate_shader_objects: require\n"
2741 "#extension GL_ARB_shading_language_420pack: require\n"
2742 "\n"
2743 "layout(location=0) out vec4 x;\n"
2744 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
2745 "void main(){\n"
2746 " x = vec4(1);\n"
2747 " y = vec4(1);\n"
2748 "}\n";
2749
2750 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2751 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2752
2753 VkPipelineObj pipe(m_device);
2754 pipe.AddShader(&vs);
2755 pipe.AddShader(&fs);
2756
Chia-I Wuc278df82015-07-07 11:50:03 +08002757 /* set up CB 0, not written */
2758 pipe.AddColorAttachment();
2759 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002760 /* FS writes CB 1, but we don't configure it */
2761
2762 VkCommandBufferObj dummyCmd(m_device);
2763 VkDescriptorSetObj descriptorSet(m_device);
2764 descriptorSet.AppendDummy();
2765 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2766
2767 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002768 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002769
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002770 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002771
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002772 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002773 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
2774 FAIL() << "Incorrect warning: " << msgString;
2775 }
2776}
2777
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002778TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
2779{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002780 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002781 std::string msgString;
2782 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002783 ScopedUseGlsl useGlsl(false);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002784
2785 char const *vsSource =
2786 "#version 140\n"
2787 "#extension GL_ARB_separate_shader_objects: require\n"
2788 "#extension GL_ARB_shading_language_420pack: require\n"
2789 "\n"
2790 "void main(){\n"
2791 " gl_Position = vec4(1);\n"
2792 "}\n";
2793 char const *fsSource =
2794 "#version 140\n"
2795 "#extension GL_ARB_separate_shader_objects: require\n"
2796 "#extension GL_ARB_shading_language_420pack: require\n"
2797 "\n"
2798 "layout(location=0) out ivec4 x;\n" /* not UNORM */
2799 "void main(){\n"
2800 " x = ivec4(1);\n"
2801 "}\n";
2802
2803 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2804 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2805
2806 VkPipelineObj pipe(m_device);
2807 pipe.AddShader(&vs);
2808 pipe.AddShader(&fs);
2809
Chia-I Wuc278df82015-07-07 11:50:03 +08002810 /* set up CB 0; type is UNORM by default */
2811 pipe.AddColorAttachment();
2812 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002813
2814 VkCommandBufferObj dummyCmd(m_device);
2815 VkDescriptorSetObj descriptorSet(m_device);
2816 descriptorSet.AppendDummy();
2817 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2818
2819 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002820 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002821
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002822 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002823
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002824 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002825 if (!strstr(msgString.c_str(),"does not match FS output type")) {
2826 FAIL() << "Incorrect error: " << msgString;
2827 }
2828}
Chris Forbesc2050732015-06-05 14:43:36 +12002829
2830TEST_F(VkLayerTest, CreatePipelineNonSpirvShader)
2831{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002832 VkFlags msgFlags;
Chris Forbesc2050732015-06-05 14:43:36 +12002833 std::string msgString;
2834 ASSERT_NO_FATAL_FAILURE(InitState());
2835 /* Intentionally provided GLSL rather than compiling to SPIRV first */
Cody Northrop1cfbd172015-06-03 16:49:20 -06002836 ScopedUseGlsl useGlsl(true);
Chris Forbesc2050732015-06-05 14:43:36 +12002837
2838 char const *vsSource =
2839 "#version 140\n"
2840 "#extension GL_ARB_separate_shader_objects: require\n"
2841 "#extension GL_ARB_shading_language_420pack: require\n"
2842 "\n"
2843 "void main(){\n"
2844 " gl_Position = vec4(1);\n"
2845 "}\n";
2846 char const *fsSource =
2847 "#version 140\n"
2848 "#extension GL_ARB_separate_shader_objects: require\n"
2849 "#extension GL_ARB_shading_language_420pack: require\n"
2850 "\n"
2851 "layout(location=0) out vec4 x;\n"
2852 "void main(){\n"
2853 " x = vec4(1);\n"
2854 "}\n";
2855
2856 m_errorMonitor->ClearState();
2857
2858 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2859 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2860
2861
2862 VkPipelineObj pipe(m_device);
2863 pipe.AddShader(&vs);
2864 pipe.AddShader(&fs);
2865
Chia-I Wuc278df82015-07-07 11:50:03 +08002866 /* set up CB 0; type is UNORM by default */
2867 pipe.AddColorAttachment();
2868 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc2050732015-06-05 14:43:36 +12002869
2870 VkCommandBufferObj dummyCmd(m_device);
2871 VkDescriptorSetObj descriptorSet(m_device);
2872 descriptorSet.AppendDummy();
2873 descriptorSet.CreateVKDescriptorSet(&dummyCmd);
2874
Chia-I Wuc278df82015-07-07 11:50:03 +08002875 VkResult res = pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbesc2050732015-06-05 14:43:36 +12002876 /* pipeline creation should have succeeded */
2877 ASSERT_EQ(VK_SUCCESS, res);
2878
2879 /* should have emitted a warning: the shader is not SPIRV, so we're
2880 * not going to be able to analyze it */
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002881 msgFlags = m_errorMonitor->GetState(&msgString);
2882 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesc2050732015-06-05 14:43:36 +12002883 if (!strstr(msgString.c_str(),"is not SPIR-V")) {
2884 FAIL() << "Incorrect warning: " << msgString;
2885 }
2886}
Chris Forbes01c9db72015-06-04 09:25:25 +12002887#endif
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002888
Tony Barbour30486ea2015-04-07 13:44:53 -06002889int main(int argc, char **argv) {
2890 int result;
2891
2892 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06002893 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06002894
2895 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
2896
2897 result = RUN_ALL_TESTS();
2898
Tony Barbour01999182015-04-09 12:58:51 -06002899 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06002900 return result;
2901}