blob: ab4e3d2031bacb76ee81eb7447189187ad5dd314 [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}
1534
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001535TEST_F(VkLayerTest, NullRenderPass)
1536{
1537 // Bind a NULL RenderPass
1538 VkFlags msgFlags;
1539 std::string msgString;
1540
1541 ASSERT_NO_FATAL_FAILURE(InitState());
1542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1543 m_errorMonitor->ClearState();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001544
Tony Barbour1490c912015-07-28 10:17:20 -06001545 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001546 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06001547 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001548
1549 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001550 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001551 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
1552 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
1553 }
1554}
1555
Tobin Ehlis254eca02015-06-25 15:46:59 -06001556TEST_F(VkLayerTest, RenderPassWithinRenderPass)
1557{
1558 // Bind a BeginRenderPass within an active RenderPass
1559 VkFlags msgFlags;
1560 std::string msgString;
1561
1562 ASSERT_NO_FATAL_FAILURE(InitState());
1563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1564 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001565
Tony Barbour1490c912015-07-28 10:17:20 -06001566 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001567 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001568 VkRenderPassBeginInfo rp_begin = {};
1569 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
1570 rp_begin.pNext = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001571 rp_begin.renderPass = renderPass();
1572 rp_begin.framebuffer = framebuffer();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001573
Tony Barbour1490c912015-07-28 10:17:20 -06001574 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001575
1576 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001577 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 -06001578 if (!strstr(msgString.c_str(),"Cannot call vkCmdBeginRenderPass() during an active RenderPass ")) {
1579 FAIL() << "Error received was not 'Cannot call vkCmdBeginRenderPass() during an active RenderPass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001580 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001581}
1582
1583TEST_F(VkLayerTest, InvalidDynamicStateObject)
1584{
1585 // Create a valid cmd buffer
1586 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001587 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1588 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001589}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06001590
Tobin Ehlise4076782015-06-24 15:53:07 -06001591TEST_F(VkLayerTest, VtxBufferNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001592{
1593 // Bind VBO out-of-bounds for given PSO
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001594 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001595 std::string msgString;
1596 VkResult err;
1597
1598 ASSERT_NO_FATAL_FAILURE(InitState());
1599 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001600
1601 VkDescriptorTypeCount ds_type_count = {};
1602 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1603 ds_type_count.count = 1;
1604
1605 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1606 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1607 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001608 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1609 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001610 ds_pool_ci.count = 1;
1611 ds_pool_ci.pTypeCount = &ds_type_count;
1612
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001613 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001614 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001615 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001616
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001617 VkDescriptorSetLayoutBinding dsl_binding = {};
1618 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1619 dsl_binding.arraySize = 1;
1620 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1621 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001622
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001623 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1624 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1625 ds_layout_ci.pNext = NULL;
1626 ds_layout_ci.count = 1;
1627 ds_layout_ci.pBinding = &dsl_binding;
1628
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001629 VkDescriptorSetLayout ds_layout;
1630 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1631 ASSERT_VK_SUCCESS(err);
1632
1633 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001634 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001635 ASSERT_VK_SUCCESS(err);
1636
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001637 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1638 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1639 pipeline_layout_ci.pNext = NULL;
1640 pipeline_layout_ci.descriptorSetCount = 1;
1641 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001642
1643 VkPipelineLayout pipeline_layout;
1644 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1645 ASSERT_VK_SUCCESS(err);
1646
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001647 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001648 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1649 // but add it to be able to run on more devices
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001650 VkPipelineObj pipe(m_device);
1651 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001652 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001653 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001654
Tony Barbour1490c912015-07-28 10:17:20 -06001655 BeginCommandBuffer();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001656 ASSERT_VK_SUCCESS(err);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001657 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001658 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06001659 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001660
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001661 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001662 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 -06001663 if (!strstr(msgString.c_str(),"Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.")) {
1664 FAIL() << "Error received was not 'Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001665 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001666}
1667
1668TEST_F(VkLayerTest, DSTypeMismatch)
1669{
1670 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001671 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001672 std::string msgString;
1673 VkResult err;
1674
1675 ASSERT_NO_FATAL_FAILURE(InitState());
1676 m_errorMonitor->ClearState();
1677 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001678 VkDescriptorTypeCount ds_type_count = {};
1679 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1680 ds_type_count.count = 1;
1681
1682 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1683 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1684 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001685 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1686 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001687 ds_pool_ci.count = 1;
1688 ds_pool_ci.pTypeCount = &ds_type_count;
1689
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001690 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001691 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001692 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001693 VkDescriptorSetLayoutBinding dsl_binding = {};
1694 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1695 dsl_binding.arraySize = 1;
1696 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1697 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001698
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001699 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1700 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1701 ds_layout_ci.pNext = NULL;
1702 ds_layout_ci.count = 1;
1703 ds_layout_ci.pBinding = &dsl_binding;
1704
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001705 VkDescriptorSetLayout ds_layout;
1706 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1707 ASSERT_VK_SUCCESS(err);
1708
1709 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001710 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001711 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001712
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001713 VkSamplerCreateInfo sampler_ci = {};
1714 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1715 sampler_ci.pNext = NULL;
1716 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1717 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1718 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06001719 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
1720 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
1721 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001722 sampler_ci.mipLodBias = 1.0;
1723 sampler_ci.maxAnisotropy = 1;
1724 sampler_ci.compareEnable = VK_FALSE;
1725 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1726 sampler_ci.minLod = 1.0;
1727 sampler_ci.maxLod = 1.0;
1728 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06001729 sampler_ci.unnormalizedCoordinates = VK_FALSE;
1730
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001731 VkSampler sampler;
1732 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1733 ASSERT_VK_SUCCESS(err);
1734
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001735 VkDescriptorInfo descriptor_info;
1736 memset(&descriptor_info, 0, sizeof(descriptor_info));
1737 descriptor_info.sampler = sampler;
1738
1739 VkWriteDescriptorSet descriptor_write;
1740 memset(&descriptor_write, 0, sizeof(descriptor_write));
1741 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1742 descriptor_write.destSet = descriptorSet;
1743 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001744 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001745 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1746 descriptor_write.pDescriptors = &descriptor_info;
1747
1748 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1749
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001750 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001751 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 +08001752 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) {
1753 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 -06001754 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001755}
1756
1757TEST_F(VkLayerTest, DSUpdateOutOfBounds)
1758{
1759 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001760 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001761 std::string msgString;
1762 VkResult err;
1763
1764 ASSERT_NO_FATAL_FAILURE(InitState());
1765 m_errorMonitor->ClearState();
1766 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001767 VkDescriptorTypeCount ds_type_count = {};
1768 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1769 ds_type_count.count = 1;
1770
1771 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1772 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1773 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001774 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1775 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001776 ds_pool_ci.count = 1;
1777 ds_pool_ci.pTypeCount = &ds_type_count;
1778
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001779 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001780 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001781 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001782
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001783 VkDescriptorSetLayoutBinding dsl_binding = {};
1784 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1785 dsl_binding.arraySize = 1;
1786 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1787 dsl_binding.pImmutableSamplers = NULL;
1788
1789 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1790 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1791 ds_layout_ci.pNext = NULL;
1792 ds_layout_ci.count = 1;
1793 ds_layout_ci.pBinding = &dsl_binding;
1794
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001795 VkDescriptorSetLayout ds_layout;
1796 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1797 ASSERT_VK_SUCCESS(err);
1798
1799 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001800 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001801 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001802
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001803 VkSamplerCreateInfo sampler_ci = {};
1804 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1805 sampler_ci.pNext = NULL;
1806 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1807 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1808 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06001809 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
1810 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
1811 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001812 sampler_ci.mipLodBias = 1.0;
1813 sampler_ci.maxAnisotropy = 1;
1814 sampler_ci.compareEnable = VK_FALSE;
1815 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1816 sampler_ci.minLod = 1.0;
1817 sampler_ci.maxLod = 1.0;
1818 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06001819 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001820
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001821 VkSampler sampler;
1822 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1823 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001824
1825 VkDescriptorInfo descriptor_info;
1826 memset(&descriptor_info, 0, sizeof(descriptor_info));
1827 descriptor_info.sampler = sampler;
1828
1829 VkWriteDescriptorSet descriptor_write;
1830 memset(&descriptor_write, 0, sizeof(descriptor_write));
1831 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1832 descriptor_write.destSet = descriptorSet;
1833 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
1834 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001835 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001836 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1837 descriptor_write.pDescriptors = &descriptor_info;
1838
1839 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1840
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001841 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001842 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 +08001843 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
1844 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 -06001845 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001846}
1847
1848TEST_F(VkLayerTest, InvalidDSUpdateIndex)
1849{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001850 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001851 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001852 std::string msgString;
1853 VkResult err;
1854
1855 ASSERT_NO_FATAL_FAILURE(InitState());
1856 m_errorMonitor->ClearState();
1857 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001858 VkDescriptorTypeCount ds_type_count = {};
1859 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1860 ds_type_count.count = 1;
1861
1862 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1863 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1864 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001865 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1866 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001867 ds_pool_ci.count = 1;
1868 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001869
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001870 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001871 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001872 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001873
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001874 VkDescriptorSetLayoutBinding dsl_binding = {};
1875 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1876 dsl_binding.arraySize = 1;
1877 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1878 dsl_binding.pImmutableSamplers = NULL;
1879
1880 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1881 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1882 ds_layout_ci.pNext = NULL;
1883 ds_layout_ci.count = 1;
1884 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001885 VkDescriptorSetLayout ds_layout;
1886 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1887 ASSERT_VK_SUCCESS(err);
1888
1889 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001890 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001891 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001892
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001893 VkSamplerCreateInfo sampler_ci = {};
1894 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1895 sampler_ci.pNext = NULL;
1896 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1897 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1898 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06001899 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
1900 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
1901 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001902 sampler_ci.mipLodBias = 1.0;
1903 sampler_ci.maxAnisotropy = 1;
1904 sampler_ci.compareEnable = VK_FALSE;
1905 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1906 sampler_ci.minLod = 1.0;
1907 sampler_ci.maxLod = 1.0;
1908 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06001909 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001910
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001911 VkSampler sampler;
1912 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1913 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001914
1915 VkDescriptorInfo descriptor_info;
1916 memset(&descriptor_info, 0, sizeof(descriptor_info));
1917 descriptor_info.sampler = sampler;
1918
1919 VkWriteDescriptorSet descriptor_write;
1920 memset(&descriptor_write, 0, sizeof(descriptor_write));
1921 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1922 descriptor_write.destSet = descriptorSet;
1923 descriptor_write.destBinding = 2;
1924 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001925 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001926 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1927 descriptor_write.pDescriptors = &descriptor_info;
1928
1929 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1930
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001931 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001932 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 -06001933 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
1934 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
1935 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001936}
1937
1938TEST_F(VkLayerTest, InvalidDSUpdateStruct)
1939{
1940 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001941 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001942 std::string msgString;
1943 VkResult err;
1944
1945 ASSERT_NO_FATAL_FAILURE(InitState());
1946 m_errorMonitor->ClearState();
1947 //VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001948
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001949 VkDescriptorTypeCount ds_type_count = {};
1950 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1951 ds_type_count.count = 1;
1952
1953 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1954 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1955 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001956 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1957 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001958 ds_pool_ci.count = 1;
1959 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001960
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001961 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001962 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001963 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001964 VkDescriptorSetLayoutBinding dsl_binding = {};
1965 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1966 dsl_binding.arraySize = 1;
1967 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1968 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001969
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001970 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1971 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1972 ds_layout_ci.pNext = NULL;
1973 ds_layout_ci.count = 1;
1974 ds_layout_ci.pBinding = &dsl_binding;
1975
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001976 VkDescriptorSetLayout ds_layout;
1977 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1978 ASSERT_VK_SUCCESS(err);
1979
1980 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001981 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001982 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001983
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001984 VkSamplerCreateInfo sampler_ci = {};
1985 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1986 sampler_ci.pNext = NULL;
1987 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1988 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1989 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06001990 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
1991 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
1992 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001993 sampler_ci.mipLodBias = 1.0;
1994 sampler_ci.maxAnisotropy = 1;
1995 sampler_ci.compareEnable = VK_FALSE;
1996 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1997 sampler_ci.minLod = 1.0;
1998 sampler_ci.maxLod = 1.0;
1999 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002000 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002001 VkSampler sampler;
2002 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2003 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002004
2005
2006 VkDescriptorInfo descriptor_info;
2007 memset(&descriptor_info, 0, sizeof(descriptor_info));
2008 descriptor_info.sampler = sampler;
2009
2010 VkWriteDescriptorSet descriptor_write;
2011 memset(&descriptor_write, 0, sizeof(descriptor_write));
2012 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
2013 descriptor_write.destSet = descriptorSet;
2014 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002015 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002016 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2017 descriptor_write.pDescriptors = &descriptor_info;
2018
2019 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2020
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002021 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002022 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 -06002023 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
2024 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
2025 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002026}
2027
2028TEST_F(VkLayerTest, NumSamplesMismatch)
2029{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002030 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002031 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002032 std::string msgString;
2033 VkResult err;
2034
2035 ASSERT_NO_FATAL_FAILURE(InitState());
2036 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2037 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002038 VkDescriptorTypeCount ds_type_count = {};
2039 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2040 ds_type_count.count = 1;
2041
2042 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002043 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2044 ds_pool_ci.pNext = NULL;
2045 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2046 ds_pool_ci.maxSets = 1;
2047 ds_pool_ci.count = 1;
2048 ds_pool_ci.pTypeCount = &ds_type_count;
2049
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002050 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002051 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002052 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002053
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002054 VkDescriptorSetLayoutBinding dsl_binding = {};
2055 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2056 dsl_binding.arraySize = 1;
2057 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2058 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002059
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002060 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2061 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2062 ds_layout_ci.pNext = NULL;
2063 ds_layout_ci.count = 1;
2064 ds_layout_ci.pBinding = &dsl_binding;
2065
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002066 VkDescriptorSetLayout ds_layout;
2067 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2068 ASSERT_VK_SUCCESS(err);
2069
2070 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002071 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002072 ASSERT_VK_SUCCESS(err);
2073
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002074 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2075 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2076 pipe_ms_state_ci.pNext = NULL;
2077 pipe_ms_state_ci.rasterSamples = 4;
2078 pipe_ms_state_ci.sampleShadingEnable = 0;
2079 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002080 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002081
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002082 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2083 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2084 pipeline_layout_ci.pNext = NULL;
2085 pipeline_layout_ci.descriptorSetCount = 1;
2086 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002087
2088 VkPipelineLayout pipeline_layout;
2089 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2090 ASSERT_VK_SUCCESS(err);
2091
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002092 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002093 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2094 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002095 VkPipelineObj pipe(m_device);
2096 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002097 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002098 pipe.SetMSAA(&pipe_ms_state_ci);
2099 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002100
Tony Barbour1490c912015-07-28 10:17:20 -06002101 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06002102 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002103
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002104 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002105 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 -06002106 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
2107 FAIL() << "Error received was not 'Num samples mismatch!...'";
2108 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002109}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002110
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002111TEST_F(VkLayerTest, ClearCmdNoDraw)
2112{
2113 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
2114 VkFlags msgFlags;
2115 std::string msgString;
2116 VkResult err;
2117
2118 ASSERT_NO_FATAL_FAILURE(InitState());
2119 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2120 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002121
2122 VkDescriptorTypeCount ds_type_count = {};
2123 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2124 ds_type_count.count = 1;
2125
2126 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2127 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2128 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002129 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2130 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002131 ds_pool_ci.count = 1;
2132 ds_pool_ci.pTypeCount = &ds_type_count;
2133
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002134 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002135 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002136 ASSERT_VK_SUCCESS(err);
2137
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002138 VkDescriptorSetLayoutBinding dsl_binding = {};
2139 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2140 dsl_binding.arraySize = 1;
2141 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2142 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002143
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002144 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2145 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2146 ds_layout_ci.pNext = NULL;
2147 ds_layout_ci.count = 1;
2148 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002149
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002150 VkDescriptorSetLayout ds_layout;
2151 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2152 ASSERT_VK_SUCCESS(err);
2153
2154 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002155 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002156 ASSERT_VK_SUCCESS(err);
2157
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002158 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2159 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2160 pipe_ms_state_ci.pNext = NULL;
2161 pipe_ms_state_ci.rasterSamples = 4;
2162 pipe_ms_state_ci.sampleShadingEnable = 0;
2163 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002164 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002165
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002166 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2167 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2168 pipeline_layout_ci.pNext = NULL;
2169 pipeline_layout_ci.descriptorSetCount = 1;
2170 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002171
2172 VkPipelineLayout pipeline_layout;
2173 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2174 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002175
Tony Barbourd7d828b2015-08-06 10:16:07 -06002176 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002177 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2178 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002179 VkPipelineObj pipe(m_device);
2180 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002181 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002182 pipe.SetMSAA(&pipe_ms_state_ci);
2183 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002184
2185 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002186
2187 m_errorMonitor->ClearState();
2188 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
2189 // Also pass down other dummy params to keep driver and paramchecker happy
2190 VkClearColorValue cCV;
Cody Northrop2563a032015-08-25 15:26:38 -06002191 cCV.float32[0] = 1.0;
2192 cCV.float32[1] = 1.0;
2193 cCV.float32[2] = 1.0;
2194 cCV.float32[3] = 1.0;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002195
Tony Barbour1490c912015-07-28 10:17:20 -06002196 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002197 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002198 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 -06002199 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) {
2200 FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'";
2201 }
2202}
2203
Tobin Ehlise4076782015-06-24 15:53:07 -06002204TEST_F(VkLayerTest, VtxBufferBadIndex)
2205{
2206 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
2207 VkFlags msgFlags;
2208 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
2215 VkDescriptorTypeCount ds_type_count = {};
2216 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2217 ds_type_count.count = 1;
2218
2219 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2220 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2221 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002222 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2223 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002224 ds_pool_ci.count = 1;
2225 ds_pool_ci.pTypeCount = &ds_type_count;
2226
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002227 VkDescriptorPool ds_pool;
2228 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06002229 ASSERT_VK_SUCCESS(err);
2230
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002231 VkDescriptorSetLayoutBinding dsl_binding = {};
2232 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2233 dsl_binding.arraySize = 1;
2234 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2235 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002236
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002237 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2238 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2239 ds_layout_ci.pNext = NULL;
2240 ds_layout_ci.count = 1;
2241 ds_layout_ci.pBinding = &dsl_binding;
2242
Tobin Ehlise4076782015-06-24 15:53:07 -06002243 VkDescriptorSetLayout ds_layout;
2244 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2245 ASSERT_VK_SUCCESS(err);
2246
2247 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002248 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06002249 ASSERT_VK_SUCCESS(err);
2250
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002251 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2252 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2253 pipe_ms_state_ci.pNext = NULL;
2254 pipe_ms_state_ci.rasterSamples = 1;
2255 pipe_ms_state_ci.sampleShadingEnable = 0;
2256 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002257 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002258
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002259 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2260 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2261 pipeline_layout_ci.pNext = NULL;
2262 pipeline_layout_ci.descriptorSetCount = 1;
2263 pipeline_layout_ci.pSetLayouts = &ds_layout;
2264 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06002265
Tobin Ehlise4076782015-06-24 15:53:07 -06002266 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2267 ASSERT_VK_SUCCESS(err);
2268
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002269 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002270 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2271 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002272 VkPipelineObj pipe(m_device);
2273 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002274 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002275 pipe.SetMSAA(&pipe_ms_state_ci);
2276 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002277
2278 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06002279 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002280 // Don't care about actual data, just need to get to draw to flag error
2281 static const float vbo_data[3] = {1.f, 0.f, 1.f};
2282 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
2283 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
2284 Draw(0, 1, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06002285
2286 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002287 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 -06002288 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 -06002289 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
2290 }
2291}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002292#endif // DRAW_STATE_TESTS
2293
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002294#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06002295#if GTEST_IS_THREADSAFE
2296struct thread_data_struct {
2297 VkCmdBuffer cmdBuffer;
2298 VkEvent event;
2299 bool bailout;
2300};
2301
2302extern "C" void *AddToCommandBuffer(void *arg)
2303{
2304 struct thread_data_struct *data = (struct thread_data_struct *) arg;
2305 std::string msgString;
2306
2307 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06002308 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06002309 if (data->bailout) {
2310 break;
2311 }
2312 }
2313 return NULL;
2314}
2315
2316TEST_F(VkLayerTest, ThreadCmdBufferCollision)
2317{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002318 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06002319 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002320 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06002321
2322 ASSERT_NO_FATAL_FAILURE(InitState());
2323 ASSERT_NO_FATAL_FAILURE(InitViewport());
2324 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2325
Mike Stroyan09aae812015-05-12 16:00:45 -06002326 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06002327 BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002328
2329 VkEventCreateInfo event_info;
2330 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06002331 VkResult err;
2332
2333 memset(&event_info, 0, sizeof(event_info));
2334 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2335
2336 err = vkCreateEvent(device(), &event_info, &event);
2337 ASSERT_VK_SUCCESS(err);
2338
Mike Stroyan09aae812015-05-12 16:00:45 -06002339 err = vkResetEvent(device(), event);
2340 ASSERT_VK_SUCCESS(err);
2341
2342 struct thread_data_struct data;
Tony Barbour1490c912015-07-28 10:17:20 -06002343 data.cmdBuffer = m_cmdBuffer->handle();
Mike Stroyan09aae812015-05-12 16:00:45 -06002344 data.event = event;
2345 data.bailout = false;
2346 m_errorMonitor->SetBailout(&data.bailout);
2347 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002348 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06002349 // Add many entries to command buffer from this thread at the same time.
2350 AddToCommandBuffer(&data);
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002351 test_platform_thread_join(thread, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -06002352 EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002353
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002354 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002355 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 -06002356 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05002357 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06002358 }
2359
2360}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002361#endif // GTEST_IS_THREADSAFE
2362#endif // THREADING_TESTS
2363
Chris Forbes5af3bf22015-05-25 11:13:08 +12002364#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06002365TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
2366{
2367 VkFlags msgFlags;
2368 std::string msgString;
2369 ASSERT_NO_FATAL_FAILURE(InitState());
2370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2371
2372 m_errorMonitor->ClearState();
2373
2374 VkShaderModule module;
2375 VkShaderModuleCreateInfo moduleCreateInfo;
2376 struct icd_spv_header spv;
2377
2378 spv.magic = ICD_SPV_MAGIC;
2379 spv.version = ICD_SPV_VERSION;
2380 spv.gen_magic = 0;
2381
2382 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2383 moduleCreateInfo.pNext = NULL;
2384 moduleCreateInfo.pCode = &spv;
2385 moduleCreateInfo.codeSize = 4;
2386 moduleCreateInfo.flags = 0;
2387 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
2388
2389 msgFlags = m_errorMonitor->GetState(&msgString);
2390
2391 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
2392 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
2393 FAIL() << "Incorrect warning: " << msgString;
2394 }
2395}
2396
2397TEST_F(VkLayerTest, InvalidSPIRVMagic)
2398{
2399 VkFlags msgFlags;
2400 std::string msgString;
2401 ASSERT_NO_FATAL_FAILURE(InitState());
2402 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2403
2404 m_errorMonitor->ClearState();
2405
2406 VkShaderModule module;
2407 VkShaderModuleCreateInfo moduleCreateInfo;
2408 struct icd_spv_header spv;
2409
2410 spv.magic = ~ICD_SPV_MAGIC;
2411 spv.version = ICD_SPV_VERSION;
2412 spv.gen_magic = 0;
2413
2414 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2415 moduleCreateInfo.pNext = NULL;
2416 moduleCreateInfo.pCode = &spv;
2417 moduleCreateInfo.codeSize = sizeof(spv) + 10;
2418 moduleCreateInfo.flags = 0;
2419 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
2420
2421 msgFlags = m_errorMonitor->GetState(&msgString);
2422
2423 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
2424 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
2425 FAIL() << "Incorrect warning: " << msgString;
2426 }
2427}
2428
2429TEST_F(VkLayerTest, InvalidSPIRVVersion)
2430{
2431 VkFlags msgFlags;
2432 std::string msgString;
2433 ASSERT_NO_FATAL_FAILURE(InitState());
2434 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2435
2436 m_errorMonitor->ClearState();
2437
2438 VkShaderModule module;
2439 VkShaderModuleCreateInfo moduleCreateInfo;
2440 struct icd_spv_header spv;
2441
2442 spv.magic = ICD_SPV_MAGIC;
2443 spv.version = ~ICD_SPV_VERSION;
2444 spv.gen_magic = 0;
2445
2446 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2447 moduleCreateInfo.pNext = NULL;
2448
2449 moduleCreateInfo.pCode = &spv;
2450 moduleCreateInfo.codeSize = sizeof(spv) + 10;
2451 moduleCreateInfo.flags = 0;
2452 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
2453
2454 msgFlags = m_errorMonitor->GetState(&msgString);
2455
2456 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
2457 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
2458 FAIL() << "Incorrect warning: " << msgString;
2459 }
2460}
2461
Chris Forbes5af3bf22015-05-25 11:13:08 +12002462TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
2463{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002464 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12002465 std::string msgString;
2466 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002467 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002468 ScopedUseGlsl useGlsl(false);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002469
2470 char const *vsSource =
2471 "#version 140\n"
2472 "#extension GL_ARB_separate_shader_objects: require\n"
2473 "#extension GL_ARB_shading_language_420pack: require\n"
2474 "\n"
2475 "layout(location=0) out float x;\n"
2476 "void main(){\n"
2477 " gl_Position = vec4(1);\n"
2478 " x = 0;\n"
2479 "}\n";
2480 char const *fsSource =
2481 "#version 140\n"
2482 "#extension GL_ARB_separate_shader_objects: require\n"
2483 "#extension GL_ARB_shading_language_420pack: require\n"
2484 "\n"
2485 "layout(location=0) out vec4 color;\n"
2486 "void main(){\n"
2487 " color = vec4(1);\n"
2488 "}\n";
2489
2490 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2491 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2492
2493 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002494 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12002495 pipe.AddShader(&vs);
2496 pipe.AddShader(&fs);
2497
Chris Forbes5af3bf22015-05-25 11:13:08 +12002498 VkDescriptorSetObj descriptorSet(m_device);
2499 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002500 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002501
2502 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002503 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12002504
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002505 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002506
Cody Northrop1684adb2015-08-05 11:15:02 -06002507 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002508 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
2509 FAIL() << "Incorrect warning: " << msgString;
2510 }
2511}
Chris Forbes5af3bf22015-05-25 11:13:08 +12002512
Chris Forbes3c10b852015-05-25 11:13:13 +12002513TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
2514{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002515 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12002516 std::string msgString;
2517 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002518 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002519 ScopedUseGlsl useGlsl(false);
Chris Forbes3c10b852015-05-25 11:13:13 +12002520
2521 char const *vsSource =
2522 "#version 140\n"
2523 "#extension GL_ARB_separate_shader_objects: require\n"
2524 "#extension GL_ARB_shading_language_420pack: require\n"
2525 "\n"
2526 "void main(){\n"
2527 " gl_Position = vec4(1);\n"
2528 "}\n";
2529 char const *fsSource =
2530 "#version 140\n"
2531 "#extension GL_ARB_separate_shader_objects: require\n"
2532 "#extension GL_ARB_shading_language_420pack: require\n"
2533 "\n"
2534 "layout(location=0) in float x;\n"
2535 "layout(location=0) out vec4 color;\n"
2536 "void main(){\n"
2537 " color = vec4(x);\n"
2538 "}\n";
2539
2540 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2541 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2542
2543 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002544 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12002545 pipe.AddShader(&vs);
2546 pipe.AddShader(&fs);
2547
Chris Forbes3c10b852015-05-25 11:13:13 +12002548 VkDescriptorSetObj descriptorSet(m_device);
2549 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002550 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12002551
2552 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002553 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12002554
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002555 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12002556
Cody Northrop1684adb2015-08-05 11:15:02 -06002557 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes3c10b852015-05-25 11:13:13 +12002558 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
2559 FAIL() << "Incorrect error: " << msgString;
2560 }
2561}
2562
Chris Forbescc281692015-05-25 11:13:17 +12002563TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
2564{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002565 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12002566 std::string msgString;
2567 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002568 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002569 ScopedUseGlsl useGlsl(false);
Chris Forbescc281692015-05-25 11:13:17 +12002570
2571 char const *vsSource =
2572 "#version 140\n"
2573 "#extension GL_ARB_separate_shader_objects: require\n"
2574 "#extension GL_ARB_shading_language_420pack: require\n"
2575 "\n"
2576 "layout(location=0) out int x;\n"
2577 "void main(){\n"
2578 " x = 0;\n"
2579 " gl_Position = vec4(1);\n"
2580 "}\n";
2581 char const *fsSource =
2582 "#version 140\n"
2583 "#extension GL_ARB_separate_shader_objects: require\n"
2584 "#extension GL_ARB_shading_language_420pack: require\n"
2585 "\n"
2586 "layout(location=0) in float x;\n" /* VS writes int */
2587 "layout(location=0) out vec4 color;\n"
2588 "void main(){\n"
2589 " color = vec4(x);\n"
2590 "}\n";
2591
2592 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2593 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2594
2595 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002596 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12002597 pipe.AddShader(&vs);
2598 pipe.AddShader(&fs);
2599
Chris Forbescc281692015-05-25 11:13:17 +12002600 VkDescriptorSetObj descriptorSet(m_device);
2601 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002602 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12002603
2604 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002605 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12002606
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002607 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12002608
Cody Northrop1684adb2015-08-05 11:15:02 -06002609 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbescc281692015-05-25 11:13:17 +12002610 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
2611 FAIL() << "Incorrect error: " << msgString;
2612 }
2613}
2614
Chris Forbes8291c052015-05-25 11:13:28 +12002615TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
2616{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002617 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12002618 std::string msgString;
2619 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002620 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002621 ScopedUseGlsl useGlsl(false);
Chris Forbes8291c052015-05-25 11:13:28 +12002622
2623 VkVertexInputBindingDescription input_binding;
2624 memset(&input_binding, 0, sizeof(input_binding));
2625
2626 VkVertexInputAttributeDescription input_attrib;
2627 memset(&input_attrib, 0, sizeof(input_attrib));
2628 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2629
2630 char const *vsSource =
2631 "#version 140\n"
2632 "#extension GL_ARB_separate_shader_objects: require\n"
2633 "#extension GL_ARB_shading_language_420pack: require\n"
2634 "\n"
2635 "void main(){\n"
2636 " gl_Position = vec4(1);\n"
2637 "}\n";
2638 char const *fsSource =
2639 "#version 140\n"
2640 "#extension GL_ARB_separate_shader_objects: require\n"
2641 "#extension GL_ARB_shading_language_420pack: require\n"
2642 "\n"
2643 "layout(location=0) out vec4 color;\n"
2644 "void main(){\n"
2645 " color = vec4(1);\n"
2646 "}\n";
2647
2648 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2649 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2650
2651 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002652 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12002653 pipe.AddShader(&vs);
2654 pipe.AddShader(&fs);
2655
2656 pipe.AddVertexInputBindings(&input_binding, 1);
2657 pipe.AddVertexInputAttribs(&input_attrib, 1);
2658
Chris Forbes8291c052015-05-25 11:13:28 +12002659 VkDescriptorSetObj descriptorSet(m_device);
2660 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002661 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12002662
2663 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002664 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12002665
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002666 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12002667
Cody Northrop1684adb2015-08-05 11:15:02 -06002668 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12002669 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
2670 FAIL() << "Incorrect warning: " << msgString;
2671 }
2672}
2673
Chris Forbes37367e62015-05-25 11:13:29 +12002674TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
2675{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002676 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12002677 std::string msgString;
2678 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002679 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002680 ScopedUseGlsl useGlsl(false);
Chris Forbes37367e62015-05-25 11:13:29 +12002681
2682 char const *vsSource =
2683 "#version 140\n"
2684 "#extension GL_ARB_separate_shader_objects: require\n"
2685 "#extension GL_ARB_shading_language_420pack: require\n"
2686 "\n"
2687 "layout(location=0) in vec4 x;\n" /* not provided */
2688 "void main(){\n"
2689 " gl_Position = x;\n"
2690 "}\n";
2691 char const *fsSource =
2692 "#version 140\n"
2693 "#extension GL_ARB_separate_shader_objects: require\n"
2694 "#extension GL_ARB_shading_language_420pack: require\n"
2695 "\n"
2696 "layout(location=0) out vec4 color;\n"
2697 "void main(){\n"
2698 " color = vec4(1);\n"
2699 "}\n";
2700
2701 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2702 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2703
2704 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002705 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12002706 pipe.AddShader(&vs);
2707 pipe.AddShader(&fs);
2708
Chris Forbes37367e62015-05-25 11:13:29 +12002709 VkDescriptorSetObj descriptorSet(m_device);
2710 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002711 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12002712
2713 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002714 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12002715
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002716 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12002717
Cody Northrop1684adb2015-08-05 11:15:02 -06002718 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes37367e62015-05-25 11:13:29 +12002719 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
2720 FAIL() << "Incorrect warning: " << msgString;
2721 }
2722}
2723
Chris Forbesa4b02322015-05-25 11:13:31 +12002724TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
2725{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002726 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12002727 std::string msgString;
2728 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002729 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002730 ScopedUseGlsl useGlsl(false);
Chris Forbesa4b02322015-05-25 11:13:31 +12002731
2732 VkVertexInputBindingDescription input_binding;
2733 memset(&input_binding, 0, sizeof(input_binding));
2734
2735 VkVertexInputAttributeDescription input_attrib;
2736 memset(&input_attrib, 0, sizeof(input_attrib));
2737 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2738
2739 char const *vsSource =
2740 "#version 140\n"
2741 "#extension GL_ARB_separate_shader_objects: require\n"
2742 "#extension GL_ARB_shading_language_420pack: require\n"
2743 "\n"
2744 "layout(location=0) in int x;\n" /* attrib provided float */
2745 "void main(){\n"
2746 " gl_Position = vec4(x);\n"
2747 "}\n";
2748 char const *fsSource =
2749 "#version 140\n"
2750 "#extension GL_ARB_separate_shader_objects: require\n"
2751 "#extension GL_ARB_shading_language_420pack: require\n"
2752 "\n"
2753 "layout(location=0) out vec4 color;\n"
2754 "void main(){\n"
2755 " color = vec4(1);\n"
2756 "}\n";
2757
2758 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2759 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2760
2761 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002762 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12002763 pipe.AddShader(&vs);
2764 pipe.AddShader(&fs);
2765
2766 pipe.AddVertexInputBindings(&input_binding, 1);
2767 pipe.AddVertexInputAttribs(&input_attrib, 1);
2768
Chris Forbesa4b02322015-05-25 11:13:31 +12002769 VkDescriptorSetObj descriptorSet(m_device);
2770 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002771 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12002772
2773 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002774 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12002775
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002776 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12002777
Cody Northrop1684adb2015-08-05 11:15:02 -06002778 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa4b02322015-05-25 11:13:31 +12002779 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
2780 FAIL() << "Incorrect error: " << msgString;
2781 }
2782}
2783
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002784TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
2785{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002786 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002787 std::string msgString;
2788 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002789 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002790 ScopedUseGlsl useGlsl(false);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002791
2792 /* Two binding descriptions for binding 0 */
2793 VkVertexInputBindingDescription input_bindings[2];
2794 memset(input_bindings, 0, sizeof(input_bindings));
2795
2796 VkVertexInputAttributeDescription input_attrib;
2797 memset(&input_attrib, 0, sizeof(input_attrib));
2798 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2799
2800 char const *vsSource =
2801 "#version 140\n"
2802 "#extension GL_ARB_separate_shader_objects: require\n"
2803 "#extension GL_ARB_shading_language_420pack: require\n"
2804 "\n"
2805 "layout(location=0) in float x;\n" /* attrib provided float */
2806 "void main(){\n"
2807 " gl_Position = vec4(x);\n"
2808 "}\n";
2809 char const *fsSource =
2810 "#version 140\n"
2811 "#extension GL_ARB_separate_shader_objects: require\n"
2812 "#extension GL_ARB_shading_language_420pack: require\n"
2813 "\n"
2814 "layout(location=0) out vec4 color;\n"
2815 "void main(){\n"
2816 " color = vec4(1);\n"
2817 "}\n";
2818
2819 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2820 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2821
2822 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002823 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002824 pipe.AddShader(&vs);
2825 pipe.AddShader(&fs);
2826
2827 pipe.AddVertexInputBindings(input_bindings, 2);
2828 pipe.AddVertexInputAttribs(&input_attrib, 1);
2829
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002830 VkDescriptorSetObj descriptorSet(m_device);
2831 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002832 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002833
2834 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002835 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002836
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002837 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002838
Cody Northrop1684adb2015-08-05 11:15:02 -06002839 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002840 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
2841 FAIL() << "Incorrect error: " << msgString;
2842 }
2843}
Chris Forbes4c948702015-05-25 11:13:32 +12002844
Chris Forbesc12ef122015-05-25 11:13:40 +12002845/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
2846 * rejects it. */
2847
2848TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
2849{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002850 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12002851 std::string msgString;
2852 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002853 ScopedUseGlsl useGlsl(false);
Chris Forbesc12ef122015-05-25 11:13:40 +12002854
2855 char const *vsSource =
2856 "#version 140\n"
2857 "#extension GL_ARB_separate_shader_objects: require\n"
2858 "#extension GL_ARB_shading_language_420pack: require\n"
2859 "\n"
2860 "void main(){\n"
2861 " gl_Position = vec4(1);\n"
2862 "}\n";
2863 char const *fsSource =
2864 "#version 140\n"
2865 "#extension GL_ARB_separate_shader_objects: require\n"
2866 "#extension GL_ARB_shading_language_420pack: require\n"
2867 "\n"
2868 "void main(){\n"
2869 "}\n";
2870
2871 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2872 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2873
2874 VkPipelineObj pipe(m_device);
2875 pipe.AddShader(&vs);
2876 pipe.AddShader(&fs);
2877
Chia-I Wuc278df82015-07-07 11:50:03 +08002878 /* set up CB 0, not written */
2879 pipe.AddColorAttachment();
2880 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12002881
Chris Forbesc12ef122015-05-25 11:13:40 +12002882 VkDescriptorSetObj descriptorSet(m_device);
2883 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002884 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12002885
2886 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002887 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12002888
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002889 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12002890
Cody Northrop1684adb2015-08-05 11:15:02 -06002891 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc12ef122015-05-25 11:13:40 +12002892 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
2893 FAIL() << "Incorrect error: " << msgString;
2894 }
2895}
2896
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002897TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
2898{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002899 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002900 std::string msgString;
2901 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002902 ScopedUseGlsl useGlsl(false);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002903
2904 char const *vsSource =
2905 "#version 140\n"
2906 "#extension GL_ARB_separate_shader_objects: require\n"
2907 "#extension GL_ARB_shading_language_420pack: require\n"
2908 "\n"
2909 "void main(){\n"
2910 " gl_Position = vec4(1);\n"
2911 "}\n";
2912 char const *fsSource =
2913 "#version 140\n"
2914 "#extension GL_ARB_separate_shader_objects: require\n"
2915 "#extension GL_ARB_shading_language_420pack: require\n"
2916 "\n"
2917 "layout(location=0) out vec4 x;\n"
2918 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
2919 "void main(){\n"
2920 " x = vec4(1);\n"
2921 " y = vec4(1);\n"
2922 "}\n";
2923
2924 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2925 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2926
2927 VkPipelineObj pipe(m_device);
2928 pipe.AddShader(&vs);
2929 pipe.AddShader(&fs);
2930
Chia-I Wuc278df82015-07-07 11:50:03 +08002931 /* set up CB 0, not written */
2932 pipe.AddColorAttachment();
2933 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002934 /* FS writes CB 1, but we don't configure it */
2935
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002936 VkDescriptorSetObj descriptorSet(m_device);
2937 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002938 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002939
2940 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002941 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002942
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002943 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002944
Cody Northrop1684adb2015-08-05 11:15:02 -06002945 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002946 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
2947 FAIL() << "Incorrect warning: " << msgString;
2948 }
2949}
2950
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002951TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
2952{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002953 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002954 std::string msgString;
2955 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002956 ScopedUseGlsl useGlsl(false);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002957
2958 char const *vsSource =
2959 "#version 140\n"
2960 "#extension GL_ARB_separate_shader_objects: require\n"
2961 "#extension GL_ARB_shading_language_420pack: require\n"
2962 "\n"
2963 "void main(){\n"
2964 " gl_Position = vec4(1);\n"
2965 "}\n";
2966 char const *fsSource =
2967 "#version 140\n"
2968 "#extension GL_ARB_separate_shader_objects: require\n"
2969 "#extension GL_ARB_shading_language_420pack: require\n"
2970 "\n"
2971 "layout(location=0) out ivec4 x;\n" /* not UNORM */
2972 "void main(){\n"
2973 " x = ivec4(1);\n"
2974 "}\n";
2975
2976 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2977 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2978
2979 VkPipelineObj pipe(m_device);
2980 pipe.AddShader(&vs);
2981 pipe.AddShader(&fs);
2982
Chia-I Wuc278df82015-07-07 11:50:03 +08002983 /* set up CB 0; type is UNORM by default */
2984 pipe.AddColorAttachment();
2985 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002986
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002987 VkDescriptorSetObj descriptorSet(m_device);
2988 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002989 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002990
2991 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002992 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002993
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002994 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002995
Cody Northrop1684adb2015-08-05 11:15:02 -06002996 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002997 if (!strstr(msgString.c_str(),"does not match FS output type")) {
2998 FAIL() << "Incorrect error: " << msgString;
2999 }
3000}
Chris Forbesc2050732015-06-05 14:43:36 +12003001
3002TEST_F(VkLayerTest, CreatePipelineNonSpirvShader)
3003{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003004 VkFlags msgFlags;
Chris Forbesc2050732015-06-05 14:43:36 +12003005 std::string msgString;
3006 ASSERT_NO_FATAL_FAILURE(InitState());
3007 /* Intentionally provided GLSL rather than compiling to SPIRV first */
Cody Northrop1cfbd172015-06-03 16:49:20 -06003008 ScopedUseGlsl useGlsl(true);
Chris Forbesc2050732015-06-05 14:43:36 +12003009
3010 char const *vsSource =
3011 "#version 140\n"
3012 "#extension GL_ARB_separate_shader_objects: require\n"
3013 "#extension GL_ARB_shading_language_420pack: require\n"
3014 "\n"
3015 "void main(){\n"
3016 " gl_Position = vec4(1);\n"
3017 "}\n";
3018 char const *fsSource =
3019 "#version 140\n"
3020 "#extension GL_ARB_separate_shader_objects: require\n"
3021 "#extension GL_ARB_shading_language_420pack: require\n"
3022 "\n"
3023 "layout(location=0) out vec4 x;\n"
3024 "void main(){\n"
3025 " x = vec4(1);\n"
3026 "}\n";
3027
3028 m_errorMonitor->ClearState();
3029
3030 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3031 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3032
3033
3034 VkPipelineObj pipe(m_device);
3035 pipe.AddShader(&vs);
3036 pipe.AddShader(&fs);
3037
Chia-I Wuc278df82015-07-07 11:50:03 +08003038 /* set up CB 0; type is UNORM by default */
3039 pipe.AddColorAttachment();
3040 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc2050732015-06-05 14:43:36 +12003041
Chris Forbesc2050732015-06-05 14:43:36 +12003042 VkDescriptorSetObj descriptorSet(m_device);
3043 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003044 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc2050732015-06-05 14:43:36 +12003045
Tony Barboured132432015-08-04 16:23:11 -06003046 VkResult res = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc2050732015-06-05 14:43:36 +12003047 /* pipeline creation should have succeeded */
3048 ASSERT_EQ(VK_SUCCESS, res);
3049
3050 /* should have emitted a warning: the shader is not SPIRV, so we're
3051 * not going to be able to analyze it */
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003052 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003053 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesc2050732015-06-05 14:43:36 +12003054 if (!strstr(msgString.c_str(),"is not SPIR-V")) {
3055 FAIL() << "Incorrect warning: " << msgString;
3056 }
3057}
Chris Forbes76ce7882015-08-14 12:04:59 +12003058
3059TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
3060{
3061 VkFlags msgFlags;
3062 std::string msgString;
3063 ASSERT_NO_FATAL_FAILURE(InitState());
3064 ScopedUseGlsl useGlsl(false);
3065
3066 char const *vsSource =
3067 "#version 140\n"
3068 "#extension GL_ARB_separate_shader_objects: require\n"
3069 "#extension GL_ARB_shading_language_420pack: require\n"
3070 "\n"
3071 "void main(){\n"
3072 " gl_Position = vec4(1);\n"
3073 "}\n";
3074 char const *fsSource =
3075 "#version 140\n"
3076 "#extension GL_ARB_separate_shader_objects: require\n"
3077 "#extension GL_ARB_shading_language_420pack: require\n"
3078 "\n"
3079 "layout(location=0) out vec4 x;\n"
3080 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
3081 "void main(){\n"
3082 " x = vec4(bar.y);\n"
3083 "}\n";
3084
3085 m_errorMonitor->ClearState();
3086
3087 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3088 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3089
3090
3091 VkPipelineObj pipe(m_device);
3092 pipe.AddShader(&vs);
3093 pipe.AddShader(&fs);
3094
3095 /* set up CB 0; type is UNORM by default */
3096 pipe.AddColorAttachment();
3097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3098
3099 VkDescriptorSetObj descriptorSet(m_device);
3100 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
3101
3102 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3103
3104 /* should have generated an error -- pipeline layout does not
3105 * provide a uniform buffer in 0.0
3106 */
3107 msgFlags = m_errorMonitor->GetState(&msgString);
3108 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
3109 if (!strstr(msgString.c_str(),"not declared in pipeline layout")) {
3110 FAIL() << "Incorrect error: " << msgString;
3111 }
3112}
3113
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003114#endif // SHADER_CHECKER_TESTS
3115
3116#if DEVICE_LIMITS_TESTS
3117// TBD
3118#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003119
Tony Barbour30486ea2015-04-07 13:44:53 -06003120int main(int argc, char **argv) {
3121 int result;
3122
3123 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06003124 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06003125
3126 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
3127
3128 result = RUN_ALL_TESTS();
3129
Tony Barbour01999182015-04-09 12:58:51 -06003130 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06003131 return result;
3132}