blob: e428cabf23297bc293fcc89cdfee6f0cf778e597 [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 Barbour1490c912015-07-28 10:17:20 -0600143 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
144 { GenericDrawPreparation(m_cmdBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600145
Tony Barbour1490c912015-07-28 10:17:20 -0600146 /* Convenience functions that use built-in command buffer */
147 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_cmdBuffer); }
148 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_cmdBuffer); }
149 void Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
150 { m_cmdBuffer->Draw(firstVertex, vertexCount, firstInstance, instanceCount); }
151 void DrawIndexed(uint32_t firstVertex, uint32_t vertexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
152 { m_cmdBuffer->DrawIndexed(firstVertex, vertexCount, vertexOffset,firstInstance, instanceCount); }
153 void QueueCommandBuffer() { m_cmdBuffer->QueueCommandBuffer(); }
154 void QueueCommandBuffer(const VkFence& fence) { m_cmdBuffer->QueueCommandBuffer(fence); }
155 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
156 { m_cmdBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
157 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
158 { m_cmdBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600159protected:
Tony Barbour01999182015-04-09 12:58:51 -0600160 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600161
162 virtual void SetUp() {
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600163 std::vector<const char *> instance_layer_names;
164 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600165 std::vector<const char *> instance_extension_names;
166 std::vector<const char *> device_extension_names;
Tony Barbour950ebc02015-04-23 12:55:36 -0600167
Courtney Goeltzenleuchter846298c2015-07-30 11:32:46 -0600168 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600169 /*
170 * Since CreateDbgMsgCallback is an instance level extension call
171 * any extension / layer that utilizes that feature also needs
172 * to be enabled at create instance time.
173 */
Mike Stroyaned254572015-06-17 16:32:06 -0600174 // Use Threading layer first to protect others from ThreadCmdBufferCollision test
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600175 instance_layer_names.push_back("Threading");
176 instance_layer_names.push_back("ObjectTracker");
177 instance_layer_names.push_back("MemTracker");
178 instance_layer_names.push_back("DrawState");
179 instance_layer_names.push_back("ShaderChecker");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600180
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600181 device_layer_names.push_back("Threading");
182 device_layer_names.push_back("ObjectTracker");
183 device_layer_names.push_back("MemTracker");
184 device_layer_names.push_back("DrawState");
185 device_layer_names.push_back("ShaderChecker");
Tony Barbour30486ea2015-04-07 13:44:53 -0600186
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600187 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -0600188 this->app_info.pNext = NULL;
189 this->app_info.pAppName = "layer_tests";
190 this->app_info.appVersion = 1;
191 this->app_info.pEngineName = "unittest";
192 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600193 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -0600194
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600195 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600196 InitFramework(instance_layer_names, device_layer_names,
197 instance_extension_names, device_extension_names,
198 myDbgFunc, m_errorMonitor);
Tony Barbour30486ea2015-04-07 13:44:53 -0600199 }
200
201 virtual void TearDown() {
202 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600203 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600204 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600205 }
206};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500207
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600208VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600209{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600210 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600211
212 result = cmdBuffer.BeginCommandBuffer();
213
214 /*
215 * For render test all drawing happens in a single render pass
216 * on a single command buffer.
217 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200218 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wuc278df82015-07-07 11:50:03 +0800219 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour30486ea2015-04-07 13:44:53 -0600220 }
221
222 return result;
223}
224
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600225VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600226{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600227 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600228
Chris Forbesfe133ef2015-06-16 14:05:59 +1200229 if (renderPass()) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800230 cmdBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200231 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600232
233 result = cmdBuffer.EndCommandBuffer();
234
235 return result;
236}
237
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500238void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
239{
240 // Create identity matrix
241 int i;
242 struct vktriangle_vs_uniform data;
243
244 glm::mat4 Projection = glm::mat4(1.0f);
245 glm::mat4 View = glm::mat4(1.0f);
246 glm::mat4 Model = glm::mat4(1.0f);
247 glm::mat4 MVP = Projection * View * Model;
248 const int matrixSize = sizeof(MVP);
249 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
250
251 memcpy(&data.mvp, &MVP[0][0], matrixSize);
252
253 static const Vertex tri_data[] =
254 {
255 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
256 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
257 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
258 };
259
260 for (i=0; i<3; i++) {
261 data.position[i][0] = tri_data[i].posX;
262 data.position[i][1] = tri_data[i].posY;
263 data.position[i][2] = tri_data[i].posZ;
264 data.position[i][3] = tri_data[i].posW;
265 data.color[i][0] = tri_data[i].r;
266 data.color[i][1] = tri_data[i].g;
267 data.color[i][2] = tri_data[i].b;
268 data.color[i][3] = tri_data[i].a;
269 }
270
271 ASSERT_NO_FATAL_FAILURE(InitState());
272 ASSERT_NO_FATAL_FAILURE(InitViewport());
273
274 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
275
276 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
277 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
278
279 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800280 pipelineobj.AddColorAttachment();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500281 pipelineobj.AddShader(&vs);
282 pipelineobj.AddShader(&ps);
283
284 VkDescriptorSetObj descriptorSet(m_device);
285 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
286
287 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600288 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500289
Tony Barbour1490c912015-07-28 10:17:20 -0600290 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500291
292 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -0600293 Draw(0, 3, 0, 1);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500294
295 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600296 EndCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500297
Tony Barbour1490c912015-07-28 10:17:20 -0600298 QueueCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500299}
300
301void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
302{
303 if (m_depthStencil->Initialized()) {
304 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
305 } else {
306 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
307 }
308
309 cmdBuffer->PrepareAttachments();
310 if ((failMask & BsoFailRaster) != BsoFailRaster) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600311 cmdBuffer->BindDynamicRasterState(m_stateRaster);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500312 }
313 if ((failMask & BsoFailViewport) != BsoFailViewport) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600314 cmdBuffer->BindDynamicViewportState(m_stateViewport);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500315 }
316 if ((failMask & BsoFailColorBlend) != BsoFailColorBlend) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600317 cmdBuffer->BindDynamicColorBlendState(m_colorBlend);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500318 }
319 if ((failMask & BsoFailDepthStencil) != BsoFailDepthStencil) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600320 cmdBuffer->BindDynamicDepthStencilState(m_stateDepthStencil);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500321 }
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600322 // Make sure depthWriteEnable is set so that DepthStencil fail test will work correctly
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600323 VkStencilOpState stencil = {};
324 stencil.stencilFailOp = VK_STENCIL_OP_KEEP;
325 stencil.stencilPassOp = VK_STENCIL_OP_KEEP;
326 stencil.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
327 stencil.stencilCompareOp = VK_COMPARE_OP_NEVER;
328
329 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
330 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
331 ds_ci.pNext = NULL;
332 ds_ci.depthTestEnable = VK_FALSE;
333 ds_ci.depthWriteEnable = VK_TRUE;
334 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
335 ds_ci.depthBoundsEnable = VK_FALSE;
336 ds_ci.stencilTestEnable = VK_FALSE;
337 ds_ci.front = stencil;
338 ds_ci.back = stencil;
339
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600340 pipelineobj.SetDepthStencil(&ds_ci);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500341 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Tony Barboured132432015-08-04 16:23:11 -0600342 pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500343 cmdBuffer->BindPipeline(pipelineobj);
344 cmdBuffer->BindDescriptorSet(descriptorSet);
345}
346
347// ********************************************************************************************************************
348// ********************************************************************************************************************
349// ********************************************************************************************************************
350// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600351#if MEM_TRACKER_TESTS
Mark Lobodzinski81078192015-05-19 10:28:29 -0500352TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
353{
354 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600355 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500356 std::string msgString;
357
358 VkFenceCreateInfo fenceInfo = {};
359 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
360 fenceInfo.pNext = NULL;
361 fenceInfo.flags = 0;
362
363 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barboure389b882015-07-20 13:00:10 -0600364
365 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
366 vk_testing::Buffer buffer;
367 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500368
Tony Barbour1490c912015-07-28 10:17:20 -0600369 BeginCommandBuffer();
370 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
371 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500372
373 testFence.init(*m_device, fenceInfo);
374
375 // Bypass framework since it does the waits automatically
376 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600377 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500378 ASSERT_VK_SUCCESS( err );
379
380 m_errorMonitor->ClearState();
381 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600382 vkResetCommandBuffer(m_cmdBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500383
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600384 msgFlags = m_errorMonitor->GetState(&msgString);
385 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 -0500386 if (!strstr(msgString.c_str(),"Resetting CB")) {
387 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
388 }
389}
390
391TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion)
392{
393 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600394 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500395 std::string msgString;
396
397 VkFenceCreateInfo fenceInfo = {};
398 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
399 fenceInfo.pNext = NULL;
400 fenceInfo.flags = 0;
401
402 ASSERT_NO_FATAL_FAILURE(InitState());
403 ASSERT_NO_FATAL_FAILURE(InitViewport());
404 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
405
Tony Barbour1490c912015-07-28 10:17:20 -0600406 BeginCommandBuffer();
407 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
408 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500409
410 testFence.init(*m_device, fenceInfo);
411
412 // Bypass framework since it does the waits automatically
413 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600414 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500415 ASSERT_VK_SUCCESS( err );
416
417 m_errorMonitor->ClearState();
418 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600419 BeginCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500420
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600421 msgFlags = m_errorMonitor->GetState(&msgString);
422 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 -0500423 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
424 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
425 }
426}
427
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500428TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
429{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600430 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500431 std::string msgString;
432 VkResult err;
433
434 ASSERT_NO_FATAL_FAILURE(InitState());
435 m_errorMonitor->ClearState();
436
437 // Create an image, allocate memory, free it, and then try to bind it
438 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500439 VkDeviceMemory mem;
440 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500441
442 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
443 const int32_t tex_width = 32;
444 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500445
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600446 VkImageCreateInfo image_create_info = {};
447 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
448 image_create_info.pNext = NULL;
449 image_create_info.imageType = VK_IMAGE_TYPE_2D;
450 image_create_info.format = tex_format;
451 image_create_info.extent.width = tex_width;
452 image_create_info.extent.height = tex_height;
453 image_create_info.extent.depth = 1;
454 image_create_info.mipLevels = 1;
455 image_create_info.arraySize = 1;
456 image_create_info.samples = 1;
457 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
458 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
459 image_create_info.flags = 0;
460
461 VkMemoryAllocInfo mem_alloc = {};
462 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
463 mem_alloc.pNext = NULL;
464 mem_alloc.allocationSize = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500465 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600466 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500467
468 err = vkCreateImage(m_device->device(), &image_create_info, &image);
469 ASSERT_VK_SUCCESS(err);
470
Tony Barboure84a8d62015-07-10 14:10:27 -0600471 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500472 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500473 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500474 ASSERT_VK_SUCCESS(err);
475
Mark Lobodzinski23182612015-05-29 09:32:35 -0500476 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500477
Mike Stroyand72da752015-08-04 10:49:29 -0600478 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tony Barbour49a3b652015-08-04 16:13:01 -0600479 if(err != VK_SUCCESS) // If we can't find any unmappable memory this test doesn't make sense
480 return;
Mike Stroyand72da752015-08-04 10:49:29 -0600481
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500482 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500483 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500484 ASSERT_VK_SUCCESS(err);
485
486 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600487 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500488 ASSERT_VK_SUCCESS(err);
489
490 // Map memory as if to initialize the image
491 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500492 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500493
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600494 msgFlags = m_errorMonitor->GetState(&msgString);
495 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 -0500496 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
497 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
498 }
499}
500
501TEST_F(VkLayerTest, BindInvalidMemory)
502{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600503 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500504 std::string msgString;
505 VkResult err;
506
507 ASSERT_NO_FATAL_FAILURE(InitState());
508 m_errorMonitor->ClearState();
509
510 // Create an image, allocate memory, free it, and then try to bind it
511 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500512 VkDeviceMemory mem;
513 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500514
515 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
516 const int32_t tex_width = 32;
517 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500518
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600519 VkImageCreateInfo image_create_info = {};
520 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
521 image_create_info.pNext = NULL;
522 image_create_info.imageType = VK_IMAGE_TYPE_2D;
523 image_create_info.format = tex_format;
524 image_create_info.extent.width = tex_width;
525 image_create_info.extent.height = tex_height;
526 image_create_info.extent.depth = 1;
527 image_create_info.mipLevels = 1;
528 image_create_info.arraySize = 1;
529 image_create_info.samples = 1;
530 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
531 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
532 image_create_info.flags = 0;
533
534 VkMemoryAllocInfo mem_alloc = {};
535 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
536 mem_alloc.pNext = NULL;
537 mem_alloc.allocationSize = 0;
538 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500539
540 err = vkCreateImage(m_device->device(), &image_create_info, &image);
541 ASSERT_VK_SUCCESS(err);
542
Tony Barboure84a8d62015-07-10 14:10:27 -0600543 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500544 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500545 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500546 ASSERT_VK_SUCCESS(err);
547
Mark Lobodzinski23182612015-05-29 09:32:35 -0500548 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500549
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800550 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600551 ASSERT_VK_SUCCESS(err);
552
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500553 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500554 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500555 ASSERT_VK_SUCCESS(err);
556
557 // Introduce validation failure, free memory before binding
Mark Lobodzinski23182612015-05-29 09:32:35 -0500558 vkFreeMemory(m_device->device(), mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500559 ASSERT_VK_SUCCESS(err);
560
561 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600562 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500563 ASSERT_VK_SUCCESS(err);
564
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600565 msgFlags = m_errorMonitor->GetState(&msgString);
566 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 -0500567 if (!strstr(msgString.c_str(),"couldn't find info for mem obj")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500568 FAIL() << "Error received did not match expected error message from BindObjectMemory in MemTracker";
569 }
570}
571
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600572// TODO : Is this test still valid. Not sure it is with updates to memory binding model
573// Verify and delete the test of fix the check
574//TEST_F(VkLayerTest, FreeBoundMemory)
575//{
576// VkFlags msgFlags;
577// std::string msgString;
578// VkResult err;
579//
580// ASSERT_NO_FATAL_FAILURE(InitState());
581// m_errorMonitor->ClearState();
582//
583// // Create an image, allocate memory, free it, and then try to bind it
584// VkImage image;
585// VkDeviceMemory mem;
586// VkMemoryRequirements mem_reqs;
587//
588// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
589// const int32_t tex_width = 32;
590// const int32_t tex_height = 32;
591//
592// const VkImageCreateInfo image_create_info = {
593// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
594// .pNext = NULL,
595// .imageType = VK_IMAGE_TYPE_2D,
596// .format = tex_format,
597// .extent = { tex_width, tex_height, 1 },
598// .mipLevels = 1,
599// .arraySize = 1,
600// .samples = 1,
601// .tiling = VK_IMAGE_TILING_LINEAR,
602// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
603// .flags = 0,
604// };
605// VkMemoryAllocInfo mem_alloc = {
606// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
607// .pNext = NULL,
608// .allocationSize = 0,
609// .memoryTypeIndex = 0,
610// };
611//
612// err = vkCreateImage(m_device->device(), &image_create_info, &image);
613// ASSERT_VK_SUCCESS(err);
614//
615// err = vkGetImageMemoryRequirements(m_device->device(),
616// image,
617// &mem_reqs);
618// ASSERT_VK_SUCCESS(err);
619//
620// mem_alloc.allocationSize = mem_reqs.size;
621//
622// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
623// ASSERT_VK_SUCCESS(err);
624//
625// // allocate memory
626// err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
627// ASSERT_VK_SUCCESS(err);
628//
629// // Bind memory to Image object
630// err = vkBindImageMemory(m_device->device(), image, mem, 0);
631// ASSERT_VK_SUCCESS(err);
632//
633// // Introduce validation failure, free memory while still bound to object
634// vkFreeMemory(m_device->device(), mem);
635// ASSERT_VK_SUCCESS(err);
636//
637// msgFlags = m_errorMonitor->GetState(&msgString);
638// ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an warning while tring to free bound memory";
639// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
640// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
641// }
642//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500643
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500644TEST_F(VkLayerTest, RebindMemory)
645{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600646 VkFlags msgFlags;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500647 std::string msgString;
648 VkResult err;
649
650 ASSERT_NO_FATAL_FAILURE(InitState());
651 m_errorMonitor->ClearState();
652
653 // Create an image, allocate memory, free it, and then try to bind it
654 VkImage image;
655 VkDeviceMemory mem1;
656 VkDeviceMemory mem2;
657 VkMemoryRequirements mem_reqs;
658
659 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
660 const int32_t tex_width = 32;
661 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500662
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600663 VkImageCreateInfo image_create_info = {};
664 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
665 image_create_info.pNext = NULL;
666 image_create_info.imageType = VK_IMAGE_TYPE_2D;
667 image_create_info.format = tex_format;
668 image_create_info.extent.width = tex_width;
669 image_create_info.extent.height = tex_height;
670 image_create_info.extent.depth = 1;
671 image_create_info.mipLevels = 1;
672 image_create_info.arraySize = 1;
673 image_create_info.samples = 1;
674 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
675 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
676 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500677
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600678 VkMemoryAllocInfo mem_alloc = {};
679 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
680 mem_alloc.pNext = NULL;
681 mem_alloc.allocationSize = 0;
682 mem_alloc.memoryTypeIndex = 0;
683
684 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
685 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500686 err = vkCreateImage(m_device->device(), &image_create_info, &image);
687 ASSERT_VK_SUCCESS(err);
688
Tony Barboure84a8d62015-07-10 14:10:27 -0600689 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500690 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500691 &mem_reqs);
692 ASSERT_VK_SUCCESS(err);
693
694 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800695 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600696 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500697
698 // allocate 2 memory objects
699 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
700 ASSERT_VK_SUCCESS(err);
701 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
702 ASSERT_VK_SUCCESS(err);
703
704 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600705 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500706 ASSERT_VK_SUCCESS(err);
707
708 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600709 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500710 ASSERT_VK_SUCCESS(err);
711
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600712 msgFlags = m_errorMonitor->GetState(&msgString);
713 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 -0500714 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
715 FAIL() << "Error received did not match expected message when rebinding memory to an object";
716 }
717}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500718
719TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
720{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600721 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500722 std::string msgString;
723 VkResult err;
724
725 ASSERT_NO_FATAL_FAILURE(InitState());
726 m_errorMonitor->ClearState();
727
728 // Create an image object, allocate memory, destroy the object and then try to bind it
729 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500730 VkDeviceMemory mem;
731 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500732
733 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
734 const int32_t tex_width = 32;
735 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500736
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600737 VkImageCreateInfo image_create_info = {};
738 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
739 image_create_info.pNext = NULL;
740 image_create_info.imageType = VK_IMAGE_TYPE_2D;
741 image_create_info.format = tex_format;
742 image_create_info.extent.width = tex_width;
743 image_create_info.extent.height = tex_height;
744 image_create_info.extent.depth = 1;
745 image_create_info.mipLevels = 1;
746 image_create_info.arraySize = 1;
747 image_create_info.samples = 1;
748 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
749 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
750 image_create_info.flags = 0;
751
752 VkMemoryAllocInfo mem_alloc = {};
753 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
754 mem_alloc.pNext = NULL;
755 mem_alloc.allocationSize = 0;
756 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500757
758 err = vkCreateImage(m_device->device(), &image_create_info, &image);
759 ASSERT_VK_SUCCESS(err);
760
Tony Barboure84a8d62015-07-10 14:10:27 -0600761 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500762 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500763 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500764 ASSERT_VK_SUCCESS(err);
765
Mark Lobodzinski23182612015-05-29 09:32:35 -0500766 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800767 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600768 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500769
770 // Allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500771 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500772 ASSERT_VK_SUCCESS(err);
773
774 // Introduce validation failure, destroy Image object before binding
Tony Barboure84a8d62015-07-10 14:10:27 -0600775 vkDestroyImage(m_device->device(), image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500776 ASSERT_VK_SUCCESS(err);
777
Mike Stroyand72da752015-08-04 10:49:29 -0600778 // Now Try to bind memory to this destroyed object
Tony Barboure84a8d62015-07-10 14:10:27 -0600779 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mike Stroyand72da752015-08-04 10:49:29 -0600780 // This may very well return an error.
781 (void) err;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500782
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600783 msgFlags = m_errorMonitor->GetState(&msgString);
784 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 -0500785 if (!strstr(msgString.c_str(),"that's not in global list")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500786 FAIL() << "Error received did not match expected error message from updateObjectBinding in MemTracker";
787 }
788}
789
Tony Barbour8508b8e2015-04-09 10:48:04 -0600790TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600791{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600792 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600793 VkFlags msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600794 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600795
796 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600797 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
798 fenceInfo.pNext = NULL;
799 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600800
Tony Barbour30486ea2015-04-07 13:44:53 -0600801 ASSERT_NO_FATAL_FAILURE(InitState());
802 ASSERT_NO_FATAL_FAILURE(InitViewport());
803 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
804
Tony Barbour1490c912015-07-28 10:17:20 -0600805 BeginCommandBuffer();
806 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
807 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600808
809 testFence.init(*m_device, fenceInfo);
810 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -0600811 QueueCommandBuffer(testFence.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600812 msgFlags = m_errorMonitor->GetState(&msgString);
813 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 -0600814 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500815 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600816 }
817
818}
819
820TEST_F(VkLayerTest, ResetUnsignaledFence)
821{
822 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600823 VkFlags msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600824 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600825 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600826 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
827 fenceInfo.pNext = NULL;
828
Tony Barbour8508b8e2015-04-09 10:48:04 -0600829 ASSERT_NO_FATAL_FAILURE(InitState());
830 testFence.init(*m_device, fenceInfo);
831 m_errorMonitor->ClearState();
Chia-I Wua4992342015-07-03 11:45:55 +0800832 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600833 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600834 msgFlags = m_errorMonitor->GetState(&msgString);
835 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 -0600836 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500837 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600838 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600839
840}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600841
Chia-I Wuc278df82015-07-07 11:50:03 +0800842/* TODO: Update for changes due to bug-14075 tiling across render passes */
843#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600844TEST_F(VkLayerTest, InvalidUsageBits)
845{
846 // Initiate Draw w/o a PSO bound
847 VkFlags msgFlags;
848 std::string msgString;
849
850 ASSERT_NO_FATAL_FAILURE(InitState());
851 m_errorMonitor->ClearState();
852 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600853 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600854
855 const VkExtent3D e3d = {
856 .width = 128,
857 .height = 128,
858 .depth = 1,
859 };
860 const VkImageCreateInfo ici = {
861 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
862 .pNext = NULL,
863 .imageType = VK_IMAGE_TYPE_2D,
864 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
865 .extent = e3d,
866 .mipLevels = 1,
867 .arraySize = 1,
868 .samples = 1,
869 .tiling = VK_IMAGE_TILING_LINEAR,
870 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_BIT
871 .flags = 0,
872 };
873
874 VkImage dsi;
875 vkCreateImage(m_device->device(), &ici, &dsi);
876 VkDepthStencilView dsv;
877 const VkDepthStencilViewCreateInfo dsvci = {
878 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
879 .pNext = NULL,
880 .image = dsi,
881 .mipLevel = 0,
882 .baseArraySlice = 0,
883 .arraySize = 1,
884 .flags = 0,
885 };
886 vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv);
887 msgFlags = m_errorMonitor->GetState(&msgString);
888 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after attempting to create DSView w/ image lacking USAGE_DS_BIT flag";
889 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
890 FAIL() << "Error received was not 'Invalid usage flag for image...'";
891 }
892}
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600893#endif
Chia-I Wuc278df82015-07-07 11:50:03 +0800894#endif
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600895#if OBJ_TRACKER_TESTS
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500896TEST_F(VkLayerTest, RasterStateNotBound)
897{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600898 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500899 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600900 ASSERT_NO_FATAL_FAILURE(InitState());
901 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500902 TEST_DESCRIPTION("Simple Draw Call that validates failure when a raster state object is not bound beforehand");
903
904 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailRaster);
905
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600906 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600907 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 -0500908 if (!strstr(msgString.c_str(),"Raster object not bound to this command buffer")) {
909 FAIL() << "Error received was not 'Raster object not bound to this command buffer'";
910 }
911}
912
913TEST_F(VkLayerTest, ViewportStateNotBound)
914{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600915 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500916 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600917 ASSERT_NO_FATAL_FAILURE(InitState());
918 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500919 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
920
921 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
922
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600923 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600924 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 -0500925 if (!strstr(msgString.c_str(),"Viewport object not bound to this command buffer")) {
926 FAIL() << "Error received was not 'Viewport object not bound to this command buffer'";
927 }
928}
929
930TEST_F(VkLayerTest, ColorBlendStateNotBound)
931{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600932 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500933 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600934 ASSERT_NO_FATAL_FAILURE(InitState());
935 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500936 TEST_DESCRIPTION("Simple Draw Call that validates failure when a color-blend state object is not bound beforehand");
937
938 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailColorBlend);
939
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600940 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600941 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 -0500942 if (!strstr(msgString.c_str(),"Color-blend object not bound to this command buffer")) {
943 FAIL() << "Error received was not 'Color-blend object not bound to this command buffer'";
944 }
945}
946
947TEST_F(VkLayerTest, DepthStencilStateNotBound)
948{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600949 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500950 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600951 ASSERT_NO_FATAL_FAILURE(InitState());
952 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500953 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth-stencil state object is not bound beforehand");
954
955 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthStencil);
956
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600957 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600958 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 -0500959 if (!strstr(msgString.c_str(),"Depth-stencil object not bound to this command buffer")) {
960 FAIL() << "Error received was not 'Depth-stencil object not bound to this command buffer'";
961 }
Tony Barbourdb686622015-05-06 09:35:56 -0600962}
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600963#endif
964#if DRAW_STATE_TESTS
Tobin Ehlise4076782015-06-24 15:53:07 -0600965TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600966{
967 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600968 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600969 std::string msgString;
970
971 ASSERT_NO_FATAL_FAILURE(InitState());
972 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -0600973 BeginCommandBuffer();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600974 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Tony Barbour1490c912015-07-28 10:17:20 -0600975 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600976 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlise4076782015-06-24 15:53:07 -0600977 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding pipeline to CmdBuffer w/o active RenderPass";
978 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
979 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0xbaadb1be) without an active RenderPass'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600980 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600981}
982
983TEST_F(VkLayerTest, InvalidDescriptorPool)
984{
985 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
986 // The DS check for this is after driver has been called to validate DS internal data struct
987 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600988/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600989 std::string msgString;
990 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
991 vkResetDescriptorPool(device(), badPool);
992
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600993 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600994 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 -0600995 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
996 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
997 }*/
998}
999
1000TEST_F(VkLayerTest, InvalidDescriptorSet)
1001{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001002 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1003 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001004 // Create a valid cmd buffer
1005 // call vkCmdBindDescriptorSets w/ false DS
1006}
1007
1008TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1009{
1010 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1011 // The DS check for this is after driver has been called to validate DS internal data struct
1012}
1013
1014TEST_F(VkLayerTest, InvalidPipeline)
1015{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001016 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1017 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001018 // Create a valid cmd buffer
1019 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -06001020// VkFlags msgFlags;
1021// std::string msgString;
1022//
1023// ASSERT_NO_FATAL_FAILURE(InitState());
1024// m_errorMonitor->ClearState();
1025// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001026// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001027// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1028// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1029// msgFlags = m_errorMonitor->GetState(&msgString);
1030// ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding invalid pipeline to CmdBuffer";
1031// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1032// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1033// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001034}
1035
Tobin Ehlis254eca02015-06-25 15:46:59 -06001036TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001037{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001038 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001039 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001040 std::string msgString;
1041 VkResult err;
1042
1043 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001044 ASSERT_NO_FATAL_FAILURE(InitViewport());
1045 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001046 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001047 VkDescriptorTypeCount ds_type_count = {};
1048 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1049 ds_type_count.count = 1;
1050
1051 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1052 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1053 ds_pool_ci.pNext = NULL;
1054 ds_pool_ci.count = 1;
1055 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001056
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001057 VkDescriptorPool ds_pool;
1058 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1059 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001060
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001061 VkDescriptorSetLayoutBinding dsl_binding = {};
1062 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1063 dsl_binding.arraySize = 1;
1064 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1065 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001066
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001067 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1068 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1069 ds_layout_ci.pNext = NULL;
1070 ds_layout_ci.count = 1;
1071 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001072 VkDescriptorSetLayout ds_layout;
1073 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1074 ASSERT_VK_SUCCESS(err);
1075
1076 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001077 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001078 ASSERT_VK_SUCCESS(err);
1079
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001080 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1081 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1082 pipeline_layout_ci.pNext = NULL;
1083 pipeline_layout_ci.descriptorSetCount = 1;
1084 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001085
1086 VkPipelineLayout pipeline_layout;
1087 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1088 ASSERT_VK_SUCCESS(err);
1089
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001090 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001091 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1092 // but add it to be able to run on more devices
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001093
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001094 VkPipelineObj pipe(m_device);
1095 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001096 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001097 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001098
1099 BeginCommandBuffer();
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001100 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbour1490c912015-07-28 10:17:20 -06001101 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001102
Tobin Ehlis254eca02015-06-25 15:46:59 -06001103 msgFlags = m_errorMonitor->GetState(&msgString);
1104 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not warn after binding a DescriptorSet that was never updated.";
1105 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1106 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1107 }
1108}
1109
1110TEST_F(VkLayerTest, NoBeginCmdBuffer)
1111{
1112 VkFlags msgFlags;
1113 std::string msgString;
1114
1115 ASSERT_NO_FATAL_FAILURE(InitState());
1116 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001117 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001118 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1119 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1120 msgFlags = m_errorMonitor->GetState(&msgString);
1121 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after ending a CmdBuffer w/o calling BeginCommandBuffer()";
1122 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1123 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1124 }
1125}
1126
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001127TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1128{
1129 VkFlags msgFlags;
1130 std::string msgString;
1131
1132 ASSERT_NO_FATAL_FAILURE(InitState());
1133 m_errorMonitor->ClearState();
1134
1135 // Calls CreateCommandBuffer
1136 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1137
1138 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northrop10d8f982015-08-04 17:35:57 -06001139 VkCmdBufferBeginInfo cmd_buf_info = {};
1140 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1141 cmd_buf_info.pNext = NULL;
1142 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1143 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1144 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1145 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1146
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001147
1148 // The error should be caught by validation of the BeginCommandBuffer call
1149 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1150
1151 msgFlags = m_errorMonitor->GetState(&msgString);
1152 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error passing a non-NULL Framebuffer and Renderpass to BeginCommandBuffer()";
1153 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1154 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1155 }
1156}
1157
1158TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1159{
1160 VkFlags msgFlags;
1161 std::string msgString;
1162 VkResult err;
1163 VkCmdBuffer draw_cmd;
1164 VkCmdPool cmd_pool;
1165
1166 ASSERT_NO_FATAL_FAILURE(InitState());
1167 m_errorMonitor->ClearState();
1168
Cody Northrop10d8f982015-08-04 17:35:57 -06001169 VkCmdBufferCreateInfo cmd = {};
1170 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1171 cmd.pNext = NULL;
1172 cmd.cmdPool = m_cmdPool;
1173 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1174 cmd.flags = 0;
1175
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001176 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
1177 assert(!err);
1178
1179 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northrop10d8f982015-08-04 17:35:57 -06001180 VkCmdBufferBeginInfo cmd_buf_info = {};
1181 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1182 cmd_buf_info.pNext = NULL;
1183 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1184 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001185
1186 // The error should be caught by validation of the BeginCommandBuffer call
1187 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1188
1189 msgFlags = m_errorMonitor->GetState(&msgString);
1190 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error passing NULL Framebuffer/Renderpass to BeginCommandBuffer()";
1191 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1192 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1193 }
1194}
1195
Tobin Ehlis254eca02015-06-25 15:46:59 -06001196TEST_F(VkLayerTest, InvalidPipelineCreateState)
1197{
1198 // Attempt to Create Gfx Pipeline w/o a VS
1199 VkFlags msgFlags;
1200 std::string msgString;
1201 VkResult err;
1202
1203 ASSERT_NO_FATAL_FAILURE(InitState());
1204 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001205
1206 VkDescriptorTypeCount ds_type_count = {};
1207 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1208 ds_type_count.count = 1;
1209
1210 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1211 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1212 ds_pool_ci.pNext = NULL;
1213 ds_pool_ci.count = 1;
1214 ds_pool_ci.pTypeCount = &ds_type_count;
1215
Tobin Ehlis254eca02015-06-25 15:46:59 -06001216 VkDescriptorPool ds_pool;
1217 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1218 ASSERT_VK_SUCCESS(err);
1219
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001220 VkDescriptorSetLayoutBinding dsl_binding = {};
1221 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1222 dsl_binding.arraySize = 1;
1223 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1224 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001225
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001226 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1227 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1228 ds_layout_ci.pNext = NULL;
1229 ds_layout_ci.count = 1;
1230 ds_layout_ci.pBinding = &dsl_binding;
1231
Tobin Ehlis254eca02015-06-25 15:46:59 -06001232 VkDescriptorSetLayout ds_layout;
1233 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1234 ASSERT_VK_SUCCESS(err);
1235
1236 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001237 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001238 ASSERT_VK_SUCCESS(err);
1239
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001240 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1241 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1242 pipeline_layout_ci.pNext = NULL;
1243 pipeline_layout_ci.descriptorSetCount = 1;
1244 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001245
1246 VkPipelineLayout pipeline_layout;
1247 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1248 ASSERT_VK_SUCCESS(err);
1249
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001250 VkGraphicsPipelineCreateInfo gp_ci = {};
1251 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1252 gp_ci.pNext = NULL;
1253 gp_ci.stageCount = 0;
1254 gp_ci.pStages = NULL;
1255 gp_ci.pVertexInputState = NULL;
1256 gp_ci.pInputAssemblyState = NULL;
1257 gp_ci.pTessellationState = NULL;
1258 gp_ci.pViewportState = NULL;
1259 gp_ci.pRasterState = NULL;
1260 gp_ci.pMultisampleState = NULL;
1261 gp_ci.pDepthStencilState = NULL;
1262 gp_ci.pColorBlendState = NULL;
1263 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1264 gp_ci.layout = pipeline_layout;
1265
1266 VkPipelineCacheCreateInfo pc_ci = {};
1267 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1268 pc_ci.pNext = NULL;
1269 pc_ci.initialSize = 0;
1270 pc_ci.initialData = 0;
1271 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001272
1273 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001274 VkPipelineCache pipelineCache;
1275
1276 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1277 ASSERT_VK_SUCCESS(err);
1278 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001279
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001280 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001281 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after creating Gfx Pipeline w/o VS.";
1282 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1283 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1284 }
1285}
1286
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001287TEST_F(VkLayerTest, NullRenderPass)
1288{
1289 // Bind a NULL RenderPass
1290 VkFlags msgFlags;
1291 std::string msgString;
1292
1293 ASSERT_NO_FATAL_FAILURE(InitState());
1294 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1295 m_errorMonitor->ClearState();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001296
Tony Barbour1490c912015-07-28 10:17:20 -06001297 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001298 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06001299 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001300
1301 msgFlags = m_errorMonitor->GetState(&msgString);
1302 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding NULL RenderPass.";
1303 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
1304 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
1305 }
1306}
1307
Tobin Ehlis254eca02015-06-25 15:46:59 -06001308TEST_F(VkLayerTest, RenderPassWithinRenderPass)
1309{
1310 // Bind a BeginRenderPass within an active RenderPass
1311 VkFlags msgFlags;
1312 std::string msgString;
1313
1314 ASSERT_NO_FATAL_FAILURE(InitState());
1315 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1316 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001317
Tony Barbour1490c912015-07-28 10:17:20 -06001318 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001319 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001320 VkRenderPassBeginInfo rp_begin = {};
1321 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
1322 rp_begin.pNext = NULL;
1323 rp_begin.renderPass = (VkRenderPass)0xc001d00d;
1324 rp_begin.framebuffer = 0;
1325
Tony Barbour1490c912015-07-28 10:17:20 -06001326 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001327
1328 msgFlags = m_errorMonitor->GetState(&msgString);
1329 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding RenderPass w/i an active RenderPass.";
1330 if (!strstr(msgString.c_str(),"Cannot call vkCmdBeginRenderPass() during an active RenderPass ")) {
1331 FAIL() << "Error received was not 'Cannot call vkCmdBeginRenderPass() during an active RenderPass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001332 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001333}
1334
1335TEST_F(VkLayerTest, InvalidDynamicStateObject)
1336{
1337 // Create a valid cmd buffer
1338 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001339 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1340 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001341}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06001342
Tobin Ehlise4076782015-06-24 15:53:07 -06001343TEST_F(VkLayerTest, VtxBufferNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001344{
1345 // Bind VBO out-of-bounds for given PSO
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001346 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001347 std::string msgString;
1348 VkResult err;
1349
1350 ASSERT_NO_FATAL_FAILURE(InitState());
1351 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001352
1353 VkDescriptorTypeCount ds_type_count = {};
1354 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1355 ds_type_count.count = 1;
1356
1357 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1358 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1359 ds_pool_ci.pNext = NULL;
1360 ds_pool_ci.count = 1;
1361 ds_pool_ci.pTypeCount = &ds_type_count;
1362
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001363 VkDescriptorPool ds_pool;
1364 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1365 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001366
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001367 VkDescriptorSetLayoutBinding dsl_binding = {};
1368 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1369 dsl_binding.arraySize = 1;
1370 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1371 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001372
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001373 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1374 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1375 ds_layout_ci.pNext = NULL;
1376 ds_layout_ci.count = 1;
1377 ds_layout_ci.pBinding = &dsl_binding;
1378
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001379 VkDescriptorSetLayout ds_layout;
1380 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1381 ASSERT_VK_SUCCESS(err);
1382
1383 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001384 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001385 ASSERT_VK_SUCCESS(err);
1386
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001387 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1388 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1389 pipeline_layout_ci.pNext = NULL;
1390 pipeline_layout_ci.descriptorSetCount = 1;
1391 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001392
1393 VkPipelineLayout pipeline_layout;
1394 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1395 ASSERT_VK_SUCCESS(err);
1396
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001397 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001398 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1399 // but add it to be able to run on more devices
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001400 VkPipelineObj pipe(m_device);
1401 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001402 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001403 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001404
Tony Barbour1490c912015-07-28 10:17:20 -06001405 BeginCommandBuffer();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001406 ASSERT_VK_SUCCESS(err);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001407 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001408 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06001409 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001410
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001411 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlise4076782015-06-24 15:53:07 -06001412 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
1413 if (!strstr(msgString.c_str(),"Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.")) {
1414 FAIL() << "Error received was not 'Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001415 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001416}
1417
1418TEST_F(VkLayerTest, DSTypeMismatch)
1419{
1420 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001421 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001422 std::string msgString;
1423 VkResult err;
1424
1425 ASSERT_NO_FATAL_FAILURE(InitState());
1426 m_errorMonitor->ClearState();
1427 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001428 VkDescriptorTypeCount ds_type_count = {};
1429 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1430 ds_type_count.count = 1;
1431
1432 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1433 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1434 ds_pool_ci.pNext = NULL;
1435 ds_pool_ci.count = 1;
1436 ds_pool_ci.pTypeCount = &ds_type_count;
1437
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001438 VkDescriptorPool ds_pool;
1439 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1440 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001441 VkDescriptorSetLayoutBinding dsl_binding = {};
1442 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1443 dsl_binding.arraySize = 1;
1444 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1445 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001446
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001447 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1448 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1449 ds_layout_ci.pNext = NULL;
1450 ds_layout_ci.count = 1;
1451 ds_layout_ci.pBinding = &dsl_binding;
1452
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001453 VkDescriptorSetLayout ds_layout;
1454 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1455 ASSERT_VK_SUCCESS(err);
1456
1457 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001458 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001459 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001460
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001461 VkSamplerCreateInfo sampler_ci = {};
1462 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1463 sampler_ci.pNext = NULL;
1464 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1465 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1466 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1467 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1468 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1469 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1470 sampler_ci.mipLodBias = 1.0;
1471 sampler_ci.maxAnisotropy = 1;
1472 sampler_ci.compareEnable = VK_FALSE;
1473 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1474 sampler_ci.minLod = 1.0;
1475 sampler_ci.maxLod = 1.0;
1476 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1477
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001478 VkSampler sampler;
1479 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1480 ASSERT_VK_SUCCESS(err);
1481
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001482 VkDescriptorInfo descriptor_info;
1483 memset(&descriptor_info, 0, sizeof(descriptor_info));
1484 descriptor_info.sampler = sampler;
1485
1486 VkWriteDescriptorSet descriptor_write;
1487 memset(&descriptor_write, 0, sizeof(descriptor_write));
1488 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1489 descriptor_write.destSet = descriptorSet;
1490 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001491 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001492 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1493 descriptor_write.pDescriptors = &descriptor_info;
1494
1495 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1496
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001497 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001498 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 +08001499 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) {
1500 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 -06001501 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001502}
1503
1504TEST_F(VkLayerTest, DSUpdateOutOfBounds)
1505{
1506 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001507 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001508 std::string msgString;
1509 VkResult err;
1510
1511 ASSERT_NO_FATAL_FAILURE(InitState());
1512 m_errorMonitor->ClearState();
1513 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001514 VkDescriptorTypeCount ds_type_count = {};
1515 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1516 ds_type_count.count = 1;
1517
1518 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1519 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1520 ds_pool_ci.pNext = NULL;
1521 ds_pool_ci.count = 1;
1522 ds_pool_ci.pTypeCount = &ds_type_count;
1523
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001524 VkDescriptorPool ds_pool;
1525 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1526 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001527
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001528 VkDescriptorSetLayoutBinding dsl_binding = {};
1529 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1530 dsl_binding.arraySize = 1;
1531 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1532 dsl_binding.pImmutableSamplers = NULL;
1533
1534 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1535 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1536 ds_layout_ci.pNext = NULL;
1537 ds_layout_ci.count = 1;
1538 ds_layout_ci.pBinding = &dsl_binding;
1539
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001540 VkDescriptorSetLayout ds_layout;
1541 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1542 ASSERT_VK_SUCCESS(err);
1543
1544 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001545 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001546 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001547
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001548 VkSamplerCreateInfo sampler_ci = {};
1549 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1550 sampler_ci.pNext = NULL;
1551 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1552 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1553 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1554 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1555 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1556 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1557 sampler_ci.mipLodBias = 1.0;
1558 sampler_ci.maxAnisotropy = 1;
1559 sampler_ci.compareEnable = VK_FALSE;
1560 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1561 sampler_ci.minLod = 1.0;
1562 sampler_ci.maxLod = 1.0;
1563 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1564
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001565 VkSampler sampler;
1566 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1567 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001568
1569 VkDescriptorInfo descriptor_info;
1570 memset(&descriptor_info, 0, sizeof(descriptor_info));
1571 descriptor_info.sampler = sampler;
1572
1573 VkWriteDescriptorSet descriptor_write;
1574 memset(&descriptor_write, 0, sizeof(descriptor_write));
1575 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1576 descriptor_write.destSet = descriptorSet;
1577 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
1578 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001579 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001580 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1581 descriptor_write.pDescriptors = &descriptor_info;
1582
1583 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1584
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001585 msgFlags = m_errorMonitor->GetState(&msgString);
1586 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 +08001587 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
1588 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 -06001589 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001590}
1591
1592TEST_F(VkLayerTest, InvalidDSUpdateIndex)
1593{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001594 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001595 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001596 std::string msgString;
1597 VkResult err;
1598
1599 ASSERT_NO_FATAL_FAILURE(InitState());
1600 m_errorMonitor->ClearState();
1601 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001602 VkDescriptorTypeCount ds_type_count = {};
1603 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1604 ds_type_count.count = 1;
1605
1606 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1607 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1608 ds_pool_ci.pNext = NULL;
1609 ds_pool_ci.count = 1;
1610 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001611 VkDescriptorPool ds_pool;
1612 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1613 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001614
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001615 VkDescriptorSetLayoutBinding dsl_binding = {};
1616 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1617 dsl_binding.arraySize = 1;
1618 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1619 dsl_binding.pImmutableSamplers = NULL;
1620
1621 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1622 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1623 ds_layout_ci.pNext = NULL;
1624 ds_layout_ci.count = 1;
1625 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001626 VkDescriptorSetLayout ds_layout;
1627 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1628 ASSERT_VK_SUCCESS(err);
1629
1630 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001631 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001632 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001633
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001634 VkSamplerCreateInfo sampler_ci = {};
1635 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1636 sampler_ci.pNext = NULL;
1637 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1638 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1639 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1640 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1641 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1642 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1643 sampler_ci.mipLodBias = 1.0;
1644 sampler_ci.maxAnisotropy = 1;
1645 sampler_ci.compareEnable = VK_FALSE;
1646 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1647 sampler_ci.minLod = 1.0;
1648 sampler_ci.maxLod = 1.0;
1649 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1650
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001651 VkSampler sampler;
1652 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1653 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001654
1655 VkDescriptorInfo descriptor_info;
1656 memset(&descriptor_info, 0, sizeof(descriptor_info));
1657 descriptor_info.sampler = sampler;
1658
1659 VkWriteDescriptorSet descriptor_write;
1660 memset(&descriptor_write, 0, sizeof(descriptor_write));
1661 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1662 descriptor_write.destSet = descriptorSet;
1663 descriptor_write.destBinding = 2;
1664 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001665 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001666 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1667 descriptor_write.pDescriptors = &descriptor_info;
1668
1669 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1670
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001671 msgFlags = m_errorMonitor->GetState(&msgString);
1672 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 -06001673 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
1674 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
1675 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001676}
1677
1678TEST_F(VkLayerTest, InvalidDSUpdateStruct)
1679{
1680 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001681 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001682 std::string msgString;
1683 VkResult err;
1684
1685 ASSERT_NO_FATAL_FAILURE(InitState());
1686 m_errorMonitor->ClearState();
1687 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001688
1689 VkDescriptorTypeCount ds_type_count = {};
1690 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1691 ds_type_count.count = 1;
1692
1693 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1694 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1695 ds_pool_ci.pNext = NULL;
1696 ds_pool_ci.count = 1;
1697 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001698 VkDescriptorPool ds_pool;
1699 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1700 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001701 VkDescriptorSetLayoutBinding dsl_binding = {};
1702 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1703 dsl_binding.arraySize = 1;
1704 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1705 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001706
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001707 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1708 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1709 ds_layout_ci.pNext = NULL;
1710 ds_layout_ci.count = 1;
1711 ds_layout_ci.pBinding = &dsl_binding;
1712
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001713 VkDescriptorSetLayout ds_layout;
1714 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1715 ASSERT_VK_SUCCESS(err);
1716
1717 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001718 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001719 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();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001774 VkDescriptorTypeCount ds_type_count = {};
1775 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1776 ds_type_count.count = 1;
1777
1778 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1779 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1780 ds_pool_ci.pNext = NULL;
1781 ds_pool_ci.count = 1;
1782 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001783 VkDescriptorPool ds_pool;
1784 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1785 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001786
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001787 VkDescriptorSetLayoutBinding dsl_binding = {};
1788 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1789 dsl_binding.arraySize = 1;
1790 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1791 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001792
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001793 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1794 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1795 ds_layout_ci.pNext = NULL;
1796 ds_layout_ci.count = 1;
1797 ds_layout_ci.pBinding = &dsl_binding;
1798
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001799 VkDescriptorSetLayout ds_layout;
1800 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1801 ASSERT_VK_SUCCESS(err);
1802
1803 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001804 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001805 ASSERT_VK_SUCCESS(err);
1806
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001807 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1808 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1809 pipe_ms_state_ci.pNext = NULL;
1810 pipe_ms_state_ci.rasterSamples = 4;
1811 pipe_ms_state_ci.sampleShadingEnable = 0;
1812 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06001813 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001814
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001815 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1816 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1817 pipeline_layout_ci.pNext = NULL;
1818 pipeline_layout_ci.descriptorSetCount = 1;
1819 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001820
1821 VkPipelineLayout pipeline_layout;
1822 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1823 ASSERT_VK_SUCCESS(err);
1824
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001825 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001826 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1827 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06001828 VkPipelineObj pipe(m_device);
1829 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001830 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06001831 pipe.SetMSAA(&pipe_ms_state_ci);
1832 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001833
Tony Barbour1490c912015-07-28 10:17:20 -06001834 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06001835 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001836
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001837 msgFlags = m_errorMonitor->GetState(&msgString);
1838 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 -06001839 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
1840 FAIL() << "Error received was not 'Num samples mismatch!...'";
1841 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001842}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001843
Tobin Ehlise4076782015-06-24 15:53:07 -06001844TEST_F(VkLayerTest, PipelineNotBound)
1845{
1846 VkFlags msgFlags;
1847 std::string msgString;
1848 VkResult err;
1849
1850 ASSERT_NO_FATAL_FAILURE(InitState());
1851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1852 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001853
1854 VkDescriptorTypeCount ds_type_count = {};
1855 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1856 ds_type_count.count = 1;
1857
1858 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1859 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1860 ds_pool_ci.pNext = NULL;
1861 ds_pool_ci.count = 1;
1862 ds_pool_ci.pTypeCount = &ds_type_count;
1863
Tobin Ehlise4076782015-06-24 15:53:07 -06001864 VkDescriptorPool ds_pool;
1865 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1866 ASSERT_VK_SUCCESS(err);
1867
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001868 VkDescriptorSetLayoutBinding dsl_binding = {};
1869 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1870 dsl_binding.arraySize = 1;
1871 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1872 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06001873
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001874 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1875 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1876 ds_layout_ci.pNext = NULL;
1877 ds_layout_ci.count = 1;
1878 ds_layout_ci.pBinding = &dsl_binding;
1879
Tobin Ehlise4076782015-06-24 15:53:07 -06001880 VkDescriptorSetLayout ds_layout;
1881 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1882 ASSERT_VK_SUCCESS(err);
1883
1884 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001885 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06001886 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001887
1888 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1889 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1890 pipeline_layout_ci.pNext = NULL;
1891 pipeline_layout_ci.descriptorSetCount = 1;
1892 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06001893
1894 VkPipelineLayout pipeline_layout;
1895 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1896 ASSERT_VK_SUCCESS(err);
1897
Tobin Ehlise4076782015-06-24 15:53:07 -06001898 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Tony Barbour1490c912015-07-28 10:17:20 -06001899
1900 BeginCommandBuffer();
1901 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06001902
1903 msgFlags = m_errorMonitor->GetState(&msgString);
1904 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding invalid pipeline to CmdBuffer";
1905 if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1906 FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1907 }
1908}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001909
1910TEST_F(VkLayerTest, ClearCmdNoDraw)
1911{
1912 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
1913 VkFlags msgFlags;
1914 std::string msgString;
1915 VkResult err;
1916
1917 ASSERT_NO_FATAL_FAILURE(InitState());
1918 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1919 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001920
1921 VkDescriptorTypeCount ds_type_count = {};
1922 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1923 ds_type_count.count = 1;
1924
1925 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1926 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1927 ds_pool_ci.pNext = NULL;
1928 ds_pool_ci.count = 1;
1929 ds_pool_ci.pTypeCount = &ds_type_count;
1930
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001931 VkDescriptorPool ds_pool;
1932 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1933 ASSERT_VK_SUCCESS(err);
1934
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001935 VkDescriptorSetLayoutBinding dsl_binding = {};
1936 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1937 dsl_binding.arraySize = 1;
1938 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1939 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001940
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001941 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1942 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1943 ds_layout_ci.pNext = NULL;
1944 ds_layout_ci.count = 1;
1945 ds_layout_ci.pBinding = &dsl_binding;
1946
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001947 VkDescriptorSetLayout ds_layout;
1948 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1949 ASSERT_VK_SUCCESS(err);
1950
1951 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001952 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001953 ASSERT_VK_SUCCESS(err);
1954
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001955 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1956 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1957 pipe_ms_state_ci.pNext = NULL;
1958 pipe_ms_state_ci.rasterSamples = 4;
1959 pipe_ms_state_ci.sampleShadingEnable = 0;
1960 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06001961 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001962
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001963 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1964 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1965 pipeline_layout_ci.pNext = NULL;
1966 pipeline_layout_ci.descriptorSetCount = 1;
1967 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001968
1969 VkPipelineLayout pipeline_layout;
1970 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1971 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001972
Tony Barbourd7d828b2015-08-06 10:16:07 -06001973 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001974 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1975 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06001976 VkPipelineObj pipe(m_device);
1977 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001978 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06001979 pipe.SetMSAA(&pipe_ms_state_ci);
1980 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001981
1982 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001983
1984 m_errorMonitor->ClearState();
1985 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
1986 // Also pass down other dummy params to keep driver and paramchecker happy
1987 VkClearColorValue cCV;
1988 cCV.f32[0] = 1.0;
1989 cCV.f32[1] = 1.0;
1990 cCV.f32[2] = 1.0;
1991 cCV.f32[3] = 1.0;
1992
Tony Barbour1490c912015-07-28 10:17:20 -06001993 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001994 msgFlags = m_errorMonitor->GetState(&msgString);
1995 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not receive error after issuing Clear Cmd on FB color attachment prior to Draw Cmd.";
1996 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) {
1997 FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'";
1998 }
1999}
2000
Tobin Ehlise4076782015-06-24 15:53:07 -06002001TEST_F(VkLayerTest, VtxBufferBadIndex)
2002{
2003 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
2004 VkFlags msgFlags;
2005 std::string msgString;
2006 VkResult err;
2007
2008 ASSERT_NO_FATAL_FAILURE(InitState());
2009 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2010 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002011
2012 VkDescriptorTypeCount ds_type_count = {};
2013 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2014 ds_type_count.count = 1;
2015
2016 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2017 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2018 ds_pool_ci.pNext = NULL;
2019 ds_pool_ci.count = 1;
2020 ds_pool_ci.pTypeCount = &ds_type_count;
2021
2022 VkDescriptorPool ds_pool;
Tobin Ehlise4076782015-06-24 15:53:07 -06002023 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
2024 ASSERT_VK_SUCCESS(err);
2025
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002026 VkDescriptorSetLayoutBinding dsl_binding = {};
2027 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2028 dsl_binding.arraySize = 1;
2029 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2030 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002031
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002032 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2033 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2034 ds_layout_ci.pNext = NULL;
2035 ds_layout_ci.count = 1;
2036 ds_layout_ci.pBinding = &dsl_binding;
2037
Tobin Ehlise4076782015-06-24 15:53:07 -06002038 VkDescriptorSetLayout ds_layout;
2039 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2040 ASSERT_VK_SUCCESS(err);
2041
2042 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002043 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06002044 ASSERT_VK_SUCCESS(err);
2045
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002046 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2047 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2048 pipe_ms_state_ci.pNext = NULL;
2049 pipe_ms_state_ci.rasterSamples = 1;
2050 pipe_ms_state_ci.sampleShadingEnable = 0;
2051 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002052 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002053
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002054 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2055 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2056 pipeline_layout_ci.pNext = NULL;
2057 pipeline_layout_ci.descriptorSetCount = 1;
2058 pipeline_layout_ci.pSetLayouts = &ds_layout;
2059 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06002060
Tobin Ehlise4076782015-06-24 15:53:07 -06002061 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2062 ASSERT_VK_SUCCESS(err);
2063
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002064 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002065 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2066 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002067 VkPipelineObj pipe(m_device);
2068 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002069 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002070 pipe.SetMSAA(&pipe_ms_state_ci);
2071 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002072
2073 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06002074 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlise4076782015-06-24 15:53:07 -06002075 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06002076 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlise4076782015-06-24 15:53:07 -06002077
2078 msgFlags = m_errorMonitor->GetState(&msgString);
2079 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding Vtx Buffer w/o VBO attached to PSO.";
2080 if (!strstr(msgString.c_str(),"Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.")) {
2081 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
2082 }
2083}
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002084#endif
2085#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06002086#if GTEST_IS_THREADSAFE
2087struct thread_data_struct {
2088 VkCmdBuffer cmdBuffer;
2089 VkEvent event;
2090 bool bailout;
2091};
2092
2093extern "C" void *AddToCommandBuffer(void *arg)
2094{
2095 struct thread_data_struct *data = (struct thread_data_struct *) arg;
2096 std::string msgString;
2097
2098 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06002099 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06002100 if (data->bailout) {
2101 break;
2102 }
2103 }
2104 return NULL;
2105}
2106
2107TEST_F(VkLayerTest, ThreadCmdBufferCollision)
2108{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002109 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06002110 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002111 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06002112
2113 ASSERT_NO_FATAL_FAILURE(InitState());
2114 ASSERT_NO_FATAL_FAILURE(InitViewport());
2115 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2116
Mike Stroyan09aae812015-05-12 16:00:45 -06002117 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06002118 BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002119
2120 VkEventCreateInfo event_info;
2121 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06002122 VkResult err;
2123
2124 memset(&event_info, 0, sizeof(event_info));
2125 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2126
2127 err = vkCreateEvent(device(), &event_info, &event);
2128 ASSERT_VK_SUCCESS(err);
2129
Mike Stroyan09aae812015-05-12 16:00:45 -06002130 err = vkResetEvent(device(), event);
2131 ASSERT_VK_SUCCESS(err);
2132
2133 struct thread_data_struct data;
Tony Barbour1490c912015-07-28 10:17:20 -06002134 data.cmdBuffer = m_cmdBuffer->handle();
Mike Stroyan09aae812015-05-12 16:00:45 -06002135 data.event = event;
2136 data.bailout = false;
2137 m_errorMonitor->SetBailout(&data.bailout);
2138 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002139 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06002140 // Add many entries to command buffer from this thread at the same time.
2141 AddToCommandBuffer(&data);
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002142 test_platform_thread_join(thread, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -06002143 EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002144
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002145 msgFlags = m_errorMonitor->GetState(&msgString);
Mike Stroyaned254572015-06-17 16:32:06 -06002146 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 -06002147 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05002148 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06002149 }
2150
2151}
2152#endif
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002153#endif
Chris Forbes5af3bf22015-05-25 11:13:08 +12002154#if SHADER_CHECKER_TESTS
2155TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
2156{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002157 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12002158 std::string msgString;
2159 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002160 ScopedUseGlsl useGlsl(false);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002161
2162 char const *vsSource =
2163 "#version 140\n"
2164 "#extension GL_ARB_separate_shader_objects: require\n"
2165 "#extension GL_ARB_shading_language_420pack: require\n"
2166 "\n"
2167 "layout(location=0) out float x;\n"
2168 "void main(){\n"
2169 " gl_Position = vec4(1);\n"
2170 " x = 0;\n"
2171 "}\n";
2172 char const *fsSource =
2173 "#version 140\n"
2174 "#extension GL_ARB_separate_shader_objects: require\n"
2175 "#extension GL_ARB_shading_language_420pack: require\n"
2176 "\n"
2177 "layout(location=0) out vec4 color;\n"
2178 "void main(){\n"
2179 " color = vec4(1);\n"
2180 "}\n";
2181
2182 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2183 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2184
2185 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002186 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12002187 pipe.AddShader(&vs);
2188 pipe.AddShader(&fs);
2189
Chris Forbes5af3bf22015-05-25 11:13:08 +12002190 VkDescriptorSetObj descriptorSet(m_device);
2191 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002192 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002193
2194 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002195 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12002196
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002197 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002198
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002199 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002200 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
2201 FAIL() << "Incorrect warning: " << msgString;
2202 }
2203}
Chris Forbes5af3bf22015-05-25 11:13:08 +12002204
Chris Forbes3c10b852015-05-25 11:13:13 +12002205TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
2206{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002207 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12002208 std::string msgString;
2209 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002210 ScopedUseGlsl useGlsl(false);
Chris Forbes3c10b852015-05-25 11:13:13 +12002211
2212 char const *vsSource =
2213 "#version 140\n"
2214 "#extension GL_ARB_separate_shader_objects: require\n"
2215 "#extension GL_ARB_shading_language_420pack: require\n"
2216 "\n"
2217 "void main(){\n"
2218 " gl_Position = vec4(1);\n"
2219 "}\n";
2220 char const *fsSource =
2221 "#version 140\n"
2222 "#extension GL_ARB_separate_shader_objects: require\n"
2223 "#extension GL_ARB_shading_language_420pack: require\n"
2224 "\n"
2225 "layout(location=0) in float x;\n"
2226 "layout(location=0) out vec4 color;\n"
2227 "void main(){\n"
2228 " color = vec4(x);\n"
2229 "}\n";
2230
2231 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2232 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2233
2234 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002235 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12002236 pipe.AddShader(&vs);
2237 pipe.AddShader(&fs);
2238
Chris Forbes3c10b852015-05-25 11:13:13 +12002239 VkDescriptorSetObj descriptorSet(m_device);
2240 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002241 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12002242
2243 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002244 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12002245
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002246 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12002247
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002248 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes3c10b852015-05-25 11:13:13 +12002249 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
2250 FAIL() << "Incorrect error: " << msgString;
2251 }
2252}
2253
Chris Forbescc281692015-05-25 11:13:17 +12002254TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
2255{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002256 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12002257 std::string msgString;
2258 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002259 ScopedUseGlsl useGlsl(false);
Chris Forbescc281692015-05-25 11:13:17 +12002260
2261 char const *vsSource =
2262 "#version 140\n"
2263 "#extension GL_ARB_separate_shader_objects: require\n"
2264 "#extension GL_ARB_shading_language_420pack: require\n"
2265 "\n"
2266 "layout(location=0) out int x;\n"
2267 "void main(){\n"
2268 " x = 0;\n"
2269 " gl_Position = vec4(1);\n"
2270 "}\n";
2271 char const *fsSource =
2272 "#version 140\n"
2273 "#extension GL_ARB_separate_shader_objects: require\n"
2274 "#extension GL_ARB_shading_language_420pack: require\n"
2275 "\n"
2276 "layout(location=0) in float x;\n" /* VS writes int */
2277 "layout(location=0) out vec4 color;\n"
2278 "void main(){\n"
2279 " color = vec4(x);\n"
2280 "}\n";
2281
2282 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2283 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2284
2285 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002286 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12002287 pipe.AddShader(&vs);
2288 pipe.AddShader(&fs);
2289
Chris Forbescc281692015-05-25 11:13:17 +12002290 VkDescriptorSetObj descriptorSet(m_device);
2291 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002292 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12002293
2294 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002295 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12002296
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002297 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12002298
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002299 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbescc281692015-05-25 11:13:17 +12002300 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
2301 FAIL() << "Incorrect error: " << msgString;
2302 }
2303}
2304
Chris Forbes8291c052015-05-25 11:13:28 +12002305TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
2306{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002307 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12002308 std::string msgString;
2309 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002310 ScopedUseGlsl useGlsl(false);
Chris Forbes8291c052015-05-25 11:13:28 +12002311
2312 VkVertexInputBindingDescription input_binding;
2313 memset(&input_binding, 0, sizeof(input_binding));
2314
2315 VkVertexInputAttributeDescription input_attrib;
2316 memset(&input_attrib, 0, sizeof(input_attrib));
2317 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2318
2319 char const *vsSource =
2320 "#version 140\n"
2321 "#extension GL_ARB_separate_shader_objects: require\n"
2322 "#extension GL_ARB_shading_language_420pack: require\n"
2323 "\n"
2324 "void main(){\n"
2325 " gl_Position = vec4(1);\n"
2326 "}\n";
2327 char const *fsSource =
2328 "#version 140\n"
2329 "#extension GL_ARB_separate_shader_objects: require\n"
2330 "#extension GL_ARB_shading_language_420pack: require\n"
2331 "\n"
2332 "layout(location=0) out vec4 color;\n"
2333 "void main(){\n"
2334 " color = vec4(1);\n"
2335 "}\n";
2336
2337 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2338 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2339
2340 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002341 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12002342 pipe.AddShader(&vs);
2343 pipe.AddShader(&fs);
2344
2345 pipe.AddVertexInputBindings(&input_binding, 1);
2346 pipe.AddVertexInputAttribs(&input_attrib, 1);
2347
Chris Forbes8291c052015-05-25 11:13:28 +12002348 VkDescriptorSetObj descriptorSet(m_device);
2349 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002350 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12002351
2352 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002353 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12002354
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002355 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12002356
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002357 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12002358 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
2359 FAIL() << "Incorrect warning: " << msgString;
2360 }
2361}
2362
Chris Forbes37367e62015-05-25 11:13:29 +12002363TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
2364{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002365 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12002366 std::string msgString;
2367 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002368 ScopedUseGlsl useGlsl(false);
Chris Forbes37367e62015-05-25 11:13:29 +12002369
2370 char const *vsSource =
2371 "#version 140\n"
2372 "#extension GL_ARB_separate_shader_objects: require\n"
2373 "#extension GL_ARB_shading_language_420pack: require\n"
2374 "\n"
2375 "layout(location=0) in vec4 x;\n" /* not provided */
2376 "void main(){\n"
2377 " gl_Position = x;\n"
2378 "}\n";
2379 char const *fsSource =
2380 "#version 140\n"
2381 "#extension GL_ARB_separate_shader_objects: require\n"
2382 "#extension GL_ARB_shading_language_420pack: require\n"
2383 "\n"
2384 "layout(location=0) out vec4 color;\n"
2385 "void main(){\n"
2386 " color = vec4(1);\n"
2387 "}\n";
2388
2389 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2390 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2391
2392 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002393 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12002394 pipe.AddShader(&vs);
2395 pipe.AddShader(&fs);
2396
Chris Forbes37367e62015-05-25 11:13:29 +12002397 VkDescriptorSetObj descriptorSet(m_device);
2398 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002399 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12002400
2401 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002402 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12002403
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002404 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12002405
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002406 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes37367e62015-05-25 11:13:29 +12002407 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
2408 FAIL() << "Incorrect warning: " << msgString;
2409 }
2410}
2411
Chris Forbesa4b02322015-05-25 11:13:31 +12002412TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
2413{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002414 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12002415 std::string msgString;
2416 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002417 ScopedUseGlsl useGlsl(false);
Chris Forbesa4b02322015-05-25 11:13:31 +12002418
2419 VkVertexInputBindingDescription input_binding;
2420 memset(&input_binding, 0, sizeof(input_binding));
2421
2422 VkVertexInputAttributeDescription input_attrib;
2423 memset(&input_attrib, 0, sizeof(input_attrib));
2424 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2425
2426 char const *vsSource =
2427 "#version 140\n"
2428 "#extension GL_ARB_separate_shader_objects: require\n"
2429 "#extension GL_ARB_shading_language_420pack: require\n"
2430 "\n"
2431 "layout(location=0) in int x;\n" /* attrib provided float */
2432 "void main(){\n"
2433 " gl_Position = vec4(x);\n"
2434 "}\n";
2435 char const *fsSource =
2436 "#version 140\n"
2437 "#extension GL_ARB_separate_shader_objects: require\n"
2438 "#extension GL_ARB_shading_language_420pack: require\n"
2439 "\n"
2440 "layout(location=0) out vec4 color;\n"
2441 "void main(){\n"
2442 " color = vec4(1);\n"
2443 "}\n";
2444
2445 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2446 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2447
2448 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002449 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12002450 pipe.AddShader(&vs);
2451 pipe.AddShader(&fs);
2452
2453 pipe.AddVertexInputBindings(&input_binding, 1);
2454 pipe.AddVertexInputAttribs(&input_attrib, 1);
2455
Chris Forbesa4b02322015-05-25 11:13:31 +12002456 VkDescriptorSetObj descriptorSet(m_device);
2457 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002458 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12002459
2460 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002461 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12002462
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002463 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12002464
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002465 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbesa4b02322015-05-25 11:13:31 +12002466 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
2467 FAIL() << "Incorrect error: " << msgString;
2468 }
2469}
2470
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002471TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
2472{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002473 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002474 std::string msgString;
2475 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002476 ScopedUseGlsl useGlsl(false);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002477
2478 /* Two binding descriptions for binding 0 */
2479 VkVertexInputBindingDescription input_bindings[2];
2480 memset(input_bindings, 0, sizeof(input_bindings));
2481
2482 VkVertexInputAttributeDescription input_attrib;
2483 memset(&input_attrib, 0, sizeof(input_attrib));
2484 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2485
2486 char const *vsSource =
2487 "#version 140\n"
2488 "#extension GL_ARB_separate_shader_objects: require\n"
2489 "#extension GL_ARB_shading_language_420pack: require\n"
2490 "\n"
2491 "layout(location=0) in float x;\n" /* attrib provided float */
2492 "void main(){\n"
2493 " gl_Position = vec4(x);\n"
2494 "}\n";
2495 char const *fsSource =
2496 "#version 140\n"
2497 "#extension GL_ARB_separate_shader_objects: require\n"
2498 "#extension GL_ARB_shading_language_420pack: require\n"
2499 "\n"
2500 "layout(location=0) out vec4 color;\n"
2501 "void main(){\n"
2502 " color = vec4(1);\n"
2503 "}\n";
2504
2505 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2506 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2507
2508 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002509 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002510 pipe.AddShader(&vs);
2511 pipe.AddShader(&fs);
2512
2513 pipe.AddVertexInputBindings(input_bindings, 2);
2514 pipe.AddVertexInputAttribs(&input_attrib, 1);
2515
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002516 VkDescriptorSetObj descriptorSet(m_device);
2517 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002518 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002519
2520 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002521 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002522
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002523 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002524
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002525 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002526 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
2527 FAIL() << "Incorrect error: " << msgString;
2528 }
2529}
Chris Forbes4c948702015-05-25 11:13:32 +12002530
Chris Forbesc12ef122015-05-25 11:13:40 +12002531/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
2532 * rejects it. */
2533
2534TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
2535{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002536 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12002537 std::string msgString;
2538 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002539 ScopedUseGlsl useGlsl(false);
Chris Forbesc12ef122015-05-25 11:13:40 +12002540
2541 char const *vsSource =
2542 "#version 140\n"
2543 "#extension GL_ARB_separate_shader_objects: require\n"
2544 "#extension GL_ARB_shading_language_420pack: require\n"
2545 "\n"
2546 "void main(){\n"
2547 " gl_Position = vec4(1);\n"
2548 "}\n";
2549 char const *fsSource =
2550 "#version 140\n"
2551 "#extension GL_ARB_separate_shader_objects: require\n"
2552 "#extension GL_ARB_shading_language_420pack: require\n"
2553 "\n"
2554 "void main(){\n"
2555 "}\n";
2556
2557 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2558 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2559
2560 VkPipelineObj pipe(m_device);
2561 pipe.AddShader(&vs);
2562 pipe.AddShader(&fs);
2563
Chia-I Wuc278df82015-07-07 11:50:03 +08002564 /* set up CB 0, not written */
2565 pipe.AddColorAttachment();
2566 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12002567
Chris Forbesc12ef122015-05-25 11:13:40 +12002568 VkDescriptorSetObj descriptorSet(m_device);
2569 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002570 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12002571
2572 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002573 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12002574
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002575 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12002576
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002577 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbesc12ef122015-05-25 11:13:40 +12002578 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
2579 FAIL() << "Incorrect error: " << msgString;
2580 }
2581}
2582
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002583TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
2584{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002585 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002586 std::string msgString;
2587 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002588 ScopedUseGlsl useGlsl(false);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002589
2590 char const *vsSource =
2591 "#version 140\n"
2592 "#extension GL_ARB_separate_shader_objects: require\n"
2593 "#extension GL_ARB_shading_language_420pack: require\n"
2594 "\n"
2595 "void main(){\n"
2596 " gl_Position = vec4(1);\n"
2597 "}\n";
2598 char const *fsSource =
2599 "#version 140\n"
2600 "#extension GL_ARB_separate_shader_objects: require\n"
2601 "#extension GL_ARB_shading_language_420pack: require\n"
2602 "\n"
2603 "layout(location=0) out vec4 x;\n"
2604 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
2605 "void main(){\n"
2606 " x = vec4(1);\n"
2607 " y = vec4(1);\n"
2608 "}\n";
2609
2610 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2611 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2612
2613 VkPipelineObj pipe(m_device);
2614 pipe.AddShader(&vs);
2615 pipe.AddShader(&fs);
2616
Chia-I Wuc278df82015-07-07 11:50:03 +08002617 /* set up CB 0, not written */
2618 pipe.AddColorAttachment();
2619 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002620 /* FS writes CB 1, but we don't configure it */
2621
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002622 VkDescriptorSetObj descriptorSet(m_device);
2623 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002624 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002625
2626 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002627 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002628
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002629 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002630
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002631 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002632 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
2633 FAIL() << "Incorrect warning: " << msgString;
2634 }
2635}
2636
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002637TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
2638{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002639 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002640 std::string msgString;
2641 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002642 ScopedUseGlsl useGlsl(false);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002643
2644 char const *vsSource =
2645 "#version 140\n"
2646 "#extension GL_ARB_separate_shader_objects: require\n"
2647 "#extension GL_ARB_shading_language_420pack: require\n"
2648 "\n"
2649 "void main(){\n"
2650 " gl_Position = vec4(1);\n"
2651 "}\n";
2652 char const *fsSource =
2653 "#version 140\n"
2654 "#extension GL_ARB_separate_shader_objects: require\n"
2655 "#extension GL_ARB_shading_language_420pack: require\n"
2656 "\n"
2657 "layout(location=0) out ivec4 x;\n" /* not UNORM */
2658 "void main(){\n"
2659 " x = ivec4(1);\n"
2660 "}\n";
2661
2662 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2663 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2664
2665 VkPipelineObj pipe(m_device);
2666 pipe.AddShader(&vs);
2667 pipe.AddShader(&fs);
2668
Chia-I Wuc278df82015-07-07 11:50:03 +08002669 /* set up CB 0; type is UNORM by default */
2670 pipe.AddColorAttachment();
2671 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002672
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002673 VkDescriptorSetObj descriptorSet(m_device);
2674 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002675 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002676
2677 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002678 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002679
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002680 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002681
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002682 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002683 if (!strstr(msgString.c_str(),"does not match FS output type")) {
2684 FAIL() << "Incorrect error: " << msgString;
2685 }
2686}
Chris Forbesc2050732015-06-05 14:43:36 +12002687
2688TEST_F(VkLayerTest, CreatePipelineNonSpirvShader)
2689{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002690 VkFlags msgFlags;
Chris Forbesc2050732015-06-05 14:43:36 +12002691 std::string msgString;
2692 ASSERT_NO_FATAL_FAILURE(InitState());
2693 /* Intentionally provided GLSL rather than compiling to SPIRV first */
Cody Northrop1cfbd172015-06-03 16:49:20 -06002694 ScopedUseGlsl useGlsl(true);
Chris Forbesc2050732015-06-05 14:43:36 +12002695
2696 char const *vsSource =
2697 "#version 140\n"
2698 "#extension GL_ARB_separate_shader_objects: require\n"
2699 "#extension GL_ARB_shading_language_420pack: require\n"
2700 "\n"
2701 "void main(){\n"
2702 " gl_Position = vec4(1);\n"
2703 "}\n";
2704 char const *fsSource =
2705 "#version 140\n"
2706 "#extension GL_ARB_separate_shader_objects: require\n"
2707 "#extension GL_ARB_shading_language_420pack: require\n"
2708 "\n"
2709 "layout(location=0) out vec4 x;\n"
2710 "void main(){\n"
2711 " x = vec4(1);\n"
2712 "}\n";
2713
2714 m_errorMonitor->ClearState();
2715
2716 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2717 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2718
2719
2720 VkPipelineObj pipe(m_device);
2721 pipe.AddShader(&vs);
2722 pipe.AddShader(&fs);
2723
Chia-I Wuc278df82015-07-07 11:50:03 +08002724 /* set up CB 0; type is UNORM by default */
2725 pipe.AddColorAttachment();
2726 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc2050732015-06-05 14:43:36 +12002727
Chris Forbesc2050732015-06-05 14:43:36 +12002728 VkDescriptorSetObj descriptorSet(m_device);
2729 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002730 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc2050732015-06-05 14:43:36 +12002731
Tony Barboured132432015-08-04 16:23:11 -06002732 VkResult res = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc2050732015-06-05 14:43:36 +12002733 /* pipeline creation should have succeeded */
2734 ASSERT_EQ(VK_SUCCESS, res);
2735
2736 /* should have emitted a warning: the shader is not SPIRV, so we're
2737 * not going to be able to analyze it */
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002738 msgFlags = m_errorMonitor->GetState(&msgString);
2739 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesc2050732015-06-05 14:43:36 +12002740 if (!strstr(msgString.c_str(),"is not SPIR-V")) {
2741 FAIL() << "Incorrect warning: " << msgString;
2742 }
2743}
Chris Forbes01c9db72015-06-04 09:25:25 +12002744#endif
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002745
Tony Barbour30486ea2015-04-07 13:44:53 -06002746int main(int argc, char **argv) {
2747 int result;
2748
2749 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06002750 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06002751
2752 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
2753
2754 result = RUN_ALL_TESTS();
2755
Tony Barbour01999182015-04-09 12:58:51 -06002756 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06002757 return result;
2758}