blob: 46dd4d4cd393c5311e5bc1cb568e79b4a34b97d5 [file] [log] [blame]
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001#include <vulkan.h>
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002#include "vk_debug_report_lunarg.h"
Tony Barbour30486ea2015-04-07 13:44:53 -06003#include "gtest-1.7.0/include/gtest/gtest.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06004#include "vkrenderframework.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -06005#include "vk_layer_config.h"
Tony Barbour30486ea2015-04-07 13:44:53 -06006
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05007#define GLM_FORCE_RADIANS
8#include "glm/glm.hpp"
9#include <glm/gtc/matrix_transform.hpp>
10
Tobin Ehlis57e6a612015-05-26 16:11:58 -060011#define MEM_TRACKER_TESTS 1
12#define OBJ_TRACKER_TESTS 1
13#define DRAW_STATE_TESTS 1
14#define THREADING_TESTS 1
Chris Forbes5af3bf22015-05-25 11:13:08 +120015#define SHADER_CHECKER_TESTS 1
Tobin Ehlis57e6a612015-05-26 16:11:58 -060016
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050017//--------------------------------------------------------------------------------------
18// Mesh and VertexFormat Data
19//--------------------------------------------------------------------------------------
20struct Vertex
21{
22 float posX, posY, posZ, posW; // Position data
23 float r, g, b, a; // Color
24};
25
26#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
27
28typedef enum _BsoFailSelect {
29 BsoFailNone = 0x00000000,
Cody Northropf5bd2252015-08-17 11:10:49 -060030 BsoFailRasterLine = 0x00000001,
31 BsoFailRasterDepthBias = 0x00000002,
32 BsoFailViewport = 0x00000004,
33 BsoFailColorBlend = 0x00000008,
34 BsoFailDepthStencil = 0x00000010,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050035} BsoFailSelect;
36
37struct vktriangle_vs_uniform {
38 // Must start with MVP
39 float mvp[4][4];
40 float position[3][4];
41 float color[3][4];
42};
43
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050044static const char bindStateVertShaderText[] =
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050045 "#version 130\n"
46 "vec2 vertices[3];\n"
47 "void main() {\n"
48 " vertices[0] = vec2(-1.0, -1.0);\n"
49 " vertices[1] = vec2( 1.0, -1.0);\n"
50 " vertices[2] = vec2( 0.0, 1.0);\n"
51 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
52 "}\n";
53
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050054static const char bindStateFragShaderText[] =
Cody Northrop74a2d2c2015-06-16 17:32:04 -060055 "#version 140\n"
56 "#extension GL_ARB_separate_shader_objects: require\n"
57 "#extension GL_ARB_shading_language_420pack: require\n"
58 "\n"
59 "layout(location = 0) out vec4 uFragColor;\n"
60 "void main(){\n"
61 " uFragColor = vec4(0,1,0,1);\n"
62 "}\n";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050063
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060064static void myDbgFunc(
Tony Barboure84a8d62015-07-10 14:10:27 -060065 VkFlags msgFlags,
66 VkDbgObjectType objType,
67 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060068 size_t location,
69 int32_t msgCode,
70 const char* pLayerPrefix,
71 const char* pMsg,
72 void* pUserData);
Tony Barbour30486ea2015-04-07 13:44:53 -060073
74class ErrorMonitor {
75public:
Tony Barbour0c1bdc62015-04-29 17:34:29 -060076 ErrorMonitor()
Tony Barbour30486ea2015-04-07 13:44:53 -060077 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060078 test_platform_thread_create_mutex(&m_mutex);
79 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060080 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mike Stroyan09aae812015-05-12 16:00:45 -060081 m_bailout = NULL;
Mike Stroyan7016f4f2015-07-13 14:45:35 -060082 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060083 }
84 void ClearState()
85 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060086 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060087 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -060088 m_msgString.clear();
Mike Stroyan7016f4f2015-07-13 14:45:35 -060089 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060090 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060091 VkFlags GetState(std::string *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -060092 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060093 test_platform_thread_lock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060094 *msgString = m_msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -060095 test_platform_thread_unlock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060096 return m_msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -060097 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060098 void SetState(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -060099 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600100 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600101 if (m_bailout != NULL) {
102 *m_bailout = true;
103 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600104 m_msgFlags = msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600105 m_msgString.reserve(strlen(msgString));
106 m_msgString = msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600107 test_platform_thread_unlock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600108 }
109 void SetBailout(bool *bailout)
110 {
111 m_bailout = bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600112 }
113
114private:
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600115 VkFlags m_msgFlags;
116 std::string m_msgString;
117 test_platform_thread_mutex m_mutex;
118 bool* m_bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600119};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500120
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600121static void myDbgFunc(
122 VkFlags msgFlags,
Tony Barboure84a8d62015-07-10 14:10:27 -0600123 VkDbgObjectType objType,
124 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600125 size_t location,
126 int32_t msgCode,
127 const char* pLayerPrefix,
128 const char* pMsg,
129 void* pUserData)
Tony Barbour30486ea2015-04-07 13:44:53 -0600130{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600131 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour8508b8e2015-04-09 10:48:04 -0600132 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600133 errMonitor->SetState(msgFlags, pMsg);
Tony Barbour8508b8e2015-04-09 10:48:04 -0600134 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600135}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500136
Tony Barbour01999182015-04-09 12:58:51 -0600137class VkLayerTest : public VkRenderFramework
Tony Barbour30486ea2015-04-07 13:44:53 -0600138{
139public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600140 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
141 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500142 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
143 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbour1490c912015-07-28 10:17:20 -0600144 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
145 { GenericDrawPreparation(m_cmdBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600146
Tony Barbour1490c912015-07-28 10:17:20 -0600147 /* Convenience functions that use built-in command buffer */
148 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_cmdBuffer); }
149 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_cmdBuffer); }
150 void Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
151 { m_cmdBuffer->Draw(firstVertex, vertexCount, firstInstance, instanceCount); }
152 void DrawIndexed(uint32_t firstVertex, uint32_t vertexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
153 { m_cmdBuffer->DrawIndexed(firstVertex, vertexCount, vertexOffset,firstInstance, instanceCount); }
154 void QueueCommandBuffer() { m_cmdBuffer->QueueCommandBuffer(); }
155 void QueueCommandBuffer(const VkFence& fence) { m_cmdBuffer->QueueCommandBuffer(fence); }
156 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
157 { m_cmdBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
158 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
159 { m_cmdBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600160protected:
Tony Barbour01999182015-04-09 12:58:51 -0600161 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600162
163 virtual void SetUp() {
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600164 std::vector<const char *> instance_layer_names;
165 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600166 std::vector<const char *> instance_extension_names;
167 std::vector<const char *> device_extension_names;
Tony Barbour950ebc02015-04-23 12:55:36 -0600168
Courtney Goeltzenleuchter846298c2015-07-30 11:32:46 -0600169 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600170 /*
171 * Since CreateDbgMsgCallback is an instance level extension call
172 * any extension / layer that utilizes that feature also needs
173 * to be enabled at create instance time.
174 */
Mike Stroyaned254572015-06-17 16:32:06 -0600175 // Use Threading layer first to protect others from ThreadCmdBufferCollision test
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600176 instance_layer_names.push_back("Threading");
177 instance_layer_names.push_back("ObjectTracker");
178 instance_layer_names.push_back("MemTracker");
179 instance_layer_names.push_back("DrawState");
180 instance_layer_names.push_back("ShaderChecker");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600181
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600182 device_layer_names.push_back("Threading");
183 device_layer_names.push_back("ObjectTracker");
184 device_layer_names.push_back("MemTracker");
185 device_layer_names.push_back("DrawState");
186 device_layer_names.push_back("ShaderChecker");
Tony Barbour30486ea2015-04-07 13:44:53 -0600187
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600188 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -0600189 this->app_info.pNext = NULL;
190 this->app_info.pAppName = "layer_tests";
191 this->app_info.appVersion = 1;
192 this->app_info.pEngineName = "unittest";
193 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600194 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -0600195
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600196 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600197 InitFramework(instance_layer_names, device_layer_names,
198 instance_extension_names, device_extension_names,
199 myDbgFunc, m_errorMonitor);
Tony Barbour30486ea2015-04-07 13:44:53 -0600200 }
201
202 virtual void TearDown() {
203 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600204 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600205 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600206 }
207};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500208
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600209VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600210{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600211 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600212
213 result = cmdBuffer.BeginCommandBuffer();
214
215 /*
216 * For render test all drawing happens in a single render pass
217 * on a single command buffer.
218 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200219 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wuc278df82015-07-07 11:50:03 +0800220 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour30486ea2015-04-07 13:44:53 -0600221 }
222
223 return result;
224}
225
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600226VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600227{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600228 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600229
Chris Forbesfe133ef2015-06-16 14:05:59 +1200230 if (renderPass()) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800231 cmdBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200232 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600233
234 result = cmdBuffer.EndCommandBuffer();
235
236 return result;
237}
238
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500239void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
240{
241 // Create identity matrix
242 int i;
243 struct vktriangle_vs_uniform data;
244
245 glm::mat4 Projection = glm::mat4(1.0f);
246 glm::mat4 View = glm::mat4(1.0f);
247 glm::mat4 Model = glm::mat4(1.0f);
248 glm::mat4 MVP = Projection * View * Model;
249 const int matrixSize = sizeof(MVP);
250 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
251
252 memcpy(&data.mvp, &MVP[0][0], matrixSize);
253
254 static const Vertex tri_data[] =
255 {
256 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
257 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
258 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
259 };
260
261 for (i=0; i<3; i++) {
262 data.position[i][0] = tri_data[i].posX;
263 data.position[i][1] = tri_data[i].posY;
264 data.position[i][2] = tri_data[i].posZ;
265 data.position[i][3] = tri_data[i].posW;
266 data.color[i][0] = tri_data[i].r;
267 data.color[i][1] = tri_data[i].g;
268 data.color[i][2] = tri_data[i].b;
269 data.color[i][3] = tri_data[i].a;
270 }
271
272 ASSERT_NO_FATAL_FAILURE(InitState());
273 ASSERT_NO_FATAL_FAILURE(InitViewport());
274
275 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
276
277 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
278 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
279
280 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800281 pipelineobj.AddColorAttachment();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500282 pipelineobj.AddShader(&vs);
283 pipelineobj.AddShader(&ps);
284
285 VkDescriptorSetObj descriptorSet(m_device);
286 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
287
288 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600289 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500290
Tony Barbour1490c912015-07-28 10:17:20 -0600291 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500292
293 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -0600294 Draw(0, 3, 0, 1);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500295
296 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600297 EndCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500298
Tony Barbour1490c912015-07-28 10:17:20 -0600299 QueueCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500300}
301
302void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
303{
304 if (m_depthStencil->Initialized()) {
305 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
306 } else {
307 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
308 }
309
310 cmdBuffer->PrepareAttachments();
Cody Northropf5bd2252015-08-17 11:10:49 -0600311 if ((failMask & BsoFailRasterLine) != BsoFailRasterLine) {
312 cmdBuffer->BindDynamicRasterLineState(m_stateRasterLine);
313 }
314 if ((failMask & BsoFailRasterDepthBias) != BsoFailRasterDepthBias) {
315 cmdBuffer->BindDynamicRasterDepthBiasState(m_stateRasterDepthBias);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500316 }
317 if ((failMask & BsoFailViewport) != BsoFailViewport) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600318 cmdBuffer->BindDynamicViewportState(m_stateViewport);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500319 }
320 if ((failMask & BsoFailColorBlend) != BsoFailColorBlend) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600321 cmdBuffer->BindDynamicColorBlendState(m_colorBlend);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500322 }
323 if ((failMask & BsoFailDepthStencil) != BsoFailDepthStencil) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600324 cmdBuffer->BindDynamicDepthStencilState(m_stateDepthStencil);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500325 }
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600326 // Make sure depthWriteEnable is set so that DepthStencil fail test will work correctly
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600327 VkStencilOpState stencil = {};
328 stencil.stencilFailOp = VK_STENCIL_OP_KEEP;
329 stencil.stencilPassOp = VK_STENCIL_OP_KEEP;
330 stencil.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
331 stencil.stencilCompareOp = VK_COMPARE_OP_NEVER;
332
333 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
334 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
335 ds_ci.pNext = NULL;
336 ds_ci.depthTestEnable = VK_FALSE;
337 ds_ci.depthWriteEnable = VK_TRUE;
338 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
339 ds_ci.depthBoundsEnable = VK_FALSE;
340 ds_ci.stencilTestEnable = VK_FALSE;
341 ds_ci.front = stencil;
342 ds_ci.back = stencil;
343
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600344 pipelineobj.SetDepthStencil(&ds_ci);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500345 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Tony Barboured132432015-08-04 16:23:11 -0600346 pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500347 cmdBuffer->BindPipeline(pipelineobj);
348 cmdBuffer->BindDescriptorSet(descriptorSet);
349}
350
351// ********************************************************************************************************************
352// ********************************************************************************************************************
353// ********************************************************************************************************************
354// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600355#if MEM_TRACKER_TESTS
Mark Lobodzinski81078192015-05-19 10:28:29 -0500356TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
357{
358 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600359 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500360 std::string msgString;
361
362 VkFenceCreateInfo fenceInfo = {};
363 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
364 fenceInfo.pNext = NULL;
365 fenceInfo.flags = 0;
366
367 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barboure389b882015-07-20 13:00:10 -0600368
369 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
370 vk_testing::Buffer buffer;
371 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500372
Tony Barbour1490c912015-07-28 10:17:20 -0600373 BeginCommandBuffer();
374 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
375 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500376
377 testFence.init(*m_device, fenceInfo);
378
379 // Bypass framework since it does the waits automatically
380 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600381 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500382 ASSERT_VK_SUCCESS( err );
383
384 m_errorMonitor->ClearState();
385 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600386 vkResetCommandBuffer(m_cmdBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500387
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600388 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600389 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling ResetCommandBuffer on an active Command Buffer";
Mark Lobodzinski81078192015-05-19 10:28:29 -0500390 if (!strstr(msgString.c_str(),"Resetting CB")) {
391 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
392 }
393}
394
395TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion)
396{
397 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600398 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500399 std::string msgString;
400
401 VkFenceCreateInfo fenceInfo = {};
402 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
403 fenceInfo.pNext = NULL;
404 fenceInfo.flags = 0;
405
406 ASSERT_NO_FATAL_FAILURE(InitState());
407 ASSERT_NO_FATAL_FAILURE(InitViewport());
408 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
409
Tony Barbour1490c912015-07-28 10:17:20 -0600410 BeginCommandBuffer();
411 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
412 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500413
414 testFence.init(*m_device, fenceInfo);
415
416 // Bypass framework since it does the waits automatically
417 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600418 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500419 ASSERT_VK_SUCCESS( err );
420
421 m_errorMonitor->ClearState();
422 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600423 BeginCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500424
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600425 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600426 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling BeginCommandBuffer on an active Command Buffer";
Mark Lobodzinski81078192015-05-19 10:28:29 -0500427 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
428 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
429 }
430}
431
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500432TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
433{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600434 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500435 std::string msgString;
436 VkResult err;
437
438 ASSERT_NO_FATAL_FAILURE(InitState());
439 m_errorMonitor->ClearState();
440
441 // Create an image, allocate memory, free it, and then try to bind it
442 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500443 VkDeviceMemory mem;
444 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500445
446 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
447 const int32_t tex_width = 32;
448 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500449
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600450 VkImageCreateInfo image_create_info = {};
451 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
452 image_create_info.pNext = NULL;
453 image_create_info.imageType = VK_IMAGE_TYPE_2D;
454 image_create_info.format = tex_format;
455 image_create_info.extent.width = tex_width;
456 image_create_info.extent.height = tex_height;
457 image_create_info.extent.depth = 1;
458 image_create_info.mipLevels = 1;
459 image_create_info.arraySize = 1;
460 image_create_info.samples = 1;
461 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
462 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
463 image_create_info.flags = 0;
464
465 VkMemoryAllocInfo mem_alloc = {};
466 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
467 mem_alloc.pNext = NULL;
468 mem_alloc.allocationSize = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500469 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600470 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500471
472 err = vkCreateImage(m_device->device(), &image_create_info, &image);
473 ASSERT_VK_SUCCESS(err);
474
Tony Barboure84a8d62015-07-10 14:10:27 -0600475 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500476 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500477 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500478 ASSERT_VK_SUCCESS(err);
479
Mark Lobodzinski23182612015-05-29 09:32:35 -0500480 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500481
Mike Stroyand72da752015-08-04 10:49:29 -0600482 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tony Barbour49a3b652015-08-04 16:13:01 -0600483 if(err != VK_SUCCESS) // If we can't find any unmappable memory this test doesn't make sense
484 return;
Mike Stroyand72da752015-08-04 10:49:29 -0600485
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500486 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500487 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500488 ASSERT_VK_SUCCESS(err);
489
490 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600491 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500492 ASSERT_VK_SUCCESS(err);
493
494 // Map memory as if to initialize the image
495 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500496 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500497
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600498 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600499 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to map memory not visible to CPU";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500500 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
501 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
502 }
503}
504
505TEST_F(VkLayerTest, BindInvalidMemory)
506{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600507 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500508 std::string msgString;
509 VkResult err;
510
511 ASSERT_NO_FATAL_FAILURE(InitState());
512 m_errorMonitor->ClearState();
513
514 // Create an image, allocate memory, free it, and then try to bind it
515 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500516 VkDeviceMemory mem;
517 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500518
519 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
520 const int32_t tex_width = 32;
521 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500522
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600523 VkImageCreateInfo image_create_info = {};
524 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
525 image_create_info.pNext = NULL;
526 image_create_info.imageType = VK_IMAGE_TYPE_2D;
527 image_create_info.format = tex_format;
528 image_create_info.extent.width = tex_width;
529 image_create_info.extent.height = tex_height;
530 image_create_info.extent.depth = 1;
531 image_create_info.mipLevels = 1;
532 image_create_info.arraySize = 1;
533 image_create_info.samples = 1;
534 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
535 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
536 image_create_info.flags = 0;
537
538 VkMemoryAllocInfo mem_alloc = {};
539 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
540 mem_alloc.pNext = NULL;
541 mem_alloc.allocationSize = 0;
542 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500543
544 err = vkCreateImage(m_device->device(), &image_create_info, &image);
545 ASSERT_VK_SUCCESS(err);
546
Tony Barboure84a8d62015-07-10 14:10:27 -0600547 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500548 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500549 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500550 ASSERT_VK_SUCCESS(err);
551
Mark Lobodzinski23182612015-05-29 09:32:35 -0500552 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500553
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800554 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600555 ASSERT_VK_SUCCESS(err);
556
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500557 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500558 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500559 ASSERT_VK_SUCCESS(err);
560
561 // Introduce validation failure, free memory before binding
Mark Lobodzinski23182612015-05-29 09:32:35 -0500562 vkFreeMemory(m_device->device(), mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500563 ASSERT_VK_SUCCESS(err);
564
565 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600566 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Cody Northrop87333892015-08-06 12:40:01 -0600567 // This may very well return an error.
568 (void)err;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500569
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600570 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600571 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to bind a freed memory object";
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500572 if (!strstr(msgString.c_str(),"couldn't find info for mem obj")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500573 FAIL() << "Error received did not match expected error message from BindObjectMemory in MemTracker";
574 }
575}
576
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600577// TODO : Is this test still valid. Not sure it is with updates to memory binding model
578// Verify and delete the test of fix the check
579//TEST_F(VkLayerTest, FreeBoundMemory)
580//{
581// VkFlags msgFlags;
582// std::string msgString;
583// VkResult err;
584//
585// ASSERT_NO_FATAL_FAILURE(InitState());
586// m_errorMonitor->ClearState();
587//
588// // Create an image, allocate memory, free it, and then try to bind it
589// VkImage image;
590// VkDeviceMemory mem;
591// VkMemoryRequirements mem_reqs;
592//
593// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
594// const int32_t tex_width = 32;
595// const int32_t tex_height = 32;
596//
597// const VkImageCreateInfo image_create_info = {
598// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
599// .pNext = NULL,
600// .imageType = VK_IMAGE_TYPE_2D,
601// .format = tex_format,
602// .extent = { tex_width, tex_height, 1 },
603// .mipLevels = 1,
604// .arraySize = 1,
605// .samples = 1,
606// .tiling = VK_IMAGE_TILING_LINEAR,
607// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
608// .flags = 0,
609// };
610// VkMemoryAllocInfo mem_alloc = {
611// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
612// .pNext = NULL,
613// .allocationSize = 0,
614// .memoryTypeIndex = 0,
615// };
616//
617// err = vkCreateImage(m_device->device(), &image_create_info, &image);
618// ASSERT_VK_SUCCESS(err);
619//
620// err = vkGetImageMemoryRequirements(m_device->device(),
621// image,
622// &mem_reqs);
623// ASSERT_VK_SUCCESS(err);
624//
625// mem_alloc.allocationSize = mem_reqs.size;
626//
627// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
628// ASSERT_VK_SUCCESS(err);
629//
630// // allocate memory
631// err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
632// ASSERT_VK_SUCCESS(err);
633//
634// // Bind memory to Image object
635// err = vkBindImageMemory(m_device->device(), image, mem, 0);
636// ASSERT_VK_SUCCESS(err);
637//
638// // Introduce validation failure, free memory while still bound to object
639// vkFreeMemory(m_device->device(), mem);
640// ASSERT_VK_SUCCESS(err);
641//
642// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600643// ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an warning while tring to free bound memory";
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600644// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
645// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
646// }
647//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500648
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500649TEST_F(VkLayerTest, RebindMemory)
650{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600651 VkFlags msgFlags;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500652 std::string msgString;
653 VkResult err;
654
655 ASSERT_NO_FATAL_FAILURE(InitState());
656 m_errorMonitor->ClearState();
657
658 // Create an image, allocate memory, free it, and then try to bind it
659 VkImage image;
660 VkDeviceMemory mem1;
661 VkDeviceMemory mem2;
662 VkMemoryRequirements mem_reqs;
663
664 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
665 const int32_t tex_width = 32;
666 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500667
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600668 VkImageCreateInfo image_create_info = {};
669 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
670 image_create_info.pNext = NULL;
671 image_create_info.imageType = VK_IMAGE_TYPE_2D;
672 image_create_info.format = tex_format;
673 image_create_info.extent.width = tex_width;
674 image_create_info.extent.height = tex_height;
675 image_create_info.extent.depth = 1;
676 image_create_info.mipLevels = 1;
677 image_create_info.arraySize = 1;
678 image_create_info.samples = 1;
679 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
680 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
681 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500682
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600683 VkMemoryAllocInfo mem_alloc = {};
684 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
685 mem_alloc.pNext = NULL;
686 mem_alloc.allocationSize = 0;
687 mem_alloc.memoryTypeIndex = 0;
688
689 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
690 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500691 err = vkCreateImage(m_device->device(), &image_create_info, &image);
692 ASSERT_VK_SUCCESS(err);
693
Tony Barboure84a8d62015-07-10 14:10:27 -0600694 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500695 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500696 &mem_reqs);
697 ASSERT_VK_SUCCESS(err);
698
699 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800700 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600701 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500702
703 // allocate 2 memory objects
704 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
705 ASSERT_VK_SUCCESS(err);
706 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
707 ASSERT_VK_SUCCESS(err);
708
709 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600710 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500711 ASSERT_VK_SUCCESS(err);
712
713 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600714 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500715 ASSERT_VK_SUCCESS(err);
716
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600717 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600718 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to rebind an object";
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500719 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
720 FAIL() << "Error received did not match expected message when rebinding memory to an object";
721 }
722}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500723
724TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
725{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600726 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500727 std::string msgString;
728 VkResult err;
729
730 ASSERT_NO_FATAL_FAILURE(InitState());
731 m_errorMonitor->ClearState();
732
733 // Create an image object, allocate memory, destroy the object and then try to bind it
734 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500735 VkDeviceMemory mem;
736 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500737
738 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
739 const int32_t tex_width = 32;
740 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500741
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600742 VkImageCreateInfo image_create_info = {};
743 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
744 image_create_info.pNext = NULL;
745 image_create_info.imageType = VK_IMAGE_TYPE_2D;
746 image_create_info.format = tex_format;
747 image_create_info.extent.width = tex_width;
748 image_create_info.extent.height = tex_height;
749 image_create_info.extent.depth = 1;
750 image_create_info.mipLevels = 1;
751 image_create_info.arraySize = 1;
752 image_create_info.samples = 1;
753 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
754 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
755 image_create_info.flags = 0;
756
757 VkMemoryAllocInfo mem_alloc = {};
758 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
759 mem_alloc.pNext = NULL;
760 mem_alloc.allocationSize = 0;
761 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500762
763 err = vkCreateImage(m_device->device(), &image_create_info, &image);
764 ASSERT_VK_SUCCESS(err);
765
Tony Barboure84a8d62015-07-10 14:10:27 -0600766 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500767 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500768 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500769 ASSERT_VK_SUCCESS(err);
770
Mark Lobodzinski23182612015-05-29 09:32:35 -0500771 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800772 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600773 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500774
775 // Allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500776 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500777 ASSERT_VK_SUCCESS(err);
778
779 // Introduce validation failure, destroy Image object before binding
Tony Barboure84a8d62015-07-10 14:10:27 -0600780 vkDestroyImage(m_device->device(), image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500781 ASSERT_VK_SUCCESS(err);
782
Mike Stroyand72da752015-08-04 10:49:29 -0600783 // Now Try to bind memory to this destroyed object
Tony Barboure84a8d62015-07-10 14:10:27 -0600784 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mike Stroyand72da752015-08-04 10:49:29 -0600785 // This may very well return an error.
786 (void) err;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500787
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600788 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600789 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while binding memory to a destroyed object";
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500790 if (!strstr(msgString.c_str(),"that's not in global list")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500791 FAIL() << "Error received did not match expected error message from updateObjectBinding in MemTracker";
792 }
793}
794
Tony Barbour8508b8e2015-04-09 10:48:04 -0600795TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600796{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600797 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600798 VkFlags msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600799 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600800
801 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600802 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
803 fenceInfo.pNext = NULL;
804 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600805
Tony Barbour30486ea2015-04-07 13:44:53 -0600806 ASSERT_NO_FATAL_FAILURE(InitState());
807 ASSERT_NO_FATAL_FAILURE(InitViewport());
808 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
809
Tony Barbour1490c912015-07-28 10:17:20 -0600810 BeginCommandBuffer();
811 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
812 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600813
814 testFence.init(*m_device, fenceInfo);
815 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -0600816 QueueCommandBuffer(testFence.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600817 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600818 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 Barbour8508b8e2015-04-09 10:48:04 -0600819 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500820 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600821 }
822
823}
824
825TEST_F(VkLayerTest, ResetUnsignaledFence)
826{
827 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600828 VkFlags msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600829 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600830 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600831 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
832 fenceInfo.pNext = NULL;
833
Tony Barbour8508b8e2015-04-09 10:48:04 -0600834 ASSERT_NO_FATAL_FAILURE(InitState());
835 testFence.init(*m_device, fenceInfo);
836 m_errorMonitor->ClearState();
Chia-I Wua4992342015-07-03 11:45:55 +0800837 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600838 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600839 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600840 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from submitting fence with UNSIGNALED state to vkResetFences";
Tony Barbour01999182015-04-09 12:58:51 -0600841 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500842 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600843 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600844
845}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600846
Chia-I Wuc278df82015-07-07 11:50:03 +0800847/* TODO: Update for changes due to bug-14075 tiling across render passes */
848#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600849TEST_F(VkLayerTest, InvalidUsageBits)
850{
851 // Initiate Draw w/o a PSO bound
852 VkFlags msgFlags;
853 std::string msgString;
854
855 ASSERT_NO_FATAL_FAILURE(InitState());
856 m_errorMonitor->ClearState();
857 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600858 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600859
860 const VkExtent3D e3d = {
861 .width = 128,
862 .height = 128,
863 .depth = 1,
864 };
865 const VkImageCreateInfo ici = {
866 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
867 .pNext = NULL,
868 .imageType = VK_IMAGE_TYPE_2D,
869 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
870 .extent = e3d,
871 .mipLevels = 1,
872 .arraySize = 1,
873 .samples = 1,
874 .tiling = VK_IMAGE_TILING_LINEAR,
875 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_BIT
876 .flags = 0,
877 };
878
879 VkImage dsi;
880 vkCreateImage(m_device->device(), &ici, &dsi);
881 VkDepthStencilView dsv;
882 const VkDepthStencilViewCreateInfo dsvci = {
883 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
884 .pNext = NULL,
885 .image = dsi,
886 .mipLevel = 0,
887 .baseArraySlice = 0,
888 .arraySize = 1,
889 .flags = 0,
890 };
891 vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv);
892 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600893 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 Ehlisd94ba722015-07-03 08:45:14 -0600894 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
895 FAIL() << "Error received was not 'Invalid usage flag for image...'";
896 }
897}
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600898#endif
Chia-I Wuc278df82015-07-07 11:50:03 +0800899#endif
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600900#if OBJ_TRACKER_TESTS
Cody Northropf5bd2252015-08-17 11:10:49 -0600901TEST_F(VkLayerTest, RasterLineStateNotBound)
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500902{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600903 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500904 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600905 ASSERT_NO_FATAL_FAILURE(InitState());
906 m_errorMonitor->ClearState();
Cody Northropf5bd2252015-08-17 11:10:49 -0600907 TEST_DESCRIPTION("Simple Draw Call that validates failure when a raster line state object is not bound beforehand");
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500908
Cody Northropf5bd2252015-08-17 11:10:49 -0600909 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailRasterLine);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500910
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600911 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropf5bd2252015-08-17 11:10:49 -0600912 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Raster Line State Object";
913 if (!strstr(msgString.c_str(),"Raster line object not bound to this command buffer")) {
914 FAIL() << "Error received was not 'Raster line object not bound to this command buffer'";
915 }
916}
917
918TEST_F(VkLayerTest, RasterDepthBiasStateNotBound)
919{
920 VkFlags msgFlags;
921 std::string msgString;
922 ASSERT_NO_FATAL_FAILURE(InitState());
923 m_errorMonitor->ClearState();
924 TEST_DESCRIPTION("Simple Draw Call that validates failure when a raster depth bias state object is not bound beforehand");
925
926 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailRasterDepthBias);
927
928 msgFlags = m_errorMonitor->GetState(&msgString);
929 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Raster Depth Bias State Object";
930 if (!strstr(msgString.c_str(),"Raster depth bias object not bound to this command buffer")) {
931 FAIL() << "Error received was not 'Raster depth bias object not bound to this command buffer'";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500932 }
933}
934
935TEST_F(VkLayerTest, ViewportStateNotBound)
936{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600937 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500938 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600939 ASSERT_NO_FATAL_FAILURE(InitState());
940 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500941 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
942
943 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
944
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600945 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600946 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500947 if (!strstr(msgString.c_str(),"Viewport object not bound to this command buffer")) {
948 FAIL() << "Error received was not 'Viewport object not bound to this command buffer'";
949 }
950}
951
952TEST_F(VkLayerTest, ColorBlendStateNotBound)
953{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600954 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500955 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600956 ASSERT_NO_FATAL_FAILURE(InitState());
957 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500958 TEST_DESCRIPTION("Simple Draw Call that validates failure when a color-blend state object is not bound beforehand");
959
960 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailColorBlend);
961
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600962 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600963 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a ColorBlend State Object";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500964 if (!strstr(msgString.c_str(),"Color-blend object not bound to this command buffer")) {
965 FAIL() << "Error received was not 'Color-blend object not bound to this command buffer'";
966 }
967}
968
969TEST_F(VkLayerTest, DepthStencilStateNotBound)
970{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600971 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500972 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600973 ASSERT_NO_FATAL_FAILURE(InitState());
974 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500975 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth-stencil state object is not bound beforehand");
976
977 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthStencil);
978
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600979 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600980 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a DepthStencil State Object";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500981 if (!strstr(msgString.c_str(),"Depth-stencil object not bound to this command buffer")) {
982 FAIL() << "Error received was not 'Depth-stencil object not bound to this command buffer'";
983 }
Tony Barbourdb686622015-05-06 09:35:56 -0600984}
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600985#endif
986#if DRAW_STATE_TESTS
Tobin Ehlis0cea4082015-08-18 07:10:58 -0600987TEST_F(VkLayerTest, CmdBufferTwoSubmits)
988{
989 vk_testing::Fence testFence;
990 VkFlags msgFlags;
991 std::string msgString;
992
993 VkFenceCreateInfo fenceInfo = {};
994 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
995 fenceInfo.pNext = NULL;
996 fenceInfo.flags = 0;
997
998 ASSERT_NO_FATAL_FAILURE(InitState());
999 ASSERT_NO_FATAL_FAILURE(InitViewport());
1000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1001
1002 // We luck out b/c by default the framework creates CB w/ the VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set
1003 BeginCommandBuffer();
1004 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
1005 EndCommandBuffer();
1006
1007 testFence.init(*m_device, fenceInfo);
1008
1009 // Bypass framework since it does the waits automatically
1010 VkResult err = VK_SUCCESS;
1011 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
1012 ASSERT_VK_SUCCESS( err );
1013
1014 m_errorMonitor->ClearState();
1015 // Cause validation error by re-submitting cmd buffer that should only be submitted once
1016 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
1017 ASSERT_VK_SUCCESS( err );
1018
1019 msgFlags = m_errorMonitor->GetState(&msgString);
1020 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 Ehlis7f7b4422015-08-18 14:24:32 -06001021 if (!strstr(msgString.c_str(),"was begun w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set, but has been submitted")) {
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001022 FAIL() << "Error received was not 'CB (0xaddress) was created w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set...'";
1023 }
1024}
1025
1026
Tobin Ehlise4076782015-06-24 15:53:07 -06001027TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001028{
1029 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001030 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001031 std::string msgString;
1032
1033 ASSERT_NO_FATAL_FAILURE(InitState());
1034 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001035 BeginCommandBuffer();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001036 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Tony Barbour1490c912015-07-28 10:17:20 -06001037 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001038 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001039 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding pipeline to CmdBuffer w/o active RenderPass";
Tobin Ehlise4076782015-06-24 15:53:07 -06001040 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
1041 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0xbaadb1be) without an active RenderPass'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001042 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001043}
1044
1045TEST_F(VkLayerTest, InvalidDescriptorPool)
1046{
1047 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1048 // The DS check for this is after driver has been called to validate DS internal data struct
1049 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001050/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001051 std::string msgString;
1052 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1053 vkResetDescriptorPool(device(), badPool);
1054
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001055 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001056 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Resetting an invalid DescriptorPool Object";
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001057 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1058 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1059 }*/
1060}
1061
1062TEST_F(VkLayerTest, InvalidDescriptorSet)
1063{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001064 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1065 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001066 // Create a valid cmd buffer
1067 // call vkCmdBindDescriptorSets w/ false DS
1068}
1069
1070TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1071{
1072 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1073 // The DS check for this is after driver has been called to validate DS internal data struct
1074}
1075
1076TEST_F(VkLayerTest, InvalidPipeline)
1077{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001078 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1079 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001080 // Create a valid cmd buffer
1081 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -06001082// VkFlags msgFlags;
1083// std::string msgString;
1084//
1085// ASSERT_NO_FATAL_FAILURE(InitState());
1086// m_errorMonitor->ClearState();
1087// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001088// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001089// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1090// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1091// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001092// ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Tobin Ehlise4076782015-06-24 15:53:07 -06001093// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1094// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1095// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001096}
1097
Tobin Ehlis254eca02015-06-25 15:46:59 -06001098TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001099{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001100 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001101 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001102 std::string msgString;
1103 VkResult err;
1104
1105 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001106 ASSERT_NO_FATAL_FAILURE(InitViewport());
1107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001108 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001109 VkDescriptorTypeCount ds_type_count = {};
1110 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1111 ds_type_count.count = 1;
1112
1113 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1114 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1115 ds_pool_ci.pNext = NULL;
1116 ds_pool_ci.count = 1;
1117 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001118
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001119 VkDescriptorPool ds_pool;
1120 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1121 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001122
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001123 VkDescriptorSetLayoutBinding dsl_binding = {};
1124 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1125 dsl_binding.arraySize = 1;
1126 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1127 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001128
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001129 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1130 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1131 ds_layout_ci.pNext = NULL;
1132 ds_layout_ci.count = 1;
1133 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001134 VkDescriptorSetLayout ds_layout;
1135 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1136 ASSERT_VK_SUCCESS(err);
1137
1138 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001139 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001140 ASSERT_VK_SUCCESS(err);
1141
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001142 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1143 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1144 pipeline_layout_ci.pNext = NULL;
1145 pipeline_layout_ci.descriptorSetCount = 1;
1146 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001147
1148 VkPipelineLayout pipeline_layout;
1149 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1150 ASSERT_VK_SUCCESS(err);
1151
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001152 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001153 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1154 // but add it to be able to run on more devices
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001155
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001156 VkPipelineObj pipe(m_device);
1157 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001158 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001159 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001160
1161 BeginCommandBuffer();
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001162 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbour1490c912015-07-28 10:17:20 -06001163 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001164
Tobin Ehlis254eca02015-06-25 15:46:59 -06001165 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001166 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not warn after binding a DescriptorSet that was never updated.";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001167 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1168 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1169 }
1170}
1171
1172TEST_F(VkLayerTest, NoBeginCmdBuffer)
1173{
1174 VkFlags msgFlags;
1175 std::string msgString;
1176
1177 ASSERT_NO_FATAL_FAILURE(InitState());
1178 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001179 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001180 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1181 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1182 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001183 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after ending a CmdBuffer w/o calling BeginCommandBuffer()";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001184 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1185 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1186 }
1187}
1188
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001189TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1190{
1191 VkFlags msgFlags;
1192 std::string msgString;
1193
1194 ASSERT_NO_FATAL_FAILURE(InitState());
1195 m_errorMonitor->ClearState();
1196
1197 // Calls CreateCommandBuffer
1198 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1199
1200 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northrop10d8f982015-08-04 17:35:57 -06001201 VkCmdBufferBeginInfo cmd_buf_info = {};
1202 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1203 cmd_buf_info.pNext = NULL;
1204 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1205 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1206 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1207 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1208
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001209
1210 // The error should be caught by validation of the BeginCommandBuffer call
1211 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1212
1213 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001214 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error passing a non-NULL Framebuffer and Renderpass to BeginCommandBuffer()";
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001215 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1216 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1217 }
1218}
1219
1220TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1221{
1222 VkFlags msgFlags;
1223 std::string msgString;
1224 VkResult err;
1225 VkCmdBuffer draw_cmd;
1226 VkCmdPool cmd_pool;
1227
1228 ASSERT_NO_FATAL_FAILURE(InitState());
1229 m_errorMonitor->ClearState();
1230
Cody Northrop10d8f982015-08-04 17:35:57 -06001231 VkCmdBufferCreateInfo cmd = {};
1232 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1233 cmd.pNext = NULL;
1234 cmd.cmdPool = m_cmdPool;
1235 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1236 cmd.flags = 0;
1237
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001238 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
1239 assert(!err);
1240
1241 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northrop10d8f982015-08-04 17:35:57 -06001242 VkCmdBufferBeginInfo cmd_buf_info = {};
1243 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1244 cmd_buf_info.pNext = NULL;
1245 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1246 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001247
1248 // The error should be caught by validation of the BeginCommandBuffer call
1249 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1250
1251 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001252 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error passing NULL Framebuffer/Renderpass to BeginCommandBuffer()";
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001253 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1254 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1255 }
1256}
1257
Tobin Ehlis254eca02015-06-25 15:46:59 -06001258TEST_F(VkLayerTest, InvalidPipelineCreateState)
1259{
1260 // Attempt to Create Gfx Pipeline w/o a VS
1261 VkFlags msgFlags;
1262 std::string msgString;
1263 VkResult err;
1264
1265 ASSERT_NO_FATAL_FAILURE(InitState());
1266 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001267
1268 VkDescriptorTypeCount ds_type_count = {};
1269 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1270 ds_type_count.count = 1;
1271
1272 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1273 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1274 ds_pool_ci.pNext = NULL;
1275 ds_pool_ci.count = 1;
1276 ds_pool_ci.pTypeCount = &ds_type_count;
1277
Tobin Ehlis254eca02015-06-25 15:46:59 -06001278 VkDescriptorPool ds_pool;
1279 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1280 ASSERT_VK_SUCCESS(err);
1281
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001282 VkDescriptorSetLayoutBinding dsl_binding = {};
1283 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1284 dsl_binding.arraySize = 1;
1285 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1286 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001287
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001288 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1289 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1290 ds_layout_ci.pNext = NULL;
1291 ds_layout_ci.count = 1;
1292 ds_layout_ci.pBinding = &dsl_binding;
1293
Tobin Ehlis254eca02015-06-25 15:46:59 -06001294 VkDescriptorSetLayout ds_layout;
1295 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1296 ASSERT_VK_SUCCESS(err);
1297
1298 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001299 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001300 ASSERT_VK_SUCCESS(err);
1301
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001302 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1303 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1304 pipeline_layout_ci.pNext = NULL;
1305 pipeline_layout_ci.descriptorSetCount = 1;
1306 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001307
1308 VkPipelineLayout pipeline_layout;
1309 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1310 ASSERT_VK_SUCCESS(err);
1311
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001312 VkGraphicsPipelineCreateInfo gp_ci = {};
1313 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1314 gp_ci.pNext = NULL;
1315 gp_ci.stageCount = 0;
1316 gp_ci.pStages = NULL;
1317 gp_ci.pVertexInputState = NULL;
1318 gp_ci.pInputAssemblyState = NULL;
1319 gp_ci.pTessellationState = NULL;
1320 gp_ci.pViewportState = NULL;
1321 gp_ci.pRasterState = NULL;
1322 gp_ci.pMultisampleState = NULL;
1323 gp_ci.pDepthStencilState = NULL;
1324 gp_ci.pColorBlendState = NULL;
1325 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1326 gp_ci.layout = pipeline_layout;
1327
1328 VkPipelineCacheCreateInfo pc_ci = {};
1329 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1330 pc_ci.pNext = NULL;
1331 pc_ci.initialSize = 0;
1332 pc_ci.initialData = 0;
1333 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001334
1335 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001336 VkPipelineCache pipelineCache;
1337
1338 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1339 ASSERT_VK_SUCCESS(err);
1340 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001341
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001342 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001343 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o VS.";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001344 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1345 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1346 }
1347}
1348
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001349TEST_F(VkLayerTest, NullRenderPass)
1350{
1351 // Bind a NULL 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 Ehlisb8b06b52015-06-25 16:27:19 -06001358
Tony Barbour1490c912015-07-28 10:17:20 -06001359 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001360 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06001361 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001362
1363 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001364 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001365 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
1366 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
1367 }
1368}
1369
Tobin Ehlis254eca02015-06-25 15:46:59 -06001370TEST_F(VkLayerTest, RenderPassWithinRenderPass)
1371{
1372 // Bind a BeginRenderPass within an active RenderPass
1373 VkFlags msgFlags;
1374 std::string msgString;
1375
1376 ASSERT_NO_FATAL_FAILURE(InitState());
1377 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1378 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001379
Tony Barbour1490c912015-07-28 10:17:20 -06001380 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001381 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001382 VkRenderPassBeginInfo rp_begin = {};
1383 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
1384 rp_begin.pNext = NULL;
1385 rp_begin.renderPass = (VkRenderPass)0xc001d00d;
1386 rp_begin.framebuffer = 0;
1387
Tony Barbour1490c912015-07-28 10:17:20 -06001388 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001389
1390 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001391 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding RenderPass w/i an active RenderPass.";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001392 if (!strstr(msgString.c_str(),"Cannot call vkCmdBeginRenderPass() during an active RenderPass ")) {
1393 FAIL() << "Error received was not 'Cannot call vkCmdBeginRenderPass() during an active RenderPass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001394 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001395}
1396
1397TEST_F(VkLayerTest, InvalidDynamicStateObject)
1398{
1399 // Create a valid cmd buffer
1400 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001401 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1402 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001403}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06001404
Tobin Ehlise4076782015-06-24 15:53:07 -06001405TEST_F(VkLayerTest, VtxBufferNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001406{
1407 // Bind VBO out-of-bounds for given PSO
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001408 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001409 std::string msgString;
1410 VkResult err;
1411
1412 ASSERT_NO_FATAL_FAILURE(InitState());
1413 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001414
1415 VkDescriptorTypeCount ds_type_count = {};
1416 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1417 ds_type_count.count = 1;
1418
1419 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1420 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1421 ds_pool_ci.pNext = NULL;
1422 ds_pool_ci.count = 1;
1423 ds_pool_ci.pTypeCount = &ds_type_count;
1424
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001425 VkDescriptorPool ds_pool;
1426 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1427 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001428
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001429 VkDescriptorSetLayoutBinding dsl_binding = {};
1430 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1431 dsl_binding.arraySize = 1;
1432 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1433 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001434
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001435 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1436 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1437 ds_layout_ci.pNext = NULL;
1438 ds_layout_ci.count = 1;
1439 ds_layout_ci.pBinding = &dsl_binding;
1440
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001441 VkDescriptorSetLayout ds_layout;
1442 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1443 ASSERT_VK_SUCCESS(err);
1444
1445 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001446 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001447 ASSERT_VK_SUCCESS(err);
1448
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001449 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1450 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1451 pipeline_layout_ci.pNext = NULL;
1452 pipeline_layout_ci.descriptorSetCount = 1;
1453 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001454
1455 VkPipelineLayout pipeline_layout;
1456 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1457 ASSERT_VK_SUCCESS(err);
1458
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001459 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001460 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1461 // but add it to be able to run on more devices
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001462 VkPipelineObj pipe(m_device);
1463 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001464 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001465 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001466
Tony Barbour1490c912015-07-28 10:17:20 -06001467 BeginCommandBuffer();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001468 ASSERT_VK_SUCCESS(err);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001469 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001470 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06001471 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001472
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001473 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001474 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
Tobin Ehlise4076782015-06-24 15:53:07 -06001475 if (!strstr(msgString.c_str(),"Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.")) {
1476 FAIL() << "Error received was not 'Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001477 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001478}
1479
1480TEST_F(VkLayerTest, DSTypeMismatch)
1481{
1482 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001483 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001484 std::string msgString;
1485 VkResult err;
1486
1487 ASSERT_NO_FATAL_FAILURE(InitState());
1488 m_errorMonitor->ClearState();
1489 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001490 VkDescriptorTypeCount ds_type_count = {};
1491 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1492 ds_type_count.count = 1;
1493
1494 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1495 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1496 ds_pool_ci.pNext = NULL;
1497 ds_pool_ci.count = 1;
1498 ds_pool_ci.pTypeCount = &ds_type_count;
1499
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001500 VkDescriptorPool ds_pool;
1501 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1502 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001503 VkDescriptorSetLayoutBinding dsl_binding = {};
1504 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1505 dsl_binding.arraySize = 1;
1506 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1507 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001508
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001509 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1510 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1511 ds_layout_ci.pNext = NULL;
1512 ds_layout_ci.count = 1;
1513 ds_layout_ci.pBinding = &dsl_binding;
1514
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001515 VkDescriptorSetLayout ds_layout;
1516 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1517 ASSERT_VK_SUCCESS(err);
1518
1519 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001520 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001521 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001522
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001523 VkSamplerCreateInfo sampler_ci = {};
1524 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1525 sampler_ci.pNext = NULL;
1526 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1527 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1528 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1529 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1530 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1531 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1532 sampler_ci.mipLodBias = 1.0;
1533 sampler_ci.maxAnisotropy = 1;
1534 sampler_ci.compareEnable = VK_FALSE;
1535 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1536 sampler_ci.minLod = 1.0;
1537 sampler_ci.maxLod = 1.0;
1538 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northrop0bf4e1d2015-08-11 15:50:55 -06001539 sampler_ci.texelCoords = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001540
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001541 VkSampler sampler;
1542 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1543 ASSERT_VK_SUCCESS(err);
1544
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001545 VkDescriptorInfo descriptor_info;
1546 memset(&descriptor_info, 0, sizeof(descriptor_info));
1547 descriptor_info.sampler = sampler;
1548
1549 VkWriteDescriptorSet descriptor_write;
1550 memset(&descriptor_write, 0, sizeof(descriptor_write));
1551 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1552 descriptor_write.destSet = descriptorSet;
1553 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001554 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001555 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1556 descriptor_write.pDescriptors = &descriptor_info;
1557
1558 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1559
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001560 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001561 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating BUFFER Descriptor w/ incorrect type of SAMPLER.";
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001562 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) {
1563 FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match overlapping binding type!'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001564 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001565}
1566
1567TEST_F(VkLayerTest, DSUpdateOutOfBounds)
1568{
1569 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001570 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001571 std::string msgString;
1572 VkResult err;
1573
1574 ASSERT_NO_FATAL_FAILURE(InitState());
1575 m_errorMonitor->ClearState();
1576 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001577 VkDescriptorTypeCount ds_type_count = {};
1578 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1579 ds_type_count.count = 1;
1580
1581 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1582 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1583 ds_pool_ci.pNext = NULL;
1584 ds_pool_ci.count = 1;
1585 ds_pool_ci.pTypeCount = &ds_type_count;
1586
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001587 VkDescriptorPool ds_pool;
1588 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1589 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001590
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001591 VkDescriptorSetLayoutBinding dsl_binding = {};
1592 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1593 dsl_binding.arraySize = 1;
1594 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1595 dsl_binding.pImmutableSamplers = NULL;
1596
1597 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1598 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1599 ds_layout_ci.pNext = NULL;
1600 ds_layout_ci.count = 1;
1601 ds_layout_ci.pBinding = &dsl_binding;
1602
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001603 VkDescriptorSetLayout ds_layout;
1604 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1605 ASSERT_VK_SUCCESS(err);
1606
1607 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001608 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001609 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001610
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001611 VkSamplerCreateInfo sampler_ci = {};
1612 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1613 sampler_ci.pNext = NULL;
1614 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1615 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1616 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1617 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1618 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1619 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1620 sampler_ci.mipLodBias = 1.0;
1621 sampler_ci.maxAnisotropy = 1;
1622 sampler_ci.compareEnable = VK_FALSE;
1623 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1624 sampler_ci.minLod = 1.0;
1625 sampler_ci.maxLod = 1.0;
1626 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northrop0bf4e1d2015-08-11 15:50:55 -06001627 sampler_ci.texelCoords = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001628
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001629 VkSampler sampler;
1630 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1631 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001632
1633 VkDescriptorInfo descriptor_info;
1634 memset(&descriptor_info, 0, sizeof(descriptor_info));
1635 descriptor_info.sampler = sampler;
1636
1637 VkWriteDescriptorSet descriptor_write;
1638 memset(&descriptor_write, 0, sizeof(descriptor_write));
1639 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1640 descriptor_write.destSet = descriptorSet;
1641 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
1642 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001643 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001644 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1645 descriptor_write.pDescriptors = &descriptor_info;
1646
1647 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1648
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001649 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001650 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ index out of bounds.";
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001651 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
1652 FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001653 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001654}
1655
1656TEST_F(VkLayerTest, InvalidDSUpdateIndex)
1657{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001658 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001659 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001660 std::string msgString;
1661 VkResult err;
1662
1663 ASSERT_NO_FATAL_FAILURE(InitState());
1664 m_errorMonitor->ClearState();
1665 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001666 VkDescriptorTypeCount ds_type_count = {};
1667 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1668 ds_type_count.count = 1;
1669
1670 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1671 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1672 ds_pool_ci.pNext = NULL;
1673 ds_pool_ci.count = 1;
1674 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001675 VkDescriptorPool ds_pool;
1676 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1677 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001678
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001679 VkDescriptorSetLayoutBinding dsl_binding = {};
1680 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1681 dsl_binding.arraySize = 1;
1682 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1683 dsl_binding.pImmutableSamplers = NULL;
1684
1685 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1686 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1687 ds_layout_ci.pNext = NULL;
1688 ds_layout_ci.count = 1;
1689 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001690 VkDescriptorSetLayout ds_layout;
1691 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1692 ASSERT_VK_SUCCESS(err);
1693
1694 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001695 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001696 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001697
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001698 VkSamplerCreateInfo sampler_ci = {};
1699 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1700 sampler_ci.pNext = NULL;
1701 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1702 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1703 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1704 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1705 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1706 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1707 sampler_ci.mipLodBias = 1.0;
1708 sampler_ci.maxAnisotropy = 1;
1709 sampler_ci.compareEnable = VK_FALSE;
1710 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1711 sampler_ci.minLod = 1.0;
1712 sampler_ci.maxLod = 1.0;
1713 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northrop0bf4e1d2015-08-11 15:50:55 -06001714 sampler_ci.texelCoords = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001715
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001716 VkSampler sampler;
1717 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1718 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001719
1720 VkDescriptorInfo descriptor_info;
1721 memset(&descriptor_info, 0, sizeof(descriptor_info));
1722 descriptor_info.sampler = sampler;
1723
1724 VkWriteDescriptorSet descriptor_write;
1725 memset(&descriptor_write, 0, sizeof(descriptor_write));
1726 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1727 descriptor_write.destSet = descriptorSet;
1728 descriptor_write.destBinding = 2;
1729 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001730 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001731 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1732 descriptor_write.pDescriptors = &descriptor_info;
1733
1734 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1735
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001736 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001737 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ count too large for layout.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001738 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
1739 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
1740 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001741}
1742
1743TEST_F(VkLayerTest, InvalidDSUpdateStruct)
1744{
1745 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001746 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001747 std::string msgString;
1748 VkResult err;
1749
1750 ASSERT_NO_FATAL_FAILURE(InitState());
1751 m_errorMonitor->ClearState();
1752 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001753
1754 VkDescriptorTypeCount ds_type_count = {};
1755 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1756 ds_type_count.count = 1;
1757
1758 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1759 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1760 ds_pool_ci.pNext = NULL;
1761 ds_pool_ci.count = 1;
1762 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001763 VkDescriptorPool ds_pool;
1764 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1765 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001766 VkDescriptorSetLayoutBinding dsl_binding = {};
1767 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1768 dsl_binding.arraySize = 1;
1769 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1770 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001771
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001772 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1773 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1774 ds_layout_ci.pNext = NULL;
1775 ds_layout_ci.count = 1;
1776 ds_layout_ci.pBinding = &dsl_binding;
1777
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001778 VkDescriptorSetLayout ds_layout;
1779 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1780 ASSERT_VK_SUCCESS(err);
1781
1782 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001783 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001784 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001785
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001786 VkSamplerCreateInfo sampler_ci = {};
1787 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1788 sampler_ci.pNext = NULL;
1789 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1790 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1791 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1792 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1793 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1794 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1795 sampler_ci.mipLodBias = 1.0;
1796 sampler_ci.maxAnisotropy = 1;
1797 sampler_ci.compareEnable = VK_FALSE;
1798 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1799 sampler_ci.minLod = 1.0;
1800 sampler_ci.maxLod = 1.0;
1801 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northrop0bf4e1d2015-08-11 15:50:55 -06001802 sampler_ci.texelCoords = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001803 VkSampler sampler;
1804 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1805 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001806
1807
1808 VkDescriptorInfo descriptor_info;
1809 memset(&descriptor_info, 0, sizeof(descriptor_info));
1810 descriptor_info.sampler = sampler;
1811
1812 VkWriteDescriptorSet descriptor_write;
1813 memset(&descriptor_write, 0, sizeof(descriptor_write));
1814 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
1815 descriptor_write.destSet = descriptorSet;
1816 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001817 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001818 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1819 descriptor_write.pDescriptors = &descriptor_info;
1820
1821 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1822
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001823 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001824 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ invalid struct type.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001825 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
1826 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
1827 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001828}
1829
1830TEST_F(VkLayerTest, NumSamplesMismatch)
1831{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001832 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001833 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001834 std::string msgString;
1835 VkResult err;
1836
1837 ASSERT_NO_FATAL_FAILURE(InitState());
1838 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1839 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001840 VkDescriptorTypeCount ds_type_count = {};
1841 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1842 ds_type_count.count = 1;
1843
1844 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1845 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1846 ds_pool_ci.pNext = NULL;
1847 ds_pool_ci.count = 1;
1848 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001849 VkDescriptorPool ds_pool;
1850 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1851 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001852
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001853 VkDescriptorSetLayoutBinding dsl_binding = {};
1854 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1855 dsl_binding.arraySize = 1;
1856 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1857 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001858
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001859 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1860 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1861 ds_layout_ci.pNext = NULL;
1862 ds_layout_ci.count = 1;
1863 ds_layout_ci.pBinding = &dsl_binding;
1864
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001865 VkDescriptorSetLayout ds_layout;
1866 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1867 ASSERT_VK_SUCCESS(err);
1868
1869 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001870 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001871 ASSERT_VK_SUCCESS(err);
1872
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001873 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1874 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1875 pipe_ms_state_ci.pNext = NULL;
1876 pipe_ms_state_ci.rasterSamples = 4;
1877 pipe_ms_state_ci.sampleShadingEnable = 0;
1878 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06001879 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001880
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001881 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1882 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1883 pipeline_layout_ci.pNext = NULL;
1884 pipeline_layout_ci.descriptorSetCount = 1;
1885 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001886
1887 VkPipelineLayout pipeline_layout;
1888 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1889 ASSERT_VK_SUCCESS(err);
1890
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001891 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001892 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1893 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06001894 VkPipelineObj pipe(m_device);
1895 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001896 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06001897 pipe.SetMSAA(&pipe_ms_state_ci);
1898 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001899
Tony Barbour1490c912015-07-28 10:17:20 -06001900 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06001901 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001902
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001903 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001904 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding RenderPass w/ mismatched MSAA from PSO.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001905 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
1906 FAIL() << "Error received was not 'Num samples mismatch!...'";
1907 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001908}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001909
Tobin Ehlise4076782015-06-24 15:53:07 -06001910TEST_F(VkLayerTest, PipelineNotBound)
1911{
1912 VkFlags msgFlags;
1913 std::string msgString;
1914 VkResult err;
1915
1916 ASSERT_NO_FATAL_FAILURE(InitState());
1917 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1918 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001919
1920 VkDescriptorTypeCount ds_type_count = {};
1921 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1922 ds_type_count.count = 1;
1923
1924 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1925 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1926 ds_pool_ci.pNext = NULL;
1927 ds_pool_ci.count = 1;
1928 ds_pool_ci.pTypeCount = &ds_type_count;
1929
Tobin Ehlise4076782015-06-24 15:53:07 -06001930 VkDescriptorPool ds_pool;
1931 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1932 ASSERT_VK_SUCCESS(err);
1933
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001934 VkDescriptorSetLayoutBinding dsl_binding = {};
1935 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1936 dsl_binding.arraySize = 1;
1937 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1938 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06001939
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001940 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1941 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1942 ds_layout_ci.pNext = NULL;
1943 ds_layout_ci.count = 1;
1944 ds_layout_ci.pBinding = &dsl_binding;
1945
Tobin Ehlise4076782015-06-24 15:53:07 -06001946 VkDescriptorSetLayout ds_layout;
1947 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1948 ASSERT_VK_SUCCESS(err);
1949
1950 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001951 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06001952 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001953
1954 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1955 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1956 pipeline_layout_ci.pNext = NULL;
1957 pipeline_layout_ci.descriptorSetCount = 1;
1958 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06001959
1960 VkPipelineLayout pipeline_layout;
1961 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1962 ASSERT_VK_SUCCESS(err);
1963
Tobin Ehlise4076782015-06-24 15:53:07 -06001964 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Tony Barbour1490c912015-07-28 10:17:20 -06001965
1966 BeginCommandBuffer();
1967 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06001968
1969 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001970 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Tobin Ehlise4076782015-06-24 15:53:07 -06001971 if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1972 FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1973 }
1974}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001975
1976TEST_F(VkLayerTest, ClearCmdNoDraw)
1977{
1978 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
1979 VkFlags msgFlags;
1980 std::string msgString;
1981 VkResult err;
1982
1983 ASSERT_NO_FATAL_FAILURE(InitState());
1984 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1985 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001986
1987 VkDescriptorTypeCount ds_type_count = {};
1988 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1989 ds_type_count.count = 1;
1990
1991 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1992 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1993 ds_pool_ci.pNext = NULL;
1994 ds_pool_ci.count = 1;
1995 ds_pool_ci.pTypeCount = &ds_type_count;
1996
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001997 VkDescriptorPool ds_pool;
1998 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1999 ASSERT_VK_SUCCESS(err);
2000
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002001 VkDescriptorSetLayoutBinding dsl_binding = {};
2002 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2003 dsl_binding.arraySize = 1;
2004 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2005 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002006
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002007 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2008 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2009 ds_layout_ci.pNext = NULL;
2010 ds_layout_ci.count = 1;
2011 ds_layout_ci.pBinding = &dsl_binding;
2012
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002013 VkDescriptorSetLayout ds_layout;
2014 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2015 ASSERT_VK_SUCCESS(err);
2016
2017 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002018 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002019 ASSERT_VK_SUCCESS(err);
2020
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002021 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2022 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2023 pipe_ms_state_ci.pNext = NULL;
2024 pipe_ms_state_ci.rasterSamples = 4;
2025 pipe_ms_state_ci.sampleShadingEnable = 0;
2026 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002027 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002028
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002029 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2030 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2031 pipeline_layout_ci.pNext = NULL;
2032 pipeline_layout_ci.descriptorSetCount = 1;
2033 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002034
2035 VkPipelineLayout pipeline_layout;
2036 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2037 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002038
Tony Barbourd7d828b2015-08-06 10:16:07 -06002039 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002040 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2041 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002042 VkPipelineObj pipe(m_device);
2043 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002044 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002045 pipe.SetMSAA(&pipe_ms_state_ci);
2046 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002047
2048 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002049
2050 m_errorMonitor->ClearState();
2051 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
2052 // Also pass down other dummy params to keep driver and paramchecker happy
2053 VkClearColorValue cCV;
2054 cCV.f32[0] = 1.0;
2055 cCV.f32[1] = 1.0;
2056 cCV.f32[2] = 1.0;
2057 cCV.f32[3] = 1.0;
2058
Tony Barbour1490c912015-07-28 10:17:20 -06002059 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002060 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002061 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 Ehlis8cd650e2015-07-01 16:46:13 -06002062 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) {
2063 FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'";
2064 }
2065}
2066
Tobin Ehlise4076782015-06-24 15:53:07 -06002067TEST_F(VkLayerTest, VtxBufferBadIndex)
2068{
2069 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
2070 VkFlags msgFlags;
2071 std::string msgString;
2072 VkResult err;
2073
2074 ASSERT_NO_FATAL_FAILURE(InitState());
2075 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2076 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002077
2078 VkDescriptorTypeCount ds_type_count = {};
2079 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2080 ds_type_count.count = 1;
2081
2082 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2083 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2084 ds_pool_ci.pNext = NULL;
2085 ds_pool_ci.count = 1;
2086 ds_pool_ci.pTypeCount = &ds_type_count;
2087
2088 VkDescriptorPool ds_pool;
Tobin Ehlise4076782015-06-24 15:53:07 -06002089 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
2090 ASSERT_VK_SUCCESS(err);
2091
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002092 VkDescriptorSetLayoutBinding dsl_binding = {};
2093 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2094 dsl_binding.arraySize = 1;
2095 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2096 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002097
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002098 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2099 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2100 ds_layout_ci.pNext = NULL;
2101 ds_layout_ci.count = 1;
2102 ds_layout_ci.pBinding = &dsl_binding;
2103
Tobin Ehlise4076782015-06-24 15:53:07 -06002104 VkDescriptorSetLayout ds_layout;
2105 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2106 ASSERT_VK_SUCCESS(err);
2107
2108 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002109 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06002110 ASSERT_VK_SUCCESS(err);
2111
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002112 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2113 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2114 pipe_ms_state_ci.pNext = NULL;
2115 pipe_ms_state_ci.rasterSamples = 1;
2116 pipe_ms_state_ci.sampleShadingEnable = 0;
2117 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002118 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002119
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002120 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2121 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2122 pipeline_layout_ci.pNext = NULL;
2123 pipeline_layout_ci.descriptorSetCount = 1;
2124 pipeline_layout_ci.pSetLayouts = &ds_layout;
2125 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06002126
Tobin Ehlise4076782015-06-24 15:53:07 -06002127 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2128 ASSERT_VK_SUCCESS(err);
2129
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002130 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002131 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2132 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002133 VkPipelineObj pipe(m_device);
2134 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002135 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002136 pipe.SetMSAA(&pipe_ms_state_ci);
2137 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002138
2139 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06002140 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlise4076782015-06-24 15:53:07 -06002141 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06002142 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlise4076782015-06-24 15:53:07 -06002143
2144 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002145 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding Vtx Buffer w/o VBO attached to PSO.";
Tobin Ehlise4076782015-06-24 15:53:07 -06002146 if (!strstr(msgString.c_str(),"Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.")) {
2147 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
2148 }
2149}
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002150#endif
2151#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06002152#if GTEST_IS_THREADSAFE
2153struct thread_data_struct {
2154 VkCmdBuffer cmdBuffer;
2155 VkEvent event;
2156 bool bailout;
2157};
2158
2159extern "C" void *AddToCommandBuffer(void *arg)
2160{
2161 struct thread_data_struct *data = (struct thread_data_struct *) arg;
2162 std::string msgString;
2163
2164 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06002165 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06002166 if (data->bailout) {
2167 break;
2168 }
2169 }
2170 return NULL;
2171}
2172
2173TEST_F(VkLayerTest, ThreadCmdBufferCollision)
2174{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002175 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06002176 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002177 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06002178
2179 ASSERT_NO_FATAL_FAILURE(InitState());
2180 ASSERT_NO_FATAL_FAILURE(InitViewport());
2181 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2182
Mike Stroyan09aae812015-05-12 16:00:45 -06002183 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06002184 BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002185
2186 VkEventCreateInfo event_info;
2187 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06002188 VkResult err;
2189
2190 memset(&event_info, 0, sizeof(event_info));
2191 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2192
2193 err = vkCreateEvent(device(), &event_info, &event);
2194 ASSERT_VK_SUCCESS(err);
2195
Mike Stroyan09aae812015-05-12 16:00:45 -06002196 err = vkResetEvent(device(), event);
2197 ASSERT_VK_SUCCESS(err);
2198
2199 struct thread_data_struct data;
Tony Barbour1490c912015-07-28 10:17:20 -06002200 data.cmdBuffer = m_cmdBuffer->handle();
Mike Stroyan09aae812015-05-12 16:00:45 -06002201 data.event = event;
2202 data.bailout = false;
2203 m_errorMonitor->SetBailout(&data.bailout);
2204 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002205 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06002206 // Add many entries to command buffer from this thread at the same time.
2207 AddToCommandBuffer(&data);
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002208 test_platform_thread_join(thread, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -06002209 EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002210
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002211 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002212 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err from using one VkCommandBufferObj in two threads";
Mike Stroyan09aae812015-05-12 16:00:45 -06002213 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05002214 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06002215 }
2216
2217}
2218#endif
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002219#endif
Chris Forbes5af3bf22015-05-25 11:13:08 +12002220#if SHADER_CHECKER_TESTS
2221TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
2222{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002223 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12002224 std::string msgString;
2225 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002226 ScopedUseGlsl useGlsl(false);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002227
2228 char const *vsSource =
2229 "#version 140\n"
2230 "#extension GL_ARB_separate_shader_objects: require\n"
2231 "#extension GL_ARB_shading_language_420pack: require\n"
2232 "\n"
2233 "layout(location=0) out float x;\n"
2234 "void main(){\n"
2235 " gl_Position = vec4(1);\n"
2236 " x = 0;\n"
2237 "}\n";
2238 char const *fsSource =
2239 "#version 140\n"
2240 "#extension GL_ARB_separate_shader_objects: require\n"
2241 "#extension GL_ARB_shading_language_420pack: require\n"
2242 "\n"
2243 "layout(location=0) out vec4 color;\n"
2244 "void main(){\n"
2245 " color = vec4(1);\n"
2246 "}\n";
2247
2248 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2249 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2250
2251 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002252 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12002253 pipe.AddShader(&vs);
2254 pipe.AddShader(&fs);
2255
Chris Forbes5af3bf22015-05-25 11:13:08 +12002256 VkDescriptorSetObj descriptorSet(m_device);
2257 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002258 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002259
2260 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002261 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12002262
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002263 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002264
Cody Northrop1684adb2015-08-05 11:15:02 -06002265 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002266 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
2267 FAIL() << "Incorrect warning: " << msgString;
2268 }
2269}
Chris Forbes5af3bf22015-05-25 11:13:08 +12002270
Chris Forbes3c10b852015-05-25 11:13:13 +12002271TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
2272{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002273 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12002274 std::string msgString;
2275 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002276 ScopedUseGlsl useGlsl(false);
Chris Forbes3c10b852015-05-25 11:13:13 +12002277
2278 char const *vsSource =
2279 "#version 140\n"
2280 "#extension GL_ARB_separate_shader_objects: require\n"
2281 "#extension GL_ARB_shading_language_420pack: require\n"
2282 "\n"
2283 "void main(){\n"
2284 " gl_Position = vec4(1);\n"
2285 "}\n";
2286 char const *fsSource =
2287 "#version 140\n"
2288 "#extension GL_ARB_separate_shader_objects: require\n"
2289 "#extension GL_ARB_shading_language_420pack: require\n"
2290 "\n"
2291 "layout(location=0) in float x;\n"
2292 "layout(location=0) out vec4 color;\n"
2293 "void main(){\n"
2294 " color = vec4(x);\n"
2295 "}\n";
2296
2297 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2298 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2299
2300 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002301 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12002302 pipe.AddShader(&vs);
2303 pipe.AddShader(&fs);
2304
Chris Forbes3c10b852015-05-25 11:13:13 +12002305 VkDescriptorSetObj descriptorSet(m_device);
2306 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002307 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12002308
2309 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002310 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12002311
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002312 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12002313
Cody Northrop1684adb2015-08-05 11:15:02 -06002314 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes3c10b852015-05-25 11:13:13 +12002315 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
2316 FAIL() << "Incorrect error: " << msgString;
2317 }
2318}
2319
Chris Forbescc281692015-05-25 11:13:17 +12002320TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
2321{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002322 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12002323 std::string msgString;
2324 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002325 ScopedUseGlsl useGlsl(false);
Chris Forbescc281692015-05-25 11:13:17 +12002326
2327 char const *vsSource =
2328 "#version 140\n"
2329 "#extension GL_ARB_separate_shader_objects: require\n"
2330 "#extension GL_ARB_shading_language_420pack: require\n"
2331 "\n"
2332 "layout(location=0) out int x;\n"
2333 "void main(){\n"
2334 " x = 0;\n"
2335 " gl_Position = vec4(1);\n"
2336 "}\n";
2337 char const *fsSource =
2338 "#version 140\n"
2339 "#extension GL_ARB_separate_shader_objects: require\n"
2340 "#extension GL_ARB_shading_language_420pack: require\n"
2341 "\n"
2342 "layout(location=0) in float x;\n" /* VS writes int */
2343 "layout(location=0) out vec4 color;\n"
2344 "void main(){\n"
2345 " color = vec4(x);\n"
2346 "}\n";
2347
2348 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2349 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2350
2351 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002352 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12002353 pipe.AddShader(&vs);
2354 pipe.AddShader(&fs);
2355
Chris Forbescc281692015-05-25 11:13:17 +12002356 VkDescriptorSetObj descriptorSet(m_device);
2357 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002358 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12002359
2360 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002361 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12002362
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002363 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12002364
Cody Northrop1684adb2015-08-05 11:15:02 -06002365 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbescc281692015-05-25 11:13:17 +12002366 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
2367 FAIL() << "Incorrect error: " << msgString;
2368 }
2369}
2370
Chris Forbes8291c052015-05-25 11:13:28 +12002371TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
2372{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002373 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12002374 std::string msgString;
2375 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002376 ScopedUseGlsl useGlsl(false);
Chris Forbes8291c052015-05-25 11:13:28 +12002377
2378 VkVertexInputBindingDescription input_binding;
2379 memset(&input_binding, 0, sizeof(input_binding));
2380
2381 VkVertexInputAttributeDescription input_attrib;
2382 memset(&input_attrib, 0, sizeof(input_attrib));
2383 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2384
2385 char const *vsSource =
2386 "#version 140\n"
2387 "#extension GL_ARB_separate_shader_objects: require\n"
2388 "#extension GL_ARB_shading_language_420pack: require\n"
2389 "\n"
2390 "void main(){\n"
2391 " gl_Position = vec4(1);\n"
2392 "}\n";
2393 char const *fsSource =
2394 "#version 140\n"
2395 "#extension GL_ARB_separate_shader_objects: require\n"
2396 "#extension GL_ARB_shading_language_420pack: require\n"
2397 "\n"
2398 "layout(location=0) out vec4 color;\n"
2399 "void main(){\n"
2400 " color = vec4(1);\n"
2401 "}\n";
2402
2403 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2404 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2405
2406 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002407 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12002408 pipe.AddShader(&vs);
2409 pipe.AddShader(&fs);
2410
2411 pipe.AddVertexInputBindings(&input_binding, 1);
2412 pipe.AddVertexInputAttribs(&input_attrib, 1);
2413
Chris Forbes8291c052015-05-25 11:13:28 +12002414 VkDescriptorSetObj descriptorSet(m_device);
2415 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002416 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12002417
2418 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002419 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12002420
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002421 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12002422
Cody Northrop1684adb2015-08-05 11:15:02 -06002423 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12002424 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
2425 FAIL() << "Incorrect warning: " << msgString;
2426 }
2427}
2428
Chris Forbes37367e62015-05-25 11:13:29 +12002429TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
2430{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002431 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12002432 std::string msgString;
2433 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002434 ScopedUseGlsl useGlsl(false);
Chris Forbes37367e62015-05-25 11:13:29 +12002435
2436 char const *vsSource =
2437 "#version 140\n"
2438 "#extension GL_ARB_separate_shader_objects: require\n"
2439 "#extension GL_ARB_shading_language_420pack: require\n"
2440 "\n"
2441 "layout(location=0) in vec4 x;\n" /* not provided */
2442 "void main(){\n"
2443 " gl_Position = x;\n"
2444 "}\n";
2445 char const *fsSource =
2446 "#version 140\n"
2447 "#extension GL_ARB_separate_shader_objects: require\n"
2448 "#extension GL_ARB_shading_language_420pack: require\n"
2449 "\n"
2450 "layout(location=0) out vec4 color;\n"
2451 "void main(){\n"
2452 " color = vec4(1);\n"
2453 "}\n";
2454
2455 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2456 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2457
2458 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002459 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12002460 pipe.AddShader(&vs);
2461 pipe.AddShader(&fs);
2462
Chris Forbes37367e62015-05-25 11:13:29 +12002463 VkDescriptorSetObj descriptorSet(m_device);
2464 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002465 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12002466
2467 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002468 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12002469
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002470 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12002471
Cody Northrop1684adb2015-08-05 11:15:02 -06002472 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes37367e62015-05-25 11:13:29 +12002473 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
2474 FAIL() << "Incorrect warning: " << msgString;
2475 }
2476}
2477
Chris Forbesa4b02322015-05-25 11:13:31 +12002478TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
2479{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002480 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12002481 std::string msgString;
2482 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002483 ScopedUseGlsl useGlsl(false);
Chris Forbesa4b02322015-05-25 11:13:31 +12002484
2485 VkVertexInputBindingDescription input_binding;
2486 memset(&input_binding, 0, sizeof(input_binding));
2487
2488 VkVertexInputAttributeDescription input_attrib;
2489 memset(&input_attrib, 0, sizeof(input_attrib));
2490 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2491
2492 char const *vsSource =
2493 "#version 140\n"
2494 "#extension GL_ARB_separate_shader_objects: require\n"
2495 "#extension GL_ARB_shading_language_420pack: require\n"
2496 "\n"
2497 "layout(location=0) in int x;\n" /* attrib provided float */
2498 "void main(){\n"
2499 " gl_Position = vec4(x);\n"
2500 "}\n";
2501 char const *fsSource =
2502 "#version 140\n"
2503 "#extension GL_ARB_separate_shader_objects: require\n"
2504 "#extension GL_ARB_shading_language_420pack: require\n"
2505 "\n"
2506 "layout(location=0) out vec4 color;\n"
2507 "void main(){\n"
2508 " color = vec4(1);\n"
2509 "}\n";
2510
2511 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2512 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2513
2514 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002515 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12002516 pipe.AddShader(&vs);
2517 pipe.AddShader(&fs);
2518
2519 pipe.AddVertexInputBindings(&input_binding, 1);
2520 pipe.AddVertexInputAttribs(&input_attrib, 1);
2521
Chris Forbesa4b02322015-05-25 11:13:31 +12002522 VkDescriptorSetObj descriptorSet(m_device);
2523 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002524 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12002525
2526 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002527 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12002528
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002529 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12002530
Cody Northrop1684adb2015-08-05 11:15:02 -06002531 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa4b02322015-05-25 11:13:31 +12002532 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
2533 FAIL() << "Incorrect error: " << msgString;
2534 }
2535}
2536
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002537TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
2538{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002539 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002540 std::string msgString;
2541 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002542 ScopedUseGlsl useGlsl(false);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002543
2544 /* Two binding descriptions for binding 0 */
2545 VkVertexInputBindingDescription input_bindings[2];
2546 memset(input_bindings, 0, sizeof(input_bindings));
2547
2548 VkVertexInputAttributeDescription input_attrib;
2549 memset(&input_attrib, 0, sizeof(input_attrib));
2550 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2551
2552 char const *vsSource =
2553 "#version 140\n"
2554 "#extension GL_ARB_separate_shader_objects: require\n"
2555 "#extension GL_ARB_shading_language_420pack: require\n"
2556 "\n"
2557 "layout(location=0) in float x;\n" /* attrib provided float */
2558 "void main(){\n"
2559 " gl_Position = vec4(x);\n"
2560 "}\n";
2561 char const *fsSource =
2562 "#version 140\n"
2563 "#extension GL_ARB_separate_shader_objects: require\n"
2564 "#extension GL_ARB_shading_language_420pack: require\n"
2565 "\n"
2566 "layout(location=0) out vec4 color;\n"
2567 "void main(){\n"
2568 " color = vec4(1);\n"
2569 "}\n";
2570
2571 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2572 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2573
2574 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002575 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002576 pipe.AddShader(&vs);
2577 pipe.AddShader(&fs);
2578
2579 pipe.AddVertexInputBindings(input_bindings, 2);
2580 pipe.AddVertexInputAttribs(&input_attrib, 1);
2581
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002582 VkDescriptorSetObj descriptorSet(m_device);
2583 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002584 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002585
2586 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002587 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002588
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002589 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002590
Cody Northrop1684adb2015-08-05 11:15:02 -06002591 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002592 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
2593 FAIL() << "Incorrect error: " << msgString;
2594 }
2595}
Chris Forbes4c948702015-05-25 11:13:32 +12002596
Chris Forbesc12ef122015-05-25 11:13:40 +12002597/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
2598 * rejects it. */
2599
2600TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
2601{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002602 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12002603 std::string msgString;
2604 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002605 ScopedUseGlsl useGlsl(false);
Chris Forbesc12ef122015-05-25 11:13:40 +12002606
2607 char const *vsSource =
2608 "#version 140\n"
2609 "#extension GL_ARB_separate_shader_objects: require\n"
2610 "#extension GL_ARB_shading_language_420pack: require\n"
2611 "\n"
2612 "void main(){\n"
2613 " gl_Position = vec4(1);\n"
2614 "}\n";
2615 char const *fsSource =
2616 "#version 140\n"
2617 "#extension GL_ARB_separate_shader_objects: require\n"
2618 "#extension GL_ARB_shading_language_420pack: require\n"
2619 "\n"
2620 "void main(){\n"
2621 "}\n";
2622
2623 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2624 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2625
2626 VkPipelineObj pipe(m_device);
2627 pipe.AddShader(&vs);
2628 pipe.AddShader(&fs);
2629
Chia-I Wuc278df82015-07-07 11:50:03 +08002630 /* set up CB 0, not written */
2631 pipe.AddColorAttachment();
2632 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12002633
Chris Forbesc12ef122015-05-25 11:13:40 +12002634 VkDescriptorSetObj descriptorSet(m_device);
2635 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002636 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12002637
2638 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002639 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12002640
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002641 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12002642
Cody Northrop1684adb2015-08-05 11:15:02 -06002643 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc12ef122015-05-25 11:13:40 +12002644 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
2645 FAIL() << "Incorrect error: " << msgString;
2646 }
2647}
2648
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002649TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
2650{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002651 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002652 std::string msgString;
2653 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002654 ScopedUseGlsl useGlsl(false);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002655
2656 char const *vsSource =
2657 "#version 140\n"
2658 "#extension GL_ARB_separate_shader_objects: require\n"
2659 "#extension GL_ARB_shading_language_420pack: require\n"
2660 "\n"
2661 "void main(){\n"
2662 " gl_Position = vec4(1);\n"
2663 "}\n";
2664 char const *fsSource =
2665 "#version 140\n"
2666 "#extension GL_ARB_separate_shader_objects: require\n"
2667 "#extension GL_ARB_shading_language_420pack: require\n"
2668 "\n"
2669 "layout(location=0) out vec4 x;\n"
2670 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
2671 "void main(){\n"
2672 " x = vec4(1);\n"
2673 " y = vec4(1);\n"
2674 "}\n";
2675
2676 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2677 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2678
2679 VkPipelineObj pipe(m_device);
2680 pipe.AddShader(&vs);
2681 pipe.AddShader(&fs);
2682
Chia-I Wuc278df82015-07-07 11:50:03 +08002683 /* set up CB 0, not written */
2684 pipe.AddColorAttachment();
2685 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002686 /* FS writes CB 1, but we don't configure it */
2687
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002688 VkDescriptorSetObj descriptorSet(m_device);
2689 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002690 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002691
2692 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002693 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002694
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002695 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002696
Cody Northrop1684adb2015-08-05 11:15:02 -06002697 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002698 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
2699 FAIL() << "Incorrect warning: " << msgString;
2700 }
2701}
2702
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002703TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
2704{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002705 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002706 std::string msgString;
2707 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002708 ScopedUseGlsl useGlsl(false);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002709
2710 char const *vsSource =
2711 "#version 140\n"
2712 "#extension GL_ARB_separate_shader_objects: require\n"
2713 "#extension GL_ARB_shading_language_420pack: require\n"
2714 "\n"
2715 "void main(){\n"
2716 " gl_Position = vec4(1);\n"
2717 "}\n";
2718 char const *fsSource =
2719 "#version 140\n"
2720 "#extension GL_ARB_separate_shader_objects: require\n"
2721 "#extension GL_ARB_shading_language_420pack: require\n"
2722 "\n"
2723 "layout(location=0) out ivec4 x;\n" /* not UNORM */
2724 "void main(){\n"
2725 " x = ivec4(1);\n"
2726 "}\n";
2727
2728 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2729 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2730
2731 VkPipelineObj pipe(m_device);
2732 pipe.AddShader(&vs);
2733 pipe.AddShader(&fs);
2734
Chia-I Wuc278df82015-07-07 11:50:03 +08002735 /* set up CB 0; type is UNORM by default */
2736 pipe.AddColorAttachment();
2737 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002738
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002739 VkDescriptorSetObj descriptorSet(m_device);
2740 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002741 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002742
2743 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002744 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002745
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002746 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002747
Cody Northrop1684adb2015-08-05 11:15:02 -06002748 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002749 if (!strstr(msgString.c_str(),"does not match FS output type")) {
2750 FAIL() << "Incorrect error: " << msgString;
2751 }
2752}
Chris Forbesc2050732015-06-05 14:43:36 +12002753
2754TEST_F(VkLayerTest, CreatePipelineNonSpirvShader)
2755{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002756 VkFlags msgFlags;
Chris Forbesc2050732015-06-05 14:43:36 +12002757 std::string msgString;
2758 ASSERT_NO_FATAL_FAILURE(InitState());
2759 /* Intentionally provided GLSL rather than compiling to SPIRV first */
Cody Northrop1cfbd172015-06-03 16:49:20 -06002760 ScopedUseGlsl useGlsl(true);
Chris Forbesc2050732015-06-05 14:43:36 +12002761
2762 char const *vsSource =
2763 "#version 140\n"
2764 "#extension GL_ARB_separate_shader_objects: require\n"
2765 "#extension GL_ARB_shading_language_420pack: require\n"
2766 "\n"
2767 "void main(){\n"
2768 " gl_Position = vec4(1);\n"
2769 "}\n";
2770 char const *fsSource =
2771 "#version 140\n"
2772 "#extension GL_ARB_separate_shader_objects: require\n"
2773 "#extension GL_ARB_shading_language_420pack: require\n"
2774 "\n"
2775 "layout(location=0) out vec4 x;\n"
2776 "void main(){\n"
2777 " x = vec4(1);\n"
2778 "}\n";
2779
2780 m_errorMonitor->ClearState();
2781
2782 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2783 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2784
2785
2786 VkPipelineObj pipe(m_device);
2787 pipe.AddShader(&vs);
2788 pipe.AddShader(&fs);
2789
Chia-I Wuc278df82015-07-07 11:50:03 +08002790 /* set up CB 0; type is UNORM by default */
2791 pipe.AddColorAttachment();
2792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc2050732015-06-05 14:43:36 +12002793
Chris Forbesc2050732015-06-05 14:43:36 +12002794 VkDescriptorSetObj descriptorSet(m_device);
2795 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002796 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc2050732015-06-05 14:43:36 +12002797
Tony Barboured132432015-08-04 16:23:11 -06002798 VkResult res = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc2050732015-06-05 14:43:36 +12002799 /* pipeline creation should have succeeded */
2800 ASSERT_EQ(VK_SUCCESS, res);
2801
2802 /* should have emitted a warning: the shader is not SPIRV, so we're
2803 * not going to be able to analyze it */
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002804 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002805 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesc2050732015-06-05 14:43:36 +12002806 if (!strstr(msgString.c_str(),"is not SPIR-V")) {
2807 FAIL() << "Incorrect warning: " << msgString;
2808 }
2809}
Chris Forbes01c9db72015-06-04 09:25:25 +12002810#endif
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002811
Tony Barbour30486ea2015-04-07 13:44:53 -06002812int main(int argc, char **argv) {
2813 int result;
2814
2815 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06002816 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06002817
2818 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
2819
2820 result = RUN_ALL_TESTS();
2821
Tony Barbour01999182015-04-09 12:58:51 -06002822 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06002823 return result;
2824}