blob: 5e8e50914770194fb8bdcca7e67f555d3733f330 [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 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600304 // Viewport and scissors must stay in synch or other errors will occur than the ones we want
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600305 if (failMask & BsoFailViewport) {
306 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600307 m_viewports.clear();
308 m_scissors.clear();
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600309 }
310 if (failMask & BsoFailScissor) {
311 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600312 m_scissors.clear();
313 m_viewports.clear();
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600314 }
315 if (failMask & BsoFailBlend) {
316 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
317 }
318 if (failMask & BsoFailDepthBounds) {
319 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
320 }
321 if (failMask & BsoFailStencilReadMask) {
322 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
323 }
324 if (failMask & BsoFailStencilWriteMask) {
325 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
326 }
327 if (failMask & BsoFailStencilReference) {
328 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
329 }
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500330
331 VkDescriptorSetObj descriptorSet(m_device);
332 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
333
334 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600335 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500336
Tony Barbour1490c912015-07-28 10:17:20 -0600337 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500338
339 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600340 Draw(3, 1, 0, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500341
342 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600343 EndCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500344
Tony Barbour1490c912015-07-28 10:17:20 -0600345 QueueCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500346}
347
348void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
349{
350 if (m_depthStencil->Initialized()) {
351 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
352 } else {
353 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
354 }
355
356 cmdBuffer->PrepareAttachments();
Cody Northrop2605cb02015-08-18 15:21:16 -0600357 // Make sure depthWriteEnable is set so that Depth fail test will work correctly
358 // Make sure stencilTestEnable is set so that Stencil fail test will work correctly
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600359 VkStencilOpState stencil = {};
360 stencil.stencilFailOp = VK_STENCIL_OP_KEEP;
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600361 stencil.stencilPassOp = VK_STENCIL_OP_KEEP;
362 stencil.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
363 stencil.stencilCompareOp = VK_COMPARE_OP_NEVER;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600364
365 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
366 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600367 ds_ci.pNext = NULL;
368 ds_ci.depthTestEnable = VK_FALSE;
369 ds_ci.depthWriteEnable = VK_TRUE;
370 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
371 ds_ci.depthBoundsTestEnable = VK_FALSE;
372 ds_ci.stencilTestEnable = VK_TRUE;
373 ds_ci.front = stencil;
374 ds_ci.back = stencil;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600375
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600376 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600377 pipelineobj.SetViewport(m_viewports);
378 pipelineobj.SetScissor(m_scissors);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500379 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Cody Northropccfa96d2015-08-27 10:20:35 -0600380 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
381 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500382 cmdBuffer->BindPipeline(pipelineobj);
383 cmdBuffer->BindDescriptorSet(descriptorSet);
384}
385
386// ********************************************************************************************************************
387// ********************************************************************************************************************
388// ********************************************************************************************************************
389// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600390#if MEM_TRACKER_TESTS
Mark Lobodzinski81078192015-05-19 10:28:29 -0500391TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
392{
393 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600394 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500395 std::string msgString;
396
397 VkFenceCreateInfo fenceInfo = {};
398 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
399 fenceInfo.pNext = NULL;
400 fenceInfo.flags = 0;
401
402 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barboure389b882015-07-20 13:00:10 -0600403
404 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
405 vk_testing::Buffer buffer;
406 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500407
Tony Barbour1490c912015-07-28 10:17:20 -0600408 BeginCommandBuffer();
409 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
410 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500411
412 testFence.init(*m_device, fenceInfo);
413
414 // Bypass framework since it does the waits automatically
415 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600416 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500417 ASSERT_VK_SUCCESS( err );
418
419 m_errorMonitor->ClearState();
420 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600421 vkResetCommandBuffer(m_cmdBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500422
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600423 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600424 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 -0500425 if (!strstr(msgString.c_str(),"Resetting CB")) {
426 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
427 }
428}
429
430TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion)
431{
432 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600433 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500434 std::string msgString;
435
436 VkFenceCreateInfo fenceInfo = {};
437 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
438 fenceInfo.pNext = NULL;
439 fenceInfo.flags = 0;
440
441 ASSERT_NO_FATAL_FAILURE(InitState());
442 ASSERT_NO_FATAL_FAILURE(InitViewport());
443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
444
Tony Barbour1490c912015-07-28 10:17:20 -0600445 BeginCommandBuffer();
446 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
447 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500448
449 testFence.init(*m_device, fenceInfo);
450
451 // Bypass framework since it does the waits automatically
452 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600453 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500454 ASSERT_VK_SUCCESS( err );
455
456 m_errorMonitor->ClearState();
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600457
458 VkCmdBufferBeginInfo info = {};
459 info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT | VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
460 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
461 info.renderPass = VK_NULL_HANDLE;
462 info.subpass = 0;
463 info.framebuffer = VK_NULL_HANDLE;
464
465 // Introduce failure by calling BCB again before checking fence
466 vkBeginCommandBuffer(m_cmdBuffer->handle(), &info);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500467
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600468 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600469 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 -0500470 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
471 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
472 }
473}
474
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500475TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
476{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600477 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500478 std::string msgString;
479 VkResult err;
480
481 ASSERT_NO_FATAL_FAILURE(InitState());
482 m_errorMonitor->ClearState();
483
484 // Create an image, allocate memory, free it, and then try to bind it
485 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500486 VkDeviceMemory mem;
487 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500488
489 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
490 const int32_t tex_width = 32;
491 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500492
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600493 VkImageCreateInfo image_create_info = {};
494 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
495 image_create_info.pNext = NULL;
496 image_create_info.imageType = VK_IMAGE_TYPE_2D;
497 image_create_info.format = tex_format;
498 image_create_info.extent.width = tex_width;
499 image_create_info.extent.height = tex_height;
500 image_create_info.extent.depth = 1;
501 image_create_info.mipLevels = 1;
502 image_create_info.arraySize = 1;
503 image_create_info.samples = 1;
504 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
505 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
506 image_create_info.flags = 0;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600507
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600508 VkMemoryAllocInfo mem_alloc = {};
509 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
510 mem_alloc.pNext = NULL;
511 mem_alloc.allocationSize = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500512 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600513 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500514
515 err = vkCreateImage(m_device->device(), &image_create_info, &image);
516 ASSERT_VK_SUCCESS(err);
517
Tony Barboure84a8d62015-07-10 14:10:27 -0600518 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500519 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500520 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500521 ASSERT_VK_SUCCESS(err);
522
Mark Lobodzinski23182612015-05-29 09:32:35 -0500523 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500524
Mike Stroyan2237f522015-08-18 14:40:24 -0600525 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
526 if(err != VK_SUCCESS) { // If we can't find any unmappable memory this test doesn't make sense
527 vkDestroyImage(m_device->device(), image);
Tony Barbour49a3b652015-08-04 16:13:01 -0600528 return;
Mike Stroyan2237f522015-08-18 14:40:24 -0600529 }
Mike Stroyand72da752015-08-04 10:49:29 -0600530
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500531 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500532 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500533 ASSERT_VK_SUCCESS(err);
534
535 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600536 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500537 ASSERT_VK_SUCCESS(err);
538
539 // Map memory as if to initialize the image
540 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500541 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500542
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600543 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600544 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 -0500545 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
546 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
547 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600548
549 vkDestroyImage(m_device->device(), image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500550}
551
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600552// TODO : Is this test still valid. Not sure it is with updates to memory binding model
553// Verify and delete the test of fix the check
554//TEST_F(VkLayerTest, FreeBoundMemory)
555//{
556// VkFlags msgFlags;
557// std::string msgString;
558// VkResult err;
559//
560// ASSERT_NO_FATAL_FAILURE(InitState());
561// m_errorMonitor->ClearState();
562//
563// // Create an image, allocate memory, free it, and then try to bind it
564// VkImage image;
565// VkDeviceMemory mem;
566// VkMemoryRequirements mem_reqs;
567//
568// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
569// const int32_t tex_width = 32;
570// const int32_t tex_height = 32;
571//
572// const VkImageCreateInfo image_create_info = {
573// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
574// .pNext = NULL,
575// .imageType = VK_IMAGE_TYPE_2D,
576// .format = tex_format,
577// .extent = { tex_width, tex_height, 1 },
578// .mipLevels = 1,
579// .arraySize = 1,
580// .samples = 1,
581// .tiling = VK_IMAGE_TILING_LINEAR,
582// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
583// .flags = 0,
584// };
585// VkMemoryAllocInfo mem_alloc = {
586// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
587// .pNext = NULL,
588// .allocationSize = 0,
589// .memoryTypeIndex = 0,
590// };
591//
592// err = vkCreateImage(m_device->device(), &image_create_info, &image);
593// ASSERT_VK_SUCCESS(err);
594//
595// err = vkGetImageMemoryRequirements(m_device->device(),
596// image,
597// &mem_reqs);
598// ASSERT_VK_SUCCESS(err);
599//
600// mem_alloc.allocationSize = mem_reqs.size;
601//
602// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
603// ASSERT_VK_SUCCESS(err);
604//
605// // allocate memory
606// err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
607// ASSERT_VK_SUCCESS(err);
608//
609// // Bind memory to Image object
610// err = vkBindImageMemory(m_device->device(), image, mem, 0);
611// ASSERT_VK_SUCCESS(err);
612//
613// // Introduce validation failure, free memory while still bound to object
614// vkFreeMemory(m_device->device(), mem);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600615// msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600616//
Cody Northrop1684adb2015-08-05 11:15:02 -0600617// 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 -0600618// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
619// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
620// }
621//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500622
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500623TEST_F(VkLayerTest, RebindMemory)
624{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600625 VkFlags msgFlags;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500626 std::string msgString;
627 VkResult err;
628
629 ASSERT_NO_FATAL_FAILURE(InitState());
630 m_errorMonitor->ClearState();
631
632 // Create an image, allocate memory, free it, and then try to bind it
633 VkImage image;
634 VkDeviceMemory mem1;
635 VkDeviceMemory mem2;
636 VkMemoryRequirements mem_reqs;
637
638 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
639 const int32_t tex_width = 32;
640 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500641
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600642 VkImageCreateInfo image_create_info = {};
643 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
644 image_create_info.pNext = NULL;
645 image_create_info.imageType = VK_IMAGE_TYPE_2D;
646 image_create_info.format = tex_format;
647 image_create_info.extent.width = tex_width;
648 image_create_info.extent.height = tex_height;
649 image_create_info.extent.depth = 1;
650 image_create_info.mipLevels = 1;
651 image_create_info.arraySize = 1;
652 image_create_info.samples = 1;
653 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
654 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
655 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500656
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600657 VkMemoryAllocInfo mem_alloc = {};
658 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
659 mem_alloc.pNext = NULL;
660 mem_alloc.allocationSize = 0;
661 mem_alloc.memoryTypeIndex = 0;
662
663 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
664 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500665 err = vkCreateImage(m_device->device(), &image_create_info, &image);
666 ASSERT_VK_SUCCESS(err);
667
Tony Barboure84a8d62015-07-10 14:10:27 -0600668 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500669 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500670 &mem_reqs);
671 ASSERT_VK_SUCCESS(err);
672
673 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800674 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600675 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500676
677 // allocate 2 memory objects
678 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
679 ASSERT_VK_SUCCESS(err);
680 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
681 ASSERT_VK_SUCCESS(err);
682
683 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600684 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500685 ASSERT_VK_SUCCESS(err);
686
687 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600688 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500689
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600690 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600691 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 -0500692 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
693 FAIL() << "Error received did not match expected message when rebinding memory to an object";
694 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600695
696 vkDestroyImage(m_device->device(), image);
697 vkFreeMemory(m_device->device(), mem1);
698 vkFreeMemory(m_device->device(), mem2);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500699}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500700
Tony Barbour8508b8e2015-04-09 10:48:04 -0600701TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600702{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600703 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600704 VkFlags msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600705 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600706
707 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600708 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
709 fenceInfo.pNext = NULL;
710 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600711
Tony Barbour30486ea2015-04-07 13:44:53 -0600712 ASSERT_NO_FATAL_FAILURE(InitState());
713 ASSERT_NO_FATAL_FAILURE(InitViewport());
714 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
715
Tony Barbour1490c912015-07-28 10:17:20 -0600716 BeginCommandBuffer();
717 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
718 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600719
720 testFence.init(*m_device, fenceInfo);
721 m_errorMonitor->ClearState();
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600722
723 vkQueueSubmit(m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
724 vkQueueWaitIdle(m_device->m_queue );
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600725 msgFlags = m_errorMonitor->GetState(&msgString);
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600726
Cody Northrop1684adb2015-08-05 11:15:02 -0600727 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 -0600728 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500729 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600730 }
731
732}
733
734TEST_F(VkLayerTest, ResetUnsignaledFence)
735{
736 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600737 VkFlags msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600738 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600739 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600740 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
741 fenceInfo.pNext = NULL;
742
Tony Barbour8508b8e2015-04-09 10:48:04 -0600743 ASSERT_NO_FATAL_FAILURE(InitState());
744 testFence.init(*m_device, fenceInfo);
745 m_errorMonitor->ClearState();
Chia-I Wua4992342015-07-03 11:45:55 +0800746 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600747 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600748 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlisc2033a02015-10-01 10:14:48 -0600749 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 -0600750 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500751 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600752 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600753
754}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600755
Chia-I Wuc278df82015-07-07 11:50:03 +0800756/* TODO: Update for changes due to bug-14075 tiling across render passes */
757#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600758TEST_F(VkLayerTest, InvalidUsageBits)
759{
760 // Initiate Draw w/o a PSO bound
761 VkFlags msgFlags;
762 std::string msgString;
763
764 ASSERT_NO_FATAL_FAILURE(InitState());
765 m_errorMonitor->ClearState();
766 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600767 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600768
769 const VkExtent3D e3d = {
770 .width = 128,
771 .height = 128,
772 .depth = 1,
773 };
774 const VkImageCreateInfo ici = {
775 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
776 .pNext = NULL,
777 .imageType = VK_IMAGE_TYPE_2D,
778 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
779 .extent = e3d,
780 .mipLevels = 1,
781 .arraySize = 1,
782 .samples = 1,
783 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchterc3b8eea2015-09-10 14:14:11 -0600784 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600785 .flags = 0,
786 };
787
788 VkImage dsi;
789 vkCreateImage(m_device->device(), &ici, &dsi);
790 VkDepthStencilView dsv;
791 const VkDepthStencilViewCreateInfo dsvci = {
792 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
793 .pNext = NULL,
794 .image = dsi,
795 .mipLevel = 0,
Courtney Goeltzenleuchter3dee8082015-09-10 16:38:41 -0600796 .baseArrayLayer = 0,
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600797 .arraySize = 1,
798 .flags = 0,
799 };
800 vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv);
801 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600802 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 -0600803 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
804 FAIL() << "Error received was not 'Invalid usage flag for image...'";
805 }
806}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600807#endif // 0
808#endif // MEM_TRACKER_TESTS
809
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600810#if OBJ_TRACKER_TESTS
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600811TEST_F(VkLayerTest, PipelineNotBound)
812{
813 VkFlags msgFlags;
814 std::string msgString;
815 VkResult err;
816
817 ASSERT_NO_FATAL_FAILURE(InitState());
818 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
819 m_errorMonitor->ClearState();
820
821 VkDescriptorTypeCount ds_type_count = {};
822 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
823 ds_type_count.count = 1;
824
825 VkDescriptorPoolCreateInfo ds_pool_ci = {};
826 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
827 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600828 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
829 ds_pool_ci.maxSets = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600830 ds_pool_ci.count = 1;
831 ds_pool_ci.pTypeCount = &ds_type_count;
832
833 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600834 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600835 ASSERT_VK_SUCCESS(err);
836
837 VkDescriptorSetLayoutBinding dsl_binding = {};
838 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
839 dsl_binding.arraySize = 1;
840 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
841 dsl_binding.pImmutableSamplers = NULL;
842
843 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
844 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
845 ds_layout_ci.pNext = NULL;
846 ds_layout_ci.count = 1;
847 ds_layout_ci.pBinding = &dsl_binding;
848
849 VkDescriptorSetLayout ds_layout;
850 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
851 ASSERT_VK_SUCCESS(err);
852
853 VkDescriptorSet descriptorSet;
854 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
855 ASSERT_VK_SUCCESS(err);
856
857 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
858 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
859 pipeline_layout_ci.pNext = NULL;
860 pipeline_layout_ci.descriptorSetCount = 1;
861 pipeline_layout_ci.pSetLayouts = &ds_layout;
862
863 VkPipelineLayout pipeline_layout;
864 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
865 ASSERT_VK_SUCCESS(err);
866
867 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
868
869 BeginCommandBuffer();
870 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
871
872 msgFlags = m_errorMonitor->GetState(&msgString);
873 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 -0600874 if (!strstr(msgString.c_str(),"Invalid VkPipeline Object ")) {
875 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be' but instead it was '" << msgString.c_str() << "'";
876 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600877
878 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
879 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
880 ASSERT_VK_SUCCESS(err);
881 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
882 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600883}
884
885TEST_F(VkLayerTest, BindInvalidMemory)
886{
887 VkFlags msgFlags;
888 std::string msgString;
889 VkResult err;
890
891 ASSERT_NO_FATAL_FAILURE(InitState());
892 m_errorMonitor->ClearState();
893
894 // Create an image, allocate memory, free it, and then try to bind it
895 VkImage image;
896 VkDeviceMemory mem;
897 VkMemoryRequirements mem_reqs;
898
899 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
900 const int32_t tex_width = 32;
901 const int32_t tex_height = 32;
902
903 VkImageCreateInfo image_create_info = {};
904 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
905 image_create_info.pNext = NULL;
906 image_create_info.imageType = VK_IMAGE_TYPE_2D;
907 image_create_info.format = tex_format;
908 image_create_info.extent.width = tex_width;
909 image_create_info.extent.height = tex_height;
910 image_create_info.extent.depth = 1;
911 image_create_info.mipLevels = 1;
912 image_create_info.arraySize = 1;
913 image_create_info.samples = 1;
914 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
915 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
916 image_create_info.flags = 0;
917
918 VkMemoryAllocInfo mem_alloc = {};
919 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
920 mem_alloc.pNext = NULL;
921 mem_alloc.allocationSize = 0;
922 mem_alloc.memoryTypeIndex = 0;
923
924 err = vkCreateImage(m_device->device(), &image_create_info, &image);
925 ASSERT_VK_SUCCESS(err);
926
927 err = vkGetImageMemoryRequirements(m_device->device(),
928 image,
929 &mem_reqs);
930 ASSERT_VK_SUCCESS(err);
931
932 mem_alloc.allocationSize = mem_reqs.size;
933
934 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
935 ASSERT_VK_SUCCESS(err);
936
937 // allocate memory
938 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
939 ASSERT_VK_SUCCESS(err);
940
941 // Introduce validation failure, free memory before binding
942 vkFreeMemory(m_device->device(), mem);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600943
944 // Try to bind free memory that has been freed
945 err = vkBindImageMemory(m_device->device(), image, mem, 0);
946 // This may very well return an error.
947 (void)err;
948
949 msgFlags = m_errorMonitor->GetState(&msgString);
950 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to bind a freed memory object";
951 if (!strstr(msgString.c_str(),"Invalid VkDeviceMemory Object ")) {
952 FAIL() << "Error received from BindInvalidMemory was not 'Invalid VkDeviceMemory Object 0x<handle>' but instead '" << msgString.c_str() << "'";
953 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600954
955 vkDestroyImage(m_device->device(), image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600956}
957
958TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
959{
960 VkFlags msgFlags;
961 std::string msgString;
962 VkResult err;
963
964 ASSERT_NO_FATAL_FAILURE(InitState());
965 m_errorMonitor->ClearState();
966
967 // Create an image object, allocate memory, destroy the object and then try to bind it
968 VkImage image;
969 VkDeviceMemory mem;
970 VkMemoryRequirements mem_reqs;
971
972 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
973 const int32_t tex_width = 32;
974 const int32_t tex_height = 32;
975
976 VkImageCreateInfo image_create_info = {};
977 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
978 image_create_info.pNext = NULL;
979 image_create_info.imageType = VK_IMAGE_TYPE_2D;
980 image_create_info.format = tex_format;
981 image_create_info.extent.width = tex_width;
982 image_create_info.extent.height = tex_height;
983 image_create_info.extent.depth = 1;
984 image_create_info.mipLevels = 1;
985 image_create_info.arraySize = 1;
986 image_create_info.samples = 1;
987 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
988 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
989 image_create_info.flags = 0;
990
991 VkMemoryAllocInfo mem_alloc = {};
992 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
993 mem_alloc.pNext = NULL;
994 mem_alloc.allocationSize = 0;
995 mem_alloc.memoryTypeIndex = 0;
996
997 err = vkCreateImage(m_device->device(), &image_create_info, &image);
998 ASSERT_VK_SUCCESS(err);
999
1000 err = vkGetImageMemoryRequirements(m_device->device(),
1001 image,
1002 &mem_reqs);
1003 ASSERT_VK_SUCCESS(err);
1004
1005 mem_alloc.allocationSize = mem_reqs.size;
1006 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1007 ASSERT_VK_SUCCESS(err);
1008
1009 // Allocate memory
1010 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
1011 ASSERT_VK_SUCCESS(err);
1012
1013 // Introduce validation failure, destroy Image object before binding
1014 vkDestroyImage(m_device->device(), image);
1015 ASSERT_VK_SUCCESS(err);
1016
1017 // Now Try to bind memory to this destroyed object
1018 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1019 // This may very well return an error.
1020 (void) err;
1021
1022 msgFlags = m_errorMonitor->GetState(&msgString);
1023 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while binding memory to a destroyed object";
1024 if (!strstr(msgString.c_str(),"Invalid VkImage Object ")) {
1025 FAIL() << "Error received from BindMemoryToDestroyedObject was not 'Invalid VkImage Object 0x<handle>' but rather '" << msgString.c_str() << "'";
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001026 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001027
1028 vkFreeMemory(m_device->device(), mem);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001029}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001030#endif // OBJ_TRACKER_TESTS
1031
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001032#if DRAW_STATE_TESTS
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001033TEST_F(VkLayerTest, LineWidthStateNotBound)
1034{
1035 VkFlags msgFlags;
1036 std::string msgString;
1037 m_errorMonitor->ClearState();
1038 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
1039
1040 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
1041
1042 msgFlags = m_errorMonitor->GetState(&msgString);
1043 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Line Width State Object";
1044 if (!strstr(msgString.c_str(),"Dynamic line width state not set for this command buffer")) {
1045 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic line width state not set for this command buffer'";
1046 }
1047}
1048
1049TEST_F(VkLayerTest, DepthBiasStateNotBound)
1050{
1051 VkFlags msgFlags;
1052 std::string msgString;
1053 m_errorMonitor->ClearState();
1054 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
1055
1056 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
1057
1058 msgFlags = m_errorMonitor->GetState(&msgString);
1059 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bias State Object";
1060 if (!strstr(msgString.c_str(),"Dynamic depth bias state not set for this command buffer")) {
1061 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bias state not set for this command buffer'";
1062 }
1063}
1064
1065TEST_F(VkLayerTest, ViewportStateNotBound)
1066{
1067 VkFlags msgFlags;
1068 std::string msgString;
1069 m_errorMonitor->ClearState();
1070 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1071
1072 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1073
1074 msgFlags = m_errorMonitor->GetState(&msgString);
1075 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 -06001076 // TODO : Viewport and scissor currently set as a pair in framework so scissor error masks viewport error
1077 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1078 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001079 }
1080}
1081
1082TEST_F(VkLayerTest, ScissorStateNotBound)
1083{
1084 VkFlags msgFlags;
1085 std::string msgString;
1086 m_errorMonitor->ClearState();
1087 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1088
1089 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1090
1091 msgFlags = m_errorMonitor->GetState(&msgString);
1092 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
1093 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1094 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
1095 }
1096}
1097
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001098TEST_F(VkLayerTest, BlendStateNotBound)
1099{
1100 VkFlags msgFlags;
1101 std::string msgString;
1102 m_errorMonitor->ClearState();
1103 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1104
1105 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1106
1107 msgFlags = m_errorMonitor->GetState(&msgString);
1108 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Blend State Object";
1109 if (!strstr(msgString.c_str(),"Dynamic blend object state not set for this command buffer")) {
1110 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic blend object state not set for this command buffer'";
1111 }
1112}
1113
1114TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1115{
1116 VkFlags msgFlags;
1117 std::string msgString;
1118 m_errorMonitor->ClearState();
1119 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1120
1121 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1122
1123 msgFlags = m_errorMonitor->GetState(&msgString);
1124 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bounds State Object";
1125 if (!strstr(msgString.c_str(),"Dynamic depth bounds state not set for this command buffer")) {
1126 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bounds state not set for this command buffer'";
1127 }
1128}
1129
1130TEST_F(VkLayerTest, StencilReadMaskNotSet)
1131{
1132 VkFlags msgFlags;
1133 std::string msgString;
1134 ASSERT_NO_FATAL_FAILURE(InitState());
1135 m_errorMonitor->ClearState();
1136 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1137
1138 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1139
1140 msgFlags = m_errorMonitor->GetState(&msgString);
1141 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Read Mask";
1142 if (!strstr(msgString.c_str(),"Dynamic stencil read mask state not set for this command buffer")) {
1143 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil read mask state not set for this command buffer'";
1144 }
1145}
1146
1147TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1148{
1149 VkFlags msgFlags;
1150 std::string msgString;
1151 ASSERT_NO_FATAL_FAILURE(InitState());
1152 m_errorMonitor->ClearState();
1153 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1154
1155 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1156
1157 msgFlags = m_errorMonitor->GetState(&msgString);
1158 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Write Mask";
1159 if (!strstr(msgString.c_str(),"Dynamic stencil write mask state not set for this command buffer")) {
1160 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil write mask state not set for this command buffer'";
1161 }
1162}
1163
1164TEST_F(VkLayerTest, StencilReferenceNotSet)
1165{
1166 VkFlags msgFlags;
1167 std::string msgString;
1168 m_errorMonitor->ClearState();
1169 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1170
1171 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1172
1173 msgFlags = m_errorMonitor->GetState(&msgString);
1174 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Reference";
1175 if (!strstr(msgString.c_str(),"Dynamic stencil reference state not set for this command buffer")) {
1176 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil reference state not set for this command buffer'";
1177 }
1178}
1179
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001180TEST_F(VkLayerTest, CmdBufferTwoSubmits)
1181{
1182 vk_testing::Fence testFence;
1183 VkFlags msgFlags;
1184 std::string msgString;
1185
1186 VkFenceCreateInfo fenceInfo = {};
1187 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1188 fenceInfo.pNext = NULL;
1189 fenceInfo.flags = 0;
1190
1191 ASSERT_NO_FATAL_FAILURE(InitState());
1192 ASSERT_NO_FATAL_FAILURE(InitViewport());
1193 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1194
1195 // We luck out b/c by default the framework creates CB w/ the VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set
1196 BeginCommandBuffer();
1197 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
1198 EndCommandBuffer();
1199
1200 testFence.init(*m_device, fenceInfo);
1201
1202 // Bypass framework since it does the waits automatically
1203 VkResult err = VK_SUCCESS;
1204 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
1205 ASSERT_VK_SUCCESS( err );
1206
1207 m_errorMonitor->ClearState();
1208 // Cause validation error by re-submitting cmd buffer that should only be submitted once
1209 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001210
1211 msgFlags = m_errorMonitor->GetState(&msgString);
1212 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 -06001213 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 -06001214 FAIL() << "Error received was not 'CB (0xaddress) was created w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set...'";
1215 }
1216}
1217
Tobin Ehlise4076782015-06-24 15:53:07 -06001218TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001219{
1220 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001221 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001222 std::string msgString;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001223 VkResult err;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001224
1225 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001227 m_errorMonitor->ClearState();
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001228
1229 VkDescriptorTypeCount ds_type_count = {};
1230 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1231 ds_type_count.count = 1;
1232
1233 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1234 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1235 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001236 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1237 ds_pool_ci.maxSets = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001238 ds_pool_ci.count = 1;
1239 ds_pool_ci.pTypeCount = &ds_type_count;
1240
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001241 VkDescriptorPool ds_pool;
1242 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001243 ASSERT_VK_SUCCESS(err);
1244
1245 VkDescriptorSetLayoutBinding dsl_binding = {};
1246 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1247 dsl_binding.arraySize = 1;
1248 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1249 dsl_binding.pImmutableSamplers = NULL;
1250
1251 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1252 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1253 ds_layout_ci.pNext = NULL;
1254 ds_layout_ci.count = 1;
1255 ds_layout_ci.pBinding = &dsl_binding;
1256
1257 VkDescriptorSetLayout ds_layout;
1258 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1259 ASSERT_VK_SUCCESS(err);
1260
1261 VkDescriptorSet descriptorSet;
1262 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1263 ASSERT_VK_SUCCESS(err);
1264 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1265 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1266 pipe_ms_state_ci.pNext = NULL;
1267 pipe_ms_state_ci.rasterSamples = 1;
1268 pipe_ms_state_ci.sampleShadingEnable = 0;
1269 pipe_ms_state_ci.minSampleShading = 1.0;
1270 pipe_ms_state_ci.pSampleMask = NULL;
1271
1272 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1273 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1274 pipeline_layout_ci.pNext = NULL;
1275 pipeline_layout_ci.descriptorSetCount = 1;
1276 pipeline_layout_ci.pSetLayouts = &ds_layout;
1277 VkPipelineLayout pipeline_layout;
1278
1279 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1280 ASSERT_VK_SUCCESS(err);
1281
1282 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
1283 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1284 // but add it to be able to run on more devices
1285 VkPipelineObj pipe(m_device);
1286 pipe.AddShader(&vs);
1287 pipe.AddShader(&fs);
1288 pipe.SetMSAA(&pipe_ms_state_ci);
1289 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1290 m_errorMonitor->ClearState();
1291 // Calls CreateCommandBuffer
1292 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1293 VkCmdBufferBeginInfo cmd_buf_info = {};
1294 memset(&cmd_buf_info, 0, sizeof(VkCmdBufferBeginInfo));
1295 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1296 cmd_buf_info.pNext = NULL;
1297 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1298 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1299
1300 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1301 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001302 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001303 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 -06001304 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001305 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0x<handle>) without an active RenderPass'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001306 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001307
1308 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
1309 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1310 ASSERT_VK_SUCCESS(err);
1311 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1312 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001313}
1314
1315TEST_F(VkLayerTest, InvalidDescriptorPool)
1316{
1317 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1318 // The DS check for this is after driver has been called to validate DS internal data struct
1319 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001320/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001321 std::string msgString;
1322 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1323 vkResetDescriptorPool(device(), badPool);
1324
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001325 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001326 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 -06001327 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1328 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1329 }*/
1330}
1331
1332TEST_F(VkLayerTest, InvalidDescriptorSet)
1333{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001334 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1335 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001336 // Create a valid cmd buffer
1337 // call vkCmdBindDescriptorSets w/ false DS
1338}
1339
1340TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1341{
1342 // 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
1344}
1345
1346TEST_F(VkLayerTest, InvalidPipeline)
1347{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001348 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1349 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001350 // Create a valid cmd buffer
1351 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -06001352// VkFlags msgFlags;
1353// std::string msgString;
1354//
1355// ASSERT_NO_FATAL_FAILURE(InitState());
1356// m_errorMonitor->ClearState();
1357// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001358// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001359// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1360// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1361// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001362// 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 -06001363// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1364// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1365// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001366}
1367
Tobin Ehlis254eca02015-06-25 15:46:59 -06001368TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001369{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001370 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001371 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001372 std::string msgString;
1373 VkResult err;
1374
1375 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001376 ASSERT_NO_FATAL_FAILURE(InitViewport());
1377 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001378 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001379 VkDescriptorTypeCount ds_type_count = {};
1380 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1381 ds_type_count.count = 1;
1382
1383 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1384 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1385 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001386 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1387 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001388 ds_pool_ci.count = 1;
1389 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001390
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001391 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001392 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001393 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001394
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001395 VkDescriptorSetLayoutBinding dsl_binding = {};
1396 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1397 dsl_binding.arraySize = 1;
1398 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1399 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001400
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001401 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1402 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1403 ds_layout_ci.pNext = NULL;
1404 ds_layout_ci.count = 1;
1405 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001406 VkDescriptorSetLayout ds_layout;
1407 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1408 ASSERT_VK_SUCCESS(err);
1409
1410 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001411 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001412 ASSERT_VK_SUCCESS(err);
1413
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001414 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1415 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1416 pipeline_layout_ci.pNext = NULL;
1417 pipeline_layout_ci.descriptorSetCount = 1;
1418 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001419
1420 VkPipelineLayout pipeline_layout;
1421 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1422 ASSERT_VK_SUCCESS(err);
1423
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001424 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001425 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1426 // but add it to be able to run on more devices
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001427
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001428 VkPipelineObj pipe(m_device);
1429 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001430 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001431 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001432
1433 BeginCommandBuffer();
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001434 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbour1490c912015-07-28 10:17:20 -06001435 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001436
Tobin Ehlis254eca02015-06-25 15:46:59 -06001437 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001438 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 -06001439 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1440 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1441 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001442
1443 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
1444 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1445 ASSERT_VK_SUCCESS(err);
1446 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1447 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001448}
1449
1450TEST_F(VkLayerTest, NoBeginCmdBuffer)
1451{
1452 VkFlags msgFlags;
1453 std::string msgString;
1454
1455 ASSERT_NO_FATAL_FAILURE(InitState());
1456 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001457 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001458 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1459 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1460 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001461 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 -06001462 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1463 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1464 }
1465}
1466
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001467TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1468{
1469 VkFlags msgFlags;
1470 std::string msgString;
1471
1472 ASSERT_NO_FATAL_FAILURE(InitState());
1473 m_errorMonitor->ClearState();
1474
1475 // Calls CreateCommandBuffer
1476 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1477
1478 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northrop10d8f982015-08-04 17:35:57 -06001479 VkCmdBufferBeginInfo cmd_buf_info = {};
1480 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1481 cmd_buf_info.pNext = NULL;
1482 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1483 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1484 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1485 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1486
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001487
1488 // The error should be caught by validation of the BeginCommandBuffer call
1489 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1490
1491 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001492 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 -06001493 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1494 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1495 }
1496}
1497
1498TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1499{
1500 VkFlags msgFlags;
1501 std::string msgString;
1502 VkResult err;
1503 VkCmdBuffer draw_cmd;
1504 VkCmdPool cmd_pool;
1505
1506 ASSERT_NO_FATAL_FAILURE(InitState());
1507 m_errorMonitor->ClearState();
1508
Cody Northrop10d8f982015-08-04 17:35:57 -06001509 VkCmdBufferCreateInfo cmd = {};
1510 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1511 cmd.pNext = NULL;
1512 cmd.cmdPool = m_cmdPool;
1513 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1514 cmd.flags = 0;
1515
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001516 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
Mike Stroyan2237f522015-08-18 14:40:24 -06001517 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001518
1519 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northrop10d8f982015-08-04 17:35:57 -06001520 VkCmdBufferBeginInfo cmd_buf_info = {};
1521 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1522 cmd_buf_info.pNext = NULL;
1523 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1524 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001525
1526 // The error should be caught by validation of the BeginCommandBuffer call
1527 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1528
1529 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001530 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 -06001531 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1532 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1533 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001534 vkDestroyCommandBuffer(m_device->device(), draw_cmd);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001535}
1536
Tobin Ehlis254eca02015-06-25 15:46:59 -06001537TEST_F(VkLayerTest, InvalidPipelineCreateState)
1538{
1539 // Attempt to Create Gfx Pipeline w/o a VS
1540 VkFlags msgFlags;
1541 std::string msgString;
1542 VkResult err;
1543
1544 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001545 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis254eca02015-06-25 15:46:59 -06001546 m_errorMonitor->ClearState();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001547
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001548 VkDescriptorTypeCount ds_type_count = {};
1549 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1550 ds_type_count.count = 1;
1551
1552 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1553 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1554 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001555 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1556 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001557 ds_pool_ci.count = 1;
1558 ds_pool_ci.pTypeCount = &ds_type_count;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001559
Tobin Ehlis254eca02015-06-25 15:46:59 -06001560 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001561 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001562 ASSERT_VK_SUCCESS(err);
1563
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001564 VkDescriptorSetLayoutBinding dsl_binding = {};
1565 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1566 dsl_binding.arraySize = 1;
1567 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1568 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001569
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001570 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1571 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1572 ds_layout_ci.pNext = NULL;
1573 ds_layout_ci.count = 1;
1574 ds_layout_ci.pBinding = &dsl_binding;
1575
Tobin Ehlis254eca02015-06-25 15:46:59 -06001576 VkDescriptorSetLayout ds_layout;
1577 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1578 ASSERT_VK_SUCCESS(err);
1579
1580 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001581 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001582 ASSERT_VK_SUCCESS(err);
1583
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001584 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1585 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001586 pipeline_layout_ci.descriptorSetCount = 1;
1587 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001588
1589 VkPipelineLayout pipeline_layout;
1590 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1591 ASSERT_VK_SUCCESS(err);
1592
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001593 VkViewport vp = {}; // Just need dummy vp to point to
1594 VkRect2D sc = {}; // dummy scissor to point to
1595
1596 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1597 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1598 vp_state_ci.scissorCount = 1;
1599 vp_state_ci.pScissors = &sc;
1600 vp_state_ci.viewportCount = 1;
1601 vp_state_ci.pViewports = &vp;
1602
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001603 VkGraphicsPipelineCreateInfo gp_ci = {};
1604 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001605 gp_ci.pViewportState = &vp_state_ci;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001606 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1607 gp_ci.layout = pipeline_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001608 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001609
1610 VkPipelineCacheCreateInfo pc_ci = {};
1611 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001612 pc_ci.initialSize = 0;
1613 pc_ci.initialData = 0;
1614 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001615
1616 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001617 VkPipelineCache pipelineCache;
1618
1619 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1620 ASSERT_VK_SUCCESS(err);
1621 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001622
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001623 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001624 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 -06001625 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1626 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1627 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001628
1629 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1630 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
1631 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1632 ASSERT_VK_SUCCESS(err);
1633 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1634 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001635}
Tobin Ehlis20693172015-09-17 08:46:18 -06001636/*// TODO : This test should be good, but needs Tess support in compiler to run
1637TEST_F(VkLayerTest, InvalidPatchControlPoints)
1638{
1639 // Attempt to Create Gfx Pipeline w/o a VS
1640 VkFlags msgFlags;
1641 std::string msgString;
1642 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001643
Tobin Ehlis20693172015-09-17 08:46:18 -06001644 ASSERT_NO_FATAL_FAILURE(InitState());
1645 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1646 m_errorMonitor->ClearState();
1647
1648 VkDescriptorTypeCount ds_type_count = {};
1649 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1650 ds_type_count.count = 1;
1651
1652 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1653 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1654 ds_pool_ci.pNext = NULL;
1655 ds_pool_ci.count = 1;
1656 ds_pool_ci.pTypeCount = &ds_type_count;
1657
1658 VkDescriptorPool ds_pool;
1659 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1660 ASSERT_VK_SUCCESS(err);
1661
1662 VkDescriptorSetLayoutBinding dsl_binding = {};
1663 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1664 dsl_binding.arraySize = 1;
1665 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1666 dsl_binding.pImmutableSamplers = NULL;
1667
1668 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1669 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1670 ds_layout_ci.pNext = NULL;
1671 ds_layout_ci.count = 1;
1672 ds_layout_ci.pBinding = &dsl_binding;
1673
1674 VkDescriptorSetLayout ds_layout;
1675 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1676 ASSERT_VK_SUCCESS(err);
1677
1678 VkDescriptorSet descriptorSet;
1679 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1680 ASSERT_VK_SUCCESS(err);
1681
1682 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1683 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1684 pipeline_layout_ci.pNext = NULL;
1685 pipeline_layout_ci.descriptorSetCount = 1;
1686 pipeline_layout_ci.pSetLayouts = &ds_layout;
1687
1688 VkPipelineLayout pipeline_layout;
1689 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1690 ASSERT_VK_SUCCESS(err);
1691
1692 VkPipelineShaderStageCreateInfo shaderStages[3];
1693 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
1694
1695 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
1696 // Just using VS txt for Tess shaders as we don't care about functionality
1697 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESS_CONTROL, this);
1698 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESS_EVALUATION, this);
1699
1700 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1701 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
1702 shaderStages[0].shader = vs.handle();
1703 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1704 shaderStages[1].stage = VK_SHADER_STAGE_TESS_CONTROL;
1705 shaderStages[1].shader = tc.handle();
1706 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1707 shaderStages[2].stage = VK_SHADER_STAGE_TESS_EVALUATION;
1708 shaderStages[2].shader = te.handle();
1709
1710 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
1711 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
1712 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH;
1713
1714 VkPipelineTessellationStateCreateInfo tsCI = {};
1715 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
1716 tsCI.patchControlPoints = 0; // This will cause an error
1717
1718 VkGraphicsPipelineCreateInfo gp_ci = {};
1719 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1720 gp_ci.pNext = NULL;
1721 gp_ci.stageCount = 3;
1722 gp_ci.pStages = shaderStages;
1723 gp_ci.pVertexInputState = NULL;
1724 gp_ci.pInputAssemblyState = &iaCI;
1725 gp_ci.pTessellationState = &tsCI;
1726 gp_ci.pViewportState = NULL;
1727 gp_ci.pRasterState = NULL;
1728 gp_ci.pMultisampleState = NULL;
1729 gp_ci.pDepthStencilState = NULL;
1730 gp_ci.pColorBlendState = NULL;
1731 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1732 gp_ci.layout = pipeline_layout;
1733 gp_ci.renderPass = renderPass();
1734
1735 VkPipelineCacheCreateInfo pc_ci = {};
1736 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1737 pc_ci.pNext = NULL;
1738 pc_ci.initialSize = 0;
1739 pc_ci.initialData = 0;
1740 pc_ci.maxSize = 0;
1741
1742 VkPipeline pipeline;
1743 VkPipelineCache pipelineCache;
1744
1745 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1746 ASSERT_VK_SUCCESS(err);
1747 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1748
1749 msgFlags = m_errorMonitor->GetState(&msgString);
1750 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Tess Gfx Pipeline w/ 0 patchControlPoints.";
1751 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ")) {
1752 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...' but instead '" << msgString.c_str() << "'";
1753 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001754
1755 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1756 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
1757 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1758 ASSERT_VK_SUCCESS(err);
1759 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1760 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis20693172015-09-17 08:46:18 -06001761}
1762*/
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001763// Set scissor and viewport counts to different numbers
1764TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
1765{
1766 // Attempt to Create Gfx Pipeline w/o a VS
1767 VkFlags msgFlags;
1768 std::string msgString;
1769 VkResult err;
1770
1771 ASSERT_NO_FATAL_FAILURE(InitState());
1772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1773 m_errorMonitor->ClearState();
1774
1775 VkDescriptorTypeCount ds_type_count = {};
1776 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1777 ds_type_count.count = 1;
1778
1779 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1780 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1781 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1782 ds_pool_ci.maxSets = 1;
1783 ds_pool_ci.count = 1;
1784 ds_pool_ci.pTypeCount = &ds_type_count;
1785
1786 VkDescriptorPool ds_pool;
1787 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1788 ASSERT_VK_SUCCESS(err);
1789
1790 VkDescriptorSetLayoutBinding dsl_binding = {};
1791 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1792 dsl_binding.arraySize = 1;
1793 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1794
1795 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1796 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1797 ds_layout_ci.count = 1;
1798 ds_layout_ci.pBinding = &dsl_binding;
1799
1800 VkDescriptorSetLayout ds_layout;
1801 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1802 ASSERT_VK_SUCCESS(err);
1803
1804 VkDescriptorSet descriptorSet;
1805 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1806 ASSERT_VK_SUCCESS(err);
1807
1808 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1809 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1810 pipeline_layout_ci.descriptorSetCount = 1;
1811 pipeline_layout_ci.pSetLayouts = &ds_layout;
1812
1813 VkPipelineLayout pipeline_layout;
1814 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1815 ASSERT_VK_SUCCESS(err);
1816
1817 VkViewport vp = {}; // Just need dummy vp to point to
1818
1819 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1820 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1821 vp_state_ci.scissorCount = 0;
1822 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
1823 vp_state_ci.pViewports = &vp;
1824
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001825 VkPipelineShaderStageCreateInfo shaderStages[2];
1826 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001827
1828 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001829 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1830 // but add it to be able to run on more devices
1831 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1832 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
1833 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001834
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001835 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1836 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT;
1837 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001838
1839 VkGraphicsPipelineCreateInfo gp_ci = {};
1840 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001841 gp_ci.stageCount = 2;
1842 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001843 gp_ci.pViewportState = &vp_state_ci;
1844 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1845 gp_ci.layout = pipeline_layout;
1846 gp_ci.renderPass = renderPass();
1847
1848 VkPipelineCacheCreateInfo pc_ci = {};
1849 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1850
1851 VkPipeline pipeline;
1852 VkPipelineCache pipelineCache;
1853
1854 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1855 ASSERT_VK_SUCCESS(err);
1856 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1857
1858 msgFlags = m_errorMonitor->GetState(&msgString);
1859 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/ viewport and scissor count mismatch.";
1860 if (!strstr(msgString.c_str(),"Gfx Pipeline viewport count (1) must match scissor count (0).")) {
1861 FAIL() << "Error received was not 'Gfx Pipeline viewport count (1) must match scissor count (0).' but instead it was '" << msgString.c_str() << "'";
1862 }
1863
1864 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1865 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
1866 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1867 ASSERT_VK_SUCCESS(err);
1868 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1869 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1870}
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001871// Don't set viewport state in PSO. This is an error b/c we always need this state
1872// for the counts even if the data is going to be set dynamically.
1873TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001874{
1875 // Attempt to Create Gfx Pipeline w/o a VS
1876 VkFlags msgFlags;
1877 std::string msgString;
1878 VkResult err;
1879
1880 ASSERT_NO_FATAL_FAILURE(InitState());
1881 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1882 m_errorMonitor->ClearState();
1883
1884 VkDescriptorTypeCount ds_type_count = {};
1885 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1886 ds_type_count.count = 1;
1887
1888 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1889 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1890 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1891 ds_pool_ci.maxSets = 1;
1892 ds_pool_ci.count = 1;
1893 ds_pool_ci.pTypeCount = &ds_type_count;
1894
1895 VkDescriptorPool ds_pool;
1896 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1897 ASSERT_VK_SUCCESS(err);
1898
1899 VkDescriptorSetLayoutBinding dsl_binding = {};
1900 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1901 dsl_binding.arraySize = 1;
1902 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1903
1904 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1905 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1906 ds_layout_ci.count = 1;
1907 ds_layout_ci.pBinding = &dsl_binding;
1908
1909 VkDescriptorSetLayout ds_layout;
1910 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1911 ASSERT_VK_SUCCESS(err);
1912
1913 VkDescriptorSet descriptorSet;
1914 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1915 ASSERT_VK_SUCCESS(err);
1916
1917 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1918 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1919 pipeline_layout_ci.descriptorSetCount = 1;
1920 pipeline_layout_ci.pSetLayouts = &ds_layout;
1921
1922 VkPipelineLayout pipeline_layout;
1923 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1924 ASSERT_VK_SUCCESS(err);
1925
1926 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
1927 // Set scissor as dynamic to avoid second error
1928 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
1929 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
1930 dyn_state_ci.dynamicStateCount = 1;
1931 dyn_state_ci.pDynamicStates = &sc_state;
1932
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001933 VkPipelineShaderStageCreateInfo shaderStages[2];
1934 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001935
1936 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001937 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1938 // but add it to be able to run on more devices
1939 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1940 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
1941 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001942
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001943 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1944 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT;
1945 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001946
1947 VkGraphicsPipelineCreateInfo gp_ci = {};
1948 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001949 gp_ci.stageCount = 2;
1950 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001951 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
1952 gp_ci.pDynamicState = &dyn_state_ci;
1953 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1954 gp_ci.layout = pipeline_layout;
1955 gp_ci.renderPass = renderPass();
1956
1957 VkPipelineCacheCreateInfo pc_ci = {};
1958 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1959
1960 VkPipeline pipeline;
1961 VkPipelineCache pipelineCache;
1962
1963 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1964 ASSERT_VK_SUCCESS(err);
1965 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1966
1967 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001968 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o viewport state set.";
1969 if (!strstr(msgString.c_str(),"Gfx Pipeline pViewportState is null. Even if ")) {
1970 FAIL() << "Error received was not 'Gfx Pipeline pViewportState is null. Even if...' but instead it was '" << msgString.c_str() << "'";
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001971 }
1972
1973 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1974 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
1975 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1976 ASSERT_VK_SUCCESS(err);
1977 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1978 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1979}
1980// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001981// Then run second test where dynamic scissor count doesn't match PSO scissor count
1982TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001983{
1984 VkFlags msgFlags;
1985 std::string msgString;
1986 VkResult err;
1987
1988 ASSERT_NO_FATAL_FAILURE(InitState());
1989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1990 m_errorMonitor->ClearState();
1991
1992 VkDescriptorTypeCount ds_type_count = {};
1993 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1994 ds_type_count.count = 1;
1995
1996 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1997 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1998 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1999 ds_pool_ci.maxSets = 1;
2000 ds_pool_ci.count = 1;
2001 ds_pool_ci.pTypeCount = &ds_type_count;
2002
2003 VkDescriptorPool ds_pool;
2004 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2005 ASSERT_VK_SUCCESS(err);
2006
2007 VkDescriptorSetLayoutBinding dsl_binding = {};
2008 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2009 dsl_binding.arraySize = 1;
2010 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2011
2012 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2013 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2014 ds_layout_ci.count = 1;
2015 ds_layout_ci.pBinding = &dsl_binding;
2016
2017 VkDescriptorSetLayout ds_layout;
2018 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2019 ASSERT_VK_SUCCESS(err);
2020
2021 VkDescriptorSet descriptorSet;
2022 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
2023 ASSERT_VK_SUCCESS(err);
2024
2025 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2026 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2027 pipeline_layout_ci.descriptorSetCount = 1;
2028 pipeline_layout_ci.pSetLayouts = &ds_layout;
2029
2030 VkPipelineLayout pipeline_layout;
2031 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2032 ASSERT_VK_SUCCESS(err);
2033
2034 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2035 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2036 vp_state_ci.viewportCount = 1;
2037 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2038 vp_state_ci.scissorCount = 1;
2039 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2040
2041 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2042 // Set scissor as dynamic to avoid that error
2043 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2044 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2045 dyn_state_ci.dynamicStateCount = 1;
2046 dyn_state_ci.pDynamicStates = &sc_state;
2047
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002048 VkPipelineShaderStageCreateInfo shaderStages[2];
2049 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002050
2051 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002052 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2053 // but add it to be able to run on more devices
2054 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2055 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
2056 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002057
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002058 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2059 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT;
2060 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002061
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002062 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2063 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2064 vi_ci.pNext = nullptr;
2065 vi_ci.bindingCount = 0;
2066 vi_ci.pVertexBindingDescriptions = nullptr;
2067 vi_ci.attributeCount = 0;
2068 vi_ci.pVertexAttributeDescriptions = nullptr;
2069
2070 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2071 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2072 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2073
2074 VkPipelineRasterStateCreateInfo rs_ci = {};
2075 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2076 rs_ci.pNext = nullptr;
2077
2078 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2079 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2080 cb_ci.pNext = nullptr;
2081
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002082 VkGraphicsPipelineCreateInfo gp_ci = {};
2083 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002084 gp_ci.stageCount = 2;
2085 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002086 gp_ci.pVertexInputState = &vi_ci;
2087 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002088 gp_ci.pViewportState = &vp_state_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002089 gp_ci.pRasterState = &rs_ci;
2090 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002091 gp_ci.pDynamicState = &dyn_state_ci;
2092 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2093 gp_ci.layout = pipeline_layout;
2094 gp_ci.renderPass = renderPass();
2095
2096 VkPipelineCacheCreateInfo pc_ci = {};
2097 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2098
2099 VkPipeline pipeline;
2100 VkPipelineCache pipelineCache;
2101
2102 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2103 ASSERT_VK_SUCCESS(err);
2104 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2105
2106 msgFlags = m_errorMonitor->GetState(&msgString);
2107 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2108 if (!strstr(msgString.c_str(),"Gfx Pipeline viewportCount is 1, but pViewports is NULL. ")) {
2109 FAIL() << "Error received was not 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...' but instead it was '" << msgString.c_str() << "'";
2110 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002111 m_errorMonitor->ClearState();
2112 // Now hit second fail case where we set scissor w/ different count than PSO
2113 // First need to successfully create the PSO from above by setting pViewports
2114 VkViewport vp = {}; // Just need dummy vp to point to
2115 vp_state_ci.pViewports = &vp;
2116 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2117 ASSERT_VK_SUCCESS(err);
2118 BeginCommandBuffer();
2119 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2120 VkRect2D scissors[2] = {}; // don't care about data
2121 // Count of 2 doesn't match PSO count of 1
2122 vkCmdSetScissor(m_cmdBuffer->GetBufferHandle(), 2, scissors);
2123 Draw(1, 0, 0, 0);
2124
2125 msgFlags = m_errorMonitor->GetState(&msgString);
2126 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic scissorCount different from PSO scissorCount.";
2127 if (!strstr(msgString.c_str(),"Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.")) {
2128 FAIL() << "Error received was not 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...' but instead it was '" << msgString.c_str() << "'";
2129 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002130
2131 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2132 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
2133 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2134 ASSERT_VK_SUCCESS(err);
2135 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2136 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2137}
2138// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002139// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2140TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002141{
2142 VkFlags msgFlags;
2143 std::string msgString;
2144 VkResult err;
2145
2146 ASSERT_NO_FATAL_FAILURE(InitState());
2147 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2148 m_errorMonitor->ClearState();
2149
2150 VkDescriptorTypeCount ds_type_count = {};
2151 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2152 ds_type_count.count = 1;
2153
2154 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2155 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2156 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2157 ds_pool_ci.maxSets = 1;
2158 ds_pool_ci.count = 1;
2159 ds_pool_ci.pTypeCount = &ds_type_count;
2160
2161 VkDescriptorPool ds_pool;
2162 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2163 ASSERT_VK_SUCCESS(err);
2164
2165 VkDescriptorSetLayoutBinding dsl_binding = {};
2166 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2167 dsl_binding.arraySize = 1;
2168 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2169
2170 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2171 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2172 ds_layout_ci.count = 1;
2173 ds_layout_ci.pBinding = &dsl_binding;
2174
2175 VkDescriptorSetLayout ds_layout;
2176 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2177 ASSERT_VK_SUCCESS(err);
2178
2179 VkDescriptorSet descriptorSet;
2180 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
2181 ASSERT_VK_SUCCESS(err);
2182
2183 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2184 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2185 pipeline_layout_ci.descriptorSetCount = 1;
2186 pipeline_layout_ci.pSetLayouts = &ds_layout;
2187
2188 VkPipelineLayout pipeline_layout;
2189 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2190 ASSERT_VK_SUCCESS(err);
2191
2192 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2193 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2194 vp_state_ci.scissorCount = 1;
2195 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2196 vp_state_ci.viewportCount = 1;
2197 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2198
2199 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2200 // Set scissor as dynamic to avoid that error
2201 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2202 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2203 dyn_state_ci.dynamicStateCount = 1;
2204 dyn_state_ci.pDynamicStates = &vp_state;
2205
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002206 VkPipelineShaderStageCreateInfo shaderStages[2];
2207 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002208
2209 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002210 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2211 // but add it to be able to run on more devices
2212 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2213 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
2214 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002215
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002216 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2217 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT;
2218 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002219
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002220 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2221 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2222 vi_ci.pNext = nullptr;
2223 vi_ci.bindingCount = 0;
2224 vi_ci.pVertexBindingDescriptions = nullptr;
2225 vi_ci.attributeCount = 0;
2226 vi_ci.pVertexAttributeDescriptions = nullptr;
2227
2228 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2229 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2230 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2231
2232 VkPipelineRasterStateCreateInfo rs_ci = {};
2233 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2234 rs_ci.pNext = nullptr;
2235
2236 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2237 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2238 cb_ci.pNext = nullptr;
2239
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002240 VkGraphicsPipelineCreateInfo gp_ci = {};
2241 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002242 gp_ci.stageCount = 2;
2243 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002244 gp_ci.pVertexInputState = &vi_ci;
2245 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002246 gp_ci.pViewportState = &vp_state_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002247 gp_ci.pRasterState = &rs_ci;
2248 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002249 gp_ci.pDynamicState = &dyn_state_ci;
2250 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2251 gp_ci.layout = pipeline_layout;
2252 gp_ci.renderPass = renderPass();
2253
2254 VkPipelineCacheCreateInfo pc_ci = {};
2255 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2256
2257 VkPipeline pipeline;
2258 VkPipelineCache pipelineCache;
2259
2260 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2261 ASSERT_VK_SUCCESS(err);
2262 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2263
2264 msgFlags = m_errorMonitor->GetState(&msgString);
2265 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2266 if (!strstr(msgString.c_str(),"Gfx Pipeline scissorCount is 1, but pScissors is NULL. ")) {
2267 FAIL() << "Error received was not 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...' but instead it was '" << msgString.c_str() << "'";
2268 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002269 m_errorMonitor->ClearState();
2270 // Now hit second fail case where we set scissor w/ different count than PSO
2271 // First need to successfully create the PSO from above by setting pViewports
2272 VkRect2D sc = {}; // Just need dummy vp to point to
2273 vp_state_ci.pScissors = &sc;
2274 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2275 ASSERT_VK_SUCCESS(err);
2276 BeginCommandBuffer();
2277 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2278 VkViewport viewports[2] = {}; // don't care about data
2279 // Count of 2 doesn't match PSO count of 1
2280 vkCmdSetViewport(m_cmdBuffer->GetBufferHandle(), 2, viewports);
2281 Draw(1, 0, 0, 0);
2282
2283 msgFlags = m_errorMonitor->GetState(&msgString);
2284 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic viewportCount different from PSO viewportCount.";
2285 if (!strstr(msgString.c_str(),"Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.")) {
2286 FAIL() << "Error received was not 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...' but instead it was '" << msgString.c_str() << "'";
2287 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002288
2289 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2290 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
2291 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2292 ASSERT_VK_SUCCESS(err);
2293 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2294 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2295}
2296
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002297TEST_F(VkLayerTest, NullRenderPass)
2298{
2299 // Bind a NULL RenderPass
2300 VkFlags msgFlags;
2301 std::string msgString;
2302
2303 ASSERT_NO_FATAL_FAILURE(InitState());
2304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2305 m_errorMonitor->ClearState();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002306
Tony Barbour1490c912015-07-28 10:17:20 -06002307 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002308 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06002309 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002310
2311 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002312 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002313 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
2314 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
2315 }
2316}
2317
Tobin Ehlis254eca02015-06-25 15:46:59 -06002318TEST_F(VkLayerTest, RenderPassWithinRenderPass)
2319{
2320 // Bind a BeginRenderPass within an active RenderPass
2321 VkFlags msgFlags;
2322 std::string msgString;
2323
2324 ASSERT_NO_FATAL_FAILURE(InitState());
2325 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2326 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06002327
Tony Barbour1490c912015-07-28 10:17:20 -06002328 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002329 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002330 VkRenderPassBeginInfo rp_begin = {};
2331 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
2332 rp_begin.pNext = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002333 rp_begin.renderPass = renderPass();
2334 rp_begin.framebuffer = framebuffer();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002335
Tony Barbour1490c912015-07-28 10:17:20 -06002336 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002337
2338 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002339 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding RenderPass w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002340 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2341 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002342 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002343}
2344
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002345TEST_F(VkLayerTest, FillBufferWithinRenderPass)
2346{
2347 // Call CmdFillBuffer within an active renderpass
2348 VkFlags msgFlags;
2349 std::string msgString;
2350
2351 ASSERT_NO_FATAL_FAILURE(InitState());
2352 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2353 m_errorMonitor->ClearState();
2354
2355 // Renderpass is started here
2356 BeginCommandBuffer();
2357
2358 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2359 vk_testing::Buffer destBuffer;
2360 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
2361
2362 m_cmdBuffer->FillBuffer(destBuffer.handle(), 0, 4, 0x11111111);
2363
2364 msgFlags = m_errorMonitor->GetState(&msgString);
2365 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2366 "Did not receive error after calling CmdFillBuffer w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002367 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2368 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002369 }
2370}
2371
2372TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
2373{
2374 // Call CmdUpdateBuffer within an active renderpass
2375 VkFlags msgFlags;
2376 std::string msgString;
2377
2378 ASSERT_NO_FATAL_FAILURE(InitState());
2379 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2380 m_errorMonitor->ClearState();
2381
2382 // Renderpass is started here
2383 BeginCommandBuffer();
2384
2385 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2386 vk_testing::Buffer destBuffer;
2387 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
2388
2389 VkDeviceSize destOffset = 0;
2390 VkDeviceSize dataSize = 1024;
2391 const uint32_t *pData = NULL;
2392
2393 vkCmdUpdateBuffer(m_cmdBuffer->GetBufferHandle(), destBuffer.handle(), destOffset, dataSize, pData);
2394
2395 msgFlags = m_errorMonitor->GetState(&msgString);
2396 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2397 "Did not receive error after calling CmdUpdateBuffer w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002398 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2399 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002400 }
2401}
2402
2403TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
2404{
2405 // Call CmdClearColorImage within an active RenderPass
2406 VkFlags msgFlags;
2407 std::string msgString;
2408
2409 ASSERT_NO_FATAL_FAILURE(InitState());
2410 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2411 m_errorMonitor->ClearState();
2412
2413 // Renderpass is started here
2414 BeginCommandBuffer();
2415
2416 VkClearColorValue clear_color = {0};
2417 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2418 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2419 const int32_t tex_width = 32;
2420 const int32_t tex_height = 32;
2421 VkImageCreateInfo image_create_info = {};
2422 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2423 image_create_info.pNext = NULL;
2424 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2425 image_create_info.format = tex_format;
2426 image_create_info.extent.width = tex_width;
2427 image_create_info.extent.height = tex_height;
2428 image_create_info.extent.depth = 1;
2429 image_create_info.mipLevels = 1;
2430 image_create_info.arraySize = 1;
2431 image_create_info.samples = 1;
2432 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2433 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2434
2435 vk_testing::Image destImage;
2436 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
2437
2438 const VkImageSubresourceRange range =
2439 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
2440
2441 vkCmdClearColorImage(m_cmdBuffer->GetBufferHandle(),
2442 destImage.handle(),
2443 VK_IMAGE_LAYOUT_GENERAL,
2444 &clear_color,
2445 1,
2446 &range);
2447
2448 msgFlags = m_errorMonitor->GetState(&msgString);
2449 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2450 "Did not receive error after calling CmdClearColorImage w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002451 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2452 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002453 }
2454}
2455
2456TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
2457{
2458 // Call CmdClearDepthStencilImage within an active RenderPass
2459 VkFlags msgFlags;
2460 std::string msgString;
2461
2462 ASSERT_NO_FATAL_FAILURE(InitState());
2463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2464 m_errorMonitor->ClearState();
2465
2466 // Renderpass is started here
2467 BeginCommandBuffer();
2468
2469 VkClearDepthStencilValue clear_value = {0};
2470 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2471 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
2472 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2473 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
2474 image_create_info.extent.width = 64;
2475 image_create_info.extent.height = 64;
2476 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2477 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
2478
2479 vk_testing::Image destImage;
2480 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
2481
2482 const VkImageSubresourceRange range =
2483 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
2484
2485 vkCmdClearDepthStencilImage(m_cmdBuffer->GetBufferHandle(),
2486 destImage.handle(),
2487 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2488 &clear_value,
2489 1,
2490 &range);
2491
2492 msgFlags = m_errorMonitor->GetState(&msgString);
2493 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2494 "Did not receive error after calling CmdClearDepthStencilImage w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002495 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2496 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002497 }
2498}
2499
2500TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
2501{
2502 // Call CmdClearColorAttachments outside of an active RenderPass
2503 VkFlags msgFlags;
2504 std::string msgString;
2505 VkResult err;
2506
2507 ASSERT_NO_FATAL_FAILURE(InitState());
2508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2509 m_errorMonitor->ClearState();
2510
2511 // Start no RenderPass
2512 err = m_cmdBuffer->BeginCommandBuffer();
2513 ASSERT_VK_SUCCESS(err);
2514
2515 VkClearColorValue clear_color = {0};
2516 VkRect3D clear_rect = { { 0, 0, 0 }, { 32, 32, 1 } };
2517
2518 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0,
2519 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2520 &clear_color, 1, &clear_rect);
2521
2522 msgFlags = m_errorMonitor->GetState(&msgString);
2523 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2524 "Did not receive error after calling CmdClearColorAttachment outside of an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002525 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment: This call must be issued inside an active render pass")) {
2526 FAIL() << "Error received was not 'vkCmdClearColorAttachment: This call must be issued inside an active render pass.'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002527 }
2528}
2529
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002530TEST_F(VkLayerTest, InvalidDynamicStateObject)
2531{
2532 // Create a valid cmd buffer
2533 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002534 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
2535 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002536}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06002537
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002538TEST_F(VkLayerTest, IdxBufferAlignmentError)
2539{
2540 // Bind a BeginRenderPass within an active RenderPass
2541 VkFlags msgFlags;
2542 std::string msgString;
2543 VkResult err;
2544
2545 ASSERT_NO_FATAL_FAILURE(InitState());
2546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2547 m_errorMonitor->ClearState();
2548 uint32_t qfi = 0;
2549 VkBufferCreateInfo buffCI = {};
2550 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2551 buffCI.size = 1024;
2552 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
2553 buffCI.queueFamilyCount = 1;
2554 buffCI.pQueueFamilyIndices = &qfi;
2555
2556 VkBuffer ib;
2557 err = vkCreateBuffer(m_device->device(), &buffCI, &ib);
2558 ASSERT_VK_SUCCESS(err);
2559
2560 BeginCommandBuffer();
2561 ASSERT_VK_SUCCESS(err);
2562 //vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2563 // Should error before calling to driver so don't care about actual data
2564 vkCmdBindIndexBuffer(m_cmdBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
2565
2566 msgFlags = m_errorMonitor->GetState(&msgString);
2567 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2568 if (!strstr(msgString.c_str(),"vkCmdBindIndexBuffer() offset (0x7) does not fall on ")) {
2569 FAIL() << "Error received was not 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...' but instead '" << msgString.c_str() << "'";
2570 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002571
2572 vkDestroyBuffer(m_device->device(), ib);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002573}
2574
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002575TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
2576{
2577 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
2578 VkFlags msgFlags;
2579 std::string msgString;
2580
2581 ASSERT_NO_FATAL_FAILURE(InitState());
2582 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2583 m_errorMonitor->ClearState();
2584
2585 BeginCommandBuffer();
2586 //ASSERT_VK_SUCCESS(err);
2587 VkCmdBuffer primCB = m_cmdBuffer->GetBufferHandle();
2588 vkCmdExecuteCommands(m_cmdBuffer->GetBufferHandle(), 1, &primCB);
2589
2590 msgFlags = m_errorMonitor->GetState(&msgString);
2591 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2592 if (!strstr(msgString.c_str(),"vkCmdExecuteCommands() called w/ Primary Cmd Buffer ")) {
2593 FAIL() << "Error received was not 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer ' but instead '" << msgString.c_str() << "'";
2594 }
2595}
2596
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002597TEST_F(VkLayerTest, DSTypeMismatch)
2598{
2599 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002600 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002601 std::string msgString;
2602 VkResult err;
2603
2604 ASSERT_NO_FATAL_FAILURE(InitState());
2605 m_errorMonitor->ClearState();
2606 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002607 VkDescriptorTypeCount ds_type_count = {};
2608 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2609 ds_type_count.count = 1;
2610
2611 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2612 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2613 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002614 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2615 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002616 ds_pool_ci.count = 1;
2617 ds_pool_ci.pTypeCount = &ds_type_count;
2618
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002619 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002620 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002621 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002622 VkDescriptorSetLayoutBinding dsl_binding = {};
2623 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2624 dsl_binding.arraySize = 1;
2625 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2626 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002627
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002628 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2629 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2630 ds_layout_ci.pNext = NULL;
2631 ds_layout_ci.count = 1;
2632 ds_layout_ci.pBinding = &dsl_binding;
2633
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002634 VkDescriptorSetLayout ds_layout;
2635 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2636 ASSERT_VK_SUCCESS(err);
2637
2638 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002639 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002640 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002641
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002642 VkSamplerCreateInfo sampler_ci = {};
2643 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2644 sampler_ci.pNext = NULL;
2645 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2646 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2647 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002648 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2649 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2650 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002651 sampler_ci.mipLodBias = 1.0;
2652 sampler_ci.maxAnisotropy = 1;
2653 sampler_ci.compareEnable = VK_FALSE;
2654 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2655 sampler_ci.minLod = 1.0;
2656 sampler_ci.maxLod = 1.0;
2657 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002658 sampler_ci.unnormalizedCoordinates = VK_FALSE;
2659
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002660 VkSampler sampler;
2661 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2662 ASSERT_VK_SUCCESS(err);
2663
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002664 VkDescriptorInfo descriptor_info;
2665 memset(&descriptor_info, 0, sizeof(descriptor_info));
2666 descriptor_info.sampler = sampler;
2667
2668 VkWriteDescriptorSet descriptor_write;
2669 memset(&descriptor_write, 0, sizeof(descriptor_write));
2670 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2671 descriptor_write.destSet = descriptorSet;
2672 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002673 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002674 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2675 descriptor_write.pDescriptors = &descriptor_info;
2676
2677 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2678
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002679 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002680 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 -06002681 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 ")) {
2682 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 -06002683 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002684
2685 vkDestroySampler(m_device->device(), sampler);
2686 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2687 ASSERT_VK_SUCCESS(err);
2688 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2689 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002690}
2691
2692TEST_F(VkLayerTest, DSUpdateOutOfBounds)
2693{
2694 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002695 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002696 std::string msgString;
2697 VkResult err;
2698
2699 ASSERT_NO_FATAL_FAILURE(InitState());
2700 m_errorMonitor->ClearState();
2701 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002702 VkDescriptorTypeCount ds_type_count = {};
2703 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2704 ds_type_count.count = 1;
2705
2706 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2707 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2708 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002709 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2710 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002711 ds_pool_ci.count = 1;
2712 ds_pool_ci.pTypeCount = &ds_type_count;
2713
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002714 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002715 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002716 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002717
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002718 VkDescriptorSetLayoutBinding dsl_binding = {};
2719 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2720 dsl_binding.arraySize = 1;
2721 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2722 dsl_binding.pImmutableSamplers = NULL;
2723
2724 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2725 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2726 ds_layout_ci.pNext = NULL;
2727 ds_layout_ci.count = 1;
2728 ds_layout_ci.pBinding = &dsl_binding;
2729
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002730 VkDescriptorSetLayout ds_layout;
2731 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2732 ASSERT_VK_SUCCESS(err);
2733
2734 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002735 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002736 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002737
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002738 VkSamplerCreateInfo sampler_ci = {};
2739 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2740 sampler_ci.pNext = NULL;
2741 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2742 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2743 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002744 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2745 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2746 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002747 sampler_ci.mipLodBias = 1.0;
2748 sampler_ci.maxAnisotropy = 1;
2749 sampler_ci.compareEnable = VK_FALSE;
2750 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2751 sampler_ci.minLod = 1.0;
2752 sampler_ci.maxLod = 1.0;
2753 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002754 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002755
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002756 VkSampler sampler;
2757 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2758 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002759
2760 VkDescriptorInfo descriptor_info;
2761 memset(&descriptor_info, 0, sizeof(descriptor_info));
2762 descriptor_info.sampler = sampler;
2763
2764 VkWriteDescriptorSet descriptor_write;
2765 memset(&descriptor_write, 0, sizeof(descriptor_write));
2766 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2767 descriptor_write.destSet = descriptorSet;
2768 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
2769 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002770 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002771 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2772 descriptor_write.pDescriptors = &descriptor_info;
2773
2774 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2775
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002776 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002777 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 +08002778 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
2779 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 -06002780 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002781
2782 vkDestroySampler(m_device->device(), sampler);
2783 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2784 ASSERT_VK_SUCCESS(err);
2785 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2786 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002787}
2788
2789TEST_F(VkLayerTest, InvalidDSUpdateIndex)
2790{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002791 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002792 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002793 std::string msgString;
2794 VkResult err;
2795
2796 ASSERT_NO_FATAL_FAILURE(InitState());
2797 m_errorMonitor->ClearState();
2798 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002799 VkDescriptorTypeCount ds_type_count = {};
2800 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2801 ds_type_count.count = 1;
2802
2803 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2804 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2805 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002806 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2807 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002808 ds_pool_ci.count = 1;
2809 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002810
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002811 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002812 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002813 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002814
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002815 VkDescriptorSetLayoutBinding dsl_binding = {};
2816 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2817 dsl_binding.arraySize = 1;
2818 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2819 dsl_binding.pImmutableSamplers = NULL;
2820
2821 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2822 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2823 ds_layout_ci.pNext = NULL;
2824 ds_layout_ci.count = 1;
2825 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002826 VkDescriptorSetLayout ds_layout;
2827 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2828 ASSERT_VK_SUCCESS(err);
2829
2830 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002831 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002832 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002833
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002834 VkSamplerCreateInfo sampler_ci = {};
2835 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2836 sampler_ci.pNext = NULL;
2837 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2838 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2839 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002840 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2841 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2842 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002843 sampler_ci.mipLodBias = 1.0;
2844 sampler_ci.maxAnisotropy = 1;
2845 sampler_ci.compareEnable = VK_FALSE;
2846 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2847 sampler_ci.minLod = 1.0;
2848 sampler_ci.maxLod = 1.0;
2849 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002850 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002851
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002852 VkSampler sampler;
2853 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2854 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002855
2856 VkDescriptorInfo descriptor_info;
2857 memset(&descriptor_info, 0, sizeof(descriptor_info));
2858 descriptor_info.sampler = sampler;
2859
2860 VkWriteDescriptorSet descriptor_write;
2861 memset(&descriptor_write, 0, sizeof(descriptor_write));
2862 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2863 descriptor_write.destSet = descriptorSet;
2864 descriptor_write.destBinding = 2;
2865 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002866 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002867 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2868 descriptor_write.pDescriptors = &descriptor_info;
2869
2870 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2871
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002872 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002873 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 -06002874 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
2875 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
2876 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002877
2878 vkDestroySampler(m_device->device(), sampler);
2879 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2880 ASSERT_VK_SUCCESS(err);
2881 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2882 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002883}
2884
2885TEST_F(VkLayerTest, InvalidDSUpdateStruct)
2886{
2887 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002888 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002889 std::string msgString;
2890 VkResult err;
2891
2892 ASSERT_NO_FATAL_FAILURE(InitState());
2893 m_errorMonitor->ClearState();
2894 //VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002895
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002896 VkDescriptorTypeCount ds_type_count = {};
2897 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2898 ds_type_count.count = 1;
2899
2900 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2901 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2902 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002903 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2904 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002905 ds_pool_ci.count = 1;
2906 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002907
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002908 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002909 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002910 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002911 VkDescriptorSetLayoutBinding dsl_binding = {};
2912 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2913 dsl_binding.arraySize = 1;
2914 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2915 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002916
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002917 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2918 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2919 ds_layout_ci.pNext = NULL;
2920 ds_layout_ci.count = 1;
2921 ds_layout_ci.pBinding = &dsl_binding;
2922
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002923 VkDescriptorSetLayout ds_layout;
2924 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2925 ASSERT_VK_SUCCESS(err);
2926
2927 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002928 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002929 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002930
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002931 VkSamplerCreateInfo sampler_ci = {};
2932 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2933 sampler_ci.pNext = NULL;
2934 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2935 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2936 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002937 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2938 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2939 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002940 sampler_ci.mipLodBias = 1.0;
2941 sampler_ci.maxAnisotropy = 1;
2942 sampler_ci.compareEnable = VK_FALSE;
2943 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2944 sampler_ci.minLod = 1.0;
2945 sampler_ci.maxLod = 1.0;
2946 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002947 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002948 VkSampler sampler;
2949 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2950 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002951
2952
2953 VkDescriptorInfo descriptor_info;
2954 memset(&descriptor_info, 0, sizeof(descriptor_info));
2955 descriptor_info.sampler = sampler;
2956
2957 VkWriteDescriptorSet descriptor_write;
2958 memset(&descriptor_write, 0, sizeof(descriptor_write));
2959 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
2960 descriptor_write.destSet = descriptorSet;
2961 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002962 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002963 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2964 descriptor_write.pDescriptors = &descriptor_info;
2965
2966 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2967
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002968 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002969 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 -06002970 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
2971 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
2972 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002973
2974 vkDestroySampler(m_device->device(), sampler);
2975 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
2976 ASSERT_VK_SUCCESS(err);
2977 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2978 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002979}
2980
2981TEST_F(VkLayerTest, NumSamplesMismatch)
2982{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002983 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002984 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002985 std::string msgString;
2986 VkResult err;
2987
2988 ASSERT_NO_FATAL_FAILURE(InitState());
2989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2990 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002991 VkDescriptorTypeCount ds_type_count = {};
2992 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2993 ds_type_count.count = 1;
2994
2995 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002996 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2997 ds_pool_ci.pNext = NULL;
2998 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2999 ds_pool_ci.maxSets = 1;
3000 ds_pool_ci.count = 1;
3001 ds_pool_ci.pTypeCount = &ds_type_count;
3002
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003003 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003004 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003005 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003006
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003007 VkDescriptorSetLayoutBinding dsl_binding = {};
3008 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3009 dsl_binding.arraySize = 1;
3010 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3011 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003012
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003013 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3014 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3015 ds_layout_ci.pNext = NULL;
3016 ds_layout_ci.count = 1;
3017 ds_layout_ci.pBinding = &dsl_binding;
3018
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003019 VkDescriptorSetLayout ds_layout;
3020 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3021 ASSERT_VK_SUCCESS(err);
3022
3023 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06003024 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003025 ASSERT_VK_SUCCESS(err);
3026
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003027 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3028 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3029 pipe_ms_state_ci.pNext = NULL;
3030 pipe_ms_state_ci.rasterSamples = 4;
3031 pipe_ms_state_ci.sampleShadingEnable = 0;
3032 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003033 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003034
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003035 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3036 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3037 pipeline_layout_ci.pNext = NULL;
3038 pipeline_layout_ci.descriptorSetCount = 1;
3039 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003040
3041 VkPipelineLayout pipeline_layout;
3042 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3043 ASSERT_VK_SUCCESS(err);
3044
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06003045 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003046 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
3047 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003048 VkPipelineObj pipe(m_device);
3049 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003050 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003051 pipe.SetMSAA(&pipe_ms_state_ci);
3052 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003053
Tony Barbour1490c912015-07-28 10:17:20 -06003054 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06003055 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003056
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003057 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003058 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 -06003059 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
3060 FAIL() << "Error received was not 'Num samples mismatch!...'";
3061 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003062
3063 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
3064 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
3065 ASSERT_VK_SUCCESS(err);
3066 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3067 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003068}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003069
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003070TEST_F(VkLayerTest, ClearCmdNoDraw)
3071{
3072 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
3073 VkFlags msgFlags;
3074 std::string msgString;
3075 VkResult err;
3076
3077 ASSERT_NO_FATAL_FAILURE(InitState());
3078 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3079 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003080
3081 VkDescriptorTypeCount ds_type_count = {};
3082 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3083 ds_type_count.count = 1;
3084
3085 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3086 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3087 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003088 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
3089 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003090 ds_pool_ci.count = 1;
3091 ds_pool_ci.pTypeCount = &ds_type_count;
3092
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003093 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003094 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003095 ASSERT_VK_SUCCESS(err);
3096
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003097 VkDescriptorSetLayoutBinding dsl_binding = {};
3098 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3099 dsl_binding.arraySize = 1;
3100 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3101 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003102
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003103 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3104 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3105 ds_layout_ci.pNext = NULL;
3106 ds_layout_ci.count = 1;
3107 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003108
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003109 VkDescriptorSetLayout ds_layout;
3110 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3111 ASSERT_VK_SUCCESS(err);
3112
3113 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06003114 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003115 ASSERT_VK_SUCCESS(err);
3116
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003117 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3118 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3119 pipe_ms_state_ci.pNext = NULL;
3120 pipe_ms_state_ci.rasterSamples = 4;
3121 pipe_ms_state_ci.sampleShadingEnable = 0;
3122 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003123 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003124
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003125 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3126 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3127 pipeline_layout_ci.pNext = NULL;
3128 pipeline_layout_ci.descriptorSetCount = 1;
3129 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003130
3131 VkPipelineLayout pipeline_layout;
3132 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3133 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003134
Tony Barbourd7d828b2015-08-06 10:16:07 -06003135 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003136 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
3137 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003138 VkPipelineObj pipe(m_device);
3139 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003140 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003141 pipe.SetMSAA(&pipe_ms_state_ci);
3142 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003143
3144 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003145
3146 m_errorMonitor->ClearState();
3147 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
3148 // Also pass down other dummy params to keep driver and paramchecker happy
3149 VkClearColorValue cCV;
Cody Northrop2563a032015-08-25 15:26:38 -06003150 cCV.float32[0] = 1.0;
3151 cCV.float32[1] = 1.0;
3152 cCV.float32[2] = 1.0;
3153 cCV.float32[3] = 1.0;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003154
Tony Barbour1490c912015-07-28 10:17:20 -06003155 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003156 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003157 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 -06003158 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) {
3159 FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'";
3160 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003161
3162 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
3163 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
3164 ASSERT_VK_SUCCESS(err);
3165 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3166 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003167}
3168
Tobin Ehlise4076782015-06-24 15:53:07 -06003169TEST_F(VkLayerTest, VtxBufferBadIndex)
3170{
3171 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
3172 VkFlags msgFlags;
3173 std::string msgString;
3174 VkResult err;
3175
3176 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003177 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlise4076782015-06-24 15:53:07 -06003178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3179 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003180
3181 VkDescriptorTypeCount ds_type_count = {};
3182 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3183 ds_type_count.count = 1;
3184
3185 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3186 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3187 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003188 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
3189 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003190 ds_pool_ci.count = 1;
3191 ds_pool_ci.pTypeCount = &ds_type_count;
3192
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003193 VkDescriptorPool ds_pool;
3194 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06003195 ASSERT_VK_SUCCESS(err);
3196
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003197 VkDescriptorSetLayoutBinding dsl_binding = {};
3198 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3199 dsl_binding.arraySize = 1;
3200 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3201 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003202
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003203 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3204 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3205 ds_layout_ci.pNext = NULL;
3206 ds_layout_ci.count = 1;
3207 ds_layout_ci.pBinding = &dsl_binding;
3208
Tobin Ehlise4076782015-06-24 15:53:07 -06003209 VkDescriptorSetLayout ds_layout;
3210 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3211 ASSERT_VK_SUCCESS(err);
3212
3213 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06003214 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06003215 ASSERT_VK_SUCCESS(err);
3216
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003217 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3218 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3219 pipe_ms_state_ci.pNext = NULL;
3220 pipe_ms_state_ci.rasterSamples = 1;
3221 pipe_ms_state_ci.sampleShadingEnable = 0;
3222 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003223 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003224
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003225 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3226 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3227 pipeline_layout_ci.pNext = NULL;
3228 pipeline_layout_ci.descriptorSetCount = 1;
3229 pipeline_layout_ci.pSetLayouts = &ds_layout;
3230 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06003231
Tobin Ehlise4076782015-06-24 15:53:07 -06003232 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3233 ASSERT_VK_SUCCESS(err);
3234
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06003235 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003236 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
3237 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003238 VkPipelineObj pipe(m_device);
3239 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003240 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003241 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003242 pipe.SetViewport(m_viewports);
3243 pipe.SetScissor(m_scissors);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003244 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003245
3246 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06003247 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06003248 // Don't care about actual data, just need to get to draw to flag error
3249 static const float vbo_data[3] = {1.f, 0.f, 1.f};
3250 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
3251 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003252 Draw(1, 0, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06003253
3254 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003255 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 -06003256 if (!strstr(msgString.c_str(),"Vtx Buffer Index 1 was bound, but no vtx buffers are attached to PSO.")) {
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003257 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.' but instead was '" << msgString.c_str() << "'";
Tobin Ehlise4076782015-06-24 15:53:07 -06003258 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003259
3260 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
3261 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
3262 ASSERT_VK_SUCCESS(err);
3263 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3264 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06003265}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003266#endif // DRAW_STATE_TESTS
3267
Tobin Ehlis57e6a612015-05-26 16:11:58 -06003268#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06003269#if GTEST_IS_THREADSAFE
3270struct thread_data_struct {
3271 VkCmdBuffer cmdBuffer;
3272 VkEvent event;
3273 bool bailout;
3274};
3275
3276extern "C" void *AddToCommandBuffer(void *arg)
3277{
3278 struct thread_data_struct *data = (struct thread_data_struct *) arg;
3279 std::string msgString;
3280
3281 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06003282 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06003283 if (data->bailout) {
3284 break;
3285 }
3286 }
3287 return NULL;
3288}
3289
3290TEST_F(VkLayerTest, ThreadCmdBufferCollision)
3291{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003292 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06003293 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003294 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06003295
3296 ASSERT_NO_FATAL_FAILURE(InitState());
3297 ASSERT_NO_FATAL_FAILURE(InitViewport());
3298 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3299
Mike Stroyan09aae812015-05-12 16:00:45 -06003300 m_errorMonitor->ClearState();
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003301
3302 // Calls CreateCommandBuffer
3303 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
3304
3305 // Avoid creating RenderPass
3306 cmdBuffer.BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06003307
3308 VkEventCreateInfo event_info;
3309 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06003310 VkResult err;
3311
3312 memset(&event_info, 0, sizeof(event_info));
3313 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3314
3315 err = vkCreateEvent(device(), &event_info, &event);
3316 ASSERT_VK_SUCCESS(err);
3317
Mike Stroyan09aae812015-05-12 16:00:45 -06003318 err = vkResetEvent(device(), event);
3319 ASSERT_VK_SUCCESS(err);
3320
3321 struct thread_data_struct data;
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003322 data.cmdBuffer = cmdBuffer.GetBufferHandle();
Mike Stroyan09aae812015-05-12 16:00:45 -06003323 data.event = event;
3324 data.bailout = false;
3325 m_errorMonitor->SetBailout(&data.bailout);
3326 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003327 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06003328 // Add many entries to command buffer from this thread at the same time.
3329 AddToCommandBuffer(&data);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003330
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003331 test_platform_thread_join(thread, NULL);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003332 cmdBuffer.EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06003333
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003334 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003335 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 -06003336 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05003337 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06003338 }
3339
Mike Stroyan2237f522015-08-18 14:40:24 -06003340 vkDestroyEvent(device(), event);
Mike Stroyan09aae812015-05-12 16:00:45 -06003341}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003342#endif // GTEST_IS_THREADSAFE
3343#endif // THREADING_TESTS
3344
Chris Forbes5af3bf22015-05-25 11:13:08 +12003345#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003346TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
3347{
3348 VkFlags msgFlags;
3349 std::string msgString;
3350 ASSERT_NO_FATAL_FAILURE(InitState());
3351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3352
3353 m_errorMonitor->ClearState();
3354
3355 VkShaderModule module;
3356 VkShaderModuleCreateInfo moduleCreateInfo;
3357 struct icd_spv_header spv;
3358
3359 spv.magic = ICD_SPV_MAGIC;
3360 spv.version = ICD_SPV_VERSION;
3361 spv.gen_magic = 0;
3362
3363 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3364 moduleCreateInfo.pNext = NULL;
3365 moduleCreateInfo.pCode = &spv;
3366 moduleCreateInfo.codeSize = 4;
3367 moduleCreateInfo.flags = 0;
3368 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3369
3370 msgFlags = m_errorMonitor->GetState(&msgString);
3371
Chris Forbes96b81762015-09-18 11:40:23 +12003372 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003373 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3374 FAIL() << "Incorrect warning: " << msgString;
3375 }
3376}
3377
3378TEST_F(VkLayerTest, InvalidSPIRVMagic)
3379{
3380 VkFlags msgFlags;
3381 std::string msgString;
3382 ASSERT_NO_FATAL_FAILURE(InitState());
3383 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3384
3385 m_errorMonitor->ClearState();
3386
3387 VkShaderModule module;
3388 VkShaderModuleCreateInfo moduleCreateInfo;
3389 struct icd_spv_header spv;
3390
3391 spv.magic = ~ICD_SPV_MAGIC;
3392 spv.version = ICD_SPV_VERSION;
3393 spv.gen_magic = 0;
3394
3395 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3396 moduleCreateInfo.pNext = NULL;
3397 moduleCreateInfo.pCode = &spv;
3398 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3399 moduleCreateInfo.flags = 0;
3400 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3401
3402 msgFlags = m_errorMonitor->GetState(&msgString);
3403
Chris Forbes96b81762015-09-18 11:40:23 +12003404 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003405 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3406 FAIL() << "Incorrect warning: " << msgString;
3407 }
3408}
3409
3410TEST_F(VkLayerTest, InvalidSPIRVVersion)
3411{
3412 VkFlags msgFlags;
3413 std::string msgString;
3414 ASSERT_NO_FATAL_FAILURE(InitState());
3415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3416
3417 m_errorMonitor->ClearState();
3418
3419 VkShaderModule module;
3420 VkShaderModuleCreateInfo moduleCreateInfo;
3421 struct icd_spv_header spv;
3422
3423 spv.magic = ICD_SPV_MAGIC;
3424 spv.version = ~ICD_SPV_VERSION;
3425 spv.gen_magic = 0;
3426
3427 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3428 moduleCreateInfo.pNext = NULL;
3429
3430 moduleCreateInfo.pCode = &spv;
3431 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3432 moduleCreateInfo.flags = 0;
3433 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3434
3435 msgFlags = m_errorMonitor->GetState(&msgString);
3436
Chris Forbes96b81762015-09-18 11:40:23 +12003437 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003438 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3439 FAIL() << "Incorrect warning: " << msgString;
3440 }
3441}
3442
Chris Forbes5af3bf22015-05-25 11:13:08 +12003443TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
3444{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003445 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12003446 std::string msgString;
3447 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12003449
3450 char const *vsSource =
3451 "#version 140\n"
3452 "#extension GL_ARB_separate_shader_objects: require\n"
3453 "#extension GL_ARB_shading_language_420pack: require\n"
3454 "\n"
3455 "layout(location=0) out float x;\n"
3456 "void main(){\n"
3457 " gl_Position = vec4(1);\n"
3458 " x = 0;\n"
3459 "}\n";
3460 char const *fsSource =
3461 "#version 140\n"
3462 "#extension GL_ARB_separate_shader_objects: require\n"
3463 "#extension GL_ARB_shading_language_420pack: require\n"
3464 "\n"
3465 "layout(location=0) out vec4 color;\n"
3466 "void main(){\n"
3467 " color = vec4(1);\n"
3468 "}\n";
3469
3470 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3471 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3472
3473 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003474 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12003475 pipe.AddShader(&vs);
3476 pipe.AddShader(&fs);
3477
Chris Forbes5af3bf22015-05-25 11:13:08 +12003478 VkDescriptorSetObj descriptorSet(m_device);
3479 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003480 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003481
3482 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003483 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12003484
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003485 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003486
Cody Northrop1684adb2015-08-05 11:15:02 -06003487 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003488 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
3489 FAIL() << "Incorrect warning: " << msgString;
3490 }
3491}
Chris Forbes5af3bf22015-05-25 11:13:08 +12003492
Chris Forbes3c10b852015-05-25 11:13:13 +12003493TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
3494{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003495 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12003496 std::string msgString;
3497 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003498 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12003499
3500 char const *vsSource =
3501 "#version 140\n"
3502 "#extension GL_ARB_separate_shader_objects: require\n"
3503 "#extension GL_ARB_shading_language_420pack: require\n"
3504 "\n"
3505 "void main(){\n"
3506 " gl_Position = vec4(1);\n"
3507 "}\n";
3508 char const *fsSource =
3509 "#version 140\n"
3510 "#extension GL_ARB_separate_shader_objects: require\n"
3511 "#extension GL_ARB_shading_language_420pack: require\n"
3512 "\n"
3513 "layout(location=0) in float x;\n"
3514 "layout(location=0) out vec4 color;\n"
3515 "void main(){\n"
3516 " color = vec4(x);\n"
3517 "}\n";
3518
3519 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3520 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3521
3522 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003523 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12003524 pipe.AddShader(&vs);
3525 pipe.AddShader(&fs);
3526
Chris Forbes3c10b852015-05-25 11:13:13 +12003527 VkDescriptorSetObj descriptorSet(m_device);
3528 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003529 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12003530
3531 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003532 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12003533
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003534 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12003535
Cody Northrop1684adb2015-08-05 11:15:02 -06003536 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes3c10b852015-05-25 11:13:13 +12003537 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
3538 FAIL() << "Incorrect error: " << msgString;
3539 }
3540}
3541
Chris Forbescc281692015-05-25 11:13:17 +12003542TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
3543{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003544 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12003545 std::string msgString;
3546 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003547 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12003548
3549 char const *vsSource =
3550 "#version 140\n"
3551 "#extension GL_ARB_separate_shader_objects: require\n"
3552 "#extension GL_ARB_shading_language_420pack: require\n"
3553 "\n"
3554 "layout(location=0) out int x;\n"
3555 "void main(){\n"
3556 " x = 0;\n"
3557 " gl_Position = vec4(1);\n"
3558 "}\n";
3559 char const *fsSource =
3560 "#version 140\n"
3561 "#extension GL_ARB_separate_shader_objects: require\n"
3562 "#extension GL_ARB_shading_language_420pack: require\n"
3563 "\n"
3564 "layout(location=0) in float x;\n" /* VS writes int */
3565 "layout(location=0) out vec4 color;\n"
3566 "void main(){\n"
3567 " color = vec4(x);\n"
3568 "}\n";
3569
3570 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3571 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3572
3573 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003574 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12003575 pipe.AddShader(&vs);
3576 pipe.AddShader(&fs);
3577
Chris Forbescc281692015-05-25 11:13:17 +12003578 VkDescriptorSetObj descriptorSet(m_device);
3579 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003580 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12003581
3582 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003583 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12003584
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003585 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12003586
Cody Northrop1684adb2015-08-05 11:15:02 -06003587 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbescc281692015-05-25 11:13:17 +12003588 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
3589 FAIL() << "Incorrect error: " << msgString;
3590 }
3591}
3592
Chris Forbes8291c052015-05-25 11:13:28 +12003593TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
3594{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003595 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12003596 std::string msgString;
3597 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003598 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12003599
3600 VkVertexInputBindingDescription input_binding;
3601 memset(&input_binding, 0, sizeof(input_binding));
3602
3603 VkVertexInputAttributeDescription input_attrib;
3604 memset(&input_attrib, 0, sizeof(input_attrib));
3605 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3606
3607 char const *vsSource =
3608 "#version 140\n"
3609 "#extension GL_ARB_separate_shader_objects: require\n"
3610 "#extension GL_ARB_shading_language_420pack: require\n"
3611 "\n"
3612 "void main(){\n"
3613 " gl_Position = vec4(1);\n"
3614 "}\n";
3615 char const *fsSource =
3616 "#version 140\n"
3617 "#extension GL_ARB_separate_shader_objects: require\n"
3618 "#extension GL_ARB_shading_language_420pack: require\n"
3619 "\n"
3620 "layout(location=0) out vec4 color;\n"
3621 "void main(){\n"
3622 " color = vec4(1);\n"
3623 "}\n";
3624
3625 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3626 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3627
3628 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003629 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12003630 pipe.AddShader(&vs);
3631 pipe.AddShader(&fs);
3632
3633 pipe.AddVertexInputBindings(&input_binding, 1);
3634 pipe.AddVertexInputAttribs(&input_attrib, 1);
3635
Chris Forbes8291c052015-05-25 11:13:28 +12003636 VkDescriptorSetObj descriptorSet(m_device);
3637 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003638 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12003639
3640 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003641 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12003642
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003643 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12003644
Cody Northrop1684adb2015-08-05 11:15:02 -06003645 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12003646 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
3647 FAIL() << "Incorrect warning: " << msgString;
3648 }
3649}
3650
Chris Forbes37367e62015-05-25 11:13:29 +12003651TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
3652{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003653 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12003654 std::string msgString;
3655 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003656 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12003657
3658 char const *vsSource =
3659 "#version 140\n"
3660 "#extension GL_ARB_separate_shader_objects: require\n"
3661 "#extension GL_ARB_shading_language_420pack: require\n"
3662 "\n"
3663 "layout(location=0) in vec4 x;\n" /* not provided */
3664 "void main(){\n"
3665 " gl_Position = x;\n"
3666 "}\n";
3667 char const *fsSource =
3668 "#version 140\n"
3669 "#extension GL_ARB_separate_shader_objects: require\n"
3670 "#extension GL_ARB_shading_language_420pack: require\n"
3671 "\n"
3672 "layout(location=0) out vec4 color;\n"
3673 "void main(){\n"
3674 " color = vec4(1);\n"
3675 "}\n";
3676
3677 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3678 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3679
3680 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003681 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12003682 pipe.AddShader(&vs);
3683 pipe.AddShader(&fs);
3684
Chris Forbes37367e62015-05-25 11:13:29 +12003685 VkDescriptorSetObj descriptorSet(m_device);
3686 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003687 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12003688
3689 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003690 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12003691
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003692 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12003693
Cody Northrop1684adb2015-08-05 11:15:02 -06003694 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes37367e62015-05-25 11:13:29 +12003695 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
3696 FAIL() << "Incorrect warning: " << msgString;
3697 }
3698}
3699
Chris Forbesa4b02322015-05-25 11:13:31 +12003700TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
3701{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003702 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12003703 std::string msgString;
3704 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12003706
3707 VkVertexInputBindingDescription input_binding;
3708 memset(&input_binding, 0, sizeof(input_binding));
3709
3710 VkVertexInputAttributeDescription input_attrib;
3711 memset(&input_attrib, 0, sizeof(input_attrib));
3712 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3713
3714 char const *vsSource =
3715 "#version 140\n"
3716 "#extension GL_ARB_separate_shader_objects: require\n"
3717 "#extension GL_ARB_shading_language_420pack: require\n"
3718 "\n"
3719 "layout(location=0) in int x;\n" /* attrib provided float */
3720 "void main(){\n"
3721 " gl_Position = vec4(x);\n"
3722 "}\n";
3723 char const *fsSource =
3724 "#version 140\n"
3725 "#extension GL_ARB_separate_shader_objects: require\n"
3726 "#extension GL_ARB_shading_language_420pack: require\n"
3727 "\n"
3728 "layout(location=0) out vec4 color;\n"
3729 "void main(){\n"
3730 " color = vec4(1);\n"
3731 "}\n";
3732
3733 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3734 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3735
3736 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003737 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12003738 pipe.AddShader(&vs);
3739 pipe.AddShader(&fs);
3740
3741 pipe.AddVertexInputBindings(&input_binding, 1);
3742 pipe.AddVertexInputAttribs(&input_attrib, 1);
3743
Chris Forbesa4b02322015-05-25 11:13:31 +12003744 VkDescriptorSetObj descriptorSet(m_device);
3745 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003746 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12003747
3748 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003749 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12003750
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003751 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12003752
Cody Northrop1684adb2015-08-05 11:15:02 -06003753 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa4b02322015-05-25 11:13:31 +12003754 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
3755 FAIL() << "Incorrect error: " << msgString;
3756 }
3757}
3758
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003759TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
3760{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003761 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003762 std::string msgString;
3763 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003764 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003765
3766 /* Two binding descriptions for binding 0 */
3767 VkVertexInputBindingDescription input_bindings[2];
3768 memset(input_bindings, 0, sizeof(input_bindings));
3769
3770 VkVertexInputAttributeDescription input_attrib;
3771 memset(&input_attrib, 0, sizeof(input_attrib));
3772 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3773
3774 char const *vsSource =
3775 "#version 140\n"
3776 "#extension GL_ARB_separate_shader_objects: require\n"
3777 "#extension GL_ARB_shading_language_420pack: require\n"
3778 "\n"
3779 "layout(location=0) in float x;\n" /* attrib provided float */
3780 "void main(){\n"
3781 " gl_Position = vec4(x);\n"
3782 "}\n";
3783 char const *fsSource =
3784 "#version 140\n"
3785 "#extension GL_ARB_separate_shader_objects: require\n"
3786 "#extension GL_ARB_shading_language_420pack: require\n"
3787 "\n"
3788 "layout(location=0) out vec4 color;\n"
3789 "void main(){\n"
3790 " color = vec4(1);\n"
3791 "}\n";
3792
3793 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3794 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3795
3796 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003797 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003798 pipe.AddShader(&vs);
3799 pipe.AddShader(&fs);
3800
3801 pipe.AddVertexInputBindings(input_bindings, 2);
3802 pipe.AddVertexInputAttribs(&input_attrib, 1);
3803
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003804 VkDescriptorSetObj descriptorSet(m_device);
3805 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003806 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003807
3808 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003809 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003810
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003811 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003812
Cody Northrop1684adb2015-08-05 11:15:02 -06003813 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003814 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
3815 FAIL() << "Incorrect error: " << msgString;
3816 }
3817}
Chris Forbes4c948702015-05-25 11:13:32 +12003818
Chris Forbesc12ef122015-05-25 11:13:40 +12003819/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
3820 * rejects it. */
3821
3822TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
3823{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003824 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12003825 std::string msgString;
3826 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12003827
3828 char const *vsSource =
3829 "#version 140\n"
3830 "#extension GL_ARB_separate_shader_objects: require\n"
3831 "#extension GL_ARB_shading_language_420pack: require\n"
3832 "\n"
3833 "void main(){\n"
3834 " gl_Position = vec4(1);\n"
3835 "}\n";
3836 char const *fsSource =
3837 "#version 140\n"
3838 "#extension GL_ARB_separate_shader_objects: require\n"
3839 "#extension GL_ARB_shading_language_420pack: require\n"
3840 "\n"
3841 "void main(){\n"
3842 "}\n";
3843
3844 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3845 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3846
3847 VkPipelineObj pipe(m_device);
3848 pipe.AddShader(&vs);
3849 pipe.AddShader(&fs);
3850
Chia-I Wuc278df82015-07-07 11:50:03 +08003851 /* set up CB 0, not written */
3852 pipe.AddColorAttachment();
3853 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12003854
Chris Forbesc12ef122015-05-25 11:13:40 +12003855 VkDescriptorSetObj descriptorSet(m_device);
3856 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003857 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12003858
3859 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003860 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12003861
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003862 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12003863
Cody Northrop1684adb2015-08-05 11:15:02 -06003864 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc12ef122015-05-25 11:13:40 +12003865 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
3866 FAIL() << "Incorrect error: " << msgString;
3867 }
3868}
3869
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003870TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
3871{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003872 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003873 std::string msgString;
3874 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003875
3876 char const *vsSource =
3877 "#version 140\n"
3878 "#extension GL_ARB_separate_shader_objects: require\n"
3879 "#extension GL_ARB_shading_language_420pack: require\n"
3880 "\n"
3881 "void main(){\n"
3882 " gl_Position = vec4(1);\n"
3883 "}\n";
3884 char const *fsSource =
3885 "#version 140\n"
3886 "#extension GL_ARB_separate_shader_objects: require\n"
3887 "#extension GL_ARB_shading_language_420pack: require\n"
3888 "\n"
3889 "layout(location=0) out vec4 x;\n"
3890 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
3891 "void main(){\n"
3892 " x = vec4(1);\n"
3893 " y = vec4(1);\n"
3894 "}\n";
3895
3896 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3897 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3898
3899 VkPipelineObj pipe(m_device);
3900 pipe.AddShader(&vs);
3901 pipe.AddShader(&fs);
3902
Chia-I Wuc278df82015-07-07 11:50:03 +08003903 /* set up CB 0, not written */
3904 pipe.AddColorAttachment();
3905 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003906 /* FS writes CB 1, but we don't configure it */
3907
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003908 VkDescriptorSetObj descriptorSet(m_device);
3909 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003910 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003911
3912 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003913 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003914
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003915 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003916
Cody Northrop1684adb2015-08-05 11:15:02 -06003917 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003918 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
3919 FAIL() << "Incorrect warning: " << msgString;
3920 }
3921}
3922
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003923TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
3924{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003925 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003926 std::string msgString;
3927 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003928
3929 char const *vsSource =
3930 "#version 140\n"
3931 "#extension GL_ARB_separate_shader_objects: require\n"
3932 "#extension GL_ARB_shading_language_420pack: require\n"
3933 "\n"
3934 "void main(){\n"
3935 " gl_Position = vec4(1);\n"
3936 "}\n";
3937 char const *fsSource =
3938 "#version 140\n"
3939 "#extension GL_ARB_separate_shader_objects: require\n"
3940 "#extension GL_ARB_shading_language_420pack: require\n"
3941 "\n"
3942 "layout(location=0) out ivec4 x;\n" /* not UNORM */
3943 "void main(){\n"
3944 " x = ivec4(1);\n"
3945 "}\n";
3946
3947 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3948 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3949
3950 VkPipelineObj pipe(m_device);
3951 pipe.AddShader(&vs);
3952 pipe.AddShader(&fs);
3953
Chia-I Wuc278df82015-07-07 11:50:03 +08003954 /* set up CB 0; type is UNORM by default */
3955 pipe.AddColorAttachment();
3956 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003957
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003958 VkDescriptorSetObj descriptorSet(m_device);
3959 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003960 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003961
3962 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003963 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003964
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003965 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003966
Cody Northrop1684adb2015-08-05 11:15:02 -06003967 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes7d64a4f2015-05-25 11:13:44 +12003968 if (!strstr(msgString.c_str(),"does not match FS output type")) {
3969 FAIL() << "Incorrect error: " << msgString;
3970 }
3971}
Chris Forbesc2050732015-06-05 14:43:36 +12003972
Chris Forbes76ce7882015-08-14 12:04:59 +12003973TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
3974{
3975 VkFlags msgFlags;
3976 std::string msgString;
3977 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +12003978
3979 char const *vsSource =
3980 "#version 140\n"
3981 "#extension GL_ARB_separate_shader_objects: require\n"
3982 "#extension GL_ARB_shading_language_420pack: require\n"
3983 "\n"
3984 "void main(){\n"
3985 " gl_Position = vec4(1);\n"
3986 "}\n";
3987 char const *fsSource =
3988 "#version 140\n"
3989 "#extension GL_ARB_separate_shader_objects: require\n"
3990 "#extension GL_ARB_shading_language_420pack: require\n"
3991 "\n"
3992 "layout(location=0) out vec4 x;\n"
3993 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
3994 "void main(){\n"
3995 " x = vec4(bar.y);\n"
3996 "}\n";
3997
3998 m_errorMonitor->ClearState();
3999
4000 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
4001 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
4002
4003
4004 VkPipelineObj pipe(m_device);
4005 pipe.AddShader(&vs);
4006 pipe.AddShader(&fs);
4007
4008 /* set up CB 0; type is UNORM by default */
4009 pipe.AddColorAttachment();
4010 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4011
4012 VkDescriptorSetObj descriptorSet(m_device);
4013 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
4014
4015 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4016
4017 /* should have generated an error -- pipeline layout does not
4018 * provide a uniform buffer in 0.0
4019 */
4020 msgFlags = m_errorMonitor->GetState(&msgString);
4021 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
4022 if (!strstr(msgString.c_str(),"not declared in pipeline layout")) {
4023 FAIL() << "Incorrect error: " << msgString;
4024 }
4025}
4026
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004027#endif // SHADER_CHECKER_TESTS
4028
4029#if DEVICE_LIMITS_TESTS
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004030TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
4031{
4032 VkFlags msgFlags;
4033 std::string msgString;
4034
4035 ASSERT_NO_FATAL_FAILURE(InitState());
4036 m_errorMonitor->ClearState();
4037
4038 // Create an image
4039 VkImage image;
4040
4041 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4042 const int32_t tex_width = 32;
4043 const int32_t tex_height = 32;
4044
4045 VkImageCreateInfo image_create_info = {};
4046 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4047 image_create_info.pNext = NULL;
4048 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4049 image_create_info.format = tex_format;
4050 image_create_info.extent.width = tex_width;
4051 image_create_info.extent.height = tex_height;
4052 image_create_info.extent.depth = 1;
4053 image_create_info.mipLevels = 1;
4054 image_create_info.arraySize = 1;
4055 image_create_info.samples = 1;
4056 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4057 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4058 image_create_info.flags = 0;
4059
4060 // Introduce error by sending down a bogus width extent
4061 image_create_info.extent.width = 65536;
4062 vkCreateImage(m_device->device(), &image_create_info, &image);
4063
4064 msgFlags = m_errorMonitor->GetState(&msgString);
4065 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4066 "with extents outside the queried limits";
4067 if (!strstr(msgString.c_str(),"CreateImage extents exceed allowable limits for format")) {
4068 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4069 }
4070}
4071
4072TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
4073{
4074 VkFlags msgFlags;
4075 std::string msgString;
4076
4077 ASSERT_NO_FATAL_FAILURE(InitState());
4078 m_errorMonitor->ClearState();
4079
4080 // Create an image
4081 VkImage image;
4082
4083 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4084 const int32_t tex_width = 32;
4085 const int32_t tex_height = 32;
4086
4087 VkImageCreateInfo image_create_info = {};
4088 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4089 image_create_info.pNext = NULL;
4090 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4091 image_create_info.format = tex_format;
4092 image_create_info.extent.width = tex_width;
4093 image_create_info.extent.height = tex_height;
4094 image_create_info.extent.depth = 1;
4095 image_create_info.mipLevels = 1;
4096 image_create_info.arraySize = 1;
4097 image_create_info.samples = 1;
4098 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4099 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4100 image_create_info.flags = 0;
4101
4102 // Introduce error by sending down individually allowable values that result in a surface size
4103 // exceeding the device maximum
4104 image_create_info.extent.width = 8192;
4105 image_create_info.extent.height = 8192;
4106 image_create_info.extent.depth = 16;
4107 image_create_info.arraySize = 4;
4108 image_create_info.samples = 2;
4109 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
4110 vkCreateImage(m_device->device(), &image_create_info, &image);
4111
4112 msgFlags = m_errorMonitor->GetState(&msgString);
4113 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4114 "with resource size exceeding queried limit";
4115 if (!strstr(msgString.c_str(),"CreateImage resource size exceeds allowable maximum")) {
4116 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4117 }
4118}
4119
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004120#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004121
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004122#if IMAGE_TESTS
4123TEST_F(VkLayerTest, InvalidImageView)
4124{
4125 VkFlags msgFlags;
4126 std::string msgString;
4127 VkResult err;
4128
4129 ASSERT_NO_FATAL_FAILURE(InitState());
4130 m_errorMonitor->ClearState();
4131
4132 // Create an image, allocate memory, free it, and then try to bind it
4133 VkImage image;
4134
4135 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4136 const int32_t tex_width = 32;
4137 const int32_t tex_height = 32;
4138
4139 VkImageCreateInfo image_create_info = {};
4140 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4141 image_create_info.pNext = NULL;
4142 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4143 image_create_info.format = tex_format;
4144 image_create_info.extent.width = tex_width;
4145 image_create_info.extent.height = tex_height;
4146 image_create_info.extent.depth = 1;
4147 image_create_info.mipLevels = 1;
4148 image_create_info.arraySize = 1;
4149 image_create_info.samples = 1;
4150 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4151 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4152 image_create_info.flags = 0;
4153
4154 err = vkCreateImage(m_device->device(), &image_create_info, &image);
4155 ASSERT_VK_SUCCESS(err);
4156
4157 VkImageViewCreateInfo image_view_create_info = {};
4158 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4159 image_view_create_info.image = image;
4160 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4161 image_view_create_info.format = tex_format;
4162 image_view_create_info.subresourceRange.arraySize = 1;
4163 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
4164 image_view_create_info.subresourceRange.mipLevels = 1;
4165
4166 VkImageView view;
4167 err = vkCreateImageView(m_device->device(), &image_view_create_info, &view);
4168
4169 msgFlags = m_errorMonitor->GetState(&msgString);
4170 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an invalid ImageView";
4171 if (!strstr(msgString.c_str(),"vkCreateImageView called with baseMipLevel 10 ")) {
4172 FAIL() << "Error received was not 'vkCreateImageView called with baseMipLevel 10...' but instaed '" << msgString.c_str() << "'";
4173 }
4174}
4175#endif // IMAGE_TESTS
4176
Tony Barbour30486ea2015-04-07 13:44:53 -06004177int main(int argc, char **argv) {
4178 int result;
4179
4180 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004181 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06004182
4183 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
4184
4185 result = RUN_ALL_TESTS();
4186
Tony Barbour01999182015-04-09 12:58:51 -06004187 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06004188 return result;
4189}