blob: 6ece510a6fa9515b3de6c34ecf05f474a4d0c061 [file] [log] [blame]
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001#include <vulkan.h>
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002#include "vk_debug_report_lunarg.h"
Tony Barbour300a6082015-04-07 13:44:53 -06003#include "gtest-1.7.0/include/gtest/gtest.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004#include "vkrenderframework.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -06005#include "vk_layer_config.h"
Tony Barbour300a6082015-04-07 13:44:53 -06006
Mark Lobodzinski3780e142015-05-14 15:08:13 -05007#define GLM_FORCE_RADIANS
8#include "glm/glm.hpp"
9#include <glm/gtc/matrix_transform.hpp>
10
Tobin Ehlis0788f522015-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 Forbes9f7ff632015-05-25 11:13:08 +120015#define SHADER_CHECKER_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060016
Mark Lobodzinski3780e142015-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 Lobodzinski75a97e62015-06-02 09:41:30 -050043static const char bindStateVertShaderText[] =
Mark Lobodzinski3780e142015-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 Lobodzinski75a97e62015-06-02 09:41:30 -050053static const char bindStateFragShaderText[] =
Cody Northrop8a3bb132015-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 Lobodzinski3780e142015-05-14 15:08:13 -050062
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060063static void myDbgFunc(
Tony Barbour67e99152015-07-10 14:10:27 -060064 VkFlags msgFlags,
65 VkDbgObjectType objType,
66 uint64_t srcObject,
Courtney Goeltzenleuchterf579fa62015-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 Barbour300a6082015-04-07 13:44:53 -060072
73class ErrorMonitor {
74public:
Tony Barbour15524c32015-04-29 17:34:29 -060075 ErrorMonitor()
Tony Barbour300a6082015-04-07 13:44:53 -060076 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060077 test_platform_thread_create_mutex(&m_mutex);
78 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060079 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mike Stroyanaccf7692015-05-12 16:00:45 -060080 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -060081 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -060082 }
83 void ClearState()
84 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060085 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060086 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -060087 m_msgString.clear();
Mike Stroyan4268d1f2015-07-13 14:45:35 -060088 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -060089 }
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060090 VkFlags GetState(std::string *msgString)
Tony Barbour300a6082015-04-07 13:44:53 -060091 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060092 test_platform_thread_lock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -060093 *msgString = m_msgString;
Mike Stroyan4268d1f2015-07-13 14:45:35 -060094 test_platform_thread_unlock_mutex(&m_mutex);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060095 return m_msgFlags;
Tony Barbour300a6082015-04-07 13:44:53 -060096 }
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060097 void SetState(VkFlags msgFlags, const char *msgString)
Tony Barbour300a6082015-04-07 13:44:53 -060098 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060099 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600100 if (m_bailout != NULL) {
101 *m_bailout = true;
102 }
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600103 m_msgFlags = msgFlags;
Tony Barbour0b4d9562015-04-09 10:48:04 -0600104 m_msgString.reserve(strlen(msgString));
105 m_msgString = msgString;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600106 test_platform_thread_unlock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600107 }
108 void SetBailout(bool *bailout)
109 {
110 m_bailout = bailout;
Tony Barbour300a6082015-04-07 13:44:53 -0600111 }
112
113private:
Mike Stroyan4268d1f2015-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 Barbour300a6082015-04-07 13:44:53 -0600118};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500119
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600120static void myDbgFunc(
121 VkFlags msgFlags,
Tony Barbour67e99152015-07-10 14:10:27 -0600122 VkDbgObjectType objType,
123 uint64_t srcObject,
Courtney Goeltzenleuchterf579fa62015-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 Barbour300a6082015-04-07 13:44:53 -0600129{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600130 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600131 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600132 errMonitor->SetState(msgFlags, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600133 }
Tony Barbour300a6082015-04-07 13:44:53 -0600134}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500135
Tony Barbour6918cd52015-04-09 12:58:51 -0600136class VkLayerTest : public VkRenderFramework
Tony Barbour300a6082015-04-07 13:44:53 -0600137{
138public:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600139 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
140 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Mark Lobodzinski3780e142015-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 Barbourfe3351b2015-07-28 10:17:20 -0600143 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
144 { GenericDrawPreparation(m_cmdBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour300a6082015-04-07 13:44:53 -0600145
Tony Barbourfe3351b2015-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 Barbour300a6082015-04-07 13:44:53 -0600159protected:
Tony Barbour6918cd52015-04-09 12:58:51 -0600160 ErrorMonitor *m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600161
162 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600163 std::vector<const char *> instance_layer_names;
164 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600165 std::vector<const char *> instance_extension_names;
166 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600167
Courtney Goeltzenleuchter05159a92015-07-30 11:32:46 -0600168 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-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 Stroyan0daf78a2015-06-17 16:32:06 -0600174 // Use Threading layer first to protect others from ThreadCmdBufferCollision test
Courtney Goeltzenleuchtercd69eee2015-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 Goeltzenleuchterd971b612015-06-17 20:51:59 -0600180
Courtney Goeltzenleuchtercd69eee2015-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 Barbour300a6082015-04-07 13:44:53 -0600186
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600187 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600193 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour300a6082015-04-07 13:44:53 -0600194
Tony Barbour15524c32015-04-29 17:34:29 -0600195 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-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 Barbour300a6082015-04-07 13:44:53 -0600199 }
200
201 virtual void TearDown() {
202 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600203 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600204 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600205 }
206};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500207
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600208VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour300a6082015-04-07 13:44:53 -0600209{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600210 VkResult result;
Tony Barbour300a6082015-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 Forbes76a5eeb2015-06-16 14:05:59 +1200218 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu08accc62015-07-07 11:50:03 +0800219 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600220 }
221
222 return result;
223}
224
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600225VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour300a6082015-04-07 13:44:53 -0600226{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600227 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600228
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200229 if (renderPass()) {
Chia-I Wu0b50a1c2015-06-26 15:34:39 +0800230 cmdBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200231 }
Tony Barbour300a6082015-04-07 13:44:53 -0600232
233 result = cmdBuffer.EndCommandBuffer();
234
235 return result;
236}
237
Mark Lobodzinski3780e142015-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 Wu08accc62015-07-07 11:50:03 +0800280 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-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 Barbourfe3351b2015-07-28 10:17:20 -0600288 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500289
Tony Barbourfe3351b2015-07-28 10:17:20 -0600290 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500291
292 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -0600293 Draw(0, 3, 0, 1);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500294
295 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600296 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500297
Tony Barbourfe3351b2015-07-28 10:17:20 -0600298 QueueCommandBuffer();
Mark Lobodzinski3780e142015-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 Barbour67e99152015-07-10 14:10:27 -0600311 cmdBuffer->BindDynamicRasterState(m_stateRaster);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500312 }
313 if ((failMask & BsoFailViewport) != BsoFailViewport) {
Tony Barbour67e99152015-07-10 14:10:27 -0600314 cmdBuffer->BindDynamicViewportState(m_stateViewport);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500315 }
316 if ((failMask & BsoFailColorBlend) != BsoFailColorBlend) {
Tony Barbour67e99152015-07-10 14:10:27 -0600317 cmdBuffer->BindDynamicColorBlendState(m_colorBlend);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500318 }
319 if ((failMask & BsoFailDepthStencil) != BsoFailDepthStencil) {
Tony Barbour67e99152015-07-10 14:10:27 -0600320 cmdBuffer->BindDynamicDepthStencilState(m_stateDepthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500321 }
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600322 // Make sure depthWriteEnable is set so that DepthStencil fail test will work correctly
Tony Barboureb254902015-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 Ehlis4bf96d12015-06-25 11:58:41 -0600340 pipelineobj.SetDepthStencil(&ds_ci);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500341 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Tony Barbour5781e8f2015-08-04 16:23:11 -0600342 pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500343 cmdBuffer->BindPipeline(pipelineobj);
344 cmdBuffer->BindDescriptorSet(descriptorSet);
345}
346
347// ********************************************************************************************************************
348// ********************************************************************************************************************
349// ********************************************************************************************************************
350// ********************************************************************************************************************
Tobin Ehlis0788f522015-05-26 16:11:58 -0600351#if MEM_TRACKER_TESTS
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500352TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
353{
354 vk_testing::Fence testFence;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600355 VkFlags msgFlags;
Mark Lobodzinskiccb2b042015-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 Barbourc1eb1a52015-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 Lobodzinskiccb2b042015-05-19 10:28:29 -0500368
Tony Barbourfe3351b2015-07-28 10:17:20 -0600369 BeginCommandBuffer();
370 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
371 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-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 Barbourfe3351b2015-07-28 10:17:20 -0600377 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinskiccb2b042015-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 Barbourfe3351b2015-07-28 10:17:20 -0600382 vkResetCommandBuffer(m_cmdBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500383
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600384 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600385 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling ResetCommandBuffer on an active Command Buffer";
Mark Lobodzinskiccb2b042015-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 Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600394 VkFlags msgFlags;
Mark Lobodzinskiccb2b042015-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 Barbourfe3351b2015-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 Lobodzinskiccb2b042015-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 Barbourfe3351b2015-07-28 10:17:20 -0600414 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinskiccb2b042015-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 Barbourfe3351b2015-07-28 10:17:20 -0600419 BeginCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500420
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600421 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600422 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling BeginCommandBuffer on an active Command Buffer";
Mark Lobodzinskiccb2b042015-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 Lobodzinski3780e142015-05-14 15:08:13 -0500428TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
429{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600430 VkFlags msgFlags;
Mark Lobodzinski3780e142015-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 Lobodzinski23065352015-05-29 09:32:35 -0500439 VkDeviceMemory mem;
440 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-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 Lobodzinski3780e142015-05-14 15:08:13 -0500445
Tony Barboureb254902015-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 Lobodzinski3780e142015-05-14 15:08:13 -0500465 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -0600466 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500467
468 err = vkCreateImage(m_device->device(), &image_create_info, &image);
469 ASSERT_VK_SUCCESS(err);
470
Tony Barbour67e99152015-07-10 14:10:27 -0600471 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500472 image,
Mark Lobodzinski23065352015-05-29 09:32:35 -0500473 &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500474 ASSERT_VK_SUCCESS(err);
475
Mark Lobodzinski23065352015-05-29 09:32:35 -0500476 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500477
Mike Stroyan713b2d72015-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 Barbour02fdc7d2015-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 Stroyan713b2d72015-08-04 10:49:29 -0600481
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500482 // allocate memory
Mark Lobodzinski23065352015-05-29 09:32:35 -0500483 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500484 ASSERT_VK_SUCCESS(err);
485
486 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -0600487 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-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 Lobodzinski23065352015-05-29 09:32:35 -0500492 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500493
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600494 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600495 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to map memory not visible to CPU";
Mark Lobodzinski3780e142015-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 Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600503 VkFlags msgFlags;
Mark Lobodzinski3780e142015-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 Lobodzinski23065352015-05-29 09:32:35 -0500512 VkDeviceMemory mem;
513 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-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 Lobodzinski3780e142015-05-14 15:08:13 -0500518
Tony Barboureb254902015-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 Lobodzinski3780e142015-05-14 15:08:13 -0500539
540 err = vkCreateImage(m_device->device(), &image_create_info, &image);
541 ASSERT_VK_SUCCESS(err);
542
Tony Barbour67e99152015-07-10 14:10:27 -0600543 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500544 image,
Mark Lobodzinski23065352015-05-29 09:32:35 -0500545 &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500546 ASSERT_VK_SUCCESS(err);
547
Mark Lobodzinski23065352015-05-29 09:32:35 -0500548 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500549
Chia-I Wu999f0482015-07-03 10:32:05 +0800550 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600551 ASSERT_VK_SUCCESS(err);
552
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500553 // allocate memory
Mark Lobodzinski23065352015-05-29 09:32:35 -0500554 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500555 ASSERT_VK_SUCCESS(err);
556
557 // Introduce validation failure, free memory before binding
Mark Lobodzinski23065352015-05-29 09:32:35 -0500558 vkFreeMemory(m_device->device(), mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500559 ASSERT_VK_SUCCESS(err);
560
561 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -0600562 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Cody Northropb2f1d132015-08-06 12:40:01 -0600563 // This may very well return an error.
564 (void)err;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500565
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600566 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600567 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to bind a freed memory object";
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500568 if (!strstr(msgString.c_str(),"couldn't find info for mem obj")) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500569 FAIL() << "Error received did not match expected error message from BindObjectMemory in MemTracker";
570 }
571}
572
Tobin Ehlis2717d132015-07-10 18:25:07 -0600573// TODO : Is this test still valid. Not sure it is with updates to memory binding model
574// Verify and delete the test of fix the check
575//TEST_F(VkLayerTest, FreeBoundMemory)
576//{
577// VkFlags msgFlags;
578// std::string msgString;
579// VkResult err;
580//
581// ASSERT_NO_FATAL_FAILURE(InitState());
582// m_errorMonitor->ClearState();
583//
584// // Create an image, allocate memory, free it, and then try to bind it
585// VkImage image;
586// VkDeviceMemory mem;
587// VkMemoryRequirements mem_reqs;
588//
589// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
590// const int32_t tex_width = 32;
591// const int32_t tex_height = 32;
592//
593// const VkImageCreateInfo image_create_info = {
594// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
595// .pNext = NULL,
596// .imageType = VK_IMAGE_TYPE_2D,
597// .format = tex_format,
598// .extent = { tex_width, tex_height, 1 },
599// .mipLevels = 1,
600// .arraySize = 1,
601// .samples = 1,
602// .tiling = VK_IMAGE_TILING_LINEAR,
603// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
604// .flags = 0,
605// };
606// VkMemoryAllocInfo mem_alloc = {
607// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
608// .pNext = NULL,
609// .allocationSize = 0,
610// .memoryTypeIndex = 0,
611// };
612//
613// err = vkCreateImage(m_device->device(), &image_create_info, &image);
614// ASSERT_VK_SUCCESS(err);
615//
616// err = vkGetImageMemoryRequirements(m_device->device(),
617// image,
618// &mem_reqs);
619// ASSERT_VK_SUCCESS(err);
620//
621// mem_alloc.allocationSize = mem_reqs.size;
622//
623// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
624// ASSERT_VK_SUCCESS(err);
625//
626// // allocate memory
627// err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
628// ASSERT_VK_SUCCESS(err);
629//
630// // Bind memory to Image object
631// err = vkBindImageMemory(m_device->device(), image, mem, 0);
632// ASSERT_VK_SUCCESS(err);
633//
634// // Introduce validation failure, free memory while still bound to object
635// vkFreeMemory(m_device->device(), mem);
636// ASSERT_VK_SUCCESS(err);
637//
638// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600639// ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an warning while tring to free bound memory";
Tobin Ehlis2717d132015-07-10 18:25:07 -0600640// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
641// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
642// }
643//}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500644
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500645TEST_F(VkLayerTest, RebindMemory)
646{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600647 VkFlags msgFlags;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500648 std::string msgString;
649 VkResult err;
650
651 ASSERT_NO_FATAL_FAILURE(InitState());
652 m_errorMonitor->ClearState();
653
654 // Create an image, allocate memory, free it, and then try to bind it
655 VkImage image;
656 VkDeviceMemory mem1;
657 VkDeviceMemory mem2;
658 VkMemoryRequirements mem_reqs;
659
660 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
661 const int32_t tex_width = 32;
662 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500663
Tony Barboureb254902015-07-15 12:50:33 -0600664 VkImageCreateInfo image_create_info = {};
665 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
666 image_create_info.pNext = NULL;
667 image_create_info.imageType = VK_IMAGE_TYPE_2D;
668 image_create_info.format = tex_format;
669 image_create_info.extent.width = tex_width;
670 image_create_info.extent.height = tex_height;
671 image_create_info.extent.depth = 1;
672 image_create_info.mipLevels = 1;
673 image_create_info.arraySize = 1;
674 image_create_info.samples = 1;
675 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
676 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
677 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500678
Tony Barboureb254902015-07-15 12:50:33 -0600679 VkMemoryAllocInfo mem_alloc = {};
680 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
681 mem_alloc.pNext = NULL;
682 mem_alloc.allocationSize = 0;
683 mem_alloc.memoryTypeIndex = 0;
684
685 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
686 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500687 err = vkCreateImage(m_device->device(), &image_create_info, &image);
688 ASSERT_VK_SUCCESS(err);
689
Tony Barbour67e99152015-07-10 14:10:27 -0600690 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500691 image,
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500692 &mem_reqs);
693 ASSERT_VK_SUCCESS(err);
694
695 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wu999f0482015-07-03 10:32:05 +0800696 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600697 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500698
699 // allocate 2 memory objects
700 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
701 ASSERT_VK_SUCCESS(err);
702 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
703 ASSERT_VK_SUCCESS(err);
704
705 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -0600706 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500707 ASSERT_VK_SUCCESS(err);
708
709 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barbour67e99152015-07-10 14:10:27 -0600710 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500711 ASSERT_VK_SUCCESS(err);
712
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600713 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600714 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to rebind an object";
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500715 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
716 FAIL() << "Error received did not match expected message when rebinding memory to an object";
717 }
718}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500719
720TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
721{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600722 VkFlags msgFlags;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500723 std::string msgString;
724 VkResult err;
725
726 ASSERT_NO_FATAL_FAILURE(InitState());
727 m_errorMonitor->ClearState();
728
729 // Create an image object, allocate memory, destroy the object and then try to bind it
730 VkImage image;
Mark Lobodzinski23065352015-05-29 09:32:35 -0500731 VkDeviceMemory mem;
732 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500733
734 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
735 const int32_t tex_width = 32;
736 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500737
Tony Barboureb254902015-07-15 12:50:33 -0600738 VkImageCreateInfo image_create_info = {};
739 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
740 image_create_info.pNext = NULL;
741 image_create_info.imageType = VK_IMAGE_TYPE_2D;
742 image_create_info.format = tex_format;
743 image_create_info.extent.width = tex_width;
744 image_create_info.extent.height = tex_height;
745 image_create_info.extent.depth = 1;
746 image_create_info.mipLevels = 1;
747 image_create_info.arraySize = 1;
748 image_create_info.samples = 1;
749 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
750 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
751 image_create_info.flags = 0;
752
753 VkMemoryAllocInfo mem_alloc = {};
754 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
755 mem_alloc.pNext = NULL;
756 mem_alloc.allocationSize = 0;
757 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500758
759 err = vkCreateImage(m_device->device(), &image_create_info, &image);
760 ASSERT_VK_SUCCESS(err);
761
Tony Barbour67e99152015-07-10 14:10:27 -0600762 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500763 image,
Mark Lobodzinski23065352015-05-29 09:32:35 -0500764 &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500765 ASSERT_VK_SUCCESS(err);
766
Mark Lobodzinski23065352015-05-29 09:32:35 -0500767 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wu999f0482015-07-03 10:32:05 +0800768 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600769 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500770
771 // Allocate memory
Mark Lobodzinski23065352015-05-29 09:32:35 -0500772 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500773 ASSERT_VK_SUCCESS(err);
774
775 // Introduce validation failure, destroy Image object before binding
Tony Barbour67e99152015-07-10 14:10:27 -0600776 vkDestroyImage(m_device->device(), image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500777 ASSERT_VK_SUCCESS(err);
778
Mike Stroyan713b2d72015-08-04 10:49:29 -0600779 // Now Try to bind memory to this destroyed object
Tony Barbour67e99152015-07-10 14:10:27 -0600780 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mike Stroyan713b2d72015-08-04 10:49:29 -0600781 // This may very well return an error.
782 (void) err;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500783
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600784 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600785 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while binding memory to a destroyed object";
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500786 if (!strstr(msgString.c_str(),"that's not in global list")) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500787 FAIL() << "Error received did not match expected error message from updateObjectBinding in MemTracker";
788 }
789}
790
Tony Barbour0b4d9562015-04-09 10:48:04 -0600791TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour300a6082015-04-07 13:44:53 -0600792{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600793 vk_testing::Fence testFence;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600794 VkFlags msgFlags;
Tony Barbour300a6082015-04-07 13:44:53 -0600795 std::string msgString;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600796
797 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600798 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
799 fenceInfo.pNext = NULL;
800 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -0600801
Tony Barbour300a6082015-04-07 13:44:53 -0600802 ASSERT_NO_FATAL_FAILURE(InitState());
803 ASSERT_NO_FATAL_FAILURE(InitViewport());
804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
805
Tony Barbourfe3351b2015-07-28 10:17:20 -0600806 BeginCommandBuffer();
807 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
808 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600809
810 testFence.init(*m_device, fenceInfo);
811 m_errorMonitor->ClearState();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600812 QueueCommandBuffer(testFence.handle());
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600813 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600814 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err from using a fence in SIGNALED state in call to vkQueueSubmit";
Tony Barbour0b4d9562015-04-09 10:48:04 -0600815 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500816 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour0b4d9562015-04-09 10:48:04 -0600817 }
818
819}
820
821TEST_F(VkLayerTest, ResetUnsignaledFence)
822{
823 vk_testing::Fence testFence;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600824 VkFlags msgFlags;
Tony Barbour0b4d9562015-04-09 10:48:04 -0600825 std::string msgString;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600826 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600827 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
828 fenceInfo.pNext = NULL;
829
Tony Barbour0b4d9562015-04-09 10:48:04 -0600830 ASSERT_NO_FATAL_FAILURE(InitState());
831 testFence.init(*m_device, fenceInfo);
832 m_errorMonitor->ClearState();
Chia-I Wud9e8e822015-07-03 11:45:55 +0800833 VkFence fences[1] = {testFence.handle()};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600834 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600835 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600836 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from submitting fence with UNSIGNALED state to vkResetFences";
Tony Barbour6918cd52015-04-09 12:58:51 -0600837 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500838 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour0b4d9562015-04-09 10:48:04 -0600839 }
Tony Barbour300a6082015-04-07 13:44:53 -0600840
841}
Tobin Ehlis41376e12015-07-03 08:45:14 -0600842
Chia-I Wu08accc62015-07-07 11:50:03 +0800843/* TODO: Update for changes due to bug-14075 tiling across render passes */
844#if 0
Tobin Ehlis41376e12015-07-03 08:45:14 -0600845TEST_F(VkLayerTest, InvalidUsageBits)
846{
847 // Initiate Draw w/o a PSO bound
848 VkFlags msgFlags;
849 std::string msgString;
850
851 ASSERT_NO_FATAL_FAILURE(InitState());
852 m_errorMonitor->ClearState();
853 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600854 BeginCommandBuffer();
Tobin Ehlis41376e12015-07-03 08:45:14 -0600855
856 const VkExtent3D e3d = {
857 .width = 128,
858 .height = 128,
859 .depth = 1,
860 };
861 const VkImageCreateInfo ici = {
862 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
863 .pNext = NULL,
864 .imageType = VK_IMAGE_TYPE_2D,
865 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
866 .extent = e3d,
867 .mipLevels = 1,
868 .arraySize = 1,
869 .samples = 1,
870 .tiling = VK_IMAGE_TILING_LINEAR,
871 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_BIT
872 .flags = 0,
873 };
874
875 VkImage dsi;
876 vkCreateImage(m_device->device(), &ici, &dsi);
877 VkDepthStencilView dsv;
878 const VkDepthStencilViewCreateInfo dsvci = {
879 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
880 .pNext = NULL,
881 .image = dsi,
882 .mipLevel = 0,
883 .baseArraySlice = 0,
884 .arraySize = 1,
885 .flags = 0,
886 };
887 vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv);
888 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600889 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after attempting to create DSView w/ image lacking USAGE_DS_BIT flag";
Tobin Ehlis41376e12015-07-03 08:45:14 -0600890 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
891 FAIL() << "Error received was not 'Invalid usage flag for image...'";
892 }
893}
Tobin Ehlis0788f522015-05-26 16:11:58 -0600894#endif
Chia-I Wu08accc62015-07-07 11:50:03 +0800895#endif
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600896#if OBJ_TRACKER_TESTS
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500897TEST_F(VkLayerTest, RasterStateNotBound)
898{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600899 VkFlags msgFlags;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500900 std::string msgString;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -0600901 ASSERT_NO_FATAL_FAILURE(InitState());
902 m_errorMonitor->ClearState();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500903 TEST_DESCRIPTION("Simple Draw Call that validates failure when a raster state object is not bound beforehand");
904
905 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailRaster);
906
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600907 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600908 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Raster State Object";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500909 if (!strstr(msgString.c_str(),"Raster object not bound to this command buffer")) {
910 FAIL() << "Error received was not 'Raster object not bound to this command buffer'";
911 }
912}
913
914TEST_F(VkLayerTest, ViewportStateNotBound)
915{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600916 VkFlags msgFlags;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500917 std::string msgString;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -0600918 ASSERT_NO_FATAL_FAILURE(InitState());
919 m_errorMonitor->ClearState();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500920 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
921
922 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
923
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600924 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600925 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500926 if (!strstr(msgString.c_str(),"Viewport object not bound to this command buffer")) {
927 FAIL() << "Error received was not 'Viewport object not bound to this command buffer'";
928 }
929}
930
931TEST_F(VkLayerTest, ColorBlendStateNotBound)
932{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600933 VkFlags msgFlags;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500934 std::string msgString;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -0600935 ASSERT_NO_FATAL_FAILURE(InitState());
936 m_errorMonitor->ClearState();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500937 TEST_DESCRIPTION("Simple Draw Call that validates failure when a color-blend state object is not bound beforehand");
938
939 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailColorBlend);
940
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600941 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600942 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a ColorBlend State Object";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500943 if (!strstr(msgString.c_str(),"Color-blend object not bound to this command buffer")) {
944 FAIL() << "Error received was not 'Color-blend object not bound to this command buffer'";
945 }
946}
947
948TEST_F(VkLayerTest, DepthStencilStateNotBound)
949{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600950 VkFlags msgFlags;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500951 std::string msgString;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -0600952 ASSERT_NO_FATAL_FAILURE(InitState());
953 m_errorMonitor->ClearState();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500954 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth-stencil state object is not bound beforehand");
955
956 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthStencil);
957
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600958 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600959 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a DepthStencil State Object";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500960 if (!strstr(msgString.c_str(),"Depth-stencil object not bound to this command buffer")) {
961 FAIL() << "Error received was not 'Depth-stencil object not bound to this command buffer'";
962 }
Tony Barbourd866ad02015-05-06 09:35:56 -0600963}
Tobin Ehlis0788f522015-05-26 16:11:58 -0600964#endif
965#if DRAW_STATE_TESTS
Tobin Ehlis59278bf2015-08-18 07:10:58 -0600966TEST_F(VkLayerTest, CmdBufferTwoSubmits)
967{
968 vk_testing::Fence testFence;
969 VkFlags msgFlags;
970 std::string msgString;
971
972 VkFenceCreateInfo fenceInfo = {};
973 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
974 fenceInfo.pNext = NULL;
975 fenceInfo.flags = 0;
976
977 ASSERT_NO_FATAL_FAILURE(InitState());
978 ASSERT_NO_FATAL_FAILURE(InitViewport());
979 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
980
981 // We luck out b/c by default the framework creates CB w/ the VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set
982 BeginCommandBuffer();
983 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
984 EndCommandBuffer();
985
986 testFence.init(*m_device, fenceInfo);
987
988 // Bypass framework since it does the waits automatically
989 VkResult err = VK_SUCCESS;
990 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
991 ASSERT_VK_SUCCESS( err );
992
993 m_errorMonitor->ClearState();
994 // Cause validation error by re-submitting cmd buffer that should only be submitted once
995 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
996 ASSERT_VK_SUCCESS( err );
997
998 msgFlags = m_errorMonitor->GetState(&msgString);
999 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after re-submitting Command Buffer that was created with one-time submit flag";
Tobin Ehlisf1878c72015-08-18 14:24:32 -06001000 if (!strstr(msgString.c_str(),"was begun w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set, but has been submitted")) {
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001001 FAIL() << "Error received was not 'CB (0xaddress) was created w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set...'";
1002 }
1003}
1004
1005
Tobin Ehlis502480b2015-06-24 15:53:07 -06001006TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001007{
1008 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001009 VkFlags msgFlags;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001010 std::string msgString;
1011
1012 ASSERT_NO_FATAL_FAILURE(InitState());
1013 m_errorMonitor->ClearState();
Tony Barbourfe3351b2015-07-28 10:17:20 -06001014 BeginCommandBuffer();
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001015 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Tony Barbourfe3351b2015-07-28 10:17:20 -06001016 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001017 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001018 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding pipeline to CmdBuffer w/o active RenderPass";
Tobin Ehlis502480b2015-06-24 15:53:07 -06001019 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
1020 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0xbaadb1be) without an active RenderPass'";
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001021 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001022}
1023
1024TEST_F(VkLayerTest, InvalidDescriptorPool)
1025{
1026 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1027 // The DS check for this is after driver has been called to validate DS internal data struct
1028 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001029/* VkFlags msgFlags;
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001030 std::string msgString;
1031 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1032 vkResetDescriptorPool(device(), badPool);
1033
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001034 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001035 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Resetting an invalid DescriptorPool Object";
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001036 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1037 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1038 }*/
1039}
1040
1041TEST_F(VkLayerTest, InvalidDescriptorSet)
1042{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001043 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1044 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001045 // Create a valid cmd buffer
1046 // call vkCmdBindDescriptorSets w/ false DS
1047}
1048
1049TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1050{
1051 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1052 // The DS check for this is after driver has been called to validate DS internal data struct
1053}
1054
1055TEST_F(VkLayerTest, InvalidPipeline)
1056{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001057 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1058 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001059 // Create a valid cmd buffer
1060 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlis502480b2015-06-24 15:53:07 -06001061// VkFlags msgFlags;
1062// std::string msgString;
1063//
1064// ASSERT_NO_FATAL_FAILURE(InitState());
1065// m_errorMonitor->ClearState();
1066// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001067// BeginCommandBuffer();
Tobin Ehlis502480b2015-06-24 15:53:07 -06001068// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1069// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1070// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001071// ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Tobin Ehlis502480b2015-06-24 15:53:07 -06001072// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1073// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1074// }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001075}
1076
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001077TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001078{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001079 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001080 VkFlags msgFlags;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001081 std::string msgString;
1082 VkResult err;
1083
1084 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06001085 ASSERT_NO_FATAL_FAILURE(InitViewport());
1086 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001087 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06001088 VkDescriptorTypeCount ds_type_count = {};
1089 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1090 ds_type_count.count = 1;
1091
1092 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1093 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1094 ds_pool_ci.pNext = NULL;
1095 ds_pool_ci.count = 1;
1096 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06001097
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001098 VkDescriptorPool ds_pool;
1099 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1100 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001101
Tony Barboureb254902015-07-15 12:50:33 -06001102 VkDescriptorSetLayoutBinding dsl_binding = {};
1103 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1104 dsl_binding.arraySize = 1;
1105 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1106 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001107
Tony Barboureb254902015-07-15 12:50:33 -06001108 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1109 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1110 ds_layout_ci.pNext = NULL;
1111 ds_layout_ci.count = 1;
1112 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001113 VkDescriptorSetLayout ds_layout;
1114 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1115 ASSERT_VK_SUCCESS(err);
1116
1117 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06001118 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001119 ASSERT_VK_SUCCESS(err);
1120
Tony Barboureb254902015-07-15 12:50:33 -06001121 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1122 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1123 pipeline_layout_ci.pNext = NULL;
1124 pipeline_layout_ci.descriptorSetCount = 1;
1125 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001126
1127 VkPipelineLayout pipeline_layout;
1128 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1129 ASSERT_VK_SUCCESS(err);
1130
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001131 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour1c94d372015-08-06 11:21:08 -06001132 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1133 // but add it to be able to run on more devices
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001134
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001135 VkPipelineObj pipe(m_device);
1136 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06001137 pipe.AddShader(&fs);
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001138 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001139
1140 BeginCommandBuffer();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001141 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001142 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001143
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001144 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001145 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not warn after binding a DescriptorSet that was never updated.";
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001146 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1147 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1148 }
1149}
1150
1151TEST_F(VkLayerTest, NoBeginCmdBuffer)
1152{
1153 VkFlags msgFlags;
1154 std::string msgString;
1155
1156 ASSERT_NO_FATAL_FAILURE(InitState());
1157 m_errorMonitor->ClearState();
Tony Barbourfe3351b2015-07-28 10:17:20 -06001158 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001159 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1160 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1161 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001162 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after ending a CmdBuffer w/o calling BeginCommandBuffer()";
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001163 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1164 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1165 }
1166}
1167
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001168TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1169{
1170 VkFlags msgFlags;
1171 std::string msgString;
1172
1173 ASSERT_NO_FATAL_FAILURE(InitState());
1174 m_errorMonitor->ClearState();
1175
1176 // Calls CreateCommandBuffer
1177 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1178
1179 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northropb4569702015-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;
1185 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1186 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1187
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001188
1189 // The error should be caught by validation of the BeginCommandBuffer call
1190 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1191
1192 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001193 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error passing a non-NULL Framebuffer and Renderpass to BeginCommandBuffer()";
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001194 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1195 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1196 }
1197}
1198
1199TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1200{
1201 VkFlags msgFlags;
1202 std::string msgString;
1203 VkResult err;
1204 VkCmdBuffer draw_cmd;
1205 VkCmdPool cmd_pool;
1206
1207 ASSERT_NO_FATAL_FAILURE(InitState());
1208 m_errorMonitor->ClearState();
1209
Cody Northropb4569702015-08-04 17:35:57 -06001210 VkCmdBufferCreateInfo cmd = {};
1211 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1212 cmd.pNext = NULL;
1213 cmd.cmdPool = m_cmdPool;
1214 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1215 cmd.flags = 0;
1216
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001217 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
1218 assert(!err);
1219
1220 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northropb4569702015-08-04 17:35:57 -06001221 VkCmdBufferBeginInfo cmd_buf_info = {};
1222 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1223 cmd_buf_info.pNext = NULL;
1224 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1225 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001226
1227 // The error should be caught by validation of the BeginCommandBuffer call
1228 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1229
1230 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001231 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error passing NULL Framebuffer/Renderpass to BeginCommandBuffer()";
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001232 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1233 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1234 }
1235}
1236
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001237TEST_F(VkLayerTest, InvalidPipelineCreateState)
1238{
1239 // Attempt to Create Gfx Pipeline w/o a VS
1240 VkFlags msgFlags;
1241 std::string msgString;
1242 VkResult err;
1243
1244 ASSERT_NO_FATAL_FAILURE(InitState());
1245 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06001246
1247 VkDescriptorTypeCount ds_type_count = {};
1248 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1249 ds_type_count.count = 1;
1250
1251 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1252 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1253 ds_pool_ci.pNext = NULL;
1254 ds_pool_ci.count = 1;
1255 ds_pool_ci.pTypeCount = &ds_type_count;
1256
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001257 VkDescriptorPool ds_pool;
1258 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1259 ASSERT_VK_SUCCESS(err);
1260
Tony Barboureb254902015-07-15 12:50:33 -06001261 VkDescriptorSetLayoutBinding dsl_binding = {};
1262 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1263 dsl_binding.arraySize = 1;
1264 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1265 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001266
Tony Barboureb254902015-07-15 12:50:33 -06001267 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1268 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1269 ds_layout_ci.pNext = NULL;
1270 ds_layout_ci.count = 1;
1271 ds_layout_ci.pBinding = &dsl_binding;
1272
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001273 VkDescriptorSetLayout ds_layout;
1274 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1275 ASSERT_VK_SUCCESS(err);
1276
1277 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06001278 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001279 ASSERT_VK_SUCCESS(err);
1280
Tony Barboureb254902015-07-15 12:50:33 -06001281 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1282 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1283 pipeline_layout_ci.pNext = NULL;
1284 pipeline_layout_ci.descriptorSetCount = 1;
1285 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001286
1287 VkPipelineLayout pipeline_layout;
1288 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1289 ASSERT_VK_SUCCESS(err);
1290
Tony Barboureb254902015-07-15 12:50:33 -06001291 VkGraphicsPipelineCreateInfo gp_ci = {};
1292 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1293 gp_ci.pNext = NULL;
1294 gp_ci.stageCount = 0;
1295 gp_ci.pStages = NULL;
1296 gp_ci.pVertexInputState = NULL;
1297 gp_ci.pInputAssemblyState = NULL;
1298 gp_ci.pTessellationState = NULL;
1299 gp_ci.pViewportState = NULL;
1300 gp_ci.pRasterState = NULL;
1301 gp_ci.pMultisampleState = NULL;
1302 gp_ci.pDepthStencilState = NULL;
1303 gp_ci.pColorBlendState = NULL;
1304 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1305 gp_ci.layout = pipeline_layout;
1306
1307 VkPipelineCacheCreateInfo pc_ci = {};
1308 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1309 pc_ci.pNext = NULL;
1310 pc_ci.initialSize = 0;
1311 pc_ci.initialData = 0;
1312 pc_ci.maxSize = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001313
1314 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06001315 VkPipelineCache pipelineCache;
1316
1317 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1318 ASSERT_VK_SUCCESS(err);
1319 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001320
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001321 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001322 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o VS.";
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001323 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1324 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1325 }
1326}
1327
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06001328TEST_F(VkLayerTest, NullRenderPass)
1329{
1330 // Bind a NULL RenderPass
1331 VkFlags msgFlags;
1332 std::string msgString;
1333
1334 ASSERT_NO_FATAL_FAILURE(InitState());
1335 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1336 m_errorMonitor->ClearState();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06001337
Tony Barbourfe3351b2015-07-28 10:17:20 -06001338 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06001339 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbourfe3351b2015-07-28 10:17:20 -06001340 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06001341
1342 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001343 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06001344 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
1345 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
1346 }
1347}
1348
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001349TEST_F(VkLayerTest, RenderPassWithinRenderPass)
1350{
1351 // Bind a BeginRenderPass within an active RenderPass
1352 VkFlags msgFlags;
1353 std::string msgString;
1354
1355 ASSERT_NO_FATAL_FAILURE(InitState());
1356 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1357 m_errorMonitor->ClearState();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001358
Tony Barbourfe3351b2015-07-28 10:17:20 -06001359 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06001360 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barboureb254902015-07-15 12:50:33 -06001361 VkRenderPassBeginInfo rp_begin = {};
1362 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
1363 rp_begin.pNext = NULL;
1364 rp_begin.renderPass = (VkRenderPass)0xc001d00d;
1365 rp_begin.framebuffer = 0;
1366
Tony Barbourfe3351b2015-07-28 10:17:20 -06001367 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001368
1369 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001370 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding RenderPass w/i an active RenderPass.";
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001371 if (!strstr(msgString.c_str(),"Cannot call vkCmdBeginRenderPass() during an active RenderPass ")) {
1372 FAIL() << "Error received was not 'Cannot call vkCmdBeginRenderPass() during an active RenderPass...'";
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001373 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001374}
1375
1376TEST_F(VkLayerTest, InvalidDynamicStateObject)
1377{
1378 // Create a valid cmd buffer
1379 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001380 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1381 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001382}
Tobin Ehlis1056d452015-05-27 14:55:35 -06001383
Tobin Ehlis502480b2015-06-24 15:53:07 -06001384TEST_F(VkLayerTest, VtxBufferNoRenderPass)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001385{
1386 // Bind VBO out-of-bounds for given PSO
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001387 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001388 std::string msgString;
1389 VkResult err;
1390
1391 ASSERT_NO_FATAL_FAILURE(InitState());
1392 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06001393
1394 VkDescriptorTypeCount ds_type_count = {};
1395 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1396 ds_type_count.count = 1;
1397
1398 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1399 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1400 ds_pool_ci.pNext = NULL;
1401 ds_pool_ci.count = 1;
1402 ds_pool_ci.pTypeCount = &ds_type_count;
1403
Tobin Ehlis3b780662015-05-28 12:11:26 -06001404 VkDescriptorPool ds_pool;
1405 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1406 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001407
Tony Barboureb254902015-07-15 12:50:33 -06001408 VkDescriptorSetLayoutBinding dsl_binding = {};
1409 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1410 dsl_binding.arraySize = 1;
1411 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1412 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001413
Tony Barboureb254902015-07-15 12:50:33 -06001414 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1415 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1416 ds_layout_ci.pNext = NULL;
1417 ds_layout_ci.count = 1;
1418 ds_layout_ci.pBinding = &dsl_binding;
1419
Tobin Ehlis3b780662015-05-28 12:11:26 -06001420 VkDescriptorSetLayout ds_layout;
1421 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1422 ASSERT_VK_SUCCESS(err);
1423
1424 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06001425 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001426 ASSERT_VK_SUCCESS(err);
1427
Tony Barboureb254902015-07-15 12:50:33 -06001428 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1429 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1430 pipeline_layout_ci.pNext = NULL;
1431 pipeline_layout_ci.descriptorSetCount = 1;
1432 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001433
1434 VkPipelineLayout pipeline_layout;
1435 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1436 ASSERT_VK_SUCCESS(err);
1437
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001438 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour1c94d372015-08-06 11:21:08 -06001439 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1440 // but add it to be able to run on more devices
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001441 VkPipelineObj pipe(m_device);
1442 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06001443 pipe.AddShader(&fs);
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001444 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06001445
Tony Barbourfe3351b2015-07-28 10:17:20 -06001446 BeginCommandBuffer();
Tobin Ehlis3b780662015-05-28 12:11:26 -06001447 ASSERT_VK_SUCCESS(err);
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001448 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06001449 // Should error before calling to driver so don't care about actual data
Tony Barbourfe3351b2015-07-28 10:17:20 -06001450 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001451
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001452 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001453 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
Tobin Ehlis502480b2015-06-24 15:53:07 -06001454 if (!strstr(msgString.c_str(),"Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.")) {
1455 FAIL() << "Error received was not 'Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.'";
Tobin Ehlis3b780662015-05-28 12:11:26 -06001456 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001457}
1458
1459TEST_F(VkLayerTest, DSTypeMismatch)
1460{
1461 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001462 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001463 std::string msgString;
1464 VkResult err;
1465
1466 ASSERT_NO_FATAL_FAILURE(InitState());
1467 m_errorMonitor->ClearState();
1468 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06001469 VkDescriptorTypeCount ds_type_count = {};
1470 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1471 ds_type_count.count = 1;
1472
1473 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1474 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1475 ds_pool_ci.pNext = NULL;
1476 ds_pool_ci.count = 1;
1477 ds_pool_ci.pTypeCount = &ds_type_count;
1478
Tobin Ehlis3b780662015-05-28 12:11:26 -06001479 VkDescriptorPool ds_pool;
1480 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1481 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06001482 VkDescriptorSetLayoutBinding dsl_binding = {};
1483 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1484 dsl_binding.arraySize = 1;
1485 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1486 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001487
Tony Barboureb254902015-07-15 12:50:33 -06001488 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1489 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1490 ds_layout_ci.pNext = NULL;
1491 ds_layout_ci.count = 1;
1492 ds_layout_ci.pBinding = &dsl_binding;
1493
Tobin Ehlis3b780662015-05-28 12:11:26 -06001494 VkDescriptorSetLayout ds_layout;
1495 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1496 ASSERT_VK_SUCCESS(err);
1497
1498 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06001499 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001500 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001501
Tony Barboureb254902015-07-15 12:50:33 -06001502 VkSamplerCreateInfo sampler_ci = {};
1503 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1504 sampler_ci.pNext = NULL;
1505 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1506 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1507 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1508 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1509 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1510 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1511 sampler_ci.mipLodBias = 1.0;
1512 sampler_ci.maxAnisotropy = 1;
1513 sampler_ci.compareEnable = VK_FALSE;
1514 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1515 sampler_ci.minLod = 1.0;
1516 sampler_ci.maxLod = 1.0;
1517 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northropab1f9e22015-08-11 15:50:55 -06001518 sampler_ci.texelCoords = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06001519
Tobin Ehlis3b780662015-05-28 12:11:26 -06001520 VkSampler sampler;
1521 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1522 ASSERT_VK_SUCCESS(err);
1523
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001524 VkDescriptorInfo descriptor_info;
1525 memset(&descriptor_info, 0, sizeof(descriptor_info));
1526 descriptor_info.sampler = sampler;
1527
1528 VkWriteDescriptorSet descriptor_write;
1529 memset(&descriptor_write, 0, sizeof(descriptor_write));
1530 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1531 descriptor_write.destSet = descriptorSet;
1532 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001533 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001534 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1535 descriptor_write.pDescriptors = &descriptor_info;
1536
1537 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1538
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001539 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001540 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating BUFFER Descriptor w/ incorrect type of SAMPLER.";
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001541 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) {
1542 FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match overlapping binding type!'";
Tobin Ehlis3b780662015-05-28 12:11:26 -06001543 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001544}
1545
1546TEST_F(VkLayerTest, DSUpdateOutOfBounds)
1547{
1548 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001549 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001550 std::string msgString;
1551 VkResult err;
1552
1553 ASSERT_NO_FATAL_FAILURE(InitState());
1554 m_errorMonitor->ClearState();
1555 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06001556 VkDescriptorTypeCount ds_type_count = {};
1557 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1558 ds_type_count.count = 1;
1559
1560 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1561 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1562 ds_pool_ci.pNext = NULL;
1563 ds_pool_ci.count = 1;
1564 ds_pool_ci.pTypeCount = &ds_type_count;
1565
Tobin Ehlis3b780662015-05-28 12:11:26 -06001566 VkDescriptorPool ds_pool;
1567 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1568 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001569
Tony Barboureb254902015-07-15 12:50:33 -06001570 VkDescriptorSetLayoutBinding dsl_binding = {};
1571 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1572 dsl_binding.arraySize = 1;
1573 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1574 dsl_binding.pImmutableSamplers = NULL;
1575
1576 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1577 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1578 ds_layout_ci.pNext = NULL;
1579 ds_layout_ci.count = 1;
1580 ds_layout_ci.pBinding = &dsl_binding;
1581
Tobin Ehlis3b780662015-05-28 12:11:26 -06001582 VkDescriptorSetLayout ds_layout;
1583 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1584 ASSERT_VK_SUCCESS(err);
1585
1586 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06001587 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001588 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001589
Tony Barboureb254902015-07-15 12:50:33 -06001590 VkSamplerCreateInfo sampler_ci = {};
1591 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1592 sampler_ci.pNext = NULL;
1593 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1594 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1595 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1596 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1597 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1598 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1599 sampler_ci.mipLodBias = 1.0;
1600 sampler_ci.maxAnisotropy = 1;
1601 sampler_ci.compareEnable = VK_FALSE;
1602 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1603 sampler_ci.minLod = 1.0;
1604 sampler_ci.maxLod = 1.0;
1605 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northropab1f9e22015-08-11 15:50:55 -06001606 sampler_ci.texelCoords = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06001607
Tobin Ehlis3b780662015-05-28 12:11:26 -06001608 VkSampler sampler;
1609 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1610 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001611
1612 VkDescriptorInfo descriptor_info;
1613 memset(&descriptor_info, 0, sizeof(descriptor_info));
1614 descriptor_info.sampler = sampler;
1615
1616 VkWriteDescriptorSet descriptor_write;
1617 memset(&descriptor_write, 0, sizeof(descriptor_write));
1618 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1619 descriptor_write.destSet = descriptorSet;
1620 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
1621 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001622 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001623 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1624 descriptor_write.pDescriptors = &descriptor_info;
1625
1626 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1627
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001628 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001629 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ index out of bounds.";
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001630 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
1631 FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
Tobin Ehlis3b780662015-05-28 12:11:26 -06001632 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001633}
1634
1635TEST_F(VkLayerTest, InvalidDSUpdateIndex)
1636{
Tobin Ehlis3b780662015-05-28 12:11:26 -06001637 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001638 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001639 std::string msgString;
1640 VkResult err;
1641
1642 ASSERT_NO_FATAL_FAILURE(InitState());
1643 m_errorMonitor->ClearState();
1644 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06001645 VkDescriptorTypeCount ds_type_count = {};
1646 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1647 ds_type_count.count = 1;
1648
1649 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1650 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1651 ds_pool_ci.pNext = NULL;
1652 ds_pool_ci.count = 1;
1653 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001654 VkDescriptorPool ds_pool;
1655 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1656 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001657
Tony Barboureb254902015-07-15 12:50:33 -06001658 VkDescriptorSetLayoutBinding dsl_binding = {};
1659 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1660 dsl_binding.arraySize = 1;
1661 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1662 dsl_binding.pImmutableSamplers = NULL;
1663
1664 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1665 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1666 ds_layout_ci.pNext = NULL;
1667 ds_layout_ci.count = 1;
1668 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001669 VkDescriptorSetLayout ds_layout;
1670 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1671 ASSERT_VK_SUCCESS(err);
1672
1673 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06001674 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001675 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001676
Tony Barboureb254902015-07-15 12:50:33 -06001677 VkSamplerCreateInfo sampler_ci = {};
1678 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1679 sampler_ci.pNext = NULL;
1680 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1681 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1682 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1683 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1684 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1685 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1686 sampler_ci.mipLodBias = 1.0;
1687 sampler_ci.maxAnisotropy = 1;
1688 sampler_ci.compareEnable = VK_FALSE;
1689 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1690 sampler_ci.minLod = 1.0;
1691 sampler_ci.maxLod = 1.0;
1692 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northropab1f9e22015-08-11 15:50:55 -06001693 sampler_ci.texelCoords = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06001694
Tobin Ehlis3b780662015-05-28 12:11:26 -06001695 VkSampler sampler;
1696 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1697 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001698
1699 VkDescriptorInfo descriptor_info;
1700 memset(&descriptor_info, 0, sizeof(descriptor_info));
1701 descriptor_info.sampler = sampler;
1702
1703 VkWriteDescriptorSet descriptor_write;
1704 memset(&descriptor_write, 0, sizeof(descriptor_write));
1705 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1706 descriptor_write.destSet = descriptorSet;
1707 descriptor_write.destBinding = 2;
1708 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001709 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001710 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1711 descriptor_write.pDescriptors = &descriptor_info;
1712
1713 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1714
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001715 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001716 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ count too large for layout.";
Tobin Ehlis3b780662015-05-28 12:11:26 -06001717 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
1718 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
1719 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001720}
1721
1722TEST_F(VkLayerTest, InvalidDSUpdateStruct)
1723{
1724 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001725 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001726 std::string msgString;
1727 VkResult err;
1728
1729 ASSERT_NO_FATAL_FAILURE(InitState());
1730 m_errorMonitor->ClearState();
1731 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06001732
1733 VkDescriptorTypeCount ds_type_count = {};
1734 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1735 ds_type_count.count = 1;
1736
1737 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1738 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1739 ds_pool_ci.pNext = NULL;
1740 ds_pool_ci.count = 1;
1741 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001742 VkDescriptorPool ds_pool;
1743 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1744 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06001745 VkDescriptorSetLayoutBinding dsl_binding = {};
1746 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1747 dsl_binding.arraySize = 1;
1748 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1749 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001750
Tony Barboureb254902015-07-15 12:50:33 -06001751 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1752 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1753 ds_layout_ci.pNext = NULL;
1754 ds_layout_ci.count = 1;
1755 ds_layout_ci.pBinding = &dsl_binding;
1756
Tobin Ehlis3b780662015-05-28 12:11:26 -06001757 VkDescriptorSetLayout ds_layout;
1758 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1759 ASSERT_VK_SUCCESS(err);
1760
1761 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06001762 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001763 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001764
Tony Barboureb254902015-07-15 12:50:33 -06001765 VkSamplerCreateInfo sampler_ci = {};
1766 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1767 sampler_ci.pNext = NULL;
1768 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1769 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1770 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1771 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1772 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1773 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1774 sampler_ci.mipLodBias = 1.0;
1775 sampler_ci.maxAnisotropy = 1;
1776 sampler_ci.compareEnable = VK_FALSE;
1777 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1778 sampler_ci.minLod = 1.0;
1779 sampler_ci.maxLod = 1.0;
1780 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northropab1f9e22015-08-11 15:50:55 -06001781 sampler_ci.texelCoords = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001782 VkSampler sampler;
1783 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1784 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001785
1786
1787 VkDescriptorInfo descriptor_info;
1788 memset(&descriptor_info, 0, sizeof(descriptor_info));
1789 descriptor_info.sampler = sampler;
1790
1791 VkWriteDescriptorSet descriptor_write;
1792 memset(&descriptor_write, 0, sizeof(descriptor_write));
1793 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
1794 descriptor_write.destSet = descriptorSet;
1795 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001796 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001797 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1798 descriptor_write.pDescriptors = &descriptor_info;
1799
1800 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1801
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001802 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001803 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ invalid struct type.";
Tobin Ehlis3b780662015-05-28 12:11:26 -06001804 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
1805 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
1806 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001807}
1808
1809TEST_F(VkLayerTest, NumSamplesMismatch)
1810{
Tobin Ehlis3b780662015-05-28 12:11:26 -06001811 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001812 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001813 std::string msgString;
1814 VkResult err;
1815
1816 ASSERT_NO_FATAL_FAILURE(InitState());
1817 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1818 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06001819 VkDescriptorTypeCount ds_type_count = {};
1820 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1821 ds_type_count.count = 1;
1822
1823 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1824 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1825 ds_pool_ci.pNext = NULL;
1826 ds_pool_ci.count = 1;
1827 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001828 VkDescriptorPool ds_pool;
1829 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1830 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001831
Tony Barboureb254902015-07-15 12:50:33 -06001832 VkDescriptorSetLayoutBinding dsl_binding = {};
1833 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1834 dsl_binding.arraySize = 1;
1835 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1836 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001837
Tony Barboureb254902015-07-15 12:50:33 -06001838 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1839 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1840 ds_layout_ci.pNext = NULL;
1841 ds_layout_ci.count = 1;
1842 ds_layout_ci.pBinding = &dsl_binding;
1843
Tobin Ehlis3b780662015-05-28 12:11:26 -06001844 VkDescriptorSetLayout ds_layout;
1845 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1846 ASSERT_VK_SUCCESS(err);
1847
1848 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06001849 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001850 ASSERT_VK_SUCCESS(err);
1851
Tony Barboureb254902015-07-15 12:50:33 -06001852 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1853 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1854 pipe_ms_state_ci.pNext = NULL;
1855 pipe_ms_state_ci.rasterSamples = 4;
1856 pipe_ms_state_ci.sampleShadingEnable = 0;
1857 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06001858 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001859
Tony Barboureb254902015-07-15 12:50:33 -06001860 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1861 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1862 pipeline_layout_ci.pNext = NULL;
1863 pipeline_layout_ci.descriptorSetCount = 1;
1864 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001865
1866 VkPipelineLayout pipeline_layout;
1867 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1868 ASSERT_VK_SUCCESS(err);
1869
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001870 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour1c94d372015-08-06 11:21:08 -06001871 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1872 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06001873 VkPipelineObj pipe(m_device);
1874 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06001875 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06001876 pipe.SetMSAA(&pipe_ms_state_ci);
1877 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06001878
Tony Barbourfe3351b2015-07-28 10:17:20 -06001879 BeginCommandBuffer();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06001880 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06001881
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001882 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001883 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding RenderPass w/ mismatched MSAA from PSO.";
Tobin Ehlis3b780662015-05-28 12:11:26 -06001884 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
1885 FAIL() << "Error received was not 'Num samples mismatch!...'";
1886 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001887}
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001888
Tobin Ehlis502480b2015-06-24 15:53:07 -06001889TEST_F(VkLayerTest, PipelineNotBound)
1890{
1891 VkFlags msgFlags;
1892 std::string msgString;
1893 VkResult err;
1894
1895 ASSERT_NO_FATAL_FAILURE(InitState());
1896 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1897 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06001898
1899 VkDescriptorTypeCount ds_type_count = {};
1900 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1901 ds_type_count.count = 1;
1902
1903 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1904 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1905 ds_pool_ci.pNext = NULL;
1906 ds_pool_ci.count = 1;
1907 ds_pool_ci.pTypeCount = &ds_type_count;
1908
Tobin Ehlis502480b2015-06-24 15:53:07 -06001909 VkDescriptorPool ds_pool;
1910 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1911 ASSERT_VK_SUCCESS(err);
1912
Tony Barboureb254902015-07-15 12:50:33 -06001913 VkDescriptorSetLayoutBinding dsl_binding = {};
1914 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1915 dsl_binding.arraySize = 1;
1916 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1917 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06001918
Tony Barboureb254902015-07-15 12:50:33 -06001919 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1920 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1921 ds_layout_ci.pNext = NULL;
1922 ds_layout_ci.count = 1;
1923 ds_layout_ci.pBinding = &dsl_binding;
1924
Tobin Ehlis502480b2015-06-24 15:53:07 -06001925 VkDescriptorSetLayout ds_layout;
1926 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1927 ASSERT_VK_SUCCESS(err);
1928
1929 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06001930 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06001931 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06001932
1933 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1934 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1935 pipeline_layout_ci.pNext = NULL;
1936 pipeline_layout_ci.descriptorSetCount = 1;
1937 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06001938
1939 VkPipelineLayout pipeline_layout;
1940 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1941 ASSERT_VK_SUCCESS(err);
1942
Tobin Ehlis502480b2015-06-24 15:53:07 -06001943 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Tony Barbourfe3351b2015-07-28 10:17:20 -06001944
1945 BeginCommandBuffer();
1946 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlis502480b2015-06-24 15:53:07 -06001947
1948 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001949 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Tobin Ehlis502480b2015-06-24 15:53:07 -06001950 if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1951 FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1952 }
1953}
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001954
1955TEST_F(VkLayerTest, ClearCmdNoDraw)
1956{
1957 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
1958 VkFlags msgFlags;
1959 std::string msgString;
1960 VkResult err;
1961
1962 ASSERT_NO_FATAL_FAILURE(InitState());
1963 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1964 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06001965
1966 VkDescriptorTypeCount ds_type_count = {};
1967 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1968 ds_type_count.count = 1;
1969
1970 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1971 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1972 ds_pool_ci.pNext = NULL;
1973 ds_pool_ci.count = 1;
1974 ds_pool_ci.pTypeCount = &ds_type_count;
1975
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001976 VkDescriptorPool ds_pool;
1977 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1978 ASSERT_VK_SUCCESS(err);
1979
Tony Barboureb254902015-07-15 12:50:33 -06001980 VkDescriptorSetLayoutBinding dsl_binding = {};
1981 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1982 dsl_binding.arraySize = 1;
1983 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1984 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001985
Tony Barboureb254902015-07-15 12:50:33 -06001986 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1987 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1988 ds_layout_ci.pNext = NULL;
1989 ds_layout_ci.count = 1;
1990 ds_layout_ci.pBinding = &dsl_binding;
1991
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001992 VkDescriptorSetLayout ds_layout;
1993 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1994 ASSERT_VK_SUCCESS(err);
1995
1996 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06001997 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001998 ASSERT_VK_SUCCESS(err);
1999
Tony Barboureb254902015-07-15 12:50:33 -06002000 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2001 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2002 pipe_ms_state_ci.pNext = NULL;
2003 pipe_ms_state_ci.rasterSamples = 4;
2004 pipe_ms_state_ci.sampleShadingEnable = 0;
2005 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06002006 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002007
Tony Barboureb254902015-07-15 12:50:33 -06002008 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2009 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2010 pipeline_layout_ci.pNext = NULL;
2011 pipeline_layout_ci.descriptorSetCount = 1;
2012 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002013
2014 VkPipelineLayout pipeline_layout;
2015 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2016 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06002017
Tony Barbour62e1a5b2015-08-06 10:16:07 -06002018 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour1c94d372015-08-06 11:21:08 -06002019 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2020 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06002021 VkPipelineObj pipe(m_device);
2022 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06002023 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06002024 pipe.SetMSAA(&pipe_ms_state_ci);
2025 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002026
2027 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002028
2029 m_errorMonitor->ClearState();
2030 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
2031 // Also pass down other dummy params to keep driver and paramchecker happy
2032 VkClearColorValue cCV;
2033 cCV.f32[0] = 1.0;
2034 cCV.f32[1] = 1.0;
2035 cCV.f32[2] = 1.0;
2036 cCV.f32[3] = 1.0;
2037
Tony Barbourfe3351b2015-07-28 10:17:20 -06002038 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002039 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002040 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not receive error after issuing Clear Cmd on FB color attachment prior to Draw Cmd.";
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002041 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) {
2042 FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'";
2043 }
2044}
2045
Tobin Ehlis502480b2015-06-24 15:53:07 -06002046TEST_F(VkLayerTest, VtxBufferBadIndex)
2047{
2048 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
2049 VkFlags msgFlags;
2050 std::string msgString;
2051 VkResult err;
2052
2053 ASSERT_NO_FATAL_FAILURE(InitState());
2054 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2055 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06002056
2057 VkDescriptorTypeCount ds_type_count = {};
2058 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2059 ds_type_count.count = 1;
2060
2061 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2062 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2063 ds_pool_ci.pNext = NULL;
2064 ds_pool_ci.count = 1;
2065 ds_pool_ci.pTypeCount = &ds_type_count;
2066
2067 VkDescriptorPool ds_pool;
Tobin Ehlis502480b2015-06-24 15:53:07 -06002068 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
2069 ASSERT_VK_SUCCESS(err);
2070
Tony Barboureb254902015-07-15 12:50:33 -06002071 VkDescriptorSetLayoutBinding dsl_binding = {};
2072 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2073 dsl_binding.arraySize = 1;
2074 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2075 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06002076
Tony Barboureb254902015-07-15 12:50:33 -06002077 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2078 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2079 ds_layout_ci.pNext = NULL;
2080 ds_layout_ci.count = 1;
2081 ds_layout_ci.pBinding = &dsl_binding;
2082
Tobin Ehlis502480b2015-06-24 15:53:07 -06002083 VkDescriptorSetLayout ds_layout;
2084 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2085 ASSERT_VK_SUCCESS(err);
2086
2087 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06002088 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002089 ASSERT_VK_SUCCESS(err);
2090
Tony Barboureb254902015-07-15 12:50:33 -06002091 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2092 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2093 pipe_ms_state_ci.pNext = NULL;
2094 pipe_ms_state_ci.rasterSamples = 1;
2095 pipe_ms_state_ci.sampleShadingEnable = 0;
2096 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06002097 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06002098
Tony Barboureb254902015-07-15 12:50:33 -06002099 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2100 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2101 pipeline_layout_ci.pNext = NULL;
2102 pipeline_layout_ci.descriptorSetCount = 1;
2103 pipeline_layout_ci.pSetLayouts = &ds_layout;
2104 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06002105
Tobin Ehlis502480b2015-06-24 15:53:07 -06002106 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2107 ASSERT_VK_SUCCESS(err);
2108
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06002109 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour1c94d372015-08-06 11:21:08 -06002110 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2111 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06002112 VkPipelineObj pipe(m_device);
2113 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06002114 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06002115 pipe.SetMSAA(&pipe_ms_state_ci);
2116 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002117
2118 BeginCommandBuffer();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06002119 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis502480b2015-06-24 15:53:07 -06002120 // Should error before calling to driver so don't care about actual data
Tony Barbourfe3351b2015-07-28 10:17:20 -06002121 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002122
2123 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002124 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding Vtx Buffer w/o VBO attached to PSO.";
Tobin Ehlis502480b2015-06-24 15:53:07 -06002125 if (!strstr(msgString.c_str(),"Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.")) {
2126 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
2127 }
2128}
Tobin Ehlis0788f522015-05-26 16:11:58 -06002129#endif
2130#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06002131#if GTEST_IS_THREADSAFE
2132struct thread_data_struct {
2133 VkCmdBuffer cmdBuffer;
2134 VkEvent event;
2135 bool bailout;
2136};
2137
2138extern "C" void *AddToCommandBuffer(void *arg)
2139{
2140 struct thread_data_struct *data = (struct thread_data_struct *) arg;
2141 std::string msgString;
2142
2143 for (int i = 0; i<10000; i++) {
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002144 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyanaccf7692015-05-12 16:00:45 -06002145 if (data->bailout) {
2146 break;
2147 }
2148 }
2149 return NULL;
2150}
2151
2152TEST_F(VkLayerTest, ThreadCmdBufferCollision)
2153{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002154 VkFlags msgFlags;
Mike Stroyanaccf7692015-05-12 16:00:45 -06002155 std::string msgString;
Mike Stroyan4268d1f2015-07-13 14:45:35 -06002156 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06002157
2158 ASSERT_NO_FATAL_FAILURE(InitState());
2159 ASSERT_NO_FATAL_FAILURE(InitViewport());
2160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2161
Mike Stroyanaccf7692015-05-12 16:00:45 -06002162 m_errorMonitor->ClearState();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002163 BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06002164
2165 VkEventCreateInfo event_info;
2166 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06002167 VkResult err;
2168
2169 memset(&event_info, 0, sizeof(event_info));
2170 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2171
2172 err = vkCreateEvent(device(), &event_info, &event);
2173 ASSERT_VK_SUCCESS(err);
2174
Mike Stroyanaccf7692015-05-12 16:00:45 -06002175 err = vkResetEvent(device(), event);
2176 ASSERT_VK_SUCCESS(err);
2177
2178 struct thread_data_struct data;
Tony Barbourfe3351b2015-07-28 10:17:20 -06002179 data.cmdBuffer = m_cmdBuffer->handle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06002180 data.event = event;
2181 data.bailout = false;
2182 m_errorMonitor->SetBailout(&data.bailout);
2183 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06002184 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06002185 // Add many entries to command buffer from this thread at the same time.
2186 AddToCommandBuffer(&data);
Mike Stroyan4268d1f2015-07-13 14:45:35 -06002187 test_platform_thread_join(thread, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002188 EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06002189
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002190 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002191 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err from using one VkCommandBufferObj in two threads";
Mike Stroyanaccf7692015-05-12 16:00:45 -06002192 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002193 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyanaccf7692015-05-12 16:00:45 -06002194 }
2195
2196}
2197#endif
Tobin Ehlis0788f522015-05-26 16:11:58 -06002198#endif
Chris Forbes9f7ff632015-05-25 11:13:08 +12002199#if SHADER_CHECKER_TESTS
2200TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
2201{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002202 VkFlags msgFlags;
Chris Forbes9f7ff632015-05-25 11:13:08 +12002203 std::string msgString;
2204 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop50a2a4b2015-06-03 16:49:20 -06002205 ScopedUseGlsl useGlsl(false);
Chris Forbes9f7ff632015-05-25 11:13:08 +12002206
2207 char const *vsSource =
2208 "#version 140\n"
2209 "#extension GL_ARB_separate_shader_objects: require\n"
2210 "#extension GL_ARB_shading_language_420pack: require\n"
2211 "\n"
2212 "layout(location=0) out float x;\n"
2213 "void main(){\n"
2214 " gl_Position = vec4(1);\n"
2215 " x = 0;\n"
2216 "}\n";
2217 char const *fsSource =
2218 "#version 140\n"
2219 "#extension GL_ARB_separate_shader_objects: require\n"
2220 "#extension GL_ARB_shading_language_420pack: require\n"
2221 "\n"
2222 "layout(location=0) out vec4 color;\n"
2223 "void main(){\n"
2224 " color = vec4(1);\n"
2225 "}\n";
2226
2227 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2228 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2229
2230 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002231 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12002232 pipe.AddShader(&vs);
2233 pipe.AddShader(&fs);
2234
Chris Forbes9f7ff632015-05-25 11:13:08 +12002235 VkDescriptorSetObj descriptorSet(m_device);
2236 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002237 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12002238
2239 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06002240 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12002241
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002242 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes9f7ff632015-05-25 11:13:08 +12002243
Cody Northropd2ad0342015-08-05 11:15:02 -06002244 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes9f7ff632015-05-25 11:13:08 +12002245 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
2246 FAIL() << "Incorrect warning: " << msgString;
2247 }
2248}
Chris Forbes9f7ff632015-05-25 11:13:08 +12002249
Chris Forbes59cb88d2015-05-25 11:13:13 +12002250TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
2251{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002252 VkFlags msgFlags;
Chris Forbes59cb88d2015-05-25 11:13:13 +12002253 std::string msgString;
2254 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop50a2a4b2015-06-03 16:49:20 -06002255 ScopedUseGlsl useGlsl(false);
Chris Forbes59cb88d2015-05-25 11:13:13 +12002256
2257 char const *vsSource =
2258 "#version 140\n"
2259 "#extension GL_ARB_separate_shader_objects: require\n"
2260 "#extension GL_ARB_shading_language_420pack: require\n"
2261 "\n"
2262 "void main(){\n"
2263 " gl_Position = vec4(1);\n"
2264 "}\n";
2265 char const *fsSource =
2266 "#version 140\n"
2267 "#extension GL_ARB_separate_shader_objects: require\n"
2268 "#extension GL_ARB_shading_language_420pack: require\n"
2269 "\n"
2270 "layout(location=0) in float x;\n"
2271 "layout(location=0) out vec4 color;\n"
2272 "void main(){\n"
2273 " color = vec4(x);\n"
2274 "}\n";
2275
2276 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2277 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2278
2279 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002280 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12002281 pipe.AddShader(&vs);
2282 pipe.AddShader(&fs);
2283
Chris Forbes59cb88d2015-05-25 11:13:13 +12002284 VkDescriptorSetObj descriptorSet(m_device);
2285 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002286 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12002287
2288 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06002289 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12002290
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002291 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes59cb88d2015-05-25 11:13:13 +12002292
Cody Northropd2ad0342015-08-05 11:15:02 -06002293 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes59cb88d2015-05-25 11:13:13 +12002294 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
2295 FAIL() << "Incorrect error: " << msgString;
2296 }
2297}
2298
Chris Forbesb56af562015-05-25 11:13:17 +12002299TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
2300{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002301 VkFlags msgFlags;
Chris Forbesb56af562015-05-25 11:13:17 +12002302 std::string msgString;
2303 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop50a2a4b2015-06-03 16:49:20 -06002304 ScopedUseGlsl useGlsl(false);
Chris Forbesb56af562015-05-25 11:13:17 +12002305
2306 char const *vsSource =
2307 "#version 140\n"
2308 "#extension GL_ARB_separate_shader_objects: require\n"
2309 "#extension GL_ARB_shading_language_420pack: require\n"
2310 "\n"
2311 "layout(location=0) out int x;\n"
2312 "void main(){\n"
2313 " x = 0;\n"
2314 " gl_Position = vec4(1);\n"
2315 "}\n";
2316 char const *fsSource =
2317 "#version 140\n"
2318 "#extension GL_ARB_separate_shader_objects: require\n"
2319 "#extension GL_ARB_shading_language_420pack: require\n"
2320 "\n"
2321 "layout(location=0) in float x;\n" /* VS writes int */
2322 "layout(location=0) out vec4 color;\n"
2323 "void main(){\n"
2324 " color = vec4(x);\n"
2325 "}\n";
2326
2327 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2328 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2329
2330 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002331 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12002332 pipe.AddShader(&vs);
2333 pipe.AddShader(&fs);
2334
Chris Forbesb56af562015-05-25 11:13:17 +12002335 VkDescriptorSetObj descriptorSet(m_device);
2336 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002337 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12002338
2339 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06002340 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12002341
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002342 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesb56af562015-05-25 11:13:17 +12002343
Cody Northropd2ad0342015-08-05 11:15:02 -06002344 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesb56af562015-05-25 11:13:17 +12002345 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
2346 FAIL() << "Incorrect error: " << msgString;
2347 }
2348}
2349
Chris Forbesde136e02015-05-25 11:13:28 +12002350TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
2351{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002352 VkFlags msgFlags;
Chris Forbesde136e02015-05-25 11:13:28 +12002353 std::string msgString;
2354 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop50a2a4b2015-06-03 16:49:20 -06002355 ScopedUseGlsl useGlsl(false);
Chris Forbesde136e02015-05-25 11:13:28 +12002356
2357 VkVertexInputBindingDescription input_binding;
2358 memset(&input_binding, 0, sizeof(input_binding));
2359
2360 VkVertexInputAttributeDescription input_attrib;
2361 memset(&input_attrib, 0, sizeof(input_attrib));
2362 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2363
2364 char const *vsSource =
2365 "#version 140\n"
2366 "#extension GL_ARB_separate_shader_objects: require\n"
2367 "#extension GL_ARB_shading_language_420pack: require\n"
2368 "\n"
2369 "void main(){\n"
2370 " gl_Position = vec4(1);\n"
2371 "}\n";
2372 char const *fsSource =
2373 "#version 140\n"
2374 "#extension GL_ARB_separate_shader_objects: require\n"
2375 "#extension GL_ARB_shading_language_420pack: require\n"
2376 "\n"
2377 "layout(location=0) out vec4 color;\n"
2378 "void main(){\n"
2379 " color = vec4(1);\n"
2380 "}\n";
2381
2382 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2383 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2384
2385 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002386 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12002387 pipe.AddShader(&vs);
2388 pipe.AddShader(&fs);
2389
2390 pipe.AddVertexInputBindings(&input_binding, 1);
2391 pipe.AddVertexInputAttribs(&input_attrib, 1);
2392
Chris Forbesde136e02015-05-25 11:13:28 +12002393 VkDescriptorSetObj descriptorSet(m_device);
2394 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002395 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12002396
2397 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06002398 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12002399
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002400 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesde136e02015-05-25 11:13:28 +12002401
Cody Northropd2ad0342015-08-05 11:15:02 -06002402 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesde136e02015-05-25 11:13:28 +12002403 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
2404 FAIL() << "Incorrect warning: " << msgString;
2405 }
2406}
2407
Chris Forbes62e8e502015-05-25 11:13:29 +12002408TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
2409{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002410 VkFlags msgFlags;
Chris Forbes62e8e502015-05-25 11:13:29 +12002411 std::string msgString;
2412 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop50a2a4b2015-06-03 16:49:20 -06002413 ScopedUseGlsl useGlsl(false);
Chris Forbes62e8e502015-05-25 11:13:29 +12002414
2415 char const *vsSource =
2416 "#version 140\n"
2417 "#extension GL_ARB_separate_shader_objects: require\n"
2418 "#extension GL_ARB_shading_language_420pack: require\n"
2419 "\n"
2420 "layout(location=0) in vec4 x;\n" /* not provided */
2421 "void main(){\n"
2422 " gl_Position = x;\n"
2423 "}\n";
2424 char const *fsSource =
2425 "#version 140\n"
2426 "#extension GL_ARB_separate_shader_objects: require\n"
2427 "#extension GL_ARB_shading_language_420pack: require\n"
2428 "\n"
2429 "layout(location=0) out vec4 color;\n"
2430 "void main(){\n"
2431 " color = vec4(1);\n"
2432 "}\n";
2433
2434 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2435 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2436
2437 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002438 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12002439 pipe.AddShader(&vs);
2440 pipe.AddShader(&fs);
2441
Chris Forbes62e8e502015-05-25 11:13:29 +12002442 VkDescriptorSetObj descriptorSet(m_device);
2443 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002444 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12002445
2446 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06002447 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12002448
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002449 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes62e8e502015-05-25 11:13:29 +12002450
Cody Northropd2ad0342015-08-05 11:15:02 -06002451 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes62e8e502015-05-25 11:13:29 +12002452 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
2453 FAIL() << "Incorrect warning: " << msgString;
2454 }
2455}
2456
Chris Forbesc97d98e2015-05-25 11:13:31 +12002457TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
2458{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002459 VkFlags msgFlags;
Chris Forbesc97d98e2015-05-25 11:13:31 +12002460 std::string msgString;
2461 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop50a2a4b2015-06-03 16:49:20 -06002462 ScopedUseGlsl useGlsl(false);
Chris Forbesc97d98e2015-05-25 11:13:31 +12002463
2464 VkVertexInputBindingDescription input_binding;
2465 memset(&input_binding, 0, sizeof(input_binding));
2466
2467 VkVertexInputAttributeDescription input_attrib;
2468 memset(&input_attrib, 0, sizeof(input_attrib));
2469 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2470
2471 char const *vsSource =
2472 "#version 140\n"
2473 "#extension GL_ARB_separate_shader_objects: require\n"
2474 "#extension GL_ARB_shading_language_420pack: require\n"
2475 "\n"
2476 "layout(location=0) in int x;\n" /* attrib provided float */
2477 "void main(){\n"
2478 " gl_Position = vec4(x);\n"
2479 "}\n";
2480 char const *fsSource =
2481 "#version 140\n"
2482 "#extension GL_ARB_separate_shader_objects: require\n"
2483 "#extension GL_ARB_shading_language_420pack: require\n"
2484 "\n"
2485 "layout(location=0) out vec4 color;\n"
2486 "void main(){\n"
2487 " color = vec4(1);\n"
2488 "}\n";
2489
2490 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2491 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2492
2493 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002494 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12002495 pipe.AddShader(&vs);
2496 pipe.AddShader(&fs);
2497
2498 pipe.AddVertexInputBindings(&input_binding, 1);
2499 pipe.AddVertexInputAttribs(&input_attrib, 1);
2500
Chris Forbesc97d98e2015-05-25 11:13:31 +12002501 VkDescriptorSetObj descriptorSet(m_device);
2502 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002503 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12002504
2505 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06002506 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12002507
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002508 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc97d98e2015-05-25 11:13:31 +12002509
Cody Northropd2ad0342015-08-05 11:15:02 -06002510 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc97d98e2015-05-25 11:13:31 +12002511 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
2512 FAIL() << "Incorrect error: " << msgString;
2513 }
2514}
2515
Chris Forbes280ba2c2015-06-12 11:16:41 +12002516TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
2517{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002518 VkFlags msgFlags;
Chris Forbes280ba2c2015-06-12 11:16:41 +12002519 std::string msgString;
2520 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop50a2a4b2015-06-03 16:49:20 -06002521 ScopedUseGlsl useGlsl(false);
Chris Forbes280ba2c2015-06-12 11:16:41 +12002522
2523 /* Two binding descriptions for binding 0 */
2524 VkVertexInputBindingDescription input_bindings[2];
2525 memset(input_bindings, 0, sizeof(input_bindings));
2526
2527 VkVertexInputAttributeDescription input_attrib;
2528 memset(&input_attrib, 0, sizeof(input_attrib));
2529 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2530
2531 char const *vsSource =
2532 "#version 140\n"
2533 "#extension GL_ARB_separate_shader_objects: require\n"
2534 "#extension GL_ARB_shading_language_420pack: require\n"
2535 "\n"
2536 "layout(location=0) in float x;\n" /* attrib provided float */
2537 "void main(){\n"
2538 " gl_Position = vec4(x);\n"
2539 "}\n";
2540 char const *fsSource =
2541 "#version 140\n"
2542 "#extension GL_ARB_separate_shader_objects: require\n"
2543 "#extension GL_ARB_shading_language_420pack: require\n"
2544 "\n"
2545 "layout(location=0) out vec4 color;\n"
2546 "void main(){\n"
2547 " color = vec4(1);\n"
2548 "}\n";
2549
2550 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2551 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2552
2553 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002554 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12002555 pipe.AddShader(&vs);
2556 pipe.AddShader(&fs);
2557
2558 pipe.AddVertexInputBindings(input_bindings, 2);
2559 pipe.AddVertexInputAttribs(&input_attrib, 1);
2560
Chris Forbes280ba2c2015-06-12 11:16:41 +12002561 VkDescriptorSetObj descriptorSet(m_device);
2562 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002563 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12002564
2565 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06002566 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12002567
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002568 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes280ba2c2015-06-12 11:16:41 +12002569
Cody Northropd2ad0342015-08-05 11:15:02 -06002570 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes280ba2c2015-06-12 11:16:41 +12002571 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
2572 FAIL() << "Incorrect error: " << msgString;
2573 }
2574}
Chris Forbes8f68b562015-05-25 11:13:32 +12002575
Chris Forbes4d6d1e52015-05-25 11:13:40 +12002576/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
2577 * rejects it. */
2578
2579TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
2580{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002581 VkFlags msgFlags;
Chris Forbes4d6d1e52015-05-25 11:13:40 +12002582 std::string msgString;
2583 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop50a2a4b2015-06-03 16:49:20 -06002584 ScopedUseGlsl useGlsl(false);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12002585
2586 char const *vsSource =
2587 "#version 140\n"
2588 "#extension GL_ARB_separate_shader_objects: require\n"
2589 "#extension GL_ARB_shading_language_420pack: require\n"
2590 "\n"
2591 "void main(){\n"
2592 " gl_Position = vec4(1);\n"
2593 "}\n";
2594 char const *fsSource =
2595 "#version 140\n"
2596 "#extension GL_ARB_separate_shader_objects: require\n"
2597 "#extension GL_ARB_shading_language_420pack: require\n"
2598 "\n"
2599 "void main(){\n"
2600 "}\n";
2601
2602 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2603 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2604
2605 VkPipelineObj pipe(m_device);
2606 pipe.AddShader(&vs);
2607 pipe.AddShader(&fs);
2608
Chia-I Wu08accc62015-07-07 11:50:03 +08002609 /* set up CB 0, not written */
2610 pipe.AddColorAttachment();
2611 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12002612
Chris Forbes4d6d1e52015-05-25 11:13:40 +12002613 VkDescriptorSetObj descriptorSet(m_device);
2614 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002615 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12002616
2617 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06002618 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12002619
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002620 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12002621
Cody Northropd2ad0342015-08-05 11:15:02 -06002622 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes4d6d1e52015-05-25 11:13:40 +12002623 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
2624 FAIL() << "Incorrect error: " << msgString;
2625 }
2626}
2627
Chris Forbesf3fffaa2015-05-25 11:13:43 +12002628TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
2629{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002630 VkFlags msgFlags;
Chris Forbesf3fffaa2015-05-25 11:13:43 +12002631 std::string msgString;
2632 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop50a2a4b2015-06-03 16:49:20 -06002633 ScopedUseGlsl useGlsl(false);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12002634
2635 char const *vsSource =
2636 "#version 140\n"
2637 "#extension GL_ARB_separate_shader_objects: require\n"
2638 "#extension GL_ARB_shading_language_420pack: require\n"
2639 "\n"
2640 "void main(){\n"
2641 " gl_Position = vec4(1);\n"
2642 "}\n";
2643 char const *fsSource =
2644 "#version 140\n"
2645 "#extension GL_ARB_separate_shader_objects: require\n"
2646 "#extension GL_ARB_shading_language_420pack: require\n"
2647 "\n"
2648 "layout(location=0) out vec4 x;\n"
2649 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
2650 "void main(){\n"
2651 " x = vec4(1);\n"
2652 " y = vec4(1);\n"
2653 "}\n";
2654
2655 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2656 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2657
2658 VkPipelineObj pipe(m_device);
2659 pipe.AddShader(&vs);
2660 pipe.AddShader(&fs);
2661
Chia-I Wu08accc62015-07-07 11:50:03 +08002662 /* set up CB 0, not written */
2663 pipe.AddColorAttachment();
2664 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12002665 /* FS writes CB 1, but we don't configure it */
2666
Chris Forbesf3fffaa2015-05-25 11:13:43 +12002667 VkDescriptorSetObj descriptorSet(m_device);
2668 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002669 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12002670
2671 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06002672 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12002673
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002674 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12002675
Cody Northropd2ad0342015-08-05 11:15:02 -06002676 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12002677 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
2678 FAIL() << "Incorrect warning: " << msgString;
2679 }
2680}
2681
Chris Forbesa36d69e2015-05-25 11:13:44 +12002682TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
2683{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002684 VkFlags msgFlags;
Chris Forbesa36d69e2015-05-25 11:13:44 +12002685 std::string msgString;
2686 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop50a2a4b2015-06-03 16:49:20 -06002687 ScopedUseGlsl useGlsl(false);
Chris Forbesa36d69e2015-05-25 11:13:44 +12002688
2689 char const *vsSource =
2690 "#version 140\n"
2691 "#extension GL_ARB_separate_shader_objects: require\n"
2692 "#extension GL_ARB_shading_language_420pack: require\n"
2693 "\n"
2694 "void main(){\n"
2695 " gl_Position = vec4(1);\n"
2696 "}\n";
2697 char const *fsSource =
2698 "#version 140\n"
2699 "#extension GL_ARB_separate_shader_objects: require\n"
2700 "#extension GL_ARB_shading_language_420pack: require\n"
2701 "\n"
2702 "layout(location=0) out ivec4 x;\n" /* not UNORM */
2703 "void main(){\n"
2704 " x = ivec4(1);\n"
2705 "}\n";
2706
2707 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2708 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2709
2710 VkPipelineObj pipe(m_device);
2711 pipe.AddShader(&vs);
2712 pipe.AddShader(&fs);
2713
Chia-I Wu08accc62015-07-07 11:50:03 +08002714 /* set up CB 0; type is UNORM by default */
2715 pipe.AddColorAttachment();
2716 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12002717
Chris Forbesa36d69e2015-05-25 11:13:44 +12002718 VkDescriptorSetObj descriptorSet(m_device);
2719 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002720 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12002721
2722 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06002723 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12002724
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002725 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa36d69e2015-05-25 11:13:44 +12002726
Cody Northropd2ad0342015-08-05 11:15:02 -06002727 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa36d69e2015-05-25 11:13:44 +12002728 if (!strstr(msgString.c_str(),"does not match FS output type")) {
2729 FAIL() << "Incorrect error: " << msgString;
2730 }
2731}
Chris Forbes7b1b8932015-06-05 14:43:36 +12002732
2733TEST_F(VkLayerTest, CreatePipelineNonSpirvShader)
2734{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002735 VkFlags msgFlags;
Chris Forbes7b1b8932015-06-05 14:43:36 +12002736 std::string msgString;
2737 ASSERT_NO_FATAL_FAILURE(InitState());
2738 /* Intentionally provided GLSL rather than compiling to SPIRV first */
Cody Northrop50a2a4b2015-06-03 16:49:20 -06002739 ScopedUseGlsl useGlsl(true);
Chris Forbes7b1b8932015-06-05 14:43:36 +12002740
2741 char const *vsSource =
2742 "#version 140\n"
2743 "#extension GL_ARB_separate_shader_objects: require\n"
2744 "#extension GL_ARB_shading_language_420pack: require\n"
2745 "\n"
2746 "void main(){\n"
2747 " gl_Position = vec4(1);\n"
2748 "}\n";
2749 char const *fsSource =
2750 "#version 140\n"
2751 "#extension GL_ARB_separate_shader_objects: require\n"
2752 "#extension GL_ARB_shading_language_420pack: require\n"
2753 "\n"
2754 "layout(location=0) out vec4 x;\n"
2755 "void main(){\n"
2756 " x = vec4(1);\n"
2757 "}\n";
2758
2759 m_errorMonitor->ClearState();
2760
2761 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2762 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2763
2764
2765 VkPipelineObj pipe(m_device);
2766 pipe.AddShader(&vs);
2767 pipe.AddShader(&fs);
2768
Chia-I Wu08accc62015-07-07 11:50:03 +08002769 /* set up CB 0; type is UNORM by default */
2770 pipe.AddColorAttachment();
2771 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7b1b8932015-06-05 14:43:36 +12002772
Chris Forbes7b1b8932015-06-05 14:43:36 +12002773 VkDescriptorSetObj descriptorSet(m_device);
2774 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002775 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7b1b8932015-06-05 14:43:36 +12002776
Tony Barbour5781e8f2015-08-04 16:23:11 -06002777 VkResult res = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7b1b8932015-06-05 14:43:36 +12002778 /* pipeline creation should have succeeded */
2779 ASSERT_EQ(VK_SUCCESS, res);
2780
2781 /* should have emitted a warning: the shader is not SPIRV, so we're
2782 * not going to be able to analyze it */
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002783 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002784 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes7b1b8932015-06-05 14:43:36 +12002785 if (!strstr(msgString.c_str(),"is not SPIR-V")) {
2786 FAIL() << "Incorrect warning: " << msgString;
2787 }
2788}
Chris Forbesd9b20ca2015-06-04 09:25:25 +12002789#endif
Chris Forbesa36d69e2015-05-25 11:13:44 +12002790
Tony Barbour300a6082015-04-07 13:44:53 -06002791int main(int argc, char **argv) {
2792 int result;
2793
2794 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06002795 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -06002796
2797 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
2798
2799 result = RUN_ALL_TESTS();
2800
Tony Barbour6918cd52015-04-09 12:58:51 -06002801 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -06002802 return result;
2803}