blob: 10a826b5f120d4f8af6016d11b7b82246053c294 [file] [log] [blame]
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001#include <vulkan.h>
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002#include "vk_debug_report_lunarg.h"
Tony Barbour30486ea2015-04-07 13:44:53 -06003#include "gtest-1.7.0/include/gtest/gtest.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06004#include "vkrenderframework.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -06005#include "vk_layer_config.h"
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06006#include "../icd/common/icd-spv.h"
Tony Barbour30486ea2015-04-07 13:44:53 -06007
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05008#define GLM_FORCE_RADIANS
9#include "glm/glm.hpp"
10#include <glm/gtc/matrix_transform.hpp>
11
Tobin Ehlis57e6a612015-05-26 16:11:58 -060012#define MEM_TRACKER_TESTS 1
13#define OBJ_TRACKER_TESTS 1
14#define DRAW_STATE_TESTS 1
15#define THREADING_TESTS 1
Chris Forbes5af3bf22015-05-25 11:13:08 +120016#define SHADER_CHECKER_TESTS 1
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -060017#define DEVICE_LIMITS_TESTS 1
Tobin Ehlis342b9bf2015-09-22 10:11:37 -060018#define IMAGE_TESTS 1
Tobin Ehlis57e6a612015-05-26 16:11:58 -060019
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050020//--------------------------------------------------------------------------------------
21// Mesh and VertexFormat Data
22//--------------------------------------------------------------------------------------
23struct Vertex
24{
25 float posX, posY, posZ, posW; // Position data
26 float r, g, b, a; // Color
27};
28
29#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
30
31typedef enum _BsoFailSelect {
32 BsoFailNone = 0x00000000,
Cody Northrope4bc6942015-08-26 10:01:32 -060033 BsoFailLineWidth = 0x00000001,
34 BsoFailDepthBias = 0x00000002,
Cody Northropf5bd2252015-08-17 11:10:49 -060035 BsoFailViewport = 0x00000004,
Tobin Ehlisf6cb4672015-09-29 08:18:34 -060036 BsoFailScissor = 0x00000008,
37 BsoFailBlend = 0x00000010,
38 BsoFailDepthBounds = 0x00000020,
39 BsoFailStencilReadMask = 0x00000040,
40 BsoFailStencilWriteMask = 0x00000080,
41 BsoFailStencilReference = 0x00000100,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050042} BsoFailSelect;
43
44struct vktriangle_vs_uniform {
45 // Must start with MVP
46 float mvp[4][4];
47 float position[3][4];
48 float color[3][4];
49};
50
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050051static const char bindStateVertShaderText[] =
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050052 "#version 130\n"
53 "vec2 vertices[3];\n"
54 "void main() {\n"
55 " vertices[0] = vec2(-1.0, -1.0);\n"
56 " vertices[1] = vec2( 1.0, -1.0);\n"
57 " vertices[2] = vec2( 0.0, 1.0);\n"
58 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
59 "}\n";
60
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050061static const char bindStateFragShaderText[] =
Cody Northrop74a2d2c2015-06-16 17:32:04 -060062 "#version 140\n"
63 "#extension GL_ARB_separate_shader_objects: require\n"
64 "#extension GL_ARB_shading_language_420pack: require\n"
65 "\n"
66 "layout(location = 0) out vec4 uFragColor;\n"
67 "void main(){\n"
68 " uFragColor = vec4(0,1,0,1);\n"
69 "}\n";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050070
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -060071static VkBool32 myDbgFunc(
Tony Barboure84a8d62015-07-10 14:10:27 -060072 VkFlags msgFlags,
73 VkDbgObjectType objType,
74 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060075 size_t location,
76 int32_t msgCode,
77 const char* pLayerPrefix,
78 const char* pMsg,
79 void* pUserData);
Tony Barbour30486ea2015-04-07 13:44:53 -060080
81class ErrorMonitor {
82public:
Tony Barbour0c1bdc62015-04-29 17:34:29 -060083 ErrorMonitor()
Tony Barbour30486ea2015-04-07 13:44:53 -060084 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060085 test_platform_thread_create_mutex(&m_mutex);
86 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060087 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mike Stroyan09aae812015-05-12 16:00:45 -060088 m_bailout = NULL;
Mike Stroyan7016f4f2015-07-13 14:45:35 -060089 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060090 }
91 void ClearState()
92 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060093 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060094 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -060095 m_msgString.clear();
Mike Stroyan7016f4f2015-07-13 14:45:35 -060096 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060097 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060098 VkFlags GetState(std::string *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -060099 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600100 test_platform_thread_lock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -0600101 *msgString = m_msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600102 test_platform_thread_unlock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600103 return m_msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600104 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600105 void SetState(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -0600106 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600107 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600108 if (m_bailout != NULL) {
109 *m_bailout = true;
110 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600111 m_msgFlags = msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600112 m_msgString.reserve(strlen(msgString));
113 m_msgString = msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600114 test_platform_thread_unlock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600115 }
116 void SetBailout(bool *bailout)
117 {
118 m_bailout = bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600119 }
120
121private:
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600122 VkFlags m_msgFlags;
123 std::string m_msgString;
124 test_platform_thread_mutex m_mutex;
125 bool* m_bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600126};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500127
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600128static VkBool32 myDbgFunc(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600129 VkFlags msgFlags,
Tony Barboure84a8d62015-07-10 14:10:27 -0600130 VkDbgObjectType objType,
131 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600132 size_t location,
133 int32_t msgCode,
134 const char* pLayerPrefix,
135 const char* pMsg,
136 void* pUserData)
Tony Barbour30486ea2015-04-07 13:44:53 -0600137{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600138 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour8508b8e2015-04-09 10:48:04 -0600139 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600140 errMonitor->SetState(msgFlags, pMsg);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600141 return true;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600142 }
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600143
144 return false;
Tony Barbour30486ea2015-04-07 13:44:53 -0600145}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500146
Tony Barbour01999182015-04-09 12:58:51 -0600147class VkLayerTest : public VkRenderFramework
Tony Barbour30486ea2015-04-07 13:44:53 -0600148{
149public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600150 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
151 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500152 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
153 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbour1490c912015-07-28 10:17:20 -0600154 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
155 { GenericDrawPreparation(m_cmdBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600156
Tony Barbour1490c912015-07-28 10:17:20 -0600157 /* Convenience functions that use built-in command buffer */
158 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_cmdBuffer); }
159 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_cmdBuffer); }
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600160 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
161 { m_cmdBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance); }
162 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
163 { m_cmdBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); }
Tony Barbour1490c912015-07-28 10:17:20 -0600164 void QueueCommandBuffer() { m_cmdBuffer->QueueCommandBuffer(); }
165 void QueueCommandBuffer(const VkFence& fence) { m_cmdBuffer->QueueCommandBuffer(fence); }
166 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
167 { m_cmdBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
168 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
169 { m_cmdBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600170protected:
Tony Barbour01999182015-04-09 12:58:51 -0600171 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600172
173 virtual void SetUp() {
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600174 std::vector<const char *> instance_layer_names;
175 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600176 std::vector<const char *> instance_extension_names;
177 std::vector<const char *> device_extension_names;
Tony Barbour950ebc02015-04-23 12:55:36 -0600178
Courtney Goeltzenleuchter846298c2015-07-30 11:32:46 -0600179 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600180 /*
181 * Since CreateDbgMsgCallback is an instance level extension call
182 * any extension / layer that utilizes that feature also needs
183 * to be enabled at create instance time.
184 */
Mike Stroyan2237f522015-08-18 14:40:24 -0600185 // Use Threading layer first to protect others from ThreadCmdBufferCollision test
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600186 instance_layer_names.push_back("Threading");
187 instance_layer_names.push_back("ObjectTracker");
188 instance_layer_names.push_back("MemTracker");
189 instance_layer_names.push_back("DrawState");
190 instance_layer_names.push_back("ShaderChecker");
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600191 instance_layer_names.push_back("DeviceLimits");
Tobin Ehlis342b9bf2015-09-22 10:11:37 -0600192 instance_layer_names.push_back("Image");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600193
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600194 device_layer_names.push_back("Threading");
195 device_layer_names.push_back("ObjectTracker");
196 device_layer_names.push_back("MemTracker");
197 device_layer_names.push_back("DrawState");
198 device_layer_names.push_back("ShaderChecker");
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600199 device_layer_names.push_back("DeviceLimits");
Tobin Ehlis342b9bf2015-09-22 10:11:37 -0600200 device_layer_names.push_back("Image");
Tony Barbour30486ea2015-04-07 13:44:53 -0600201
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600202 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -0600203 this->app_info.pNext = NULL;
204 this->app_info.pAppName = "layer_tests";
205 this->app_info.appVersion = 1;
206 this->app_info.pEngineName = "unittest";
207 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600208 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -0600209
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600210 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600211 InitFramework(instance_layer_names, device_layer_names,
212 instance_extension_names, device_extension_names,
213 myDbgFunc, m_errorMonitor);
Tony Barbour30486ea2015-04-07 13:44:53 -0600214 }
215
216 virtual void TearDown() {
217 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600218 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600219 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600220 }
221};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500222
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600223VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600224{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600225 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600226
227 result = cmdBuffer.BeginCommandBuffer();
228
229 /*
230 * For render test all drawing happens in a single render pass
231 * on a single command buffer.
232 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200233 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wuc278df82015-07-07 11:50:03 +0800234 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour30486ea2015-04-07 13:44:53 -0600235 }
236
237 return result;
238}
239
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600240VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600241{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600242 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600243
Chris Forbesfe133ef2015-06-16 14:05:59 +1200244 if (renderPass()) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800245 cmdBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200246 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600247
248 result = cmdBuffer.EndCommandBuffer();
249
250 return result;
251}
252
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500253void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
254{
255 // Create identity matrix
256 int i;
257 struct vktriangle_vs_uniform data;
258
259 glm::mat4 Projection = glm::mat4(1.0f);
260 glm::mat4 View = glm::mat4(1.0f);
261 glm::mat4 Model = glm::mat4(1.0f);
262 glm::mat4 MVP = Projection * View * Model;
263 const int matrixSize = sizeof(MVP);
264 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
265
266 memcpy(&data.mvp, &MVP[0][0], matrixSize);
267
268 static const Vertex tri_data[] =
269 {
270 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
271 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
272 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
273 };
274
275 for (i=0; i<3; i++) {
276 data.position[i][0] = tri_data[i].posX;
277 data.position[i][1] = tri_data[i].posY;
278 data.position[i][2] = tri_data[i].posZ;
279 data.position[i][3] = tri_data[i].posW;
280 data.color[i][0] = tri_data[i].r;
281 data.color[i][1] = tri_data[i].g;
282 data.color[i][2] = tri_data[i].b;
283 data.color[i][3] = tri_data[i].a;
284 }
285
286 ASSERT_NO_FATAL_FAILURE(InitState());
287 ASSERT_NO_FATAL_FAILURE(InitViewport());
288
289 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
290
291 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
292 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
293
294 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800295 pipelineobj.AddColorAttachment();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500296 pipelineobj.AddShader(&vs);
297 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600298 if (failMask & BsoFailLineWidth) {
299 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
300 }
301 if (failMask & BsoFailDepthBias) {
302 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
303 }
304 if (failMask & BsoFailViewport) {
305 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
306 }
307 if (failMask & BsoFailScissor) {
308 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
309 }
310 if (failMask & BsoFailBlend) {
311 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
312 }
313 if (failMask & BsoFailDepthBounds) {
314 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
315 }
316 if (failMask & BsoFailStencilReadMask) {
317 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
318 }
319 if (failMask & BsoFailStencilWriteMask) {
320 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
321 }
322 if (failMask & BsoFailStencilReference) {
323 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
324 }
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500325
326 VkDescriptorSetObj descriptorSet(m_device);
327 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
328
329 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600330 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500331
Tony Barbour1490c912015-07-28 10:17:20 -0600332 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500333
334 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600335 Draw(3, 1, 0, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500336
337 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600338 EndCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500339
Tony Barbour1490c912015-07-28 10:17:20 -0600340 QueueCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500341}
342
343void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
344{
345 if (m_depthStencil->Initialized()) {
346 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
347 } else {
348 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
349 }
350
351 cmdBuffer->PrepareAttachments();
Cody Northrop2605cb02015-08-18 15:21:16 -0600352 // Make sure depthWriteEnable is set so that Depth fail test will work correctly
353 // Make sure stencilTestEnable is set so that Stencil fail test will work correctly
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600354 VkStencilOpState stencil = {};
355 stencil.stencilFailOp = VK_STENCIL_OP_KEEP;
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600356 stencil.stencilPassOp = VK_STENCIL_OP_KEEP;
357 stencil.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
358 stencil.stencilCompareOp = VK_COMPARE_OP_NEVER;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600359
360 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
361 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600362 ds_ci.pNext = NULL;
363 ds_ci.depthTestEnable = VK_FALSE;
364 ds_ci.depthWriteEnable = VK_TRUE;
365 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
366 ds_ci.depthBoundsTestEnable = VK_FALSE;
367 ds_ci.stencilTestEnable = VK_TRUE;
368 ds_ci.front = stencil;
369 ds_ci.back = stencil;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600370
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600371 pipelineobj.SetDepthStencil(&ds_ci);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500372 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Cody Northropccfa96d2015-08-27 10:20:35 -0600373 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
374 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500375 cmdBuffer->BindPipeline(pipelineobj);
376 cmdBuffer->BindDescriptorSet(descriptorSet);
377}
378
379// ********************************************************************************************************************
380// ********************************************************************************************************************
381// ********************************************************************************************************************
382// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600383#if MEM_TRACKER_TESTS
Mark Lobodzinski81078192015-05-19 10:28:29 -0500384TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
385{
386 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600387 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500388 std::string msgString;
389
390 VkFenceCreateInfo fenceInfo = {};
391 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
392 fenceInfo.pNext = NULL;
393 fenceInfo.flags = 0;
394
395 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barboure389b882015-07-20 13:00:10 -0600396
397 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
398 vk_testing::Buffer buffer;
399 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500400
Tony Barbour1490c912015-07-28 10:17:20 -0600401 BeginCommandBuffer();
402 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
403 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500404
405 testFence.init(*m_device, fenceInfo);
406
407 // Bypass framework since it does the waits automatically
408 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600409 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500410 ASSERT_VK_SUCCESS( err );
411
412 m_errorMonitor->ClearState();
413 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600414 vkResetCommandBuffer(m_cmdBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500415
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600416 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600417 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling ResetCommandBuffer on an active Command Buffer";
Mark Lobodzinski81078192015-05-19 10:28:29 -0500418 if (!strstr(msgString.c_str(),"Resetting CB")) {
419 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
420 }
421}
422
423TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion)
424{
425 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600426 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500427 std::string msgString;
428
429 VkFenceCreateInfo fenceInfo = {};
430 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
431 fenceInfo.pNext = NULL;
432 fenceInfo.flags = 0;
433
434 ASSERT_NO_FATAL_FAILURE(InitState());
435 ASSERT_NO_FATAL_FAILURE(InitViewport());
436 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
437
Tony Barbour1490c912015-07-28 10:17:20 -0600438 BeginCommandBuffer();
439 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
440 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500441
442 testFence.init(*m_device, fenceInfo);
443
444 // Bypass framework since it does the waits automatically
445 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600446 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500447 ASSERT_VK_SUCCESS( err );
448
449 m_errorMonitor->ClearState();
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600450
451 VkCmdBufferBeginInfo info = {};
452 info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT | VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
453 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
454 info.renderPass = VK_NULL_HANDLE;
455 info.subpass = 0;
456 info.framebuffer = VK_NULL_HANDLE;
457
458 // Introduce failure by calling BCB again before checking fence
459 vkBeginCommandBuffer(m_cmdBuffer->handle(), &info);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500460
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600461 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600462 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling BeginCommandBuffer on an active Command Buffer";
Mark Lobodzinski81078192015-05-19 10:28:29 -0500463 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
464 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
465 }
466}
467
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500468TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
469{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600470 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500471 std::string msgString;
472 VkResult err;
473
474 ASSERT_NO_FATAL_FAILURE(InitState());
475 m_errorMonitor->ClearState();
476
477 // Create an image, allocate memory, free it, and then try to bind it
478 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500479 VkDeviceMemory mem;
480 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500481
482 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
483 const int32_t tex_width = 32;
484 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500485
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600486 VkImageCreateInfo image_create_info = {};
487 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
488 image_create_info.pNext = NULL;
489 image_create_info.imageType = VK_IMAGE_TYPE_2D;
490 image_create_info.format = tex_format;
491 image_create_info.extent.width = tex_width;
492 image_create_info.extent.height = tex_height;
493 image_create_info.extent.depth = 1;
494 image_create_info.mipLevels = 1;
495 image_create_info.arraySize = 1;
496 image_create_info.samples = 1;
497 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
498 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
499 image_create_info.flags = 0;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600500
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600501 VkMemoryAllocInfo mem_alloc = {};
502 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
503 mem_alloc.pNext = NULL;
504 mem_alloc.allocationSize = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500505 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600506 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500507
508 err = vkCreateImage(m_device->device(), &image_create_info, &image);
509 ASSERT_VK_SUCCESS(err);
510
Tony Barboure84a8d62015-07-10 14:10:27 -0600511 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500512 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500513 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500514 ASSERT_VK_SUCCESS(err);
515
Mark Lobodzinski23182612015-05-29 09:32:35 -0500516 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500517
Mike Stroyan2237f522015-08-18 14:40:24 -0600518 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
519 if(err != VK_SUCCESS) { // If we can't find any unmappable memory this test doesn't make sense
520 vkDestroyImage(m_device->device(), image);
Tony Barbour49a3b652015-08-04 16:13:01 -0600521 return;
Mike Stroyan2237f522015-08-18 14:40:24 -0600522 }
Mike Stroyand72da752015-08-04 10:49:29 -0600523
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500524 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500525 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500526 ASSERT_VK_SUCCESS(err);
527
528 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600529 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500530 ASSERT_VK_SUCCESS(err);
531
532 // Map memory as if to initialize the image
533 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500534 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500535
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600536 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600537 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to map memory not visible to CPU";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500538 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
539 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
540 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600541
542 vkDestroyImage(m_device->device(), image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500543}
544
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600545// TODO : Is this test still valid. Not sure it is with updates to memory binding model
546// Verify and delete the test of fix the check
547//TEST_F(VkLayerTest, FreeBoundMemory)
548//{
549// VkFlags msgFlags;
550// std::string msgString;
551// VkResult err;
552//
553// ASSERT_NO_FATAL_FAILURE(InitState());
554// m_errorMonitor->ClearState();
555//
556// // Create an image, allocate memory, free it, and then try to bind it
557// VkImage image;
558// VkDeviceMemory mem;
559// VkMemoryRequirements mem_reqs;
560//
561// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
562// const int32_t tex_width = 32;
563// const int32_t tex_height = 32;
564//
565// const VkImageCreateInfo image_create_info = {
566// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
567// .pNext = NULL,
568// .imageType = VK_IMAGE_TYPE_2D,
569// .format = tex_format,
570// .extent = { tex_width, tex_height, 1 },
571// .mipLevels = 1,
572// .arraySize = 1,
573// .samples = 1,
574// .tiling = VK_IMAGE_TILING_LINEAR,
575// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
576// .flags = 0,
577// };
578// VkMemoryAllocInfo mem_alloc = {
579// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
580// .pNext = NULL,
581// .allocationSize = 0,
582// .memoryTypeIndex = 0,
583// };
584//
585// err = vkCreateImage(m_device->device(), &image_create_info, &image);
586// ASSERT_VK_SUCCESS(err);
587//
588// err = vkGetImageMemoryRequirements(m_device->device(),
589// image,
590// &mem_reqs);
591// ASSERT_VK_SUCCESS(err);
592//
593// mem_alloc.allocationSize = mem_reqs.size;
594//
595// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
596// ASSERT_VK_SUCCESS(err);
597//
598// // allocate memory
599// err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
600// ASSERT_VK_SUCCESS(err);
601//
602// // Bind memory to Image object
603// err = vkBindImageMemory(m_device->device(), image, mem, 0);
604// ASSERT_VK_SUCCESS(err);
605//
606// // Introduce validation failure, free memory while still bound to object
607// vkFreeMemory(m_device->device(), mem);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600608// msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600609//
Cody Northrop1684adb2015-08-05 11:15:02 -0600610// ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an warning while tring to free bound memory";
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600611// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
612// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
613// }
614//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500615
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500616TEST_F(VkLayerTest, RebindMemory)
617{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600618 VkFlags msgFlags;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500619 std::string msgString;
620 VkResult err;
621
622 ASSERT_NO_FATAL_FAILURE(InitState());
623 m_errorMonitor->ClearState();
624
625 // Create an image, allocate memory, free it, and then try to bind it
626 VkImage image;
627 VkDeviceMemory mem1;
628 VkDeviceMemory mem2;
629 VkMemoryRequirements mem_reqs;
630
631 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
632 const int32_t tex_width = 32;
633 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500634
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600635 VkImageCreateInfo image_create_info = {};
636 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
637 image_create_info.pNext = NULL;
638 image_create_info.imageType = VK_IMAGE_TYPE_2D;
639 image_create_info.format = tex_format;
640 image_create_info.extent.width = tex_width;
641 image_create_info.extent.height = tex_height;
642 image_create_info.extent.depth = 1;
643 image_create_info.mipLevels = 1;
644 image_create_info.arraySize = 1;
645 image_create_info.samples = 1;
646 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
647 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
648 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500649
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600650 VkMemoryAllocInfo mem_alloc = {};
651 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
652 mem_alloc.pNext = NULL;
653 mem_alloc.allocationSize = 0;
654 mem_alloc.memoryTypeIndex = 0;
655
656 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
657 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500658 err = vkCreateImage(m_device->device(), &image_create_info, &image);
659 ASSERT_VK_SUCCESS(err);
660
Tony Barboure84a8d62015-07-10 14:10:27 -0600661 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500662 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500663 &mem_reqs);
664 ASSERT_VK_SUCCESS(err);
665
666 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800667 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600668 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500669
670 // allocate 2 memory objects
671 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
672 ASSERT_VK_SUCCESS(err);
673 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
674 ASSERT_VK_SUCCESS(err);
675
676 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600677 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500678 ASSERT_VK_SUCCESS(err);
679
680 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600681 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500682
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600683 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600684 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to rebind an object";
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500685 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
686 FAIL() << "Error received did not match expected message when rebinding memory to an object";
687 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600688
689 vkDestroyImage(m_device->device(), image);
690 vkFreeMemory(m_device->device(), mem1);
691 vkFreeMemory(m_device->device(), mem2);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500692}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500693
Tony Barbour8508b8e2015-04-09 10:48:04 -0600694TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600695{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600696 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600697 VkFlags msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600698 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600699
700 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600701 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
702 fenceInfo.pNext = NULL;
703 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600704
Tony Barbour30486ea2015-04-07 13:44:53 -0600705 ASSERT_NO_FATAL_FAILURE(InitState());
706 ASSERT_NO_FATAL_FAILURE(InitViewport());
707 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
708
Tony Barbour1490c912015-07-28 10:17:20 -0600709 BeginCommandBuffer();
710 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
711 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600712
713 testFence.init(*m_device, fenceInfo);
714 m_errorMonitor->ClearState();
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600715
716 vkQueueSubmit(m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
717 vkQueueWaitIdle(m_device->m_queue );
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600718 msgFlags = m_errorMonitor->GetState(&msgString);
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600719
Cody Northrop1684adb2015-08-05 11:15:02 -0600720 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err from using a fence in SIGNALED state in call to vkQueueSubmit";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600721 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500722 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600723 }
724
725}
726
727TEST_F(VkLayerTest, ResetUnsignaledFence)
728{
729 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600730 VkFlags msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600731 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600732 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600733 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
734 fenceInfo.pNext = NULL;
735
Tony Barbour8508b8e2015-04-09 10:48:04 -0600736 ASSERT_NO_FATAL_FAILURE(InitState());
737 testFence.init(*m_device, fenceInfo);
738 m_errorMonitor->ClearState();
Chia-I Wua4992342015-07-03 11:45:55 +0800739 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600740 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600741 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600742 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from submitting fence with UNSIGNALED state to vkResetFences";
Tony Barbour01999182015-04-09 12:58:51 -0600743 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500744 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600745 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600746
747}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600748
Chia-I Wuc278df82015-07-07 11:50:03 +0800749/* TODO: Update for changes due to bug-14075 tiling across render passes */
750#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600751TEST_F(VkLayerTest, InvalidUsageBits)
752{
753 // Initiate Draw w/o a PSO bound
754 VkFlags msgFlags;
755 std::string msgString;
756
757 ASSERT_NO_FATAL_FAILURE(InitState());
758 m_errorMonitor->ClearState();
759 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600760 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600761
762 const VkExtent3D e3d = {
763 .width = 128,
764 .height = 128,
765 .depth = 1,
766 };
767 const VkImageCreateInfo ici = {
768 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
769 .pNext = NULL,
770 .imageType = VK_IMAGE_TYPE_2D,
771 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
772 .extent = e3d,
773 .mipLevels = 1,
774 .arraySize = 1,
775 .samples = 1,
776 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchterc3b8eea2015-09-10 14:14:11 -0600777 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600778 .flags = 0,
779 };
780
781 VkImage dsi;
782 vkCreateImage(m_device->device(), &ici, &dsi);
783 VkDepthStencilView dsv;
784 const VkDepthStencilViewCreateInfo dsvci = {
785 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
786 .pNext = NULL,
787 .image = dsi,
788 .mipLevel = 0,
Courtney Goeltzenleuchter3dee8082015-09-10 16:38:41 -0600789 .baseArrayLayer = 0,
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600790 .arraySize = 1,
791 .flags = 0,
792 };
793 vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv);
794 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600795 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after attempting to create DSView w/ image lacking USAGE_DS_BIT flag";
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600796 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
797 FAIL() << "Error received was not 'Invalid usage flag for image...'";
798 }
799}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600800#endif // 0
801#endif // MEM_TRACKER_TESTS
802
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600803#if OBJ_TRACKER_TESTS
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600804TEST_F(VkLayerTest, PipelineNotBound)
805{
806 VkFlags msgFlags;
807 std::string msgString;
808 VkResult err;
809
810 ASSERT_NO_FATAL_FAILURE(InitState());
811 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
812 m_errorMonitor->ClearState();
813
814 VkDescriptorTypeCount ds_type_count = {};
815 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
816 ds_type_count.count = 1;
817
818 VkDescriptorPoolCreateInfo ds_pool_ci = {};
819 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
820 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600821 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
822 ds_pool_ci.maxSets = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600823 ds_pool_ci.count = 1;
824 ds_pool_ci.pTypeCount = &ds_type_count;
825
826 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600827 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600828 ASSERT_VK_SUCCESS(err);
829
830 VkDescriptorSetLayoutBinding dsl_binding = {};
831 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
832 dsl_binding.arraySize = 1;
833 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
834 dsl_binding.pImmutableSamplers = NULL;
835
836 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
837 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
838 ds_layout_ci.pNext = NULL;
839 ds_layout_ci.count = 1;
840 ds_layout_ci.pBinding = &dsl_binding;
841
842 VkDescriptorSetLayout ds_layout;
843 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
844 ASSERT_VK_SUCCESS(err);
845
846 VkDescriptorSet descriptorSet;
847 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
848 ASSERT_VK_SUCCESS(err);
849
850 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
851 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
852 pipeline_layout_ci.pNext = NULL;
853 pipeline_layout_ci.descriptorSetCount = 1;
854 pipeline_layout_ci.pSetLayouts = &ds_layout;
855
856 VkPipelineLayout pipeline_layout;
857 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
858 ASSERT_VK_SUCCESS(err);
859
860 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
861
862 BeginCommandBuffer();
863 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
864
865 msgFlags = m_errorMonitor->GetState(&msgString);
866 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600867 if (!strstr(msgString.c_str(),"Invalid VkPipeline Object ")) {
868 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be' but instead it was '" << msgString.c_str() << "'";
869 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600870
871 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
872 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
873 ASSERT_VK_SUCCESS(err);
874 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
875 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600876}
877
878TEST_F(VkLayerTest, BindInvalidMemory)
879{
880 VkFlags msgFlags;
881 std::string msgString;
882 VkResult err;
883
884 ASSERT_NO_FATAL_FAILURE(InitState());
885 m_errorMonitor->ClearState();
886
887 // Create an image, allocate memory, free it, and then try to bind it
888 VkImage image;
889 VkDeviceMemory mem;
890 VkMemoryRequirements mem_reqs;
891
892 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
893 const int32_t tex_width = 32;
894 const int32_t tex_height = 32;
895
896 VkImageCreateInfo image_create_info = {};
897 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
898 image_create_info.pNext = NULL;
899 image_create_info.imageType = VK_IMAGE_TYPE_2D;
900 image_create_info.format = tex_format;
901 image_create_info.extent.width = tex_width;
902 image_create_info.extent.height = tex_height;
903 image_create_info.extent.depth = 1;
904 image_create_info.mipLevels = 1;
905 image_create_info.arraySize = 1;
906 image_create_info.samples = 1;
907 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
908 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
909 image_create_info.flags = 0;
910
911 VkMemoryAllocInfo mem_alloc = {};
912 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
913 mem_alloc.pNext = NULL;
914 mem_alloc.allocationSize = 0;
915 mem_alloc.memoryTypeIndex = 0;
916
917 err = vkCreateImage(m_device->device(), &image_create_info, &image);
918 ASSERT_VK_SUCCESS(err);
919
920 err = vkGetImageMemoryRequirements(m_device->device(),
921 image,
922 &mem_reqs);
923 ASSERT_VK_SUCCESS(err);
924
925 mem_alloc.allocationSize = mem_reqs.size;
926
927 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
928 ASSERT_VK_SUCCESS(err);
929
930 // allocate memory
931 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
932 ASSERT_VK_SUCCESS(err);
933
934 // Introduce validation failure, free memory before binding
935 vkFreeMemory(m_device->device(), mem);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600936
937 // Try to bind free memory that has been freed
938 err = vkBindImageMemory(m_device->device(), image, mem, 0);
939 // This may very well return an error.
940 (void)err;
941
942 msgFlags = m_errorMonitor->GetState(&msgString);
943 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to bind a freed memory object";
944 if (!strstr(msgString.c_str(),"Invalid VkDeviceMemory Object ")) {
945 FAIL() << "Error received from BindInvalidMemory was not 'Invalid VkDeviceMemory Object 0x<handle>' but instead '" << msgString.c_str() << "'";
946 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600947
948 vkDestroyImage(m_device->device(), image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600949}
950
951TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
952{
953 VkFlags msgFlags;
954 std::string msgString;
955 VkResult err;
956
957 ASSERT_NO_FATAL_FAILURE(InitState());
958 m_errorMonitor->ClearState();
959
960 // Create an image object, allocate memory, destroy the object and then try to bind it
961 VkImage image;
962 VkDeviceMemory mem;
963 VkMemoryRequirements mem_reqs;
964
965 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
966 const int32_t tex_width = 32;
967 const int32_t tex_height = 32;
968
969 VkImageCreateInfo image_create_info = {};
970 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
971 image_create_info.pNext = NULL;
972 image_create_info.imageType = VK_IMAGE_TYPE_2D;
973 image_create_info.format = tex_format;
974 image_create_info.extent.width = tex_width;
975 image_create_info.extent.height = tex_height;
976 image_create_info.extent.depth = 1;
977 image_create_info.mipLevels = 1;
978 image_create_info.arraySize = 1;
979 image_create_info.samples = 1;
980 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
981 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
982 image_create_info.flags = 0;
983
984 VkMemoryAllocInfo mem_alloc = {};
985 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
986 mem_alloc.pNext = NULL;
987 mem_alloc.allocationSize = 0;
988 mem_alloc.memoryTypeIndex = 0;
989
990 err = vkCreateImage(m_device->device(), &image_create_info, &image);
991 ASSERT_VK_SUCCESS(err);
992
993 err = vkGetImageMemoryRequirements(m_device->device(),
994 image,
995 &mem_reqs);
996 ASSERT_VK_SUCCESS(err);
997
998 mem_alloc.allocationSize = mem_reqs.size;
999 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1000 ASSERT_VK_SUCCESS(err);
1001
1002 // Allocate memory
1003 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
1004 ASSERT_VK_SUCCESS(err);
1005
1006 // Introduce validation failure, destroy Image object before binding
1007 vkDestroyImage(m_device->device(), image);
1008 ASSERT_VK_SUCCESS(err);
1009
1010 // Now Try to bind memory to this destroyed object
1011 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1012 // This may very well return an error.
1013 (void) err;
1014
1015 msgFlags = m_errorMonitor->GetState(&msgString);
1016 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while binding memory to a destroyed object";
1017 if (!strstr(msgString.c_str(),"Invalid VkImage Object ")) {
1018 FAIL() << "Error received from BindMemoryToDestroyedObject was not 'Invalid VkImage Object 0x<handle>' but rather '" << msgString.c_str() << "'";
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001019 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001020
1021 vkFreeMemory(m_device->device(), mem);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001022}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001023#endif // OBJ_TRACKER_TESTS
1024
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001025#if DRAW_STATE_TESTS
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001026TEST_F(VkLayerTest, LineWidthStateNotBound)
1027{
1028 VkFlags msgFlags;
1029 std::string msgString;
1030 m_errorMonitor->ClearState();
1031 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
1032
1033 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
1034
1035 msgFlags = m_errorMonitor->GetState(&msgString);
1036 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Line Width State Object";
1037 if (!strstr(msgString.c_str(),"Dynamic line width state not set for this command buffer")) {
1038 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic line width state not set for this command buffer'";
1039 }
1040}
1041
1042TEST_F(VkLayerTest, DepthBiasStateNotBound)
1043{
1044 VkFlags msgFlags;
1045 std::string msgString;
1046 m_errorMonitor->ClearState();
1047 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
1048
1049 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
1050
1051 msgFlags = m_errorMonitor->GetState(&msgString);
1052 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bias State Object";
1053 if (!strstr(msgString.c_str(),"Dynamic depth bias state not set for this command buffer")) {
1054 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bias state not set for this command buffer'";
1055 }
1056}
1057
1058TEST_F(VkLayerTest, ViewportStateNotBound)
1059{
1060 VkFlags msgFlags;
1061 std::string msgString;
1062 m_errorMonitor->ClearState();
1063 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1064
1065 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1066
1067 msgFlags = m_errorMonitor->GetState(&msgString);
1068 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
1069 if (!strstr(msgString.c_str(),"Dynamic viewport state not set for this command buffer")) {
1070 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic viewport state not set for this command buffer'";
1071 }
1072}
1073
1074TEST_F(VkLayerTest, ScissorStateNotBound)
1075{
1076 VkFlags msgFlags;
1077 std::string msgString;
1078 m_errorMonitor->ClearState();
1079 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1080
1081 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1082
1083 msgFlags = m_errorMonitor->GetState(&msgString);
1084 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
1085 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1086 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
1087 }
1088}
1089
1090
1091TEST_F(VkLayerTest, BlendStateNotBound)
1092{
1093 VkFlags msgFlags;
1094 std::string msgString;
1095 m_errorMonitor->ClearState();
1096 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1097
1098 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1099
1100 msgFlags = m_errorMonitor->GetState(&msgString);
1101 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Blend State Object";
1102 if (!strstr(msgString.c_str(),"Dynamic blend object state not set for this command buffer")) {
1103 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic blend object state not set for this command buffer'";
1104 }
1105}
1106
1107TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1108{
1109 VkFlags msgFlags;
1110 std::string msgString;
1111 m_errorMonitor->ClearState();
1112 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1113
1114 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1115
1116 msgFlags = m_errorMonitor->GetState(&msgString);
1117 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bounds State Object";
1118 if (!strstr(msgString.c_str(),"Dynamic depth bounds state not set for this command buffer")) {
1119 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bounds state not set for this command buffer'";
1120 }
1121}
1122
1123TEST_F(VkLayerTest, StencilReadMaskNotSet)
1124{
1125 VkFlags msgFlags;
1126 std::string msgString;
1127 ASSERT_NO_FATAL_FAILURE(InitState());
1128 m_errorMonitor->ClearState();
1129 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1130
1131 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1132
1133 msgFlags = m_errorMonitor->GetState(&msgString);
1134 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Read Mask";
1135 if (!strstr(msgString.c_str(),"Dynamic stencil read mask state not set for this command buffer")) {
1136 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil read mask state not set for this command buffer'";
1137 }
1138}
1139
1140TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1141{
1142 VkFlags msgFlags;
1143 std::string msgString;
1144 ASSERT_NO_FATAL_FAILURE(InitState());
1145 m_errorMonitor->ClearState();
1146 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1147
1148 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1149
1150 msgFlags = m_errorMonitor->GetState(&msgString);
1151 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Write Mask";
1152 if (!strstr(msgString.c_str(),"Dynamic stencil write mask state not set for this command buffer")) {
1153 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil write mask state not set for this command buffer'";
1154 }
1155}
1156
1157TEST_F(VkLayerTest, StencilReferenceNotSet)
1158{
1159 VkFlags msgFlags;
1160 std::string msgString;
1161 m_errorMonitor->ClearState();
1162 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1163
1164 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1165
1166 msgFlags = m_errorMonitor->GetState(&msgString);
1167 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Reference";
1168 if (!strstr(msgString.c_str(),"Dynamic stencil reference state not set for this command buffer")) {
1169 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil reference state not set for this command buffer'";
1170 }
1171}
1172
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001173TEST_F(VkLayerTest, CmdBufferTwoSubmits)
1174{
1175 vk_testing::Fence testFence;
1176 VkFlags msgFlags;
1177 std::string msgString;
1178
1179 VkFenceCreateInfo fenceInfo = {};
1180 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1181 fenceInfo.pNext = NULL;
1182 fenceInfo.flags = 0;
1183
1184 ASSERT_NO_FATAL_FAILURE(InitState());
1185 ASSERT_NO_FATAL_FAILURE(InitViewport());
1186 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1187
1188 // We luck out b/c by default the framework creates CB w/ the VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set
1189 BeginCommandBuffer();
1190 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
1191 EndCommandBuffer();
1192
1193 testFence.init(*m_device, fenceInfo);
1194
1195 // Bypass framework since it does the waits automatically
1196 VkResult err = VK_SUCCESS;
1197 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
1198 ASSERT_VK_SUCCESS( err );
1199
1200 m_errorMonitor->ClearState();
1201 // Cause validation error by re-submitting cmd buffer that should only be submitted once
1202 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001203
1204 msgFlags = m_errorMonitor->GetState(&msgString);
1205 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after re-submitting Command Buffer that was created with one-time submit flag";
Tobin Ehlis7f7b4422015-08-18 14:24:32 -06001206 if (!strstr(msgString.c_str(),"was begun w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set, but has been submitted")) {
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001207 FAIL() << "Error received was not 'CB (0xaddress) was created w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set...'";
1208 }
1209}
1210
Tobin Ehlise4076782015-06-24 15:53:07 -06001211TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001212{
1213 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001214 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001215 std::string msgString;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001216 VkResult err;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001217
1218 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001219 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001220 m_errorMonitor->ClearState();
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001221
1222 VkDescriptorTypeCount ds_type_count = {};
1223 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1224 ds_type_count.count = 1;
1225
1226 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1227 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1228 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001229 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1230 ds_pool_ci.maxSets = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001231 ds_pool_ci.count = 1;
1232 ds_pool_ci.pTypeCount = &ds_type_count;
1233
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001234 VkDescriptorPool ds_pool;
1235 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001236 ASSERT_VK_SUCCESS(err);
1237
1238 VkDescriptorSetLayoutBinding dsl_binding = {};
1239 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1240 dsl_binding.arraySize = 1;
1241 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1242 dsl_binding.pImmutableSamplers = NULL;
1243
1244 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1245 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1246 ds_layout_ci.pNext = NULL;
1247 ds_layout_ci.count = 1;
1248 ds_layout_ci.pBinding = &dsl_binding;
1249
1250 VkDescriptorSetLayout ds_layout;
1251 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1252 ASSERT_VK_SUCCESS(err);
1253
1254 VkDescriptorSet descriptorSet;
1255 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1256 ASSERT_VK_SUCCESS(err);
1257 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1258 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1259 pipe_ms_state_ci.pNext = NULL;
1260 pipe_ms_state_ci.rasterSamples = 1;
1261 pipe_ms_state_ci.sampleShadingEnable = 0;
1262 pipe_ms_state_ci.minSampleShading = 1.0;
1263 pipe_ms_state_ci.pSampleMask = NULL;
1264
1265 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1266 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1267 pipeline_layout_ci.pNext = NULL;
1268 pipeline_layout_ci.descriptorSetCount = 1;
1269 pipeline_layout_ci.pSetLayouts = &ds_layout;
1270 VkPipelineLayout pipeline_layout;
1271
1272 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1273 ASSERT_VK_SUCCESS(err);
1274
1275 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
1276 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1277 // but add it to be able to run on more devices
1278 VkPipelineObj pipe(m_device);
1279 pipe.AddShader(&vs);
1280 pipe.AddShader(&fs);
1281 pipe.SetMSAA(&pipe_ms_state_ci);
1282 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1283 m_errorMonitor->ClearState();
1284 // Calls CreateCommandBuffer
1285 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1286 VkCmdBufferBeginInfo cmd_buf_info = {};
1287 memset(&cmd_buf_info, 0, sizeof(VkCmdBufferBeginInfo));
1288 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1289 cmd_buf_info.pNext = NULL;
1290 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1291 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1292
1293 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1294 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001295 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001296 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding pipeline to CmdBuffer w/o active RenderPass";
Tobin Ehlise4076782015-06-24 15:53:07 -06001297 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001298 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0x<handle>) without an active RenderPass'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001299 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001300
1301 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
1302 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1303 ASSERT_VK_SUCCESS(err);
1304 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1305 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001306}
1307
1308TEST_F(VkLayerTest, InvalidDescriptorPool)
1309{
1310 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1311 // The DS check for this is after driver has been called to validate DS internal data struct
1312 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001313/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001314 std::string msgString;
1315 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1316 vkResetDescriptorPool(device(), badPool);
1317
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001318 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001319 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Resetting an invalid DescriptorPool Object";
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001320 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1321 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1322 }*/
1323}
1324
1325TEST_F(VkLayerTest, InvalidDescriptorSet)
1326{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001327 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1328 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001329 // Create a valid cmd buffer
1330 // call vkCmdBindDescriptorSets w/ false DS
1331}
1332
1333TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1334{
1335 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1336 // The DS check for this is after driver has been called to validate DS internal data struct
1337}
1338
1339TEST_F(VkLayerTest, InvalidPipeline)
1340{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001341 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1342 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001343 // Create a valid cmd buffer
1344 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -06001345// VkFlags msgFlags;
1346// std::string msgString;
1347//
1348// ASSERT_NO_FATAL_FAILURE(InitState());
1349// m_errorMonitor->ClearState();
1350// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001351// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001352// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1353// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1354// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001355// ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Tobin Ehlise4076782015-06-24 15:53:07 -06001356// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1357// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1358// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001359}
1360
Tobin Ehlis254eca02015-06-25 15:46:59 -06001361TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001362{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001363 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001364 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001365 std::string msgString;
1366 VkResult err;
1367
1368 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001369 ASSERT_NO_FATAL_FAILURE(InitViewport());
1370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001371 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001372 VkDescriptorTypeCount ds_type_count = {};
1373 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1374 ds_type_count.count = 1;
1375
1376 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1377 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1378 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001379 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1380 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001381 ds_pool_ci.count = 1;
1382 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001383
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001384 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001385 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001386 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001387
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001388 VkDescriptorSetLayoutBinding dsl_binding = {};
1389 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1390 dsl_binding.arraySize = 1;
1391 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1392 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001393
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001394 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1395 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1396 ds_layout_ci.pNext = NULL;
1397 ds_layout_ci.count = 1;
1398 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001399 VkDescriptorSetLayout ds_layout;
1400 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1401 ASSERT_VK_SUCCESS(err);
1402
1403 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001404 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001405 ASSERT_VK_SUCCESS(err);
1406
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001407 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1408 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1409 pipeline_layout_ci.pNext = NULL;
1410 pipeline_layout_ci.descriptorSetCount = 1;
1411 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001412
1413 VkPipelineLayout pipeline_layout;
1414 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1415 ASSERT_VK_SUCCESS(err);
1416
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001417 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001418 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1419 // but add it to be able to run on more devices
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001420
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001421 VkPipelineObj pipe(m_device);
1422 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001423 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001424 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001425
1426 BeginCommandBuffer();
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001427 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbour1490c912015-07-28 10:17:20 -06001428 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001429
Tobin Ehlis254eca02015-06-25 15:46:59 -06001430 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001431 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not warn after binding a DescriptorSet that was never updated.";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001432 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1433 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1434 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001435
1436 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
1437 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1438 ASSERT_VK_SUCCESS(err);
1439 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1440 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001441}
1442
1443TEST_F(VkLayerTest, NoBeginCmdBuffer)
1444{
1445 VkFlags msgFlags;
1446 std::string msgString;
1447
1448 ASSERT_NO_FATAL_FAILURE(InitState());
1449 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001450 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001451 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1452 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1453 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001454 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after ending a CmdBuffer w/o calling BeginCommandBuffer()";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001455 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1456 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1457 }
1458}
1459
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001460TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1461{
1462 VkFlags msgFlags;
1463 std::string msgString;
1464
1465 ASSERT_NO_FATAL_FAILURE(InitState());
1466 m_errorMonitor->ClearState();
1467
1468 // Calls CreateCommandBuffer
1469 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1470
1471 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northrop10d8f982015-08-04 17:35:57 -06001472 VkCmdBufferBeginInfo cmd_buf_info = {};
1473 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1474 cmd_buf_info.pNext = NULL;
1475 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1476 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1477 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1478 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1479
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001480
1481 // The error should be caught by validation of the BeginCommandBuffer call
1482 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1483
1484 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001485 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error passing a non-NULL Framebuffer and Renderpass to BeginCommandBuffer()";
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001486 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1487 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1488 }
1489}
1490
1491TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1492{
1493 VkFlags msgFlags;
1494 std::string msgString;
1495 VkResult err;
1496 VkCmdBuffer draw_cmd;
1497 VkCmdPool cmd_pool;
1498
1499 ASSERT_NO_FATAL_FAILURE(InitState());
1500 m_errorMonitor->ClearState();
1501
Cody Northrop10d8f982015-08-04 17:35:57 -06001502 VkCmdBufferCreateInfo cmd = {};
1503 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1504 cmd.pNext = NULL;
1505 cmd.cmdPool = m_cmdPool;
1506 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1507 cmd.flags = 0;
1508
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001509 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
Mike Stroyan2237f522015-08-18 14:40:24 -06001510 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001511
1512 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northrop10d8f982015-08-04 17:35:57 -06001513 VkCmdBufferBeginInfo cmd_buf_info = {};
1514 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1515 cmd_buf_info.pNext = NULL;
1516 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1517 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001518
1519 // The error should be caught by validation of the BeginCommandBuffer call
1520 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1521
1522 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001523 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error passing NULL Framebuffer/Renderpass to BeginCommandBuffer()";
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001524 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1525 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1526 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001527 vkDestroyCommandBuffer(m_device->device(), draw_cmd);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001528}
1529
Tobin Ehlis254eca02015-06-25 15:46:59 -06001530TEST_F(VkLayerTest, InvalidPipelineCreateState)
1531{
1532 // Attempt to Create Gfx Pipeline w/o a VS
1533 VkFlags msgFlags;
1534 std::string msgString;
1535 VkResult err;
1536
1537 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis254eca02015-06-25 15:46:59 -06001539 m_errorMonitor->ClearState();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001540
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001541 VkDescriptorTypeCount ds_type_count = {};
1542 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1543 ds_type_count.count = 1;
1544
1545 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1546 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1547 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001548 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1549 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001550 ds_pool_ci.count = 1;
1551 ds_pool_ci.pTypeCount = &ds_type_count;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001552
Tobin Ehlis254eca02015-06-25 15:46:59 -06001553 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001554 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001555 ASSERT_VK_SUCCESS(err);
1556
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001557 VkDescriptorSetLayoutBinding dsl_binding = {};
1558 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1559 dsl_binding.arraySize = 1;
1560 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1561 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001562
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001563 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1564 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1565 ds_layout_ci.pNext = NULL;
1566 ds_layout_ci.count = 1;
1567 ds_layout_ci.pBinding = &dsl_binding;
1568
Tobin Ehlis254eca02015-06-25 15:46:59 -06001569 VkDescriptorSetLayout ds_layout;
1570 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1571 ASSERT_VK_SUCCESS(err);
1572
1573 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001574 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001575 ASSERT_VK_SUCCESS(err);
1576
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001577 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1578 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1579 pipeline_layout_ci.pNext = NULL;
1580 pipeline_layout_ci.descriptorSetCount = 1;
1581 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001582
1583 VkPipelineLayout pipeline_layout;
1584 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1585 ASSERT_VK_SUCCESS(err);
1586
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001587 VkGraphicsPipelineCreateInfo gp_ci = {};
1588 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1589 gp_ci.pNext = NULL;
1590 gp_ci.stageCount = 0;
1591 gp_ci.pStages = NULL;
1592 gp_ci.pVertexInputState = NULL;
1593 gp_ci.pInputAssemblyState = NULL;
1594 gp_ci.pTessellationState = NULL;
1595 gp_ci.pViewportState = NULL;
1596 gp_ci.pRasterState = NULL;
1597 gp_ci.pMultisampleState = NULL;
1598 gp_ci.pDepthStencilState = NULL;
1599 gp_ci.pColorBlendState = NULL;
1600 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1601 gp_ci.layout = pipeline_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001602 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001603
1604 VkPipelineCacheCreateInfo pc_ci = {};
1605 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1606 pc_ci.pNext = NULL;
1607 pc_ci.initialSize = 0;
1608 pc_ci.initialData = 0;
1609 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001610
1611 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001612 VkPipelineCache pipelineCache;
1613
1614 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1615 ASSERT_VK_SUCCESS(err);
1616 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001617
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001618 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001619 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o VS.";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001620 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1621 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1622 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001623
1624 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1625 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
1626 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1627 ASSERT_VK_SUCCESS(err);
1628 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1629 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001630}
Tobin Ehlis20693172015-09-17 08:46:18 -06001631/*// TODO : This test should be good, but needs Tess support in compiler to run
1632TEST_F(VkLayerTest, InvalidPatchControlPoints)
1633{
1634 // Attempt to Create Gfx Pipeline w/o a VS
1635 VkFlags msgFlags;
1636 std::string msgString;
1637 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001638
Tobin Ehlis20693172015-09-17 08:46:18 -06001639 ASSERT_NO_FATAL_FAILURE(InitState());
1640 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1641 m_errorMonitor->ClearState();
1642
1643 VkDescriptorTypeCount ds_type_count = {};
1644 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1645 ds_type_count.count = 1;
1646
1647 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1648 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1649 ds_pool_ci.pNext = NULL;
1650 ds_pool_ci.count = 1;
1651 ds_pool_ci.pTypeCount = &ds_type_count;
1652
1653 VkDescriptorPool ds_pool;
1654 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1655 ASSERT_VK_SUCCESS(err);
1656
1657 VkDescriptorSetLayoutBinding dsl_binding = {};
1658 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1659 dsl_binding.arraySize = 1;
1660 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1661 dsl_binding.pImmutableSamplers = NULL;
1662
1663 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1664 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1665 ds_layout_ci.pNext = NULL;
1666 ds_layout_ci.count = 1;
1667 ds_layout_ci.pBinding = &dsl_binding;
1668
1669 VkDescriptorSetLayout ds_layout;
1670 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1671 ASSERT_VK_SUCCESS(err);
1672
1673 VkDescriptorSet descriptorSet;
1674 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1675 ASSERT_VK_SUCCESS(err);
1676
1677 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1678 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1679 pipeline_layout_ci.pNext = NULL;
1680 pipeline_layout_ci.descriptorSetCount = 1;
1681 pipeline_layout_ci.pSetLayouts = &ds_layout;
1682
1683 VkPipelineLayout pipeline_layout;
1684 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1685 ASSERT_VK_SUCCESS(err);
1686
1687 VkPipelineShaderStageCreateInfo shaderStages[3];
1688 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
1689
1690 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
1691 // Just using VS txt for Tess shaders as we don't care about functionality
1692 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESS_CONTROL, this);
1693 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESS_EVALUATION, this);
1694
1695 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1696 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
1697 shaderStages[0].shader = vs.handle();
1698 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1699 shaderStages[1].stage = VK_SHADER_STAGE_TESS_CONTROL;
1700 shaderStages[1].shader = tc.handle();
1701 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1702 shaderStages[2].stage = VK_SHADER_STAGE_TESS_EVALUATION;
1703 shaderStages[2].shader = te.handle();
1704
1705 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
1706 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
1707 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH;
1708
1709 VkPipelineTessellationStateCreateInfo tsCI = {};
1710 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
1711 tsCI.patchControlPoints = 0; // This will cause an error
1712
1713 VkGraphicsPipelineCreateInfo gp_ci = {};
1714 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1715 gp_ci.pNext = NULL;
1716 gp_ci.stageCount = 3;
1717 gp_ci.pStages = shaderStages;
1718 gp_ci.pVertexInputState = NULL;
1719 gp_ci.pInputAssemblyState = &iaCI;
1720 gp_ci.pTessellationState = &tsCI;
1721 gp_ci.pViewportState = NULL;
1722 gp_ci.pRasterState = NULL;
1723 gp_ci.pMultisampleState = NULL;
1724 gp_ci.pDepthStencilState = NULL;
1725 gp_ci.pColorBlendState = NULL;
1726 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1727 gp_ci.layout = pipeline_layout;
1728 gp_ci.renderPass = renderPass();
1729
1730 VkPipelineCacheCreateInfo pc_ci = {};
1731 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1732 pc_ci.pNext = NULL;
1733 pc_ci.initialSize = 0;
1734 pc_ci.initialData = 0;
1735 pc_ci.maxSize = 0;
1736
1737 VkPipeline pipeline;
1738 VkPipelineCache pipelineCache;
1739
1740 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1741 ASSERT_VK_SUCCESS(err);
1742 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1743
1744 msgFlags = m_errorMonitor->GetState(&msgString);
1745 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Tess Gfx Pipeline w/ 0 patchControlPoints.";
1746 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ")) {
1747 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...' but instead '" << msgString.c_str() << "'";
1748 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001749
1750 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1751 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
1752 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1753 ASSERT_VK_SUCCESS(err);
1754 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1755 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis20693172015-09-17 08:46:18 -06001756}
1757*/
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001758TEST_F(VkLayerTest, NullRenderPass)
1759{
1760 // Bind a NULL RenderPass
1761 VkFlags msgFlags;
1762 std::string msgString;
1763
1764 ASSERT_NO_FATAL_FAILURE(InitState());
1765 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1766 m_errorMonitor->ClearState();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001767
Tony Barbour1490c912015-07-28 10:17:20 -06001768 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001769 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06001770 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001771
1772 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001773 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001774 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
1775 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
1776 }
1777}
1778
Tobin Ehlis254eca02015-06-25 15:46:59 -06001779TEST_F(VkLayerTest, RenderPassWithinRenderPass)
1780{
1781 // Bind a BeginRenderPass within an active RenderPass
1782 VkFlags msgFlags;
1783 std::string msgString;
1784
1785 ASSERT_NO_FATAL_FAILURE(InitState());
1786 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1787 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001788
Tony Barbour1490c912015-07-28 10:17:20 -06001789 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001790 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001791 VkRenderPassBeginInfo rp_begin = {};
1792 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
1793 rp_begin.pNext = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001794 rp_begin.renderPass = renderPass();
1795 rp_begin.framebuffer = framebuffer();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001796
Tony Barbour1490c912015-07-28 10:17:20 -06001797 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001798
1799 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001800 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding RenderPass w/i an active RenderPass.";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001801 if (!strstr(msgString.c_str(),"Cannot call vkCmdBeginRenderPass() during an active RenderPass ")) {
1802 FAIL() << "Error received was not 'Cannot call vkCmdBeginRenderPass() during an active RenderPass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001803 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001804}
1805
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06001806TEST_F(VkLayerTest, FillBufferWithinRenderPass)
1807{
1808 // Call CmdFillBuffer within an active renderpass
1809 VkFlags msgFlags;
1810 std::string msgString;
1811
1812 ASSERT_NO_FATAL_FAILURE(InitState());
1813 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1814 m_errorMonitor->ClearState();
1815
1816 // Renderpass is started here
1817 BeginCommandBuffer();
1818
1819 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1820 vk_testing::Buffer destBuffer;
1821 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
1822
1823 m_cmdBuffer->FillBuffer(destBuffer.handle(), 0, 4, 0x11111111);
1824
1825 msgFlags = m_errorMonitor->GetState(&msgString);
1826 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
1827 "Did not receive error after calling CmdFillBuffer w/i an active RenderPass.";
1828 if (!strstr(msgString.c_str(),"CmdFillBuffer cmd issued within an active RenderPass")) {
1829 FAIL() << "Error received was not 'CmdFillBuffer cmd issued within an active RenderPass'";
1830 }
1831}
1832
1833TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
1834{
1835 // Call CmdUpdateBuffer within an active renderpass
1836 VkFlags msgFlags;
1837 std::string msgString;
1838
1839 ASSERT_NO_FATAL_FAILURE(InitState());
1840 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1841 m_errorMonitor->ClearState();
1842
1843 // Renderpass is started here
1844 BeginCommandBuffer();
1845
1846 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1847 vk_testing::Buffer destBuffer;
1848 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
1849
1850 VkDeviceSize destOffset = 0;
1851 VkDeviceSize dataSize = 1024;
1852 const uint32_t *pData = NULL;
1853
1854 vkCmdUpdateBuffer(m_cmdBuffer->GetBufferHandle(), destBuffer.handle(), destOffset, dataSize, pData);
1855
1856 msgFlags = m_errorMonitor->GetState(&msgString);
1857 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
1858 "Did not receive error after calling CmdUpdateBuffer w/i an active RenderPass.";
1859 if (!strstr(msgString.c_str(),"CmdUpdateBuffer cmd issued within an active RenderPass")) {
1860 FAIL() << "Error received was not 'CmdUpdateBuffer cmd issued within an active RenderPass'";
1861 }
1862}
1863
1864TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
1865{
1866 // Call CmdClearColorImage within an active RenderPass
1867 VkFlags msgFlags;
1868 std::string msgString;
1869
1870 ASSERT_NO_FATAL_FAILURE(InitState());
1871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1872 m_errorMonitor->ClearState();
1873
1874 // Renderpass is started here
1875 BeginCommandBuffer();
1876
1877 VkClearColorValue clear_color = {0};
1878 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1879 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1880 const int32_t tex_width = 32;
1881 const int32_t tex_height = 32;
1882 VkImageCreateInfo image_create_info = {};
1883 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1884 image_create_info.pNext = NULL;
1885 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1886 image_create_info.format = tex_format;
1887 image_create_info.extent.width = tex_width;
1888 image_create_info.extent.height = tex_height;
1889 image_create_info.extent.depth = 1;
1890 image_create_info.mipLevels = 1;
1891 image_create_info.arraySize = 1;
1892 image_create_info.samples = 1;
1893 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1894 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1895
1896 vk_testing::Image destImage;
1897 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
1898
1899 const VkImageSubresourceRange range =
1900 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
1901
1902 vkCmdClearColorImage(m_cmdBuffer->GetBufferHandle(),
1903 destImage.handle(),
1904 VK_IMAGE_LAYOUT_GENERAL,
1905 &clear_color,
1906 1,
1907 &range);
1908
1909 msgFlags = m_errorMonitor->GetState(&msgString);
1910 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
1911 "Did not receive error after calling CmdClearColorImage w/i an active RenderPass.";
1912 if (!strstr(msgString.c_str(),"CmdClearColorImage cmd issued within an active RenderPass")) {
1913 FAIL() << "Error received was not 'CmdClearColorImage cmd issued within an active RenderPass'";
1914 }
1915}
1916
1917TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
1918{
1919 // Call CmdClearDepthStencilImage within an active RenderPass
1920 VkFlags msgFlags;
1921 std::string msgString;
1922
1923 ASSERT_NO_FATAL_FAILURE(InitState());
1924 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1925 m_errorMonitor->ClearState();
1926
1927 // Renderpass is started here
1928 BeginCommandBuffer();
1929
1930 VkClearDepthStencilValue clear_value = {0};
1931 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1932 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
1933 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1934 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
1935 image_create_info.extent.width = 64;
1936 image_create_info.extent.height = 64;
1937 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1938 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1939
1940 vk_testing::Image destImage;
1941 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
1942
1943 const VkImageSubresourceRange range =
1944 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
1945
1946 vkCmdClearDepthStencilImage(m_cmdBuffer->GetBufferHandle(),
1947 destImage.handle(),
1948 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
1949 &clear_value,
1950 1,
1951 &range);
1952
1953 msgFlags = m_errorMonitor->GetState(&msgString);
1954 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
1955 "Did not receive error after calling CmdClearDepthStencilImage w/i an active RenderPass.";
1956 if (!strstr(msgString.c_str(),"CmdClearDepthStencilImage cmd issued within an active RenderPass")) {
1957 FAIL() << "Error received was not 'CmdClearDepthStencilImage cmd issued within an active RenderPass'";
1958 }
1959}
1960
1961TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
1962{
1963 // Call CmdClearColorAttachments outside of an active RenderPass
1964 VkFlags msgFlags;
1965 std::string msgString;
1966 VkResult err;
1967
1968 ASSERT_NO_FATAL_FAILURE(InitState());
1969 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1970 m_errorMonitor->ClearState();
1971
1972 // Start no RenderPass
1973 err = m_cmdBuffer->BeginCommandBuffer();
1974 ASSERT_VK_SUCCESS(err);
1975
1976 VkClearColorValue clear_color = {0};
1977 VkRect3D clear_rect = { { 0, 0, 0 }, { 32, 32, 1 } };
1978
1979 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0,
1980 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
1981 &clear_color, 1, &clear_rect);
1982
1983 msgFlags = m_errorMonitor->GetState(&msgString);
1984 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
1985 "Did not receive error after calling CmdClearColorAttachment outside of an active RenderPass.";
1986 if (!strstr(msgString.c_str(),"CmdClearColorAttachment cmd issued outside of an active RenderPass")) {
1987 FAIL() << "Error received was not 'CmdClearColorAttachment cmd issued outside of an active RenderPass'";
1988 }
1989}
1990
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001991TEST_F(VkLayerTest, InvalidDynamicStateObject)
1992{
1993 // Create a valid cmd buffer
1994 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001995 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1996 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001997}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06001998
Tobin Ehlise4076782015-06-24 15:53:07 -06001999TEST_F(VkLayerTest, VtxBufferNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002000{
2001 // Bind VBO out-of-bounds for given PSO
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002002 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002003 std::string msgString;
2004 VkResult err;
2005
2006 ASSERT_NO_FATAL_FAILURE(InitState());
2007 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002008
2009 VkDescriptorTypeCount ds_type_count = {};
2010 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2011 ds_type_count.count = 1;
2012
2013 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2014 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2015 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002016 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2017 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002018 ds_pool_ci.count = 1;
2019 ds_pool_ci.pTypeCount = &ds_type_count;
2020
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002021 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002022 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002023 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002024
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002025 VkDescriptorSetLayoutBinding dsl_binding = {};
2026 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2027 dsl_binding.arraySize = 1;
2028 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2029 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002030
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002031 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2032 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2033 ds_layout_ci.pNext = NULL;
2034 ds_layout_ci.count = 1;
2035 ds_layout_ci.pBinding = &dsl_binding;
2036
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002037 VkDescriptorSetLayout ds_layout;
2038 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2039 ASSERT_VK_SUCCESS(err);
2040
2041 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002042 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002043 ASSERT_VK_SUCCESS(err);
2044
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002045 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2046 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2047 pipeline_layout_ci.pNext = NULL;
2048 pipeline_layout_ci.descriptorSetCount = 1;
2049 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002050
2051 VkPipelineLayout pipeline_layout;
2052 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2053 ASSERT_VK_SUCCESS(err);
2054
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002055 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002056 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2057 // but add it to be able to run on more devices
Tony Barbour4e8d1b12015-08-04 17:05:26 -06002058 VkPipelineObj pipe(m_device);
2059 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002060 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06002061 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002062
Tony Barbour1490c912015-07-28 10:17:20 -06002063 BeginCommandBuffer();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002064 ASSERT_VK_SUCCESS(err);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06002065 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002066 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06002067 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002068
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002069 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002070 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
Tobin Ehlise4076782015-06-24 15:53:07 -06002071 if (!strstr(msgString.c_str(),"Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.")) {
2072 FAIL() << "Error received was not 'Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002073 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002074
2075 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
2076 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2077 ASSERT_VK_SUCCESS(err);
2078 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2079 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002080}
2081
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002082TEST_F(VkLayerTest, IdxBufferAlignmentError)
2083{
2084 // Bind a BeginRenderPass within an active RenderPass
2085 VkFlags msgFlags;
2086 std::string msgString;
2087 VkResult err;
2088
2089 ASSERT_NO_FATAL_FAILURE(InitState());
2090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2091 m_errorMonitor->ClearState();
2092 uint32_t qfi = 0;
2093 VkBufferCreateInfo buffCI = {};
2094 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2095 buffCI.size = 1024;
2096 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
2097 buffCI.queueFamilyCount = 1;
2098 buffCI.pQueueFamilyIndices = &qfi;
2099
2100 VkBuffer ib;
2101 err = vkCreateBuffer(m_device->device(), &buffCI, &ib);
2102 ASSERT_VK_SUCCESS(err);
2103
2104 BeginCommandBuffer();
2105 ASSERT_VK_SUCCESS(err);
2106 //vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2107 // Should error before calling to driver so don't care about actual data
2108 vkCmdBindIndexBuffer(m_cmdBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
2109
2110 msgFlags = m_errorMonitor->GetState(&msgString);
2111 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2112 if (!strstr(msgString.c_str(),"vkCmdBindIndexBuffer() offset (0x7) does not fall on ")) {
2113 FAIL() << "Error received was not 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...' but instead '" << msgString.c_str() << "'";
2114 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002115
2116 vkDestroyBuffer(m_device->device(), ib);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002117}
2118
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002119TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
2120{
2121 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
2122 VkFlags msgFlags;
2123 std::string msgString;
2124
2125 ASSERT_NO_FATAL_FAILURE(InitState());
2126 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2127 m_errorMonitor->ClearState();
2128
2129 BeginCommandBuffer();
2130 //ASSERT_VK_SUCCESS(err);
2131 VkCmdBuffer primCB = m_cmdBuffer->GetBufferHandle();
2132 vkCmdExecuteCommands(m_cmdBuffer->GetBufferHandle(), 1, &primCB);
2133
2134 msgFlags = m_errorMonitor->GetState(&msgString);
2135 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2136 if (!strstr(msgString.c_str(),"vkCmdExecuteCommands() called w/ Primary Cmd Buffer ")) {
2137 FAIL() << "Error received was not 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer ' but instead '" << msgString.c_str() << "'";
2138 }
2139}
2140
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002141TEST_F(VkLayerTest, DSTypeMismatch)
2142{
2143 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002144 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002145 std::string msgString;
2146 VkResult err;
2147
2148 ASSERT_NO_FATAL_FAILURE(InitState());
2149 m_errorMonitor->ClearState();
2150 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002151 VkDescriptorTypeCount ds_type_count = {};
2152 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2153 ds_type_count.count = 1;
2154
2155 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2156 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2157 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002158 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2159 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002160 ds_pool_ci.count = 1;
2161 ds_pool_ci.pTypeCount = &ds_type_count;
2162
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002163 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002164 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002165 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002166 VkDescriptorSetLayoutBinding dsl_binding = {};
2167 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2168 dsl_binding.arraySize = 1;
2169 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2170 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002171
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002172 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2173 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2174 ds_layout_ci.pNext = NULL;
2175 ds_layout_ci.count = 1;
2176 ds_layout_ci.pBinding = &dsl_binding;
2177
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002178 VkDescriptorSetLayout ds_layout;
2179 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2180 ASSERT_VK_SUCCESS(err);
2181
2182 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002183 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002184 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002185
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002186 VkSamplerCreateInfo sampler_ci = {};
2187 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2188 sampler_ci.pNext = NULL;
2189 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2190 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2191 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002192 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2193 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2194 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002195 sampler_ci.mipLodBias = 1.0;
2196 sampler_ci.maxAnisotropy = 1;
2197 sampler_ci.compareEnable = VK_FALSE;
2198 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2199 sampler_ci.minLod = 1.0;
2200 sampler_ci.maxLod = 1.0;
2201 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002202 sampler_ci.unnormalizedCoordinates = VK_FALSE;
2203
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002204 VkSampler sampler;
2205 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2206 ASSERT_VK_SUCCESS(err);
2207
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002208 VkDescriptorInfo descriptor_info;
2209 memset(&descriptor_info, 0, sizeof(descriptor_info));
2210 descriptor_info.sampler = sampler;
2211
2212 VkWriteDescriptorSet descriptor_write;
2213 memset(&descriptor_write, 0, sizeof(descriptor_write));
2214 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2215 descriptor_write.destSet = descriptorSet;
2216 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002217 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002218 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2219 descriptor_write.pDescriptors = &descriptor_info;
2220
2221 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2222
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002223 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002224 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating BUFFER Descriptor w/ incorrect type of SAMPLER.";
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002225 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) {
2226 FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match overlapping binding type!'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002227 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002228
2229 vkDestroySampler(m_device->device(), sampler);
2230 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2231 ASSERT_VK_SUCCESS(err);
2232 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2233 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002234}
2235
2236TEST_F(VkLayerTest, DSUpdateOutOfBounds)
2237{
2238 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002239 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002240 std::string msgString;
2241 VkResult err;
2242
2243 ASSERT_NO_FATAL_FAILURE(InitState());
2244 m_errorMonitor->ClearState();
2245 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002246 VkDescriptorTypeCount ds_type_count = {};
2247 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2248 ds_type_count.count = 1;
2249
2250 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2251 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2252 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002253 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2254 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002255 ds_pool_ci.count = 1;
2256 ds_pool_ci.pTypeCount = &ds_type_count;
2257
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002258 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002259 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002260 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002261
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002262 VkDescriptorSetLayoutBinding dsl_binding = {};
2263 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2264 dsl_binding.arraySize = 1;
2265 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2266 dsl_binding.pImmutableSamplers = NULL;
2267
2268 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2269 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2270 ds_layout_ci.pNext = NULL;
2271 ds_layout_ci.count = 1;
2272 ds_layout_ci.pBinding = &dsl_binding;
2273
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002274 VkDescriptorSetLayout ds_layout;
2275 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2276 ASSERT_VK_SUCCESS(err);
2277
2278 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002279 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002280 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002281
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002282 VkSamplerCreateInfo sampler_ci = {};
2283 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2284 sampler_ci.pNext = NULL;
2285 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2286 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2287 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002288 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2289 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2290 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002291 sampler_ci.mipLodBias = 1.0;
2292 sampler_ci.maxAnisotropy = 1;
2293 sampler_ci.compareEnable = VK_FALSE;
2294 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2295 sampler_ci.minLod = 1.0;
2296 sampler_ci.maxLod = 1.0;
2297 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002298 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002299
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002300 VkSampler sampler;
2301 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2302 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002303
2304 VkDescriptorInfo descriptor_info;
2305 memset(&descriptor_info, 0, sizeof(descriptor_info));
2306 descriptor_info.sampler = sampler;
2307
2308 VkWriteDescriptorSet descriptor_write;
2309 memset(&descriptor_write, 0, sizeof(descriptor_write));
2310 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2311 descriptor_write.destSet = descriptorSet;
2312 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
2313 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002314 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002315 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2316 descriptor_write.pDescriptors = &descriptor_info;
2317
2318 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2319
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002320 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002321 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ index out of bounds.";
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002322 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
2323 FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002324 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002325
2326 vkDestroySampler(m_device->device(), sampler);
2327 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2328 ASSERT_VK_SUCCESS(err);
2329 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2330 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002331}
2332
2333TEST_F(VkLayerTest, InvalidDSUpdateIndex)
2334{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002335 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002336 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002337 std::string msgString;
2338 VkResult err;
2339
2340 ASSERT_NO_FATAL_FAILURE(InitState());
2341 m_errorMonitor->ClearState();
2342 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002343 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 Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002350 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2351 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002352 ds_pool_ci.count = 1;
2353 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002354
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002355 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002356 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002357 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002358
Tony Barbourefbe9ca2015-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;
2364
2365 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;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002370 VkDescriptorSetLayout ds_layout;
2371 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2372 ASSERT_VK_SUCCESS(err);
2373
2374 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002375 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002376 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002377
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002378 VkSamplerCreateInfo sampler_ci = {};
2379 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2380 sampler_ci.pNext = NULL;
2381 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2382 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2383 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002384 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2385 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2386 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002387 sampler_ci.mipLodBias = 1.0;
2388 sampler_ci.maxAnisotropy = 1;
2389 sampler_ci.compareEnable = VK_FALSE;
2390 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2391 sampler_ci.minLod = 1.0;
2392 sampler_ci.maxLod = 1.0;
2393 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002394 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002395
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002396 VkSampler sampler;
2397 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2398 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002399
2400 VkDescriptorInfo descriptor_info;
2401 memset(&descriptor_info, 0, sizeof(descriptor_info));
2402 descriptor_info.sampler = sampler;
2403
2404 VkWriteDescriptorSet descriptor_write;
2405 memset(&descriptor_write, 0, sizeof(descriptor_write));
2406 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2407 descriptor_write.destSet = descriptorSet;
2408 descriptor_write.destBinding = 2;
2409 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002410 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002411 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2412 descriptor_write.pDescriptors = &descriptor_info;
2413
2414 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2415
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002416 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002417 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ count too large for layout.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002418 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
2419 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
2420 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002421
2422 vkDestroySampler(m_device->device(), sampler);
2423 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2424 ASSERT_VK_SUCCESS(err);
2425 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2426 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002427}
2428
2429TEST_F(VkLayerTest, InvalidDSUpdateStruct)
2430{
2431 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002432 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002433 std::string msgString;
2434 VkResult err;
2435
2436 ASSERT_NO_FATAL_FAILURE(InitState());
2437 m_errorMonitor->ClearState();
2438 //VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002439
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002440 VkDescriptorTypeCount ds_type_count = {};
2441 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2442 ds_type_count.count = 1;
2443
2444 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2445 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2446 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002447 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2448 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002449 ds_pool_ci.count = 1;
2450 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002451
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002452 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002453 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002454 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002455 VkDescriptorSetLayoutBinding dsl_binding = {};
2456 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2457 dsl_binding.arraySize = 1;
2458 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2459 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002460
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002461 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2462 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2463 ds_layout_ci.pNext = NULL;
2464 ds_layout_ci.count = 1;
2465 ds_layout_ci.pBinding = &dsl_binding;
2466
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002467 VkDescriptorSetLayout ds_layout;
2468 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2469 ASSERT_VK_SUCCESS(err);
2470
2471 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002472 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002473 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002474
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002475 VkSamplerCreateInfo sampler_ci = {};
2476 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2477 sampler_ci.pNext = NULL;
2478 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2479 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2480 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002481 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2482 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2483 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002484 sampler_ci.mipLodBias = 1.0;
2485 sampler_ci.maxAnisotropy = 1;
2486 sampler_ci.compareEnable = VK_FALSE;
2487 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2488 sampler_ci.minLod = 1.0;
2489 sampler_ci.maxLod = 1.0;
2490 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002491 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002492 VkSampler sampler;
2493 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2494 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002495
2496
2497 VkDescriptorInfo descriptor_info;
2498 memset(&descriptor_info, 0, sizeof(descriptor_info));
2499 descriptor_info.sampler = sampler;
2500
2501 VkWriteDescriptorSet descriptor_write;
2502 memset(&descriptor_write, 0, sizeof(descriptor_write));
2503 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
2504 descriptor_write.destSet = descriptorSet;
2505 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002506 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002507 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2508 descriptor_write.pDescriptors = &descriptor_info;
2509
2510 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2511
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002512 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002513 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ invalid struct type.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002514 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
2515 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
2516 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002517
2518 vkDestroySampler(m_device->device(), sampler);
2519 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2520 ASSERT_VK_SUCCESS(err);
2521 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2522 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002523}
2524
2525TEST_F(VkLayerTest, NumSamplesMismatch)
2526{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002527 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002528 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002529 std::string msgString;
2530 VkResult err;
2531
2532 ASSERT_NO_FATAL_FAILURE(InitState());
2533 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2534 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002535 VkDescriptorTypeCount ds_type_count = {};
2536 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2537 ds_type_count.count = 1;
2538
2539 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002540 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2541 ds_pool_ci.pNext = NULL;
2542 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2543 ds_pool_ci.maxSets = 1;
2544 ds_pool_ci.count = 1;
2545 ds_pool_ci.pTypeCount = &ds_type_count;
2546
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002547 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002548 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002549 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002550
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002551 VkDescriptorSetLayoutBinding dsl_binding = {};
2552 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2553 dsl_binding.arraySize = 1;
2554 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2555 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002556
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002557 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2558 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2559 ds_layout_ci.pNext = NULL;
2560 ds_layout_ci.count = 1;
2561 ds_layout_ci.pBinding = &dsl_binding;
2562
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002563 VkDescriptorSetLayout ds_layout;
2564 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2565 ASSERT_VK_SUCCESS(err);
2566
2567 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002568 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002569 ASSERT_VK_SUCCESS(err);
2570
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002571 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2572 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2573 pipe_ms_state_ci.pNext = NULL;
2574 pipe_ms_state_ci.rasterSamples = 4;
2575 pipe_ms_state_ci.sampleShadingEnable = 0;
2576 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002577 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002578
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002579 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2580 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2581 pipeline_layout_ci.pNext = NULL;
2582 pipeline_layout_ci.descriptorSetCount = 1;
2583 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002584
2585 VkPipelineLayout pipeline_layout;
2586 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2587 ASSERT_VK_SUCCESS(err);
2588
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002589 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002590 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2591 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002592 VkPipelineObj pipe(m_device);
2593 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002594 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002595 pipe.SetMSAA(&pipe_ms_state_ci);
2596 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002597
Tony Barbour1490c912015-07-28 10:17:20 -06002598 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06002599 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002600
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002601 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002602 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding RenderPass w/ mismatched MSAA from PSO.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002603 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
2604 FAIL() << "Error received was not 'Num samples mismatch!...'";
2605 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002606
2607 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
2608 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2609 ASSERT_VK_SUCCESS(err);
2610 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2611 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002612}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002613
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002614TEST_F(VkLayerTest, ClearCmdNoDraw)
2615{
2616 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
2617 VkFlags msgFlags;
2618 std::string msgString;
2619 VkResult err;
2620
2621 ASSERT_NO_FATAL_FAILURE(InitState());
2622 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2623 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002624
2625 VkDescriptorTypeCount ds_type_count = {};
2626 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2627 ds_type_count.count = 1;
2628
2629 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2630 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2631 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002632 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2633 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002634 ds_pool_ci.count = 1;
2635 ds_pool_ci.pTypeCount = &ds_type_count;
2636
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002637 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002638 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002639 ASSERT_VK_SUCCESS(err);
2640
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002641 VkDescriptorSetLayoutBinding dsl_binding = {};
2642 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2643 dsl_binding.arraySize = 1;
2644 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2645 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002646
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002647 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2648 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2649 ds_layout_ci.pNext = NULL;
2650 ds_layout_ci.count = 1;
2651 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002652
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002653 VkDescriptorSetLayout ds_layout;
2654 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2655 ASSERT_VK_SUCCESS(err);
2656
2657 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002658 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002659 ASSERT_VK_SUCCESS(err);
2660
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002661 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2662 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2663 pipe_ms_state_ci.pNext = NULL;
2664 pipe_ms_state_ci.rasterSamples = 4;
2665 pipe_ms_state_ci.sampleShadingEnable = 0;
2666 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002667 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002668
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002669 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2670 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2671 pipeline_layout_ci.pNext = NULL;
2672 pipeline_layout_ci.descriptorSetCount = 1;
2673 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002674
2675 VkPipelineLayout pipeline_layout;
2676 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2677 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002678
Tony Barbourd7d828b2015-08-06 10:16:07 -06002679 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002680 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2681 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002682 VkPipelineObj pipe(m_device);
2683 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002684 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002685 pipe.SetMSAA(&pipe_ms_state_ci);
2686 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002687
2688 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002689
2690 m_errorMonitor->ClearState();
2691 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
2692 // Also pass down other dummy params to keep driver and paramchecker happy
2693 VkClearColorValue cCV;
Cody Northrop2563a032015-08-25 15:26:38 -06002694 cCV.float32[0] = 1.0;
2695 cCV.float32[1] = 1.0;
2696 cCV.float32[2] = 1.0;
2697 cCV.float32[3] = 1.0;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002698
Tony Barbour1490c912015-07-28 10:17:20 -06002699 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002700 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002701 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not receive error after issuing Clear Cmd on FB color attachment prior to Draw Cmd.";
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002702 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) {
2703 FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'";
2704 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002705
2706 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
2707 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2708 ASSERT_VK_SUCCESS(err);
2709 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2710 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002711}
2712
Tobin Ehlise4076782015-06-24 15:53:07 -06002713TEST_F(VkLayerTest, VtxBufferBadIndex)
2714{
2715 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
2716 VkFlags msgFlags;
2717 std::string msgString;
2718 VkResult err;
2719
2720 ASSERT_NO_FATAL_FAILURE(InitState());
2721 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2722 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002723
2724 VkDescriptorTypeCount ds_type_count = {};
2725 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2726 ds_type_count.count = 1;
2727
2728 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2729 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2730 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002731 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2732 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002733 ds_pool_ci.count = 1;
2734 ds_pool_ci.pTypeCount = &ds_type_count;
2735
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002736 VkDescriptorPool ds_pool;
2737 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06002738 ASSERT_VK_SUCCESS(err);
2739
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002740 VkDescriptorSetLayoutBinding dsl_binding = {};
2741 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2742 dsl_binding.arraySize = 1;
2743 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2744 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002745
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002746 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2747 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2748 ds_layout_ci.pNext = NULL;
2749 ds_layout_ci.count = 1;
2750 ds_layout_ci.pBinding = &dsl_binding;
2751
Tobin Ehlise4076782015-06-24 15:53:07 -06002752 VkDescriptorSetLayout ds_layout;
2753 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2754 ASSERT_VK_SUCCESS(err);
2755
2756 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002757 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06002758 ASSERT_VK_SUCCESS(err);
2759
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002760 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2761 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2762 pipe_ms_state_ci.pNext = NULL;
2763 pipe_ms_state_ci.rasterSamples = 1;
2764 pipe_ms_state_ci.sampleShadingEnable = 0;
2765 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002766 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002767
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002768 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2769 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2770 pipeline_layout_ci.pNext = NULL;
2771 pipeline_layout_ci.descriptorSetCount = 1;
2772 pipeline_layout_ci.pSetLayouts = &ds_layout;
2773 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06002774
Tobin Ehlise4076782015-06-24 15:53:07 -06002775 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2776 ASSERT_VK_SUCCESS(err);
2777
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002778 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002779 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2780 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002781 VkPipelineObj pipe(m_device);
2782 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002783 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002784 pipe.SetMSAA(&pipe_ms_state_ci);
2785 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002786
2787 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06002788 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002789 // Don't care about actual data, just need to get to draw to flag error
2790 static const float vbo_data[3] = {1.f, 0.f, 1.f};
2791 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
2792 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002793 Draw(1, 0, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06002794
2795 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002796 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding Vtx Buffer w/o VBO attached to PSO.";
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002797 if (!strstr(msgString.c_str(),"Vtx Buffer Index 1 was bound, but no vtx buffers are attached to PSO.")) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002798 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
2799 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002800
2801 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
2802 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2803 ASSERT_VK_SUCCESS(err);
2804 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2805 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06002806}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002807#endif // DRAW_STATE_TESTS
2808
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002809#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06002810#if GTEST_IS_THREADSAFE
2811struct thread_data_struct {
2812 VkCmdBuffer cmdBuffer;
2813 VkEvent event;
2814 bool bailout;
2815};
2816
2817extern "C" void *AddToCommandBuffer(void *arg)
2818{
2819 struct thread_data_struct *data = (struct thread_data_struct *) arg;
2820 std::string msgString;
2821
2822 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06002823 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06002824 if (data->bailout) {
2825 break;
2826 }
2827 }
2828 return NULL;
2829}
2830
2831TEST_F(VkLayerTest, ThreadCmdBufferCollision)
2832{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002833 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06002834 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002835 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06002836
2837 ASSERT_NO_FATAL_FAILURE(InitState());
2838 ASSERT_NO_FATAL_FAILURE(InitViewport());
2839 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2840
Mike Stroyan09aae812015-05-12 16:00:45 -06002841 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06002842 BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002843
2844 VkEventCreateInfo event_info;
2845 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06002846 VkResult err;
2847
2848 memset(&event_info, 0, sizeof(event_info));
2849 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2850
2851 err = vkCreateEvent(device(), &event_info, &event);
2852 ASSERT_VK_SUCCESS(err);
2853
Mike Stroyan09aae812015-05-12 16:00:45 -06002854 err = vkResetEvent(device(), event);
2855 ASSERT_VK_SUCCESS(err);
2856
2857 struct thread_data_struct data;
Tony Barbour1490c912015-07-28 10:17:20 -06002858 data.cmdBuffer = m_cmdBuffer->handle();
Mike Stroyan09aae812015-05-12 16:00:45 -06002859 data.event = event;
2860 data.bailout = false;
2861 m_errorMonitor->SetBailout(&data.bailout);
2862 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002863 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06002864 // Add many entries to command buffer from this thread at the same time.
2865 AddToCommandBuffer(&data);
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002866 test_platform_thread_join(thread, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -06002867 EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002868
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002869 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002870 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err from using one VkCommandBufferObj in two threads";
Mike Stroyan09aae812015-05-12 16:00:45 -06002871 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05002872 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06002873 }
2874
Mike Stroyan2237f522015-08-18 14:40:24 -06002875 vkDestroyEvent(device(), event);
Mike Stroyan09aae812015-05-12 16:00:45 -06002876}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002877#endif // GTEST_IS_THREADSAFE
2878#endif // THREADING_TESTS
2879
Chris Forbes5af3bf22015-05-25 11:13:08 +12002880#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06002881TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
2882{
2883 VkFlags msgFlags;
2884 std::string msgString;
2885 ASSERT_NO_FATAL_FAILURE(InitState());
2886 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2887
2888 m_errorMonitor->ClearState();
2889
2890 VkShaderModule module;
2891 VkShaderModuleCreateInfo moduleCreateInfo;
2892 struct icd_spv_header spv;
2893
2894 spv.magic = ICD_SPV_MAGIC;
2895 spv.version = ICD_SPV_VERSION;
2896 spv.gen_magic = 0;
2897
2898 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2899 moduleCreateInfo.pNext = NULL;
2900 moduleCreateInfo.pCode = &spv;
2901 moduleCreateInfo.codeSize = 4;
2902 moduleCreateInfo.flags = 0;
2903 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
2904
2905 msgFlags = m_errorMonitor->GetState(&msgString);
2906
Chris Forbes96b81762015-09-18 11:40:23 +12002907 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06002908 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
2909 FAIL() << "Incorrect warning: " << msgString;
2910 }
2911}
2912
2913TEST_F(VkLayerTest, InvalidSPIRVMagic)
2914{
2915 VkFlags msgFlags;
2916 std::string msgString;
2917 ASSERT_NO_FATAL_FAILURE(InitState());
2918 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2919
2920 m_errorMonitor->ClearState();
2921
2922 VkShaderModule module;
2923 VkShaderModuleCreateInfo moduleCreateInfo;
2924 struct icd_spv_header spv;
2925
2926 spv.magic = ~ICD_SPV_MAGIC;
2927 spv.version = ICD_SPV_VERSION;
2928 spv.gen_magic = 0;
2929
2930 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2931 moduleCreateInfo.pNext = NULL;
2932 moduleCreateInfo.pCode = &spv;
2933 moduleCreateInfo.codeSize = sizeof(spv) + 10;
2934 moduleCreateInfo.flags = 0;
2935 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
2936
2937 msgFlags = m_errorMonitor->GetState(&msgString);
2938
Chris Forbes96b81762015-09-18 11:40:23 +12002939 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06002940 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
2941 FAIL() << "Incorrect warning: " << msgString;
2942 }
2943}
2944
2945TEST_F(VkLayerTest, InvalidSPIRVVersion)
2946{
2947 VkFlags msgFlags;
2948 std::string msgString;
2949 ASSERT_NO_FATAL_FAILURE(InitState());
2950 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2951
2952 m_errorMonitor->ClearState();
2953
2954 VkShaderModule module;
2955 VkShaderModuleCreateInfo moduleCreateInfo;
2956 struct icd_spv_header spv;
2957
2958 spv.magic = ICD_SPV_MAGIC;
2959 spv.version = ~ICD_SPV_VERSION;
2960 spv.gen_magic = 0;
2961
2962 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2963 moduleCreateInfo.pNext = NULL;
2964
2965 moduleCreateInfo.pCode = &spv;
2966 moduleCreateInfo.codeSize = sizeof(spv) + 10;
2967 moduleCreateInfo.flags = 0;
2968 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
2969
2970 msgFlags = m_errorMonitor->GetState(&msgString);
2971
Chris Forbes96b81762015-09-18 11:40:23 +12002972 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06002973 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
2974 FAIL() << "Incorrect warning: " << msgString;
2975 }
2976}
2977
Chris Forbes5af3bf22015-05-25 11:13:08 +12002978TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
2979{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002980 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12002981 std::string msgString;
2982 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002983 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12002984
2985 char const *vsSource =
2986 "#version 140\n"
2987 "#extension GL_ARB_separate_shader_objects: require\n"
2988 "#extension GL_ARB_shading_language_420pack: require\n"
2989 "\n"
2990 "layout(location=0) out float x;\n"
2991 "void main(){\n"
2992 " gl_Position = vec4(1);\n"
2993 " x = 0;\n"
2994 "}\n";
2995 char const *fsSource =
2996 "#version 140\n"
2997 "#extension GL_ARB_separate_shader_objects: require\n"
2998 "#extension GL_ARB_shading_language_420pack: require\n"
2999 "\n"
3000 "layout(location=0) out vec4 color;\n"
3001 "void main(){\n"
3002 " color = vec4(1);\n"
3003 "}\n";
3004
3005 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3006 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3007
3008 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003009 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12003010 pipe.AddShader(&vs);
3011 pipe.AddShader(&fs);
3012
Chris Forbes5af3bf22015-05-25 11:13:08 +12003013 VkDescriptorSetObj descriptorSet(m_device);
3014 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003015 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003016
3017 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003018 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12003019
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003020 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003021
Cody Northrop1684adb2015-08-05 11:15:02 -06003022 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003023 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
3024 FAIL() << "Incorrect warning: " << msgString;
3025 }
3026}
Chris Forbes5af3bf22015-05-25 11:13:08 +12003027
Chris Forbes3c10b852015-05-25 11:13:13 +12003028TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
3029{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003030 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12003031 std::string msgString;
3032 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003033 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12003034
3035 char const *vsSource =
3036 "#version 140\n"
3037 "#extension GL_ARB_separate_shader_objects: require\n"
3038 "#extension GL_ARB_shading_language_420pack: require\n"
3039 "\n"
3040 "void main(){\n"
3041 " gl_Position = vec4(1);\n"
3042 "}\n";
3043 char const *fsSource =
3044 "#version 140\n"
3045 "#extension GL_ARB_separate_shader_objects: require\n"
3046 "#extension GL_ARB_shading_language_420pack: require\n"
3047 "\n"
3048 "layout(location=0) in float x;\n"
3049 "layout(location=0) out vec4 color;\n"
3050 "void main(){\n"
3051 " color = vec4(x);\n"
3052 "}\n";
3053
3054 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3055 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3056
3057 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003058 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12003059 pipe.AddShader(&vs);
3060 pipe.AddShader(&fs);
3061
Chris Forbes3c10b852015-05-25 11:13:13 +12003062 VkDescriptorSetObj descriptorSet(m_device);
3063 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003064 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12003065
3066 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003067 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12003068
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003069 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12003070
Cody Northrop1684adb2015-08-05 11:15:02 -06003071 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes3c10b852015-05-25 11:13:13 +12003072 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
3073 FAIL() << "Incorrect error: " << msgString;
3074 }
3075}
3076
Chris Forbescc281692015-05-25 11:13:17 +12003077TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
3078{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003079 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12003080 std::string msgString;
3081 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12003083
3084 char const *vsSource =
3085 "#version 140\n"
3086 "#extension GL_ARB_separate_shader_objects: require\n"
3087 "#extension GL_ARB_shading_language_420pack: require\n"
3088 "\n"
3089 "layout(location=0) out int x;\n"
3090 "void main(){\n"
3091 " x = 0;\n"
3092 " gl_Position = vec4(1);\n"
3093 "}\n";
3094 char const *fsSource =
3095 "#version 140\n"
3096 "#extension GL_ARB_separate_shader_objects: require\n"
3097 "#extension GL_ARB_shading_language_420pack: require\n"
3098 "\n"
3099 "layout(location=0) in float x;\n" /* VS writes int */
3100 "layout(location=0) out vec4 color;\n"
3101 "void main(){\n"
3102 " color = vec4(x);\n"
3103 "}\n";
3104
3105 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3106 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3107
3108 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003109 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12003110 pipe.AddShader(&vs);
3111 pipe.AddShader(&fs);
3112
Chris Forbescc281692015-05-25 11:13:17 +12003113 VkDescriptorSetObj descriptorSet(m_device);
3114 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003115 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12003116
3117 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003118 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12003119
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003120 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12003121
Cody Northrop1684adb2015-08-05 11:15:02 -06003122 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbescc281692015-05-25 11:13:17 +12003123 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
3124 FAIL() << "Incorrect error: " << msgString;
3125 }
3126}
3127
Chris Forbes8291c052015-05-25 11:13:28 +12003128TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
3129{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003130 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12003131 std::string msgString;
3132 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003133 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12003134
3135 VkVertexInputBindingDescription input_binding;
3136 memset(&input_binding, 0, sizeof(input_binding));
3137
3138 VkVertexInputAttributeDescription input_attrib;
3139 memset(&input_attrib, 0, sizeof(input_attrib));
3140 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3141
3142 char const *vsSource =
3143 "#version 140\n"
3144 "#extension GL_ARB_separate_shader_objects: require\n"
3145 "#extension GL_ARB_shading_language_420pack: require\n"
3146 "\n"
3147 "void main(){\n"
3148 " gl_Position = vec4(1);\n"
3149 "}\n";
3150 char const *fsSource =
3151 "#version 140\n"
3152 "#extension GL_ARB_separate_shader_objects: require\n"
3153 "#extension GL_ARB_shading_language_420pack: require\n"
3154 "\n"
3155 "layout(location=0) out vec4 color;\n"
3156 "void main(){\n"
3157 " color = vec4(1);\n"
3158 "}\n";
3159
3160 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3161 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3162
3163 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003164 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12003165 pipe.AddShader(&vs);
3166 pipe.AddShader(&fs);
3167
3168 pipe.AddVertexInputBindings(&input_binding, 1);
3169 pipe.AddVertexInputAttribs(&input_attrib, 1);
3170
Chris Forbes8291c052015-05-25 11:13:28 +12003171 VkDescriptorSetObj descriptorSet(m_device);
3172 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003173 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12003174
3175 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003176 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12003177
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003178 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12003179
Cody Northrop1684adb2015-08-05 11:15:02 -06003180 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12003181 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
3182 FAIL() << "Incorrect warning: " << msgString;
3183 }
3184}
3185
Chris Forbes37367e62015-05-25 11:13:29 +12003186TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
3187{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003188 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12003189 std::string msgString;
3190 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003191 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12003192
3193 char const *vsSource =
3194 "#version 140\n"
3195 "#extension GL_ARB_separate_shader_objects: require\n"
3196 "#extension GL_ARB_shading_language_420pack: require\n"
3197 "\n"
3198 "layout(location=0) in vec4 x;\n" /* not provided */
3199 "void main(){\n"
3200 " gl_Position = x;\n"
3201 "}\n";
3202 char const *fsSource =
3203 "#version 140\n"
3204 "#extension GL_ARB_separate_shader_objects: require\n"
3205 "#extension GL_ARB_shading_language_420pack: require\n"
3206 "\n"
3207 "layout(location=0) out vec4 color;\n"
3208 "void main(){\n"
3209 " color = vec4(1);\n"
3210 "}\n";
3211
3212 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3213 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3214
3215 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003216 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12003217 pipe.AddShader(&vs);
3218 pipe.AddShader(&fs);
3219
Chris Forbes37367e62015-05-25 11:13:29 +12003220 VkDescriptorSetObj descriptorSet(m_device);
3221 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003222 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12003223
3224 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003225 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12003226
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003227 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12003228
Cody Northrop1684adb2015-08-05 11:15:02 -06003229 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes37367e62015-05-25 11:13:29 +12003230 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
3231 FAIL() << "Incorrect warning: " << msgString;
3232 }
3233}
3234
Chris Forbesa4b02322015-05-25 11:13:31 +12003235TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
3236{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003237 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12003238 std::string msgString;
3239 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003240 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12003241
3242 VkVertexInputBindingDescription input_binding;
3243 memset(&input_binding, 0, sizeof(input_binding));
3244
3245 VkVertexInputAttributeDescription input_attrib;
3246 memset(&input_attrib, 0, sizeof(input_attrib));
3247 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3248
3249 char const *vsSource =
3250 "#version 140\n"
3251 "#extension GL_ARB_separate_shader_objects: require\n"
3252 "#extension GL_ARB_shading_language_420pack: require\n"
3253 "\n"
3254 "layout(location=0) in int x;\n" /* attrib provided float */
3255 "void main(){\n"
3256 " gl_Position = vec4(x);\n"
3257 "}\n";
3258 char const *fsSource =
3259 "#version 140\n"
3260 "#extension GL_ARB_separate_shader_objects: require\n"
3261 "#extension GL_ARB_shading_language_420pack: require\n"
3262 "\n"
3263 "layout(location=0) out vec4 color;\n"
3264 "void main(){\n"
3265 " color = vec4(1);\n"
3266 "}\n";
3267
3268 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3269 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3270
3271 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003272 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12003273 pipe.AddShader(&vs);
3274 pipe.AddShader(&fs);
3275
3276 pipe.AddVertexInputBindings(&input_binding, 1);
3277 pipe.AddVertexInputAttribs(&input_attrib, 1);
3278
Chris Forbesa4b02322015-05-25 11:13:31 +12003279 VkDescriptorSetObj descriptorSet(m_device);
3280 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003281 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12003282
3283 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003284 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12003285
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003286 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12003287
Cody Northrop1684adb2015-08-05 11:15:02 -06003288 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa4b02322015-05-25 11:13:31 +12003289 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
3290 FAIL() << "Incorrect error: " << msgString;
3291 }
3292}
3293
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003294TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
3295{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003296 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003297 std::string msgString;
3298 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003300
3301 /* Two binding descriptions for binding 0 */
3302 VkVertexInputBindingDescription input_bindings[2];
3303 memset(input_bindings, 0, sizeof(input_bindings));
3304
3305 VkVertexInputAttributeDescription input_attrib;
3306 memset(&input_attrib, 0, sizeof(input_attrib));
3307 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3308
3309 char const *vsSource =
3310 "#version 140\n"
3311 "#extension GL_ARB_separate_shader_objects: require\n"
3312 "#extension GL_ARB_shading_language_420pack: require\n"
3313 "\n"
3314 "layout(location=0) in float x;\n" /* attrib provided float */
3315 "void main(){\n"
3316 " gl_Position = vec4(x);\n"
3317 "}\n";
3318 char const *fsSource =
3319 "#version 140\n"
3320 "#extension GL_ARB_separate_shader_objects: require\n"
3321 "#extension GL_ARB_shading_language_420pack: require\n"
3322 "\n"
3323 "layout(location=0) out vec4 color;\n"
3324 "void main(){\n"
3325 " color = vec4(1);\n"
3326 "}\n";
3327
3328 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3329 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3330
3331 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003332 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003333 pipe.AddShader(&vs);
3334 pipe.AddShader(&fs);
3335
3336 pipe.AddVertexInputBindings(input_bindings, 2);
3337 pipe.AddVertexInputAttribs(&input_attrib, 1);
3338
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003339 VkDescriptorSetObj descriptorSet(m_device);
3340 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003341 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003342
3343 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003344 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003345
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003346 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003347
Cody Northrop1684adb2015-08-05 11:15:02 -06003348 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003349 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
3350 FAIL() << "Incorrect error: " << msgString;
3351 }
3352}
Chris Forbes4c948702015-05-25 11:13:32 +12003353
Chris Forbesc12ef122015-05-25 11:13:40 +12003354/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
3355 * rejects it. */
3356
3357TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
3358{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003359 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12003360 std::string msgString;
3361 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12003362
3363 char const *vsSource =
3364 "#version 140\n"
3365 "#extension GL_ARB_separate_shader_objects: require\n"
3366 "#extension GL_ARB_shading_language_420pack: require\n"
3367 "\n"
3368 "void main(){\n"
3369 " gl_Position = vec4(1);\n"
3370 "}\n";
3371 char const *fsSource =
3372 "#version 140\n"
3373 "#extension GL_ARB_separate_shader_objects: require\n"
3374 "#extension GL_ARB_shading_language_420pack: require\n"
3375 "\n"
3376 "void main(){\n"
3377 "}\n";
3378
3379 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3380 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3381
3382 VkPipelineObj pipe(m_device);
3383 pipe.AddShader(&vs);
3384 pipe.AddShader(&fs);
3385
Chia-I Wuc278df82015-07-07 11:50:03 +08003386 /* set up CB 0, not written */
3387 pipe.AddColorAttachment();
3388 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12003389
Chris Forbesc12ef122015-05-25 11:13:40 +12003390 VkDescriptorSetObj descriptorSet(m_device);
3391 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003392 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12003393
3394 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003395 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12003396
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003397 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12003398
Cody Northrop1684adb2015-08-05 11:15:02 -06003399 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc12ef122015-05-25 11:13:40 +12003400 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
3401 FAIL() << "Incorrect error: " << msgString;
3402 }
3403}
3404
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003405TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
3406{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003407 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003408 std::string msgString;
3409 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003410
3411 char const *vsSource =
3412 "#version 140\n"
3413 "#extension GL_ARB_separate_shader_objects: require\n"
3414 "#extension GL_ARB_shading_language_420pack: require\n"
3415 "\n"
3416 "void main(){\n"
3417 " gl_Position = vec4(1);\n"
3418 "}\n";
3419 char const *fsSource =
3420 "#version 140\n"
3421 "#extension GL_ARB_separate_shader_objects: require\n"
3422 "#extension GL_ARB_shading_language_420pack: require\n"
3423 "\n"
3424 "layout(location=0) out vec4 x;\n"
3425 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
3426 "void main(){\n"
3427 " x = vec4(1);\n"
3428 " y = vec4(1);\n"
3429 "}\n";
3430
3431 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3432 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3433
3434 VkPipelineObj pipe(m_device);
3435 pipe.AddShader(&vs);
3436 pipe.AddShader(&fs);
3437
Chia-I Wuc278df82015-07-07 11:50:03 +08003438 /* set up CB 0, not written */
3439 pipe.AddColorAttachment();
3440 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003441 /* FS writes CB 1, but we don't configure it */
3442
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003443 VkDescriptorSetObj descriptorSet(m_device);
3444 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003445 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003446
3447 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003448 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003449
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003450 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003451
Cody Northrop1684adb2015-08-05 11:15:02 -06003452 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003453 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
3454 FAIL() << "Incorrect warning: " << msgString;
3455 }
3456}
3457
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003458TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
3459{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003460 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003461 std::string msgString;
3462 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003463
3464 char const *vsSource =
3465 "#version 140\n"
3466 "#extension GL_ARB_separate_shader_objects: require\n"
3467 "#extension GL_ARB_shading_language_420pack: require\n"
3468 "\n"
3469 "void main(){\n"
3470 " gl_Position = vec4(1);\n"
3471 "}\n";
3472 char const *fsSource =
3473 "#version 140\n"
3474 "#extension GL_ARB_separate_shader_objects: require\n"
3475 "#extension GL_ARB_shading_language_420pack: require\n"
3476 "\n"
3477 "layout(location=0) out ivec4 x;\n" /* not UNORM */
3478 "void main(){\n"
3479 " x = ivec4(1);\n"
3480 "}\n";
3481
3482 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3483 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3484
3485 VkPipelineObj pipe(m_device);
3486 pipe.AddShader(&vs);
3487 pipe.AddShader(&fs);
3488
Chia-I Wuc278df82015-07-07 11:50:03 +08003489 /* set up CB 0; type is UNORM by default */
3490 pipe.AddColorAttachment();
3491 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003492
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003493 VkDescriptorSetObj descriptorSet(m_device);
3494 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003495 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003496
3497 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003498 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003499
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003500 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003501
Cody Northrop1684adb2015-08-05 11:15:02 -06003502 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003503 if (!strstr(msgString.c_str(),"does not match FS output type")) {
3504 FAIL() << "Incorrect error: " << msgString;
3505 }
3506}
Chris Forbesc2050732015-06-05 14:43:36 +12003507
Chris Forbes76ce7882015-08-14 12:04:59 +12003508TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
3509{
3510 VkFlags msgFlags;
3511 std::string msgString;
3512 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +12003513
3514 char const *vsSource =
3515 "#version 140\n"
3516 "#extension GL_ARB_separate_shader_objects: require\n"
3517 "#extension GL_ARB_shading_language_420pack: require\n"
3518 "\n"
3519 "void main(){\n"
3520 " gl_Position = vec4(1);\n"
3521 "}\n";
3522 char const *fsSource =
3523 "#version 140\n"
3524 "#extension GL_ARB_separate_shader_objects: require\n"
3525 "#extension GL_ARB_shading_language_420pack: require\n"
3526 "\n"
3527 "layout(location=0) out vec4 x;\n"
3528 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
3529 "void main(){\n"
3530 " x = vec4(bar.y);\n"
3531 "}\n";
3532
3533 m_errorMonitor->ClearState();
3534
3535 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3536 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3537
3538
3539 VkPipelineObj pipe(m_device);
3540 pipe.AddShader(&vs);
3541 pipe.AddShader(&fs);
3542
3543 /* set up CB 0; type is UNORM by default */
3544 pipe.AddColorAttachment();
3545 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3546
3547 VkDescriptorSetObj descriptorSet(m_device);
3548 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
3549
3550 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3551
3552 /* should have generated an error -- pipeline layout does not
3553 * provide a uniform buffer in 0.0
3554 */
3555 msgFlags = m_errorMonitor->GetState(&msgString);
3556 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
3557 if (!strstr(msgString.c_str(),"not declared in pipeline layout")) {
3558 FAIL() << "Incorrect error: " << msgString;
3559 }
3560}
3561
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003562#endif // SHADER_CHECKER_TESTS
3563
3564#if DEVICE_LIMITS_TESTS
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06003565TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
3566{
3567 VkFlags msgFlags;
3568 std::string msgString;
3569
3570 ASSERT_NO_FATAL_FAILURE(InitState());
3571 m_errorMonitor->ClearState();
3572
3573 // Create an image
3574 VkImage image;
3575
3576 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3577 const int32_t tex_width = 32;
3578 const int32_t tex_height = 32;
3579
3580 VkImageCreateInfo image_create_info = {};
3581 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3582 image_create_info.pNext = NULL;
3583 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3584 image_create_info.format = tex_format;
3585 image_create_info.extent.width = tex_width;
3586 image_create_info.extent.height = tex_height;
3587 image_create_info.extent.depth = 1;
3588 image_create_info.mipLevels = 1;
3589 image_create_info.arraySize = 1;
3590 image_create_info.samples = 1;
3591 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3592 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3593 image_create_info.flags = 0;
3594
3595 // Introduce error by sending down a bogus width extent
3596 image_create_info.extent.width = 65536;
3597 vkCreateImage(m_device->device(), &image_create_info, &image);
3598
3599 msgFlags = m_errorMonitor->GetState(&msgString);
3600 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
3601 "with extents outside the queried limits";
3602 if (!strstr(msgString.c_str(),"CreateImage extents exceed allowable limits for format")) {
3603 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
3604 }
3605}
3606
3607TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
3608{
3609 VkFlags msgFlags;
3610 std::string msgString;
3611
3612 ASSERT_NO_FATAL_FAILURE(InitState());
3613 m_errorMonitor->ClearState();
3614
3615 // Create an image
3616 VkImage image;
3617
3618 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3619 const int32_t tex_width = 32;
3620 const int32_t tex_height = 32;
3621
3622 VkImageCreateInfo image_create_info = {};
3623 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3624 image_create_info.pNext = NULL;
3625 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3626 image_create_info.format = tex_format;
3627 image_create_info.extent.width = tex_width;
3628 image_create_info.extent.height = tex_height;
3629 image_create_info.extent.depth = 1;
3630 image_create_info.mipLevels = 1;
3631 image_create_info.arraySize = 1;
3632 image_create_info.samples = 1;
3633 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3634 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3635 image_create_info.flags = 0;
3636
3637 // Introduce error by sending down individually allowable values that result in a surface size
3638 // exceeding the device maximum
3639 image_create_info.extent.width = 8192;
3640 image_create_info.extent.height = 8192;
3641 image_create_info.extent.depth = 16;
3642 image_create_info.arraySize = 4;
3643 image_create_info.samples = 2;
3644 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
3645 vkCreateImage(m_device->device(), &image_create_info, &image);
3646
3647 msgFlags = m_errorMonitor->GetState(&msgString);
3648 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
3649 "with resource size exceeding queried limit";
3650 if (!strstr(msgString.c_str(),"CreateImage resource size exceeds allowable maximum")) {
3651 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
3652 }
3653}
3654
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003655#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003656
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06003657#if IMAGE_TESTS
3658TEST_F(VkLayerTest, InvalidImageView)
3659{
3660 VkFlags msgFlags;
3661 std::string msgString;
3662 VkResult err;
3663
3664 ASSERT_NO_FATAL_FAILURE(InitState());
3665 m_errorMonitor->ClearState();
3666
3667 // Create an image, allocate memory, free it, and then try to bind it
3668 VkImage image;
3669
3670 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3671 const int32_t tex_width = 32;
3672 const int32_t tex_height = 32;
3673
3674 VkImageCreateInfo image_create_info = {};
3675 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3676 image_create_info.pNext = NULL;
3677 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3678 image_create_info.format = tex_format;
3679 image_create_info.extent.width = tex_width;
3680 image_create_info.extent.height = tex_height;
3681 image_create_info.extent.depth = 1;
3682 image_create_info.mipLevels = 1;
3683 image_create_info.arraySize = 1;
3684 image_create_info.samples = 1;
3685 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3686 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3687 image_create_info.flags = 0;
3688
3689 err = vkCreateImage(m_device->device(), &image_create_info, &image);
3690 ASSERT_VK_SUCCESS(err);
3691
3692 VkImageViewCreateInfo image_view_create_info = {};
3693 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3694 image_view_create_info.image = image;
3695 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
3696 image_view_create_info.format = tex_format;
3697 image_view_create_info.subresourceRange.arraySize = 1;
3698 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
3699 image_view_create_info.subresourceRange.mipLevels = 1;
3700
3701 VkImageView view;
3702 err = vkCreateImageView(m_device->device(), &image_view_create_info, &view);
3703
3704 msgFlags = m_errorMonitor->GetState(&msgString);
3705 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an invalid ImageView";
3706 if (!strstr(msgString.c_str(),"vkCreateImageView called with baseMipLevel 10 ")) {
3707 FAIL() << "Error received was not 'vkCreateImageView called with baseMipLevel 10...' but instaed '" << msgString.c_str() << "'";
3708 }
3709}
3710#endif // IMAGE_TESTS
3711
Tony Barbour30486ea2015-04-07 13:44:53 -06003712int main(int argc, char **argv) {
3713 int result;
3714
3715 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06003716 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06003717
3718 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
3719
3720 result = RUN_ALL_TESTS();
3721
Tony Barbour01999182015-04-09 12:58:51 -06003722 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06003723 return result;
3724}