blob: 929e1de604fb9bb0cba2dd1949fd379d1079636a [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);
Tobin Ehlisc2033a02015-10-01 10:14:48 -0600742 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_WARN_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";
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06001069 // TODO : Viewport and scissor currently set as a pair in framework so scissor error masks viewport error
1070 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1071 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001072 }
1073}
1074
1075TEST_F(VkLayerTest, ScissorStateNotBound)
1076{
1077 VkFlags msgFlags;
1078 std::string msgString;
1079 m_errorMonitor->ClearState();
1080 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1081
1082 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1083
1084 msgFlags = m_errorMonitor->GetState(&msgString);
1085 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
1086 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1087 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
1088 }
1089}
1090
1091
1092TEST_F(VkLayerTest, BlendStateNotBound)
1093{
1094 VkFlags msgFlags;
1095 std::string msgString;
1096 m_errorMonitor->ClearState();
1097 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1098
1099 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1100
1101 msgFlags = m_errorMonitor->GetState(&msgString);
1102 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Blend State Object";
1103 if (!strstr(msgString.c_str(),"Dynamic blend object state not set for this command buffer")) {
1104 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic blend object state not set for this command buffer'";
1105 }
1106}
1107
1108TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1109{
1110 VkFlags msgFlags;
1111 std::string msgString;
1112 m_errorMonitor->ClearState();
1113 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1114
1115 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1116
1117 msgFlags = m_errorMonitor->GetState(&msgString);
1118 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bounds State Object";
1119 if (!strstr(msgString.c_str(),"Dynamic depth bounds state not set for this command buffer")) {
1120 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bounds state not set for this command buffer'";
1121 }
1122}
1123
1124TEST_F(VkLayerTest, StencilReadMaskNotSet)
1125{
1126 VkFlags msgFlags;
1127 std::string msgString;
1128 ASSERT_NO_FATAL_FAILURE(InitState());
1129 m_errorMonitor->ClearState();
1130 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1131
1132 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1133
1134 msgFlags = m_errorMonitor->GetState(&msgString);
1135 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Read Mask";
1136 if (!strstr(msgString.c_str(),"Dynamic stencil read mask state not set for this command buffer")) {
1137 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil read mask state not set for this command buffer'";
1138 }
1139}
1140
1141TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1142{
1143 VkFlags msgFlags;
1144 std::string msgString;
1145 ASSERT_NO_FATAL_FAILURE(InitState());
1146 m_errorMonitor->ClearState();
1147 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1148
1149 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1150
1151 msgFlags = m_errorMonitor->GetState(&msgString);
1152 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Write Mask";
1153 if (!strstr(msgString.c_str(),"Dynamic stencil write mask state not set for this command buffer")) {
1154 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil write mask state not set for this command buffer'";
1155 }
1156}
1157
1158TEST_F(VkLayerTest, StencilReferenceNotSet)
1159{
1160 VkFlags msgFlags;
1161 std::string msgString;
1162 m_errorMonitor->ClearState();
1163 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1164
1165 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1166
1167 msgFlags = m_errorMonitor->GetState(&msgString);
1168 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Reference";
1169 if (!strstr(msgString.c_str(),"Dynamic stencil reference state not set for this command buffer")) {
1170 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil reference state not set for this command buffer'";
1171 }
1172}
1173
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001174TEST_F(VkLayerTest, CmdBufferTwoSubmits)
1175{
1176 vk_testing::Fence testFence;
1177 VkFlags msgFlags;
1178 std::string msgString;
1179
1180 VkFenceCreateInfo fenceInfo = {};
1181 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1182 fenceInfo.pNext = NULL;
1183 fenceInfo.flags = 0;
1184
1185 ASSERT_NO_FATAL_FAILURE(InitState());
1186 ASSERT_NO_FATAL_FAILURE(InitViewport());
1187 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1188
1189 // We luck out b/c by default the framework creates CB w/ the VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set
1190 BeginCommandBuffer();
1191 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
1192 EndCommandBuffer();
1193
1194 testFence.init(*m_device, fenceInfo);
1195
1196 // Bypass framework since it does the waits automatically
1197 VkResult err = VK_SUCCESS;
1198 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
1199 ASSERT_VK_SUCCESS( err );
1200
1201 m_errorMonitor->ClearState();
1202 // Cause validation error by re-submitting cmd buffer that should only be submitted once
1203 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001204
1205 msgFlags = m_errorMonitor->GetState(&msgString);
1206 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 -06001207 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 -06001208 FAIL() << "Error received was not 'CB (0xaddress) was created w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set...'";
1209 }
1210}
1211
Tobin Ehlise4076782015-06-24 15:53:07 -06001212TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001213{
1214 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001215 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001216 std::string msgString;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001217 VkResult err;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001218
1219 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001220 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001221 m_errorMonitor->ClearState();
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001222
1223 VkDescriptorTypeCount ds_type_count = {};
1224 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1225 ds_type_count.count = 1;
1226
1227 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1228 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1229 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001230 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1231 ds_pool_ci.maxSets = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001232 ds_pool_ci.count = 1;
1233 ds_pool_ci.pTypeCount = &ds_type_count;
1234
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001235 VkDescriptorPool ds_pool;
1236 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001237 ASSERT_VK_SUCCESS(err);
1238
1239 VkDescriptorSetLayoutBinding dsl_binding = {};
1240 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1241 dsl_binding.arraySize = 1;
1242 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1243 dsl_binding.pImmutableSamplers = NULL;
1244
1245 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1246 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1247 ds_layout_ci.pNext = NULL;
1248 ds_layout_ci.count = 1;
1249 ds_layout_ci.pBinding = &dsl_binding;
1250
1251 VkDescriptorSetLayout ds_layout;
1252 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1253 ASSERT_VK_SUCCESS(err);
1254
1255 VkDescriptorSet descriptorSet;
1256 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1257 ASSERT_VK_SUCCESS(err);
1258 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1259 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1260 pipe_ms_state_ci.pNext = NULL;
1261 pipe_ms_state_ci.rasterSamples = 1;
1262 pipe_ms_state_ci.sampleShadingEnable = 0;
1263 pipe_ms_state_ci.minSampleShading = 1.0;
1264 pipe_ms_state_ci.pSampleMask = NULL;
1265
1266 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1267 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1268 pipeline_layout_ci.pNext = NULL;
1269 pipeline_layout_ci.descriptorSetCount = 1;
1270 pipeline_layout_ci.pSetLayouts = &ds_layout;
1271 VkPipelineLayout pipeline_layout;
1272
1273 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1274 ASSERT_VK_SUCCESS(err);
1275
1276 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
1277 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1278 // but add it to be able to run on more devices
1279 VkPipelineObj pipe(m_device);
1280 pipe.AddShader(&vs);
1281 pipe.AddShader(&fs);
1282 pipe.SetMSAA(&pipe_ms_state_ci);
1283 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1284 m_errorMonitor->ClearState();
1285 // Calls CreateCommandBuffer
1286 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1287 VkCmdBufferBeginInfo cmd_buf_info = {};
1288 memset(&cmd_buf_info, 0, sizeof(VkCmdBufferBeginInfo));
1289 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1290 cmd_buf_info.pNext = NULL;
1291 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1292 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1293
1294 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1295 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001296 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001297 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 -06001298 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001299 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0x<handle>) without an active RenderPass'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001300 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001301
1302 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
1303 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1304 ASSERT_VK_SUCCESS(err);
1305 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1306 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001307}
1308
1309TEST_F(VkLayerTest, InvalidDescriptorPool)
1310{
1311 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1312 // The DS check for this is after driver has been called to validate DS internal data struct
1313 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001314/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001315 std::string msgString;
1316 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1317 vkResetDescriptorPool(device(), badPool);
1318
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001319 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001320 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 -06001321 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1322 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1323 }*/
1324}
1325
1326TEST_F(VkLayerTest, InvalidDescriptorSet)
1327{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001328 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1329 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001330 // Create a valid cmd buffer
1331 // call vkCmdBindDescriptorSets w/ false DS
1332}
1333
1334TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1335{
1336 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1337 // The DS check for this is after driver has been called to validate DS internal data struct
1338}
1339
1340TEST_F(VkLayerTest, InvalidPipeline)
1341{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001342 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1343 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001344 // Create a valid cmd buffer
1345 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -06001346// VkFlags msgFlags;
1347// std::string msgString;
1348//
1349// ASSERT_NO_FATAL_FAILURE(InitState());
1350// m_errorMonitor->ClearState();
1351// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001352// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001353// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1354// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1355// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001356// 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 -06001357// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1358// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1359// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001360}
1361
Tobin Ehlis254eca02015-06-25 15:46:59 -06001362TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001363{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001364 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001365 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001366 std::string msgString;
1367 VkResult err;
1368
1369 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001370 ASSERT_NO_FATAL_FAILURE(InitViewport());
1371 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001372 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001373 VkDescriptorTypeCount ds_type_count = {};
1374 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1375 ds_type_count.count = 1;
1376
1377 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1378 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1379 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001380 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1381 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001382 ds_pool_ci.count = 1;
1383 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001384
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001385 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001386 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001387 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001388
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001389 VkDescriptorSetLayoutBinding dsl_binding = {};
1390 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1391 dsl_binding.arraySize = 1;
1392 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1393 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001394
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001395 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1396 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1397 ds_layout_ci.pNext = NULL;
1398 ds_layout_ci.count = 1;
1399 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001400 VkDescriptorSetLayout ds_layout;
1401 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1402 ASSERT_VK_SUCCESS(err);
1403
1404 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001405 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001406 ASSERT_VK_SUCCESS(err);
1407
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001408 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1409 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1410 pipeline_layout_ci.pNext = NULL;
1411 pipeline_layout_ci.descriptorSetCount = 1;
1412 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001413
1414 VkPipelineLayout pipeline_layout;
1415 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1416 ASSERT_VK_SUCCESS(err);
1417
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001418 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001419 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1420 // but add it to be able to run on more devices
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001421
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001422 VkPipelineObj pipe(m_device);
1423 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001424 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001425 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001426
1427 BeginCommandBuffer();
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001428 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbour1490c912015-07-28 10:17:20 -06001429 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001430
Tobin Ehlis254eca02015-06-25 15:46:59 -06001431 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001432 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 -06001433 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1434 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1435 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001436
1437 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
1438 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1439 ASSERT_VK_SUCCESS(err);
1440 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1441 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001442}
1443
1444TEST_F(VkLayerTest, NoBeginCmdBuffer)
1445{
1446 VkFlags msgFlags;
1447 std::string msgString;
1448
1449 ASSERT_NO_FATAL_FAILURE(InitState());
1450 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001451 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001452 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1453 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1454 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001455 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 -06001456 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1457 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1458 }
1459}
1460
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001461TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1462{
1463 VkFlags msgFlags;
1464 std::string msgString;
1465
1466 ASSERT_NO_FATAL_FAILURE(InitState());
1467 m_errorMonitor->ClearState();
1468
1469 // Calls CreateCommandBuffer
1470 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1471
1472 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northrop10d8f982015-08-04 17:35:57 -06001473 VkCmdBufferBeginInfo cmd_buf_info = {};
1474 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1475 cmd_buf_info.pNext = NULL;
1476 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1477 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1478 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1479 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1480
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001481
1482 // The error should be caught by validation of the BeginCommandBuffer call
1483 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1484
1485 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001486 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 -06001487 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1488 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1489 }
1490}
1491
1492TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1493{
1494 VkFlags msgFlags;
1495 std::string msgString;
1496 VkResult err;
1497 VkCmdBuffer draw_cmd;
1498 VkCmdPool cmd_pool;
1499
1500 ASSERT_NO_FATAL_FAILURE(InitState());
1501 m_errorMonitor->ClearState();
1502
Cody Northrop10d8f982015-08-04 17:35:57 -06001503 VkCmdBufferCreateInfo cmd = {};
1504 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1505 cmd.pNext = NULL;
1506 cmd.cmdPool = m_cmdPool;
1507 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1508 cmd.flags = 0;
1509
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001510 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
Mike Stroyan2237f522015-08-18 14:40:24 -06001511 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001512
1513 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northrop10d8f982015-08-04 17:35:57 -06001514 VkCmdBufferBeginInfo cmd_buf_info = {};
1515 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1516 cmd_buf_info.pNext = NULL;
1517 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1518 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001519
1520 // The error should be caught by validation of the BeginCommandBuffer call
1521 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1522
1523 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001524 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 -06001525 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1526 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1527 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001528 vkDestroyCommandBuffer(m_device->device(), draw_cmd);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001529}
1530
Tobin Ehlis254eca02015-06-25 15:46:59 -06001531TEST_F(VkLayerTest, InvalidPipelineCreateState)
1532{
1533 // Attempt to Create Gfx Pipeline w/o a VS
1534 VkFlags msgFlags;
1535 std::string msgString;
1536 VkResult err;
1537
1538 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001539 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis254eca02015-06-25 15:46:59 -06001540 m_errorMonitor->ClearState();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001541
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001542 VkDescriptorTypeCount ds_type_count = {};
1543 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1544 ds_type_count.count = 1;
1545
1546 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1547 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1548 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001549 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1550 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001551 ds_pool_ci.count = 1;
1552 ds_pool_ci.pTypeCount = &ds_type_count;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001553
Tobin Ehlis254eca02015-06-25 15:46:59 -06001554 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001555 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001556 ASSERT_VK_SUCCESS(err);
1557
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001558 VkDescriptorSetLayoutBinding dsl_binding = {};
1559 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1560 dsl_binding.arraySize = 1;
1561 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1562 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001563
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001564 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1565 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1566 ds_layout_ci.pNext = NULL;
1567 ds_layout_ci.count = 1;
1568 ds_layout_ci.pBinding = &dsl_binding;
1569
Tobin Ehlis254eca02015-06-25 15:46:59 -06001570 VkDescriptorSetLayout ds_layout;
1571 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1572 ASSERT_VK_SUCCESS(err);
1573
1574 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001575 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001576 ASSERT_VK_SUCCESS(err);
1577
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001578 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1579 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1580 pipeline_layout_ci.pNext = NULL;
1581 pipeline_layout_ci.descriptorSetCount = 1;
1582 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001583
1584 VkPipelineLayout pipeline_layout;
1585 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1586 ASSERT_VK_SUCCESS(err);
1587
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001588 VkGraphicsPipelineCreateInfo gp_ci = {};
1589 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1590 gp_ci.pNext = NULL;
1591 gp_ci.stageCount = 0;
1592 gp_ci.pStages = NULL;
1593 gp_ci.pVertexInputState = NULL;
1594 gp_ci.pInputAssemblyState = NULL;
1595 gp_ci.pTessellationState = NULL;
1596 gp_ci.pViewportState = NULL;
1597 gp_ci.pRasterState = NULL;
1598 gp_ci.pMultisampleState = NULL;
1599 gp_ci.pDepthStencilState = NULL;
1600 gp_ci.pColorBlendState = NULL;
1601 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1602 gp_ci.layout = pipeline_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001603 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001604
1605 VkPipelineCacheCreateInfo pc_ci = {};
1606 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1607 pc_ci.pNext = NULL;
1608 pc_ci.initialSize = 0;
1609 pc_ci.initialData = 0;
1610 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001611
1612 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001613 VkPipelineCache pipelineCache;
1614
1615 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1616 ASSERT_VK_SUCCESS(err);
1617 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001618
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001619 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001620 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 -06001621 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1622 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1623 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001624
1625 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1626 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
1627 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1628 ASSERT_VK_SUCCESS(err);
1629 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1630 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001631}
Tobin Ehlis20693172015-09-17 08:46:18 -06001632/*// TODO : This test should be good, but needs Tess support in compiler to run
1633TEST_F(VkLayerTest, InvalidPatchControlPoints)
1634{
1635 // Attempt to Create Gfx Pipeline w/o a VS
1636 VkFlags msgFlags;
1637 std::string msgString;
1638 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001639
Tobin Ehlis20693172015-09-17 08:46:18 -06001640 ASSERT_NO_FATAL_FAILURE(InitState());
1641 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1642 m_errorMonitor->ClearState();
1643
1644 VkDescriptorTypeCount ds_type_count = {};
1645 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1646 ds_type_count.count = 1;
1647
1648 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1649 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1650 ds_pool_ci.pNext = NULL;
1651 ds_pool_ci.count = 1;
1652 ds_pool_ci.pTypeCount = &ds_type_count;
1653
1654 VkDescriptorPool ds_pool;
1655 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1656 ASSERT_VK_SUCCESS(err);
1657
1658 VkDescriptorSetLayoutBinding dsl_binding = {};
1659 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1660 dsl_binding.arraySize = 1;
1661 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1662 dsl_binding.pImmutableSamplers = NULL;
1663
1664 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1665 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1666 ds_layout_ci.pNext = NULL;
1667 ds_layout_ci.count = 1;
1668 ds_layout_ci.pBinding = &dsl_binding;
1669
1670 VkDescriptorSetLayout ds_layout;
1671 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1672 ASSERT_VK_SUCCESS(err);
1673
1674 VkDescriptorSet descriptorSet;
1675 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1676 ASSERT_VK_SUCCESS(err);
1677
1678 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1679 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1680 pipeline_layout_ci.pNext = NULL;
1681 pipeline_layout_ci.descriptorSetCount = 1;
1682 pipeline_layout_ci.pSetLayouts = &ds_layout;
1683
1684 VkPipelineLayout pipeline_layout;
1685 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1686 ASSERT_VK_SUCCESS(err);
1687
1688 VkPipelineShaderStageCreateInfo shaderStages[3];
1689 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
1690
1691 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
1692 // Just using VS txt for Tess shaders as we don't care about functionality
1693 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESS_CONTROL, this);
1694 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESS_EVALUATION, this);
1695
1696 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1697 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
1698 shaderStages[0].shader = vs.handle();
1699 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1700 shaderStages[1].stage = VK_SHADER_STAGE_TESS_CONTROL;
1701 shaderStages[1].shader = tc.handle();
1702 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1703 shaderStages[2].stage = VK_SHADER_STAGE_TESS_EVALUATION;
1704 shaderStages[2].shader = te.handle();
1705
1706 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
1707 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
1708 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH;
1709
1710 VkPipelineTessellationStateCreateInfo tsCI = {};
1711 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
1712 tsCI.patchControlPoints = 0; // This will cause an error
1713
1714 VkGraphicsPipelineCreateInfo gp_ci = {};
1715 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1716 gp_ci.pNext = NULL;
1717 gp_ci.stageCount = 3;
1718 gp_ci.pStages = shaderStages;
1719 gp_ci.pVertexInputState = NULL;
1720 gp_ci.pInputAssemblyState = &iaCI;
1721 gp_ci.pTessellationState = &tsCI;
1722 gp_ci.pViewportState = NULL;
1723 gp_ci.pRasterState = NULL;
1724 gp_ci.pMultisampleState = NULL;
1725 gp_ci.pDepthStencilState = NULL;
1726 gp_ci.pColorBlendState = NULL;
1727 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1728 gp_ci.layout = pipeline_layout;
1729 gp_ci.renderPass = renderPass();
1730
1731 VkPipelineCacheCreateInfo pc_ci = {};
1732 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1733 pc_ci.pNext = NULL;
1734 pc_ci.initialSize = 0;
1735 pc_ci.initialData = 0;
1736 pc_ci.maxSize = 0;
1737
1738 VkPipeline pipeline;
1739 VkPipelineCache pipelineCache;
1740
1741 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1742 ASSERT_VK_SUCCESS(err);
1743 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1744
1745 msgFlags = m_errorMonitor->GetState(&msgString);
1746 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Tess Gfx Pipeline w/ 0 patchControlPoints.";
1747 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ")) {
1748 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...' but instead '" << msgString.c_str() << "'";
1749 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001750
1751 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1752 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
1753 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1754 ASSERT_VK_SUCCESS(err);
1755 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1756 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis20693172015-09-17 08:46:18 -06001757}
1758*/
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001759TEST_F(VkLayerTest, NullRenderPass)
1760{
1761 // Bind a NULL RenderPass
1762 VkFlags msgFlags;
1763 std::string msgString;
1764
1765 ASSERT_NO_FATAL_FAILURE(InitState());
1766 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1767 m_errorMonitor->ClearState();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001768
Tony Barbour1490c912015-07-28 10:17:20 -06001769 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001770 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06001771 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001772
1773 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001774 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001775 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
1776 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
1777 }
1778}
1779
Tobin Ehlis254eca02015-06-25 15:46:59 -06001780TEST_F(VkLayerTest, RenderPassWithinRenderPass)
1781{
1782 // Bind a BeginRenderPass within an active RenderPass
1783 VkFlags msgFlags;
1784 std::string msgString;
1785
1786 ASSERT_NO_FATAL_FAILURE(InitState());
1787 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1788 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001789
Tony Barbour1490c912015-07-28 10:17:20 -06001790 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001791 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001792 VkRenderPassBeginInfo rp_begin = {};
1793 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
1794 rp_begin.pNext = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001795 rp_begin.renderPass = renderPass();
1796 rp_begin.framebuffer = framebuffer();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001797
Tony Barbour1490c912015-07-28 10:17:20 -06001798 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001799
1800 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001801 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 -06001802 if (!strstr(msgString.c_str(),"Cannot call vkCmdBeginRenderPass() during an active RenderPass ")) {
1803 FAIL() << "Error received was not 'Cannot call vkCmdBeginRenderPass() during an active RenderPass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001804 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001805}
1806
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06001807TEST_F(VkLayerTest, FillBufferWithinRenderPass)
1808{
1809 // Call CmdFillBuffer within an active renderpass
1810 VkFlags msgFlags;
1811 std::string msgString;
1812
1813 ASSERT_NO_FATAL_FAILURE(InitState());
1814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1815 m_errorMonitor->ClearState();
1816
1817 // Renderpass is started here
1818 BeginCommandBuffer();
1819
1820 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1821 vk_testing::Buffer destBuffer;
1822 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
1823
1824 m_cmdBuffer->FillBuffer(destBuffer.handle(), 0, 4, 0x11111111);
1825
1826 msgFlags = m_errorMonitor->GetState(&msgString);
1827 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
1828 "Did not receive error after calling CmdFillBuffer w/i an active RenderPass.";
1829 if (!strstr(msgString.c_str(),"CmdFillBuffer cmd issued within an active RenderPass")) {
1830 FAIL() << "Error received was not 'CmdFillBuffer cmd issued within an active RenderPass'";
1831 }
1832}
1833
1834TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
1835{
1836 // Call CmdUpdateBuffer within an active renderpass
1837 VkFlags msgFlags;
1838 std::string msgString;
1839
1840 ASSERT_NO_FATAL_FAILURE(InitState());
1841 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1842 m_errorMonitor->ClearState();
1843
1844 // Renderpass is started here
1845 BeginCommandBuffer();
1846
1847 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1848 vk_testing::Buffer destBuffer;
1849 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
1850
1851 VkDeviceSize destOffset = 0;
1852 VkDeviceSize dataSize = 1024;
1853 const uint32_t *pData = NULL;
1854
1855 vkCmdUpdateBuffer(m_cmdBuffer->GetBufferHandle(), destBuffer.handle(), destOffset, dataSize, pData);
1856
1857 msgFlags = m_errorMonitor->GetState(&msgString);
1858 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
1859 "Did not receive error after calling CmdUpdateBuffer w/i an active RenderPass.";
1860 if (!strstr(msgString.c_str(),"CmdUpdateBuffer cmd issued within an active RenderPass")) {
1861 FAIL() << "Error received was not 'CmdUpdateBuffer cmd issued within an active RenderPass'";
1862 }
1863}
1864
1865TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
1866{
1867 // Call CmdClearColorImage within an active RenderPass
1868 VkFlags msgFlags;
1869 std::string msgString;
1870
1871 ASSERT_NO_FATAL_FAILURE(InitState());
1872 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1873 m_errorMonitor->ClearState();
1874
1875 // Renderpass is started here
1876 BeginCommandBuffer();
1877
1878 VkClearColorValue clear_color = {0};
1879 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1880 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1881 const int32_t tex_width = 32;
1882 const int32_t tex_height = 32;
1883 VkImageCreateInfo image_create_info = {};
1884 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1885 image_create_info.pNext = NULL;
1886 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1887 image_create_info.format = tex_format;
1888 image_create_info.extent.width = tex_width;
1889 image_create_info.extent.height = tex_height;
1890 image_create_info.extent.depth = 1;
1891 image_create_info.mipLevels = 1;
1892 image_create_info.arraySize = 1;
1893 image_create_info.samples = 1;
1894 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1895 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1896
1897 vk_testing::Image destImage;
1898 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
1899
1900 const VkImageSubresourceRange range =
1901 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
1902
1903 vkCmdClearColorImage(m_cmdBuffer->GetBufferHandle(),
1904 destImage.handle(),
1905 VK_IMAGE_LAYOUT_GENERAL,
1906 &clear_color,
1907 1,
1908 &range);
1909
1910 msgFlags = m_errorMonitor->GetState(&msgString);
1911 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
1912 "Did not receive error after calling CmdClearColorImage w/i an active RenderPass.";
1913 if (!strstr(msgString.c_str(),"CmdClearColorImage cmd issued within an active RenderPass")) {
1914 FAIL() << "Error received was not 'CmdClearColorImage cmd issued within an active RenderPass'";
1915 }
1916}
1917
1918TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
1919{
1920 // Call CmdClearDepthStencilImage within an active RenderPass
1921 VkFlags msgFlags;
1922 std::string msgString;
1923
1924 ASSERT_NO_FATAL_FAILURE(InitState());
1925 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1926 m_errorMonitor->ClearState();
1927
1928 // Renderpass is started here
1929 BeginCommandBuffer();
1930
1931 VkClearDepthStencilValue clear_value = {0};
1932 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1933 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
1934 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1935 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
1936 image_create_info.extent.width = 64;
1937 image_create_info.extent.height = 64;
1938 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1939 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1940
1941 vk_testing::Image destImage;
1942 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
1943
1944 const VkImageSubresourceRange range =
1945 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
1946
1947 vkCmdClearDepthStencilImage(m_cmdBuffer->GetBufferHandle(),
1948 destImage.handle(),
1949 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
1950 &clear_value,
1951 1,
1952 &range);
1953
1954 msgFlags = m_errorMonitor->GetState(&msgString);
1955 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
1956 "Did not receive error after calling CmdClearDepthStencilImage w/i an active RenderPass.";
1957 if (!strstr(msgString.c_str(),"CmdClearDepthStencilImage cmd issued within an active RenderPass")) {
1958 FAIL() << "Error received was not 'CmdClearDepthStencilImage cmd issued within an active RenderPass'";
1959 }
1960}
1961
1962TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
1963{
1964 // Call CmdClearColorAttachments outside of an active RenderPass
1965 VkFlags msgFlags;
1966 std::string msgString;
1967 VkResult err;
1968
1969 ASSERT_NO_FATAL_FAILURE(InitState());
1970 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1971 m_errorMonitor->ClearState();
1972
1973 // Start no RenderPass
1974 err = m_cmdBuffer->BeginCommandBuffer();
1975 ASSERT_VK_SUCCESS(err);
1976
1977 VkClearColorValue clear_color = {0};
1978 VkRect3D clear_rect = { { 0, 0, 0 }, { 32, 32, 1 } };
1979
1980 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0,
1981 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
1982 &clear_color, 1, &clear_rect);
1983
1984 msgFlags = m_errorMonitor->GetState(&msgString);
1985 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
1986 "Did not receive error after calling CmdClearColorAttachment outside of an active RenderPass.";
1987 if (!strstr(msgString.c_str(),"CmdClearColorAttachment cmd issued outside of an active RenderPass")) {
1988 FAIL() << "Error received was not 'CmdClearColorAttachment cmd issued outside of an active RenderPass'";
1989 }
1990}
1991
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001992TEST_F(VkLayerTest, InvalidDynamicStateObject)
1993{
1994 // Create a valid cmd buffer
1995 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001996 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1997 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001998}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06001999
Tobin Ehlise4076782015-06-24 15:53:07 -06002000TEST_F(VkLayerTest, VtxBufferNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002001{
2002 // Bind VBO out-of-bounds for given PSO
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002003 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002004 std::string msgString;
2005 VkResult err;
2006
2007 ASSERT_NO_FATAL_FAILURE(InitState());
2008 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002009
2010 VkDescriptorTypeCount ds_type_count = {};
2011 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2012 ds_type_count.count = 1;
2013
2014 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2015 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2016 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002017 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2018 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002019 ds_pool_ci.count = 1;
2020 ds_pool_ci.pTypeCount = &ds_type_count;
2021
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002022 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002023 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002024 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002025
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002026 VkDescriptorSetLayoutBinding dsl_binding = {};
2027 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2028 dsl_binding.arraySize = 1;
2029 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2030 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002031
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002032 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2033 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2034 ds_layout_ci.pNext = NULL;
2035 ds_layout_ci.count = 1;
2036 ds_layout_ci.pBinding = &dsl_binding;
2037
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002038 VkDescriptorSetLayout ds_layout;
2039 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2040 ASSERT_VK_SUCCESS(err);
2041
2042 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002043 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002044 ASSERT_VK_SUCCESS(err);
2045
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002046 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2047 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2048 pipeline_layout_ci.pNext = NULL;
2049 pipeline_layout_ci.descriptorSetCount = 1;
2050 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002051
2052 VkPipelineLayout pipeline_layout;
2053 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2054 ASSERT_VK_SUCCESS(err);
2055
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002056 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002057 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2058 // but add it to be able to run on more devices
Tony Barbour4e8d1b12015-08-04 17:05:26 -06002059 VkPipelineObj pipe(m_device);
2060 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002061 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06002062 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002063
Tony Barbour1490c912015-07-28 10:17:20 -06002064 BeginCommandBuffer();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002065 ASSERT_VK_SUCCESS(err);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06002066 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002067 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06002068 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002069
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002070 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002071 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 -06002072 if (!strstr(msgString.c_str(),"Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.")) {
2073 FAIL() << "Error received was not 'Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002074 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002075
2076 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
2077 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2078 ASSERT_VK_SUCCESS(err);
2079 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2080 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002081}
2082
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002083TEST_F(VkLayerTest, IdxBufferAlignmentError)
2084{
2085 // Bind a BeginRenderPass within an active RenderPass
2086 VkFlags msgFlags;
2087 std::string msgString;
2088 VkResult err;
2089
2090 ASSERT_NO_FATAL_FAILURE(InitState());
2091 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2092 m_errorMonitor->ClearState();
2093 uint32_t qfi = 0;
2094 VkBufferCreateInfo buffCI = {};
2095 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2096 buffCI.size = 1024;
2097 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
2098 buffCI.queueFamilyCount = 1;
2099 buffCI.pQueueFamilyIndices = &qfi;
2100
2101 VkBuffer ib;
2102 err = vkCreateBuffer(m_device->device(), &buffCI, &ib);
2103 ASSERT_VK_SUCCESS(err);
2104
2105 BeginCommandBuffer();
2106 ASSERT_VK_SUCCESS(err);
2107 //vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2108 // Should error before calling to driver so don't care about actual data
2109 vkCmdBindIndexBuffer(m_cmdBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
2110
2111 msgFlags = m_errorMonitor->GetState(&msgString);
2112 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2113 if (!strstr(msgString.c_str(),"vkCmdBindIndexBuffer() offset (0x7) does not fall on ")) {
2114 FAIL() << "Error received was not 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...' but instead '" << msgString.c_str() << "'";
2115 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002116
2117 vkDestroyBuffer(m_device->device(), ib);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002118}
2119
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002120TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
2121{
2122 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
2123 VkFlags msgFlags;
2124 std::string msgString;
2125
2126 ASSERT_NO_FATAL_FAILURE(InitState());
2127 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2128 m_errorMonitor->ClearState();
2129
2130 BeginCommandBuffer();
2131 //ASSERT_VK_SUCCESS(err);
2132 VkCmdBuffer primCB = m_cmdBuffer->GetBufferHandle();
2133 vkCmdExecuteCommands(m_cmdBuffer->GetBufferHandle(), 1, &primCB);
2134
2135 msgFlags = m_errorMonitor->GetState(&msgString);
2136 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2137 if (!strstr(msgString.c_str(),"vkCmdExecuteCommands() called w/ Primary Cmd Buffer ")) {
2138 FAIL() << "Error received was not 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer ' but instead '" << msgString.c_str() << "'";
2139 }
2140}
2141
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002142TEST_F(VkLayerTest, DSTypeMismatch)
2143{
2144 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002145 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002146 std::string msgString;
2147 VkResult err;
2148
2149 ASSERT_NO_FATAL_FAILURE(InitState());
2150 m_errorMonitor->ClearState();
2151 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002152 VkDescriptorTypeCount ds_type_count = {};
2153 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2154 ds_type_count.count = 1;
2155
2156 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2157 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2158 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002159 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2160 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002161 ds_pool_ci.count = 1;
2162 ds_pool_ci.pTypeCount = &ds_type_count;
2163
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002164 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002165 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002166 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002167 VkDescriptorSetLayoutBinding dsl_binding = {};
2168 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2169 dsl_binding.arraySize = 1;
2170 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2171 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002172
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002173 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2174 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2175 ds_layout_ci.pNext = NULL;
2176 ds_layout_ci.count = 1;
2177 ds_layout_ci.pBinding = &dsl_binding;
2178
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002179 VkDescriptorSetLayout ds_layout;
2180 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2181 ASSERT_VK_SUCCESS(err);
2182
2183 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002184 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002185 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002186
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002187 VkSamplerCreateInfo sampler_ci = {};
2188 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2189 sampler_ci.pNext = NULL;
2190 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2191 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2192 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002193 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2194 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2195 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002196 sampler_ci.mipLodBias = 1.0;
2197 sampler_ci.maxAnisotropy = 1;
2198 sampler_ci.compareEnable = VK_FALSE;
2199 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2200 sampler_ci.minLod = 1.0;
2201 sampler_ci.maxLod = 1.0;
2202 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002203 sampler_ci.unnormalizedCoordinates = VK_FALSE;
2204
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002205 VkSampler sampler;
2206 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2207 ASSERT_VK_SUCCESS(err);
2208
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002209 VkDescriptorInfo descriptor_info;
2210 memset(&descriptor_info, 0, sizeof(descriptor_info));
2211 descriptor_info.sampler = sampler;
2212
2213 VkWriteDescriptorSet descriptor_write;
2214 memset(&descriptor_write, 0, sizeof(descriptor_write));
2215 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2216 descriptor_write.destSet = descriptorSet;
2217 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002218 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002219 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2220 descriptor_write.pDescriptors = &descriptor_info;
2221
2222 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2223
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002224 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002225 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating BUFFER Descriptor w/ incorrect type of SAMPLER.";
Tobin Ehlis3b341092015-09-30 08:30:20 -06002226 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match ")) {
2227 FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...' but instead '" << msgString.c_str() << "'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002228 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002229
2230 vkDestroySampler(m_device->device(), sampler);
2231 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2232 ASSERT_VK_SUCCESS(err);
2233 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2234 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002235}
2236
2237TEST_F(VkLayerTest, DSUpdateOutOfBounds)
2238{
2239 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002240 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002241 std::string msgString;
2242 VkResult err;
2243
2244 ASSERT_NO_FATAL_FAILURE(InitState());
2245 m_errorMonitor->ClearState();
2246 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002247 VkDescriptorTypeCount ds_type_count = {};
2248 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2249 ds_type_count.count = 1;
2250
2251 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2252 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2253 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002254 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2255 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002256 ds_pool_ci.count = 1;
2257 ds_pool_ci.pTypeCount = &ds_type_count;
2258
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002259 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002260 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002261 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002262
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002263 VkDescriptorSetLayoutBinding dsl_binding = {};
2264 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2265 dsl_binding.arraySize = 1;
2266 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2267 dsl_binding.pImmutableSamplers = NULL;
2268
2269 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2270 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2271 ds_layout_ci.pNext = NULL;
2272 ds_layout_ci.count = 1;
2273 ds_layout_ci.pBinding = &dsl_binding;
2274
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002275 VkDescriptorSetLayout ds_layout;
2276 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2277 ASSERT_VK_SUCCESS(err);
2278
2279 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002280 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002281 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002282
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002283 VkSamplerCreateInfo sampler_ci = {};
2284 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2285 sampler_ci.pNext = NULL;
2286 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2287 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2288 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002289 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2290 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2291 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002292 sampler_ci.mipLodBias = 1.0;
2293 sampler_ci.maxAnisotropy = 1;
2294 sampler_ci.compareEnable = VK_FALSE;
2295 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2296 sampler_ci.minLod = 1.0;
2297 sampler_ci.maxLod = 1.0;
2298 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002299 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002300
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002301 VkSampler sampler;
2302 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2303 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002304
2305 VkDescriptorInfo descriptor_info;
2306 memset(&descriptor_info, 0, sizeof(descriptor_info));
2307 descriptor_info.sampler = sampler;
2308
2309 VkWriteDescriptorSet descriptor_write;
2310 memset(&descriptor_write, 0, sizeof(descriptor_write));
2311 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2312 descriptor_write.destSet = descriptorSet;
2313 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
2314 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002315 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002316 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2317 descriptor_write.pDescriptors = &descriptor_info;
2318
2319 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2320
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002321 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002322 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 +08002323 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
2324 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 -06002325 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002326
2327 vkDestroySampler(m_device->device(), sampler);
2328 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2329 ASSERT_VK_SUCCESS(err);
2330 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2331 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002332}
2333
2334TEST_F(VkLayerTest, InvalidDSUpdateIndex)
2335{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002336 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002337 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002338 std::string msgString;
2339 VkResult err;
2340
2341 ASSERT_NO_FATAL_FAILURE(InitState());
2342 m_errorMonitor->ClearState();
2343 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002344 VkDescriptorTypeCount ds_type_count = {};
2345 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2346 ds_type_count.count = 1;
2347
2348 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2349 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2350 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002351 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2352 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002353 ds_pool_ci.count = 1;
2354 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002355
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002356 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002357 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002358 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002359
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002360 VkDescriptorSetLayoutBinding dsl_binding = {};
2361 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2362 dsl_binding.arraySize = 1;
2363 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2364 dsl_binding.pImmutableSamplers = NULL;
2365
2366 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2367 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2368 ds_layout_ci.pNext = NULL;
2369 ds_layout_ci.count = 1;
2370 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002371 VkDescriptorSetLayout ds_layout;
2372 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2373 ASSERT_VK_SUCCESS(err);
2374
2375 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002376 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002377 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002378
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002379 VkSamplerCreateInfo sampler_ci = {};
2380 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2381 sampler_ci.pNext = NULL;
2382 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2383 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2384 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002385 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2386 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2387 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002388 sampler_ci.mipLodBias = 1.0;
2389 sampler_ci.maxAnisotropy = 1;
2390 sampler_ci.compareEnable = VK_FALSE;
2391 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2392 sampler_ci.minLod = 1.0;
2393 sampler_ci.maxLod = 1.0;
2394 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002395 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002396
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002397 VkSampler sampler;
2398 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2399 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002400
2401 VkDescriptorInfo descriptor_info;
2402 memset(&descriptor_info, 0, sizeof(descriptor_info));
2403 descriptor_info.sampler = sampler;
2404
2405 VkWriteDescriptorSet descriptor_write;
2406 memset(&descriptor_write, 0, sizeof(descriptor_write));
2407 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2408 descriptor_write.destSet = descriptorSet;
2409 descriptor_write.destBinding = 2;
2410 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002411 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002412 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2413 descriptor_write.pDescriptors = &descriptor_info;
2414
2415 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2416
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002417 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002418 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 -06002419 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
2420 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
2421 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002422
2423 vkDestroySampler(m_device->device(), sampler);
2424 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2425 ASSERT_VK_SUCCESS(err);
2426 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2427 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002428}
2429
2430TEST_F(VkLayerTest, InvalidDSUpdateStruct)
2431{
2432 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002433 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002434 std::string msgString;
2435 VkResult err;
2436
2437 ASSERT_NO_FATAL_FAILURE(InitState());
2438 m_errorMonitor->ClearState();
2439 //VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002440
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002441 VkDescriptorTypeCount ds_type_count = {};
2442 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2443 ds_type_count.count = 1;
2444
2445 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2446 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2447 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002448 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2449 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002450 ds_pool_ci.count = 1;
2451 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002452
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002453 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002454 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002455 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002456 VkDescriptorSetLayoutBinding dsl_binding = {};
2457 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2458 dsl_binding.arraySize = 1;
2459 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2460 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002461
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002462 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2463 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2464 ds_layout_ci.pNext = NULL;
2465 ds_layout_ci.count = 1;
2466 ds_layout_ci.pBinding = &dsl_binding;
2467
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002468 VkDescriptorSetLayout ds_layout;
2469 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2470 ASSERT_VK_SUCCESS(err);
2471
2472 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002473 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002474 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002475
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002476 VkSamplerCreateInfo sampler_ci = {};
2477 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2478 sampler_ci.pNext = NULL;
2479 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2480 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2481 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002482 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2483 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2484 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002485 sampler_ci.mipLodBias = 1.0;
2486 sampler_ci.maxAnisotropy = 1;
2487 sampler_ci.compareEnable = VK_FALSE;
2488 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2489 sampler_ci.minLod = 1.0;
2490 sampler_ci.maxLod = 1.0;
2491 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002492 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002493 VkSampler sampler;
2494 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2495 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002496
2497
2498 VkDescriptorInfo descriptor_info;
2499 memset(&descriptor_info, 0, sizeof(descriptor_info));
2500 descriptor_info.sampler = sampler;
2501
2502 VkWriteDescriptorSet descriptor_write;
2503 memset(&descriptor_write, 0, sizeof(descriptor_write));
2504 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
2505 descriptor_write.destSet = descriptorSet;
2506 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002507 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002508 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2509 descriptor_write.pDescriptors = &descriptor_info;
2510
2511 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2512
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002513 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002514 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 -06002515 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
2516 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
2517 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002518
2519 vkDestroySampler(m_device->device(), sampler);
2520 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2521 ASSERT_VK_SUCCESS(err);
2522 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2523 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002524}
2525
2526TEST_F(VkLayerTest, NumSamplesMismatch)
2527{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002528 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002529 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002530 std::string msgString;
2531 VkResult err;
2532
2533 ASSERT_NO_FATAL_FAILURE(InitState());
2534 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2535 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002536 VkDescriptorTypeCount ds_type_count = {};
2537 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2538 ds_type_count.count = 1;
2539
2540 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002541 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2542 ds_pool_ci.pNext = NULL;
2543 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2544 ds_pool_ci.maxSets = 1;
2545 ds_pool_ci.count = 1;
2546 ds_pool_ci.pTypeCount = &ds_type_count;
2547
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002548 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002549 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002550 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002551
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002552 VkDescriptorSetLayoutBinding dsl_binding = {};
2553 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2554 dsl_binding.arraySize = 1;
2555 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2556 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002557
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002558 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2559 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2560 ds_layout_ci.pNext = NULL;
2561 ds_layout_ci.count = 1;
2562 ds_layout_ci.pBinding = &dsl_binding;
2563
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002564 VkDescriptorSetLayout ds_layout;
2565 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2566 ASSERT_VK_SUCCESS(err);
2567
2568 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002569 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002570 ASSERT_VK_SUCCESS(err);
2571
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002572 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2573 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2574 pipe_ms_state_ci.pNext = NULL;
2575 pipe_ms_state_ci.rasterSamples = 4;
2576 pipe_ms_state_ci.sampleShadingEnable = 0;
2577 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002578 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002579
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002580 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2581 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2582 pipeline_layout_ci.pNext = NULL;
2583 pipeline_layout_ci.descriptorSetCount = 1;
2584 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002585
2586 VkPipelineLayout pipeline_layout;
2587 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2588 ASSERT_VK_SUCCESS(err);
2589
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002590 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002591 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2592 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002593 VkPipelineObj pipe(m_device);
2594 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002595 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002596 pipe.SetMSAA(&pipe_ms_state_ci);
2597 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002598
Tony Barbour1490c912015-07-28 10:17:20 -06002599 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06002600 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002601
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002602 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002603 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 -06002604 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
2605 FAIL() << "Error received was not 'Num samples mismatch!...'";
2606 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002607
2608 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
2609 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2610 ASSERT_VK_SUCCESS(err);
2611 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2612 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002613}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002614
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002615TEST_F(VkLayerTest, ClearCmdNoDraw)
2616{
2617 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
2618 VkFlags msgFlags;
2619 std::string msgString;
2620 VkResult err;
2621
2622 ASSERT_NO_FATAL_FAILURE(InitState());
2623 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2624 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002625
2626 VkDescriptorTypeCount ds_type_count = {};
2627 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2628 ds_type_count.count = 1;
2629
2630 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2631 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2632 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002633 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2634 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002635 ds_pool_ci.count = 1;
2636 ds_pool_ci.pTypeCount = &ds_type_count;
2637
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002638 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002639 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002640 ASSERT_VK_SUCCESS(err);
2641
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002642 VkDescriptorSetLayoutBinding dsl_binding = {};
2643 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2644 dsl_binding.arraySize = 1;
2645 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2646 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002647
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002648 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2649 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2650 ds_layout_ci.pNext = NULL;
2651 ds_layout_ci.count = 1;
2652 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002653
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002654 VkDescriptorSetLayout ds_layout;
2655 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2656 ASSERT_VK_SUCCESS(err);
2657
2658 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002659 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002660 ASSERT_VK_SUCCESS(err);
2661
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002662 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2663 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2664 pipe_ms_state_ci.pNext = NULL;
2665 pipe_ms_state_ci.rasterSamples = 4;
2666 pipe_ms_state_ci.sampleShadingEnable = 0;
2667 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002668 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002669
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002670 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2671 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2672 pipeline_layout_ci.pNext = NULL;
2673 pipeline_layout_ci.descriptorSetCount = 1;
2674 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002675
2676 VkPipelineLayout pipeline_layout;
2677 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2678 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002679
Tony Barbourd7d828b2015-08-06 10:16:07 -06002680 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002681 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2682 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002683 VkPipelineObj pipe(m_device);
2684 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002685 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002686 pipe.SetMSAA(&pipe_ms_state_ci);
2687 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002688
2689 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002690
2691 m_errorMonitor->ClearState();
2692 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
2693 // Also pass down other dummy params to keep driver and paramchecker happy
2694 VkClearColorValue cCV;
Cody Northrop2563a032015-08-25 15:26:38 -06002695 cCV.float32[0] = 1.0;
2696 cCV.float32[1] = 1.0;
2697 cCV.float32[2] = 1.0;
2698 cCV.float32[3] = 1.0;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002699
Tony Barbour1490c912015-07-28 10:17:20 -06002700 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002701 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002702 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 -06002703 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) {
2704 FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'";
2705 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002706
2707 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
2708 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2709 ASSERT_VK_SUCCESS(err);
2710 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2711 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002712}
2713
Tobin Ehlise4076782015-06-24 15:53:07 -06002714TEST_F(VkLayerTest, VtxBufferBadIndex)
2715{
2716 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
2717 VkFlags msgFlags;
2718 std::string msgString;
2719 VkResult err;
2720
2721 ASSERT_NO_FATAL_FAILURE(InitState());
2722 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2723 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002724
2725 VkDescriptorTypeCount ds_type_count = {};
2726 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2727 ds_type_count.count = 1;
2728
2729 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2730 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2731 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002732 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2733 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002734 ds_pool_ci.count = 1;
2735 ds_pool_ci.pTypeCount = &ds_type_count;
2736
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002737 VkDescriptorPool ds_pool;
2738 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06002739 ASSERT_VK_SUCCESS(err);
2740
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002741 VkDescriptorSetLayoutBinding dsl_binding = {};
2742 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2743 dsl_binding.arraySize = 1;
2744 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2745 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002746
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002747 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2748 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2749 ds_layout_ci.pNext = NULL;
2750 ds_layout_ci.count = 1;
2751 ds_layout_ci.pBinding = &dsl_binding;
2752
Tobin Ehlise4076782015-06-24 15:53:07 -06002753 VkDescriptorSetLayout ds_layout;
2754 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2755 ASSERT_VK_SUCCESS(err);
2756
2757 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002758 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06002759 ASSERT_VK_SUCCESS(err);
2760
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002761 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2762 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2763 pipe_ms_state_ci.pNext = NULL;
2764 pipe_ms_state_ci.rasterSamples = 1;
2765 pipe_ms_state_ci.sampleShadingEnable = 0;
2766 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002767 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002768
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002769 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2770 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2771 pipeline_layout_ci.pNext = NULL;
2772 pipeline_layout_ci.descriptorSetCount = 1;
2773 pipeline_layout_ci.pSetLayouts = &ds_layout;
2774 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06002775
Tobin Ehlise4076782015-06-24 15:53:07 -06002776 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2777 ASSERT_VK_SUCCESS(err);
2778
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002779 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002780 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2781 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002782 VkPipelineObj pipe(m_device);
2783 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002784 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002785 pipe.SetMSAA(&pipe_ms_state_ci);
2786 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002787
2788 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06002789 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002790 // Don't care about actual data, just need to get to draw to flag error
2791 static const float vbo_data[3] = {1.f, 0.f, 1.f};
2792 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
2793 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002794 Draw(1, 0, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06002795
2796 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002797 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 -06002798 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 -06002799 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
2800 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002801
2802 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
2803 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2804 ASSERT_VK_SUCCESS(err);
2805 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2806 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06002807}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002808#endif // DRAW_STATE_TESTS
2809
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002810#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06002811#if GTEST_IS_THREADSAFE
2812struct thread_data_struct {
2813 VkCmdBuffer cmdBuffer;
2814 VkEvent event;
2815 bool bailout;
2816};
2817
2818extern "C" void *AddToCommandBuffer(void *arg)
2819{
2820 struct thread_data_struct *data = (struct thread_data_struct *) arg;
2821 std::string msgString;
2822
2823 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06002824 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06002825 if (data->bailout) {
2826 break;
2827 }
2828 }
2829 return NULL;
2830}
2831
2832TEST_F(VkLayerTest, ThreadCmdBufferCollision)
2833{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002834 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06002835 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002836 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06002837
2838 ASSERT_NO_FATAL_FAILURE(InitState());
2839 ASSERT_NO_FATAL_FAILURE(InitViewport());
2840 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2841
Mike Stroyan09aae812015-05-12 16:00:45 -06002842 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06002843 BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002844
2845 VkEventCreateInfo event_info;
2846 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06002847 VkResult err;
2848
2849 memset(&event_info, 0, sizeof(event_info));
2850 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2851
2852 err = vkCreateEvent(device(), &event_info, &event);
2853 ASSERT_VK_SUCCESS(err);
2854
Mike Stroyan09aae812015-05-12 16:00:45 -06002855 err = vkResetEvent(device(), event);
2856 ASSERT_VK_SUCCESS(err);
2857
2858 struct thread_data_struct data;
Tony Barbour1490c912015-07-28 10:17:20 -06002859 data.cmdBuffer = m_cmdBuffer->handle();
Mike Stroyan09aae812015-05-12 16:00:45 -06002860 data.event = event;
2861 data.bailout = false;
2862 m_errorMonitor->SetBailout(&data.bailout);
2863 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002864 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06002865 // Add many entries to command buffer from this thread at the same time.
2866 AddToCommandBuffer(&data);
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002867 test_platform_thread_join(thread, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -06002868 EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002869
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002870 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002871 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 -06002872 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05002873 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06002874 }
2875
Mike Stroyan2237f522015-08-18 14:40:24 -06002876 vkDestroyEvent(device(), event);
Mike Stroyan09aae812015-05-12 16:00:45 -06002877}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002878#endif // GTEST_IS_THREADSAFE
2879#endif // THREADING_TESTS
2880
Chris Forbes5af3bf22015-05-25 11:13:08 +12002881#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06002882TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
2883{
2884 VkFlags msgFlags;
2885 std::string msgString;
2886 ASSERT_NO_FATAL_FAILURE(InitState());
2887 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2888
2889 m_errorMonitor->ClearState();
2890
2891 VkShaderModule module;
2892 VkShaderModuleCreateInfo moduleCreateInfo;
2893 struct icd_spv_header spv;
2894
2895 spv.magic = ICD_SPV_MAGIC;
2896 spv.version = ICD_SPV_VERSION;
2897 spv.gen_magic = 0;
2898
2899 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2900 moduleCreateInfo.pNext = NULL;
2901 moduleCreateInfo.pCode = &spv;
2902 moduleCreateInfo.codeSize = 4;
2903 moduleCreateInfo.flags = 0;
2904 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
2905
2906 msgFlags = m_errorMonitor->GetState(&msgString);
2907
Chris Forbes96b81762015-09-18 11:40:23 +12002908 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06002909 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
2910 FAIL() << "Incorrect warning: " << msgString;
2911 }
2912}
2913
2914TEST_F(VkLayerTest, InvalidSPIRVMagic)
2915{
2916 VkFlags msgFlags;
2917 std::string msgString;
2918 ASSERT_NO_FATAL_FAILURE(InitState());
2919 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2920
2921 m_errorMonitor->ClearState();
2922
2923 VkShaderModule module;
2924 VkShaderModuleCreateInfo moduleCreateInfo;
2925 struct icd_spv_header spv;
2926
2927 spv.magic = ~ICD_SPV_MAGIC;
2928 spv.version = ICD_SPV_VERSION;
2929 spv.gen_magic = 0;
2930
2931 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2932 moduleCreateInfo.pNext = NULL;
2933 moduleCreateInfo.pCode = &spv;
2934 moduleCreateInfo.codeSize = sizeof(spv) + 10;
2935 moduleCreateInfo.flags = 0;
2936 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
2937
2938 msgFlags = m_errorMonitor->GetState(&msgString);
2939
Chris Forbes96b81762015-09-18 11:40:23 +12002940 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06002941 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
2942 FAIL() << "Incorrect warning: " << msgString;
2943 }
2944}
2945
2946TEST_F(VkLayerTest, InvalidSPIRVVersion)
2947{
2948 VkFlags msgFlags;
2949 std::string msgString;
2950 ASSERT_NO_FATAL_FAILURE(InitState());
2951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2952
2953 m_errorMonitor->ClearState();
2954
2955 VkShaderModule module;
2956 VkShaderModuleCreateInfo moduleCreateInfo;
2957 struct icd_spv_header spv;
2958
2959 spv.magic = ICD_SPV_MAGIC;
2960 spv.version = ~ICD_SPV_VERSION;
2961 spv.gen_magic = 0;
2962
2963 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2964 moduleCreateInfo.pNext = NULL;
2965
2966 moduleCreateInfo.pCode = &spv;
2967 moduleCreateInfo.codeSize = sizeof(spv) + 10;
2968 moduleCreateInfo.flags = 0;
2969 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
2970
2971 msgFlags = m_errorMonitor->GetState(&msgString);
2972
Chris Forbes96b81762015-09-18 11:40:23 +12002973 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06002974 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
2975 FAIL() << "Incorrect warning: " << msgString;
2976 }
2977}
2978
Chris Forbes5af3bf22015-05-25 11:13:08 +12002979TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
2980{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002981 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12002982 std::string msgString;
2983 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002984 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12002985
2986 char const *vsSource =
2987 "#version 140\n"
2988 "#extension GL_ARB_separate_shader_objects: require\n"
2989 "#extension GL_ARB_shading_language_420pack: require\n"
2990 "\n"
2991 "layout(location=0) out float x;\n"
2992 "void main(){\n"
2993 " gl_Position = vec4(1);\n"
2994 " x = 0;\n"
2995 "}\n";
2996 char const *fsSource =
2997 "#version 140\n"
2998 "#extension GL_ARB_separate_shader_objects: require\n"
2999 "#extension GL_ARB_shading_language_420pack: require\n"
3000 "\n"
3001 "layout(location=0) out vec4 color;\n"
3002 "void main(){\n"
3003 " color = vec4(1);\n"
3004 "}\n";
3005
3006 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3007 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3008
3009 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003010 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12003011 pipe.AddShader(&vs);
3012 pipe.AddShader(&fs);
3013
Chris Forbes5af3bf22015-05-25 11:13:08 +12003014 VkDescriptorSetObj descriptorSet(m_device);
3015 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003016 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003017
3018 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003019 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12003020
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003021 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003022
Cody Northrop1684adb2015-08-05 11:15:02 -06003023 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003024 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
3025 FAIL() << "Incorrect warning: " << msgString;
3026 }
3027}
Chris Forbes5af3bf22015-05-25 11:13:08 +12003028
Chris Forbes3c10b852015-05-25 11:13:13 +12003029TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
3030{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003031 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12003032 std::string msgString;
3033 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12003035
3036 char const *vsSource =
3037 "#version 140\n"
3038 "#extension GL_ARB_separate_shader_objects: require\n"
3039 "#extension GL_ARB_shading_language_420pack: require\n"
3040 "\n"
3041 "void main(){\n"
3042 " gl_Position = vec4(1);\n"
3043 "}\n";
3044 char const *fsSource =
3045 "#version 140\n"
3046 "#extension GL_ARB_separate_shader_objects: require\n"
3047 "#extension GL_ARB_shading_language_420pack: require\n"
3048 "\n"
3049 "layout(location=0) in float x;\n"
3050 "layout(location=0) out vec4 color;\n"
3051 "void main(){\n"
3052 " color = vec4(x);\n"
3053 "}\n";
3054
3055 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3056 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3057
3058 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003059 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12003060 pipe.AddShader(&vs);
3061 pipe.AddShader(&fs);
3062
Chris Forbes3c10b852015-05-25 11:13:13 +12003063 VkDescriptorSetObj descriptorSet(m_device);
3064 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003065 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12003066
3067 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003068 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12003069
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003070 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12003071
Cody Northrop1684adb2015-08-05 11:15:02 -06003072 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes3c10b852015-05-25 11:13:13 +12003073 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
3074 FAIL() << "Incorrect error: " << msgString;
3075 }
3076}
3077
Chris Forbescc281692015-05-25 11:13:17 +12003078TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
3079{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003080 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12003081 std::string msgString;
3082 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003083 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12003084
3085 char const *vsSource =
3086 "#version 140\n"
3087 "#extension GL_ARB_separate_shader_objects: require\n"
3088 "#extension GL_ARB_shading_language_420pack: require\n"
3089 "\n"
3090 "layout(location=0) out int x;\n"
3091 "void main(){\n"
3092 " x = 0;\n"
3093 " gl_Position = vec4(1);\n"
3094 "}\n";
3095 char const *fsSource =
3096 "#version 140\n"
3097 "#extension GL_ARB_separate_shader_objects: require\n"
3098 "#extension GL_ARB_shading_language_420pack: require\n"
3099 "\n"
3100 "layout(location=0) in float x;\n" /* VS writes int */
3101 "layout(location=0) out vec4 color;\n"
3102 "void main(){\n"
3103 " color = vec4(x);\n"
3104 "}\n";
3105
3106 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3107 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3108
3109 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003110 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12003111 pipe.AddShader(&vs);
3112 pipe.AddShader(&fs);
3113
Chris Forbescc281692015-05-25 11:13:17 +12003114 VkDescriptorSetObj descriptorSet(m_device);
3115 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003116 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12003117
3118 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003119 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12003120
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003121 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12003122
Cody Northrop1684adb2015-08-05 11:15:02 -06003123 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbescc281692015-05-25 11:13:17 +12003124 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
3125 FAIL() << "Incorrect error: " << msgString;
3126 }
3127}
3128
Chris Forbes8291c052015-05-25 11:13:28 +12003129TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
3130{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003131 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12003132 std::string msgString;
3133 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003134 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12003135
3136 VkVertexInputBindingDescription input_binding;
3137 memset(&input_binding, 0, sizeof(input_binding));
3138
3139 VkVertexInputAttributeDescription input_attrib;
3140 memset(&input_attrib, 0, sizeof(input_attrib));
3141 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3142
3143 char const *vsSource =
3144 "#version 140\n"
3145 "#extension GL_ARB_separate_shader_objects: require\n"
3146 "#extension GL_ARB_shading_language_420pack: require\n"
3147 "\n"
3148 "void main(){\n"
3149 " gl_Position = vec4(1);\n"
3150 "}\n";
3151 char const *fsSource =
3152 "#version 140\n"
3153 "#extension GL_ARB_separate_shader_objects: require\n"
3154 "#extension GL_ARB_shading_language_420pack: require\n"
3155 "\n"
3156 "layout(location=0) out vec4 color;\n"
3157 "void main(){\n"
3158 " color = vec4(1);\n"
3159 "}\n";
3160
3161 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3162 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3163
3164 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003165 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12003166 pipe.AddShader(&vs);
3167 pipe.AddShader(&fs);
3168
3169 pipe.AddVertexInputBindings(&input_binding, 1);
3170 pipe.AddVertexInputAttribs(&input_attrib, 1);
3171
Chris Forbes8291c052015-05-25 11:13:28 +12003172 VkDescriptorSetObj descriptorSet(m_device);
3173 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003174 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12003175
3176 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003177 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12003178
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003179 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12003180
Cody Northrop1684adb2015-08-05 11:15:02 -06003181 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12003182 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
3183 FAIL() << "Incorrect warning: " << msgString;
3184 }
3185}
3186
Chris Forbes37367e62015-05-25 11:13:29 +12003187TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
3188{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003189 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12003190 std::string msgString;
3191 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003192 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12003193
3194 char const *vsSource =
3195 "#version 140\n"
3196 "#extension GL_ARB_separate_shader_objects: require\n"
3197 "#extension GL_ARB_shading_language_420pack: require\n"
3198 "\n"
3199 "layout(location=0) in vec4 x;\n" /* not provided */
3200 "void main(){\n"
3201 " gl_Position = x;\n"
3202 "}\n";
3203 char const *fsSource =
3204 "#version 140\n"
3205 "#extension GL_ARB_separate_shader_objects: require\n"
3206 "#extension GL_ARB_shading_language_420pack: require\n"
3207 "\n"
3208 "layout(location=0) out vec4 color;\n"
3209 "void main(){\n"
3210 " color = vec4(1);\n"
3211 "}\n";
3212
3213 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3214 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3215
3216 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003217 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12003218 pipe.AddShader(&vs);
3219 pipe.AddShader(&fs);
3220
Chris Forbes37367e62015-05-25 11:13:29 +12003221 VkDescriptorSetObj descriptorSet(m_device);
3222 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003223 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12003224
3225 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003226 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12003227
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003228 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12003229
Cody Northrop1684adb2015-08-05 11:15:02 -06003230 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes37367e62015-05-25 11:13:29 +12003231 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
3232 FAIL() << "Incorrect warning: " << msgString;
3233 }
3234}
3235
Chris Forbesa4b02322015-05-25 11:13:31 +12003236TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
3237{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003238 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12003239 std::string msgString;
3240 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003241 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12003242
3243 VkVertexInputBindingDescription input_binding;
3244 memset(&input_binding, 0, sizeof(input_binding));
3245
3246 VkVertexInputAttributeDescription input_attrib;
3247 memset(&input_attrib, 0, sizeof(input_attrib));
3248 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3249
3250 char const *vsSource =
3251 "#version 140\n"
3252 "#extension GL_ARB_separate_shader_objects: require\n"
3253 "#extension GL_ARB_shading_language_420pack: require\n"
3254 "\n"
3255 "layout(location=0) in int x;\n" /* attrib provided float */
3256 "void main(){\n"
3257 " gl_Position = vec4(x);\n"
3258 "}\n";
3259 char const *fsSource =
3260 "#version 140\n"
3261 "#extension GL_ARB_separate_shader_objects: require\n"
3262 "#extension GL_ARB_shading_language_420pack: require\n"
3263 "\n"
3264 "layout(location=0) out vec4 color;\n"
3265 "void main(){\n"
3266 " color = vec4(1);\n"
3267 "}\n";
3268
3269 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3270 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3271
3272 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003273 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12003274 pipe.AddShader(&vs);
3275 pipe.AddShader(&fs);
3276
3277 pipe.AddVertexInputBindings(&input_binding, 1);
3278 pipe.AddVertexInputAttribs(&input_attrib, 1);
3279
Chris Forbesa4b02322015-05-25 11:13:31 +12003280 VkDescriptorSetObj descriptorSet(m_device);
3281 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003282 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12003283
3284 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003285 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12003286
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003287 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12003288
Cody Northrop1684adb2015-08-05 11:15:02 -06003289 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa4b02322015-05-25 11:13:31 +12003290 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
3291 FAIL() << "Incorrect error: " << msgString;
3292 }
3293}
3294
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003295TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
3296{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003297 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003298 std::string msgString;
3299 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003300 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003301
3302 /* Two binding descriptions for binding 0 */
3303 VkVertexInputBindingDescription input_bindings[2];
3304 memset(input_bindings, 0, sizeof(input_bindings));
3305
3306 VkVertexInputAttributeDescription input_attrib;
3307 memset(&input_attrib, 0, sizeof(input_attrib));
3308 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3309
3310 char const *vsSource =
3311 "#version 140\n"
3312 "#extension GL_ARB_separate_shader_objects: require\n"
3313 "#extension GL_ARB_shading_language_420pack: require\n"
3314 "\n"
3315 "layout(location=0) in float x;\n" /* attrib provided float */
3316 "void main(){\n"
3317 " gl_Position = vec4(x);\n"
3318 "}\n";
3319 char const *fsSource =
3320 "#version 140\n"
3321 "#extension GL_ARB_separate_shader_objects: require\n"
3322 "#extension GL_ARB_shading_language_420pack: require\n"
3323 "\n"
3324 "layout(location=0) out vec4 color;\n"
3325 "void main(){\n"
3326 " color = vec4(1);\n"
3327 "}\n";
3328
3329 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3330 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3331
3332 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003333 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003334 pipe.AddShader(&vs);
3335 pipe.AddShader(&fs);
3336
3337 pipe.AddVertexInputBindings(input_bindings, 2);
3338 pipe.AddVertexInputAttribs(&input_attrib, 1);
3339
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003340 VkDescriptorSetObj descriptorSet(m_device);
3341 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003342 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003343
3344 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003345 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003346
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003347 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003348
Cody Northrop1684adb2015-08-05 11:15:02 -06003349 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003350 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
3351 FAIL() << "Incorrect error: " << msgString;
3352 }
3353}
Chris Forbes4c948702015-05-25 11:13:32 +12003354
Chris Forbesc12ef122015-05-25 11:13:40 +12003355/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
3356 * rejects it. */
3357
3358TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
3359{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003360 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12003361 std::string msgString;
3362 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12003363
3364 char const *vsSource =
3365 "#version 140\n"
3366 "#extension GL_ARB_separate_shader_objects: require\n"
3367 "#extension GL_ARB_shading_language_420pack: require\n"
3368 "\n"
3369 "void main(){\n"
3370 " gl_Position = vec4(1);\n"
3371 "}\n";
3372 char const *fsSource =
3373 "#version 140\n"
3374 "#extension GL_ARB_separate_shader_objects: require\n"
3375 "#extension GL_ARB_shading_language_420pack: require\n"
3376 "\n"
3377 "void main(){\n"
3378 "}\n";
3379
3380 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3381 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3382
3383 VkPipelineObj pipe(m_device);
3384 pipe.AddShader(&vs);
3385 pipe.AddShader(&fs);
3386
Chia-I Wuc278df82015-07-07 11:50:03 +08003387 /* set up CB 0, not written */
3388 pipe.AddColorAttachment();
3389 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12003390
Chris Forbesc12ef122015-05-25 11:13:40 +12003391 VkDescriptorSetObj descriptorSet(m_device);
3392 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003393 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12003394
3395 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003396 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12003397
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003398 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12003399
Cody Northrop1684adb2015-08-05 11:15:02 -06003400 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc12ef122015-05-25 11:13:40 +12003401 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
3402 FAIL() << "Incorrect error: " << msgString;
3403 }
3404}
3405
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003406TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
3407{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003408 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003409 std::string msgString;
3410 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003411
3412 char const *vsSource =
3413 "#version 140\n"
3414 "#extension GL_ARB_separate_shader_objects: require\n"
3415 "#extension GL_ARB_shading_language_420pack: require\n"
3416 "\n"
3417 "void main(){\n"
3418 " gl_Position = vec4(1);\n"
3419 "}\n";
3420 char const *fsSource =
3421 "#version 140\n"
3422 "#extension GL_ARB_separate_shader_objects: require\n"
3423 "#extension GL_ARB_shading_language_420pack: require\n"
3424 "\n"
3425 "layout(location=0) out vec4 x;\n"
3426 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
3427 "void main(){\n"
3428 " x = vec4(1);\n"
3429 " y = vec4(1);\n"
3430 "}\n";
3431
3432 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3433 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3434
3435 VkPipelineObj pipe(m_device);
3436 pipe.AddShader(&vs);
3437 pipe.AddShader(&fs);
3438
Chia-I Wuc278df82015-07-07 11:50:03 +08003439 /* set up CB 0, not written */
3440 pipe.AddColorAttachment();
3441 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003442 /* FS writes CB 1, but we don't configure it */
3443
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003444 VkDescriptorSetObj descriptorSet(m_device);
3445 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003446 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003447
3448 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003449 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003450
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003451 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003452
Cody Northrop1684adb2015-08-05 11:15:02 -06003453 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003454 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
3455 FAIL() << "Incorrect warning: " << msgString;
3456 }
3457}
3458
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003459TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
3460{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003461 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003462 std::string msgString;
3463 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003464
3465 char const *vsSource =
3466 "#version 140\n"
3467 "#extension GL_ARB_separate_shader_objects: require\n"
3468 "#extension GL_ARB_shading_language_420pack: require\n"
3469 "\n"
3470 "void main(){\n"
3471 " gl_Position = vec4(1);\n"
3472 "}\n";
3473 char const *fsSource =
3474 "#version 140\n"
3475 "#extension GL_ARB_separate_shader_objects: require\n"
3476 "#extension GL_ARB_shading_language_420pack: require\n"
3477 "\n"
3478 "layout(location=0) out ivec4 x;\n" /* not UNORM */
3479 "void main(){\n"
3480 " x = ivec4(1);\n"
3481 "}\n";
3482
3483 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3484 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3485
3486 VkPipelineObj pipe(m_device);
3487 pipe.AddShader(&vs);
3488 pipe.AddShader(&fs);
3489
Chia-I Wuc278df82015-07-07 11:50:03 +08003490 /* set up CB 0; type is UNORM by default */
3491 pipe.AddColorAttachment();
3492 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003493
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003494 VkDescriptorSetObj descriptorSet(m_device);
3495 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003496 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003497
3498 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003499 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003500
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003501 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003502
Cody Northrop1684adb2015-08-05 11:15:02 -06003503 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003504 if (!strstr(msgString.c_str(),"does not match FS output type")) {
3505 FAIL() << "Incorrect error: " << msgString;
3506 }
3507}
Chris Forbesc2050732015-06-05 14:43:36 +12003508
Chris Forbes76ce7882015-08-14 12:04:59 +12003509TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
3510{
3511 VkFlags msgFlags;
3512 std::string msgString;
3513 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +12003514
3515 char const *vsSource =
3516 "#version 140\n"
3517 "#extension GL_ARB_separate_shader_objects: require\n"
3518 "#extension GL_ARB_shading_language_420pack: require\n"
3519 "\n"
3520 "void main(){\n"
3521 " gl_Position = vec4(1);\n"
3522 "}\n";
3523 char const *fsSource =
3524 "#version 140\n"
3525 "#extension GL_ARB_separate_shader_objects: require\n"
3526 "#extension GL_ARB_shading_language_420pack: require\n"
3527 "\n"
3528 "layout(location=0) out vec4 x;\n"
3529 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
3530 "void main(){\n"
3531 " x = vec4(bar.y);\n"
3532 "}\n";
3533
3534 m_errorMonitor->ClearState();
3535
3536 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3537 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3538
3539
3540 VkPipelineObj pipe(m_device);
3541 pipe.AddShader(&vs);
3542 pipe.AddShader(&fs);
3543
3544 /* set up CB 0; type is UNORM by default */
3545 pipe.AddColorAttachment();
3546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3547
3548 VkDescriptorSetObj descriptorSet(m_device);
3549 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
3550
3551 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3552
3553 /* should have generated an error -- pipeline layout does not
3554 * provide a uniform buffer in 0.0
3555 */
3556 msgFlags = m_errorMonitor->GetState(&msgString);
3557 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
3558 if (!strstr(msgString.c_str(),"not declared in pipeline layout")) {
3559 FAIL() << "Incorrect error: " << msgString;
3560 }
3561}
3562
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003563#endif // SHADER_CHECKER_TESTS
3564
3565#if DEVICE_LIMITS_TESTS
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06003566TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
3567{
3568 VkFlags msgFlags;
3569 std::string msgString;
3570
3571 ASSERT_NO_FATAL_FAILURE(InitState());
3572 m_errorMonitor->ClearState();
3573
3574 // Create an image
3575 VkImage image;
3576
3577 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3578 const int32_t tex_width = 32;
3579 const int32_t tex_height = 32;
3580
3581 VkImageCreateInfo image_create_info = {};
3582 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3583 image_create_info.pNext = NULL;
3584 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3585 image_create_info.format = tex_format;
3586 image_create_info.extent.width = tex_width;
3587 image_create_info.extent.height = tex_height;
3588 image_create_info.extent.depth = 1;
3589 image_create_info.mipLevels = 1;
3590 image_create_info.arraySize = 1;
3591 image_create_info.samples = 1;
3592 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3593 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3594 image_create_info.flags = 0;
3595
3596 // Introduce error by sending down a bogus width extent
3597 image_create_info.extent.width = 65536;
3598 vkCreateImage(m_device->device(), &image_create_info, &image);
3599
3600 msgFlags = m_errorMonitor->GetState(&msgString);
3601 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
3602 "with extents outside the queried limits";
3603 if (!strstr(msgString.c_str(),"CreateImage extents exceed allowable limits for format")) {
3604 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
3605 }
3606}
3607
3608TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
3609{
3610 VkFlags msgFlags;
3611 std::string msgString;
3612
3613 ASSERT_NO_FATAL_FAILURE(InitState());
3614 m_errorMonitor->ClearState();
3615
3616 // Create an image
3617 VkImage image;
3618
3619 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3620 const int32_t tex_width = 32;
3621 const int32_t tex_height = 32;
3622
3623 VkImageCreateInfo image_create_info = {};
3624 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3625 image_create_info.pNext = NULL;
3626 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3627 image_create_info.format = tex_format;
3628 image_create_info.extent.width = tex_width;
3629 image_create_info.extent.height = tex_height;
3630 image_create_info.extent.depth = 1;
3631 image_create_info.mipLevels = 1;
3632 image_create_info.arraySize = 1;
3633 image_create_info.samples = 1;
3634 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3635 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3636 image_create_info.flags = 0;
3637
3638 // Introduce error by sending down individually allowable values that result in a surface size
3639 // exceeding the device maximum
3640 image_create_info.extent.width = 8192;
3641 image_create_info.extent.height = 8192;
3642 image_create_info.extent.depth = 16;
3643 image_create_info.arraySize = 4;
3644 image_create_info.samples = 2;
3645 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
3646 vkCreateImage(m_device->device(), &image_create_info, &image);
3647
3648 msgFlags = m_errorMonitor->GetState(&msgString);
3649 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
3650 "with resource size exceeding queried limit";
3651 if (!strstr(msgString.c_str(),"CreateImage resource size exceeds allowable maximum")) {
3652 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
3653 }
3654}
3655
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003656#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003657
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06003658#if IMAGE_TESTS
3659TEST_F(VkLayerTest, InvalidImageView)
3660{
3661 VkFlags msgFlags;
3662 std::string msgString;
3663 VkResult err;
3664
3665 ASSERT_NO_FATAL_FAILURE(InitState());
3666 m_errorMonitor->ClearState();
3667
3668 // Create an image, allocate memory, free it, and then try to bind it
3669 VkImage image;
3670
3671 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3672 const int32_t tex_width = 32;
3673 const int32_t tex_height = 32;
3674
3675 VkImageCreateInfo image_create_info = {};
3676 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3677 image_create_info.pNext = NULL;
3678 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3679 image_create_info.format = tex_format;
3680 image_create_info.extent.width = tex_width;
3681 image_create_info.extent.height = tex_height;
3682 image_create_info.extent.depth = 1;
3683 image_create_info.mipLevels = 1;
3684 image_create_info.arraySize = 1;
3685 image_create_info.samples = 1;
3686 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3687 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3688 image_create_info.flags = 0;
3689
3690 err = vkCreateImage(m_device->device(), &image_create_info, &image);
3691 ASSERT_VK_SUCCESS(err);
3692
3693 VkImageViewCreateInfo image_view_create_info = {};
3694 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3695 image_view_create_info.image = image;
3696 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
3697 image_view_create_info.format = tex_format;
3698 image_view_create_info.subresourceRange.arraySize = 1;
3699 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
3700 image_view_create_info.subresourceRange.mipLevels = 1;
3701
3702 VkImageView view;
3703 err = vkCreateImageView(m_device->device(), &image_view_create_info, &view);
3704
3705 msgFlags = m_errorMonitor->GetState(&msgString);
3706 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an invalid ImageView";
3707 if (!strstr(msgString.c_str(),"vkCreateImageView called with baseMipLevel 10 ")) {
3708 FAIL() << "Error received was not 'vkCreateImageView called with baseMipLevel 10...' but instaed '" << msgString.c_str() << "'";
3709 }
3710}
3711#endif // IMAGE_TESTS
3712
Tony Barbour30486ea2015-04-07 13:44:53 -06003713int main(int argc, char **argv) {
3714 int result;
3715
3716 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06003717 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06003718
3719 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
3720
3721 result = RUN_ALL_TESTS();
3722
Tony Barbour01999182015-04-09 12:58:51 -06003723 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06003724 return result;
3725}