blob: 07c41aab50f4eb39daa822d0e5492781ce38c9e4 [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 Northrope4bc6942015-08-26 10:01:32 -060030 BsoFailLineWidth = 0x00000001,
31 BsoFailDepthBias = 0x00000002,
Cody Northropf5bd2252015-08-17 11:10:49 -060032 BsoFailViewport = 0x00000004,
Cody Northrope4bc6942015-08-26 10:01:32 -060033 BsoFailBlend = 0x00000008,
34 BsoFailDepthBounds = 0x00000010,
Cody Northrop2605cb02015-08-18 15:21:16 -060035 BsoFailStencil = 0x00000020,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050036} BsoFailSelect;
37
38struct vktriangle_vs_uniform {
39 // Must start with MVP
40 float mvp[4][4];
41 float position[3][4];
42 float color[3][4];
43};
44
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050045static const char bindStateVertShaderText[] =
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050046 "#version 130\n"
47 "vec2 vertices[3];\n"
48 "void main() {\n"
49 " vertices[0] = vec2(-1.0, -1.0);\n"
50 " vertices[1] = vec2( 1.0, -1.0);\n"
51 " vertices[2] = vec2( 0.0, 1.0);\n"
52 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
53 "}\n";
54
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050055static const char bindStateFragShaderText[] =
Cody Northrop74a2d2c2015-06-16 17:32:04 -060056 "#version 140\n"
57 "#extension GL_ARB_separate_shader_objects: require\n"
58 "#extension GL_ARB_shading_language_420pack: require\n"
59 "\n"
60 "layout(location = 0) out vec4 uFragColor;\n"
61 "void main(){\n"
62 " uFragColor = vec4(0,1,0,1);\n"
63 "}\n";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050064
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -060065static VkBool32 myDbgFunc(
Tony Barboure84a8d62015-07-10 14:10:27 -060066 VkFlags msgFlags,
67 VkDbgObjectType objType,
68 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060069 size_t location,
70 int32_t msgCode,
71 const char* pLayerPrefix,
72 const char* pMsg,
73 void* pUserData);
Tony Barbour30486ea2015-04-07 13:44:53 -060074
75class ErrorMonitor {
76public:
Tony Barbour0c1bdc62015-04-29 17:34:29 -060077 ErrorMonitor()
Tony Barbour30486ea2015-04-07 13:44:53 -060078 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060079 test_platform_thread_create_mutex(&m_mutex);
80 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060081 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mike Stroyan09aae812015-05-12 16:00:45 -060082 m_bailout = NULL;
Mike Stroyan7016f4f2015-07-13 14:45:35 -060083 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060084 }
85 void ClearState()
86 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060087 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060088 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -060089 m_msgString.clear();
Mike Stroyan7016f4f2015-07-13 14:45:35 -060090 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060091 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060092 VkFlags GetState(std::string *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -060093 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060094 test_platform_thread_lock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060095 *msgString = m_msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -060096 test_platform_thread_unlock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060097 return m_msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -060098 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060099 void SetState(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -0600100 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600101 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600102 if (m_bailout != NULL) {
103 *m_bailout = true;
104 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600105 m_msgFlags = msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600106 m_msgString.reserve(strlen(msgString));
107 m_msgString = msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600108 test_platform_thread_unlock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600109 }
110 void SetBailout(bool *bailout)
111 {
112 m_bailout = bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600113 }
114
115private:
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600116 VkFlags m_msgFlags;
117 std::string m_msgString;
118 test_platform_thread_mutex m_mutex;
119 bool* m_bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600120};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500121
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600122static VkBool32 myDbgFunc(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600123 VkFlags msgFlags,
Tony Barboure84a8d62015-07-10 14:10:27 -0600124 VkDbgObjectType objType,
125 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600126 size_t location,
127 int32_t msgCode,
128 const char* pLayerPrefix,
129 const char* pMsg,
130 void* pUserData)
Tony Barbour30486ea2015-04-07 13:44:53 -0600131{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600132 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour8508b8e2015-04-09 10:48:04 -0600133 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600134 errMonitor->SetState(msgFlags, pMsg);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600135 return true;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600136 }
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600137
138 return false;
Tony Barbour30486ea2015-04-07 13:44:53 -0600139}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500140
Tony Barbour01999182015-04-09 12:58:51 -0600141class VkLayerTest : public VkRenderFramework
Tony Barbour30486ea2015-04-07 13:44:53 -0600142{
143public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600144 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
145 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500146 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
147 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbour1490c912015-07-28 10:17:20 -0600148 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
149 { GenericDrawPreparation(m_cmdBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600150
Tony Barbour1490c912015-07-28 10:17:20 -0600151 /* Convenience functions that use built-in command buffer */
152 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_cmdBuffer); }
153 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_cmdBuffer); }
154 void Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
155 { m_cmdBuffer->Draw(firstVertex, vertexCount, firstInstance, instanceCount); }
156 void DrawIndexed(uint32_t firstVertex, uint32_t vertexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
157 { m_cmdBuffer->DrawIndexed(firstVertex, vertexCount, vertexOffset,firstInstance, instanceCount); }
158 void QueueCommandBuffer() { m_cmdBuffer->QueueCommandBuffer(); }
159 void QueueCommandBuffer(const VkFence& fence) { m_cmdBuffer->QueueCommandBuffer(fence); }
160 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
161 { m_cmdBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
162 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
163 { m_cmdBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600164protected:
Tony Barbour01999182015-04-09 12:58:51 -0600165 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600166
167 virtual void SetUp() {
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600168 std::vector<const char *> instance_layer_names;
169 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600170 std::vector<const char *> instance_extension_names;
171 std::vector<const char *> device_extension_names;
Tony Barbour950ebc02015-04-23 12:55:36 -0600172
Courtney Goeltzenleuchter846298c2015-07-30 11:32:46 -0600173 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600174 /*
175 * Since CreateDbgMsgCallback is an instance level extension call
176 * any extension / layer that utilizes that feature also needs
177 * to be enabled at create instance time.
178 */
Mike Stroyaned254572015-06-17 16:32:06 -0600179 // Use Threading layer first to protect others from ThreadCmdBufferCollision test
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600180 instance_layer_names.push_back("Threading");
181 instance_layer_names.push_back("ObjectTracker");
182 instance_layer_names.push_back("MemTracker");
183 instance_layer_names.push_back("DrawState");
184 instance_layer_names.push_back("ShaderChecker");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600185
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600186 device_layer_names.push_back("Threading");
187 device_layer_names.push_back("ObjectTracker");
188 device_layer_names.push_back("MemTracker");
189 device_layer_names.push_back("DrawState");
190 device_layer_names.push_back("ShaderChecker");
Tony Barbour30486ea2015-04-07 13:44:53 -0600191
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600192 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -0600193 this->app_info.pNext = NULL;
194 this->app_info.pAppName = "layer_tests";
195 this->app_info.appVersion = 1;
196 this->app_info.pEngineName = "unittest";
197 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600198 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -0600199
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600200 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600201 InitFramework(instance_layer_names, device_layer_names,
202 instance_extension_names, device_extension_names,
203 myDbgFunc, m_errorMonitor);
Tony Barbour30486ea2015-04-07 13:44:53 -0600204 }
205
206 virtual void TearDown() {
207 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600208 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600209 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600210 }
211};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500212
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600213VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600214{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600215 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600216
217 result = cmdBuffer.BeginCommandBuffer();
218
219 /*
220 * For render test all drawing happens in a single render pass
221 * on a single command buffer.
222 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200223 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wuc278df82015-07-07 11:50:03 +0800224 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour30486ea2015-04-07 13:44:53 -0600225 }
226
227 return result;
228}
229
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600230VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600231{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600232 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600233
Chris Forbesfe133ef2015-06-16 14:05:59 +1200234 if (renderPass()) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800235 cmdBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200236 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600237
238 result = cmdBuffer.EndCommandBuffer();
239
240 return result;
241}
242
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500243void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
244{
245 // Create identity matrix
246 int i;
247 struct vktriangle_vs_uniform data;
248
249 glm::mat4 Projection = glm::mat4(1.0f);
250 glm::mat4 View = glm::mat4(1.0f);
251 glm::mat4 Model = glm::mat4(1.0f);
252 glm::mat4 MVP = Projection * View * Model;
253 const int matrixSize = sizeof(MVP);
254 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
255
256 memcpy(&data.mvp, &MVP[0][0], matrixSize);
257
258 static const Vertex tri_data[] =
259 {
260 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
261 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
262 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
263 };
264
265 for (i=0; i<3; i++) {
266 data.position[i][0] = tri_data[i].posX;
267 data.position[i][1] = tri_data[i].posY;
268 data.position[i][2] = tri_data[i].posZ;
269 data.position[i][3] = tri_data[i].posW;
270 data.color[i][0] = tri_data[i].r;
271 data.color[i][1] = tri_data[i].g;
272 data.color[i][2] = tri_data[i].b;
273 data.color[i][3] = tri_data[i].a;
274 }
275
276 ASSERT_NO_FATAL_FAILURE(InitState());
277 ASSERT_NO_FATAL_FAILURE(InitViewport());
278
279 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
280
281 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
282 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
283
284 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800285 pipelineobj.AddColorAttachment();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500286 pipelineobj.AddShader(&vs);
287 pipelineobj.AddShader(&ps);
288
289 VkDescriptorSetObj descriptorSet(m_device);
290 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
291
292 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600293 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500294
Tony Barbour1490c912015-07-28 10:17:20 -0600295 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500296
297 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -0600298 Draw(0, 3, 0, 1);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500299
300 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600301 EndCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500302
Tony Barbour1490c912015-07-28 10:17:20 -0600303 QueueCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500304}
305
306void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
307{
308 if (m_depthStencil->Initialized()) {
309 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
310 } else {
311 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
312 }
313
314 cmdBuffer->PrepareAttachments();
Cody Northrope4bc6942015-08-26 10:01:32 -0600315 if ((failMask & BsoFailLineWidth) != BsoFailLineWidth) {
316 cmdBuffer->BindDynamicLineWidthState(m_stateLineWidth);
Cody Northropf5bd2252015-08-17 11:10:49 -0600317 }
Cody Northrope4bc6942015-08-26 10:01:32 -0600318 if ((failMask & BsoFailDepthBias) != BsoFailDepthBias) {
319 cmdBuffer->BindDynamicDepthBiasState(m_stateDepthBias);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500320 }
321 if ((failMask & BsoFailViewport) != BsoFailViewport) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600322 cmdBuffer->BindDynamicViewportState(m_stateViewport);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500323 }
Cody Northrope4bc6942015-08-26 10:01:32 -0600324 if ((failMask & BsoFailBlend) != BsoFailBlend) {
325 cmdBuffer->BindDynamicBlendState(m_stateBlend);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500326 }
Cody Northrope4bc6942015-08-26 10:01:32 -0600327 if ((failMask & BsoFailDepthBounds) != BsoFailDepthBounds) {
328 cmdBuffer->BindDynamicDepthBoundsState(m_stateDepthBounds);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500329 }
Cody Northrop2605cb02015-08-18 15:21:16 -0600330 if ((failMask & BsoFailStencil) != BsoFailStencil) {
331 cmdBuffer->BindDynamicStencilState(m_stateStencil);
332 }
333 // Make sure depthWriteEnable is set so that Depth fail test will work correctly
334 // Make sure stencilTestEnable is set so that Stencil fail test will work correctly
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600335 VkStencilOpState stencil = {};
336 stencil.stencilFailOp = VK_STENCIL_OP_KEEP;
337 stencil.stencilPassOp = VK_STENCIL_OP_KEEP;
338 stencil.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
339 stencil.stencilCompareOp = VK_COMPARE_OP_NEVER;
340
341 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
342 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
343 ds_ci.pNext = NULL;
344 ds_ci.depthTestEnable = VK_FALSE;
345 ds_ci.depthWriteEnable = VK_TRUE;
346 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
Cody Northrope4bc6942015-08-26 10:01:32 -0600347 ds_ci.depthBoundsTestEnable = VK_FALSE;
Cody Northrop2605cb02015-08-18 15:21:16 -0600348 ds_ci.stencilTestEnable = VK_TRUE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600349 ds_ci.front = stencil;
350 ds_ci.back = stencil;
351
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600352 pipelineobj.SetDepthStencil(&ds_ci);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500353 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Cody Northropccfa96d2015-08-27 10:20:35 -0600354 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
355 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500356 cmdBuffer->BindPipeline(pipelineobj);
357 cmdBuffer->BindDescriptorSet(descriptorSet);
358}
359
360// ********************************************************************************************************************
361// ********************************************************************************************************************
362// ********************************************************************************************************************
363// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600364#if MEM_TRACKER_TESTS
Mark Lobodzinski81078192015-05-19 10:28:29 -0500365TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
366{
367 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600368 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500369 std::string msgString;
370
371 VkFenceCreateInfo fenceInfo = {};
372 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
373 fenceInfo.pNext = NULL;
374 fenceInfo.flags = 0;
375
376 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barboure389b882015-07-20 13:00:10 -0600377
378 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
379 vk_testing::Buffer buffer;
380 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500381
Tony Barbour1490c912015-07-28 10:17:20 -0600382 BeginCommandBuffer();
383 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
384 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500385
386 testFence.init(*m_device, fenceInfo);
387
388 // Bypass framework since it does the waits automatically
389 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600390 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500391 ASSERT_VK_SUCCESS( err );
392
393 m_errorMonitor->ClearState();
394 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600395 vkResetCommandBuffer(m_cmdBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500396
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600397 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600398 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 -0500399 if (!strstr(msgString.c_str(),"Resetting CB")) {
400 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
401 }
402}
403
404TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion)
405{
406 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600407 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500408 std::string msgString;
409
410 VkFenceCreateInfo fenceInfo = {};
411 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
412 fenceInfo.pNext = NULL;
413 fenceInfo.flags = 0;
414
415 ASSERT_NO_FATAL_FAILURE(InitState());
416 ASSERT_NO_FATAL_FAILURE(InitViewport());
417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
418
Tony Barbour1490c912015-07-28 10:17:20 -0600419 BeginCommandBuffer();
420 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
421 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500422
423 testFence.init(*m_device, fenceInfo);
424
425 // Bypass framework since it does the waits automatically
426 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600427 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500428 ASSERT_VK_SUCCESS( err );
429
430 m_errorMonitor->ClearState();
431 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600432 BeginCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500433
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600434 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600435 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 -0500436 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
437 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
438 }
439}
440
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500441TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
442{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600443 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500444 std::string msgString;
445 VkResult err;
446
447 ASSERT_NO_FATAL_FAILURE(InitState());
448 m_errorMonitor->ClearState();
449
450 // Create an image, allocate memory, free it, and then try to bind it
451 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500452 VkDeviceMemory mem;
453 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500454
455 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
456 const int32_t tex_width = 32;
457 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500458
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600459 VkImageCreateInfo image_create_info = {};
460 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
461 image_create_info.pNext = NULL;
462 image_create_info.imageType = VK_IMAGE_TYPE_2D;
463 image_create_info.format = tex_format;
464 image_create_info.extent.width = tex_width;
465 image_create_info.extent.height = tex_height;
466 image_create_info.extent.depth = 1;
467 image_create_info.mipLevels = 1;
468 image_create_info.arraySize = 1;
469 image_create_info.samples = 1;
470 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
471 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
472 image_create_info.flags = 0;
473
474 VkMemoryAllocInfo mem_alloc = {};
475 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
476 mem_alloc.pNext = NULL;
477 mem_alloc.allocationSize = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500478 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600479 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500480
481 err = vkCreateImage(m_device->device(), &image_create_info, &image);
482 ASSERT_VK_SUCCESS(err);
483
Tony Barboure84a8d62015-07-10 14:10:27 -0600484 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500485 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500486 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500487 ASSERT_VK_SUCCESS(err);
488
Mark Lobodzinski23182612015-05-29 09:32:35 -0500489 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500490
Mike Stroyand72da752015-08-04 10:49:29 -0600491 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 -0600492 if(err != VK_SUCCESS) // If we can't find any unmappable memory this test doesn't make sense
493 return;
Mike Stroyand72da752015-08-04 10:49:29 -0600494
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500495 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500496 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500497 ASSERT_VK_SUCCESS(err);
498
499 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600500 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500501 ASSERT_VK_SUCCESS(err);
502
503 // Map memory as if to initialize the image
504 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500505 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500506
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600507 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600508 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 -0500509 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
510 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
511 }
512}
513
514TEST_F(VkLayerTest, BindInvalidMemory)
515{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600516 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500517 std::string msgString;
518 VkResult err;
519
520 ASSERT_NO_FATAL_FAILURE(InitState());
521 m_errorMonitor->ClearState();
522
523 // Create an image, allocate memory, free it, and then try to bind it
524 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500525 VkDeviceMemory mem;
526 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500527
528 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
529 const int32_t tex_width = 32;
530 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500531
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600532 VkImageCreateInfo image_create_info = {};
533 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
534 image_create_info.pNext = NULL;
535 image_create_info.imageType = VK_IMAGE_TYPE_2D;
536 image_create_info.format = tex_format;
537 image_create_info.extent.width = tex_width;
538 image_create_info.extent.height = tex_height;
539 image_create_info.extent.depth = 1;
540 image_create_info.mipLevels = 1;
541 image_create_info.arraySize = 1;
542 image_create_info.samples = 1;
543 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
544 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
545 image_create_info.flags = 0;
546
547 VkMemoryAllocInfo mem_alloc = {};
548 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
549 mem_alloc.pNext = NULL;
550 mem_alloc.allocationSize = 0;
551 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500552
553 err = vkCreateImage(m_device->device(), &image_create_info, &image);
554 ASSERT_VK_SUCCESS(err);
555
Tony Barboure84a8d62015-07-10 14:10:27 -0600556 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500557 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500558 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500559 ASSERT_VK_SUCCESS(err);
560
Mark Lobodzinski23182612015-05-29 09:32:35 -0500561 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500562
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800563 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600564 ASSERT_VK_SUCCESS(err);
565
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500566 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500567 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500568 ASSERT_VK_SUCCESS(err);
569
570 // Introduce validation failure, free memory before binding
Mark Lobodzinski23182612015-05-29 09:32:35 -0500571 vkFreeMemory(m_device->device(), mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500572 ASSERT_VK_SUCCESS(err);
573
574 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600575 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Cody Northrop87333892015-08-06 12:40:01 -0600576 // This may very well return an error.
577 (void)err;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500578
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600579 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600580 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 -0500581 if (!strstr(msgString.c_str(),"couldn't find info for mem obj")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500582 FAIL() << "Error received did not match expected error message from BindObjectMemory in MemTracker";
583 }
584}
585
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600586// TODO : Is this test still valid. Not sure it is with updates to memory binding model
587// Verify and delete the test of fix the check
588//TEST_F(VkLayerTest, FreeBoundMemory)
589//{
590// VkFlags msgFlags;
591// std::string msgString;
592// VkResult err;
593//
594// ASSERT_NO_FATAL_FAILURE(InitState());
595// m_errorMonitor->ClearState();
596//
597// // Create an image, allocate memory, free it, and then try to bind it
598// VkImage image;
599// VkDeviceMemory mem;
600// VkMemoryRequirements mem_reqs;
601//
602// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
603// const int32_t tex_width = 32;
604// const int32_t tex_height = 32;
605//
606// const VkImageCreateInfo image_create_info = {
607// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
608// .pNext = NULL,
609// .imageType = VK_IMAGE_TYPE_2D,
610// .format = tex_format,
611// .extent = { tex_width, tex_height, 1 },
612// .mipLevels = 1,
613// .arraySize = 1,
614// .samples = 1,
615// .tiling = VK_IMAGE_TILING_LINEAR,
616// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
617// .flags = 0,
618// };
619// VkMemoryAllocInfo mem_alloc = {
620// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
621// .pNext = NULL,
622// .allocationSize = 0,
623// .memoryTypeIndex = 0,
624// };
625//
626// err = vkCreateImage(m_device->device(), &image_create_info, &image);
627// ASSERT_VK_SUCCESS(err);
628//
629// err = vkGetImageMemoryRequirements(m_device->device(),
630// image,
631// &mem_reqs);
632// ASSERT_VK_SUCCESS(err);
633//
634// mem_alloc.allocationSize = mem_reqs.size;
635//
636// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
637// ASSERT_VK_SUCCESS(err);
638//
639// // allocate memory
640// err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
641// ASSERT_VK_SUCCESS(err);
642//
643// // Bind memory to Image object
644// err = vkBindImageMemory(m_device->device(), image, mem, 0);
645// ASSERT_VK_SUCCESS(err);
646//
647// // Introduce validation failure, free memory while still bound to object
648// vkFreeMemory(m_device->device(), mem);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600649// msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600650//
Cody Northrop1684adb2015-08-05 11:15:02 -0600651// 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 -0600652// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
653// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
654// }
655//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500656
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500657TEST_F(VkLayerTest, RebindMemory)
658{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600659 VkFlags msgFlags;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500660 std::string msgString;
661 VkResult err;
662
663 ASSERT_NO_FATAL_FAILURE(InitState());
664 m_errorMonitor->ClearState();
665
666 // Create an image, allocate memory, free it, and then try to bind it
667 VkImage image;
668 VkDeviceMemory mem1;
669 VkDeviceMemory mem2;
670 VkMemoryRequirements mem_reqs;
671
672 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
673 const int32_t tex_width = 32;
674 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500675
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600676 VkImageCreateInfo image_create_info = {};
677 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
678 image_create_info.pNext = NULL;
679 image_create_info.imageType = VK_IMAGE_TYPE_2D;
680 image_create_info.format = tex_format;
681 image_create_info.extent.width = tex_width;
682 image_create_info.extent.height = tex_height;
683 image_create_info.extent.depth = 1;
684 image_create_info.mipLevels = 1;
685 image_create_info.arraySize = 1;
686 image_create_info.samples = 1;
687 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
688 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
689 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500690
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600691 VkMemoryAllocInfo mem_alloc = {};
692 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
693 mem_alloc.pNext = NULL;
694 mem_alloc.allocationSize = 0;
695 mem_alloc.memoryTypeIndex = 0;
696
697 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
698 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500699 err = vkCreateImage(m_device->device(), &image_create_info, &image);
700 ASSERT_VK_SUCCESS(err);
701
Tony Barboure84a8d62015-07-10 14:10:27 -0600702 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500703 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500704 &mem_reqs);
705 ASSERT_VK_SUCCESS(err);
706
707 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800708 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600709 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500710
711 // allocate 2 memory objects
712 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
713 ASSERT_VK_SUCCESS(err);
714 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
715 ASSERT_VK_SUCCESS(err);
716
717 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600718 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500719 ASSERT_VK_SUCCESS(err);
720
721 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600722 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500723 ASSERT_VK_SUCCESS(err);
724
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600725 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600726 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 -0500727 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
728 FAIL() << "Error received did not match expected message when rebinding memory to an object";
729 }
730}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500731
732TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
733{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600734 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500735 std::string msgString;
736 VkResult err;
737
738 ASSERT_NO_FATAL_FAILURE(InitState());
739 m_errorMonitor->ClearState();
740
741 // Create an image object, allocate memory, destroy the object and then try to bind it
742 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500743 VkDeviceMemory mem;
744 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500745
746 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
747 const int32_t tex_width = 32;
748 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500749
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600750 VkImageCreateInfo image_create_info = {};
751 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
752 image_create_info.pNext = NULL;
753 image_create_info.imageType = VK_IMAGE_TYPE_2D;
754 image_create_info.format = tex_format;
755 image_create_info.extent.width = tex_width;
756 image_create_info.extent.height = tex_height;
757 image_create_info.extent.depth = 1;
758 image_create_info.mipLevels = 1;
759 image_create_info.arraySize = 1;
760 image_create_info.samples = 1;
761 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
762 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
763 image_create_info.flags = 0;
764
765 VkMemoryAllocInfo mem_alloc = {};
766 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
767 mem_alloc.pNext = NULL;
768 mem_alloc.allocationSize = 0;
769 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500770
771 err = vkCreateImage(m_device->device(), &image_create_info, &image);
772 ASSERT_VK_SUCCESS(err);
773
Tony Barboure84a8d62015-07-10 14:10:27 -0600774 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500775 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500776 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500777 ASSERT_VK_SUCCESS(err);
778
Mark Lobodzinski23182612015-05-29 09:32:35 -0500779 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800780 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600781 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500782
783 // Allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500784 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500785 ASSERT_VK_SUCCESS(err);
786
787 // Introduce validation failure, destroy Image object before binding
Tony Barboure84a8d62015-07-10 14:10:27 -0600788 vkDestroyImage(m_device->device(), image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500789 ASSERT_VK_SUCCESS(err);
790
Mike Stroyand72da752015-08-04 10:49:29 -0600791 // Now Try to bind memory to this destroyed object
Tony Barboure84a8d62015-07-10 14:10:27 -0600792 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mike Stroyand72da752015-08-04 10:49:29 -0600793 // This may very well return an error.
794 (void) err;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500795
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600796 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600797 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 -0500798 if (!strstr(msgString.c_str(),"that's not in global list")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500799 FAIL() << "Error received did not match expected error message from updateObjectBinding in MemTracker";
800 }
801}
802
Tony Barbour8508b8e2015-04-09 10:48:04 -0600803TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600804{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600805 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600806 VkFlags msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600807 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600808
809 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600810 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
811 fenceInfo.pNext = NULL;
812 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600813
Tony Barbour30486ea2015-04-07 13:44:53 -0600814 ASSERT_NO_FATAL_FAILURE(InitState());
815 ASSERT_NO_FATAL_FAILURE(InitViewport());
816 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
817
Tony Barbour1490c912015-07-28 10:17:20 -0600818 BeginCommandBuffer();
819 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
820 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600821
822 testFence.init(*m_device, fenceInfo);
823 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -0600824 QueueCommandBuffer(testFence.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600825 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600826 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 -0600827 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500828 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600829 }
830
831}
832
833TEST_F(VkLayerTest, ResetUnsignaledFence)
834{
835 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600836 VkFlags msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600837 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600838 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600839 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
840 fenceInfo.pNext = NULL;
841
Tony Barbour8508b8e2015-04-09 10:48:04 -0600842 ASSERT_NO_FATAL_FAILURE(InitState());
843 testFence.init(*m_device, fenceInfo);
844 m_errorMonitor->ClearState();
Chia-I Wua4992342015-07-03 11:45:55 +0800845 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600846 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600847 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600848 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 -0600849 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500850 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600851 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600852
853}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600854
Chia-I Wuc278df82015-07-07 11:50:03 +0800855/* TODO: Update for changes due to bug-14075 tiling across render passes */
856#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600857TEST_F(VkLayerTest, InvalidUsageBits)
858{
859 // Initiate Draw w/o a PSO bound
860 VkFlags msgFlags;
861 std::string msgString;
862
863 ASSERT_NO_FATAL_FAILURE(InitState());
864 m_errorMonitor->ClearState();
865 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600866 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600867
868 const VkExtent3D e3d = {
869 .width = 128,
870 .height = 128,
871 .depth = 1,
872 };
873 const VkImageCreateInfo ici = {
874 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
875 .pNext = NULL,
876 .imageType = VK_IMAGE_TYPE_2D,
877 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
878 .extent = e3d,
879 .mipLevels = 1,
880 .arraySize = 1,
881 .samples = 1,
882 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchterc3b8eea2015-09-10 14:14:11 -0600883 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600884 .flags = 0,
885 };
886
887 VkImage dsi;
888 vkCreateImage(m_device->device(), &ici, &dsi);
889 VkDepthStencilView dsv;
890 const VkDepthStencilViewCreateInfo dsvci = {
891 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
892 .pNext = NULL,
893 .image = dsi,
894 .mipLevel = 0,
Courtney Goeltzenleuchter3dee8082015-09-10 16:38:41 -0600895 .baseArrayLayer = 0,
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600896 .arraySize = 1,
897 .flags = 0,
898 };
899 vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv);
900 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600901 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 -0600902 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
903 FAIL() << "Error received was not 'Invalid usage flag for image...'";
904 }
905}
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600906#endif
Chia-I Wuc278df82015-07-07 11:50:03 +0800907#endif
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600908#if OBJ_TRACKER_TESTS
Cody Northrope4bc6942015-08-26 10:01:32 -0600909TEST_F(VkLayerTest, LineWidthStateNotBound)
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500910{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600911 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500912 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600913 ASSERT_NO_FATAL_FAILURE(InitState());
914 m_errorMonitor->ClearState();
Cody Northrope4bc6942015-08-26 10:01:32 -0600915 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500916
Cody Northrope4bc6942015-08-26 10:01:32 -0600917 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500918
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600919 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrope4bc6942015-08-26 10:01:32 -0600920 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Line Width State Object";
921 if (!strstr(msgString.c_str(),"Line width object not bound to this command buffer")) {
922 FAIL() << "Error received was not 'Line Width object not bound to this command buffer'";
Cody Northropf5bd2252015-08-17 11:10:49 -0600923 }
924}
925
Cody Northrope4bc6942015-08-26 10:01:32 -0600926TEST_F(VkLayerTest, DepthBiasStateNotBound)
Cody Northropf5bd2252015-08-17 11:10:49 -0600927{
928 VkFlags msgFlags;
929 std::string msgString;
930 ASSERT_NO_FATAL_FAILURE(InitState());
931 m_errorMonitor->ClearState();
Cody Northrope4bc6942015-08-26 10:01:32 -0600932 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
Cody Northropf5bd2252015-08-17 11:10:49 -0600933
Cody Northrope4bc6942015-08-26 10:01:32 -0600934 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Cody Northropf5bd2252015-08-17 11:10:49 -0600935
936 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrope4bc6942015-08-26 10:01:32 -0600937 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bias State Object";
938 if (!strstr(msgString.c_str(),"Depth bias object not bound to this command buffer")) {
939 FAIL() << "Error received was not 'Depth bias object not bound to this command buffer'";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500940 }
941}
942
943TEST_F(VkLayerTest, ViewportStateNotBound)
944{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600945 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500946 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600947 ASSERT_NO_FATAL_FAILURE(InitState());
948 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500949 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
950
951 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
952
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600953 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600954 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 -0500955 if (!strstr(msgString.c_str(),"Viewport object not bound to this command buffer")) {
956 FAIL() << "Error received was not 'Viewport object not bound to this command buffer'";
957 }
958}
959
Cody Northrope4bc6942015-08-26 10:01:32 -0600960TEST_F(VkLayerTest, BlendStateNotBound)
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500961{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600962 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500963 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600964 ASSERT_NO_FATAL_FAILURE(InitState());
965 m_errorMonitor->ClearState();
Cody Northrope4bc6942015-08-26 10:01:32 -0600966 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500967
Cody Northrope4bc6942015-08-26 10:01:32 -0600968 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500969
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600970 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrope4bc6942015-08-26 10:01:32 -0600971 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Blend State Object";
972 if (!strstr(msgString.c_str(),"Blend object not bound to this command buffer")) {
973 FAIL() << "Error received was not 'Blend object not bound to this command buffer'";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500974 }
975}
976
Cody Northrope4bc6942015-08-26 10:01:32 -0600977TEST_F(VkLayerTest, DepthBoundsStateNotBound)
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500978{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600979 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500980 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600981 ASSERT_NO_FATAL_FAILURE(InitState());
982 m_errorMonitor->ClearState();
Cody Northrope4bc6942015-08-26 10:01:32 -0600983 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500984
Cody Northrope4bc6942015-08-26 10:01:32 -0600985 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500986
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600987 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrope4bc6942015-08-26 10:01:32 -0600988 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bounds State Object";
989 if (!strstr(msgString.c_str(),"Depth bounds object not bound to this command buffer")) {
990 FAIL() << "Error received was not 'Depth bounds object not bound to this command buffer'";
Cody Northrop2605cb02015-08-18 15:21:16 -0600991 }
992}
993
994TEST_F(VkLayerTest, StencilStateNotBound)
995{
996 VkFlags msgFlags;
997 std::string msgString;
998 ASSERT_NO_FATAL_FAILURE(InitState());
999 m_errorMonitor->ClearState();
1000 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil state object is not bound beforehand");
1001
1002 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencil);
1003
1004 msgFlags = m_errorMonitor->GetState(&msgString);
1005 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Stencil State Object";
1006 if (!strstr(msgString.c_str(),"Stencil object not bound to this command buffer")) {
1007 FAIL() << "Error received was not 'Stencil object not bound to this command buffer'";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05001008 }
Tony Barbourdb686622015-05-06 09:35:56 -06001009}
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001010
1011TEST_F(VkLayerTest, PipelineNotBound)
1012{
1013 VkFlags msgFlags;
1014 std::string msgString;
1015 VkResult err;
1016
1017 ASSERT_NO_FATAL_FAILURE(InitState());
1018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1019 m_errorMonitor->ClearState();
1020
1021 VkDescriptorTypeCount ds_type_count = {};
1022 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1023 ds_type_count.count = 1;
1024
1025 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1026 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1027 ds_pool_ci.pNext = NULL;
1028 ds_pool_ci.count = 1;
1029 ds_pool_ci.pTypeCount = &ds_type_count;
1030
1031 VkDescriptorPool ds_pool;
1032 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1033 ASSERT_VK_SUCCESS(err);
1034
1035 VkDescriptorSetLayoutBinding dsl_binding = {};
1036 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1037 dsl_binding.arraySize = 1;
1038 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1039 dsl_binding.pImmutableSamplers = NULL;
1040
1041 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1042 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1043 ds_layout_ci.pNext = NULL;
1044 ds_layout_ci.count = 1;
1045 ds_layout_ci.pBinding = &dsl_binding;
1046
1047 VkDescriptorSetLayout ds_layout;
1048 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1049 ASSERT_VK_SUCCESS(err);
1050
1051 VkDescriptorSet descriptorSet;
1052 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1053 ASSERT_VK_SUCCESS(err);
1054
1055 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1056 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1057 pipeline_layout_ci.pNext = NULL;
1058 pipeline_layout_ci.descriptorSetCount = 1;
1059 pipeline_layout_ci.pSetLayouts = &ds_layout;
1060
1061 VkPipelineLayout pipeline_layout;
1062 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1063 ASSERT_VK_SUCCESS(err);
1064
1065 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1066
1067 BeginCommandBuffer();
1068 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1069
1070 msgFlags = m_errorMonitor->GetState(&msgString);
1071 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Cody Northrop655ec2c2015-09-15 16:56:30 -06001072 if (!strstr(msgString.c_str(),"Invalid VkPipeline Object")) {
1073 FAIL() << "Error received was not 'Invalid VkPipeline Object'";
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001074 }
1075}
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001076#endif
1077#if DRAW_STATE_TESTS
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001078TEST_F(VkLayerTest, CmdBufferTwoSubmits)
1079{
1080 vk_testing::Fence testFence;
1081 VkFlags msgFlags;
1082 std::string msgString;
1083
1084 VkFenceCreateInfo fenceInfo = {};
1085 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1086 fenceInfo.pNext = NULL;
1087 fenceInfo.flags = 0;
1088
1089 ASSERT_NO_FATAL_FAILURE(InitState());
1090 ASSERT_NO_FATAL_FAILURE(InitViewport());
1091 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1092
1093 // We luck out b/c by default the framework creates CB w/ the VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set
1094 BeginCommandBuffer();
1095 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
1096 EndCommandBuffer();
1097
1098 testFence.init(*m_device, fenceInfo);
1099
1100 // Bypass framework since it does the waits automatically
1101 VkResult err = VK_SUCCESS;
1102 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
1103 ASSERT_VK_SUCCESS( err );
1104
1105 m_errorMonitor->ClearState();
1106 // Cause validation error by re-submitting cmd buffer that should only be submitted once
1107 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001108
1109 msgFlags = m_errorMonitor->GetState(&msgString);
1110 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 -06001111 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 -06001112 FAIL() << "Error received was not 'CB (0xaddress) was created w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set...'";
1113 }
1114}
1115
Tobin Ehlise4076782015-06-24 15:53:07 -06001116TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001117{
1118 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001119 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001120 std::string msgString;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001121 VkResult err;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001122
1123 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001125 m_errorMonitor->ClearState();
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001126
1127 VkDescriptorTypeCount ds_type_count = {};
1128 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1129 ds_type_count.count = 1;
1130
1131 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1132 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1133 ds_pool_ci.pNext = NULL;
1134 ds_pool_ci.count = 1;
1135 ds_pool_ci.pTypeCount = &ds_type_count;
1136
1137 VkDescriptorPool ds_pool;
1138 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1139 ASSERT_VK_SUCCESS(err);
1140
1141 VkDescriptorSetLayoutBinding dsl_binding = {};
1142 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1143 dsl_binding.arraySize = 1;
1144 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1145 dsl_binding.pImmutableSamplers = NULL;
1146
1147 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1148 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1149 ds_layout_ci.pNext = NULL;
1150 ds_layout_ci.count = 1;
1151 ds_layout_ci.pBinding = &dsl_binding;
1152
1153 VkDescriptorSetLayout ds_layout;
1154 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1155 ASSERT_VK_SUCCESS(err);
1156
1157 VkDescriptorSet descriptorSet;
1158 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1159 ASSERT_VK_SUCCESS(err);
1160 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1161 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1162 pipe_ms_state_ci.pNext = NULL;
1163 pipe_ms_state_ci.rasterSamples = 1;
1164 pipe_ms_state_ci.sampleShadingEnable = 0;
1165 pipe_ms_state_ci.minSampleShading = 1.0;
1166 pipe_ms_state_ci.pSampleMask = NULL;
1167
1168 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1169 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1170 pipeline_layout_ci.pNext = NULL;
1171 pipeline_layout_ci.descriptorSetCount = 1;
1172 pipeline_layout_ci.pSetLayouts = &ds_layout;
1173 VkPipelineLayout pipeline_layout;
1174
1175 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1176 ASSERT_VK_SUCCESS(err);
1177
1178 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
1179 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1180 // but add it to be able to run on more devices
1181 VkPipelineObj pipe(m_device);
1182 pipe.AddShader(&vs);
1183 pipe.AddShader(&fs);
1184 pipe.SetMSAA(&pipe_ms_state_ci);
1185 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1186 m_errorMonitor->ClearState();
1187 // Calls CreateCommandBuffer
1188 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1189 VkCmdBufferBeginInfo cmd_buf_info = {};
1190 memset(&cmd_buf_info, 0, sizeof(VkCmdBufferBeginInfo));
1191 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1192 cmd_buf_info.pNext = NULL;
1193 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1194 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1195
1196 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1197 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001198 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001199 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 -06001200 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001201 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0x<handle>) without an active RenderPass'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001202 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001203}
1204
1205TEST_F(VkLayerTest, InvalidDescriptorPool)
1206{
1207 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1208 // The DS check for this is after driver has been called to validate DS internal data struct
1209 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001210/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001211 std::string msgString;
1212 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1213 vkResetDescriptorPool(device(), badPool);
1214
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001215 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001216 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 -06001217 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1218 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1219 }*/
1220}
1221
1222TEST_F(VkLayerTest, InvalidDescriptorSet)
1223{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001224 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1225 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001226 // Create a valid cmd buffer
1227 // call vkCmdBindDescriptorSets w/ false DS
1228}
1229
1230TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1231{
1232 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1233 // The DS check for this is after driver has been called to validate DS internal data struct
1234}
1235
1236TEST_F(VkLayerTest, InvalidPipeline)
1237{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001238 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1239 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001240 // Create a valid cmd buffer
1241 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -06001242// VkFlags msgFlags;
1243// std::string msgString;
1244//
1245// ASSERT_NO_FATAL_FAILURE(InitState());
1246// m_errorMonitor->ClearState();
1247// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001248// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001249// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1250// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
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 after binding invalid pipeline to CmdBuffer";
Tobin Ehlise4076782015-06-24 15:53:07 -06001253// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1254// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1255// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001256}
1257
Tobin Ehlis254eca02015-06-25 15:46:59 -06001258TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001259{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001260 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001261 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001262 std::string msgString;
1263 VkResult err;
1264
1265 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001266 ASSERT_NO_FATAL_FAILURE(InitViewport());
1267 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001268 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001269 VkDescriptorTypeCount ds_type_count = {};
1270 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1271 ds_type_count.count = 1;
1272
1273 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1274 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1275 ds_pool_ci.pNext = NULL;
1276 ds_pool_ci.count = 1;
1277 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001278
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001279 VkDescriptorPool ds_pool;
1280 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1281 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001282
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001283 VkDescriptorSetLayoutBinding dsl_binding = {};
1284 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1285 dsl_binding.arraySize = 1;
1286 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1287 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001288
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001289 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1290 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1291 ds_layout_ci.pNext = NULL;
1292 ds_layout_ci.count = 1;
1293 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -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 Ehlis6bdfa372015-05-27 14:32:28 -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 Ehlis6bdfa372015-05-27 14:32:28 -06001307
1308 VkPipelineLayout pipeline_layout;
1309 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1310 ASSERT_VK_SUCCESS(err);
1311
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001312 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001313 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1314 // but add it to be able to run on more devices
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001315
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001316 VkPipelineObj pipe(m_device);
1317 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001318 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001319 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001320
1321 BeginCommandBuffer();
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001322 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbour1490c912015-07-28 10:17:20 -06001323 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001324
Tobin Ehlis254eca02015-06-25 15:46:59 -06001325 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001326 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 -06001327 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1328 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1329 }
1330}
1331
1332TEST_F(VkLayerTest, NoBeginCmdBuffer)
1333{
1334 VkFlags msgFlags;
1335 std::string msgString;
1336
1337 ASSERT_NO_FATAL_FAILURE(InitState());
1338 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001339 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001340 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1341 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1342 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 ending a CmdBuffer w/o calling BeginCommandBuffer()";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001344 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1345 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1346 }
1347}
1348
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001349TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1350{
1351 VkFlags msgFlags;
1352 std::string msgString;
1353
1354 ASSERT_NO_FATAL_FAILURE(InitState());
1355 m_errorMonitor->ClearState();
1356
1357 // Calls CreateCommandBuffer
1358 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1359
1360 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northrop10d8f982015-08-04 17:35:57 -06001361 VkCmdBufferBeginInfo cmd_buf_info = {};
1362 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1363 cmd_buf_info.pNext = NULL;
1364 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1365 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1366 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1367 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1368
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001369
1370 // The error should be caught by validation of the BeginCommandBuffer call
1371 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1372
1373 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001374 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 -06001375 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1376 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1377 }
1378}
1379
1380TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1381{
1382 VkFlags msgFlags;
1383 std::string msgString;
1384 VkResult err;
1385 VkCmdBuffer draw_cmd;
1386 VkCmdPool cmd_pool;
1387
1388 ASSERT_NO_FATAL_FAILURE(InitState());
1389 m_errorMonitor->ClearState();
1390
Cody Northrop10d8f982015-08-04 17:35:57 -06001391 VkCmdBufferCreateInfo cmd = {};
1392 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1393 cmd.pNext = NULL;
1394 cmd.cmdPool = m_cmdPool;
1395 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1396 cmd.flags = 0;
1397
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001398 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
1399 assert(!err);
1400
1401 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northrop10d8f982015-08-04 17:35:57 -06001402 VkCmdBufferBeginInfo cmd_buf_info = {};
1403 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1404 cmd_buf_info.pNext = NULL;
1405 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1406 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001407
1408 // The error should be caught by validation of the BeginCommandBuffer call
1409 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1410
1411 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001412 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 -06001413 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1414 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1415 }
1416}
1417
Tobin Ehlis254eca02015-06-25 15:46:59 -06001418TEST_F(VkLayerTest, InvalidPipelineCreateState)
1419{
1420 // Attempt to Create Gfx Pipeline w/o a VS
1421 VkFlags msgFlags;
1422 std::string msgString;
1423 VkResult err;
1424
1425 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001426 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis254eca02015-06-25 15:46:59 -06001427 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001428
1429 VkDescriptorTypeCount ds_type_count = {};
1430 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1431 ds_type_count.count = 1;
1432
1433 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1434 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1435 ds_pool_ci.pNext = NULL;
1436 ds_pool_ci.count = 1;
1437 ds_pool_ci.pTypeCount = &ds_type_count;
1438
Tobin Ehlis254eca02015-06-25 15:46:59 -06001439 VkDescriptorPool ds_pool;
1440 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1441 ASSERT_VK_SUCCESS(err);
1442
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001443 VkDescriptorSetLayoutBinding dsl_binding = {};
1444 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1445 dsl_binding.arraySize = 1;
1446 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1447 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001448
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001449 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1450 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1451 ds_layout_ci.pNext = NULL;
1452 ds_layout_ci.count = 1;
1453 ds_layout_ci.pBinding = &dsl_binding;
1454
Tobin Ehlis254eca02015-06-25 15:46:59 -06001455 VkDescriptorSetLayout ds_layout;
1456 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1457 ASSERT_VK_SUCCESS(err);
1458
1459 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001460 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001461 ASSERT_VK_SUCCESS(err);
1462
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001463 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1464 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1465 pipeline_layout_ci.pNext = NULL;
1466 pipeline_layout_ci.descriptorSetCount = 1;
1467 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001468
1469 VkPipelineLayout pipeline_layout;
1470 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1471 ASSERT_VK_SUCCESS(err);
1472
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001473 VkGraphicsPipelineCreateInfo gp_ci = {};
1474 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1475 gp_ci.pNext = NULL;
1476 gp_ci.stageCount = 0;
1477 gp_ci.pStages = NULL;
1478 gp_ci.pVertexInputState = NULL;
1479 gp_ci.pInputAssemblyState = NULL;
1480 gp_ci.pTessellationState = NULL;
1481 gp_ci.pViewportState = NULL;
1482 gp_ci.pRasterState = NULL;
1483 gp_ci.pMultisampleState = NULL;
1484 gp_ci.pDepthStencilState = NULL;
1485 gp_ci.pColorBlendState = NULL;
1486 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1487 gp_ci.layout = pipeline_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001488 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001489
1490 VkPipelineCacheCreateInfo pc_ci = {};
1491 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1492 pc_ci.pNext = NULL;
1493 pc_ci.initialSize = 0;
1494 pc_ci.initialData = 0;
1495 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001496
1497 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001498 VkPipelineCache pipelineCache;
1499
1500 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1501 ASSERT_VK_SUCCESS(err);
1502 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001503
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001504 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001505 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 -06001506 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1507 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1508 }
1509}
1510
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001511TEST_F(VkLayerTest, NullRenderPass)
1512{
1513 // Bind a NULL RenderPass
1514 VkFlags msgFlags;
1515 std::string msgString;
1516
1517 ASSERT_NO_FATAL_FAILURE(InitState());
1518 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1519 m_errorMonitor->ClearState();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001520
Tony Barbour1490c912015-07-28 10:17:20 -06001521 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001522 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06001523 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001524
1525 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001526 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001527 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
1528 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
1529 }
1530}
1531
Tobin Ehlis254eca02015-06-25 15:46:59 -06001532TEST_F(VkLayerTest, RenderPassWithinRenderPass)
1533{
1534 // Bind a BeginRenderPass within an active RenderPass
1535 VkFlags msgFlags;
1536 std::string msgString;
1537
1538 ASSERT_NO_FATAL_FAILURE(InitState());
1539 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1540 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001541
Tony Barbour1490c912015-07-28 10:17:20 -06001542 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001543 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001544 VkRenderPassBeginInfo rp_begin = {};
1545 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
1546 rp_begin.pNext = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001547 rp_begin.renderPass = renderPass();
1548 rp_begin.framebuffer = framebuffer();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001549
Tony Barbour1490c912015-07-28 10:17:20 -06001550 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001551
1552 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001553 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 -06001554 if (!strstr(msgString.c_str(),"Cannot call vkCmdBeginRenderPass() during an active RenderPass ")) {
1555 FAIL() << "Error received was not 'Cannot call vkCmdBeginRenderPass() during an active RenderPass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001556 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001557}
1558
1559TEST_F(VkLayerTest, InvalidDynamicStateObject)
1560{
1561 // Create a valid cmd buffer
1562 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001563 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1564 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001565}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06001566
Tobin Ehlise4076782015-06-24 15:53:07 -06001567TEST_F(VkLayerTest, VtxBufferNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001568{
1569 // Bind VBO out-of-bounds for given PSO
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();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001576
1577 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;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001596
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001597 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);
1610
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001611 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1612 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1613 pipeline_layout_ci.pNext = NULL;
1614 pipeline_layout_ci.descriptorSetCount = 1;
1615 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001616
1617 VkPipelineLayout pipeline_layout;
1618 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1619 ASSERT_VK_SUCCESS(err);
1620
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001621 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001622 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1623 // but add it to be able to run on more devices
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001624 VkPipelineObj pipe(m_device);
1625 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001626 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001627 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001628
Tony Barbour1490c912015-07-28 10:17:20 -06001629 BeginCommandBuffer();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001630 ASSERT_VK_SUCCESS(err);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001631 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001632 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06001633 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001634
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001635 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001636 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 -06001637 if (!strstr(msgString.c_str(),"Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.")) {
1638 FAIL() << "Error received was not 'Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001639 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001640}
1641
1642TEST_F(VkLayerTest, DSTypeMismatch)
1643{
1644 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001645 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001646 std::string msgString;
1647 VkResult err;
1648
1649 ASSERT_NO_FATAL_FAILURE(InitState());
1650 m_errorMonitor->ClearState();
1651 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001652 VkDescriptorTypeCount ds_type_count = {};
1653 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1654 ds_type_count.count = 1;
1655
1656 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1657 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1658 ds_pool_ci.pNext = NULL;
1659 ds_pool_ci.count = 1;
1660 ds_pool_ci.pTypeCount = &ds_type_count;
1661
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001662 VkDescriptorPool ds_pool;
1663 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1664 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001665 VkDescriptorSetLayoutBinding dsl_binding = {};
1666 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1667 dsl_binding.arraySize = 1;
1668 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1669 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001670
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001671 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1672 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1673 ds_layout_ci.pNext = NULL;
1674 ds_layout_ci.count = 1;
1675 ds_layout_ci.pBinding = &dsl_binding;
1676
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001677 VkDescriptorSetLayout ds_layout;
1678 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1679 ASSERT_VK_SUCCESS(err);
1680
1681 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001682 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001683 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001684
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001685 VkSamplerCreateInfo sampler_ci = {};
1686 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1687 sampler_ci.pNext = NULL;
1688 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1689 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1690 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06001691 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
1692 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
1693 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001694 sampler_ci.mipLodBias = 1.0;
1695 sampler_ci.maxAnisotropy = 1;
1696 sampler_ci.compareEnable = VK_FALSE;
1697 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1698 sampler_ci.minLod = 1.0;
1699 sampler_ci.maxLod = 1.0;
1700 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06001701 sampler_ci.unnormalizedCoordinates = VK_FALSE;
1702
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001703 VkSampler sampler;
1704 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1705 ASSERT_VK_SUCCESS(err);
1706
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001707 VkDescriptorInfo descriptor_info;
1708 memset(&descriptor_info, 0, sizeof(descriptor_info));
1709 descriptor_info.sampler = sampler;
1710
1711 VkWriteDescriptorSet descriptor_write;
1712 memset(&descriptor_write, 0, sizeof(descriptor_write));
1713 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1714 descriptor_write.destSet = descriptorSet;
1715 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001716 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001717 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1718 descriptor_write.pDescriptors = &descriptor_info;
1719
1720 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1721
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001722 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001723 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 +08001724 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) {
1725 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 -06001726 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001727}
1728
1729TEST_F(VkLayerTest, DSUpdateOutOfBounds)
1730{
1731 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001732 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001733 std::string msgString;
1734 VkResult err;
1735
1736 ASSERT_NO_FATAL_FAILURE(InitState());
1737 m_errorMonitor->ClearState();
1738 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001739 VkDescriptorTypeCount ds_type_count = {};
1740 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1741 ds_type_count.count = 1;
1742
1743 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1744 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1745 ds_pool_ci.pNext = NULL;
1746 ds_pool_ci.count = 1;
1747 ds_pool_ci.pTypeCount = &ds_type_count;
1748
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001749 VkDescriptorPool ds_pool;
1750 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1751 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001752
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001753 VkDescriptorSetLayoutBinding dsl_binding = {};
1754 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1755 dsl_binding.arraySize = 1;
1756 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1757 dsl_binding.pImmutableSamplers = NULL;
1758
1759 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1760 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1761 ds_layout_ci.pNext = NULL;
1762 ds_layout_ci.count = 1;
1763 ds_layout_ci.pBinding = &dsl_binding;
1764
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001765 VkDescriptorSetLayout ds_layout;
1766 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1767 ASSERT_VK_SUCCESS(err);
1768
1769 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001770 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001771 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001772
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001773 VkSamplerCreateInfo sampler_ci = {};
1774 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1775 sampler_ci.pNext = NULL;
1776 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1777 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1778 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06001779 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
1780 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
1781 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001782 sampler_ci.mipLodBias = 1.0;
1783 sampler_ci.maxAnisotropy = 1;
1784 sampler_ci.compareEnable = VK_FALSE;
1785 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1786 sampler_ci.minLod = 1.0;
1787 sampler_ci.maxLod = 1.0;
1788 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06001789 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001790
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001791 VkSampler sampler;
1792 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1793 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001794
1795 VkDescriptorInfo descriptor_info;
1796 memset(&descriptor_info, 0, sizeof(descriptor_info));
1797 descriptor_info.sampler = sampler;
1798
1799 VkWriteDescriptorSet descriptor_write;
1800 memset(&descriptor_write, 0, sizeof(descriptor_write));
1801 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1802 descriptor_write.destSet = descriptorSet;
1803 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
1804 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001805 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001806 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1807 descriptor_write.pDescriptors = &descriptor_info;
1808
1809 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1810
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001811 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001812 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 +08001813 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
1814 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 -06001815 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001816}
1817
1818TEST_F(VkLayerTest, InvalidDSUpdateIndex)
1819{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001820 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001821 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001822 std::string msgString;
1823 VkResult err;
1824
1825 ASSERT_NO_FATAL_FAILURE(InitState());
1826 m_errorMonitor->ClearState();
1827 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001828 VkDescriptorTypeCount ds_type_count = {};
1829 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1830 ds_type_count.count = 1;
1831
1832 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1833 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1834 ds_pool_ci.pNext = NULL;
1835 ds_pool_ci.count = 1;
1836 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001837 VkDescriptorPool ds_pool;
1838 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1839 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001840
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001841 VkDescriptorSetLayoutBinding dsl_binding = {};
1842 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1843 dsl_binding.arraySize = 1;
1844 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1845 dsl_binding.pImmutableSamplers = NULL;
1846
1847 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1848 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1849 ds_layout_ci.pNext = NULL;
1850 ds_layout_ci.count = 1;
1851 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001852 VkDescriptorSetLayout ds_layout;
1853 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1854 ASSERT_VK_SUCCESS(err);
1855
1856 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001857 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001858 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001859
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001860 VkSamplerCreateInfo sampler_ci = {};
1861 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1862 sampler_ci.pNext = NULL;
1863 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1864 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1865 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06001866 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
1867 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
1868 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001869 sampler_ci.mipLodBias = 1.0;
1870 sampler_ci.maxAnisotropy = 1;
1871 sampler_ci.compareEnable = VK_FALSE;
1872 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1873 sampler_ci.minLod = 1.0;
1874 sampler_ci.maxLod = 1.0;
1875 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06001876 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001877
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001878 VkSampler sampler;
1879 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1880 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001881
1882 VkDescriptorInfo descriptor_info;
1883 memset(&descriptor_info, 0, sizeof(descriptor_info));
1884 descriptor_info.sampler = sampler;
1885
1886 VkWriteDescriptorSet descriptor_write;
1887 memset(&descriptor_write, 0, sizeof(descriptor_write));
1888 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1889 descriptor_write.destSet = descriptorSet;
1890 descriptor_write.destBinding = 2;
1891 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001892 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001893 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1894 descriptor_write.pDescriptors = &descriptor_info;
1895
1896 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1897
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001898 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001899 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 -06001900 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
1901 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
1902 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001903}
1904
1905TEST_F(VkLayerTest, InvalidDSUpdateStruct)
1906{
1907 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001908 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001909 std::string msgString;
1910 VkResult err;
1911
1912 ASSERT_NO_FATAL_FAILURE(InitState());
1913 m_errorMonitor->ClearState();
1914 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001915
1916 VkDescriptorTypeCount ds_type_count = {};
1917 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1918 ds_type_count.count = 1;
1919
1920 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1921 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1922 ds_pool_ci.pNext = NULL;
1923 ds_pool_ci.count = 1;
1924 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001925 VkDescriptorPool ds_pool;
1926 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1927 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001928 VkDescriptorSetLayoutBinding dsl_binding = {};
1929 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1930 dsl_binding.arraySize = 1;
1931 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1932 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001933
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001934 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1935 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1936 ds_layout_ci.pNext = NULL;
1937 ds_layout_ci.count = 1;
1938 ds_layout_ci.pBinding = &dsl_binding;
1939
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001940 VkDescriptorSetLayout ds_layout;
1941 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1942 ASSERT_VK_SUCCESS(err);
1943
1944 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001945 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001946 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001947
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001948 VkSamplerCreateInfo sampler_ci = {};
1949 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1950 sampler_ci.pNext = NULL;
1951 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1952 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1953 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06001954 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
1955 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
1956 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001957 sampler_ci.mipLodBias = 1.0;
1958 sampler_ci.maxAnisotropy = 1;
1959 sampler_ci.compareEnable = VK_FALSE;
1960 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1961 sampler_ci.minLod = 1.0;
1962 sampler_ci.maxLod = 1.0;
1963 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06001964 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001965 VkSampler sampler;
1966 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1967 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001968
1969
1970 VkDescriptorInfo descriptor_info;
1971 memset(&descriptor_info, 0, sizeof(descriptor_info));
1972 descriptor_info.sampler = sampler;
1973
1974 VkWriteDescriptorSet descriptor_write;
1975 memset(&descriptor_write, 0, sizeof(descriptor_write));
1976 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
1977 descriptor_write.destSet = descriptorSet;
1978 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001979 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001980 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1981 descriptor_write.pDescriptors = &descriptor_info;
1982
1983 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1984
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001985 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001986 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 -06001987 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
1988 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
1989 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001990}
1991
1992TEST_F(VkLayerTest, NumSamplesMismatch)
1993{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001994 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001995 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001996 std::string msgString;
1997 VkResult err;
1998
1999 ASSERT_NO_FATAL_FAILURE(InitState());
2000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2001 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002002 VkDescriptorTypeCount ds_type_count = {};
2003 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2004 ds_type_count.count = 1;
2005
2006 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2007 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2008 ds_pool_ci.pNext = NULL;
2009 ds_pool_ci.count = 1;
2010 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002011 VkDescriptorPool ds_pool;
2012 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
2013 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002014
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002015 VkDescriptorSetLayoutBinding dsl_binding = {};
2016 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2017 dsl_binding.arraySize = 1;
2018 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2019 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002020
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002021 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2022 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2023 ds_layout_ci.pNext = NULL;
2024 ds_layout_ci.count = 1;
2025 ds_layout_ci.pBinding = &dsl_binding;
2026
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002027 VkDescriptorSetLayout ds_layout;
2028 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2029 ASSERT_VK_SUCCESS(err);
2030
2031 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002032 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002033 ASSERT_VK_SUCCESS(err);
2034
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002035 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2036 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2037 pipe_ms_state_ci.pNext = NULL;
2038 pipe_ms_state_ci.rasterSamples = 4;
2039 pipe_ms_state_ci.sampleShadingEnable = 0;
2040 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002041 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002042
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002043 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2044 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2045 pipeline_layout_ci.pNext = NULL;
2046 pipeline_layout_ci.descriptorSetCount = 1;
2047 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002048
2049 VkPipelineLayout pipeline_layout;
2050 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2051 ASSERT_VK_SUCCESS(err);
2052
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002053 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002054 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2055 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002056 VkPipelineObj pipe(m_device);
2057 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002058 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002059 pipe.SetMSAA(&pipe_ms_state_ci);
2060 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002061
Tony Barbour1490c912015-07-28 10:17:20 -06002062 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06002063 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002064
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002065 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002066 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 -06002067 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
2068 FAIL() << "Error received was not 'Num samples mismatch!...'";
2069 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002070}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002071
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002072TEST_F(VkLayerTest, ClearCmdNoDraw)
2073{
2074 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
2075 VkFlags msgFlags;
2076 std::string msgString;
2077 VkResult err;
2078
2079 ASSERT_NO_FATAL_FAILURE(InitState());
2080 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2081 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002082
2083 VkDescriptorTypeCount ds_type_count = {};
2084 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2085 ds_type_count.count = 1;
2086
2087 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2088 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2089 ds_pool_ci.pNext = NULL;
2090 ds_pool_ci.count = 1;
2091 ds_pool_ci.pTypeCount = &ds_type_count;
2092
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002093 VkDescriptorPool ds_pool;
2094 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
2095 ASSERT_VK_SUCCESS(err);
2096
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002097 VkDescriptorSetLayoutBinding dsl_binding = {};
2098 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2099 dsl_binding.arraySize = 1;
2100 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2101 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002102
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002103 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2104 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2105 ds_layout_ci.pNext = NULL;
2106 ds_layout_ci.count = 1;
2107 ds_layout_ci.pBinding = &dsl_binding;
2108
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002109 VkDescriptorSetLayout ds_layout;
2110 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2111 ASSERT_VK_SUCCESS(err);
2112
2113 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002114 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002115 ASSERT_VK_SUCCESS(err);
2116
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002117 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2118 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2119 pipe_ms_state_ci.pNext = NULL;
2120 pipe_ms_state_ci.rasterSamples = 4;
2121 pipe_ms_state_ci.sampleShadingEnable = 0;
2122 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002123 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002124
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002125 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2126 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2127 pipeline_layout_ci.pNext = NULL;
2128 pipeline_layout_ci.descriptorSetCount = 1;
2129 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002130
2131 VkPipelineLayout pipeline_layout;
2132 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2133 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002134
Tony Barbourd7d828b2015-08-06 10:16:07 -06002135 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002136 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2137 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002138 VkPipelineObj pipe(m_device);
2139 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002140 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002141 pipe.SetMSAA(&pipe_ms_state_ci);
2142 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002143
2144 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002145
2146 m_errorMonitor->ClearState();
2147 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
2148 // Also pass down other dummy params to keep driver and paramchecker happy
2149 VkClearColorValue cCV;
Cody Northrop2563a032015-08-25 15:26:38 -06002150 cCV.float32[0] = 1.0;
2151 cCV.float32[1] = 1.0;
2152 cCV.float32[2] = 1.0;
2153 cCV.float32[3] = 1.0;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002154
Tony Barbour1490c912015-07-28 10:17:20 -06002155 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002156 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002157 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 -06002158 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) {
2159 FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'";
2160 }
2161}
2162
Tobin Ehlise4076782015-06-24 15:53:07 -06002163TEST_F(VkLayerTest, VtxBufferBadIndex)
2164{
2165 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
2166 VkFlags msgFlags;
2167 std::string msgString;
2168 VkResult err;
2169
2170 ASSERT_NO_FATAL_FAILURE(InitState());
2171 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2172 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002173
2174 VkDescriptorTypeCount ds_type_count = {};
2175 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2176 ds_type_count.count = 1;
2177
2178 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2179 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2180 ds_pool_ci.pNext = NULL;
2181 ds_pool_ci.count = 1;
2182 ds_pool_ci.pTypeCount = &ds_type_count;
2183
2184 VkDescriptorPool ds_pool;
Tobin Ehlise4076782015-06-24 15:53:07 -06002185 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
2186 ASSERT_VK_SUCCESS(err);
2187
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002188 VkDescriptorSetLayoutBinding dsl_binding = {};
2189 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2190 dsl_binding.arraySize = 1;
2191 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2192 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002193
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002194 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2195 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2196 ds_layout_ci.pNext = NULL;
2197 ds_layout_ci.count = 1;
2198 ds_layout_ci.pBinding = &dsl_binding;
2199
Tobin Ehlise4076782015-06-24 15:53:07 -06002200 VkDescriptorSetLayout ds_layout;
2201 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2202 ASSERT_VK_SUCCESS(err);
2203
2204 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002205 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06002206 ASSERT_VK_SUCCESS(err);
2207
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002208 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2209 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2210 pipe_ms_state_ci.pNext = NULL;
2211 pipe_ms_state_ci.rasterSamples = 1;
2212 pipe_ms_state_ci.sampleShadingEnable = 0;
2213 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002214 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002215
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002216 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2217 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2218 pipeline_layout_ci.pNext = NULL;
2219 pipeline_layout_ci.descriptorSetCount = 1;
2220 pipeline_layout_ci.pSetLayouts = &ds_layout;
2221 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06002222
Tobin Ehlise4076782015-06-24 15:53:07 -06002223 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2224 ASSERT_VK_SUCCESS(err);
2225
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002226 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002227 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2228 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002229 VkPipelineObj pipe(m_device);
2230 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002231 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002232 pipe.SetMSAA(&pipe_ms_state_ci);
2233 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002234
2235 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06002236 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002237 // Don't care about actual data, just need to get to draw to flag error
2238 static const float vbo_data[3] = {1.f, 0.f, 1.f};
2239 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
2240 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
2241 Draw(0, 1, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06002242
2243 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002244 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding Vtx Buffer w/o VBO attached to PSO.";
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002245 if (!strstr(msgString.c_str(),"Vtx Buffer Index 1 was bound, but no vtx buffers are attached to PSO.")) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002246 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
2247 }
2248}
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002249#endif
2250#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06002251#if GTEST_IS_THREADSAFE
2252struct thread_data_struct {
2253 VkCmdBuffer cmdBuffer;
2254 VkEvent event;
2255 bool bailout;
2256};
2257
2258extern "C" void *AddToCommandBuffer(void *arg)
2259{
2260 struct thread_data_struct *data = (struct thread_data_struct *) arg;
2261 std::string msgString;
2262
2263 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06002264 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06002265 if (data->bailout) {
2266 break;
2267 }
2268 }
2269 return NULL;
2270}
2271
2272TEST_F(VkLayerTest, ThreadCmdBufferCollision)
2273{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002274 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06002275 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002276 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06002277
2278 ASSERT_NO_FATAL_FAILURE(InitState());
2279 ASSERT_NO_FATAL_FAILURE(InitViewport());
2280 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2281
Mike Stroyan09aae812015-05-12 16:00:45 -06002282 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06002283 BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002284
2285 VkEventCreateInfo event_info;
2286 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06002287 VkResult err;
2288
2289 memset(&event_info, 0, sizeof(event_info));
2290 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2291
2292 err = vkCreateEvent(device(), &event_info, &event);
2293 ASSERT_VK_SUCCESS(err);
2294
Mike Stroyan09aae812015-05-12 16:00:45 -06002295 err = vkResetEvent(device(), event);
2296 ASSERT_VK_SUCCESS(err);
2297
2298 struct thread_data_struct data;
Tony Barbour1490c912015-07-28 10:17:20 -06002299 data.cmdBuffer = m_cmdBuffer->handle();
Mike Stroyan09aae812015-05-12 16:00:45 -06002300 data.event = event;
2301 data.bailout = false;
2302 m_errorMonitor->SetBailout(&data.bailout);
2303 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002304 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06002305 // Add many entries to command buffer from this thread at the same time.
2306 AddToCommandBuffer(&data);
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002307 test_platform_thread_join(thread, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -06002308 EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002309
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002310 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002311 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 -06002312 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05002313 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06002314 }
2315
2316}
2317#endif
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002318#endif
Chris Forbes5af3bf22015-05-25 11:13:08 +12002319#if SHADER_CHECKER_TESTS
2320TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
2321{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002322 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12002323 std::string msgString;
2324 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002325 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002326 ScopedUseGlsl useGlsl(false);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002327
2328 char const *vsSource =
2329 "#version 140\n"
2330 "#extension GL_ARB_separate_shader_objects: require\n"
2331 "#extension GL_ARB_shading_language_420pack: require\n"
2332 "\n"
2333 "layout(location=0) out float x;\n"
2334 "void main(){\n"
2335 " gl_Position = vec4(1);\n"
2336 " x = 0;\n"
2337 "}\n";
2338 char const *fsSource =
2339 "#version 140\n"
2340 "#extension GL_ARB_separate_shader_objects: require\n"
2341 "#extension GL_ARB_shading_language_420pack: require\n"
2342 "\n"
2343 "layout(location=0) out vec4 color;\n"
2344 "void main(){\n"
2345 " color = vec4(1);\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 Forbes5af3bf22015-05-25 11:13:08 +12002353 pipe.AddShader(&vs);
2354 pipe.AddShader(&fs);
2355
Chris Forbes5af3bf22015-05-25 11:13:08 +12002356 VkDescriptorSetObj descriptorSet(m_device);
2357 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002358 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002359
2360 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002361 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12002362
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002363 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002364
Cody Northrop1684adb2015-08-05 11:15:02 -06002365 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002366 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
2367 FAIL() << "Incorrect warning: " << msgString;
2368 }
2369}
Chris Forbes5af3bf22015-05-25 11:13:08 +12002370
Chris Forbes3c10b852015-05-25 11:13:13 +12002371TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
2372{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002373 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12002374 std::string msgString;
2375 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002376 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002377 ScopedUseGlsl useGlsl(false);
Chris Forbes3c10b852015-05-25 11:13:13 +12002378
2379 char const *vsSource =
2380 "#version 140\n"
2381 "#extension GL_ARB_separate_shader_objects: require\n"
2382 "#extension GL_ARB_shading_language_420pack: require\n"
2383 "\n"
2384 "void main(){\n"
2385 " gl_Position = vec4(1);\n"
2386 "}\n";
2387 char const *fsSource =
2388 "#version 140\n"
2389 "#extension GL_ARB_separate_shader_objects: require\n"
2390 "#extension GL_ARB_shading_language_420pack: require\n"
2391 "\n"
2392 "layout(location=0) in float x;\n"
2393 "layout(location=0) out vec4 color;\n"
2394 "void main(){\n"
2395 " color = vec4(x);\n"
2396 "}\n";
2397
2398 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2399 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2400
2401 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002402 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12002403 pipe.AddShader(&vs);
2404 pipe.AddShader(&fs);
2405
Chris Forbes3c10b852015-05-25 11:13:13 +12002406 VkDescriptorSetObj descriptorSet(m_device);
2407 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002408 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12002409
2410 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002411 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12002412
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002413 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12002414
Cody Northrop1684adb2015-08-05 11:15:02 -06002415 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes3c10b852015-05-25 11:13:13 +12002416 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
2417 FAIL() << "Incorrect error: " << msgString;
2418 }
2419}
2420
Chris Forbescc281692015-05-25 11:13:17 +12002421TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
2422{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002423 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12002424 std::string msgString;
2425 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002426 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002427 ScopedUseGlsl useGlsl(false);
Chris Forbescc281692015-05-25 11:13:17 +12002428
2429 char const *vsSource =
2430 "#version 140\n"
2431 "#extension GL_ARB_separate_shader_objects: require\n"
2432 "#extension GL_ARB_shading_language_420pack: require\n"
2433 "\n"
2434 "layout(location=0) out int x;\n"
2435 "void main(){\n"
2436 " x = 0;\n"
2437 " gl_Position = vec4(1);\n"
2438 "}\n";
2439 char const *fsSource =
2440 "#version 140\n"
2441 "#extension GL_ARB_separate_shader_objects: require\n"
2442 "#extension GL_ARB_shading_language_420pack: require\n"
2443 "\n"
2444 "layout(location=0) in float x;\n" /* VS writes int */
2445 "layout(location=0) out vec4 color;\n"
2446 "void main(){\n"
2447 " color = vec4(x);\n"
2448 "}\n";
2449
2450 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2451 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2452
2453 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002454 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12002455 pipe.AddShader(&vs);
2456 pipe.AddShader(&fs);
2457
Chris Forbescc281692015-05-25 11:13:17 +12002458 VkDescriptorSetObj descriptorSet(m_device);
2459 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002460 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12002461
2462 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002463 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12002464
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002465 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12002466
Cody Northrop1684adb2015-08-05 11:15:02 -06002467 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbescc281692015-05-25 11:13:17 +12002468 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
2469 FAIL() << "Incorrect error: " << msgString;
2470 }
2471}
2472
Chris Forbes8291c052015-05-25 11:13:28 +12002473TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
2474{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002475 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12002476 std::string msgString;
2477 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002478 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002479 ScopedUseGlsl useGlsl(false);
Chris Forbes8291c052015-05-25 11:13:28 +12002480
2481 VkVertexInputBindingDescription input_binding;
2482 memset(&input_binding, 0, sizeof(input_binding));
2483
2484 VkVertexInputAttributeDescription input_attrib;
2485 memset(&input_attrib, 0, sizeof(input_attrib));
2486 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2487
2488 char const *vsSource =
2489 "#version 140\n"
2490 "#extension GL_ARB_separate_shader_objects: require\n"
2491 "#extension GL_ARB_shading_language_420pack: require\n"
2492 "\n"
2493 "void main(){\n"
2494 " gl_Position = vec4(1);\n"
2495 "}\n";
2496 char const *fsSource =
2497 "#version 140\n"
2498 "#extension GL_ARB_separate_shader_objects: require\n"
2499 "#extension GL_ARB_shading_language_420pack: require\n"
2500 "\n"
2501 "layout(location=0) out vec4 color;\n"
2502 "void main(){\n"
2503 " color = vec4(1);\n"
2504 "}\n";
2505
2506 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2507 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2508
2509 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002510 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12002511 pipe.AddShader(&vs);
2512 pipe.AddShader(&fs);
2513
2514 pipe.AddVertexInputBindings(&input_binding, 1);
2515 pipe.AddVertexInputAttribs(&input_attrib, 1);
2516
Chris Forbes8291c052015-05-25 11:13:28 +12002517 VkDescriptorSetObj descriptorSet(m_device);
2518 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002519 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12002520
2521 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002522 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12002523
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002524 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12002525
Cody Northrop1684adb2015-08-05 11:15:02 -06002526 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12002527 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
2528 FAIL() << "Incorrect warning: " << msgString;
2529 }
2530}
2531
Chris Forbes37367e62015-05-25 11:13:29 +12002532TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
2533{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002534 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12002535 std::string msgString;
2536 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002537 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002538 ScopedUseGlsl useGlsl(false);
Chris Forbes37367e62015-05-25 11:13:29 +12002539
2540 char const *vsSource =
2541 "#version 140\n"
2542 "#extension GL_ARB_separate_shader_objects: require\n"
2543 "#extension GL_ARB_shading_language_420pack: require\n"
2544 "\n"
2545 "layout(location=0) in vec4 x;\n" /* not provided */
2546 "void main(){\n"
2547 " gl_Position = x;\n"
2548 "}\n";
2549 char const *fsSource =
2550 "#version 140\n"
2551 "#extension GL_ARB_separate_shader_objects: require\n"
2552 "#extension GL_ARB_shading_language_420pack: require\n"
2553 "\n"
2554 "layout(location=0) out vec4 color;\n"
2555 "void main(){\n"
2556 " color = vec4(1);\n"
2557 "}\n";
2558
2559 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2560 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2561
2562 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002563 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12002564 pipe.AddShader(&vs);
2565 pipe.AddShader(&fs);
2566
Chris Forbes37367e62015-05-25 11:13:29 +12002567 VkDescriptorSetObj descriptorSet(m_device);
2568 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002569 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12002570
2571 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002572 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12002573
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002574 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12002575
Cody Northrop1684adb2015-08-05 11:15:02 -06002576 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes37367e62015-05-25 11:13:29 +12002577 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
2578 FAIL() << "Incorrect warning: " << msgString;
2579 }
2580}
2581
Chris Forbesa4b02322015-05-25 11:13:31 +12002582TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
2583{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002584 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12002585 std::string msgString;
2586 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002588 ScopedUseGlsl useGlsl(false);
Chris Forbesa4b02322015-05-25 11:13:31 +12002589
2590 VkVertexInputBindingDescription input_binding;
2591 memset(&input_binding, 0, sizeof(input_binding));
2592
2593 VkVertexInputAttributeDescription input_attrib;
2594 memset(&input_attrib, 0, sizeof(input_attrib));
2595 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2596
2597 char const *vsSource =
2598 "#version 140\n"
2599 "#extension GL_ARB_separate_shader_objects: require\n"
2600 "#extension GL_ARB_shading_language_420pack: require\n"
2601 "\n"
2602 "layout(location=0) in int x;\n" /* attrib provided float */
2603 "void main(){\n"
2604 " gl_Position = vec4(x);\n"
2605 "}\n";
2606 char const *fsSource =
2607 "#version 140\n"
2608 "#extension GL_ARB_separate_shader_objects: require\n"
2609 "#extension GL_ARB_shading_language_420pack: require\n"
2610 "\n"
2611 "layout(location=0) out vec4 color;\n"
2612 "void main(){\n"
2613 " color = vec4(1);\n"
2614 "}\n";
2615
2616 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2617 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2618
2619 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002620 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12002621 pipe.AddShader(&vs);
2622 pipe.AddShader(&fs);
2623
2624 pipe.AddVertexInputBindings(&input_binding, 1);
2625 pipe.AddVertexInputAttribs(&input_attrib, 1);
2626
Chris Forbesa4b02322015-05-25 11:13:31 +12002627 VkDescriptorSetObj descriptorSet(m_device);
2628 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002629 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12002630
2631 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002632 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12002633
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002634 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12002635
Cody Northrop1684adb2015-08-05 11:15:02 -06002636 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa4b02322015-05-25 11:13:31 +12002637 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
2638 FAIL() << "Incorrect error: " << msgString;
2639 }
2640}
2641
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002642TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
2643{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002644 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002645 std::string msgString;
2646 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002648 ScopedUseGlsl useGlsl(false);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002649
2650 /* Two binding descriptions for binding 0 */
2651 VkVertexInputBindingDescription input_bindings[2];
2652 memset(input_bindings, 0, sizeof(input_bindings));
2653
2654 VkVertexInputAttributeDescription input_attrib;
2655 memset(&input_attrib, 0, sizeof(input_attrib));
2656 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2657
2658 char const *vsSource =
2659 "#version 140\n"
2660 "#extension GL_ARB_separate_shader_objects: require\n"
2661 "#extension GL_ARB_shading_language_420pack: require\n"
2662 "\n"
2663 "layout(location=0) in float x;\n" /* attrib provided float */
2664 "void main(){\n"
2665 " gl_Position = vec4(x);\n"
2666 "}\n";
2667 char const *fsSource =
2668 "#version 140\n"
2669 "#extension GL_ARB_separate_shader_objects: require\n"
2670 "#extension GL_ARB_shading_language_420pack: require\n"
2671 "\n"
2672 "layout(location=0) out vec4 color;\n"
2673 "void main(){\n"
2674 " color = vec4(1);\n"
2675 "}\n";
2676
2677 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2678 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2679
2680 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002681 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002682 pipe.AddShader(&vs);
2683 pipe.AddShader(&fs);
2684
2685 pipe.AddVertexInputBindings(input_bindings, 2);
2686 pipe.AddVertexInputAttribs(&input_attrib, 1);
2687
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002688 VkDescriptorSetObj descriptorSet(m_device);
2689 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002690 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002691
2692 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002693 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002694
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002695 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002696
Cody Northrop1684adb2015-08-05 11:15:02 -06002697 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002698 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
2699 FAIL() << "Incorrect error: " << msgString;
2700 }
2701}
Chris Forbes4c948702015-05-25 11:13:32 +12002702
Chris Forbesc12ef122015-05-25 11:13:40 +12002703/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
2704 * rejects it. */
2705
2706TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
2707{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002708 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12002709 std::string msgString;
2710 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002711 ScopedUseGlsl useGlsl(false);
Chris Forbesc12ef122015-05-25 11:13:40 +12002712
2713 char const *vsSource =
2714 "#version 140\n"
2715 "#extension GL_ARB_separate_shader_objects: require\n"
2716 "#extension GL_ARB_shading_language_420pack: require\n"
2717 "\n"
2718 "void main(){\n"
2719 " gl_Position = vec4(1);\n"
2720 "}\n";
2721 char const *fsSource =
2722 "#version 140\n"
2723 "#extension GL_ARB_separate_shader_objects: require\n"
2724 "#extension GL_ARB_shading_language_420pack: require\n"
2725 "\n"
2726 "void main(){\n"
2727 "}\n";
2728
2729 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2730 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2731
2732 VkPipelineObj pipe(m_device);
2733 pipe.AddShader(&vs);
2734 pipe.AddShader(&fs);
2735
Chia-I Wuc278df82015-07-07 11:50:03 +08002736 /* set up CB 0, not written */
2737 pipe.AddColorAttachment();
2738 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12002739
Chris Forbesc12ef122015-05-25 11:13:40 +12002740 VkDescriptorSetObj descriptorSet(m_device);
2741 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002742 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12002743
2744 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002745 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12002746
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002747 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12002748
Cody Northrop1684adb2015-08-05 11:15:02 -06002749 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc12ef122015-05-25 11:13:40 +12002750 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
2751 FAIL() << "Incorrect error: " << msgString;
2752 }
2753}
2754
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002755TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
2756{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002757 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002758 std::string msgString;
2759 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002760 ScopedUseGlsl useGlsl(false);
Chris Forbes5d15a4f2015-05-25 11:13:43 +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 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
2777 "void main(){\n"
2778 " x = vec4(1);\n"
2779 " y = vec4(1);\n"
2780 "}\n";
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 VkPipelineObj pipe(m_device);
2786 pipe.AddShader(&vs);
2787 pipe.AddShader(&fs);
2788
Chia-I Wuc278df82015-07-07 11:50:03 +08002789 /* set up CB 0, not written */
2790 pipe.AddColorAttachment();
2791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002792 /* FS writes CB 1, but we don't configure it */
2793
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002794 VkDescriptorSetObj descriptorSet(m_device);
2795 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002796 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002797
2798 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002799 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002800
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002801 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002802
Cody Northrop1684adb2015-08-05 11:15:02 -06002803 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002804 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
2805 FAIL() << "Incorrect warning: " << msgString;
2806 }
2807}
2808
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002809TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
2810{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002811 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002812 std::string msgString;
2813 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002814 ScopedUseGlsl useGlsl(false);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002815
2816 char const *vsSource =
2817 "#version 140\n"
2818 "#extension GL_ARB_separate_shader_objects: require\n"
2819 "#extension GL_ARB_shading_language_420pack: require\n"
2820 "\n"
2821 "void main(){\n"
2822 " gl_Position = vec4(1);\n"
2823 "}\n";
2824 char const *fsSource =
2825 "#version 140\n"
2826 "#extension GL_ARB_separate_shader_objects: require\n"
2827 "#extension GL_ARB_shading_language_420pack: require\n"
2828 "\n"
2829 "layout(location=0) out ivec4 x;\n" /* not UNORM */
2830 "void main(){\n"
2831 " x = ivec4(1);\n"
2832 "}\n";
2833
2834 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2835 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2836
2837 VkPipelineObj pipe(m_device);
2838 pipe.AddShader(&vs);
2839 pipe.AddShader(&fs);
2840
Chia-I Wuc278df82015-07-07 11:50:03 +08002841 /* set up CB 0; type is UNORM by default */
2842 pipe.AddColorAttachment();
2843 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002844
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002845 VkDescriptorSetObj descriptorSet(m_device);
2846 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002847 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002848
2849 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002850 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002851
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002852 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002853
Cody Northrop1684adb2015-08-05 11:15:02 -06002854 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002855 if (!strstr(msgString.c_str(),"does not match FS output type")) {
2856 FAIL() << "Incorrect error: " << msgString;
2857 }
2858}
Chris Forbesc2050732015-06-05 14:43:36 +12002859
2860TEST_F(VkLayerTest, CreatePipelineNonSpirvShader)
2861{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002862 VkFlags msgFlags;
Chris Forbesc2050732015-06-05 14:43:36 +12002863 std::string msgString;
2864 ASSERT_NO_FATAL_FAILURE(InitState());
2865 /* Intentionally provided GLSL rather than compiling to SPIRV first */
Cody Northrop1cfbd172015-06-03 16:49:20 -06002866 ScopedUseGlsl useGlsl(true);
Chris Forbesc2050732015-06-05 14:43:36 +12002867
2868 char const *vsSource =
2869 "#version 140\n"
2870 "#extension GL_ARB_separate_shader_objects: require\n"
2871 "#extension GL_ARB_shading_language_420pack: require\n"
2872 "\n"
2873 "void main(){\n"
2874 " gl_Position = vec4(1);\n"
2875 "}\n";
2876 char const *fsSource =
2877 "#version 140\n"
2878 "#extension GL_ARB_separate_shader_objects: require\n"
2879 "#extension GL_ARB_shading_language_420pack: require\n"
2880 "\n"
2881 "layout(location=0) out vec4 x;\n"
2882 "void main(){\n"
2883 " x = vec4(1);\n"
2884 "}\n";
2885
2886 m_errorMonitor->ClearState();
2887
2888 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2889 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2890
2891
2892 VkPipelineObj pipe(m_device);
2893 pipe.AddShader(&vs);
2894 pipe.AddShader(&fs);
2895
Chia-I Wuc278df82015-07-07 11:50:03 +08002896 /* set up CB 0; type is UNORM by default */
2897 pipe.AddColorAttachment();
2898 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc2050732015-06-05 14:43:36 +12002899
Chris Forbesc2050732015-06-05 14:43:36 +12002900 VkDescriptorSetObj descriptorSet(m_device);
2901 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002902 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc2050732015-06-05 14:43:36 +12002903
Tony Barboured132432015-08-04 16:23:11 -06002904 VkResult res = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc2050732015-06-05 14:43:36 +12002905 /* pipeline creation should have succeeded */
2906 ASSERT_EQ(VK_SUCCESS, res);
2907
2908 /* should have emitted a warning: the shader is not SPIRV, so we're
2909 * not going to be able to analyze it */
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002910 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002911 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesc2050732015-06-05 14:43:36 +12002912 if (!strstr(msgString.c_str(),"is not SPIR-V")) {
2913 FAIL() << "Incorrect warning: " << msgString;
2914 }
2915}
Chris Forbes01c9db72015-06-04 09:25:25 +12002916#endif
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002917
Tony Barbour30486ea2015-04-07 13:44:53 -06002918int main(int argc, char **argv) {
2919 int result;
2920
2921 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06002922 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06002923
2924 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
2925
2926 result = RUN_ALL_TESTS();
2927
Tony Barbour01999182015-04-09 12:58:51 -06002928 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06002929 return result;
2930}