blob: 3e23997ae4f5c8a239ba960c42ad7d1275ac208b [file] [log] [blame]
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001#include <vulkan.h>
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002#include "vk_debug_report_lunarg.h"
Tony Barbour300a6082015-04-07 13:44:53 -06003#include "gtest-1.7.0/include/gtest/gtest.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004#include "vkrenderframework.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -06005#include "vk_layer_config.h"
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006#include "../icd/common/icd-spv.h"
Tony Barbour300a6082015-04-07 13:44:53 -06007
Mark Lobodzinski3780e142015-05-14 15:08:13 -05008#define GLM_FORCE_RADIANS
9#include "glm/glm.hpp"
10#include <glm/gtc/matrix_transform.hpp>
11
Tobin Ehlis0788f522015-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 Forbes9f7ff632015-05-25 11:13:08 +120016#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060017#define DEVICE_LIMITS_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060018
Mark Lobodzinski3780e142015-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 Northrop271ba752015-08-26 10:01:32 -060032 BsoFailLineWidth = 0x00000001,
33 BsoFailDepthBias = 0x00000002,
Cody Northrop12365112015-08-17 11:10:49 -060034 BsoFailViewport = 0x00000004,
Cody Northrop271ba752015-08-26 10:01:32 -060035 BsoFailBlend = 0x00000008,
36 BsoFailDepthBounds = 0x00000010,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -060037 BsoFailStencilReadMask = 0x00000020,
38 BsoFailStencilWriteMask = 0x00000040,
39 BsoFailStencilReference = 0x00000080,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050040} BsoFailSelect;
41
42struct vktriangle_vs_uniform {
43 // Must start with MVP
44 float mvp[4][4];
45 float position[3][4];
46 float color[3][4];
47};
48
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050049static const char bindStateVertShaderText[] =
Mark Lobodzinski3780e142015-05-14 15:08:13 -050050 "#version 130\n"
51 "vec2 vertices[3];\n"
52 "void main() {\n"
53 " vertices[0] = vec2(-1.0, -1.0);\n"
54 " vertices[1] = vec2( 1.0, -1.0);\n"
55 " vertices[2] = vec2( 0.0, 1.0);\n"
56 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
57 "}\n";
58
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050059static const char bindStateFragShaderText[] =
Cody Northrop8a3bb132015-06-16 17:32:04 -060060 "#version 140\n"
61 "#extension GL_ARB_separate_shader_objects: require\n"
62 "#extension GL_ARB_shading_language_420pack: require\n"
63 "\n"
64 "layout(location = 0) out vec4 uFragColor;\n"
65 "void main(){\n"
66 " uFragColor = vec4(0,1,0,1);\n"
67 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050068
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -060069static VkBool32 myDbgFunc(
Tony Barbour67e99152015-07-10 14:10:27 -060070 VkFlags msgFlags,
71 VkDbgObjectType objType,
72 uint64_t srcObject,
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060073 size_t location,
74 int32_t msgCode,
75 const char* pLayerPrefix,
76 const char* pMsg,
77 void* pUserData);
Tony Barbour300a6082015-04-07 13:44:53 -060078
79class ErrorMonitor {
80public:
Tony Barbour15524c32015-04-29 17:34:29 -060081 ErrorMonitor()
Tony Barbour300a6082015-04-07 13:44:53 -060082 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060083 test_platform_thread_create_mutex(&m_mutex);
84 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060085 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mike Stroyanaccf7692015-05-12 16:00:45 -060086 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -060087 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -060088 }
89 void ClearState()
90 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060091 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060092 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -060093 m_msgString.clear();
Mike Stroyan4268d1f2015-07-13 14:45:35 -060094 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -060095 }
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060096 VkFlags GetState(std::string *msgString)
Tony Barbour300a6082015-04-07 13:44:53 -060097 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060098 test_platform_thread_lock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -060099 *msgString = m_msgString;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600100 test_platform_thread_unlock_mutex(&m_mutex);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600101 return m_msgFlags;
Tony Barbour300a6082015-04-07 13:44:53 -0600102 }
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600103 void SetState(VkFlags msgFlags, const char *msgString)
Tony Barbour300a6082015-04-07 13:44:53 -0600104 {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600105 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600106 if (m_bailout != NULL) {
107 *m_bailout = true;
108 }
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600109 m_msgFlags = msgFlags;
Tony Barbour0b4d9562015-04-09 10:48:04 -0600110 m_msgString.reserve(strlen(msgString));
111 m_msgString = msgString;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600112 test_platform_thread_unlock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600113 }
114 void SetBailout(bool *bailout)
115 {
116 m_bailout = bailout;
Tony Barbour300a6082015-04-07 13:44:53 -0600117 }
118
119private:
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600120 VkFlags m_msgFlags;
121 std::string m_msgString;
122 test_platform_thread_mutex m_mutex;
123 bool* m_bailout;
Tony Barbour300a6082015-04-07 13:44:53 -0600124};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500125
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600126static VkBool32 myDbgFunc(
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600127 VkFlags msgFlags,
Tony Barbour67e99152015-07-10 14:10:27 -0600128 VkDbgObjectType objType,
129 uint64_t srcObject,
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600130 size_t location,
131 int32_t msgCode,
132 const char* pLayerPrefix,
133 const char* pMsg,
134 void* pUserData)
Tony Barbour300a6082015-04-07 13:44:53 -0600135{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600136 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600137 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600138 errMonitor->SetState(msgFlags, pMsg);
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600139 return true;
Tony Barbour0b4d9562015-04-09 10:48:04 -0600140 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600141
142 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600143}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500144
Tony Barbour6918cd52015-04-09 12:58:51 -0600145class VkLayerTest : public VkRenderFramework
Tony Barbour300a6082015-04-07 13:44:53 -0600146{
147public:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600148 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
149 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500150 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
151 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600152 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
153 { GenericDrawPreparation(m_cmdBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour300a6082015-04-07 13:44:53 -0600154
Tony Barbourfe3351b2015-07-28 10:17:20 -0600155 /* Convenience functions that use built-in command buffer */
156 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_cmdBuffer); }
157 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_cmdBuffer); }
158 void Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
159 { m_cmdBuffer->Draw(firstVertex, vertexCount, firstInstance, instanceCount); }
160 void DrawIndexed(uint32_t firstVertex, uint32_t vertexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
161 { m_cmdBuffer->DrawIndexed(firstVertex, vertexCount, vertexOffset,firstInstance, instanceCount); }
162 void QueueCommandBuffer() { m_cmdBuffer->QueueCommandBuffer(); }
163 void QueueCommandBuffer(const VkFence& fence) { m_cmdBuffer->QueueCommandBuffer(fence); }
164 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
165 { m_cmdBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
166 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
167 { m_cmdBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour300a6082015-04-07 13:44:53 -0600168protected:
Tony Barbour6918cd52015-04-09 12:58:51 -0600169 ErrorMonitor *m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600170
171 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600172 std::vector<const char *> instance_layer_names;
173 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600174 std::vector<const char *> instance_extension_names;
175 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600176
Courtney Goeltzenleuchter05159a92015-07-30 11:32:46 -0600177 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600178 /*
179 * Since CreateDbgMsgCallback is an instance level extension call
180 * any extension / layer that utilizes that feature also needs
181 * to be enabled at create instance time.
182 */
Mike Stroyan0daf78a2015-06-17 16:32:06 -0600183 // Use Threading layer first to protect others from ThreadCmdBufferCollision test
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600184 instance_layer_names.push_back("Threading");
185 instance_layer_names.push_back("ObjectTracker");
186 instance_layer_names.push_back("MemTracker");
187 instance_layer_names.push_back("DrawState");
188 instance_layer_names.push_back("ShaderChecker");
Mark Lobodzinski209b5292015-09-17 09:44:05 -0600189 instance_layer_names.push_back("DeviceLimits");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600190
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600191 device_layer_names.push_back("Threading");
192 device_layer_names.push_back("ObjectTracker");
193 device_layer_names.push_back("MemTracker");
194 device_layer_names.push_back("DrawState");
195 device_layer_names.push_back("ShaderChecker");
Mark Lobodzinski209b5292015-09-17 09:44:05 -0600196 device_layer_names.push_back("DeviceLimits");
Tony Barbour300a6082015-04-07 13:44:53 -0600197
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600198 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600199 this->app_info.pNext = NULL;
200 this->app_info.pAppName = "layer_tests";
201 this->app_info.appVersion = 1;
202 this->app_info.pEngineName = "unittest";
203 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600204 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour300a6082015-04-07 13:44:53 -0600205
Tony Barbour15524c32015-04-29 17:34:29 -0600206 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600207 InitFramework(instance_layer_names, device_layer_names,
208 instance_extension_names, device_extension_names,
209 myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600210 }
211
212 virtual void TearDown() {
213 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600214 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600215 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600216 }
217};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500218
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600219VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour300a6082015-04-07 13:44:53 -0600220{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600221 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600222
223 result = cmdBuffer.BeginCommandBuffer();
224
225 /*
226 * For render test all drawing happens in a single render pass
227 * on a single command buffer.
228 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200229 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu08accc62015-07-07 11:50:03 +0800230 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600231 }
232
233 return result;
234}
235
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600236VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour300a6082015-04-07 13:44:53 -0600237{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600238 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600239
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200240 if (renderPass()) {
Chia-I Wu0b50a1c2015-06-26 15:34:39 +0800241 cmdBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200242 }
Tony Barbour300a6082015-04-07 13:44:53 -0600243
244 result = cmdBuffer.EndCommandBuffer();
245
246 return result;
247}
248
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500249void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
250{
251 // Create identity matrix
252 int i;
253 struct vktriangle_vs_uniform data;
254
255 glm::mat4 Projection = glm::mat4(1.0f);
256 glm::mat4 View = glm::mat4(1.0f);
257 glm::mat4 Model = glm::mat4(1.0f);
258 glm::mat4 MVP = Projection * View * Model;
259 const int matrixSize = sizeof(MVP);
260 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
261
262 memcpy(&data.mvp, &MVP[0][0], matrixSize);
263
264 static const Vertex tri_data[] =
265 {
266 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
267 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
268 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
269 };
270
271 for (i=0; i<3; i++) {
272 data.position[i][0] = tri_data[i].posX;
273 data.position[i][1] = tri_data[i].posY;
274 data.position[i][2] = tri_data[i].posZ;
275 data.position[i][3] = tri_data[i].posW;
276 data.color[i][0] = tri_data[i].r;
277 data.color[i][1] = tri_data[i].g;
278 data.color[i][2] = tri_data[i].b;
279 data.color[i][3] = tri_data[i].a;
280 }
281
282 ASSERT_NO_FATAL_FAILURE(InitState());
283 ASSERT_NO_FATAL_FAILURE(InitViewport());
284
285 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
286
287 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
288 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
289
290 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800291 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500292 pipelineobj.AddShader(&vs);
293 pipelineobj.AddShader(&ps);
294
295 VkDescriptorSetObj descriptorSet(m_device);
296 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
297
298 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600299 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500300
Tony Barbourfe3351b2015-07-28 10:17:20 -0600301 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500302
303 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -0600304 Draw(0, 3, 0, 1);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500305
306 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600307 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500308
Tony Barbourfe3351b2015-07-28 10:17:20 -0600309 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500310}
311
312void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
313{
314 if (m_depthStencil->Initialized()) {
315 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
316 } else {
317 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
318 }
319
320 cmdBuffer->PrepareAttachments();
Cody Northrop271ba752015-08-26 10:01:32 -0600321 if ((failMask & BsoFailLineWidth) != BsoFailLineWidth) {
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600322 cmdBuffer->SetLineWidth(m_lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -0600323 }
Cody Northrop271ba752015-08-26 10:01:32 -0600324 if ((failMask & BsoFailDepthBias) != BsoFailDepthBias) {
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600325 cmdBuffer->SetDepthBias(m_depthBias, m_depthBiasClamp, m_slopeScaledDepthBias);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500326 }
327 if ((failMask & BsoFailViewport) != BsoFailViewport) {
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600328 /* TODO: Need separate test for missing scissor */
329 /* TODO: Need test for mismatched viewport and scissor count */
330 cmdBuffer->SetViewport(m_viewports.size(), m_viewports.data());
331 cmdBuffer->SetScissor(m_scissors.size(), m_scissors.data());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500332 }
Cody Northrop271ba752015-08-26 10:01:32 -0600333 if ((failMask & BsoFailBlend) != BsoFailBlend) {
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600334 cmdBuffer->SetBlendConstants(m_blendConst);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500335 }
Cody Northrop271ba752015-08-26 10:01:32 -0600336 if ((failMask & BsoFailDepthBounds) != BsoFailDepthBounds) {
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600337 cmdBuffer->SetDepthBounds(m_minDepthBounds, m_maxDepthBounds);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500338 }
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600339 if ((failMask & BsoFailStencilReadMask) != BsoFailStencilReadMask) {
340 cmdBuffer->SetStencilReadMask(VK_STENCIL_FACE_FRONT_BIT | VK_STENCIL_FACE_BACK_BIT, m_stencilCompareMask);
341 }
342 if ((failMask & BsoFailStencilWriteMask) != BsoFailStencilWriteMask) {
343 cmdBuffer->SetStencilWriteMask(VK_STENCIL_FACE_FRONT_BIT | VK_STENCIL_FACE_BACK_BIT, m_stencilWriteMask);
344 }
345 if ((failMask & BsoFailStencilReference) != BsoFailStencilReference) {
346 cmdBuffer->SetStencilReference(VK_STENCIL_FACE_FRONT_BIT | VK_STENCIL_FACE_BACK_BIT, m_stencilReference);
Cody Northrop82485a82015-08-18 15:21:16 -0600347 }
348 // Make sure depthWriteEnable is set so that Depth fail test will work correctly
349 // Make sure stencilTestEnable is set so that Stencil fail test will work correctly
Tony Barboureb254902015-07-15 12:50:33 -0600350 VkStencilOpState stencil = {};
351 stencil.stencilFailOp = VK_STENCIL_OP_KEEP;
352 stencil.stencilPassOp = VK_STENCIL_OP_KEEP;
353 stencil.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
354 stencil.stencilCompareOp = VK_COMPARE_OP_NEVER;
355
356 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
357 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
358 ds_ci.pNext = NULL;
359 ds_ci.depthTestEnable = VK_FALSE;
360 ds_ci.depthWriteEnable = VK_TRUE;
361 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
Cody Northrop271ba752015-08-26 10:01:32 -0600362 ds_ci.depthBoundsTestEnable = VK_FALSE;
Cody Northrop82485a82015-08-18 15:21:16 -0600363 ds_ci.stencilTestEnable = VK_TRUE;
Tony Barboureb254902015-07-15 12:50:33 -0600364 ds_ci.front = stencil;
365 ds_ci.back = stencil;
366
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600367 pipelineobj.SetDepthStencil(&ds_ci);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500368 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Cody Northrop29a08f22015-08-27 10:20:35 -0600369 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
370 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500371 cmdBuffer->BindPipeline(pipelineobj);
372 cmdBuffer->BindDescriptorSet(descriptorSet);
373}
374
375// ********************************************************************************************************************
376// ********************************************************************************************************************
377// ********************************************************************************************************************
378// ********************************************************************************************************************
Tobin Ehlis0788f522015-05-26 16:11:58 -0600379#if MEM_TRACKER_TESTS
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500380TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
381{
382 vk_testing::Fence testFence;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600383 VkFlags msgFlags;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500384 std::string msgString;
385
386 VkFenceCreateInfo fenceInfo = {};
387 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
388 fenceInfo.pNext = NULL;
389 fenceInfo.flags = 0;
390
391 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -0600392
393 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
394 vk_testing::Buffer buffer;
395 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500396
Tony Barbourfe3351b2015-07-28 10:17:20 -0600397 BeginCommandBuffer();
398 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
399 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500400
401 testFence.init(*m_device, fenceInfo);
402
403 // Bypass framework since it does the waits automatically
404 VkResult err = VK_SUCCESS;
Tony Barbourfe3351b2015-07-28 10:17:20 -0600405 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500406 ASSERT_VK_SUCCESS( err );
407
408 m_errorMonitor->ClearState();
409 // Introduce failure by calling begin again before checking fence
Tony Barbourfe3351b2015-07-28 10:17:20 -0600410 vkResetCommandBuffer(m_cmdBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500411
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600412 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600413 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling ResetCommandBuffer on an active Command Buffer";
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500414 if (!strstr(msgString.c_str(),"Resetting CB")) {
415 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
416 }
417}
418
419TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion)
420{
421 vk_testing::Fence testFence;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600422 VkFlags msgFlags;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500423 std::string msgString;
424
425 VkFenceCreateInfo fenceInfo = {};
426 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
427 fenceInfo.pNext = NULL;
428 fenceInfo.flags = 0;
429
430 ASSERT_NO_FATAL_FAILURE(InitState());
431 ASSERT_NO_FATAL_FAILURE(InitViewport());
432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
433
Tony Barbourfe3351b2015-07-28 10:17:20 -0600434 BeginCommandBuffer();
435 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
436 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500437
438 testFence.init(*m_device, fenceInfo);
439
440 // Bypass framework since it does the waits automatically
441 VkResult err = VK_SUCCESS;
Tony Barbourfe3351b2015-07-28 10:17:20 -0600442 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500443 ASSERT_VK_SUCCESS( err );
444
445 m_errorMonitor->ClearState();
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600446
447 VkCmdBufferBeginInfo info = {};
448 info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT | VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
449 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
450 info.renderPass = VK_NULL_HANDLE;
451 info.subpass = 0;
452 info.framebuffer = VK_NULL_HANDLE;
453
454 // Introduce failure by calling BCB again before checking fence
455 vkBeginCommandBuffer(m_cmdBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500456
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600457 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600458 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling BeginCommandBuffer on an active Command Buffer";
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500459 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
460 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
461 }
462}
463
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500464TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
465{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600466 VkFlags msgFlags;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500467 std::string msgString;
468 VkResult err;
469
470 ASSERT_NO_FATAL_FAILURE(InitState());
471 m_errorMonitor->ClearState();
472
473 // Create an image, allocate memory, free it, and then try to bind it
474 VkImage image;
Mark Lobodzinski23065352015-05-29 09:32:35 -0500475 VkDeviceMemory mem;
476 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500477
478 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
479 const int32_t tex_width = 32;
480 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500481
Tony Barboureb254902015-07-15 12:50:33 -0600482 VkImageCreateInfo image_create_info = {};
483 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
484 image_create_info.pNext = NULL;
485 image_create_info.imageType = VK_IMAGE_TYPE_2D;
486 image_create_info.format = tex_format;
487 image_create_info.extent.width = tex_width;
488 image_create_info.extent.height = tex_height;
489 image_create_info.extent.depth = 1;
490 image_create_info.mipLevels = 1;
491 image_create_info.arraySize = 1;
492 image_create_info.samples = 1;
493 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
494 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
495 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600496
Tony Barboureb254902015-07-15 12:50:33 -0600497 VkMemoryAllocInfo mem_alloc = {};
498 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
499 mem_alloc.pNext = NULL;
500 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500501 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -0600502 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
504 err = vkCreateImage(m_device->device(), &image_create_info, &image);
505 ASSERT_VK_SUCCESS(err);
506
Tony Barbour67e99152015-07-10 14:10:27 -0600507 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500508 image,
Mark Lobodzinski23065352015-05-29 09:32:35 -0500509 &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500510 ASSERT_VK_SUCCESS(err);
511
Mark Lobodzinski23065352015-05-29 09:32:35 -0500512 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500513
Mike Stroyan713b2d72015-08-04 10:49:29 -0600514 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tony Barbour02fdc7d2015-08-04 16:13:01 -0600515 if(err != VK_SUCCESS) // If we can't find any unmappable memory this test doesn't make sense
516 return;
Mike Stroyan713b2d72015-08-04 10:49:29 -0600517
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500518 // allocate memory
Mark Lobodzinski23065352015-05-29 09:32:35 -0500519 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500520 ASSERT_VK_SUCCESS(err);
521
522 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -0600523 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500524 ASSERT_VK_SUCCESS(err);
525
526 // Map memory as if to initialize the image
527 void *mappedAddress = NULL;
Mark Lobodzinski23065352015-05-29 09:32:35 -0500528 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500529
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600530 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600531 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to map memory not visible to CPU";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500532 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
533 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
534 }
535}
536
Tobin Ehlis2717d132015-07-10 18:25:07 -0600537// TODO : Is this test still valid. Not sure it is with updates to memory binding model
538// Verify and delete the test of fix the check
539//TEST_F(VkLayerTest, FreeBoundMemory)
540//{
541// VkFlags msgFlags;
542// std::string msgString;
543// VkResult err;
544//
545// ASSERT_NO_FATAL_FAILURE(InitState());
546// m_errorMonitor->ClearState();
547//
548// // Create an image, allocate memory, free it, and then try to bind it
549// VkImage image;
550// VkDeviceMemory mem;
551// VkMemoryRequirements mem_reqs;
552//
553// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
554// const int32_t tex_width = 32;
555// const int32_t tex_height = 32;
556//
557// const VkImageCreateInfo image_create_info = {
558// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
559// .pNext = NULL,
560// .imageType = VK_IMAGE_TYPE_2D,
561// .format = tex_format,
562// .extent = { tex_width, tex_height, 1 },
563// .mipLevels = 1,
564// .arraySize = 1,
565// .samples = 1,
566// .tiling = VK_IMAGE_TILING_LINEAR,
567// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
568// .flags = 0,
569// };
570// VkMemoryAllocInfo mem_alloc = {
571// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
572// .pNext = NULL,
573// .allocationSize = 0,
574// .memoryTypeIndex = 0,
575// };
576//
577// err = vkCreateImage(m_device->device(), &image_create_info, &image);
578// ASSERT_VK_SUCCESS(err);
579//
580// err = vkGetImageMemoryRequirements(m_device->device(),
581// image,
582// &mem_reqs);
583// ASSERT_VK_SUCCESS(err);
584//
585// mem_alloc.allocationSize = mem_reqs.size;
586//
587// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
588// ASSERT_VK_SUCCESS(err);
589//
590// // allocate memory
591// err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
592// ASSERT_VK_SUCCESS(err);
593//
594// // Bind memory to Image object
595// err = vkBindImageMemory(m_device->device(), image, mem, 0);
596// ASSERT_VK_SUCCESS(err);
597//
598// // Introduce validation failure, free memory while still bound to object
599// vkFreeMemory(m_device->device(), mem);
Tobin Ehlis2717d132015-07-10 18:25:07 -0600600// msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600601//
Cody Northropd2ad0342015-08-05 11:15:02 -0600602// ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an warning while tring to free bound memory";
Tobin Ehlis2717d132015-07-10 18:25:07 -0600603// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
604// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
605// }
606//}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500607
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500608TEST_F(VkLayerTest, RebindMemory)
609{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600610 VkFlags msgFlags;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500611 std::string msgString;
612 VkResult err;
613
614 ASSERT_NO_FATAL_FAILURE(InitState());
615 m_errorMonitor->ClearState();
616
617 // Create an image, allocate memory, free it, and then try to bind it
618 VkImage image;
619 VkDeviceMemory mem1;
620 VkDeviceMemory mem2;
621 VkMemoryRequirements mem_reqs;
622
623 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
624 const int32_t tex_width = 32;
625 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500626
Tony Barboureb254902015-07-15 12:50:33 -0600627 VkImageCreateInfo image_create_info = {};
628 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
629 image_create_info.pNext = NULL;
630 image_create_info.imageType = VK_IMAGE_TYPE_2D;
631 image_create_info.format = tex_format;
632 image_create_info.extent.width = tex_width;
633 image_create_info.extent.height = tex_height;
634 image_create_info.extent.depth = 1;
635 image_create_info.mipLevels = 1;
636 image_create_info.arraySize = 1;
637 image_create_info.samples = 1;
638 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
639 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
640 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500641
Tony Barboureb254902015-07-15 12:50:33 -0600642 VkMemoryAllocInfo mem_alloc = {};
643 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
644 mem_alloc.pNext = NULL;
645 mem_alloc.allocationSize = 0;
646 mem_alloc.memoryTypeIndex = 0;
647
648 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
649 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500650 err = vkCreateImage(m_device->device(), &image_create_info, &image);
651 ASSERT_VK_SUCCESS(err);
652
Tony Barbour67e99152015-07-10 14:10:27 -0600653 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500654 image,
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500655 &mem_reqs);
656 ASSERT_VK_SUCCESS(err);
657
658 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wu999f0482015-07-03 10:32:05 +0800659 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600660 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500661
662 // allocate 2 memory objects
663 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
664 ASSERT_VK_SUCCESS(err);
665 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
666 ASSERT_VK_SUCCESS(err);
667
668 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -0600669 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500670 ASSERT_VK_SUCCESS(err);
671
672 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barbour67e99152015-07-10 14:10:27 -0600673 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500674
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600675 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600676 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to rebind an object";
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500677 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
678 FAIL() << "Error received did not match expected message when rebinding memory to an object";
679 }
680}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500681
Tony Barbour0b4d9562015-04-09 10:48:04 -0600682TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour300a6082015-04-07 13:44:53 -0600683{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600684 vk_testing::Fence testFence;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600685 VkFlags msgFlags;
Tony Barbour300a6082015-04-07 13:44:53 -0600686 std::string msgString;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600687
688 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600689 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
690 fenceInfo.pNext = NULL;
691 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -0600692
Tony Barbour300a6082015-04-07 13:44:53 -0600693 ASSERT_NO_FATAL_FAILURE(InitState());
694 ASSERT_NO_FATAL_FAILURE(InitViewport());
695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
696
Tony Barbourfe3351b2015-07-28 10:17:20 -0600697 BeginCommandBuffer();
698 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
699 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600700
701 testFence.init(*m_device, fenceInfo);
702 m_errorMonitor->ClearState();
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600703
704 vkQueueSubmit(m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
705 vkQueueWaitIdle(m_device->m_queue );
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600706 msgFlags = m_errorMonitor->GetState(&msgString);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600707
Cody Northropd2ad0342015-08-05 11:15:02 -0600708 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err from using a fence in SIGNALED state in call to vkQueueSubmit";
Tony Barbour0b4d9562015-04-09 10:48:04 -0600709 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500710 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour0b4d9562015-04-09 10:48:04 -0600711 }
712
713}
714
715TEST_F(VkLayerTest, ResetUnsignaledFence)
716{
717 vk_testing::Fence testFence;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600718 VkFlags msgFlags;
Tony Barbour0b4d9562015-04-09 10:48:04 -0600719 std::string msgString;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600720 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600721 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
722 fenceInfo.pNext = NULL;
723
Tony Barbour0b4d9562015-04-09 10:48:04 -0600724 ASSERT_NO_FATAL_FAILURE(InitState());
725 testFence.init(*m_device, fenceInfo);
726 m_errorMonitor->ClearState();
Chia-I Wud9e8e822015-07-03 11:45:55 +0800727 VkFence fences[1] = {testFence.handle()};
Tony Barbour0b4d9562015-04-09 10:48:04 -0600728 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600729 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600730 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from submitting fence with UNSIGNALED state to vkResetFences";
Tony Barbour6918cd52015-04-09 12:58:51 -0600731 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500732 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour0b4d9562015-04-09 10:48:04 -0600733 }
Tony Barbour300a6082015-04-07 13:44:53 -0600734
735}
Tobin Ehlis41376e12015-07-03 08:45:14 -0600736
Chia-I Wu08accc62015-07-07 11:50:03 +0800737/* TODO: Update for changes due to bug-14075 tiling across render passes */
738#if 0
Tobin Ehlis41376e12015-07-03 08:45:14 -0600739TEST_F(VkLayerTest, InvalidUsageBits)
740{
741 // Initiate Draw w/o a PSO bound
742 VkFlags msgFlags;
743 std::string msgString;
744
745 ASSERT_NO_FATAL_FAILURE(InitState());
746 m_errorMonitor->ClearState();
747 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600748 BeginCommandBuffer();
Tobin Ehlis41376e12015-07-03 08:45:14 -0600749
750 const VkExtent3D e3d = {
751 .width = 128,
752 .height = 128,
753 .depth = 1,
754 };
755 const VkImageCreateInfo ici = {
756 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
757 .pNext = NULL,
758 .imageType = VK_IMAGE_TYPE_2D,
759 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
760 .extent = e3d,
761 .mipLevels = 1,
762 .arraySize = 1,
763 .samples = 1,
764 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchter660f0ca2015-09-10 14:14:11 -0600765 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlis41376e12015-07-03 08:45:14 -0600766 .flags = 0,
767 };
768
769 VkImage dsi;
770 vkCreateImage(m_device->device(), &ici, &dsi);
771 VkDepthStencilView dsv;
772 const VkDepthStencilViewCreateInfo dsvci = {
773 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
774 .pNext = NULL,
775 .image = dsi,
776 .mipLevel = 0,
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600777 .baseArrayLayer = 0,
Tobin Ehlis41376e12015-07-03 08:45:14 -0600778 .arraySize = 1,
779 .flags = 0,
780 };
781 vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv);
782 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600783 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after attempting to create DSView w/ image lacking USAGE_DS_BIT flag";
Tobin Ehlis41376e12015-07-03 08:45:14 -0600784 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
785 FAIL() << "Error received was not 'Invalid usage flag for image...'";
786 }
787}
Mark Lobodzinski209b5292015-09-17 09:44:05 -0600788#endif // 0
789#endif // MEM_TRACKER_TESTS
790
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600791#if OBJ_TRACKER_TESTS
Cody Northrop271ba752015-08-26 10:01:32 -0600792TEST_F(VkLayerTest, LineWidthStateNotBound)
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500793{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600794 VkFlags msgFlags;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500795 std::string msgString;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -0600796 ASSERT_NO_FATAL_FAILURE(InitState());
797 m_errorMonitor->ClearState();
Cody Northrop271ba752015-08-26 10:01:32 -0600798 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500799
Cody Northrop271ba752015-08-26 10:01:32 -0600800 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500801
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600802 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop271ba752015-08-26 10:01:32 -0600803 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Line Width State Object";
804 if (!strstr(msgString.c_str(),"Line width object not bound to this command buffer")) {
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600805 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Line Width object not bound to this command buffer'";
Cody Northrop12365112015-08-17 11:10:49 -0600806 }
807}
808
Cody Northrop271ba752015-08-26 10:01:32 -0600809TEST_F(VkLayerTest, DepthBiasStateNotBound)
Cody Northrop12365112015-08-17 11:10:49 -0600810{
811 VkFlags msgFlags;
812 std::string msgString;
813 ASSERT_NO_FATAL_FAILURE(InitState());
814 m_errorMonitor->ClearState();
Cody Northrop271ba752015-08-26 10:01:32 -0600815 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
Cody Northrop12365112015-08-17 11:10:49 -0600816
Cody Northrop271ba752015-08-26 10:01:32 -0600817 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Cody Northrop12365112015-08-17 11:10:49 -0600818
819 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop271ba752015-08-26 10:01:32 -0600820 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bias State Object";
821 if (!strstr(msgString.c_str(),"Depth bias object not bound to this command buffer")) {
822 FAIL() << "Error received was not 'Depth bias object not bound to this command buffer'";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500823 }
824}
825
826TEST_F(VkLayerTest, ViewportStateNotBound)
827{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600828 VkFlags msgFlags;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500829 std::string msgString;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -0600830 ASSERT_NO_FATAL_FAILURE(InitState());
831 m_errorMonitor->ClearState();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500832 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
833
834 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
835
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600836 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -0600837 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500838 if (!strstr(msgString.c_str(),"Viewport object not bound to this command buffer")) {
839 FAIL() << "Error received was not 'Viewport object not bound to this command buffer'";
840 }
841}
842
Cody Northrop271ba752015-08-26 10:01:32 -0600843TEST_F(VkLayerTest, BlendStateNotBound)
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500844{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600845 VkFlags msgFlags;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500846 std::string msgString;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -0600847 ASSERT_NO_FATAL_FAILURE(InitState());
848 m_errorMonitor->ClearState();
Cody Northrop271ba752015-08-26 10:01:32 -0600849 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500850
Cody Northrop271ba752015-08-26 10:01:32 -0600851 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500852
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600853 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop271ba752015-08-26 10:01:32 -0600854 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Blend State Object";
855 if (!strstr(msgString.c_str(),"Blend object not bound to this command buffer")) {
856 FAIL() << "Error received was not 'Blend object not bound to this command buffer'";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500857 }
858}
859
Cody Northrop271ba752015-08-26 10:01:32 -0600860TEST_F(VkLayerTest, DepthBoundsStateNotBound)
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500861{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600862 VkFlags msgFlags;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500863 std::string msgString;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -0600864 ASSERT_NO_FATAL_FAILURE(InitState());
865 m_errorMonitor->ClearState();
Cody Northrop271ba752015-08-26 10:01:32 -0600866 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500867
Cody Northrop271ba752015-08-26 10:01:32 -0600868 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500869
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600870 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop271ba752015-08-26 10:01:32 -0600871 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bounds State Object";
872 if (!strstr(msgString.c_str(),"Depth bounds object not bound to this command buffer")) {
873 FAIL() << "Error received was not 'Depth bounds object not bound to this command buffer'";
Cody Northrop82485a82015-08-18 15:21:16 -0600874 }
875}
876
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600877TEST_F(VkLayerTest, StencilReadMaskNotSet)
Cody Northrop82485a82015-08-18 15:21:16 -0600878{
879 VkFlags msgFlags;
880 std::string msgString;
881 ASSERT_NO_FATAL_FAILURE(InitState());
882 m_errorMonitor->ClearState();
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600883 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
Cody Northrop82485a82015-08-18 15:21:16 -0600884
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600885 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Cody Northrop82485a82015-08-18 15:21:16 -0600886
887 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600888 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Read Mask";
889 if (!strstr(msgString.c_str(),"Stencil read mask not set on this command buffer")) {
890 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Stencil read mask not set on this command buffer'";
891 }
892}
893
894TEST_F(VkLayerTest, StencilWriteMaskNotSet)
895{
896 VkFlags msgFlags;
897 std::string msgString;
898 ASSERT_NO_FATAL_FAILURE(InitState());
899 m_errorMonitor->ClearState();
900 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
901
902 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
903
904 msgFlags = m_errorMonitor->GetState(&msgString);
905 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Write Mask";
906 if (!strstr(msgString.c_str(),"Stencil write mask not set on this command buffer")) {
907 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Stencil write mask not set on this command buffer'";
908 }
909}
910
911TEST_F(VkLayerTest, StencilReferenceNotSet)
912{
913 VkFlags msgFlags;
914 std::string msgString;
915 ASSERT_NO_FATAL_FAILURE(InitState());
916 m_errorMonitor->ClearState();
917 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
918
919 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
920
921 msgFlags = m_errorMonitor->GetState(&msgString);
922 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Reference";
923 if (!strstr(msgString.c_str(),"Stencil reference not set on this command buffer")) {
924 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Stencil reference not set on this command buffer'";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500925 }
Tony Barbourd866ad02015-05-06 09:35:56 -0600926}
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600927
928TEST_F(VkLayerTest, PipelineNotBound)
929{
930 VkFlags msgFlags;
931 std::string msgString;
932 VkResult err;
933
934 ASSERT_NO_FATAL_FAILURE(InitState());
935 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
936 m_errorMonitor->ClearState();
937
938 VkDescriptorTypeCount ds_type_count = {};
939 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
940 ds_type_count.count = 1;
941
942 VkDescriptorPoolCreateInfo ds_pool_ci = {};
943 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
944 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -0600945 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
946 ds_pool_ci.maxSets = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600947 ds_pool_ci.count = 1;
948 ds_pool_ci.pTypeCount = &ds_type_count;
949
950 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -0600951 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -0600952 ASSERT_VK_SUCCESS(err);
953
954 VkDescriptorSetLayoutBinding dsl_binding = {};
955 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
956 dsl_binding.arraySize = 1;
957 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
958 dsl_binding.pImmutableSamplers = NULL;
959
960 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
961 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
962 ds_layout_ci.pNext = NULL;
963 ds_layout_ci.count = 1;
964 ds_layout_ci.pBinding = &dsl_binding;
965
966 VkDescriptorSetLayout ds_layout;
967 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
968 ASSERT_VK_SUCCESS(err);
969
970 VkDescriptorSet descriptorSet;
971 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
972 ASSERT_VK_SUCCESS(err);
973
974 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
975 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
976 pipeline_layout_ci.pNext = NULL;
977 pipeline_layout_ci.descriptorSetCount = 1;
978 pipeline_layout_ci.pSetLayouts = &ds_layout;
979
980 VkPipelineLayout pipeline_layout;
981 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
982 ASSERT_VK_SUCCESS(err);
983
984 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
985
986 BeginCommandBuffer();
987 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
988
989 msgFlags = m_errorMonitor->GetState(&msgString);
990 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Tobin Ehlisec598302015-09-15 15:02:17 -0600991 if (!strstr(msgString.c_str(),"Invalid VkPipeline Object ")) {
992 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be' but instead it was '" << msgString.c_str() << "'";
993 }
994}
995
996TEST_F(VkLayerTest, BindInvalidMemory)
997{
998 VkFlags msgFlags;
999 std::string msgString;
1000 VkResult err;
1001
1002 ASSERT_NO_FATAL_FAILURE(InitState());
1003 m_errorMonitor->ClearState();
1004
1005 // Create an image, allocate memory, free it, and then try to bind it
1006 VkImage image;
1007 VkDeviceMemory mem;
1008 VkMemoryRequirements mem_reqs;
1009
1010 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1011 const int32_t tex_width = 32;
1012 const int32_t tex_height = 32;
1013
1014 VkImageCreateInfo image_create_info = {};
1015 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1016 image_create_info.pNext = NULL;
1017 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1018 image_create_info.format = tex_format;
1019 image_create_info.extent.width = tex_width;
1020 image_create_info.extent.height = tex_height;
1021 image_create_info.extent.depth = 1;
1022 image_create_info.mipLevels = 1;
1023 image_create_info.arraySize = 1;
1024 image_create_info.samples = 1;
1025 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1026 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1027 image_create_info.flags = 0;
1028
1029 VkMemoryAllocInfo mem_alloc = {};
1030 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
1031 mem_alloc.pNext = NULL;
1032 mem_alloc.allocationSize = 0;
1033 mem_alloc.memoryTypeIndex = 0;
1034
1035 err = vkCreateImage(m_device->device(), &image_create_info, &image);
1036 ASSERT_VK_SUCCESS(err);
1037
1038 err = vkGetImageMemoryRequirements(m_device->device(),
1039 image,
1040 &mem_reqs);
1041 ASSERT_VK_SUCCESS(err);
1042
1043 mem_alloc.allocationSize = mem_reqs.size;
1044
1045 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1046 ASSERT_VK_SUCCESS(err);
1047
1048 // allocate memory
1049 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
1050 ASSERT_VK_SUCCESS(err);
1051
1052 // Introduce validation failure, free memory before binding
1053 vkFreeMemory(m_device->device(), mem);
1054 ASSERT_VK_SUCCESS(err);
1055
1056 // Try to bind free memory that has been freed
1057 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1058 // This may very well return an error.
1059 (void)err;
1060
1061 msgFlags = m_errorMonitor->GetState(&msgString);
1062 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to bind a freed memory object";
1063 if (!strstr(msgString.c_str(),"Invalid VkDeviceMemory Object ")) {
1064 FAIL() << "Error received from BindInvalidMemory was not 'Invalid VkDeviceMemory Object 0x<handle>' but instead '" << msgString.c_str() << "'";
1065 }
1066}
1067
1068TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
1069{
1070 VkFlags msgFlags;
1071 std::string msgString;
1072 VkResult err;
1073
1074 ASSERT_NO_FATAL_FAILURE(InitState());
1075 m_errorMonitor->ClearState();
1076
1077 // Create an image object, allocate memory, destroy the object and then try to bind it
1078 VkImage image;
1079 VkDeviceMemory mem;
1080 VkMemoryRequirements mem_reqs;
1081
1082 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1083 const int32_t tex_width = 32;
1084 const int32_t tex_height = 32;
1085
1086 VkImageCreateInfo image_create_info = {};
1087 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1088 image_create_info.pNext = NULL;
1089 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1090 image_create_info.format = tex_format;
1091 image_create_info.extent.width = tex_width;
1092 image_create_info.extent.height = tex_height;
1093 image_create_info.extent.depth = 1;
1094 image_create_info.mipLevels = 1;
1095 image_create_info.arraySize = 1;
1096 image_create_info.samples = 1;
1097 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1098 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1099 image_create_info.flags = 0;
1100
1101 VkMemoryAllocInfo mem_alloc = {};
1102 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
1103 mem_alloc.pNext = NULL;
1104 mem_alloc.allocationSize = 0;
1105 mem_alloc.memoryTypeIndex = 0;
1106
1107 err = vkCreateImage(m_device->device(), &image_create_info, &image);
1108 ASSERT_VK_SUCCESS(err);
1109
1110 err = vkGetImageMemoryRequirements(m_device->device(),
1111 image,
1112 &mem_reqs);
1113 ASSERT_VK_SUCCESS(err);
1114
1115 mem_alloc.allocationSize = mem_reqs.size;
1116 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1117 ASSERT_VK_SUCCESS(err);
1118
1119 // Allocate memory
1120 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
1121 ASSERT_VK_SUCCESS(err);
1122
1123 // Introduce validation failure, destroy Image object before binding
1124 vkDestroyImage(m_device->device(), image);
1125 ASSERT_VK_SUCCESS(err);
1126
1127 // Now Try to bind memory to this destroyed object
1128 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1129 // This may very well return an error.
1130 (void) err;
1131
1132 msgFlags = m_errorMonitor->GetState(&msgString);
1133 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while binding memory to a destroyed object";
1134 if (!strstr(msgString.c_str(),"Invalid VkImage Object ")) {
1135 FAIL() << "Error received from BindMemoryToDestroyedObject was not 'Invalid VkImage Object 0x<handle>' but rather '" << msgString.c_str() << "'";
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001136 }
1137}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001138#endif // OBJ_TRACKER_TESTS
1139
Tobin Ehlis0788f522015-05-26 16:11:58 -06001140#if DRAW_STATE_TESTS
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001141TEST_F(VkLayerTest, CmdBufferTwoSubmits)
1142{
1143 vk_testing::Fence testFence;
1144 VkFlags msgFlags;
1145 std::string msgString;
1146
1147 VkFenceCreateInfo fenceInfo = {};
1148 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1149 fenceInfo.pNext = NULL;
1150 fenceInfo.flags = 0;
1151
1152 ASSERT_NO_FATAL_FAILURE(InitState());
1153 ASSERT_NO_FATAL_FAILURE(InitViewport());
1154 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1155
1156 // We luck out b/c by default the framework creates CB w/ the VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set
1157 BeginCommandBuffer();
1158 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
1159 EndCommandBuffer();
1160
1161 testFence.init(*m_device, fenceInfo);
1162
1163 // Bypass framework since it does the waits automatically
1164 VkResult err = VK_SUCCESS;
1165 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
1166 ASSERT_VK_SUCCESS( err );
1167
1168 m_errorMonitor->ClearState();
1169 // Cause validation error by re-submitting cmd buffer that should only be submitted once
1170 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001171
1172 msgFlags = m_errorMonitor->GetState(&msgString);
1173 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after re-submitting Command Buffer that was created with one-time submit flag";
Tobin Ehlisf1878c72015-08-18 14:24:32 -06001174 if (!strstr(msgString.c_str(),"was begun w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set, but has been submitted")) {
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001175 FAIL() << "Error received was not 'CB (0xaddress) was created w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set...'";
1176 }
1177}
1178
Tobin Ehlis502480b2015-06-24 15:53:07 -06001179TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001180{
1181 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001182 VkFlags msgFlags;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001183 std::string msgString;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001184 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001185
1186 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001187 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001188 m_errorMonitor->ClearState();
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001189
1190 VkDescriptorTypeCount ds_type_count = {};
1191 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1192 ds_type_count.count = 1;
1193
1194 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1195 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1196 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001197 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1198 ds_pool_ci.maxSets = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001199 ds_pool_ci.count = 1;
1200 ds_pool_ci.pTypeCount = &ds_type_count;
1201
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001202 VkDescriptorPool ds_pool;
1203 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001204 ASSERT_VK_SUCCESS(err);
1205
1206 VkDescriptorSetLayoutBinding dsl_binding = {};
1207 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1208 dsl_binding.arraySize = 1;
1209 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1210 dsl_binding.pImmutableSamplers = NULL;
1211
1212 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1213 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1214 ds_layout_ci.pNext = NULL;
1215 ds_layout_ci.count = 1;
1216 ds_layout_ci.pBinding = &dsl_binding;
1217
1218 VkDescriptorSetLayout ds_layout;
1219 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1220 ASSERT_VK_SUCCESS(err);
1221
1222 VkDescriptorSet descriptorSet;
1223 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1224 ASSERT_VK_SUCCESS(err);
1225 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1226 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1227 pipe_ms_state_ci.pNext = NULL;
1228 pipe_ms_state_ci.rasterSamples = 1;
1229 pipe_ms_state_ci.sampleShadingEnable = 0;
1230 pipe_ms_state_ci.minSampleShading = 1.0;
1231 pipe_ms_state_ci.pSampleMask = NULL;
1232
1233 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1234 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1235 pipeline_layout_ci.pNext = NULL;
1236 pipeline_layout_ci.descriptorSetCount = 1;
1237 pipeline_layout_ci.pSetLayouts = &ds_layout;
1238 VkPipelineLayout pipeline_layout;
1239
1240 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1241 ASSERT_VK_SUCCESS(err);
1242
1243 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
1244 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1245 // but add it to be able to run on more devices
1246 VkPipelineObj pipe(m_device);
1247 pipe.AddShader(&vs);
1248 pipe.AddShader(&fs);
1249 pipe.SetMSAA(&pipe_ms_state_ci);
1250 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1251 m_errorMonitor->ClearState();
1252 // Calls CreateCommandBuffer
1253 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1254 VkCmdBufferBeginInfo cmd_buf_info = {};
1255 memset(&cmd_buf_info, 0, sizeof(VkCmdBufferBeginInfo));
1256 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1257 cmd_buf_info.pNext = NULL;
1258 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1259 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1260
1261 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1262 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001263 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001264 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding pipeline to CmdBuffer w/o active RenderPass";
Tobin Ehlis502480b2015-06-24 15:53:07 -06001265 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001266 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0x<handle>) without an active RenderPass'";
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001267 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001268}
1269
1270TEST_F(VkLayerTest, InvalidDescriptorPool)
1271{
1272 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1273 // The DS check for this is after driver has been called to validate DS internal data struct
1274 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001275/* VkFlags msgFlags;
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001276 std::string msgString;
1277 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1278 vkResetDescriptorPool(device(), badPool);
1279
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001280 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001281 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Resetting an invalid DescriptorPool Object";
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001282 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1283 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1284 }*/
1285}
1286
1287TEST_F(VkLayerTest, InvalidDescriptorSet)
1288{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001289 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1290 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001291 // Create a valid cmd buffer
1292 // call vkCmdBindDescriptorSets w/ false DS
1293}
1294
1295TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1296{
1297 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1298 // The DS check for this is after driver has been called to validate DS internal data struct
1299}
1300
1301TEST_F(VkLayerTest, InvalidPipeline)
1302{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001303 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1304 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001305 // Create a valid cmd buffer
1306 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlis502480b2015-06-24 15:53:07 -06001307// VkFlags msgFlags;
1308// std::string msgString;
1309//
1310// ASSERT_NO_FATAL_FAILURE(InitState());
1311// m_errorMonitor->ClearState();
1312// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001313// BeginCommandBuffer();
Tobin Ehlis502480b2015-06-24 15:53:07 -06001314// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1315// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1316// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001317// ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Tobin Ehlis502480b2015-06-24 15:53:07 -06001318// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1319// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1320// }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001321}
1322
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001323TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001324{
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001325 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001326 VkFlags msgFlags;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001327 std::string msgString;
1328 VkResult err;
1329
1330 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06001331 ASSERT_NO_FATAL_FAILURE(InitViewport());
1332 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001333 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06001334 VkDescriptorTypeCount ds_type_count = {};
1335 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1336 ds_type_count.count = 1;
1337
1338 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1339 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1340 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001341 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1342 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001343 ds_pool_ci.count = 1;
1344 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06001345
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001346 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001347 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001348 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001349
Tony Barboureb254902015-07-15 12:50:33 -06001350 VkDescriptorSetLayoutBinding dsl_binding = {};
1351 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1352 dsl_binding.arraySize = 1;
1353 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1354 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001355
Tony Barboureb254902015-07-15 12:50:33 -06001356 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1357 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1358 ds_layout_ci.pNext = NULL;
1359 ds_layout_ci.count = 1;
1360 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001361 VkDescriptorSetLayout ds_layout;
1362 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1363 ASSERT_VK_SUCCESS(err);
1364
1365 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06001366 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001367 ASSERT_VK_SUCCESS(err);
1368
Tony Barboureb254902015-07-15 12:50:33 -06001369 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1370 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1371 pipeline_layout_ci.pNext = NULL;
1372 pipeline_layout_ci.descriptorSetCount = 1;
1373 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001374
1375 VkPipelineLayout pipeline_layout;
1376 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1377 ASSERT_VK_SUCCESS(err);
1378
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001379 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour1c94d372015-08-06 11:21:08 -06001380 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1381 // but add it to be able to run on more devices
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001382
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001383 VkPipelineObj pipe(m_device);
1384 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06001385 pipe.AddShader(&fs);
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001386 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001387
1388 BeginCommandBuffer();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001389 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001390 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001391
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001392 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001393 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not warn after binding a DescriptorSet that was never updated.";
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001394 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1395 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1396 }
1397}
1398
1399TEST_F(VkLayerTest, NoBeginCmdBuffer)
1400{
1401 VkFlags msgFlags;
1402 std::string msgString;
1403
1404 ASSERT_NO_FATAL_FAILURE(InitState());
1405 m_errorMonitor->ClearState();
Tony Barbourfe3351b2015-07-28 10:17:20 -06001406 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001407 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1408 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1409 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001410 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after ending a CmdBuffer w/o calling BeginCommandBuffer()";
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001411 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1412 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1413 }
1414}
1415
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001416TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1417{
1418 VkFlags msgFlags;
1419 std::string msgString;
1420
1421 ASSERT_NO_FATAL_FAILURE(InitState());
1422 m_errorMonitor->ClearState();
1423
1424 // Calls CreateCommandBuffer
1425 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1426
1427 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northropb4569702015-08-04 17:35:57 -06001428 VkCmdBufferBeginInfo cmd_buf_info = {};
1429 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1430 cmd_buf_info.pNext = NULL;
1431 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1432 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1433 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1434 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1435
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001436
1437 // The error should be caught by validation of the BeginCommandBuffer call
1438 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1439
1440 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001441 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error passing a non-NULL Framebuffer and Renderpass to BeginCommandBuffer()";
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001442 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1443 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1444 }
1445}
1446
1447TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1448{
1449 VkFlags msgFlags;
1450 std::string msgString;
1451 VkResult err;
1452 VkCmdBuffer draw_cmd;
1453 VkCmdPool cmd_pool;
1454
1455 ASSERT_NO_FATAL_FAILURE(InitState());
1456 m_errorMonitor->ClearState();
1457
Cody Northropb4569702015-08-04 17:35:57 -06001458 VkCmdBufferCreateInfo cmd = {};
1459 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1460 cmd.pNext = NULL;
1461 cmd.cmdPool = m_cmdPool;
1462 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1463 cmd.flags = 0;
1464
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001465 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
1466 assert(!err);
1467
1468 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northropb4569702015-08-04 17:35:57 -06001469 VkCmdBufferBeginInfo cmd_buf_info = {};
1470 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1471 cmd_buf_info.pNext = NULL;
1472 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1473 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001474
1475 // The error should be caught by validation of the BeginCommandBuffer call
1476 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1477
1478 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001479 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error passing NULL Framebuffer/Renderpass to BeginCommandBuffer()";
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001480 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1481 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1482 }
1483}
1484
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001485TEST_F(VkLayerTest, InvalidPipelineCreateState)
1486{
1487 // Attempt to Create Gfx Pipeline w/o a VS
1488 VkFlags msgFlags;
1489 std::string msgString;
1490 VkResult err;
1491
1492 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001493 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001494 m_errorMonitor->ClearState();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001495
Tony Barboureb254902015-07-15 12:50:33 -06001496 VkDescriptorTypeCount ds_type_count = {};
1497 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1498 ds_type_count.count = 1;
1499
1500 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1501 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1502 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001503 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1504 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001505 ds_pool_ci.count = 1;
1506 ds_pool_ci.pTypeCount = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001507
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001508 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001509 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001510 ASSERT_VK_SUCCESS(err);
1511
Tony Barboureb254902015-07-15 12:50:33 -06001512 VkDescriptorSetLayoutBinding dsl_binding = {};
1513 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1514 dsl_binding.arraySize = 1;
1515 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1516 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001517
Tony Barboureb254902015-07-15 12:50:33 -06001518 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1519 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1520 ds_layout_ci.pNext = NULL;
1521 ds_layout_ci.count = 1;
1522 ds_layout_ci.pBinding = &dsl_binding;
1523
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001524 VkDescriptorSetLayout ds_layout;
1525 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1526 ASSERT_VK_SUCCESS(err);
1527
1528 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06001529 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001530 ASSERT_VK_SUCCESS(err);
1531
Tony Barboureb254902015-07-15 12:50:33 -06001532 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1533 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1534 pipeline_layout_ci.pNext = NULL;
1535 pipeline_layout_ci.descriptorSetCount = 1;
1536 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001537
1538 VkPipelineLayout pipeline_layout;
1539 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1540 ASSERT_VK_SUCCESS(err);
1541
Tony Barboureb254902015-07-15 12:50:33 -06001542 VkGraphicsPipelineCreateInfo gp_ci = {};
1543 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1544 gp_ci.pNext = NULL;
1545 gp_ci.stageCount = 0;
1546 gp_ci.pStages = NULL;
1547 gp_ci.pVertexInputState = NULL;
1548 gp_ci.pInputAssemblyState = NULL;
1549 gp_ci.pTessellationState = NULL;
1550 gp_ci.pViewportState = NULL;
1551 gp_ci.pRasterState = NULL;
1552 gp_ci.pMultisampleState = NULL;
1553 gp_ci.pDepthStencilState = NULL;
1554 gp_ci.pColorBlendState = NULL;
1555 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1556 gp_ci.layout = pipeline_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001557 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06001558
1559 VkPipelineCacheCreateInfo pc_ci = {};
1560 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1561 pc_ci.pNext = NULL;
1562 pc_ci.initialSize = 0;
1563 pc_ci.initialData = 0;
1564 pc_ci.maxSize = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001565
1566 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06001567 VkPipelineCache pipelineCache;
1568
1569 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1570 ASSERT_VK_SUCCESS(err);
1571 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001572
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001573 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001574 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o VS.";
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001575 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1576 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1577 }
1578}
Tobin Ehlis912df022015-09-17 08:46:18 -06001579/*// TODO : This test should be good, but needs Tess support in compiler to run
1580TEST_F(VkLayerTest, InvalidPatchControlPoints)
1581{
1582 // Attempt to Create Gfx Pipeline w/o a VS
1583 VkFlags msgFlags;
1584 std::string msgString;
1585 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001586
Tobin Ehlis912df022015-09-17 08:46:18 -06001587 ASSERT_NO_FATAL_FAILURE(InitState());
1588 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1589 m_errorMonitor->ClearState();
1590
1591 VkDescriptorTypeCount ds_type_count = {};
1592 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1593 ds_type_count.count = 1;
1594
1595 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1596 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1597 ds_pool_ci.pNext = NULL;
1598 ds_pool_ci.count = 1;
1599 ds_pool_ci.pTypeCount = &ds_type_count;
1600
1601 VkDescriptorPool ds_pool;
1602 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1603 ASSERT_VK_SUCCESS(err);
1604
1605 VkDescriptorSetLayoutBinding dsl_binding = {};
1606 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1607 dsl_binding.arraySize = 1;
1608 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1609 dsl_binding.pImmutableSamplers = NULL;
1610
1611 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1612 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1613 ds_layout_ci.pNext = NULL;
1614 ds_layout_ci.count = 1;
1615 ds_layout_ci.pBinding = &dsl_binding;
1616
1617 VkDescriptorSetLayout ds_layout;
1618 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1619 ASSERT_VK_SUCCESS(err);
1620
1621 VkDescriptorSet descriptorSet;
1622 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1623 ASSERT_VK_SUCCESS(err);
1624
1625 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1626 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1627 pipeline_layout_ci.pNext = NULL;
1628 pipeline_layout_ci.descriptorSetCount = 1;
1629 pipeline_layout_ci.pSetLayouts = &ds_layout;
1630
1631 VkPipelineLayout pipeline_layout;
1632 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1633 ASSERT_VK_SUCCESS(err);
1634
1635 VkPipelineShaderStageCreateInfo shaderStages[3];
1636 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
1637
1638 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
1639 // Just using VS txt for Tess shaders as we don't care about functionality
1640 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESS_CONTROL, this);
1641 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESS_EVALUATION, this);
1642
1643 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1644 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
1645 shaderStages[0].shader = vs.handle();
1646 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1647 shaderStages[1].stage = VK_SHADER_STAGE_TESS_CONTROL;
1648 shaderStages[1].shader = tc.handle();
1649 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1650 shaderStages[2].stage = VK_SHADER_STAGE_TESS_EVALUATION;
1651 shaderStages[2].shader = te.handle();
1652
1653 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
1654 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
1655 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH;
1656
1657 VkPipelineTessellationStateCreateInfo tsCI = {};
1658 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
1659 tsCI.patchControlPoints = 0; // This will cause an error
1660
1661 VkGraphicsPipelineCreateInfo gp_ci = {};
1662 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1663 gp_ci.pNext = NULL;
1664 gp_ci.stageCount = 3;
1665 gp_ci.pStages = shaderStages;
1666 gp_ci.pVertexInputState = NULL;
1667 gp_ci.pInputAssemblyState = &iaCI;
1668 gp_ci.pTessellationState = &tsCI;
1669 gp_ci.pViewportState = NULL;
1670 gp_ci.pRasterState = NULL;
1671 gp_ci.pMultisampleState = NULL;
1672 gp_ci.pDepthStencilState = NULL;
1673 gp_ci.pColorBlendState = NULL;
1674 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1675 gp_ci.layout = pipeline_layout;
1676 gp_ci.renderPass = renderPass();
1677
1678 VkPipelineCacheCreateInfo pc_ci = {};
1679 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1680 pc_ci.pNext = NULL;
1681 pc_ci.initialSize = 0;
1682 pc_ci.initialData = 0;
1683 pc_ci.maxSize = 0;
1684
1685 VkPipeline pipeline;
1686 VkPipelineCache pipelineCache;
1687
1688 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1689 ASSERT_VK_SUCCESS(err);
1690 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1691
1692 msgFlags = m_errorMonitor->GetState(&msgString);
1693 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Tess Gfx Pipeline w/ 0 patchControlPoints.";
1694 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ")) {
1695 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...' but instead '" << msgString.c_str() << "'";
1696 }
1697}
1698*/
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06001699TEST_F(VkLayerTest, NullRenderPass)
1700{
1701 // Bind a NULL RenderPass
1702 VkFlags msgFlags;
1703 std::string msgString;
1704
1705 ASSERT_NO_FATAL_FAILURE(InitState());
1706 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1707 m_errorMonitor->ClearState();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06001708
Tony Barbourfe3351b2015-07-28 10:17:20 -06001709 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06001710 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbourfe3351b2015-07-28 10:17:20 -06001711 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06001712
1713 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001714 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06001715 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
1716 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
1717 }
1718}
1719
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001720TEST_F(VkLayerTest, RenderPassWithinRenderPass)
1721{
1722 // Bind a BeginRenderPass within an active RenderPass
1723 VkFlags msgFlags;
1724 std::string msgString;
1725
1726 ASSERT_NO_FATAL_FAILURE(InitState());
1727 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1728 m_errorMonitor->ClearState();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001729
Tony Barbourfe3351b2015-07-28 10:17:20 -06001730 BeginCommandBuffer();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06001731 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barboureb254902015-07-15 12:50:33 -06001732 VkRenderPassBeginInfo rp_begin = {};
1733 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
1734 rp_begin.pNext = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001735 rp_begin.renderPass = renderPass();
1736 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001737
Tony Barbourfe3351b2015-07-28 10:17:20 -06001738 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001739
1740 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001741 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding RenderPass w/i an active RenderPass.";
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06001742 if (!strstr(msgString.c_str(),"Cannot call vkCmdBeginRenderPass() during an active RenderPass ")) {
1743 FAIL() << "Error received was not 'Cannot call vkCmdBeginRenderPass() during an active RenderPass...'";
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001744 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001745}
1746
1747TEST_F(VkLayerTest, InvalidDynamicStateObject)
1748{
1749 // Create a valid cmd buffer
1750 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06001751 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1752 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001753}
Tobin Ehlis1056d452015-05-27 14:55:35 -06001754
Tobin Ehlis502480b2015-06-24 15:53:07 -06001755TEST_F(VkLayerTest, VtxBufferNoRenderPass)
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001756{
1757 // Bind VBO out-of-bounds for given PSO
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001758 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001759 std::string msgString;
1760 VkResult err;
1761
1762 ASSERT_NO_FATAL_FAILURE(InitState());
1763 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06001764
1765 VkDescriptorTypeCount ds_type_count = {};
1766 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1767 ds_type_count.count = 1;
1768
1769 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1770 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1771 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001772 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1773 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001774 ds_pool_ci.count = 1;
1775 ds_pool_ci.pTypeCount = &ds_type_count;
1776
Tobin Ehlis3b780662015-05-28 12:11:26 -06001777 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001778 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001779 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001780
Tony Barboureb254902015-07-15 12:50:33 -06001781 VkDescriptorSetLayoutBinding dsl_binding = {};
1782 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1783 dsl_binding.arraySize = 1;
1784 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1785 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001786
Tony Barboureb254902015-07-15 12:50:33 -06001787 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1788 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1789 ds_layout_ci.pNext = NULL;
1790 ds_layout_ci.count = 1;
1791 ds_layout_ci.pBinding = &dsl_binding;
1792
Tobin Ehlis3b780662015-05-28 12:11:26 -06001793 VkDescriptorSetLayout ds_layout;
1794 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1795 ASSERT_VK_SUCCESS(err);
1796
1797 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06001798 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001799 ASSERT_VK_SUCCESS(err);
1800
Tony Barboureb254902015-07-15 12:50:33 -06001801 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1802 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1803 pipeline_layout_ci.pNext = NULL;
1804 pipeline_layout_ci.descriptorSetCount = 1;
1805 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001806
1807 VkPipelineLayout pipeline_layout;
1808 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1809 ASSERT_VK_SUCCESS(err);
1810
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001811 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour1c94d372015-08-06 11:21:08 -06001812 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1813 // but add it to be able to run on more devices
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001814 VkPipelineObj pipe(m_device);
1815 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06001816 pipe.AddShader(&fs);
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001817 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06001818
Tony Barbourfe3351b2015-07-28 10:17:20 -06001819 BeginCommandBuffer();
Tobin Ehlis3b780662015-05-28 12:11:26 -06001820 ASSERT_VK_SUCCESS(err);
Tony Barbourc95e4ac2015-08-04 17:05:26 -06001821 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06001822 // Should error before calling to driver so don't care about actual data
Tony Barbourfe3351b2015-07-28 10:17:20 -06001823 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001824
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001825 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001826 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
Tobin Ehlis502480b2015-06-24 15:53:07 -06001827 if (!strstr(msgString.c_str(),"Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.")) {
1828 FAIL() << "Error received was not 'Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.'";
Tobin Ehlis3b780662015-05-28 12:11:26 -06001829 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001830}
1831
Tobin Ehlisc4c23182015-09-17 12:24:13 -06001832TEST_F(VkLayerTest, IdxBufferAlignmentError)
1833{
1834 // Bind a BeginRenderPass within an active RenderPass
1835 VkFlags msgFlags;
1836 std::string msgString;
1837 VkResult err;
1838
1839 ASSERT_NO_FATAL_FAILURE(InitState());
1840 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1841 m_errorMonitor->ClearState();
1842 uint32_t qfi = 0;
1843 VkBufferCreateInfo buffCI = {};
1844 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1845 buffCI.size = 1024;
1846 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
1847 buffCI.queueFamilyCount = 1;
1848 buffCI.pQueueFamilyIndices = &qfi;
1849
1850 VkBuffer ib;
1851 err = vkCreateBuffer(m_device->device(), &buffCI, &ib);
1852 ASSERT_VK_SUCCESS(err);
1853
1854 BeginCommandBuffer();
1855 ASSERT_VK_SUCCESS(err);
1856 //vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
1857 // Should error before calling to driver so don't care about actual data
1858 vkCmdBindIndexBuffer(m_cmdBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
1859
1860 msgFlags = m_errorMonitor->GetState(&msgString);
1861 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
1862 if (!strstr(msgString.c_str(),"vkCmdBindIndexBuffer() offset (0x7) does not fall on ")) {
1863 FAIL() << "Error received was not 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...' but instead '" << msgString.c_str() << "'";
1864 }
1865}
1866
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06001867TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
1868{
1869 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
1870 VkFlags msgFlags;
1871 std::string msgString;
1872
1873 ASSERT_NO_FATAL_FAILURE(InitState());
1874 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1875 m_errorMonitor->ClearState();
1876
1877 BeginCommandBuffer();
1878 //ASSERT_VK_SUCCESS(err);
1879 VkCmdBuffer primCB = m_cmdBuffer->GetBufferHandle();
1880 vkCmdExecuteCommands(m_cmdBuffer->GetBufferHandle(), 1, &primCB);
1881
1882 msgFlags = m_errorMonitor->GetState(&msgString);
1883 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
1884 if (!strstr(msgString.c_str(),"vkCmdExecuteCommands() called w/ Primary Cmd Buffer ")) {
1885 FAIL() << "Error received was not 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer ' but instead '" << msgString.c_str() << "'";
1886 }
1887}
1888
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001889TEST_F(VkLayerTest, DSTypeMismatch)
1890{
1891 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001892 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001893 std::string msgString;
1894 VkResult err;
1895
1896 ASSERT_NO_FATAL_FAILURE(InitState());
1897 m_errorMonitor->ClearState();
1898 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06001899 VkDescriptorTypeCount ds_type_count = {};
1900 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1901 ds_type_count.count = 1;
1902
1903 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1904 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1905 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001906 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1907 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001908 ds_pool_ci.count = 1;
1909 ds_pool_ci.pTypeCount = &ds_type_count;
1910
Tobin Ehlis3b780662015-05-28 12:11:26 -06001911 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001912 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001913 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06001914 VkDescriptorSetLayoutBinding dsl_binding = {};
1915 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1916 dsl_binding.arraySize = 1;
1917 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1918 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001919
Tony Barboureb254902015-07-15 12:50:33 -06001920 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1921 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1922 ds_layout_ci.pNext = NULL;
1923 ds_layout_ci.count = 1;
1924 ds_layout_ci.pBinding = &dsl_binding;
1925
Tobin Ehlis3b780662015-05-28 12:11:26 -06001926 VkDescriptorSetLayout ds_layout;
1927 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1928 ASSERT_VK_SUCCESS(err);
1929
1930 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06001931 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001932 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06001933
Tony Barboureb254902015-07-15 12:50:33 -06001934 VkSamplerCreateInfo sampler_ci = {};
1935 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1936 sampler_ci.pNext = NULL;
1937 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1938 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1939 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter97953352015-09-10 14:08:50 -06001940 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
1941 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
1942 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barboureb254902015-07-15 12:50:33 -06001943 sampler_ci.mipLodBias = 1.0;
1944 sampler_ci.maxAnisotropy = 1;
1945 sampler_ci.compareEnable = VK_FALSE;
1946 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1947 sampler_ci.minLod = 1.0;
1948 sampler_ci.maxLod = 1.0;
1949 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06001950 sampler_ci.unnormalizedCoordinates = VK_FALSE;
1951
Tobin Ehlis3b780662015-05-28 12:11:26 -06001952 VkSampler sampler;
1953 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1954 ASSERT_VK_SUCCESS(err);
1955
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001956 VkDescriptorInfo descriptor_info;
1957 memset(&descriptor_info, 0, sizeof(descriptor_info));
1958 descriptor_info.sampler = sampler;
1959
1960 VkWriteDescriptorSet descriptor_write;
1961 memset(&descriptor_write, 0, sizeof(descriptor_write));
1962 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1963 descriptor_write.destSet = descriptorSet;
1964 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001965 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001966 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1967 descriptor_write.pDescriptors = &descriptor_info;
1968
1969 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1970
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001971 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06001972 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating BUFFER Descriptor w/ incorrect type of SAMPLER.";
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001973 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) {
1974 FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match overlapping binding type!'";
Tobin Ehlis3b780662015-05-28 12:11:26 -06001975 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06001976}
1977
1978TEST_F(VkLayerTest, DSUpdateOutOfBounds)
1979{
1980 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001981 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06001982 std::string msgString;
1983 VkResult err;
1984
1985 ASSERT_NO_FATAL_FAILURE(InitState());
1986 m_errorMonitor->ClearState();
1987 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06001988 VkDescriptorTypeCount ds_type_count = {};
1989 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1990 ds_type_count.count = 1;
1991
1992 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1993 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1994 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001995 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1996 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06001997 ds_pool_ci.count = 1;
1998 ds_pool_ci.pTypeCount = &ds_type_count;
1999
Tobin Ehlis3b780662015-05-28 12:11:26 -06002000 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002001 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002002 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002003
Tony Barboureb254902015-07-15 12:50:33 -06002004 VkDescriptorSetLayoutBinding dsl_binding = {};
2005 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2006 dsl_binding.arraySize = 1;
2007 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2008 dsl_binding.pImmutableSamplers = NULL;
2009
2010 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2011 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2012 ds_layout_ci.pNext = NULL;
2013 ds_layout_ci.count = 1;
2014 ds_layout_ci.pBinding = &dsl_binding;
2015
Tobin Ehlis3b780662015-05-28 12:11:26 -06002016 VkDescriptorSetLayout ds_layout;
2017 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2018 ASSERT_VK_SUCCESS(err);
2019
2020 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06002021 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002022 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002023
Tony Barboureb254902015-07-15 12:50:33 -06002024 VkSamplerCreateInfo sampler_ci = {};
2025 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2026 sampler_ci.pNext = NULL;
2027 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2028 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2029 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter97953352015-09-10 14:08:50 -06002030 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2031 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2032 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barboureb254902015-07-15 12:50:33 -06002033 sampler_ci.mipLodBias = 1.0;
2034 sampler_ci.maxAnisotropy = 1;
2035 sampler_ci.compareEnable = VK_FALSE;
2036 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2037 sampler_ci.minLod = 1.0;
2038 sampler_ci.maxLod = 1.0;
2039 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06002040 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06002041
Tobin Ehlis3b780662015-05-28 12:11:26 -06002042 VkSampler sampler;
2043 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2044 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002045
2046 VkDescriptorInfo descriptor_info;
2047 memset(&descriptor_info, 0, sizeof(descriptor_info));
2048 descriptor_info.sampler = sampler;
2049
2050 VkWriteDescriptorSet descriptor_write;
2051 memset(&descriptor_write, 0, sizeof(descriptor_write));
2052 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2053 descriptor_write.destSet = descriptorSet;
2054 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
2055 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002056 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002057 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2058 descriptor_write.pDescriptors = &descriptor_info;
2059
2060 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2061
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002062 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002063 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ index out of bounds.";
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002064 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
2065 FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
Tobin Ehlis3b780662015-05-28 12:11:26 -06002066 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002067}
2068
2069TEST_F(VkLayerTest, InvalidDSUpdateIndex)
2070{
Tobin Ehlis3b780662015-05-28 12:11:26 -06002071 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002072 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002073 std::string msgString;
2074 VkResult err;
2075
2076 ASSERT_NO_FATAL_FAILURE(InitState());
2077 m_errorMonitor->ClearState();
2078 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barboureb254902015-07-15 12:50:33 -06002079 VkDescriptorTypeCount ds_type_count = {};
2080 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2081 ds_type_count.count = 1;
2082
2083 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2084 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2085 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002086 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2087 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002088 ds_pool_ci.count = 1;
2089 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002090
Tobin Ehlis3b780662015-05-28 12:11:26 -06002091 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002092 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002093 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002094
Tony Barboureb254902015-07-15 12:50:33 -06002095 VkDescriptorSetLayoutBinding dsl_binding = {};
2096 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2097 dsl_binding.arraySize = 1;
2098 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2099 dsl_binding.pImmutableSamplers = NULL;
2100
2101 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2102 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2103 ds_layout_ci.pNext = NULL;
2104 ds_layout_ci.count = 1;
2105 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002106 VkDescriptorSetLayout ds_layout;
2107 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2108 ASSERT_VK_SUCCESS(err);
2109
2110 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06002111 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002112 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002113
Tony Barboureb254902015-07-15 12:50:33 -06002114 VkSamplerCreateInfo sampler_ci = {};
2115 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2116 sampler_ci.pNext = NULL;
2117 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2118 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2119 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter97953352015-09-10 14:08:50 -06002120 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2121 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2122 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barboureb254902015-07-15 12:50:33 -06002123 sampler_ci.mipLodBias = 1.0;
2124 sampler_ci.maxAnisotropy = 1;
2125 sampler_ci.compareEnable = VK_FALSE;
2126 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2127 sampler_ci.minLod = 1.0;
2128 sampler_ci.maxLod = 1.0;
2129 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06002130 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06002131
Tobin Ehlis3b780662015-05-28 12:11:26 -06002132 VkSampler sampler;
2133 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2134 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002135
2136 VkDescriptorInfo descriptor_info;
2137 memset(&descriptor_info, 0, sizeof(descriptor_info));
2138 descriptor_info.sampler = sampler;
2139
2140 VkWriteDescriptorSet descriptor_write;
2141 memset(&descriptor_write, 0, sizeof(descriptor_write));
2142 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2143 descriptor_write.destSet = descriptorSet;
2144 descriptor_write.destBinding = 2;
2145 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002146 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002147 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2148 descriptor_write.pDescriptors = &descriptor_info;
2149
2150 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2151
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002152 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002153 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ count too large for layout.";
Tobin Ehlis3b780662015-05-28 12:11:26 -06002154 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
2155 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
2156 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002157}
2158
2159TEST_F(VkLayerTest, InvalidDSUpdateStruct)
2160{
2161 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002162 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002163 std::string msgString;
2164 VkResult err;
2165
2166 ASSERT_NO_FATAL_FAILURE(InitState());
2167 m_errorMonitor->ClearState();
2168 //VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002169
Tony Barboureb254902015-07-15 12:50:33 -06002170 VkDescriptorTypeCount ds_type_count = {};
2171 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2172 ds_type_count.count = 1;
2173
2174 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2175 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2176 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002177 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2178 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002179 ds_pool_ci.count = 1;
2180 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002181
Tobin Ehlis3b780662015-05-28 12:11:26 -06002182 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002183 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002184 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06002185 VkDescriptorSetLayoutBinding dsl_binding = {};
2186 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2187 dsl_binding.arraySize = 1;
2188 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2189 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002190
Tony Barboureb254902015-07-15 12:50:33 -06002191 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2192 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2193 ds_layout_ci.pNext = NULL;
2194 ds_layout_ci.count = 1;
2195 ds_layout_ci.pBinding = &dsl_binding;
2196
Tobin Ehlis3b780662015-05-28 12:11:26 -06002197 VkDescriptorSetLayout ds_layout;
2198 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2199 ASSERT_VK_SUCCESS(err);
2200
2201 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06002202 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002203 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002204
Tony Barboureb254902015-07-15 12:50:33 -06002205 VkSamplerCreateInfo sampler_ci = {};
2206 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2207 sampler_ci.pNext = NULL;
2208 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2209 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2210 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter97953352015-09-10 14:08:50 -06002211 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2212 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2213 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barboureb254902015-07-15 12:50:33 -06002214 sampler_ci.mipLodBias = 1.0;
2215 sampler_ci.maxAnisotropy = 1;
2216 sampler_ci.compareEnable = VK_FALSE;
2217 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2218 sampler_ci.minLod = 1.0;
2219 sampler_ci.maxLod = 1.0;
2220 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski52ac6582015-09-01 15:42:56 -06002221 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002222 VkSampler sampler;
2223 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2224 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002225
2226
2227 VkDescriptorInfo descriptor_info;
2228 memset(&descriptor_info, 0, sizeof(descriptor_info));
2229 descriptor_info.sampler = sampler;
2230
2231 VkWriteDescriptorSet descriptor_write;
2232 memset(&descriptor_write, 0, sizeof(descriptor_write));
2233 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
2234 descriptor_write.destSet = descriptorSet;
2235 descriptor_write.count = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002236 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002237 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2238 descriptor_write.pDescriptors = &descriptor_info;
2239
2240 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2241
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002242 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002243 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ invalid struct type.";
Tobin Ehlis3b780662015-05-28 12:11:26 -06002244 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
2245 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
2246 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002247}
2248
2249TEST_F(VkLayerTest, NumSamplesMismatch)
2250{
Tobin Ehlis3b780662015-05-28 12:11:26 -06002251 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002252 VkFlags msgFlags;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002253 std::string msgString;
2254 VkResult err;
2255
2256 ASSERT_NO_FATAL_FAILURE(InitState());
2257 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2258 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06002259 VkDescriptorTypeCount ds_type_count = {};
2260 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2261 ds_type_count.count = 1;
2262
2263 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002264 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2265 ds_pool_ci.pNext = NULL;
2266 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2267 ds_pool_ci.maxSets = 1;
2268 ds_pool_ci.count = 1;
2269 ds_pool_ci.pTypeCount = &ds_type_count;
2270
Tobin Ehlis3b780662015-05-28 12:11:26 -06002271 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002272 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002273 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002274
Tony Barboureb254902015-07-15 12:50:33 -06002275 VkDescriptorSetLayoutBinding dsl_binding = {};
2276 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2277 dsl_binding.arraySize = 1;
2278 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2279 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002280
Tony Barboureb254902015-07-15 12:50:33 -06002281 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2282 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2283 ds_layout_ci.pNext = NULL;
2284 ds_layout_ci.count = 1;
2285 ds_layout_ci.pBinding = &dsl_binding;
2286
Tobin Ehlis3b780662015-05-28 12:11:26 -06002287 VkDescriptorSetLayout ds_layout;
2288 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2289 ASSERT_VK_SUCCESS(err);
2290
2291 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06002292 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06002293 ASSERT_VK_SUCCESS(err);
2294
Tony Barboureb254902015-07-15 12:50:33 -06002295 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2296 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2297 pipe_ms_state_ci.pNext = NULL;
2298 pipe_ms_state_ci.rasterSamples = 4;
2299 pipe_ms_state_ci.sampleShadingEnable = 0;
2300 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06002301 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002302
Tony Barboureb254902015-07-15 12:50:33 -06002303 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2304 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2305 pipeline_layout_ci.pNext = NULL;
2306 pipeline_layout_ci.descriptorSetCount = 1;
2307 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06002308
2309 VkPipelineLayout pipeline_layout;
2310 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2311 ASSERT_VK_SUCCESS(err);
2312
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06002313 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour1c94d372015-08-06 11:21:08 -06002314 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2315 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06002316 VkPipelineObj pipe(m_device);
2317 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06002318 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06002319 pipe.SetMSAA(&pipe_ms_state_ci);
2320 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06002321
Tony Barbourfe3351b2015-07-28 10:17:20 -06002322 BeginCommandBuffer();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06002323 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06002324
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002325 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002326 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding RenderPass w/ mismatched MSAA from PSO.";
Tobin Ehlis3b780662015-05-28 12:11:26 -06002327 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
2328 FAIL() << "Error received was not 'Num samples mismatch!...'";
2329 }
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06002330}
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002331
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002332TEST_F(VkLayerTest, ClearCmdNoDraw)
2333{
2334 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
2335 VkFlags msgFlags;
2336 std::string msgString;
2337 VkResult err;
2338
2339 ASSERT_NO_FATAL_FAILURE(InitState());
2340 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2341 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06002342
2343 VkDescriptorTypeCount ds_type_count = {};
2344 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2345 ds_type_count.count = 1;
2346
2347 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2348 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2349 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002350 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2351 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002352 ds_pool_ci.count = 1;
2353 ds_pool_ci.pTypeCount = &ds_type_count;
2354
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002355 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002356 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002357 ASSERT_VK_SUCCESS(err);
2358
Tony Barboureb254902015-07-15 12:50:33 -06002359 VkDescriptorSetLayoutBinding dsl_binding = {};
2360 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2361 dsl_binding.arraySize = 1;
2362 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2363 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002364
Tony Barboureb254902015-07-15 12:50:33 -06002365 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2366 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2367 ds_layout_ci.pNext = NULL;
2368 ds_layout_ci.count = 1;
2369 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002370
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002371 VkDescriptorSetLayout ds_layout;
2372 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2373 ASSERT_VK_SUCCESS(err);
2374
2375 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06002376 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002377 ASSERT_VK_SUCCESS(err);
2378
Tony Barboureb254902015-07-15 12:50:33 -06002379 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2380 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2381 pipe_ms_state_ci.pNext = NULL;
2382 pipe_ms_state_ci.rasterSamples = 4;
2383 pipe_ms_state_ci.sampleShadingEnable = 0;
2384 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06002385 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002386
Tony Barboureb254902015-07-15 12:50:33 -06002387 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2388 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2389 pipeline_layout_ci.pNext = NULL;
2390 pipeline_layout_ci.descriptorSetCount = 1;
2391 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002392
2393 VkPipelineLayout pipeline_layout;
2394 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2395 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002396
Tony Barbour62e1a5b2015-08-06 10:16:07 -06002397 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour1c94d372015-08-06 11:21:08 -06002398 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2399 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06002400 VkPipelineObj pipe(m_device);
2401 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06002402 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06002403 pipe.SetMSAA(&pipe_ms_state_ci);
2404 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002405
2406 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002407
2408 m_errorMonitor->ClearState();
2409 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
2410 // Also pass down other dummy params to keep driver and paramchecker happy
2411 VkClearColorValue cCV;
Cody Northrop85789d52015-08-25 15:26:38 -06002412 cCV.float32[0] = 1.0;
2413 cCV.float32[1] = 1.0;
2414 cCV.float32[2] = 1.0;
2415 cCV.float32[3] = 1.0;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002416
Tony Barbourfe3351b2015-07-28 10:17:20 -06002417 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002418 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002419 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not receive error after issuing Clear Cmd on FB color attachment prior to Draw Cmd.";
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002420 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) {
2421 FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'";
2422 }
2423}
2424
Tobin Ehlis502480b2015-06-24 15:53:07 -06002425TEST_F(VkLayerTest, VtxBufferBadIndex)
2426{
2427 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
2428 VkFlags msgFlags;
2429 std::string msgString;
2430 VkResult err;
2431
2432 ASSERT_NO_FATAL_FAILURE(InitState());
2433 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2434 m_errorMonitor->ClearState();
Tony Barboureb254902015-07-15 12:50:33 -06002435
2436 VkDescriptorTypeCount ds_type_count = {};
2437 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2438 ds_type_count.count = 1;
2439
2440 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2441 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2442 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002443 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2444 ds_pool_ci.maxSets = 1;
Tony Barboureb254902015-07-15 12:50:33 -06002445 ds_pool_ci.count = 1;
2446 ds_pool_ci.pTypeCount = &ds_type_count;
2447
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06002448 VkDescriptorPool ds_pool;
2449 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002450 ASSERT_VK_SUCCESS(err);
2451
Tony Barboureb254902015-07-15 12:50:33 -06002452 VkDescriptorSetLayoutBinding dsl_binding = {};
2453 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2454 dsl_binding.arraySize = 1;
2455 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2456 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06002457
Tony Barboureb254902015-07-15 12:50:33 -06002458 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2459 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2460 ds_layout_ci.pNext = NULL;
2461 ds_layout_ci.count = 1;
2462 ds_layout_ci.pBinding = &dsl_binding;
2463
Tobin Ehlis502480b2015-06-24 15:53:07 -06002464 VkDescriptorSetLayout ds_layout;
2465 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2466 ASSERT_VK_SUCCESS(err);
2467
2468 VkDescriptorSet descriptorSet;
Cody Northrop1e4f8022015-08-03 12:47:29 -06002469 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002470 ASSERT_VK_SUCCESS(err);
2471
Tony Barboureb254902015-07-15 12:50:33 -06002472 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2473 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2474 pipe_ms_state_ci.pNext = NULL;
2475 pipe_ms_state_ci.rasterSamples = 1;
2476 pipe_ms_state_ci.sampleShadingEnable = 0;
2477 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrop02e61ed2015-08-04 14:34:54 -06002478 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06002479
Tony Barboureb254902015-07-15 12:50:33 -06002480 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2481 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2482 pipeline_layout_ci.pNext = NULL;
2483 pipeline_layout_ci.descriptorSetCount = 1;
2484 pipeline_layout_ci.pSetLayouts = &ds_layout;
2485 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06002486
Tobin Ehlis502480b2015-06-24 15:53:07 -06002487 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2488 ASSERT_VK_SUCCESS(err);
2489
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06002490 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour1c94d372015-08-06 11:21:08 -06002491 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2492 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06002493 VkPipelineObj pipe(m_device);
2494 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06002495 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06002496 pipe.SetMSAA(&pipe_ms_state_ci);
2497 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002498
2499 BeginCommandBuffer();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06002500 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06002501 // Don't care about actual data, just need to get to draw to flag error
2502 static const float vbo_data[3] = {1.f, 0.f, 1.f};
2503 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
2504 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
2505 Draw(0, 1, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002506
2507 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002508 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding Vtx Buffer w/o VBO attached to PSO.";
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06002509 if (!strstr(msgString.c_str(),"Vtx Buffer Index 1 was bound, but no vtx buffers are attached to PSO.")) {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002510 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
2511 }
2512}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002513#endif // DRAW_STATE_TESTS
2514
Tobin Ehlis0788f522015-05-26 16:11:58 -06002515#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06002516#if GTEST_IS_THREADSAFE
2517struct thread_data_struct {
2518 VkCmdBuffer cmdBuffer;
2519 VkEvent event;
2520 bool bailout;
2521};
2522
2523extern "C" void *AddToCommandBuffer(void *arg)
2524{
2525 struct thread_data_struct *data = (struct thread_data_struct *) arg;
2526 std::string msgString;
2527
2528 for (int i = 0; i<10000; i++) {
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002529 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyanaccf7692015-05-12 16:00:45 -06002530 if (data->bailout) {
2531 break;
2532 }
2533 }
2534 return NULL;
2535}
2536
2537TEST_F(VkLayerTest, ThreadCmdBufferCollision)
2538{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002539 VkFlags msgFlags;
Mike Stroyanaccf7692015-05-12 16:00:45 -06002540 std::string msgString;
Mike Stroyan4268d1f2015-07-13 14:45:35 -06002541 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06002542
2543 ASSERT_NO_FATAL_FAILURE(InitState());
2544 ASSERT_NO_FATAL_FAILURE(InitViewport());
2545 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2546
Mike Stroyanaccf7692015-05-12 16:00:45 -06002547 m_errorMonitor->ClearState();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002548 BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06002549
2550 VkEventCreateInfo event_info;
2551 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06002552 VkResult err;
2553
2554 memset(&event_info, 0, sizeof(event_info));
2555 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2556
2557 err = vkCreateEvent(device(), &event_info, &event);
2558 ASSERT_VK_SUCCESS(err);
2559
Mike Stroyanaccf7692015-05-12 16:00:45 -06002560 err = vkResetEvent(device(), event);
2561 ASSERT_VK_SUCCESS(err);
2562
2563 struct thread_data_struct data;
Tony Barbourfe3351b2015-07-28 10:17:20 -06002564 data.cmdBuffer = m_cmdBuffer->handle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06002565 data.event = event;
2566 data.bailout = false;
2567 m_errorMonitor->SetBailout(&data.bailout);
2568 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06002569 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06002570 // Add many entries to command buffer from this thread at the same time.
2571 AddToCommandBuffer(&data);
Mike Stroyan4268d1f2015-07-13 14:45:35 -06002572 test_platform_thread_join(thread, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002573 EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06002574
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002575 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northropd2ad0342015-08-05 11:15:02 -06002576 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err from using one VkCommandBufferObj in two threads";
Mike Stroyanaccf7692015-05-12 16:00:45 -06002577 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002578 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyanaccf7692015-05-12 16:00:45 -06002579 }
2580
2581}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002582#endif // GTEST_IS_THREADSAFE
2583#endif // THREADING_TESTS
2584
Chris Forbes9f7ff632015-05-25 11:13:08 +12002585#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06002586TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
2587{
2588 VkFlags msgFlags;
2589 std::string msgString;
2590 ASSERT_NO_FATAL_FAILURE(InitState());
2591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2592
2593 m_errorMonitor->ClearState();
2594
2595 VkShaderModule module;
2596 VkShaderModuleCreateInfo moduleCreateInfo;
2597 struct icd_spv_header spv;
2598
2599 spv.magic = ICD_SPV_MAGIC;
2600 spv.version = ICD_SPV_VERSION;
2601 spv.gen_magic = 0;
2602
2603 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2604 moduleCreateInfo.pNext = NULL;
2605 moduleCreateInfo.pCode = &spv;
2606 moduleCreateInfo.codeSize = 4;
2607 moduleCreateInfo.flags = 0;
2608 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
2609
2610 msgFlags = m_errorMonitor->GetState(&msgString);
2611
Chris Forbes46794b82015-09-18 11:40:23 +12002612 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06002613 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
2614 FAIL() << "Incorrect warning: " << msgString;
2615 }
2616}
2617
2618TEST_F(VkLayerTest, InvalidSPIRVMagic)
2619{
2620 VkFlags msgFlags;
2621 std::string msgString;
2622 ASSERT_NO_FATAL_FAILURE(InitState());
2623 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2624
2625 m_errorMonitor->ClearState();
2626
2627 VkShaderModule module;
2628 VkShaderModuleCreateInfo moduleCreateInfo;
2629 struct icd_spv_header spv;
2630
2631 spv.magic = ~ICD_SPV_MAGIC;
2632 spv.version = ICD_SPV_VERSION;
2633 spv.gen_magic = 0;
2634
2635 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2636 moduleCreateInfo.pNext = NULL;
2637 moduleCreateInfo.pCode = &spv;
2638 moduleCreateInfo.codeSize = sizeof(spv) + 10;
2639 moduleCreateInfo.flags = 0;
2640 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
2641
2642 msgFlags = m_errorMonitor->GetState(&msgString);
2643
Chris Forbes46794b82015-09-18 11:40:23 +12002644 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06002645 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
2646 FAIL() << "Incorrect warning: " << msgString;
2647 }
2648}
2649
2650TEST_F(VkLayerTest, InvalidSPIRVVersion)
2651{
2652 VkFlags msgFlags;
2653 std::string msgString;
2654 ASSERT_NO_FATAL_FAILURE(InitState());
2655 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2656
2657 m_errorMonitor->ClearState();
2658
2659 VkShaderModule module;
2660 VkShaderModuleCreateInfo moduleCreateInfo;
2661 struct icd_spv_header spv;
2662
2663 spv.magic = ICD_SPV_MAGIC;
2664 spv.version = ~ICD_SPV_VERSION;
2665 spv.gen_magic = 0;
2666
2667 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2668 moduleCreateInfo.pNext = NULL;
2669
2670 moduleCreateInfo.pCode = &spv;
2671 moduleCreateInfo.codeSize = sizeof(spv) + 10;
2672 moduleCreateInfo.flags = 0;
2673 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
2674
2675 msgFlags = m_errorMonitor->GetState(&msgString);
2676
Chris Forbes46794b82015-09-18 11:40:23 +12002677 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06002678 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
2679 FAIL() << "Incorrect warning: " << msgString;
2680 }
2681}
2682
Chris Forbes9f7ff632015-05-25 11:13:08 +12002683TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
2684{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002685 VkFlags msgFlags;
Chris Forbes9f7ff632015-05-25 11:13:08 +12002686 std::string msgString;
2687 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002688 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12002689
2690 char const *vsSource =
2691 "#version 140\n"
2692 "#extension GL_ARB_separate_shader_objects: require\n"
2693 "#extension GL_ARB_shading_language_420pack: require\n"
2694 "\n"
2695 "layout(location=0) out float x;\n"
2696 "void main(){\n"
2697 " gl_Position = vec4(1);\n"
2698 " x = 0;\n"
2699 "}\n";
2700 char const *fsSource =
2701 "#version 140\n"
2702 "#extension GL_ARB_separate_shader_objects: require\n"
2703 "#extension GL_ARB_shading_language_420pack: require\n"
2704 "\n"
2705 "layout(location=0) out vec4 color;\n"
2706 "void main(){\n"
2707 " color = vec4(1);\n"
2708 "}\n";
2709
2710 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2711 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2712
2713 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002714 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12002715 pipe.AddShader(&vs);
2716 pipe.AddShader(&fs);
2717
Chris Forbes9f7ff632015-05-25 11:13:08 +12002718 VkDescriptorSetObj descriptorSet(m_device);
2719 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002720 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12002721
2722 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06002723 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12002724
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002725 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes9f7ff632015-05-25 11:13:08 +12002726
Cody Northropd2ad0342015-08-05 11:15:02 -06002727 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes9f7ff632015-05-25 11:13:08 +12002728 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
2729 FAIL() << "Incorrect warning: " << msgString;
2730 }
2731}
Chris Forbes9f7ff632015-05-25 11:13:08 +12002732
Chris Forbes59cb88d2015-05-25 11:13:13 +12002733TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
2734{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002735 VkFlags msgFlags;
Chris Forbes59cb88d2015-05-25 11:13:13 +12002736 std::string msgString;
2737 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002738 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12002739
2740 char const *vsSource =
2741 "#version 140\n"
2742 "#extension GL_ARB_separate_shader_objects: require\n"
2743 "#extension GL_ARB_shading_language_420pack: require\n"
2744 "\n"
2745 "void main(){\n"
2746 " gl_Position = vec4(1);\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) in float x;\n"
2754 "layout(location=0) out vec4 color;\n"
2755 "void main(){\n"
2756 " color = vec4(x);\n"
2757 "}\n";
2758
2759 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2760 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2761
2762 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002763 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12002764 pipe.AddShader(&vs);
2765 pipe.AddShader(&fs);
2766
Chris Forbes59cb88d2015-05-25 11:13:13 +12002767 VkDescriptorSetObj descriptorSet(m_device);
2768 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002769 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12002770
2771 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06002772 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12002773
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002774 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes59cb88d2015-05-25 11:13:13 +12002775
Cody Northropd2ad0342015-08-05 11:15:02 -06002776 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes59cb88d2015-05-25 11:13:13 +12002777 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
2778 FAIL() << "Incorrect error: " << msgString;
2779 }
2780}
2781
Chris Forbesb56af562015-05-25 11:13:17 +12002782TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
2783{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002784 VkFlags msgFlags;
Chris Forbesb56af562015-05-25 11:13:17 +12002785 std::string msgString;
2786 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002787 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12002788
2789 char const *vsSource =
2790 "#version 140\n"
2791 "#extension GL_ARB_separate_shader_objects: require\n"
2792 "#extension GL_ARB_shading_language_420pack: require\n"
2793 "\n"
2794 "layout(location=0) out int x;\n"
2795 "void main(){\n"
2796 " x = 0;\n"
2797 " gl_Position = vec4(1);\n"
2798 "}\n";
2799 char const *fsSource =
2800 "#version 140\n"
2801 "#extension GL_ARB_separate_shader_objects: require\n"
2802 "#extension GL_ARB_shading_language_420pack: require\n"
2803 "\n"
2804 "layout(location=0) in float x;\n" /* VS writes int */
2805 "layout(location=0) out vec4 color;\n"
2806 "void main(){\n"
2807 " color = vec4(x);\n"
2808 "}\n";
2809
2810 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2811 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2812
2813 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002814 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12002815 pipe.AddShader(&vs);
2816 pipe.AddShader(&fs);
2817
Chris Forbesb56af562015-05-25 11:13:17 +12002818 VkDescriptorSetObj descriptorSet(m_device);
2819 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002820 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12002821
2822 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06002823 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12002824
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002825 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesb56af562015-05-25 11:13:17 +12002826
Cody Northropd2ad0342015-08-05 11:15:02 -06002827 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesb56af562015-05-25 11:13:17 +12002828 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
2829 FAIL() << "Incorrect error: " << msgString;
2830 }
2831}
2832
Chris Forbesde136e02015-05-25 11:13:28 +12002833TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
2834{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002835 VkFlags msgFlags;
Chris Forbesde136e02015-05-25 11:13:28 +12002836 std::string msgString;
2837 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002838 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12002839
2840 VkVertexInputBindingDescription input_binding;
2841 memset(&input_binding, 0, sizeof(input_binding));
2842
2843 VkVertexInputAttributeDescription input_attrib;
2844 memset(&input_attrib, 0, sizeof(input_attrib));
2845 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2846
2847 char const *vsSource =
2848 "#version 140\n"
2849 "#extension GL_ARB_separate_shader_objects: require\n"
2850 "#extension GL_ARB_shading_language_420pack: require\n"
2851 "\n"
2852 "void main(){\n"
2853 " gl_Position = vec4(1);\n"
2854 "}\n";
2855 char const *fsSource =
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 "layout(location=0) out vec4 color;\n"
2861 "void main(){\n"
2862 " color = vec4(1);\n"
2863 "}\n";
2864
2865 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2866 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2867
2868 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002869 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12002870 pipe.AddShader(&vs);
2871 pipe.AddShader(&fs);
2872
2873 pipe.AddVertexInputBindings(&input_binding, 1);
2874 pipe.AddVertexInputAttribs(&input_attrib, 1);
2875
Chris Forbesde136e02015-05-25 11:13:28 +12002876 VkDescriptorSetObj descriptorSet(m_device);
2877 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002878 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12002879
2880 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06002881 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12002882
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002883 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesde136e02015-05-25 11:13:28 +12002884
Cody Northropd2ad0342015-08-05 11:15:02 -06002885 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesde136e02015-05-25 11:13:28 +12002886 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
2887 FAIL() << "Incorrect warning: " << msgString;
2888 }
2889}
2890
Chris Forbes62e8e502015-05-25 11:13:29 +12002891TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
2892{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002893 VkFlags msgFlags;
Chris Forbes62e8e502015-05-25 11:13:29 +12002894 std::string msgString;
2895 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002896 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12002897
2898 char const *vsSource =
2899 "#version 140\n"
2900 "#extension GL_ARB_separate_shader_objects: require\n"
2901 "#extension GL_ARB_shading_language_420pack: require\n"
2902 "\n"
2903 "layout(location=0) in vec4 x;\n" /* not provided */
2904 "void main(){\n"
2905 " gl_Position = x;\n"
2906 "}\n";
2907 char const *fsSource =
2908 "#version 140\n"
2909 "#extension GL_ARB_separate_shader_objects: require\n"
2910 "#extension GL_ARB_shading_language_420pack: require\n"
2911 "\n"
2912 "layout(location=0) out vec4 color;\n"
2913 "void main(){\n"
2914 " color = vec4(1);\n"
2915 "}\n";
2916
2917 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2918 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2919
2920 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002921 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12002922 pipe.AddShader(&vs);
2923 pipe.AddShader(&fs);
2924
Chris Forbes62e8e502015-05-25 11:13:29 +12002925 VkDescriptorSetObj descriptorSet(m_device);
2926 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002927 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12002928
2929 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06002930 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12002931
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002932 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes62e8e502015-05-25 11:13:29 +12002933
Cody Northropd2ad0342015-08-05 11:15:02 -06002934 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes62e8e502015-05-25 11:13:29 +12002935 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
2936 FAIL() << "Incorrect warning: " << msgString;
2937 }
2938}
2939
Chris Forbesc97d98e2015-05-25 11:13:31 +12002940TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
2941{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002942 VkFlags msgFlags;
Chris Forbesc97d98e2015-05-25 11:13:31 +12002943 std::string msgString;
2944 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002945 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12002946
2947 VkVertexInputBindingDescription input_binding;
2948 memset(&input_binding, 0, sizeof(input_binding));
2949
2950 VkVertexInputAttributeDescription input_attrib;
2951 memset(&input_attrib, 0, sizeof(input_attrib));
2952 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2953
2954 char const *vsSource =
2955 "#version 140\n"
2956 "#extension GL_ARB_separate_shader_objects: require\n"
2957 "#extension GL_ARB_shading_language_420pack: require\n"
2958 "\n"
2959 "layout(location=0) in int x;\n" /* attrib provided float */
2960 "void main(){\n"
2961 " gl_Position = vec4(x);\n"
2962 "}\n";
2963 char const *fsSource =
2964 "#version 140\n"
2965 "#extension GL_ARB_separate_shader_objects: require\n"
2966 "#extension GL_ARB_shading_language_420pack: require\n"
2967 "\n"
2968 "layout(location=0) out vec4 color;\n"
2969 "void main(){\n"
2970 " color = vec4(1);\n"
2971 "}\n";
2972
2973 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2974 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2975
2976 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002977 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12002978 pipe.AddShader(&vs);
2979 pipe.AddShader(&fs);
2980
2981 pipe.AddVertexInputBindings(&input_binding, 1);
2982 pipe.AddVertexInputAttribs(&input_attrib, 1);
2983
Chris Forbesc97d98e2015-05-25 11:13:31 +12002984 VkDescriptorSetObj descriptorSet(m_device);
2985 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06002986 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12002987
2988 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06002989 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12002990
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002991 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc97d98e2015-05-25 11:13:31 +12002992
Cody Northropd2ad0342015-08-05 11:15:02 -06002993 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc97d98e2015-05-25 11:13:31 +12002994 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
2995 FAIL() << "Incorrect error: " << msgString;
2996 }
2997}
2998
Chris Forbes280ba2c2015-06-12 11:16:41 +12002999TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
3000{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003001 VkFlags msgFlags;
Chris Forbes280ba2c2015-06-12 11:16:41 +12003002 std::string msgString;
3003 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12003005
3006 /* Two binding descriptions for binding 0 */
3007 VkVertexInputBindingDescription input_bindings[2];
3008 memset(input_bindings, 0, sizeof(input_bindings));
3009
3010 VkVertexInputAttributeDescription input_attrib;
3011 memset(&input_attrib, 0, sizeof(input_attrib));
3012 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3013
3014 char const *vsSource =
3015 "#version 140\n"
3016 "#extension GL_ARB_separate_shader_objects: require\n"
3017 "#extension GL_ARB_shading_language_420pack: require\n"
3018 "\n"
3019 "layout(location=0) in float x;\n" /* attrib provided float */
3020 "void main(){\n"
3021 " gl_Position = vec4(x);\n"
3022 "}\n";
3023 char const *fsSource =
3024 "#version 140\n"
3025 "#extension GL_ARB_separate_shader_objects: require\n"
3026 "#extension GL_ARB_shading_language_420pack: require\n"
3027 "\n"
3028 "layout(location=0) out vec4 color;\n"
3029 "void main(){\n"
3030 " color = vec4(1);\n"
3031 "}\n";
3032
3033 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3034 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3035
3036 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003037 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12003038 pipe.AddShader(&vs);
3039 pipe.AddShader(&fs);
3040
3041 pipe.AddVertexInputBindings(input_bindings, 2);
3042 pipe.AddVertexInputAttribs(&input_attrib, 1);
3043
Chris Forbes280ba2c2015-06-12 11:16:41 +12003044 VkDescriptorSetObj descriptorSet(m_device);
3045 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003046 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12003047
3048 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003049 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12003050
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003051 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes280ba2c2015-06-12 11:16:41 +12003052
Cody Northropd2ad0342015-08-05 11:15:02 -06003053 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes280ba2c2015-06-12 11:16:41 +12003054 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
3055 FAIL() << "Incorrect error: " << msgString;
3056 }
3057}
Chris Forbes8f68b562015-05-25 11:13:32 +12003058
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003059/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
3060 * rejects it. */
3061
3062TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
3063{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003064 VkFlags msgFlags;
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003065 std::string msgString;
3066 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003067
3068 char const *vsSource =
3069 "#version 140\n"
3070 "#extension GL_ARB_separate_shader_objects: require\n"
3071 "#extension GL_ARB_shading_language_420pack: require\n"
3072 "\n"
3073 "void main(){\n"
3074 " gl_Position = vec4(1);\n"
3075 "}\n";
3076 char const *fsSource =
3077 "#version 140\n"
3078 "#extension GL_ARB_separate_shader_objects: require\n"
3079 "#extension GL_ARB_shading_language_420pack: require\n"
3080 "\n"
3081 "void main(){\n"
3082 "}\n";
3083
3084 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3085 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3086
3087 VkPipelineObj pipe(m_device);
3088 pipe.AddShader(&vs);
3089 pipe.AddShader(&fs);
3090
Chia-I Wu08accc62015-07-07 11:50:03 +08003091 /* set up CB 0, not written */
3092 pipe.AddColorAttachment();
3093 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003094
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003095 VkDescriptorSetObj descriptorSet(m_device);
3096 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003097 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003098
3099 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003100 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003101
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003102 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003103
Cody Northropd2ad0342015-08-05 11:15:02 -06003104 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes4d6d1e52015-05-25 11:13:40 +12003105 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
3106 FAIL() << "Incorrect error: " << msgString;
3107 }
3108}
3109
Chris Forbesf3fffaa2015-05-25 11:13:43 +12003110TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
3111{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003112 VkFlags msgFlags;
Chris Forbesf3fffaa2015-05-25 11:13:43 +12003113 std::string msgString;
3114 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12003115
3116 char const *vsSource =
3117 "#version 140\n"
3118 "#extension GL_ARB_separate_shader_objects: require\n"
3119 "#extension GL_ARB_shading_language_420pack: require\n"
3120 "\n"
3121 "void main(){\n"
3122 " gl_Position = vec4(1);\n"
3123 "}\n";
3124 char const *fsSource =
3125 "#version 140\n"
3126 "#extension GL_ARB_separate_shader_objects: require\n"
3127 "#extension GL_ARB_shading_language_420pack: require\n"
3128 "\n"
3129 "layout(location=0) out vec4 x;\n"
3130 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
3131 "void main(){\n"
3132 " x = vec4(1);\n"
3133 " y = vec4(1);\n"
3134 "}\n";
3135
3136 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3137 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3138
3139 VkPipelineObj pipe(m_device);
3140 pipe.AddShader(&vs);
3141 pipe.AddShader(&fs);
3142
Chia-I Wu08accc62015-07-07 11:50:03 +08003143 /* set up CB 0, not written */
3144 pipe.AddColorAttachment();
3145 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12003146 /* FS writes CB 1, but we don't configure it */
3147
Chris Forbesf3fffaa2015-05-25 11:13:43 +12003148 VkDescriptorSetObj descriptorSet(m_device);
3149 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003150 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12003151
3152 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003153 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12003154
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003155 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12003156
Cody Northropd2ad0342015-08-05 11:15:02 -06003157 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12003158 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
3159 FAIL() << "Incorrect warning: " << msgString;
3160 }
3161}
3162
Chris Forbesa36d69e2015-05-25 11:13:44 +12003163TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
3164{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003165 VkFlags msgFlags;
Chris Forbesa36d69e2015-05-25 11:13:44 +12003166 std::string msgString;
3167 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12003168
3169 char const *vsSource =
3170 "#version 140\n"
3171 "#extension GL_ARB_separate_shader_objects: require\n"
3172 "#extension GL_ARB_shading_language_420pack: require\n"
3173 "\n"
3174 "void main(){\n"
3175 " gl_Position = vec4(1);\n"
3176 "}\n";
3177 char const *fsSource =
3178 "#version 140\n"
3179 "#extension GL_ARB_separate_shader_objects: require\n"
3180 "#extension GL_ARB_shading_language_420pack: require\n"
3181 "\n"
3182 "layout(location=0) out ivec4 x;\n" /* not UNORM */
3183 "void main(){\n"
3184 " x = ivec4(1);\n"
3185 "}\n";
3186
3187 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3188 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3189
3190 VkPipelineObj pipe(m_device);
3191 pipe.AddShader(&vs);
3192 pipe.AddShader(&fs);
3193
Chia-I Wu08accc62015-07-07 11:50:03 +08003194 /* set up CB 0; type is UNORM by default */
3195 pipe.AddColorAttachment();
3196 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12003197
Chris Forbesa36d69e2015-05-25 11:13:44 +12003198 VkDescriptorSetObj descriptorSet(m_device);
3199 descriptorSet.AppendDummy();
Tony Barbourfe3351b2015-07-28 10:17:20 -06003200 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12003201
3202 m_errorMonitor->ClearState();
Tony Barbour5781e8f2015-08-04 16:23:11 -06003203 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12003204
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003205 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa36d69e2015-05-25 11:13:44 +12003206
Cody Northropd2ad0342015-08-05 11:15:02 -06003207 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa36d69e2015-05-25 11:13:44 +12003208 if (!strstr(msgString.c_str(),"does not match FS output type")) {
3209 FAIL() << "Incorrect error: " << msgString;
3210 }
3211}
Chris Forbes7b1b8932015-06-05 14:43:36 +12003212
Chris Forbes556c76c2015-08-14 12:04:59 +12003213TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
3214{
3215 VkFlags msgFlags;
3216 std::string msgString;
3217 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12003218
3219 char const *vsSource =
3220 "#version 140\n"
3221 "#extension GL_ARB_separate_shader_objects: require\n"
3222 "#extension GL_ARB_shading_language_420pack: require\n"
3223 "\n"
3224 "void main(){\n"
3225 " gl_Position = vec4(1);\n"
3226 "}\n";
3227 char const *fsSource =
3228 "#version 140\n"
3229 "#extension GL_ARB_separate_shader_objects: require\n"
3230 "#extension GL_ARB_shading_language_420pack: require\n"
3231 "\n"
3232 "layout(location=0) out vec4 x;\n"
3233 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
3234 "void main(){\n"
3235 " x = vec4(bar.y);\n"
3236 "}\n";
3237
3238 m_errorMonitor->ClearState();
3239
3240 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3241 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3242
3243
3244 VkPipelineObj pipe(m_device);
3245 pipe.AddShader(&vs);
3246 pipe.AddShader(&fs);
3247
3248 /* set up CB 0; type is UNORM by default */
3249 pipe.AddColorAttachment();
3250 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3251
3252 VkDescriptorSetObj descriptorSet(m_device);
3253 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
3254
3255 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3256
3257 /* should have generated an error -- pipeline layout does not
3258 * provide a uniform buffer in 0.0
3259 */
3260 msgFlags = m_errorMonitor->GetState(&msgString);
3261 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
3262 if (!strstr(msgString.c_str(),"not declared in pipeline layout")) {
3263 FAIL() << "Incorrect error: " << msgString;
3264 }
3265}
3266
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003267#endif // SHADER_CHECKER_TESTS
3268
3269#if DEVICE_LIMITS_TESTS
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06003270TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
3271{
3272 VkFlags msgFlags;
3273 std::string msgString;
3274
3275 ASSERT_NO_FATAL_FAILURE(InitState());
3276 m_errorMonitor->ClearState();
3277
3278 // Create an image
3279 VkImage image;
3280
3281 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3282 const int32_t tex_width = 32;
3283 const int32_t tex_height = 32;
3284
3285 VkImageCreateInfo image_create_info = {};
3286 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3287 image_create_info.pNext = NULL;
3288 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3289 image_create_info.format = tex_format;
3290 image_create_info.extent.width = tex_width;
3291 image_create_info.extent.height = tex_height;
3292 image_create_info.extent.depth = 1;
3293 image_create_info.mipLevels = 1;
3294 image_create_info.arraySize = 1;
3295 image_create_info.samples = 1;
3296 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3297 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3298 image_create_info.flags = 0;
3299
3300 // Introduce error by sending down a bogus width extent
3301 image_create_info.extent.width = 65536;
3302 vkCreateImage(m_device->device(), &image_create_info, &image);
3303
3304 msgFlags = m_errorMonitor->GetState(&msgString);
3305 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
3306 "with extents outside the queried limits";
3307 if (!strstr(msgString.c_str(),"CreateImage extents exceed allowable limits for format")) {
3308 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
3309 }
3310}
3311
3312TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
3313{
3314 VkFlags msgFlags;
3315 std::string msgString;
3316
3317 ASSERT_NO_FATAL_FAILURE(InitState());
3318 m_errorMonitor->ClearState();
3319
3320 // Create an image
3321 VkImage image;
3322
3323 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3324 const int32_t tex_width = 32;
3325 const int32_t tex_height = 32;
3326
3327 VkImageCreateInfo image_create_info = {};
3328 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3329 image_create_info.pNext = NULL;
3330 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3331 image_create_info.format = tex_format;
3332 image_create_info.extent.width = tex_width;
3333 image_create_info.extent.height = tex_height;
3334 image_create_info.extent.depth = 1;
3335 image_create_info.mipLevels = 1;
3336 image_create_info.arraySize = 1;
3337 image_create_info.samples = 1;
3338 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3339 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3340 image_create_info.flags = 0;
3341
3342 // Introduce error by sending down individually allowable values that result in a surface size
3343 // exceeding the device maximum
3344 image_create_info.extent.width = 8192;
3345 image_create_info.extent.height = 8192;
3346 image_create_info.extent.depth = 16;
3347 image_create_info.arraySize = 4;
3348 image_create_info.samples = 2;
3349 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
3350 vkCreateImage(m_device->device(), &image_create_info, &image);
3351
3352 msgFlags = m_errorMonitor->GetState(&msgString);
3353 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
3354 "with resource size exceeding queried limit";
3355 if (!strstr(msgString.c_str(),"CreateImage resource size exceeds allowable maximum")) {
3356 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
3357 }
3358}
3359
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003360#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12003361
Tony Barbour300a6082015-04-07 13:44:53 -06003362int main(int argc, char **argv) {
3363 int result;
3364
3365 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06003366 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -06003367
3368 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
3369
3370 result = RUN_ALL_TESTS();
3371
Tony Barbour6918cd52015-04-09 12:58:51 -06003372 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -06003373 return result;
3374}