blob: eeeee3264e26e32c950edf38c84369df792e5693 [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"
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06006#include "../icd/common/icd-spv.h"
Tony Barbour30486ea2015-04-07 13:44:53 -06007
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05008#define GLM_FORCE_RADIANS
9#include "glm/glm.hpp"
10#include <glm/gtc/matrix_transform.hpp>
11
Tobin Ehlis57e6a612015-05-26 16:11:58 -060012#define MEM_TRACKER_TESTS 1
13#define OBJ_TRACKER_TESTS 1
14#define DRAW_STATE_TESTS 1
15#define THREADING_TESTS 1
Chris Forbes5af3bf22015-05-25 11:13:08 +120016#define SHADER_CHECKER_TESTS 1
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -060017#define DEVICE_LIMITS_TESTS 1
Tobin Ehlis57e6a612015-05-26 16:11:58 -060018
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050019//--------------------------------------------------------------------------------------
20// Mesh and VertexFormat Data
21//--------------------------------------------------------------------------------------
22struct Vertex
23{
24 float posX, posY, posZ, posW; // Position data
25 float r, g, b, a; // Color
26};
27
28#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
29
30typedef enum _BsoFailSelect {
31 BsoFailNone = 0x00000000,
Cody Northrope4bc6942015-08-26 10:01:32 -060032 BsoFailLineWidth = 0x00000001,
33 BsoFailDepthBias = 0x00000002,
Cody Northropf5bd2252015-08-17 11:10:49 -060034 BsoFailViewport = 0x00000004,
Cody Northrope4bc6942015-08-26 10:01:32 -060035 BsoFailBlend = 0x00000008,
36 BsoFailDepthBounds = 0x00000010,
Cody Northrop2605cb02015-08-18 15:21:16 -060037 BsoFailStencil = 0x00000020,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050038} BsoFailSelect;
39
40struct vktriangle_vs_uniform {
41 // Must start with MVP
42 float mvp[4][4];
43 float position[3][4];
44 float color[3][4];
45};
46
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050047static const char bindStateVertShaderText[] =
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050048 "#version 130\n"
49 "vec2 vertices[3];\n"
50 "void main() {\n"
51 " vertices[0] = vec2(-1.0, -1.0);\n"
52 " vertices[1] = vec2( 1.0, -1.0);\n"
53 " vertices[2] = vec2( 0.0, 1.0);\n"
54 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
55 "}\n";
56
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050057static const char bindStateFragShaderText[] =
Cody Northrop74a2d2c2015-06-16 17:32:04 -060058 "#version 140\n"
59 "#extension GL_ARB_separate_shader_objects: require\n"
60 "#extension GL_ARB_shading_language_420pack: require\n"
61 "\n"
62 "layout(location = 0) out vec4 uFragColor;\n"
63 "void main(){\n"
64 " uFragColor = vec4(0,1,0,1);\n"
65 "}\n";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050066
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -060067static VkBool32 myDbgFunc(
Tony Barboure84a8d62015-07-10 14:10:27 -060068 VkFlags msgFlags,
69 VkDbgObjectType objType,
70 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060071 size_t location,
72 int32_t msgCode,
73 const char* pLayerPrefix,
74 const char* pMsg,
75 void* pUserData);
Tony Barbour30486ea2015-04-07 13:44:53 -060076
77class ErrorMonitor {
78public:
Tony Barbour0c1bdc62015-04-29 17:34:29 -060079 ErrorMonitor()
Tony Barbour30486ea2015-04-07 13:44:53 -060080 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060081 test_platform_thread_create_mutex(&m_mutex);
82 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060083 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mike Stroyan09aae812015-05-12 16:00:45 -060084 m_bailout = NULL;
Mike Stroyan7016f4f2015-07-13 14:45:35 -060085 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060086 }
87 void ClearState()
88 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060089 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060090 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -060091 m_msgString.clear();
Mike Stroyan7016f4f2015-07-13 14:45:35 -060092 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060093 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060094 VkFlags GetState(std::string *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -060095 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060096 test_platform_thread_lock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060097 *msgString = m_msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -060098 test_platform_thread_unlock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060099 return m_msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600100 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600101 void SetState(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -0600102 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600103 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600104 if (m_bailout != NULL) {
105 *m_bailout = true;
106 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600107 m_msgFlags = msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600108 m_msgString.reserve(strlen(msgString));
109 m_msgString = msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600110 test_platform_thread_unlock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600111 }
112 void SetBailout(bool *bailout)
113 {
114 m_bailout = bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600115 }
116
117private:
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600118 VkFlags m_msgFlags;
119 std::string m_msgString;
120 test_platform_thread_mutex m_mutex;
121 bool* m_bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600122};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500123
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600124static VkBool32 myDbgFunc(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600125 VkFlags msgFlags,
Tony Barboure84a8d62015-07-10 14:10:27 -0600126 VkDbgObjectType objType,
127 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600128 size_t location,
129 int32_t msgCode,
130 const char* pLayerPrefix,
131 const char* pMsg,
132 void* pUserData)
Tony Barbour30486ea2015-04-07 13:44:53 -0600133{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600134 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour8508b8e2015-04-09 10:48:04 -0600135 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600136 errMonitor->SetState(msgFlags, pMsg);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600137 return true;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600138 }
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600139
140 return false;
Tony Barbour30486ea2015-04-07 13:44:53 -0600141}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500142
Tony Barbour01999182015-04-09 12:58:51 -0600143class VkLayerTest : public VkRenderFramework
Tony Barbour30486ea2015-04-07 13:44:53 -0600144{
145public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600146 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
147 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500148 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
149 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbour1490c912015-07-28 10:17:20 -0600150 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
151 { GenericDrawPreparation(m_cmdBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600152
Tony Barbour1490c912015-07-28 10:17:20 -0600153 /* Convenience functions that use built-in command buffer */
154 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_cmdBuffer); }
155 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_cmdBuffer); }
156 void Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
157 { m_cmdBuffer->Draw(firstVertex, vertexCount, firstInstance, instanceCount); }
158 void DrawIndexed(uint32_t firstVertex, uint32_t vertexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
159 { m_cmdBuffer->DrawIndexed(firstVertex, vertexCount, vertexOffset,firstInstance, instanceCount); }
160 void QueueCommandBuffer() { m_cmdBuffer->QueueCommandBuffer(); }
161 void QueueCommandBuffer(const VkFence& fence) { m_cmdBuffer->QueueCommandBuffer(fence); }
162 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
163 { m_cmdBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
164 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
165 { m_cmdBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600166protected:
Tony Barbour01999182015-04-09 12:58:51 -0600167 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600168
169 virtual void SetUp() {
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600170 std::vector<const char *> instance_layer_names;
171 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600172 std::vector<const char *> instance_extension_names;
173 std::vector<const char *> device_extension_names;
Tony Barbour950ebc02015-04-23 12:55:36 -0600174
Courtney Goeltzenleuchter846298c2015-07-30 11:32:46 -0600175 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600176 /*
177 * Since CreateDbgMsgCallback is an instance level extension call
178 * any extension / layer that utilizes that feature also needs
179 * to be enabled at create instance time.
180 */
Mike Stroyaned254572015-06-17 16:32:06 -0600181 // Use Threading layer first to protect others from ThreadCmdBufferCollision test
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600182 instance_layer_names.push_back("Threading");
183 instance_layer_names.push_back("ObjectTracker");
184 instance_layer_names.push_back("MemTracker");
185 instance_layer_names.push_back("DrawState");
186 instance_layer_names.push_back("ShaderChecker");
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600187 instance_layer_names.push_back("DeviceLimits");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600188
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600189 device_layer_names.push_back("Threading");
190 device_layer_names.push_back("ObjectTracker");
191 device_layer_names.push_back("MemTracker");
192 device_layer_names.push_back("DrawState");
193 device_layer_names.push_back("ShaderChecker");
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600194 device_layer_names.push_back("DeviceLimits");
Tony Barbour30486ea2015-04-07 13:44:53 -0600195
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600196 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -0600197 this->app_info.pNext = NULL;
198 this->app_info.pAppName = "layer_tests";
199 this->app_info.appVersion = 1;
200 this->app_info.pEngineName = "unittest";
201 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600202 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -0600203
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600204 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600205 InitFramework(instance_layer_names, device_layer_names,
206 instance_extension_names, device_extension_names,
207 myDbgFunc, m_errorMonitor);
Tony Barbour30486ea2015-04-07 13:44:53 -0600208 }
209
210 virtual void TearDown() {
211 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600212 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600213 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600214 }
215};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500216
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600217VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600218{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600219 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600220
221 result = cmdBuffer.BeginCommandBuffer();
222
223 /*
224 * For render test all drawing happens in a single render pass
225 * on a single command buffer.
226 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200227 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wuc278df82015-07-07 11:50:03 +0800228 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour30486ea2015-04-07 13:44:53 -0600229 }
230
231 return result;
232}
233
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600234VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600235{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600236 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600237
Chris Forbesfe133ef2015-06-16 14:05:59 +1200238 if (renderPass()) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800239 cmdBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200240 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600241
242 result = cmdBuffer.EndCommandBuffer();
243
244 return result;
245}
246
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500247void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
248{
249 // Create identity matrix
250 int i;
251 struct vktriangle_vs_uniform data;
252
253 glm::mat4 Projection = glm::mat4(1.0f);
254 glm::mat4 View = glm::mat4(1.0f);
255 glm::mat4 Model = glm::mat4(1.0f);
256 glm::mat4 MVP = Projection * View * Model;
257 const int matrixSize = sizeof(MVP);
258 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
259
260 memcpy(&data.mvp, &MVP[0][0], matrixSize);
261
262 static const Vertex tri_data[] =
263 {
264 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
265 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
266 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
267 };
268
269 for (i=0; i<3; i++) {
270 data.position[i][0] = tri_data[i].posX;
271 data.position[i][1] = tri_data[i].posY;
272 data.position[i][2] = tri_data[i].posZ;
273 data.position[i][3] = tri_data[i].posW;
274 data.color[i][0] = tri_data[i].r;
275 data.color[i][1] = tri_data[i].g;
276 data.color[i][2] = tri_data[i].b;
277 data.color[i][3] = tri_data[i].a;
278 }
279
280 ASSERT_NO_FATAL_FAILURE(InitState());
281 ASSERT_NO_FATAL_FAILURE(InitViewport());
282
283 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
284
285 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
286 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
287
288 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800289 pipelineobj.AddColorAttachment();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500290 pipelineobj.AddShader(&vs);
291 pipelineobj.AddShader(&ps);
292
293 VkDescriptorSetObj descriptorSet(m_device);
294 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
295
296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600297 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500298
Tony Barbour1490c912015-07-28 10:17:20 -0600299 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500300
301 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -0600302 Draw(0, 3, 0, 1);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500303
304 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600305 EndCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500306
Tony Barbour1490c912015-07-28 10:17:20 -0600307 QueueCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500308}
309
310void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
311{
312 if (m_depthStencil->Initialized()) {
313 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
314 } else {
315 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
316 }
317
318 cmdBuffer->PrepareAttachments();
Cody Northrope4bc6942015-08-26 10:01:32 -0600319 if ((failMask & BsoFailLineWidth) != BsoFailLineWidth) {
320 cmdBuffer->BindDynamicLineWidthState(m_stateLineWidth);
Cody Northropf5bd2252015-08-17 11:10:49 -0600321 }
Cody Northrope4bc6942015-08-26 10:01:32 -0600322 if ((failMask & BsoFailDepthBias) != BsoFailDepthBias) {
323 cmdBuffer->BindDynamicDepthBiasState(m_stateDepthBias);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500324 }
325 if ((failMask & BsoFailViewport) != BsoFailViewport) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600326 cmdBuffer->BindDynamicViewportState(m_stateViewport);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500327 }
Cody Northrope4bc6942015-08-26 10:01:32 -0600328 if ((failMask & BsoFailBlend) != BsoFailBlend) {
329 cmdBuffer->BindDynamicBlendState(m_stateBlend);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500330 }
Cody Northrope4bc6942015-08-26 10:01:32 -0600331 if ((failMask & BsoFailDepthBounds) != BsoFailDepthBounds) {
332 cmdBuffer->BindDynamicDepthBoundsState(m_stateDepthBounds);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500333 }
Cody Northrop2605cb02015-08-18 15:21:16 -0600334 if ((failMask & BsoFailStencil) != BsoFailStencil) {
335 cmdBuffer->BindDynamicStencilState(m_stateStencil);
336 }
337 // Make sure depthWriteEnable is set so that Depth fail test will work correctly
338 // Make sure stencilTestEnable is set so that Stencil fail test will work correctly
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600339 VkStencilOpState stencil = {};
340 stencil.stencilFailOp = VK_STENCIL_OP_KEEP;
341 stencil.stencilPassOp = VK_STENCIL_OP_KEEP;
342 stencil.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
343 stencil.stencilCompareOp = VK_COMPARE_OP_NEVER;
344
345 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
346 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
347 ds_ci.pNext = NULL;
348 ds_ci.depthTestEnable = VK_FALSE;
349 ds_ci.depthWriteEnable = VK_TRUE;
350 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
Cody Northrope4bc6942015-08-26 10:01:32 -0600351 ds_ci.depthBoundsTestEnable = VK_FALSE;
Cody Northrop2605cb02015-08-18 15:21:16 -0600352 ds_ci.stencilTestEnable = VK_TRUE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600353 ds_ci.front = stencil;
354 ds_ci.back = stencil;
355
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600356 pipelineobj.SetDepthStencil(&ds_ci);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500357 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Cody Northropccfa96d2015-08-27 10:20:35 -0600358 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
359 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500360 cmdBuffer->BindPipeline(pipelineobj);
361 cmdBuffer->BindDescriptorSet(descriptorSet);
362}
363
364// ********************************************************************************************************************
365// ********************************************************************************************************************
366// ********************************************************************************************************************
367// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600368#if MEM_TRACKER_TESTS
Mark Lobodzinski81078192015-05-19 10:28:29 -0500369TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
370{
371 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600372 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500373 std::string msgString;
374
375 VkFenceCreateInfo fenceInfo = {};
376 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
377 fenceInfo.pNext = NULL;
378 fenceInfo.flags = 0;
379
380 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barboure389b882015-07-20 13:00:10 -0600381
382 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
383 vk_testing::Buffer buffer;
384 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500385
Tony Barbour1490c912015-07-28 10:17:20 -0600386 BeginCommandBuffer();
387 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
388 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500389
390 testFence.init(*m_device, fenceInfo);
391
392 // Bypass framework since it does the waits automatically
393 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600394 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500395 ASSERT_VK_SUCCESS( err );
396
397 m_errorMonitor->ClearState();
398 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600399 vkResetCommandBuffer(m_cmdBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500400
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600401 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600402 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 -0500403 if (!strstr(msgString.c_str(),"Resetting CB")) {
404 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
405 }
406}
407
408TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion)
409{
410 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600411 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500412 std::string msgString;
413
414 VkFenceCreateInfo fenceInfo = {};
415 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
416 fenceInfo.pNext = NULL;
417 fenceInfo.flags = 0;
418
419 ASSERT_NO_FATAL_FAILURE(InitState());
420 ASSERT_NO_FATAL_FAILURE(InitViewport());
421 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
422
Tony Barbour1490c912015-07-28 10:17:20 -0600423 BeginCommandBuffer();
424 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
425 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500426
427 testFence.init(*m_device, fenceInfo);
428
429 // Bypass framework since it does the waits automatically
430 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600431 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500432 ASSERT_VK_SUCCESS( err );
433
434 m_errorMonitor->ClearState();
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600435
436 VkCmdBufferBeginInfo info = {};
437 info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT | VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
438 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
439 info.renderPass = VK_NULL_HANDLE;
440 info.subpass = 0;
441 info.framebuffer = VK_NULL_HANDLE;
442
443 // Introduce failure by calling BCB again before checking fence
444 vkBeginCommandBuffer(m_cmdBuffer->handle(), &info);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500445
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600446 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600447 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 -0500448 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
449 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
450 }
451}
452
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500453TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
454{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600455 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500456 std::string msgString;
457 VkResult err;
458
459 ASSERT_NO_FATAL_FAILURE(InitState());
460 m_errorMonitor->ClearState();
461
462 // Create an image, allocate memory, free it, and then try to bind it
463 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500464 VkDeviceMemory mem;
465 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500466
467 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
468 const int32_t tex_width = 32;
469 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500470
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600471 VkImageCreateInfo image_create_info = {};
472 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
473 image_create_info.pNext = NULL;
474 image_create_info.imageType = VK_IMAGE_TYPE_2D;
475 image_create_info.format = tex_format;
476 image_create_info.extent.width = tex_width;
477 image_create_info.extent.height = tex_height;
478 image_create_info.extent.depth = 1;
479 image_create_info.mipLevels = 1;
480 image_create_info.arraySize = 1;
481 image_create_info.samples = 1;
482 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
483 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
484 image_create_info.flags = 0;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600485
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600486 VkMemoryAllocInfo mem_alloc = {};
487 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
488 mem_alloc.pNext = NULL;
489 mem_alloc.allocationSize = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500490 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600491 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500492
493 err = vkCreateImage(m_device->device(), &image_create_info, &image);
494 ASSERT_VK_SUCCESS(err);
495
Tony Barboure84a8d62015-07-10 14:10:27 -0600496 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500497 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500498 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500499 ASSERT_VK_SUCCESS(err);
500
Mark Lobodzinski23182612015-05-29 09:32:35 -0500501 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500502
Mike Stroyand72da752015-08-04 10:49:29 -0600503 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 -0600504 if(err != VK_SUCCESS) // If we can't find any unmappable memory this test doesn't make sense
505 return;
Mike Stroyand72da752015-08-04 10:49:29 -0600506
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500507 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500508 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500509 ASSERT_VK_SUCCESS(err);
510
511 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600512 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500513 ASSERT_VK_SUCCESS(err);
514
515 // Map memory as if to initialize the image
516 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500517 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500518
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600519 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600520 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 -0500521 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
522 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
523 }
524}
525
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600526// TODO : Is this test still valid. Not sure it is with updates to memory binding model
527// Verify and delete the test of fix the check
528//TEST_F(VkLayerTest, FreeBoundMemory)
529//{
530// VkFlags msgFlags;
531// std::string msgString;
532// VkResult err;
533//
534// ASSERT_NO_FATAL_FAILURE(InitState());
535// m_errorMonitor->ClearState();
536//
537// // Create an image, allocate memory, free it, and then try to bind it
538// VkImage image;
539// VkDeviceMemory mem;
540// VkMemoryRequirements mem_reqs;
541//
542// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
543// const int32_t tex_width = 32;
544// const int32_t tex_height = 32;
545//
546// const VkImageCreateInfo image_create_info = {
547// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
548// .pNext = NULL,
549// .imageType = VK_IMAGE_TYPE_2D,
550// .format = tex_format,
551// .extent = { tex_width, tex_height, 1 },
552// .mipLevels = 1,
553// .arraySize = 1,
554// .samples = 1,
555// .tiling = VK_IMAGE_TILING_LINEAR,
556// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
557// .flags = 0,
558// };
559// VkMemoryAllocInfo mem_alloc = {
560// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
561// .pNext = NULL,
562// .allocationSize = 0,
563// .memoryTypeIndex = 0,
564// };
565//
566// err = vkCreateImage(m_device->device(), &image_create_info, &image);
567// ASSERT_VK_SUCCESS(err);
568//
569// err = vkGetImageMemoryRequirements(m_device->device(),
570// image,
571// &mem_reqs);
572// ASSERT_VK_SUCCESS(err);
573//
574// mem_alloc.allocationSize = mem_reqs.size;
575//
576// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
577// ASSERT_VK_SUCCESS(err);
578//
579// // allocate memory
580// err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
581// ASSERT_VK_SUCCESS(err);
582//
583// // Bind memory to Image object
584// err = vkBindImageMemory(m_device->device(), image, mem, 0);
585// ASSERT_VK_SUCCESS(err);
586//
587// // Introduce validation failure, free memory while still bound to object
588// vkFreeMemory(m_device->device(), mem);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600589// msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600590//
Cody Northrop1684adb2015-08-05 11:15:02 -0600591// 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 -0600592// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
593// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
594// }
595//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500596
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500597TEST_F(VkLayerTest, RebindMemory)
598{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600599 VkFlags msgFlags;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500600 std::string msgString;
601 VkResult err;
602
603 ASSERT_NO_FATAL_FAILURE(InitState());
604 m_errorMonitor->ClearState();
605
606 // Create an image, allocate memory, free it, and then try to bind it
607 VkImage image;
608 VkDeviceMemory mem1;
609 VkDeviceMemory mem2;
610 VkMemoryRequirements mem_reqs;
611
612 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
613 const int32_t tex_width = 32;
614 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500615
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600616 VkImageCreateInfo image_create_info = {};
617 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
618 image_create_info.pNext = NULL;
619 image_create_info.imageType = VK_IMAGE_TYPE_2D;
620 image_create_info.format = tex_format;
621 image_create_info.extent.width = tex_width;
622 image_create_info.extent.height = tex_height;
623 image_create_info.extent.depth = 1;
624 image_create_info.mipLevels = 1;
625 image_create_info.arraySize = 1;
626 image_create_info.samples = 1;
627 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
628 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
629 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500630
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600631 VkMemoryAllocInfo mem_alloc = {};
632 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
633 mem_alloc.pNext = NULL;
634 mem_alloc.allocationSize = 0;
635 mem_alloc.memoryTypeIndex = 0;
636
637 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
638 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500639 err = vkCreateImage(m_device->device(), &image_create_info, &image);
640 ASSERT_VK_SUCCESS(err);
641
Tony Barboure84a8d62015-07-10 14:10:27 -0600642 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500643 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500644 &mem_reqs);
645 ASSERT_VK_SUCCESS(err);
646
647 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800648 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600649 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500650
651 // allocate 2 memory objects
652 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
653 ASSERT_VK_SUCCESS(err);
654 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
655 ASSERT_VK_SUCCESS(err);
656
657 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600658 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500659 ASSERT_VK_SUCCESS(err);
660
661 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600662 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500663
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600664 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600665 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 -0500666 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
667 FAIL() << "Error received did not match expected message when rebinding memory to an object";
668 }
669}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500670
Tony Barbour8508b8e2015-04-09 10:48:04 -0600671TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600672{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600673 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600674 VkFlags msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600675 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600676
677 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600678 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
679 fenceInfo.pNext = NULL;
680 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600681
Tony Barbour30486ea2015-04-07 13:44:53 -0600682 ASSERT_NO_FATAL_FAILURE(InitState());
683 ASSERT_NO_FATAL_FAILURE(InitViewport());
684 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
685
Tony Barbour1490c912015-07-28 10:17:20 -0600686 BeginCommandBuffer();
687 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
688 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600689
690 testFence.init(*m_device, fenceInfo);
691 m_errorMonitor->ClearState();
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600692
693 vkQueueSubmit(m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
694 vkQueueWaitIdle(m_device->m_queue );
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600695 msgFlags = m_errorMonitor->GetState(&msgString);
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600696
Cody Northrop1684adb2015-08-05 11:15:02 -0600697 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 -0600698 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500699 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600700 }
701
702}
703
704TEST_F(VkLayerTest, ResetUnsignaledFence)
705{
706 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600707 VkFlags msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600708 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600709 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600710 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
711 fenceInfo.pNext = NULL;
712
Tony Barbour8508b8e2015-04-09 10:48:04 -0600713 ASSERT_NO_FATAL_FAILURE(InitState());
714 testFence.init(*m_device, fenceInfo);
715 m_errorMonitor->ClearState();
Chia-I Wua4992342015-07-03 11:45:55 +0800716 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600717 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600718 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600719 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 -0600720 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500721 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600722 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600723
724}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600725
Chia-I Wuc278df82015-07-07 11:50:03 +0800726/* TODO: Update for changes due to bug-14075 tiling across render passes */
727#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600728TEST_F(VkLayerTest, InvalidUsageBits)
729{
730 // Initiate Draw w/o a PSO bound
731 VkFlags msgFlags;
732 std::string msgString;
733
734 ASSERT_NO_FATAL_FAILURE(InitState());
735 m_errorMonitor->ClearState();
736 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600737 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600738
739 const VkExtent3D e3d = {
740 .width = 128,
741 .height = 128,
742 .depth = 1,
743 };
744 const VkImageCreateInfo ici = {
745 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
746 .pNext = NULL,
747 .imageType = VK_IMAGE_TYPE_2D,
748 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
749 .extent = e3d,
750 .mipLevels = 1,
751 .arraySize = 1,
752 .samples = 1,
753 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchterc3b8eea2015-09-10 14:14:11 -0600754 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600755 .flags = 0,
756 };
757
758 VkImage dsi;
759 vkCreateImage(m_device->device(), &ici, &dsi);
760 VkDepthStencilView dsv;
761 const VkDepthStencilViewCreateInfo dsvci = {
762 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
763 .pNext = NULL,
764 .image = dsi,
765 .mipLevel = 0,
Courtney Goeltzenleuchter3dee8082015-09-10 16:38:41 -0600766 .baseArrayLayer = 0,
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600767 .arraySize = 1,
768 .flags = 0,
769 };
770 vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv);
771 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600772 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 -0600773 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
774 FAIL() << "Error received was not 'Invalid usage flag for image...'";
775 }
776}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600777#endif // 0
778#endif // MEM_TRACKER_TESTS
779
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600780#if OBJ_TRACKER_TESTS
Cody Northrope4bc6942015-08-26 10:01:32 -0600781TEST_F(VkLayerTest, LineWidthStateNotBound)
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500782{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600783 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500784 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600785 ASSERT_NO_FATAL_FAILURE(InitState());
786 m_errorMonitor->ClearState();
Cody Northrope4bc6942015-08-26 10:01:32 -0600787 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 -0500788
Cody Northrope4bc6942015-08-26 10:01:32 -0600789 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500790
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600791 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrope4bc6942015-08-26 10:01:32 -0600792 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Line Width State Object";
793 if (!strstr(msgString.c_str(),"Line width object not bound to this command buffer")) {
794 FAIL() << "Error received was not 'Line Width object not bound to this command buffer'";
Cody Northropf5bd2252015-08-17 11:10:49 -0600795 }
796}
797
Cody Northrope4bc6942015-08-26 10:01:32 -0600798TEST_F(VkLayerTest, DepthBiasStateNotBound)
Cody Northropf5bd2252015-08-17 11:10:49 -0600799{
800 VkFlags msgFlags;
801 std::string msgString;
802 ASSERT_NO_FATAL_FAILURE(InitState());
803 m_errorMonitor->ClearState();
Cody Northrope4bc6942015-08-26 10:01:32 -0600804 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 -0600805
Cody Northrope4bc6942015-08-26 10:01:32 -0600806 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Cody Northropf5bd2252015-08-17 11:10:49 -0600807
808 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrope4bc6942015-08-26 10:01:32 -0600809 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bias State Object";
810 if (!strstr(msgString.c_str(),"Depth bias object not bound to this command buffer")) {
811 FAIL() << "Error received was not 'Depth bias object not bound to this command buffer'";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500812 }
813}
814
815TEST_F(VkLayerTest, ViewportStateNotBound)
816{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600817 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500818 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600819 ASSERT_NO_FATAL_FAILURE(InitState());
820 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500821 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
822
823 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
824
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 error from Not Binding a Viewport State Object";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500827 if (!strstr(msgString.c_str(),"Viewport object not bound to this command buffer")) {
828 FAIL() << "Error received was not 'Viewport object not bound to this command buffer'";
829 }
830}
831
Cody Northrope4bc6942015-08-26 10:01:32 -0600832TEST_F(VkLayerTest, BlendStateNotBound)
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500833{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600834 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500835 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600836 ASSERT_NO_FATAL_FAILURE(InitState());
837 m_errorMonitor->ClearState();
Cody Northrope4bc6942015-08-26 10:01:32 -0600838 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500839
Cody Northrope4bc6942015-08-26 10:01:32 -0600840 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500841
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600842 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrope4bc6942015-08-26 10:01:32 -0600843 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Blend State Object";
844 if (!strstr(msgString.c_str(),"Blend object not bound to this command buffer")) {
845 FAIL() << "Error received was not 'Blend object not bound to this command buffer'";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500846 }
847}
848
Cody Northrope4bc6942015-08-26 10:01:32 -0600849TEST_F(VkLayerTest, DepthBoundsStateNotBound)
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500850{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600851 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500852 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600853 ASSERT_NO_FATAL_FAILURE(InitState());
854 m_errorMonitor->ClearState();
Cody Northrope4bc6942015-08-26 10:01:32 -0600855 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 -0500856
Cody Northrope4bc6942015-08-26 10:01:32 -0600857 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500858
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600859 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrope4bc6942015-08-26 10:01:32 -0600860 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bounds State Object";
861 if (!strstr(msgString.c_str(),"Depth bounds object not bound to this command buffer")) {
862 FAIL() << "Error received was not 'Depth bounds object not bound to this command buffer'";
Cody Northrop2605cb02015-08-18 15:21:16 -0600863 }
864}
865
866TEST_F(VkLayerTest, StencilStateNotBound)
867{
868 VkFlags msgFlags;
869 std::string msgString;
870 ASSERT_NO_FATAL_FAILURE(InitState());
871 m_errorMonitor->ClearState();
872 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil state object is not bound beforehand");
873
874 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencil);
875
876 msgFlags = m_errorMonitor->GetState(&msgString);
877 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Stencil State Object";
878 if (!strstr(msgString.c_str(),"Stencil object not bound to this command buffer")) {
879 FAIL() << "Error received was not 'Stencil object not bound to this command buffer'";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500880 }
Tony Barbourdb686622015-05-06 09:35:56 -0600881}
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600882
883TEST_F(VkLayerTest, PipelineNotBound)
884{
885 VkFlags msgFlags;
886 std::string msgString;
887 VkResult err;
888
889 ASSERT_NO_FATAL_FAILURE(InitState());
890 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
891 m_errorMonitor->ClearState();
892
893 VkDescriptorTypeCount ds_type_count = {};
894 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
895 ds_type_count.count = 1;
896
897 VkDescriptorPoolCreateInfo ds_pool_ci = {};
898 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
899 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600900 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
901 ds_pool_ci.maxSets = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600902 ds_pool_ci.count = 1;
903 ds_pool_ci.pTypeCount = &ds_type_count;
904
905 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600906 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600907 ASSERT_VK_SUCCESS(err);
908
909 VkDescriptorSetLayoutBinding dsl_binding = {};
910 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
911 dsl_binding.arraySize = 1;
912 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
913 dsl_binding.pImmutableSamplers = NULL;
914
915 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
916 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
917 ds_layout_ci.pNext = NULL;
918 ds_layout_ci.count = 1;
919 ds_layout_ci.pBinding = &dsl_binding;
920
921 VkDescriptorSetLayout ds_layout;
922 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
923 ASSERT_VK_SUCCESS(err);
924
925 VkDescriptorSet descriptorSet;
926 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
927 ASSERT_VK_SUCCESS(err);
928
929 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
930 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
931 pipeline_layout_ci.pNext = NULL;
932 pipeline_layout_ci.descriptorSetCount = 1;
933 pipeline_layout_ci.pSetLayouts = &ds_layout;
934
935 VkPipelineLayout pipeline_layout;
936 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
937 ASSERT_VK_SUCCESS(err);
938
939 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
940
941 BeginCommandBuffer();
942 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
943
944 msgFlags = m_errorMonitor->GetState(&msgString);
945 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600946 if (!strstr(msgString.c_str(),"Invalid VkPipeline Object ")) {
947 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be' but instead it was '" << msgString.c_str() << "'";
948 }
949}
950
951TEST_F(VkLayerTest, BindInvalidMemory)
952{
953 VkFlags msgFlags;
954 std::string msgString;
955 VkResult err;
956
957 ASSERT_NO_FATAL_FAILURE(InitState());
958 m_errorMonitor->ClearState();
959
960 // Create an image, allocate memory, free it, and then try to bind it
961 VkImage image;
962 VkDeviceMemory mem;
963 VkMemoryRequirements mem_reqs;
964
965 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
966 const int32_t tex_width = 32;
967 const int32_t tex_height = 32;
968
969 VkImageCreateInfo image_create_info = {};
970 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
971 image_create_info.pNext = NULL;
972 image_create_info.imageType = VK_IMAGE_TYPE_2D;
973 image_create_info.format = tex_format;
974 image_create_info.extent.width = tex_width;
975 image_create_info.extent.height = tex_height;
976 image_create_info.extent.depth = 1;
977 image_create_info.mipLevels = 1;
978 image_create_info.arraySize = 1;
979 image_create_info.samples = 1;
980 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
981 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
982 image_create_info.flags = 0;
983
984 VkMemoryAllocInfo mem_alloc = {};
985 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
986 mem_alloc.pNext = NULL;
987 mem_alloc.allocationSize = 0;
988 mem_alloc.memoryTypeIndex = 0;
989
990 err = vkCreateImage(m_device->device(), &image_create_info, &image);
991 ASSERT_VK_SUCCESS(err);
992
993 err = vkGetImageMemoryRequirements(m_device->device(),
994 image,
995 &mem_reqs);
996 ASSERT_VK_SUCCESS(err);
997
998 mem_alloc.allocationSize = mem_reqs.size;
999
1000 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1001 ASSERT_VK_SUCCESS(err);
1002
1003 // allocate memory
1004 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
1005 ASSERT_VK_SUCCESS(err);
1006
1007 // Introduce validation failure, free memory before binding
1008 vkFreeMemory(m_device->device(), mem);
1009 ASSERT_VK_SUCCESS(err);
1010
1011 // Try to bind free memory that has been freed
1012 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1013 // This may very well return an error.
1014 (void)err;
1015
1016 msgFlags = m_errorMonitor->GetState(&msgString);
1017 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to bind a freed memory object";
1018 if (!strstr(msgString.c_str(),"Invalid VkDeviceMemory Object ")) {
1019 FAIL() << "Error received from BindInvalidMemory was not 'Invalid VkDeviceMemory Object 0x<handle>' but instead '" << msgString.c_str() << "'";
1020 }
1021}
1022
1023TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
1024{
1025 VkFlags msgFlags;
1026 std::string msgString;
1027 VkResult err;
1028
1029 ASSERT_NO_FATAL_FAILURE(InitState());
1030 m_errorMonitor->ClearState();
1031
1032 // Create an image object, allocate memory, destroy the object and then try to bind it
1033 VkImage image;
1034 VkDeviceMemory mem;
1035 VkMemoryRequirements mem_reqs;
1036
1037 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1038 const int32_t tex_width = 32;
1039 const int32_t tex_height = 32;
1040
1041 VkImageCreateInfo image_create_info = {};
1042 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1043 image_create_info.pNext = NULL;
1044 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1045 image_create_info.format = tex_format;
1046 image_create_info.extent.width = tex_width;
1047 image_create_info.extent.height = tex_height;
1048 image_create_info.extent.depth = 1;
1049 image_create_info.mipLevels = 1;
1050 image_create_info.arraySize = 1;
1051 image_create_info.samples = 1;
1052 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1053 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1054 image_create_info.flags = 0;
1055
1056 VkMemoryAllocInfo mem_alloc = {};
1057 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
1058 mem_alloc.pNext = NULL;
1059 mem_alloc.allocationSize = 0;
1060 mem_alloc.memoryTypeIndex = 0;
1061
1062 err = vkCreateImage(m_device->device(), &image_create_info, &image);
1063 ASSERT_VK_SUCCESS(err);
1064
1065 err = vkGetImageMemoryRequirements(m_device->device(),
1066 image,
1067 &mem_reqs);
1068 ASSERT_VK_SUCCESS(err);
1069
1070 mem_alloc.allocationSize = mem_reqs.size;
1071 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1072 ASSERT_VK_SUCCESS(err);
1073
1074 // Allocate memory
1075 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
1076 ASSERT_VK_SUCCESS(err);
1077
1078 // Introduce validation failure, destroy Image object before binding
1079 vkDestroyImage(m_device->device(), image);
1080 ASSERT_VK_SUCCESS(err);
1081
1082 // Now Try to bind memory to this destroyed object
1083 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1084 // This may very well return an error.
1085 (void) err;
1086
1087 msgFlags = m_errorMonitor->GetState(&msgString);
1088 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while binding memory to a destroyed object";
1089 if (!strstr(msgString.c_str(),"Invalid VkImage Object ")) {
1090 FAIL() << "Error received from BindMemoryToDestroyedObject was not 'Invalid VkImage Object 0x<handle>' but rather '" << msgString.c_str() << "'";
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001091 }
1092}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001093#endif // OBJ_TRACKER_TESTS
1094
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001095#if DRAW_STATE_TESTS
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001096TEST_F(VkLayerTest, CmdBufferTwoSubmits)
1097{
1098 vk_testing::Fence testFence;
1099 VkFlags msgFlags;
1100 std::string msgString;
1101
1102 VkFenceCreateInfo fenceInfo = {};
1103 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1104 fenceInfo.pNext = NULL;
1105 fenceInfo.flags = 0;
1106
1107 ASSERT_NO_FATAL_FAILURE(InitState());
1108 ASSERT_NO_FATAL_FAILURE(InitViewport());
1109 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1110
1111 // We luck out b/c by default the framework creates CB w/ the VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set
1112 BeginCommandBuffer();
1113 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
1114 EndCommandBuffer();
1115
1116 testFence.init(*m_device, fenceInfo);
1117
1118 // Bypass framework since it does the waits automatically
1119 VkResult err = VK_SUCCESS;
1120 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
1121 ASSERT_VK_SUCCESS( err );
1122
1123 m_errorMonitor->ClearState();
1124 // Cause validation error by re-submitting cmd buffer that should only be submitted once
1125 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001126
1127 msgFlags = m_errorMonitor->GetState(&msgString);
1128 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 -06001129 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 -06001130 FAIL() << "Error received was not 'CB (0xaddress) was created w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set...'";
1131 }
1132}
1133
Tobin Ehlise4076782015-06-24 15:53:07 -06001134TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001135{
1136 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001137 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001138 std::string msgString;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001139 VkResult err;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001140
1141 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001143 m_errorMonitor->ClearState();
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001144
1145 VkDescriptorTypeCount ds_type_count = {};
1146 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1147 ds_type_count.count = 1;
1148
1149 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1150 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1151 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001152 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1153 ds_pool_ci.maxSets = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001154 ds_pool_ci.count = 1;
1155 ds_pool_ci.pTypeCount = &ds_type_count;
1156
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001157 VkDescriptorPool ds_pool;
1158 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001159 ASSERT_VK_SUCCESS(err);
1160
1161 VkDescriptorSetLayoutBinding dsl_binding = {};
1162 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1163 dsl_binding.arraySize = 1;
1164 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1165 dsl_binding.pImmutableSamplers = NULL;
1166
1167 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1168 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1169 ds_layout_ci.pNext = NULL;
1170 ds_layout_ci.count = 1;
1171 ds_layout_ci.pBinding = &dsl_binding;
1172
1173 VkDescriptorSetLayout ds_layout;
1174 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1175 ASSERT_VK_SUCCESS(err);
1176
1177 VkDescriptorSet descriptorSet;
1178 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1179 ASSERT_VK_SUCCESS(err);
1180 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1181 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1182 pipe_ms_state_ci.pNext = NULL;
1183 pipe_ms_state_ci.rasterSamples = 1;
1184 pipe_ms_state_ci.sampleShadingEnable = 0;
1185 pipe_ms_state_ci.minSampleShading = 1.0;
1186 pipe_ms_state_ci.pSampleMask = NULL;
1187
1188 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1189 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1190 pipeline_layout_ci.pNext = NULL;
1191 pipeline_layout_ci.descriptorSetCount = 1;
1192 pipeline_layout_ci.pSetLayouts = &ds_layout;
1193 VkPipelineLayout pipeline_layout;
1194
1195 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1196 ASSERT_VK_SUCCESS(err);
1197
1198 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
1199 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1200 // but add it to be able to run on more devices
1201 VkPipelineObj pipe(m_device);
1202 pipe.AddShader(&vs);
1203 pipe.AddShader(&fs);
1204 pipe.SetMSAA(&pipe_ms_state_ci);
1205 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1206 m_errorMonitor->ClearState();
1207 // Calls CreateCommandBuffer
1208 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1209 VkCmdBufferBeginInfo cmd_buf_info = {};
1210 memset(&cmd_buf_info, 0, sizeof(VkCmdBufferBeginInfo));
1211 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1212 cmd_buf_info.pNext = NULL;
1213 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1214 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1215
1216 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1217 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001218 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001219 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 -06001220 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001221 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0x<handle>) without an active RenderPass'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001222 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001223}
1224
1225TEST_F(VkLayerTest, InvalidDescriptorPool)
1226{
1227 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1228 // The DS check for this is after driver has been called to validate DS internal data struct
1229 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001230/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001231 std::string msgString;
1232 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1233 vkResetDescriptorPool(device(), badPool);
1234
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001235 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001236 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 -06001237 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1238 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1239 }*/
1240}
1241
1242TEST_F(VkLayerTest, InvalidDescriptorSet)
1243{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001244 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1245 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001246 // Create a valid cmd buffer
1247 // call vkCmdBindDescriptorSets w/ false DS
1248}
1249
1250TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1251{
1252 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1253 // The DS check for this is after driver has been called to validate DS internal data struct
1254}
1255
1256TEST_F(VkLayerTest, InvalidPipeline)
1257{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001258 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1259 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001260 // Create a valid cmd buffer
1261 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -06001262// VkFlags msgFlags;
1263// std::string msgString;
1264//
1265// ASSERT_NO_FATAL_FAILURE(InitState());
1266// m_errorMonitor->ClearState();
1267// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001268// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001269// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1270// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1271// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001272// 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 -06001273// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1274// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1275// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001276}
1277
Tobin Ehlis254eca02015-06-25 15:46:59 -06001278TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001279{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001280 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001281 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001282 std::string msgString;
1283 VkResult err;
1284
1285 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001286 ASSERT_NO_FATAL_FAILURE(InitViewport());
1287 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001288 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001289 VkDescriptorTypeCount ds_type_count = {};
1290 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1291 ds_type_count.count = 1;
1292
1293 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1294 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1295 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001296 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1297 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001298 ds_pool_ci.count = 1;
1299 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001300
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001301 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001302 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001303 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001304
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001305 VkDescriptorSetLayoutBinding dsl_binding = {};
1306 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1307 dsl_binding.arraySize = 1;
1308 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1309 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001310
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001311 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1312 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1313 ds_layout_ci.pNext = NULL;
1314 ds_layout_ci.count = 1;
1315 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001316 VkDescriptorSetLayout ds_layout;
1317 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1318 ASSERT_VK_SUCCESS(err);
1319
1320 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001321 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001322 ASSERT_VK_SUCCESS(err);
1323
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001324 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1325 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1326 pipeline_layout_ci.pNext = NULL;
1327 pipeline_layout_ci.descriptorSetCount = 1;
1328 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001329
1330 VkPipelineLayout pipeline_layout;
1331 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1332 ASSERT_VK_SUCCESS(err);
1333
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001334 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001335 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1336 // but add it to be able to run on more devices
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001337
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001338 VkPipelineObj pipe(m_device);
1339 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001340 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001341 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001342
1343 BeginCommandBuffer();
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001344 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbour1490c912015-07-28 10:17:20 -06001345 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001346
Tobin Ehlis254eca02015-06-25 15:46:59 -06001347 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001348 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 -06001349 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1350 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1351 }
1352}
1353
1354TEST_F(VkLayerTest, NoBeginCmdBuffer)
1355{
1356 VkFlags msgFlags;
1357 std::string msgString;
1358
1359 ASSERT_NO_FATAL_FAILURE(InitState());
1360 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001361 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001362 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1363 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1364 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001365 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 -06001366 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1367 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1368 }
1369}
1370
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001371TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1372{
1373 VkFlags msgFlags;
1374 std::string msgString;
1375
1376 ASSERT_NO_FATAL_FAILURE(InitState());
1377 m_errorMonitor->ClearState();
1378
1379 // Calls CreateCommandBuffer
1380 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1381
1382 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northrop10d8f982015-08-04 17:35:57 -06001383 VkCmdBufferBeginInfo cmd_buf_info = {};
1384 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1385 cmd_buf_info.pNext = NULL;
1386 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1387 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1388 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1389 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1390
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001391
1392 // The error should be caught by validation of the BeginCommandBuffer call
1393 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1394
1395 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001396 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 -06001397 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1398 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1399 }
1400}
1401
1402TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1403{
1404 VkFlags msgFlags;
1405 std::string msgString;
1406 VkResult err;
1407 VkCmdBuffer draw_cmd;
1408 VkCmdPool cmd_pool;
1409
1410 ASSERT_NO_FATAL_FAILURE(InitState());
1411 m_errorMonitor->ClearState();
1412
Cody Northrop10d8f982015-08-04 17:35:57 -06001413 VkCmdBufferCreateInfo cmd = {};
1414 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1415 cmd.pNext = NULL;
1416 cmd.cmdPool = m_cmdPool;
1417 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1418 cmd.flags = 0;
1419
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001420 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
1421 assert(!err);
1422
1423 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northrop10d8f982015-08-04 17:35:57 -06001424 VkCmdBufferBeginInfo cmd_buf_info = {};
1425 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1426 cmd_buf_info.pNext = NULL;
1427 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1428 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001429
1430 // The error should be caught by validation of the BeginCommandBuffer call
1431 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1432
1433 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001434 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 -06001435 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1436 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1437 }
1438}
1439
Tobin Ehlis254eca02015-06-25 15:46:59 -06001440TEST_F(VkLayerTest, InvalidPipelineCreateState)
1441{
1442 // Attempt to Create Gfx Pipeline w/o a VS
1443 VkFlags msgFlags;
1444 std::string msgString;
1445 VkResult err;
1446
1447 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis254eca02015-06-25 15:46:59 -06001449 m_errorMonitor->ClearState();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001450
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001451 VkDescriptorTypeCount ds_type_count = {};
1452 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1453 ds_type_count.count = 1;
1454
1455 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1456 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1457 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001458 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1459 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001460 ds_pool_ci.count = 1;
1461 ds_pool_ci.pTypeCount = &ds_type_count;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001462
Tobin Ehlis254eca02015-06-25 15:46:59 -06001463 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001464 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001465 ASSERT_VK_SUCCESS(err);
1466
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001467 VkDescriptorSetLayoutBinding dsl_binding = {};
1468 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1469 dsl_binding.arraySize = 1;
1470 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1471 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001472
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001473 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1474 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1475 ds_layout_ci.pNext = NULL;
1476 ds_layout_ci.count = 1;
1477 ds_layout_ci.pBinding = &dsl_binding;
1478
Tobin Ehlis254eca02015-06-25 15:46:59 -06001479 VkDescriptorSetLayout ds_layout;
1480 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1481 ASSERT_VK_SUCCESS(err);
1482
1483 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001484 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001485 ASSERT_VK_SUCCESS(err);
1486
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001487 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1488 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1489 pipeline_layout_ci.pNext = NULL;
1490 pipeline_layout_ci.descriptorSetCount = 1;
1491 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001492
1493 VkPipelineLayout pipeline_layout;
1494 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1495 ASSERT_VK_SUCCESS(err);
1496
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001497 VkGraphicsPipelineCreateInfo gp_ci = {};
1498 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1499 gp_ci.pNext = NULL;
1500 gp_ci.stageCount = 0;
1501 gp_ci.pStages = NULL;
1502 gp_ci.pVertexInputState = NULL;
1503 gp_ci.pInputAssemblyState = NULL;
1504 gp_ci.pTessellationState = NULL;
1505 gp_ci.pViewportState = NULL;
1506 gp_ci.pRasterState = NULL;
1507 gp_ci.pMultisampleState = NULL;
1508 gp_ci.pDepthStencilState = NULL;
1509 gp_ci.pColorBlendState = NULL;
1510 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1511 gp_ci.layout = pipeline_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001512 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001513
1514 VkPipelineCacheCreateInfo pc_ci = {};
1515 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1516 pc_ci.pNext = NULL;
1517 pc_ci.initialSize = 0;
1518 pc_ci.initialData = 0;
1519 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001520
1521 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001522 VkPipelineCache pipelineCache;
1523
1524 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1525 ASSERT_VK_SUCCESS(err);
1526 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001527
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001528 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001529 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 -06001530 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1531 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1532 }
1533}
Tobin Ehlis20693172015-09-17 08:46:18 -06001534/*// TODO : This test should be good, but needs Tess support in compiler to run
1535TEST_F(VkLayerTest, InvalidPatchControlPoints)
1536{
1537 // Attempt to Create Gfx Pipeline w/o a VS
1538 VkFlags msgFlags;
1539 std::string msgString;
1540 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001541
Tobin Ehlis20693172015-09-17 08:46:18 -06001542 ASSERT_NO_FATAL_FAILURE(InitState());
1543 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1544 m_errorMonitor->ClearState();
1545
1546 VkDescriptorTypeCount ds_type_count = {};
1547 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1548 ds_type_count.count = 1;
1549
1550 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1551 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1552 ds_pool_ci.pNext = NULL;
1553 ds_pool_ci.count = 1;
1554 ds_pool_ci.pTypeCount = &ds_type_count;
1555
1556 VkDescriptorPool ds_pool;
1557 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1558 ASSERT_VK_SUCCESS(err);
1559
1560 VkDescriptorSetLayoutBinding dsl_binding = {};
1561 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1562 dsl_binding.arraySize = 1;
1563 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1564 dsl_binding.pImmutableSamplers = NULL;
1565
1566 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1567 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1568 ds_layout_ci.pNext = NULL;
1569 ds_layout_ci.count = 1;
1570 ds_layout_ci.pBinding = &dsl_binding;
1571
1572 VkDescriptorSetLayout ds_layout;
1573 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1574 ASSERT_VK_SUCCESS(err);
1575
1576 VkDescriptorSet descriptorSet;
1577 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1578 ASSERT_VK_SUCCESS(err);
1579
1580 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1581 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1582 pipeline_layout_ci.pNext = NULL;
1583 pipeline_layout_ci.descriptorSetCount = 1;
1584 pipeline_layout_ci.pSetLayouts = &ds_layout;
1585
1586 VkPipelineLayout pipeline_layout;
1587 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1588 ASSERT_VK_SUCCESS(err);
1589
1590 VkPipelineShaderStageCreateInfo shaderStages[3];
1591 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
1592
1593 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
1594 // Just using VS txt for Tess shaders as we don't care about functionality
1595 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESS_CONTROL, this);
1596 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESS_EVALUATION, this);
1597
1598 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1599 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
1600 shaderStages[0].shader = vs.handle();
1601 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1602 shaderStages[1].stage = VK_SHADER_STAGE_TESS_CONTROL;
1603 shaderStages[1].shader = tc.handle();
1604 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1605 shaderStages[2].stage = VK_SHADER_STAGE_TESS_EVALUATION;
1606 shaderStages[2].shader = te.handle();
1607
1608 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
1609 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
1610 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH;
1611
1612 VkPipelineTessellationStateCreateInfo tsCI = {};
1613 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
1614 tsCI.patchControlPoints = 0; // This will cause an error
1615
1616 VkGraphicsPipelineCreateInfo gp_ci = {};
1617 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1618 gp_ci.pNext = NULL;
1619 gp_ci.stageCount = 3;
1620 gp_ci.pStages = shaderStages;
1621 gp_ci.pVertexInputState = NULL;
1622 gp_ci.pInputAssemblyState = &iaCI;
1623 gp_ci.pTessellationState = &tsCI;
1624 gp_ci.pViewportState = NULL;
1625 gp_ci.pRasterState = NULL;
1626 gp_ci.pMultisampleState = NULL;
1627 gp_ci.pDepthStencilState = NULL;
1628 gp_ci.pColorBlendState = NULL;
1629 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1630 gp_ci.layout = pipeline_layout;
1631 gp_ci.renderPass = renderPass();
1632
1633 VkPipelineCacheCreateInfo pc_ci = {};
1634 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1635 pc_ci.pNext = NULL;
1636 pc_ci.initialSize = 0;
1637 pc_ci.initialData = 0;
1638 pc_ci.maxSize = 0;
1639
1640 VkPipeline pipeline;
1641 VkPipelineCache pipelineCache;
1642
1643 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1644 ASSERT_VK_SUCCESS(err);
1645 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1646
1647 msgFlags = m_errorMonitor->GetState(&msgString);
1648 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Tess Gfx Pipeline w/ 0 patchControlPoints.";
1649 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ")) {
1650 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...' but instead '" << msgString.c_str() << "'";
1651 }
1652}
1653*/
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001654TEST_F(VkLayerTest, NullRenderPass)
1655{
1656 // Bind a NULL RenderPass
1657 VkFlags msgFlags;
1658 std::string msgString;
1659
1660 ASSERT_NO_FATAL_FAILURE(InitState());
1661 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1662 m_errorMonitor->ClearState();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001663
Tony Barbour1490c912015-07-28 10:17:20 -06001664 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001665 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06001666 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001667
1668 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001669 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001670 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
1671 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
1672 }
1673}
1674
Tobin Ehlis254eca02015-06-25 15:46:59 -06001675TEST_F(VkLayerTest, RenderPassWithinRenderPass)
1676{
1677 // Bind a BeginRenderPass within an active RenderPass
1678 VkFlags msgFlags;
1679 std::string msgString;
1680
1681 ASSERT_NO_FATAL_FAILURE(InitState());
1682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1683 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001684
Tony Barbour1490c912015-07-28 10:17:20 -06001685 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001686 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001687 VkRenderPassBeginInfo rp_begin = {};
1688 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
1689 rp_begin.pNext = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001690 rp_begin.renderPass = renderPass();
1691 rp_begin.framebuffer = framebuffer();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001692
Tony Barbour1490c912015-07-28 10:17:20 -06001693 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001694
1695 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001696 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 -06001697 if (!strstr(msgString.c_str(),"Cannot call vkCmdBeginRenderPass() during an active RenderPass ")) {
1698 FAIL() << "Error received was not 'Cannot call vkCmdBeginRenderPass() during an active RenderPass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001699 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001700}
1701
1702TEST_F(VkLayerTest, InvalidDynamicStateObject)
1703{
1704 // Create a valid cmd buffer
1705 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001706 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1707 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001708}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06001709
Tobin Ehlise4076782015-06-24 15:53:07 -06001710TEST_F(VkLayerTest, VtxBufferNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001711{
1712 // Bind VBO out-of-bounds for given PSO
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001713 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001714 std::string msgString;
1715 VkResult err;
1716
1717 ASSERT_NO_FATAL_FAILURE(InitState());
1718 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001719
1720 VkDescriptorTypeCount ds_type_count = {};
1721 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1722 ds_type_count.count = 1;
1723
1724 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1725 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1726 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001727 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1728 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001729 ds_pool_ci.count = 1;
1730 ds_pool_ci.pTypeCount = &ds_type_count;
1731
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001732 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001733 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001734 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001735
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001736 VkDescriptorSetLayoutBinding dsl_binding = {};
1737 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1738 dsl_binding.arraySize = 1;
1739 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1740 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001741
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001742 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1743 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1744 ds_layout_ci.pNext = NULL;
1745 ds_layout_ci.count = 1;
1746 ds_layout_ci.pBinding = &dsl_binding;
1747
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001748 VkDescriptorSetLayout ds_layout;
1749 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1750 ASSERT_VK_SUCCESS(err);
1751
1752 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001753 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001754 ASSERT_VK_SUCCESS(err);
1755
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001756 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1757 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1758 pipeline_layout_ci.pNext = NULL;
1759 pipeline_layout_ci.descriptorSetCount = 1;
1760 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001761
1762 VkPipelineLayout pipeline_layout;
1763 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1764 ASSERT_VK_SUCCESS(err);
1765
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001766 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001767 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1768 // but add it to be able to run on more devices
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001769 VkPipelineObj pipe(m_device);
1770 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001771 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001772 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001773
Tony Barbour1490c912015-07-28 10:17:20 -06001774 BeginCommandBuffer();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001775 ASSERT_VK_SUCCESS(err);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001776 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001777 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06001778 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001779
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001780 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001781 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 -06001782 if (!strstr(msgString.c_str(),"Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.")) {
1783 FAIL() << "Error received was not 'Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001784 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001785}
1786
Tobin Ehlis8d199e52015-09-17 12:24:13 -06001787TEST_F(VkLayerTest, IdxBufferAlignmentError)
1788{
1789 // Bind a BeginRenderPass within an active RenderPass
1790 VkFlags msgFlags;
1791 std::string msgString;
1792 VkResult err;
1793
1794 ASSERT_NO_FATAL_FAILURE(InitState());
1795 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1796 m_errorMonitor->ClearState();
1797 uint32_t qfi = 0;
1798 VkBufferCreateInfo buffCI = {};
1799 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1800 buffCI.size = 1024;
1801 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
1802 buffCI.queueFamilyCount = 1;
1803 buffCI.pQueueFamilyIndices = &qfi;
1804
1805 VkBuffer ib;
1806 err = vkCreateBuffer(m_device->device(), &buffCI, &ib);
1807 ASSERT_VK_SUCCESS(err);
1808
1809 BeginCommandBuffer();
1810 ASSERT_VK_SUCCESS(err);
1811 //vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1812 // Should error before calling to driver so don't care about actual data
1813 vkCmdBindIndexBuffer(m_cmdBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
1814
1815 msgFlags = m_errorMonitor->GetState(&msgString);
1816 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
1817 if (!strstr(msgString.c_str(),"vkCmdBindIndexBuffer() offset (0x7) does not fall on ")) {
1818 FAIL() << "Error received was not 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...' but instead '" << msgString.c_str() << "'";
1819 }
1820}
1821
Tobin Ehlis5f728d32015-09-17 14:18:16 -06001822TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
1823{
1824 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
1825 VkFlags msgFlags;
1826 std::string msgString;
1827
1828 ASSERT_NO_FATAL_FAILURE(InitState());
1829 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1830 m_errorMonitor->ClearState();
1831
1832 BeginCommandBuffer();
1833 //ASSERT_VK_SUCCESS(err);
1834 VkCmdBuffer primCB = m_cmdBuffer->GetBufferHandle();
1835 vkCmdExecuteCommands(m_cmdBuffer->GetBufferHandle(), 1, &primCB);
1836
1837 msgFlags = m_errorMonitor->GetState(&msgString);
1838 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
1839 if (!strstr(msgString.c_str(),"vkCmdExecuteCommands() called w/ Primary Cmd Buffer ")) {
1840 FAIL() << "Error received was not 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer ' but instead '" << msgString.c_str() << "'";
1841 }
1842}
1843
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001844TEST_F(VkLayerTest, DSTypeMismatch)
1845{
1846 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001847 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001848 std::string msgString;
1849 VkResult err;
1850
1851 ASSERT_NO_FATAL_FAILURE(InitState());
1852 m_errorMonitor->ClearState();
1853 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001854 VkDescriptorTypeCount ds_type_count = {};
1855 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1856 ds_type_count.count = 1;
1857
1858 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1859 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1860 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001861 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1862 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001863 ds_pool_ci.count = 1;
1864 ds_pool_ci.pTypeCount = &ds_type_count;
1865
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001866 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001867 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001868 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001869 VkDescriptorSetLayoutBinding dsl_binding = {};
1870 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1871 dsl_binding.arraySize = 1;
1872 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1873 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001874
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001875 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1876 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1877 ds_layout_ci.pNext = NULL;
1878 ds_layout_ci.count = 1;
1879 ds_layout_ci.pBinding = &dsl_binding;
1880
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001881 VkDescriptorSetLayout ds_layout;
1882 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1883 ASSERT_VK_SUCCESS(err);
1884
1885 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001886 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001887 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001888
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001889 VkSamplerCreateInfo sampler_ci = {};
1890 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1891 sampler_ci.pNext = NULL;
1892 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1893 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1894 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06001895 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
1896 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
1897 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001898 sampler_ci.mipLodBias = 1.0;
1899 sampler_ci.maxAnisotropy = 1;
1900 sampler_ci.compareEnable = VK_FALSE;
1901 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1902 sampler_ci.minLod = 1.0;
1903 sampler_ci.maxLod = 1.0;
1904 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06001905 sampler_ci.unnormalizedCoordinates = VK_FALSE;
1906
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001907 VkSampler sampler;
1908 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1909 ASSERT_VK_SUCCESS(err);
1910
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001911 VkDescriptorInfo descriptor_info;
1912 memset(&descriptor_info, 0, sizeof(descriptor_info));
1913 descriptor_info.sampler = sampler;
1914
1915 VkWriteDescriptorSet descriptor_write;
1916 memset(&descriptor_write, 0, sizeof(descriptor_write));
1917 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1918 descriptor_write.destSet = descriptorSet;
1919 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001920 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001921 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1922 descriptor_write.pDescriptors = &descriptor_info;
1923
1924 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1925
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001926 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001927 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 +08001928 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) {
1929 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 -06001930 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001931}
1932
1933TEST_F(VkLayerTest, DSUpdateOutOfBounds)
1934{
1935 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001936 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001937 std::string msgString;
1938 VkResult err;
1939
1940 ASSERT_NO_FATAL_FAILURE(InitState());
1941 m_errorMonitor->ClearState();
1942 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001943 VkDescriptorTypeCount ds_type_count = {};
1944 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1945 ds_type_count.count = 1;
1946
1947 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1948 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1949 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001950 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1951 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001952 ds_pool_ci.count = 1;
1953 ds_pool_ci.pTypeCount = &ds_type_count;
1954
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001955 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001956 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001957 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001958
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001959 VkDescriptorSetLayoutBinding dsl_binding = {};
1960 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1961 dsl_binding.arraySize = 1;
1962 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1963 dsl_binding.pImmutableSamplers = NULL;
1964
1965 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1966 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1967 ds_layout_ci.pNext = NULL;
1968 ds_layout_ci.count = 1;
1969 ds_layout_ci.pBinding = &dsl_binding;
1970
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001971 VkDescriptorSetLayout ds_layout;
1972 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1973 ASSERT_VK_SUCCESS(err);
1974
1975 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001976 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001977 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001978
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001979 VkSamplerCreateInfo sampler_ci = {};
1980 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1981 sampler_ci.pNext = NULL;
1982 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1983 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1984 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06001985 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
1986 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
1987 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001988 sampler_ci.mipLodBias = 1.0;
1989 sampler_ci.maxAnisotropy = 1;
1990 sampler_ci.compareEnable = VK_FALSE;
1991 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1992 sampler_ci.minLod = 1.0;
1993 sampler_ci.maxLod = 1.0;
1994 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06001995 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001996
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001997 VkSampler sampler;
1998 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1999 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002000
2001 VkDescriptorInfo descriptor_info;
2002 memset(&descriptor_info, 0, sizeof(descriptor_info));
2003 descriptor_info.sampler = sampler;
2004
2005 VkWriteDescriptorSet descriptor_write;
2006 memset(&descriptor_write, 0, sizeof(descriptor_write));
2007 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2008 descriptor_write.destSet = descriptorSet;
2009 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
2010 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002011 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002012 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2013 descriptor_write.pDescriptors = &descriptor_info;
2014
2015 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2016
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002017 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002018 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 +08002019 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
2020 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 -06002021 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002022}
2023
2024TEST_F(VkLayerTest, InvalidDSUpdateIndex)
2025{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002026 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002027 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002028 std::string msgString;
2029 VkResult err;
2030
2031 ASSERT_NO_FATAL_FAILURE(InitState());
2032 m_errorMonitor->ClearState();
2033 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002034 VkDescriptorTypeCount ds_type_count = {};
2035 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2036 ds_type_count.count = 1;
2037
2038 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2039 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2040 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002041 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2042 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002043 ds_pool_ci.count = 1;
2044 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002045
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002046 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002047 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002048 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002049
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002050 VkDescriptorSetLayoutBinding dsl_binding = {};
2051 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2052 dsl_binding.arraySize = 1;
2053 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2054 dsl_binding.pImmutableSamplers = NULL;
2055
2056 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2057 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2058 ds_layout_ci.pNext = NULL;
2059 ds_layout_ci.count = 1;
2060 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002061 VkDescriptorSetLayout ds_layout;
2062 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2063 ASSERT_VK_SUCCESS(err);
2064
2065 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002066 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002067 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002068
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002069 VkSamplerCreateInfo sampler_ci = {};
2070 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2071 sampler_ci.pNext = NULL;
2072 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2073 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2074 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002075 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2076 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2077 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002078 sampler_ci.mipLodBias = 1.0;
2079 sampler_ci.maxAnisotropy = 1;
2080 sampler_ci.compareEnable = VK_FALSE;
2081 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2082 sampler_ci.minLod = 1.0;
2083 sampler_ci.maxLod = 1.0;
2084 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002085 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002086
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002087 VkSampler sampler;
2088 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2089 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002090
2091 VkDescriptorInfo descriptor_info;
2092 memset(&descriptor_info, 0, sizeof(descriptor_info));
2093 descriptor_info.sampler = sampler;
2094
2095 VkWriteDescriptorSet descriptor_write;
2096 memset(&descriptor_write, 0, sizeof(descriptor_write));
2097 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2098 descriptor_write.destSet = descriptorSet;
2099 descriptor_write.destBinding = 2;
2100 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002101 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002102 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2103 descriptor_write.pDescriptors = &descriptor_info;
2104
2105 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2106
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002107 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002108 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 -06002109 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
2110 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
2111 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002112}
2113
2114TEST_F(VkLayerTest, InvalidDSUpdateStruct)
2115{
2116 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002117 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002118 std::string msgString;
2119 VkResult err;
2120
2121 ASSERT_NO_FATAL_FAILURE(InitState());
2122 m_errorMonitor->ClearState();
2123 //VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002124
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002125 VkDescriptorTypeCount ds_type_count = {};
2126 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2127 ds_type_count.count = 1;
2128
2129 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2130 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2131 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002132 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2133 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002134 ds_pool_ci.count = 1;
2135 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002136
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002137 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002138 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002139 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002140 VkDescriptorSetLayoutBinding dsl_binding = {};
2141 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2142 dsl_binding.arraySize = 1;
2143 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2144 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002145
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002146 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2147 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2148 ds_layout_ci.pNext = NULL;
2149 ds_layout_ci.count = 1;
2150 ds_layout_ci.pBinding = &dsl_binding;
2151
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002152 VkDescriptorSetLayout ds_layout;
2153 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2154 ASSERT_VK_SUCCESS(err);
2155
2156 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002157 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002158 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002159
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002160 VkSamplerCreateInfo sampler_ci = {};
2161 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2162 sampler_ci.pNext = NULL;
2163 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2164 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2165 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002166 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2167 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2168 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002169 sampler_ci.mipLodBias = 1.0;
2170 sampler_ci.maxAnisotropy = 1;
2171 sampler_ci.compareEnable = VK_FALSE;
2172 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2173 sampler_ci.minLod = 1.0;
2174 sampler_ci.maxLod = 1.0;
2175 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002176 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002177 VkSampler sampler;
2178 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2179 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002180
2181
2182 VkDescriptorInfo descriptor_info;
2183 memset(&descriptor_info, 0, sizeof(descriptor_info));
2184 descriptor_info.sampler = sampler;
2185
2186 VkWriteDescriptorSet descriptor_write;
2187 memset(&descriptor_write, 0, sizeof(descriptor_write));
2188 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
2189 descriptor_write.destSet = descriptorSet;
2190 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002191 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002192 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2193 descriptor_write.pDescriptors = &descriptor_info;
2194
2195 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2196
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002197 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002198 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 -06002199 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
2200 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
2201 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002202}
2203
2204TEST_F(VkLayerTest, NumSamplesMismatch)
2205{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002206 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002207 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002208 std::string msgString;
2209 VkResult err;
2210
2211 ASSERT_NO_FATAL_FAILURE(InitState());
2212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2213 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002214 VkDescriptorTypeCount ds_type_count = {};
2215 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2216 ds_type_count.count = 1;
2217
2218 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002219 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2220 ds_pool_ci.pNext = NULL;
2221 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2222 ds_pool_ci.maxSets = 1;
2223 ds_pool_ci.count = 1;
2224 ds_pool_ci.pTypeCount = &ds_type_count;
2225
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002226 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002227 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002228 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002229
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002230 VkDescriptorSetLayoutBinding dsl_binding = {};
2231 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2232 dsl_binding.arraySize = 1;
2233 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2234 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002235
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002236 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2237 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2238 ds_layout_ci.pNext = NULL;
2239 ds_layout_ci.count = 1;
2240 ds_layout_ci.pBinding = &dsl_binding;
2241
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002242 VkDescriptorSetLayout ds_layout;
2243 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2244 ASSERT_VK_SUCCESS(err);
2245
2246 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002247 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002248 ASSERT_VK_SUCCESS(err);
2249
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002250 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2251 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2252 pipe_ms_state_ci.pNext = NULL;
2253 pipe_ms_state_ci.rasterSamples = 4;
2254 pipe_ms_state_ci.sampleShadingEnable = 0;
2255 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002256 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002257
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002258 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2259 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2260 pipeline_layout_ci.pNext = NULL;
2261 pipeline_layout_ci.descriptorSetCount = 1;
2262 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002263
2264 VkPipelineLayout pipeline_layout;
2265 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2266 ASSERT_VK_SUCCESS(err);
2267
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002268 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002269 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2270 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002271 VkPipelineObj pipe(m_device);
2272 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002273 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002274 pipe.SetMSAA(&pipe_ms_state_ci);
2275 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002276
Tony Barbour1490c912015-07-28 10:17:20 -06002277 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06002278 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002279
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002280 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002281 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 -06002282 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
2283 FAIL() << "Error received was not 'Num samples mismatch!...'";
2284 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002285}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002286
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002287TEST_F(VkLayerTest, ClearCmdNoDraw)
2288{
2289 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
2290 VkFlags msgFlags;
2291 std::string msgString;
2292 VkResult err;
2293
2294 ASSERT_NO_FATAL_FAILURE(InitState());
2295 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2296 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002297
2298 VkDescriptorTypeCount ds_type_count = {};
2299 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2300 ds_type_count.count = 1;
2301
2302 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2303 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2304 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002305 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2306 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002307 ds_pool_ci.count = 1;
2308 ds_pool_ci.pTypeCount = &ds_type_count;
2309
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002310 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002311 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002312 ASSERT_VK_SUCCESS(err);
2313
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002314 VkDescriptorSetLayoutBinding dsl_binding = {};
2315 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2316 dsl_binding.arraySize = 1;
2317 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2318 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002319
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002320 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2321 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2322 ds_layout_ci.pNext = NULL;
2323 ds_layout_ci.count = 1;
2324 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002325
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002326 VkDescriptorSetLayout ds_layout;
2327 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2328 ASSERT_VK_SUCCESS(err);
2329
2330 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002331 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002332 ASSERT_VK_SUCCESS(err);
2333
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002334 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2335 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2336 pipe_ms_state_ci.pNext = NULL;
2337 pipe_ms_state_ci.rasterSamples = 4;
2338 pipe_ms_state_ci.sampleShadingEnable = 0;
2339 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002340 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002341
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002342 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2343 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2344 pipeline_layout_ci.pNext = NULL;
2345 pipeline_layout_ci.descriptorSetCount = 1;
2346 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002347
2348 VkPipelineLayout pipeline_layout;
2349 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2350 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002351
Tony Barbourd7d828b2015-08-06 10:16:07 -06002352 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002353 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2354 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002355 VkPipelineObj pipe(m_device);
2356 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002357 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002358 pipe.SetMSAA(&pipe_ms_state_ci);
2359 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002360
2361 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002362
2363 m_errorMonitor->ClearState();
2364 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
2365 // Also pass down other dummy params to keep driver and paramchecker happy
2366 VkClearColorValue cCV;
Cody Northrop2563a032015-08-25 15:26:38 -06002367 cCV.float32[0] = 1.0;
2368 cCV.float32[1] = 1.0;
2369 cCV.float32[2] = 1.0;
2370 cCV.float32[3] = 1.0;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002371
Tony Barbour1490c912015-07-28 10:17:20 -06002372 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002373 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002374 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 -06002375 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) {
2376 FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'";
2377 }
2378}
2379
Tobin Ehlise4076782015-06-24 15:53:07 -06002380TEST_F(VkLayerTest, VtxBufferBadIndex)
2381{
2382 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
2383 VkFlags msgFlags;
2384 std::string msgString;
2385 VkResult err;
2386
2387 ASSERT_NO_FATAL_FAILURE(InitState());
2388 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2389 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002390
2391 VkDescriptorTypeCount ds_type_count = {};
2392 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2393 ds_type_count.count = 1;
2394
2395 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2396 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2397 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002398 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2399 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002400 ds_pool_ci.count = 1;
2401 ds_pool_ci.pTypeCount = &ds_type_count;
2402
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002403 VkDescriptorPool ds_pool;
2404 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06002405 ASSERT_VK_SUCCESS(err);
2406
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002407 VkDescriptorSetLayoutBinding dsl_binding = {};
2408 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2409 dsl_binding.arraySize = 1;
2410 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2411 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002412
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002413 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2414 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2415 ds_layout_ci.pNext = NULL;
2416 ds_layout_ci.count = 1;
2417 ds_layout_ci.pBinding = &dsl_binding;
2418
Tobin Ehlise4076782015-06-24 15:53:07 -06002419 VkDescriptorSetLayout ds_layout;
2420 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2421 ASSERT_VK_SUCCESS(err);
2422
2423 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002424 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06002425 ASSERT_VK_SUCCESS(err);
2426
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002427 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2428 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2429 pipe_ms_state_ci.pNext = NULL;
2430 pipe_ms_state_ci.rasterSamples = 1;
2431 pipe_ms_state_ci.sampleShadingEnable = 0;
2432 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002433 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002434
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002435 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2436 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2437 pipeline_layout_ci.pNext = NULL;
2438 pipeline_layout_ci.descriptorSetCount = 1;
2439 pipeline_layout_ci.pSetLayouts = &ds_layout;
2440 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06002441
Tobin Ehlise4076782015-06-24 15:53:07 -06002442 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2443 ASSERT_VK_SUCCESS(err);
2444
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002445 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002446 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2447 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002448 VkPipelineObj pipe(m_device);
2449 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002450 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002451 pipe.SetMSAA(&pipe_ms_state_ci);
2452 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002453
2454 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06002455 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002456 // Don't care about actual data, just need to get to draw to flag error
2457 static const float vbo_data[3] = {1.f, 0.f, 1.f};
2458 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
2459 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
2460 Draw(0, 1, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06002461
2462 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002463 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 -06002464 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 -06002465 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
2466 }
2467}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002468#endif // DRAW_STATE_TESTS
2469
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002470#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06002471#if GTEST_IS_THREADSAFE
2472struct thread_data_struct {
2473 VkCmdBuffer cmdBuffer;
2474 VkEvent event;
2475 bool bailout;
2476};
2477
2478extern "C" void *AddToCommandBuffer(void *arg)
2479{
2480 struct thread_data_struct *data = (struct thread_data_struct *) arg;
2481 std::string msgString;
2482
2483 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06002484 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06002485 if (data->bailout) {
2486 break;
2487 }
2488 }
2489 return NULL;
2490}
2491
2492TEST_F(VkLayerTest, ThreadCmdBufferCollision)
2493{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002494 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06002495 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002496 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06002497
2498 ASSERT_NO_FATAL_FAILURE(InitState());
2499 ASSERT_NO_FATAL_FAILURE(InitViewport());
2500 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2501
Mike Stroyan09aae812015-05-12 16:00:45 -06002502 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06002503 BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002504
2505 VkEventCreateInfo event_info;
2506 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06002507 VkResult err;
2508
2509 memset(&event_info, 0, sizeof(event_info));
2510 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2511
2512 err = vkCreateEvent(device(), &event_info, &event);
2513 ASSERT_VK_SUCCESS(err);
2514
Mike Stroyan09aae812015-05-12 16:00:45 -06002515 err = vkResetEvent(device(), event);
2516 ASSERT_VK_SUCCESS(err);
2517
2518 struct thread_data_struct data;
Tony Barbour1490c912015-07-28 10:17:20 -06002519 data.cmdBuffer = m_cmdBuffer->handle();
Mike Stroyan09aae812015-05-12 16:00:45 -06002520 data.event = event;
2521 data.bailout = false;
2522 m_errorMonitor->SetBailout(&data.bailout);
2523 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002524 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06002525 // Add many entries to command buffer from this thread at the same time.
2526 AddToCommandBuffer(&data);
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002527 test_platform_thread_join(thread, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -06002528 EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002529
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002530 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002531 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 -06002532 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05002533 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06002534 }
2535
2536}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002537#endif // GTEST_IS_THREADSAFE
2538#endif // THREADING_TESTS
2539
Chris Forbes5af3bf22015-05-25 11:13:08 +12002540#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06002541TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
2542{
2543 VkFlags msgFlags;
2544 std::string msgString;
2545 ASSERT_NO_FATAL_FAILURE(InitState());
2546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2547
2548 m_errorMonitor->ClearState();
2549
2550 VkShaderModule module;
2551 VkShaderModuleCreateInfo moduleCreateInfo;
2552 struct icd_spv_header spv;
2553
2554 spv.magic = ICD_SPV_MAGIC;
2555 spv.version = ICD_SPV_VERSION;
2556 spv.gen_magic = 0;
2557
2558 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2559 moduleCreateInfo.pNext = NULL;
2560 moduleCreateInfo.pCode = &spv;
2561 moduleCreateInfo.codeSize = 4;
2562 moduleCreateInfo.flags = 0;
2563 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
2564
2565 msgFlags = m_errorMonitor->GetState(&msgString);
2566
Chris Forbes96b81762015-09-18 11:40:23 +12002567 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06002568 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
2569 FAIL() << "Incorrect warning: " << msgString;
2570 }
2571}
2572
2573TEST_F(VkLayerTest, InvalidSPIRVMagic)
2574{
2575 VkFlags msgFlags;
2576 std::string msgString;
2577 ASSERT_NO_FATAL_FAILURE(InitState());
2578 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2579
2580 m_errorMonitor->ClearState();
2581
2582 VkShaderModule module;
2583 VkShaderModuleCreateInfo moduleCreateInfo;
2584 struct icd_spv_header spv;
2585
2586 spv.magic = ~ICD_SPV_MAGIC;
2587 spv.version = ICD_SPV_VERSION;
2588 spv.gen_magic = 0;
2589
2590 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2591 moduleCreateInfo.pNext = NULL;
2592 moduleCreateInfo.pCode = &spv;
2593 moduleCreateInfo.codeSize = sizeof(spv) + 10;
2594 moduleCreateInfo.flags = 0;
2595 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
2596
2597 msgFlags = m_errorMonitor->GetState(&msgString);
2598
Chris Forbes96b81762015-09-18 11:40:23 +12002599 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06002600 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
2601 FAIL() << "Incorrect warning: " << msgString;
2602 }
2603}
2604
2605TEST_F(VkLayerTest, InvalidSPIRVVersion)
2606{
2607 VkFlags msgFlags;
2608 std::string msgString;
2609 ASSERT_NO_FATAL_FAILURE(InitState());
2610 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2611
2612 m_errorMonitor->ClearState();
2613
2614 VkShaderModule module;
2615 VkShaderModuleCreateInfo moduleCreateInfo;
2616 struct icd_spv_header spv;
2617
2618 spv.magic = ICD_SPV_MAGIC;
2619 spv.version = ~ICD_SPV_VERSION;
2620 spv.gen_magic = 0;
2621
2622 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2623 moduleCreateInfo.pNext = NULL;
2624
2625 moduleCreateInfo.pCode = &spv;
2626 moduleCreateInfo.codeSize = sizeof(spv) + 10;
2627 moduleCreateInfo.flags = 0;
2628 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
2629
2630 msgFlags = m_errorMonitor->GetState(&msgString);
2631
Chris Forbes96b81762015-09-18 11:40:23 +12002632 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06002633 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
2634 FAIL() << "Incorrect warning: " << msgString;
2635 }
2636}
2637
Chris Forbes5af3bf22015-05-25 11:13:08 +12002638TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
2639{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002640 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12002641 std::string msgString;
2642 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002643 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12002644
2645 char const *vsSource =
2646 "#version 140\n"
2647 "#extension GL_ARB_separate_shader_objects: require\n"
2648 "#extension GL_ARB_shading_language_420pack: require\n"
2649 "\n"
2650 "layout(location=0) out float x;\n"
2651 "void main(){\n"
2652 " gl_Position = vec4(1);\n"
2653 " x = 0;\n"
2654 "}\n";
2655 char const *fsSource =
2656 "#version 140\n"
2657 "#extension GL_ARB_separate_shader_objects: require\n"
2658 "#extension GL_ARB_shading_language_420pack: require\n"
2659 "\n"
2660 "layout(location=0) out vec4 color;\n"
2661 "void main(){\n"
2662 " color = vec4(1);\n"
2663 "}\n";
2664
2665 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2666 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2667
2668 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002669 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12002670 pipe.AddShader(&vs);
2671 pipe.AddShader(&fs);
2672
Chris Forbes5af3bf22015-05-25 11:13:08 +12002673 VkDescriptorSetObj descriptorSet(m_device);
2674 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002675 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002676
2677 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002678 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12002679
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002680 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002681
Cody Northrop1684adb2015-08-05 11:15:02 -06002682 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002683 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
2684 FAIL() << "Incorrect warning: " << msgString;
2685 }
2686}
Chris Forbes5af3bf22015-05-25 11:13:08 +12002687
Chris Forbes3c10b852015-05-25 11:13:13 +12002688TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
2689{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002690 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12002691 std::string msgString;
2692 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002693 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12002694
2695 char const *vsSource =
2696 "#version 140\n"
2697 "#extension GL_ARB_separate_shader_objects: require\n"
2698 "#extension GL_ARB_shading_language_420pack: require\n"
2699 "\n"
2700 "void main(){\n"
2701 " gl_Position = vec4(1);\n"
2702 "}\n";
2703 char const *fsSource =
2704 "#version 140\n"
2705 "#extension GL_ARB_separate_shader_objects: require\n"
2706 "#extension GL_ARB_shading_language_420pack: require\n"
2707 "\n"
2708 "layout(location=0) in float x;\n"
2709 "layout(location=0) out vec4 color;\n"
2710 "void main(){\n"
2711 " color = vec4(x);\n"
2712 "}\n";
2713
2714 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2715 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2716
2717 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002718 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12002719 pipe.AddShader(&vs);
2720 pipe.AddShader(&fs);
2721
Chris Forbes3c10b852015-05-25 11:13:13 +12002722 VkDescriptorSetObj descriptorSet(m_device);
2723 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002724 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12002725
2726 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002727 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12002728
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002729 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12002730
Cody Northrop1684adb2015-08-05 11:15:02 -06002731 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes3c10b852015-05-25 11:13:13 +12002732 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
2733 FAIL() << "Incorrect error: " << msgString;
2734 }
2735}
2736
Chris Forbescc281692015-05-25 11:13:17 +12002737TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
2738{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002739 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12002740 std::string msgString;
2741 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002742 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12002743
2744 char const *vsSource =
2745 "#version 140\n"
2746 "#extension GL_ARB_separate_shader_objects: require\n"
2747 "#extension GL_ARB_shading_language_420pack: require\n"
2748 "\n"
2749 "layout(location=0) out int x;\n"
2750 "void main(){\n"
2751 " x = 0;\n"
2752 " gl_Position = vec4(1);\n"
2753 "}\n";
2754 char const *fsSource =
2755 "#version 140\n"
2756 "#extension GL_ARB_separate_shader_objects: require\n"
2757 "#extension GL_ARB_shading_language_420pack: require\n"
2758 "\n"
2759 "layout(location=0) in float x;\n" /* VS writes int */
2760 "layout(location=0) out vec4 color;\n"
2761 "void main(){\n"
2762 " color = vec4(x);\n"
2763 "}\n";
2764
2765 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2766 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2767
2768 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002769 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12002770 pipe.AddShader(&vs);
2771 pipe.AddShader(&fs);
2772
Chris Forbescc281692015-05-25 11:13:17 +12002773 VkDescriptorSetObj descriptorSet(m_device);
2774 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002775 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12002776
2777 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002778 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12002779
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002780 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12002781
Cody Northrop1684adb2015-08-05 11:15:02 -06002782 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbescc281692015-05-25 11:13:17 +12002783 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
2784 FAIL() << "Incorrect error: " << msgString;
2785 }
2786}
2787
Chris Forbes8291c052015-05-25 11:13:28 +12002788TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
2789{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002790 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12002791 std::string msgString;
2792 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002793 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12002794
2795 VkVertexInputBindingDescription input_binding;
2796 memset(&input_binding, 0, sizeof(input_binding));
2797
2798 VkVertexInputAttributeDescription input_attrib;
2799 memset(&input_attrib, 0, sizeof(input_attrib));
2800 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2801
2802 char const *vsSource =
2803 "#version 140\n"
2804 "#extension GL_ARB_separate_shader_objects: require\n"
2805 "#extension GL_ARB_shading_language_420pack: require\n"
2806 "\n"
2807 "void main(){\n"
2808 " gl_Position = vec4(1);\n"
2809 "}\n";
2810 char const *fsSource =
2811 "#version 140\n"
2812 "#extension GL_ARB_separate_shader_objects: require\n"
2813 "#extension GL_ARB_shading_language_420pack: require\n"
2814 "\n"
2815 "layout(location=0) out vec4 color;\n"
2816 "void main(){\n"
2817 " color = vec4(1);\n"
2818 "}\n";
2819
2820 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2821 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2822
2823 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002824 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12002825 pipe.AddShader(&vs);
2826 pipe.AddShader(&fs);
2827
2828 pipe.AddVertexInputBindings(&input_binding, 1);
2829 pipe.AddVertexInputAttribs(&input_attrib, 1);
2830
Chris Forbes8291c052015-05-25 11:13:28 +12002831 VkDescriptorSetObj descriptorSet(m_device);
2832 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002833 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12002834
2835 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002836 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12002837
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002838 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12002839
Cody Northrop1684adb2015-08-05 11:15:02 -06002840 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12002841 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
2842 FAIL() << "Incorrect warning: " << msgString;
2843 }
2844}
2845
Chris Forbes37367e62015-05-25 11:13:29 +12002846TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
2847{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002848 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12002849 std::string msgString;
2850 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12002852
2853 char const *vsSource =
2854 "#version 140\n"
2855 "#extension GL_ARB_separate_shader_objects: require\n"
2856 "#extension GL_ARB_shading_language_420pack: require\n"
2857 "\n"
2858 "layout(location=0) in vec4 x;\n" /* not provided */
2859 "void main(){\n"
2860 " gl_Position = x;\n"
2861 "}\n";
2862 char const *fsSource =
2863 "#version 140\n"
2864 "#extension GL_ARB_separate_shader_objects: require\n"
2865 "#extension GL_ARB_shading_language_420pack: require\n"
2866 "\n"
2867 "layout(location=0) out vec4 color;\n"
2868 "void main(){\n"
2869 " color = vec4(1);\n"
2870 "}\n";
2871
2872 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2873 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2874
2875 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002876 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12002877 pipe.AddShader(&vs);
2878 pipe.AddShader(&fs);
2879
Chris Forbes37367e62015-05-25 11:13:29 +12002880 VkDescriptorSetObj descriptorSet(m_device);
2881 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002882 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12002883
2884 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002885 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12002886
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002887 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12002888
Cody Northrop1684adb2015-08-05 11:15:02 -06002889 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes37367e62015-05-25 11:13:29 +12002890 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
2891 FAIL() << "Incorrect warning: " << msgString;
2892 }
2893}
2894
Chris Forbesa4b02322015-05-25 11:13:31 +12002895TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
2896{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002897 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12002898 std::string msgString;
2899 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002900 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12002901
2902 VkVertexInputBindingDescription input_binding;
2903 memset(&input_binding, 0, sizeof(input_binding));
2904
2905 VkVertexInputAttributeDescription input_attrib;
2906 memset(&input_attrib, 0, sizeof(input_attrib));
2907 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2908
2909 char const *vsSource =
2910 "#version 140\n"
2911 "#extension GL_ARB_separate_shader_objects: require\n"
2912 "#extension GL_ARB_shading_language_420pack: require\n"
2913 "\n"
2914 "layout(location=0) in int x;\n" /* attrib provided float */
2915 "void main(){\n"
2916 " gl_Position = vec4(x);\n"
2917 "}\n";
2918 char const *fsSource =
2919 "#version 140\n"
2920 "#extension GL_ARB_separate_shader_objects: require\n"
2921 "#extension GL_ARB_shading_language_420pack: require\n"
2922 "\n"
2923 "layout(location=0) out vec4 color;\n"
2924 "void main(){\n"
2925 " color = vec4(1);\n"
2926 "}\n";
2927
2928 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2929 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2930
2931 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002932 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12002933 pipe.AddShader(&vs);
2934 pipe.AddShader(&fs);
2935
2936 pipe.AddVertexInputBindings(&input_binding, 1);
2937 pipe.AddVertexInputAttribs(&input_attrib, 1);
2938
Chris Forbesa4b02322015-05-25 11:13:31 +12002939 VkDescriptorSetObj descriptorSet(m_device);
2940 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002941 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12002942
2943 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002944 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12002945
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002946 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12002947
Cody Northrop1684adb2015-08-05 11:15:02 -06002948 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa4b02322015-05-25 11:13:31 +12002949 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
2950 FAIL() << "Incorrect error: " << msgString;
2951 }
2952}
2953
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002954TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
2955{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002956 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002957 std::string msgString;
2958 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002960
2961 /* Two binding descriptions for binding 0 */
2962 VkVertexInputBindingDescription input_bindings[2];
2963 memset(input_bindings, 0, sizeof(input_bindings));
2964
2965 VkVertexInputAttributeDescription input_attrib;
2966 memset(&input_attrib, 0, sizeof(input_attrib));
2967 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2968
2969 char const *vsSource =
2970 "#version 140\n"
2971 "#extension GL_ARB_separate_shader_objects: require\n"
2972 "#extension GL_ARB_shading_language_420pack: require\n"
2973 "\n"
2974 "layout(location=0) in float x;\n" /* attrib provided float */
2975 "void main(){\n"
2976 " gl_Position = vec4(x);\n"
2977 "}\n";
2978 char const *fsSource =
2979 "#version 140\n"
2980 "#extension GL_ARB_separate_shader_objects: require\n"
2981 "#extension GL_ARB_shading_language_420pack: require\n"
2982 "\n"
2983 "layout(location=0) out vec4 color;\n"
2984 "void main(){\n"
2985 " color = vec4(1);\n"
2986 "}\n";
2987
2988 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2989 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2990
2991 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002992 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002993 pipe.AddShader(&vs);
2994 pipe.AddShader(&fs);
2995
2996 pipe.AddVertexInputBindings(input_bindings, 2);
2997 pipe.AddVertexInputAttribs(&input_attrib, 1);
2998
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002999 VkDescriptorSetObj descriptorSet(m_device);
3000 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003001 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003002
3003 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003004 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003005
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003006 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003007
Cody Northrop1684adb2015-08-05 11:15:02 -06003008 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003009 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
3010 FAIL() << "Incorrect error: " << msgString;
3011 }
3012}
Chris Forbes4c948702015-05-25 11:13:32 +12003013
Chris Forbesc12ef122015-05-25 11:13:40 +12003014/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
3015 * rejects it. */
3016
3017TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
3018{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003019 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12003020 std::string msgString;
3021 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12003022
3023 char const *vsSource =
3024 "#version 140\n"
3025 "#extension GL_ARB_separate_shader_objects: require\n"
3026 "#extension GL_ARB_shading_language_420pack: require\n"
3027 "\n"
3028 "void main(){\n"
3029 " gl_Position = vec4(1);\n"
3030 "}\n";
3031 char const *fsSource =
3032 "#version 140\n"
3033 "#extension GL_ARB_separate_shader_objects: require\n"
3034 "#extension GL_ARB_shading_language_420pack: require\n"
3035 "\n"
3036 "void main(){\n"
3037 "}\n";
3038
3039 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3040 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3041
3042 VkPipelineObj pipe(m_device);
3043 pipe.AddShader(&vs);
3044 pipe.AddShader(&fs);
3045
Chia-I Wuc278df82015-07-07 11:50:03 +08003046 /* set up CB 0, not written */
3047 pipe.AddColorAttachment();
3048 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12003049
Chris Forbesc12ef122015-05-25 11:13:40 +12003050 VkDescriptorSetObj descriptorSet(m_device);
3051 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003052 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12003053
3054 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003055 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12003056
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003057 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12003058
Cody Northrop1684adb2015-08-05 11:15:02 -06003059 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc12ef122015-05-25 11:13:40 +12003060 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
3061 FAIL() << "Incorrect error: " << msgString;
3062 }
3063}
3064
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003065TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
3066{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003067 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003068 std::string msgString;
3069 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003070
3071 char const *vsSource =
3072 "#version 140\n"
3073 "#extension GL_ARB_separate_shader_objects: require\n"
3074 "#extension GL_ARB_shading_language_420pack: require\n"
3075 "\n"
3076 "void main(){\n"
3077 " gl_Position = vec4(1);\n"
3078 "}\n";
3079 char const *fsSource =
3080 "#version 140\n"
3081 "#extension GL_ARB_separate_shader_objects: require\n"
3082 "#extension GL_ARB_shading_language_420pack: require\n"
3083 "\n"
3084 "layout(location=0) out vec4 x;\n"
3085 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
3086 "void main(){\n"
3087 " x = vec4(1);\n"
3088 " y = vec4(1);\n"
3089 "}\n";
3090
3091 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3092 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3093
3094 VkPipelineObj pipe(m_device);
3095 pipe.AddShader(&vs);
3096 pipe.AddShader(&fs);
3097
Chia-I Wuc278df82015-07-07 11:50:03 +08003098 /* set up CB 0, not written */
3099 pipe.AddColorAttachment();
3100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003101 /* FS writes CB 1, but we don't configure it */
3102
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003103 VkDescriptorSetObj descriptorSet(m_device);
3104 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003105 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003106
3107 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003108 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003109
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003110 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003111
Cody Northrop1684adb2015-08-05 11:15:02 -06003112 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003113 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
3114 FAIL() << "Incorrect warning: " << msgString;
3115 }
3116}
3117
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003118TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
3119{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003120 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003121 std::string msgString;
3122 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003123
3124 char const *vsSource =
3125 "#version 140\n"
3126 "#extension GL_ARB_separate_shader_objects: require\n"
3127 "#extension GL_ARB_shading_language_420pack: require\n"
3128 "\n"
3129 "void main(){\n"
3130 " gl_Position = vec4(1);\n"
3131 "}\n";
3132 char const *fsSource =
3133 "#version 140\n"
3134 "#extension GL_ARB_separate_shader_objects: require\n"
3135 "#extension GL_ARB_shading_language_420pack: require\n"
3136 "\n"
3137 "layout(location=0) out ivec4 x;\n" /* not UNORM */
3138 "void main(){\n"
3139 " x = ivec4(1);\n"
3140 "}\n";
3141
3142 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3143 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3144
3145 VkPipelineObj pipe(m_device);
3146 pipe.AddShader(&vs);
3147 pipe.AddShader(&fs);
3148
Chia-I Wuc278df82015-07-07 11:50:03 +08003149 /* set up CB 0; type is UNORM by default */
3150 pipe.AddColorAttachment();
3151 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003152
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003153 VkDescriptorSetObj descriptorSet(m_device);
3154 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003155 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003156
3157 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003158 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003159
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003160 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003161
Cody Northrop1684adb2015-08-05 11:15:02 -06003162 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003163 if (!strstr(msgString.c_str(),"does not match FS output type")) {
3164 FAIL() << "Incorrect error: " << msgString;
3165 }
3166}
Chris Forbesc2050732015-06-05 14:43:36 +12003167
Chris Forbes76ce7882015-08-14 12:04:59 +12003168TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
3169{
3170 VkFlags msgFlags;
3171 std::string msgString;
3172 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +12003173
3174 char const *vsSource =
3175 "#version 140\n"
3176 "#extension GL_ARB_separate_shader_objects: require\n"
3177 "#extension GL_ARB_shading_language_420pack: require\n"
3178 "\n"
3179 "void main(){\n"
3180 " gl_Position = vec4(1);\n"
3181 "}\n";
3182 char const *fsSource =
3183 "#version 140\n"
3184 "#extension GL_ARB_separate_shader_objects: require\n"
3185 "#extension GL_ARB_shading_language_420pack: require\n"
3186 "\n"
3187 "layout(location=0) out vec4 x;\n"
3188 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
3189 "void main(){\n"
3190 " x = vec4(bar.y);\n"
3191 "}\n";
3192
3193 m_errorMonitor->ClearState();
3194
3195 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3196 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3197
3198
3199 VkPipelineObj pipe(m_device);
3200 pipe.AddShader(&vs);
3201 pipe.AddShader(&fs);
3202
3203 /* set up CB 0; type is UNORM by default */
3204 pipe.AddColorAttachment();
3205 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3206
3207 VkDescriptorSetObj descriptorSet(m_device);
3208 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
3209
3210 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3211
3212 /* should have generated an error -- pipeline layout does not
3213 * provide a uniform buffer in 0.0
3214 */
3215 msgFlags = m_errorMonitor->GetState(&msgString);
3216 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
3217 if (!strstr(msgString.c_str(),"not declared in pipeline layout")) {
3218 FAIL() << "Incorrect error: " << msgString;
3219 }
3220}
3221
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003222#endif // SHADER_CHECKER_TESTS
3223
3224#if DEVICE_LIMITS_TESTS
3225// TBD
3226#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003227
Tony Barbour30486ea2015-04-07 13:44:53 -06003228int main(int argc, char **argv) {
3229 int result;
3230
3231 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06003232 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06003233
3234 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
3235
3236 result = RUN_ALL_TESTS();
3237
Tony Barbour01999182015-04-09 12:58:51 -06003238 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06003239 return result;
3240}