blob: ffb1cd13ca726c568707996e9cf5ac6d647795c6 [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"
Tony Barbour30486ea2015-04-07 13:44:53 -06006
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05007#define GLM_FORCE_RADIANS
8#include "glm/glm.hpp"
9#include <glm/gtc/matrix_transform.hpp>
10
Tobin Ehlis57e6a612015-05-26 16:11:58 -060011#define MEM_TRACKER_TESTS 1
12#define OBJ_TRACKER_TESTS 1
13#define DRAW_STATE_TESTS 1
14#define THREADING_TESTS 1
Chris Forbes5af3bf22015-05-25 11:13:08 +120015#define SHADER_CHECKER_TESTS 1
Tobin Ehlis57e6a612015-05-26 16:11:58 -060016
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050017//--------------------------------------------------------------------------------------
18// Mesh and VertexFormat Data
19//--------------------------------------------------------------------------------------
20struct Vertex
21{
22 float posX, posY, posZ, posW; // Position data
23 float r, g, b, a; // Color
24};
25
26#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
27
28typedef enum _BsoFailSelect {
29 BsoFailNone = 0x00000000,
Cody Northrope4bc6942015-08-26 10:01:32 -060030 BsoFailLineWidth = 0x00000001,
31 BsoFailDepthBias = 0x00000002,
Cody Northropf5bd2252015-08-17 11:10:49 -060032 BsoFailViewport = 0x00000004,
Cody Northrope4bc6942015-08-26 10:01:32 -060033 BsoFailBlend = 0x00000008,
34 BsoFailDepthBounds = 0x00000010,
Cody Northrop2605cb02015-08-18 15:21:16 -060035 BsoFailStencil = 0x00000020,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050036} BsoFailSelect;
37
38struct vktriangle_vs_uniform {
39 // Must start with MVP
40 float mvp[4][4];
41 float position[3][4];
42 float color[3][4];
43};
44
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050045static const char bindStateVertShaderText[] =
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050046 "#version 130\n"
47 "vec2 vertices[3];\n"
48 "void main() {\n"
49 " vertices[0] = vec2(-1.0, -1.0);\n"
50 " vertices[1] = vec2( 1.0, -1.0);\n"
51 " vertices[2] = vec2( 0.0, 1.0);\n"
52 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
53 "}\n";
54
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050055static const char bindStateFragShaderText[] =
Cody Northrop74a2d2c2015-06-16 17:32:04 -060056 "#version 140\n"
57 "#extension GL_ARB_separate_shader_objects: require\n"
58 "#extension GL_ARB_shading_language_420pack: require\n"
59 "\n"
60 "layout(location = 0) out vec4 uFragColor;\n"
61 "void main(){\n"
62 " uFragColor = vec4(0,1,0,1);\n"
63 "}\n";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050064
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060065static void myDbgFunc(
Tony Barboure84a8d62015-07-10 14:10:27 -060066 VkFlags msgFlags,
67 VkDbgObjectType objType,
68 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060069 size_t location,
70 int32_t msgCode,
71 const char* pLayerPrefix,
72 const char* pMsg,
73 void* pUserData);
Tony Barbour30486ea2015-04-07 13:44:53 -060074
75class ErrorMonitor {
76public:
Tony Barbour0c1bdc62015-04-29 17:34:29 -060077 ErrorMonitor()
Tony Barbour30486ea2015-04-07 13:44:53 -060078 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060079 test_platform_thread_create_mutex(&m_mutex);
80 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060081 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mike Stroyan09aae812015-05-12 16:00:45 -060082 m_bailout = NULL;
Mike Stroyan7016f4f2015-07-13 14:45:35 -060083 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060084 }
85 void ClearState()
86 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060087 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060088 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -060089 m_msgString.clear();
Mike Stroyan7016f4f2015-07-13 14:45:35 -060090 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060091 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060092 VkFlags GetState(std::string *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -060093 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060094 test_platform_thread_lock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060095 *msgString = m_msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -060096 test_platform_thread_unlock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060097 return m_msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -060098 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060099 void SetState(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -0600100 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600101 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600102 if (m_bailout != NULL) {
103 *m_bailout = true;
104 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600105 m_msgFlags = msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600106 m_msgString.reserve(strlen(msgString));
107 m_msgString = msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600108 test_platform_thread_unlock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600109 }
110 void SetBailout(bool *bailout)
111 {
112 m_bailout = bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600113 }
114
115private:
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600116 VkFlags m_msgFlags;
117 std::string m_msgString;
118 test_platform_thread_mutex m_mutex;
119 bool* m_bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600120};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500121
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600122static void myDbgFunc(
123 VkFlags msgFlags,
Tony Barboure84a8d62015-07-10 14:10:27 -0600124 VkDbgObjectType objType,
125 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600126 size_t location,
127 int32_t msgCode,
128 const char* pLayerPrefix,
129 const char* pMsg,
130 void* pUserData)
Tony Barbour30486ea2015-04-07 13:44:53 -0600131{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600132 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour8508b8e2015-04-09 10:48:04 -0600133 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600134 errMonitor->SetState(msgFlags, pMsg);
Tony Barbour8508b8e2015-04-09 10:48:04 -0600135 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600136}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500137
Tony Barbour01999182015-04-09 12:58:51 -0600138class VkLayerTest : public VkRenderFramework
Tony Barbour30486ea2015-04-07 13:44:53 -0600139{
140public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600141 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
142 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500143 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
144 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbour1490c912015-07-28 10:17:20 -0600145 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
146 { GenericDrawPreparation(m_cmdBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600147
Tony Barbour1490c912015-07-28 10:17:20 -0600148 /* Convenience functions that use built-in command buffer */
149 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_cmdBuffer); }
150 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_cmdBuffer); }
151 void Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
152 { m_cmdBuffer->Draw(firstVertex, vertexCount, firstInstance, instanceCount); }
153 void DrawIndexed(uint32_t firstVertex, uint32_t vertexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
154 { m_cmdBuffer->DrawIndexed(firstVertex, vertexCount, vertexOffset,firstInstance, instanceCount); }
155 void QueueCommandBuffer() { m_cmdBuffer->QueueCommandBuffer(); }
156 void QueueCommandBuffer(const VkFence& fence) { m_cmdBuffer->QueueCommandBuffer(fence); }
157 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
158 { m_cmdBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
159 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
160 { m_cmdBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600161protected:
Tony Barbour01999182015-04-09 12:58:51 -0600162 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600163
164 virtual void SetUp() {
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600165 std::vector<const char *> instance_layer_names;
166 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600167 std::vector<const char *> instance_extension_names;
168 std::vector<const char *> device_extension_names;
Tony Barbour950ebc02015-04-23 12:55:36 -0600169
Courtney Goeltzenleuchter846298c2015-07-30 11:32:46 -0600170 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600171 /*
172 * Since CreateDbgMsgCallback is an instance level extension call
173 * any extension / layer that utilizes that feature also needs
174 * to be enabled at create instance time.
175 */
Mike Stroyaned254572015-06-17 16:32:06 -0600176 // Use Threading layer first to protect others from ThreadCmdBufferCollision test
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600177 instance_layer_names.push_back("Threading");
178 instance_layer_names.push_back("ObjectTracker");
179 instance_layer_names.push_back("MemTracker");
180 instance_layer_names.push_back("DrawState");
181 instance_layer_names.push_back("ShaderChecker");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600182
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600183 device_layer_names.push_back("Threading");
184 device_layer_names.push_back("ObjectTracker");
185 device_layer_names.push_back("MemTracker");
186 device_layer_names.push_back("DrawState");
187 device_layer_names.push_back("ShaderChecker");
Tony Barbour30486ea2015-04-07 13:44:53 -0600188
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600189 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -0600190 this->app_info.pNext = NULL;
191 this->app_info.pAppName = "layer_tests";
192 this->app_info.appVersion = 1;
193 this->app_info.pEngineName = "unittest";
194 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600195 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -0600196
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600197 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600198 InitFramework(instance_layer_names, device_layer_names,
199 instance_extension_names, device_extension_names,
200 myDbgFunc, m_errorMonitor);
Tony Barbour30486ea2015-04-07 13:44:53 -0600201 }
202
203 virtual void TearDown() {
204 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600205 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600206 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600207 }
208};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500209
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600210VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600211{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600212 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600213
214 result = cmdBuffer.BeginCommandBuffer();
215
216 /*
217 * For render test all drawing happens in a single render pass
218 * on a single command buffer.
219 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200220 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wuc278df82015-07-07 11:50:03 +0800221 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour30486ea2015-04-07 13:44:53 -0600222 }
223
224 return result;
225}
226
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600227VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600228{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600229 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600230
Chris Forbesfe133ef2015-06-16 14:05:59 +1200231 if (renderPass()) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800232 cmdBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200233 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600234
235 result = cmdBuffer.EndCommandBuffer();
236
237 return result;
238}
239
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500240void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
241{
242 // Create identity matrix
243 int i;
244 struct vktriangle_vs_uniform data;
245
246 glm::mat4 Projection = glm::mat4(1.0f);
247 glm::mat4 View = glm::mat4(1.0f);
248 glm::mat4 Model = glm::mat4(1.0f);
249 glm::mat4 MVP = Projection * View * Model;
250 const int matrixSize = sizeof(MVP);
251 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
252
253 memcpy(&data.mvp, &MVP[0][0], matrixSize);
254
255 static const Vertex tri_data[] =
256 {
257 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
258 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
259 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
260 };
261
262 for (i=0; i<3; i++) {
263 data.position[i][0] = tri_data[i].posX;
264 data.position[i][1] = tri_data[i].posY;
265 data.position[i][2] = tri_data[i].posZ;
266 data.position[i][3] = tri_data[i].posW;
267 data.color[i][0] = tri_data[i].r;
268 data.color[i][1] = tri_data[i].g;
269 data.color[i][2] = tri_data[i].b;
270 data.color[i][3] = tri_data[i].a;
271 }
272
273 ASSERT_NO_FATAL_FAILURE(InitState());
274 ASSERT_NO_FATAL_FAILURE(InitViewport());
275
276 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
277
278 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
279 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
280
281 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800282 pipelineobj.AddColorAttachment();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500283 pipelineobj.AddShader(&vs);
284 pipelineobj.AddShader(&ps);
285
286 VkDescriptorSetObj descriptorSet(m_device);
287 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
288
289 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600290 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500291
Tony Barbour1490c912015-07-28 10:17:20 -0600292 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500293
294 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -0600295 Draw(0, 3, 0, 1);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500296
297 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600298 EndCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500299
Tony Barbour1490c912015-07-28 10:17:20 -0600300 QueueCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500301}
302
303void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
304{
305 if (m_depthStencil->Initialized()) {
306 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
307 } else {
308 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
309 }
310
311 cmdBuffer->PrepareAttachments();
Cody Northrope4bc6942015-08-26 10:01:32 -0600312 if ((failMask & BsoFailLineWidth) != BsoFailLineWidth) {
313 cmdBuffer->BindDynamicLineWidthState(m_stateLineWidth);
Cody Northropf5bd2252015-08-17 11:10:49 -0600314 }
Cody Northrope4bc6942015-08-26 10:01:32 -0600315 if ((failMask & BsoFailDepthBias) != BsoFailDepthBias) {
316 cmdBuffer->BindDynamicDepthBiasState(m_stateDepthBias);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500317 }
318 if ((failMask & BsoFailViewport) != BsoFailViewport) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600319 cmdBuffer->BindDynamicViewportState(m_stateViewport);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500320 }
Cody Northrope4bc6942015-08-26 10:01:32 -0600321 if ((failMask & BsoFailBlend) != BsoFailBlend) {
322 cmdBuffer->BindDynamicBlendState(m_stateBlend);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500323 }
Cody Northrope4bc6942015-08-26 10:01:32 -0600324 if ((failMask & BsoFailDepthBounds) != BsoFailDepthBounds) {
325 cmdBuffer->BindDynamicDepthBoundsState(m_stateDepthBounds);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500326 }
Cody Northrop2605cb02015-08-18 15:21:16 -0600327 if ((failMask & BsoFailStencil) != BsoFailStencil) {
328 cmdBuffer->BindDynamicStencilState(m_stateStencil);
329 }
330 // Make sure depthWriteEnable is set so that Depth fail test will work correctly
331 // Make sure stencilTestEnable is set so that Stencil fail test will work correctly
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600332 VkStencilOpState stencil = {};
333 stencil.stencilFailOp = VK_STENCIL_OP_KEEP;
334 stencil.stencilPassOp = VK_STENCIL_OP_KEEP;
335 stencil.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
336 stencil.stencilCompareOp = VK_COMPARE_OP_NEVER;
337
338 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
339 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
340 ds_ci.pNext = NULL;
341 ds_ci.depthTestEnable = VK_FALSE;
342 ds_ci.depthWriteEnable = VK_TRUE;
343 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
Cody Northrope4bc6942015-08-26 10:01:32 -0600344 ds_ci.depthBoundsTestEnable = VK_FALSE;
Cody Northrop2605cb02015-08-18 15:21:16 -0600345 ds_ci.stencilTestEnable = VK_TRUE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600346 ds_ci.front = stencil;
347 ds_ci.back = stencil;
348
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600349 pipelineobj.SetDepthStencil(&ds_ci);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500350 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Tony Barboured132432015-08-04 16:23:11 -0600351 pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500352 cmdBuffer->BindPipeline(pipelineobj);
353 cmdBuffer->BindDescriptorSet(descriptorSet);
354}
355
356// ********************************************************************************************************************
357// ********************************************************************************************************************
358// ********************************************************************************************************************
359// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600360#if MEM_TRACKER_TESTS
Mark Lobodzinski81078192015-05-19 10:28:29 -0500361TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
362{
363 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600364 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500365 std::string msgString;
366
367 VkFenceCreateInfo fenceInfo = {};
368 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
369 fenceInfo.pNext = NULL;
370 fenceInfo.flags = 0;
371
372 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barboure389b882015-07-20 13:00:10 -0600373
374 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
375 vk_testing::Buffer buffer;
376 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500377
Tony Barbour1490c912015-07-28 10:17:20 -0600378 BeginCommandBuffer();
379 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
380 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500381
382 testFence.init(*m_device, fenceInfo);
383
384 // Bypass framework since it does the waits automatically
385 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600386 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500387 ASSERT_VK_SUCCESS( err );
388
389 m_errorMonitor->ClearState();
390 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600391 vkResetCommandBuffer(m_cmdBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500392
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600393 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600394 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 -0500395 if (!strstr(msgString.c_str(),"Resetting CB")) {
396 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
397 }
398}
399
400TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion)
401{
402 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600403 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500404 std::string msgString;
405
406 VkFenceCreateInfo fenceInfo = {};
407 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
408 fenceInfo.pNext = NULL;
409 fenceInfo.flags = 0;
410
411 ASSERT_NO_FATAL_FAILURE(InitState());
412 ASSERT_NO_FATAL_FAILURE(InitViewport());
413 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
414
Tony Barbour1490c912015-07-28 10:17:20 -0600415 BeginCommandBuffer();
416 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
417 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500418
419 testFence.init(*m_device, fenceInfo);
420
421 // Bypass framework since it does the waits automatically
422 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600423 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500424 ASSERT_VK_SUCCESS( err );
425
426 m_errorMonitor->ClearState();
427 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600428 BeginCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500429
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600430 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600431 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 -0500432 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
433 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
434 }
435}
436
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500437TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
438{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600439 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500440 std::string msgString;
441 VkResult err;
442
443 ASSERT_NO_FATAL_FAILURE(InitState());
444 m_errorMonitor->ClearState();
445
446 // Create an image, allocate memory, free it, and then try to bind it
447 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500448 VkDeviceMemory mem;
449 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500450
451 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
452 const int32_t tex_width = 32;
453 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500454
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600455 VkImageCreateInfo image_create_info = {};
456 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
457 image_create_info.pNext = NULL;
458 image_create_info.imageType = VK_IMAGE_TYPE_2D;
459 image_create_info.format = tex_format;
460 image_create_info.extent.width = tex_width;
461 image_create_info.extent.height = tex_height;
462 image_create_info.extent.depth = 1;
463 image_create_info.mipLevels = 1;
464 image_create_info.arraySize = 1;
465 image_create_info.samples = 1;
466 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
467 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
468 image_create_info.flags = 0;
469
470 VkMemoryAllocInfo mem_alloc = {};
471 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
472 mem_alloc.pNext = NULL;
473 mem_alloc.allocationSize = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500474 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600475 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500476
477 err = vkCreateImage(m_device->device(), &image_create_info, &image);
478 ASSERT_VK_SUCCESS(err);
479
Tony Barboure84a8d62015-07-10 14:10:27 -0600480 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500481 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500482 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500483 ASSERT_VK_SUCCESS(err);
484
Mark Lobodzinski23182612015-05-29 09:32:35 -0500485 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500486
Mike Stroyand72da752015-08-04 10:49:29 -0600487 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tony Barbour49a3b652015-08-04 16:13:01 -0600488 if(err != VK_SUCCESS) // If we can't find any unmappable memory this test doesn't make sense
489 return;
Mike Stroyand72da752015-08-04 10:49:29 -0600490
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500491 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500492 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500493 ASSERT_VK_SUCCESS(err);
494
495 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600496 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500497 ASSERT_VK_SUCCESS(err);
498
499 // Map memory as if to initialize the image
500 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500501 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500502
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600503 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600504 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 -0500505 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
506 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
507 }
508}
509
510TEST_F(VkLayerTest, BindInvalidMemory)
511{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600512 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500513 std::string msgString;
514 VkResult err;
515
516 ASSERT_NO_FATAL_FAILURE(InitState());
517 m_errorMonitor->ClearState();
518
519 // Create an image, allocate memory, free it, and then try to bind it
520 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500521 VkDeviceMemory mem;
522 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500523
524 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
525 const int32_t tex_width = 32;
526 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500527
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600528 VkImageCreateInfo image_create_info = {};
529 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
530 image_create_info.pNext = NULL;
531 image_create_info.imageType = VK_IMAGE_TYPE_2D;
532 image_create_info.format = tex_format;
533 image_create_info.extent.width = tex_width;
534 image_create_info.extent.height = tex_height;
535 image_create_info.extent.depth = 1;
536 image_create_info.mipLevels = 1;
537 image_create_info.arraySize = 1;
538 image_create_info.samples = 1;
539 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
540 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
541 image_create_info.flags = 0;
542
543 VkMemoryAllocInfo mem_alloc = {};
544 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
545 mem_alloc.pNext = NULL;
546 mem_alloc.allocationSize = 0;
547 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500548
549 err = vkCreateImage(m_device->device(), &image_create_info, &image);
550 ASSERT_VK_SUCCESS(err);
551
Tony Barboure84a8d62015-07-10 14:10:27 -0600552 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500553 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500554 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500555 ASSERT_VK_SUCCESS(err);
556
Mark Lobodzinski23182612015-05-29 09:32:35 -0500557 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500558
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800559 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600560 ASSERT_VK_SUCCESS(err);
561
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500562 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500563 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500564 ASSERT_VK_SUCCESS(err);
565
566 // Introduce validation failure, free memory before binding
Mark Lobodzinski23182612015-05-29 09:32:35 -0500567 vkFreeMemory(m_device->device(), mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500568 ASSERT_VK_SUCCESS(err);
569
570 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600571 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Cody Northrop87333892015-08-06 12:40:01 -0600572 // This may very well return an error.
573 (void)err;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500574
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600575 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600576 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to bind a freed memory object";
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500577 if (!strstr(msgString.c_str(),"couldn't find info for mem obj")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500578 FAIL() << "Error received did not match expected error message from BindObjectMemory in MemTracker";
579 }
580}
581
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600582// TODO : Is this test still valid. Not sure it is with updates to memory binding model
583// Verify and delete the test of fix the check
584//TEST_F(VkLayerTest, FreeBoundMemory)
585//{
586// VkFlags msgFlags;
587// std::string msgString;
588// VkResult err;
589//
590// ASSERT_NO_FATAL_FAILURE(InitState());
591// m_errorMonitor->ClearState();
592//
593// // Create an image, allocate memory, free it, and then try to bind it
594// VkImage image;
595// VkDeviceMemory mem;
596// VkMemoryRequirements mem_reqs;
597//
598// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
599// const int32_t tex_width = 32;
600// const int32_t tex_height = 32;
601//
602// const VkImageCreateInfo image_create_info = {
603// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
604// .pNext = NULL,
605// .imageType = VK_IMAGE_TYPE_2D,
606// .format = tex_format,
607// .extent = { tex_width, tex_height, 1 },
608// .mipLevels = 1,
609// .arraySize = 1,
610// .samples = 1,
611// .tiling = VK_IMAGE_TILING_LINEAR,
612// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
613// .flags = 0,
614// };
615// VkMemoryAllocInfo mem_alloc = {
616// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
617// .pNext = NULL,
618// .allocationSize = 0,
619// .memoryTypeIndex = 0,
620// };
621//
622// err = vkCreateImage(m_device->device(), &image_create_info, &image);
623// ASSERT_VK_SUCCESS(err);
624//
625// err = vkGetImageMemoryRequirements(m_device->device(),
626// image,
627// &mem_reqs);
628// ASSERT_VK_SUCCESS(err);
629//
630// mem_alloc.allocationSize = mem_reqs.size;
631//
632// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
633// ASSERT_VK_SUCCESS(err);
634//
635// // allocate memory
636// err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
637// ASSERT_VK_SUCCESS(err);
638//
639// // Bind memory to Image object
640// err = vkBindImageMemory(m_device->device(), image, mem, 0);
641// ASSERT_VK_SUCCESS(err);
642//
643// // Introduce validation failure, free memory while still bound to object
644// vkFreeMemory(m_device->device(), mem);
645// ASSERT_VK_SUCCESS(err);
646//
647// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600648// 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 -0600649// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
650// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
651// }
652//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500653
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500654TEST_F(VkLayerTest, RebindMemory)
655{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600656 VkFlags msgFlags;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500657 std::string msgString;
658 VkResult err;
659
660 ASSERT_NO_FATAL_FAILURE(InitState());
661 m_errorMonitor->ClearState();
662
663 // Create an image, allocate memory, free it, and then try to bind it
664 VkImage image;
665 VkDeviceMemory mem1;
666 VkDeviceMemory mem2;
667 VkMemoryRequirements mem_reqs;
668
669 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
670 const int32_t tex_width = 32;
671 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500672
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600673 VkImageCreateInfo image_create_info = {};
674 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
675 image_create_info.pNext = NULL;
676 image_create_info.imageType = VK_IMAGE_TYPE_2D;
677 image_create_info.format = tex_format;
678 image_create_info.extent.width = tex_width;
679 image_create_info.extent.height = tex_height;
680 image_create_info.extent.depth = 1;
681 image_create_info.mipLevels = 1;
682 image_create_info.arraySize = 1;
683 image_create_info.samples = 1;
684 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
685 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
686 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500687
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600688 VkMemoryAllocInfo mem_alloc = {};
689 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
690 mem_alloc.pNext = NULL;
691 mem_alloc.allocationSize = 0;
692 mem_alloc.memoryTypeIndex = 0;
693
694 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
695 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500696 err = vkCreateImage(m_device->device(), &image_create_info, &image);
697 ASSERT_VK_SUCCESS(err);
698
Tony Barboure84a8d62015-07-10 14:10:27 -0600699 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500700 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500701 &mem_reqs);
702 ASSERT_VK_SUCCESS(err);
703
704 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800705 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600706 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500707
708 // allocate 2 memory objects
709 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
710 ASSERT_VK_SUCCESS(err);
711 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
712 ASSERT_VK_SUCCESS(err);
713
714 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600715 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500716 ASSERT_VK_SUCCESS(err);
717
718 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600719 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500720 ASSERT_VK_SUCCESS(err);
721
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600722 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600723 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 -0500724 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
725 FAIL() << "Error received did not match expected message when rebinding memory to an object";
726 }
727}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500728
729TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
730{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600731 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500732 std::string msgString;
733 VkResult err;
734
735 ASSERT_NO_FATAL_FAILURE(InitState());
736 m_errorMonitor->ClearState();
737
738 // Create an image object, allocate memory, destroy the object and then try to bind it
739 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500740 VkDeviceMemory mem;
741 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500742
743 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
744 const int32_t tex_width = 32;
745 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500746
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600747 VkImageCreateInfo image_create_info = {};
748 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
749 image_create_info.pNext = NULL;
750 image_create_info.imageType = VK_IMAGE_TYPE_2D;
751 image_create_info.format = tex_format;
752 image_create_info.extent.width = tex_width;
753 image_create_info.extent.height = tex_height;
754 image_create_info.extent.depth = 1;
755 image_create_info.mipLevels = 1;
756 image_create_info.arraySize = 1;
757 image_create_info.samples = 1;
758 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
759 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
760 image_create_info.flags = 0;
761
762 VkMemoryAllocInfo mem_alloc = {};
763 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
764 mem_alloc.pNext = NULL;
765 mem_alloc.allocationSize = 0;
766 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500767
768 err = vkCreateImage(m_device->device(), &image_create_info, &image);
769 ASSERT_VK_SUCCESS(err);
770
Tony Barboure84a8d62015-07-10 14:10:27 -0600771 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500772 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500773 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500774 ASSERT_VK_SUCCESS(err);
775
Mark Lobodzinski23182612015-05-29 09:32:35 -0500776 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800777 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600778 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500779
780 // Allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500781 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500782 ASSERT_VK_SUCCESS(err);
783
784 // Introduce validation failure, destroy Image object before binding
Tony Barboure84a8d62015-07-10 14:10:27 -0600785 vkDestroyImage(m_device->device(), image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500786 ASSERT_VK_SUCCESS(err);
787
Mike Stroyand72da752015-08-04 10:49:29 -0600788 // Now Try to bind memory to this destroyed object
Tony Barboure84a8d62015-07-10 14:10:27 -0600789 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mike Stroyand72da752015-08-04 10:49:29 -0600790 // This may very well return an error.
791 (void) err;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500792
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600793 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600794 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while binding memory to a destroyed object";
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500795 if (!strstr(msgString.c_str(),"that's not in global list")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500796 FAIL() << "Error received did not match expected error message from updateObjectBinding in MemTracker";
797 }
798}
799
Tony Barbour8508b8e2015-04-09 10:48:04 -0600800TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600801{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600802 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600803 VkFlags msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600804 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600805
806 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600807 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
808 fenceInfo.pNext = NULL;
809 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600810
Tony Barbour30486ea2015-04-07 13:44:53 -0600811 ASSERT_NO_FATAL_FAILURE(InitState());
812 ASSERT_NO_FATAL_FAILURE(InitViewport());
813 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
814
Tony Barbour1490c912015-07-28 10:17:20 -0600815 BeginCommandBuffer();
816 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
817 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600818
819 testFence.init(*m_device, fenceInfo);
820 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -0600821 QueueCommandBuffer(testFence.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600822 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600823 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 -0600824 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500825 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600826 }
827
828}
829
830TEST_F(VkLayerTest, ResetUnsignaledFence)
831{
832 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600833 VkFlags msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600834 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600835 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600836 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
837 fenceInfo.pNext = NULL;
838
Tony Barbour8508b8e2015-04-09 10:48:04 -0600839 ASSERT_NO_FATAL_FAILURE(InitState());
840 testFence.init(*m_device, fenceInfo);
841 m_errorMonitor->ClearState();
Chia-I Wua4992342015-07-03 11:45:55 +0800842 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600843 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600844 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600845 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from submitting fence with UNSIGNALED state to vkResetFences";
Tony Barbour01999182015-04-09 12:58:51 -0600846 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500847 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600848 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600849
850}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600851
Chia-I Wuc278df82015-07-07 11:50:03 +0800852/* TODO: Update for changes due to bug-14075 tiling across render passes */
853#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600854TEST_F(VkLayerTest, InvalidUsageBits)
855{
856 // Initiate Draw w/o a PSO bound
857 VkFlags msgFlags;
858 std::string msgString;
859
860 ASSERT_NO_FATAL_FAILURE(InitState());
861 m_errorMonitor->ClearState();
862 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600863 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600864
865 const VkExtent3D e3d = {
866 .width = 128,
867 .height = 128,
868 .depth = 1,
869 };
870 const VkImageCreateInfo ici = {
871 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
872 .pNext = NULL,
873 .imageType = VK_IMAGE_TYPE_2D,
874 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
875 .extent = e3d,
876 .mipLevels = 1,
877 .arraySize = 1,
878 .samples = 1,
879 .tiling = VK_IMAGE_TILING_LINEAR,
880 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_BIT
881 .flags = 0,
882 };
883
884 VkImage dsi;
885 vkCreateImage(m_device->device(), &ici, &dsi);
886 VkDepthStencilView dsv;
887 const VkDepthStencilViewCreateInfo dsvci = {
888 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
889 .pNext = NULL,
890 .image = dsi,
891 .mipLevel = 0,
892 .baseArraySlice = 0,
893 .arraySize = 1,
894 .flags = 0,
895 };
896 vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv);
897 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600898 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 -0600899 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
900 FAIL() << "Error received was not 'Invalid usage flag for image...'";
901 }
902}
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600903#endif
Chia-I Wuc278df82015-07-07 11:50:03 +0800904#endif
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600905#if OBJ_TRACKER_TESTS
Cody Northrope4bc6942015-08-26 10:01:32 -0600906TEST_F(VkLayerTest, LineWidthStateNotBound)
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500907{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600908 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500909 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600910 ASSERT_NO_FATAL_FAILURE(InitState());
911 m_errorMonitor->ClearState();
Cody Northrope4bc6942015-08-26 10:01:32 -0600912 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500913
Cody Northrope4bc6942015-08-26 10:01:32 -0600914 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500915
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600916 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrope4bc6942015-08-26 10:01:32 -0600917 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Line Width State Object";
918 if (!strstr(msgString.c_str(),"Line width object not bound to this command buffer")) {
919 FAIL() << "Error received was not 'Line Width object not bound to this command buffer'";
Cody Northropf5bd2252015-08-17 11:10:49 -0600920 }
921}
922
Cody Northrope4bc6942015-08-26 10:01:32 -0600923TEST_F(VkLayerTest, DepthBiasStateNotBound)
Cody Northropf5bd2252015-08-17 11:10:49 -0600924{
925 VkFlags msgFlags;
926 std::string msgString;
927 ASSERT_NO_FATAL_FAILURE(InitState());
928 m_errorMonitor->ClearState();
Cody Northrope4bc6942015-08-26 10:01:32 -0600929 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
Cody Northropf5bd2252015-08-17 11:10:49 -0600930
Cody Northrope4bc6942015-08-26 10:01:32 -0600931 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Cody Northropf5bd2252015-08-17 11:10:49 -0600932
933 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrope4bc6942015-08-26 10:01:32 -0600934 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bias State Object";
935 if (!strstr(msgString.c_str(),"Depth bias object not bound to this command buffer")) {
936 FAIL() << "Error received was not 'Depth bias object not bound to this command buffer'";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500937 }
938}
939
940TEST_F(VkLayerTest, ViewportStateNotBound)
941{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600942 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500943 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600944 ASSERT_NO_FATAL_FAILURE(InitState());
945 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500946 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
947
948 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
949
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600950 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600951 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500952 if (!strstr(msgString.c_str(),"Viewport object not bound to this command buffer")) {
953 FAIL() << "Error received was not 'Viewport object not bound to this command buffer'";
954 }
955}
956
Cody Northrope4bc6942015-08-26 10:01:32 -0600957TEST_F(VkLayerTest, BlendStateNotBound)
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500958{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600959 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500960 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600961 ASSERT_NO_FATAL_FAILURE(InitState());
962 m_errorMonitor->ClearState();
Cody Northrope4bc6942015-08-26 10:01:32 -0600963 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500964
Cody Northrope4bc6942015-08-26 10:01:32 -0600965 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500966
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600967 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrope4bc6942015-08-26 10:01:32 -0600968 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Blend State Object";
969 if (!strstr(msgString.c_str(),"Blend object not bound to this command buffer")) {
970 FAIL() << "Error received was not 'Blend object not bound to this command buffer'";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500971 }
972}
973
Cody Northrope4bc6942015-08-26 10:01:32 -0600974TEST_F(VkLayerTest, DepthBoundsStateNotBound)
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500975{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600976 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500977 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600978 ASSERT_NO_FATAL_FAILURE(InitState());
979 m_errorMonitor->ClearState();
Cody Northrope4bc6942015-08-26 10:01:32 -0600980 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500981
Cody Northrope4bc6942015-08-26 10:01:32 -0600982 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500983
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600984 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrope4bc6942015-08-26 10:01:32 -0600985 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bounds State Object";
986 if (!strstr(msgString.c_str(),"Depth bounds object not bound to this command buffer")) {
987 FAIL() << "Error received was not 'Depth bounds object not bound to this command buffer'";
Cody Northrop2605cb02015-08-18 15:21:16 -0600988 }
989}
990
991TEST_F(VkLayerTest, StencilStateNotBound)
992{
993 VkFlags msgFlags;
994 std::string msgString;
995 ASSERT_NO_FATAL_FAILURE(InitState());
996 m_errorMonitor->ClearState();
997 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil state object is not bound beforehand");
998
999 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencil);
1000
1001 msgFlags = m_errorMonitor->GetState(&msgString);
1002 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Stencil State Object";
1003 if (!strstr(msgString.c_str(),"Stencil object not bound to this command buffer")) {
1004 FAIL() << "Error received was not 'Stencil object not bound to this command buffer'";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05001005 }
Tony Barbourdb686622015-05-06 09:35:56 -06001006}
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001007#endif
1008#if DRAW_STATE_TESTS
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001009TEST_F(VkLayerTest, CmdBufferTwoSubmits)
1010{
1011 vk_testing::Fence testFence;
1012 VkFlags msgFlags;
1013 std::string msgString;
1014
1015 VkFenceCreateInfo fenceInfo = {};
1016 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1017 fenceInfo.pNext = NULL;
1018 fenceInfo.flags = 0;
1019
1020 ASSERT_NO_FATAL_FAILURE(InitState());
1021 ASSERT_NO_FATAL_FAILURE(InitViewport());
1022 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1023
1024 // We luck out b/c by default the framework creates CB w/ the VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set
1025 BeginCommandBuffer();
1026 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
1027 EndCommandBuffer();
1028
1029 testFence.init(*m_device, fenceInfo);
1030
1031 // Bypass framework since it does the waits automatically
1032 VkResult err = VK_SUCCESS;
1033 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
1034 ASSERT_VK_SUCCESS( err );
1035
1036 m_errorMonitor->ClearState();
1037 // Cause validation error by re-submitting cmd buffer that should only be submitted once
1038 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
1039 ASSERT_VK_SUCCESS( err );
1040
1041 msgFlags = m_errorMonitor->GetState(&msgString);
1042 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 -06001043 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 -06001044 FAIL() << "Error received was not 'CB (0xaddress) was created w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set...'";
1045 }
1046}
1047
1048
Tobin Ehlise4076782015-06-24 15:53:07 -06001049TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001050{
1051 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001052 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001053 std::string msgString;
1054
1055 ASSERT_NO_FATAL_FAILURE(InitState());
1056 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001057 BeginCommandBuffer();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001058 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Tony Barbour1490c912015-07-28 10:17:20 -06001059 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001060 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001061 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 -06001062 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
1063 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0xbaadb1be) without an active RenderPass'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001064 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001065}
1066
1067TEST_F(VkLayerTest, InvalidDescriptorPool)
1068{
1069 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1070 // The DS check for this is after driver has been called to validate DS internal data struct
1071 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001072/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001073 std::string msgString;
1074 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1075 vkResetDescriptorPool(device(), badPool);
1076
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001077 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001078 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 -06001079 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1080 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1081 }*/
1082}
1083
1084TEST_F(VkLayerTest, InvalidDescriptorSet)
1085{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001086 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1087 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001088 // Create a valid cmd buffer
1089 // call vkCmdBindDescriptorSets w/ false DS
1090}
1091
1092TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1093{
1094 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1095 // The DS check for this is after driver has been called to validate DS internal data struct
1096}
1097
1098TEST_F(VkLayerTest, InvalidPipeline)
1099{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001100 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1101 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001102 // Create a valid cmd buffer
1103 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -06001104// VkFlags msgFlags;
1105// std::string msgString;
1106//
1107// ASSERT_NO_FATAL_FAILURE(InitState());
1108// m_errorMonitor->ClearState();
1109// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001110// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001111// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1112// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1113// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001114// 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 -06001115// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1116// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1117// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001118}
1119
Tobin Ehlis254eca02015-06-25 15:46:59 -06001120TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001121{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001122 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001123 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001124 std::string msgString;
1125 VkResult err;
1126
1127 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001128 ASSERT_NO_FATAL_FAILURE(InitViewport());
1129 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001130 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001131 VkDescriptorTypeCount ds_type_count = {};
1132 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1133 ds_type_count.count = 1;
1134
1135 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1136 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1137 ds_pool_ci.pNext = NULL;
1138 ds_pool_ci.count = 1;
1139 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001140
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001141 VkDescriptorPool ds_pool;
1142 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1143 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001144
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001145 VkDescriptorSetLayoutBinding dsl_binding = {};
1146 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1147 dsl_binding.arraySize = 1;
1148 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1149 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001150
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001151 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1152 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1153 ds_layout_ci.pNext = NULL;
1154 ds_layout_ci.count = 1;
1155 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001156 VkDescriptorSetLayout ds_layout;
1157 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1158 ASSERT_VK_SUCCESS(err);
1159
1160 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001161 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001162 ASSERT_VK_SUCCESS(err);
1163
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001164 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1165 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1166 pipeline_layout_ci.pNext = NULL;
1167 pipeline_layout_ci.descriptorSetCount = 1;
1168 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001169
1170 VkPipelineLayout pipeline_layout;
1171 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1172 ASSERT_VK_SUCCESS(err);
1173
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001174 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001175 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1176 // but add it to be able to run on more devices
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001177
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001178 VkPipelineObj pipe(m_device);
1179 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001180 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001181 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001182
1183 BeginCommandBuffer();
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001184 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbour1490c912015-07-28 10:17:20 -06001185 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001186
Tobin Ehlis254eca02015-06-25 15:46:59 -06001187 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001188 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 -06001189 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1190 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1191 }
1192}
1193
1194TEST_F(VkLayerTest, NoBeginCmdBuffer)
1195{
1196 VkFlags msgFlags;
1197 std::string msgString;
1198
1199 ASSERT_NO_FATAL_FAILURE(InitState());
1200 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001201 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001202 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1203 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1204 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001205 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 -06001206 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1207 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1208 }
1209}
1210
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001211TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1212{
1213 VkFlags msgFlags;
1214 std::string msgString;
1215
1216 ASSERT_NO_FATAL_FAILURE(InitState());
1217 m_errorMonitor->ClearState();
1218
1219 // Calls CreateCommandBuffer
1220 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1221
1222 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northrop10d8f982015-08-04 17:35:57 -06001223 VkCmdBufferBeginInfo cmd_buf_info = {};
1224 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1225 cmd_buf_info.pNext = NULL;
1226 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1227 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1228 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1229 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1230
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001231
1232 // The error should be caught by validation of the BeginCommandBuffer call
1233 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1234
1235 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001236 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error passing a non-NULL Framebuffer and Renderpass to BeginCommandBuffer()";
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001237 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1238 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1239 }
1240}
1241
1242TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1243{
1244 VkFlags msgFlags;
1245 std::string msgString;
1246 VkResult err;
1247 VkCmdBuffer draw_cmd;
1248 VkCmdPool cmd_pool;
1249
1250 ASSERT_NO_FATAL_FAILURE(InitState());
1251 m_errorMonitor->ClearState();
1252
Cody Northrop10d8f982015-08-04 17:35:57 -06001253 VkCmdBufferCreateInfo cmd = {};
1254 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1255 cmd.pNext = NULL;
1256 cmd.cmdPool = m_cmdPool;
1257 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1258 cmd.flags = 0;
1259
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001260 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
1261 assert(!err);
1262
1263 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northrop10d8f982015-08-04 17:35:57 -06001264 VkCmdBufferBeginInfo cmd_buf_info = {};
1265 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1266 cmd_buf_info.pNext = NULL;
1267 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1268 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001269
1270 // The error should be caught by validation of the BeginCommandBuffer call
1271 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1272
1273 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001274 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 -06001275 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1276 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1277 }
1278}
1279
Tobin Ehlis254eca02015-06-25 15:46:59 -06001280TEST_F(VkLayerTest, InvalidPipelineCreateState)
1281{
1282 // Attempt to Create Gfx Pipeline w/o a VS
1283 VkFlags msgFlags;
1284 std::string msgString;
1285 VkResult err;
1286
1287 ASSERT_NO_FATAL_FAILURE(InitState());
1288 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001289
1290 VkDescriptorTypeCount ds_type_count = {};
1291 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1292 ds_type_count.count = 1;
1293
1294 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1295 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1296 ds_pool_ci.pNext = NULL;
1297 ds_pool_ci.count = 1;
1298 ds_pool_ci.pTypeCount = &ds_type_count;
1299
Tobin Ehlis254eca02015-06-25 15:46:59 -06001300 VkDescriptorPool ds_pool;
1301 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1302 ASSERT_VK_SUCCESS(err);
1303
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001304 VkDescriptorSetLayoutBinding dsl_binding = {};
1305 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1306 dsl_binding.arraySize = 1;
1307 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1308 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001309
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001310 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1311 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1312 ds_layout_ci.pNext = NULL;
1313 ds_layout_ci.count = 1;
1314 ds_layout_ci.pBinding = &dsl_binding;
1315
Tobin Ehlis254eca02015-06-25 15:46:59 -06001316 VkDescriptorSetLayout ds_layout;
1317 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1318 ASSERT_VK_SUCCESS(err);
1319
1320 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001321 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001322 ASSERT_VK_SUCCESS(err);
1323
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001324 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1325 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1326 pipeline_layout_ci.pNext = NULL;
1327 pipeline_layout_ci.descriptorSetCount = 1;
1328 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001329
1330 VkPipelineLayout pipeline_layout;
1331 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1332 ASSERT_VK_SUCCESS(err);
1333
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001334 VkGraphicsPipelineCreateInfo gp_ci = {};
1335 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1336 gp_ci.pNext = NULL;
1337 gp_ci.stageCount = 0;
1338 gp_ci.pStages = NULL;
1339 gp_ci.pVertexInputState = NULL;
1340 gp_ci.pInputAssemblyState = NULL;
1341 gp_ci.pTessellationState = NULL;
1342 gp_ci.pViewportState = NULL;
1343 gp_ci.pRasterState = NULL;
1344 gp_ci.pMultisampleState = NULL;
1345 gp_ci.pDepthStencilState = NULL;
1346 gp_ci.pColorBlendState = NULL;
1347 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1348 gp_ci.layout = pipeline_layout;
1349
1350 VkPipelineCacheCreateInfo pc_ci = {};
1351 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1352 pc_ci.pNext = NULL;
1353 pc_ci.initialSize = 0;
1354 pc_ci.initialData = 0;
1355 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001356
1357 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001358 VkPipelineCache pipelineCache;
1359
1360 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1361 ASSERT_VK_SUCCESS(err);
1362 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001363
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001364 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001365 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o VS.";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001366 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1367 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1368 }
1369}
1370
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001371TEST_F(VkLayerTest, NullRenderPass)
1372{
1373 // Bind a NULL RenderPass
1374 VkFlags msgFlags;
1375 std::string msgString;
1376
1377 ASSERT_NO_FATAL_FAILURE(InitState());
1378 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1379 m_errorMonitor->ClearState();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001380
Tony Barbour1490c912015-07-28 10:17:20 -06001381 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001382 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06001383 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001384
1385 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001386 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001387 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
1388 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
1389 }
1390}
1391
Tobin Ehlis254eca02015-06-25 15:46:59 -06001392TEST_F(VkLayerTest, RenderPassWithinRenderPass)
1393{
1394 // Bind a BeginRenderPass within an active RenderPass
1395 VkFlags msgFlags;
1396 std::string msgString;
1397
1398 ASSERT_NO_FATAL_FAILURE(InitState());
1399 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1400 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001401
Tony Barbour1490c912015-07-28 10:17:20 -06001402 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001403 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001404 VkRenderPassBeginInfo rp_begin = {};
1405 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
1406 rp_begin.pNext = NULL;
1407 rp_begin.renderPass = (VkRenderPass)0xc001d00d;
1408 rp_begin.framebuffer = 0;
1409
Tony Barbour1490c912015-07-28 10:17:20 -06001410 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001411
1412 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001413 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding RenderPass w/i an active RenderPass.";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001414 if (!strstr(msgString.c_str(),"Cannot call vkCmdBeginRenderPass() during an active RenderPass ")) {
1415 FAIL() << "Error received was not 'Cannot call vkCmdBeginRenderPass() during an active RenderPass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001416 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001417}
1418
1419TEST_F(VkLayerTest, InvalidDynamicStateObject)
1420{
1421 // Create a valid cmd buffer
1422 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001423 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1424 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001425}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06001426
Tobin Ehlise4076782015-06-24 15:53:07 -06001427TEST_F(VkLayerTest, VtxBufferNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001428{
1429 // Bind VBO out-of-bounds for given PSO
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001430 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001431 std::string msgString;
1432 VkResult err;
1433
1434 ASSERT_NO_FATAL_FAILURE(InitState());
1435 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001436
1437 VkDescriptorTypeCount ds_type_count = {};
1438 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1439 ds_type_count.count = 1;
1440
1441 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1442 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1443 ds_pool_ci.pNext = NULL;
1444 ds_pool_ci.count = 1;
1445 ds_pool_ci.pTypeCount = &ds_type_count;
1446
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001447 VkDescriptorPool ds_pool;
1448 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1449 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001450
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001451 VkDescriptorSetLayoutBinding dsl_binding = {};
1452 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1453 dsl_binding.arraySize = 1;
1454 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1455 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001456
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001457 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1458 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1459 ds_layout_ci.pNext = NULL;
1460 ds_layout_ci.count = 1;
1461 ds_layout_ci.pBinding = &dsl_binding;
1462
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001463 VkDescriptorSetLayout ds_layout;
1464 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1465 ASSERT_VK_SUCCESS(err);
1466
1467 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001468 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001469 ASSERT_VK_SUCCESS(err);
1470
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001471 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1472 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1473 pipeline_layout_ci.pNext = NULL;
1474 pipeline_layout_ci.descriptorSetCount = 1;
1475 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001476
1477 VkPipelineLayout pipeline_layout;
1478 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1479 ASSERT_VK_SUCCESS(err);
1480
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001481 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001482 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1483 // but add it to be able to run on more devices
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001484 VkPipelineObj pipe(m_device);
1485 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001486 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001487 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001488
Tony Barbour1490c912015-07-28 10:17:20 -06001489 BeginCommandBuffer();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001490 ASSERT_VK_SUCCESS(err);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001491 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001492 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06001493 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001494
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001495 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001496 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
Tobin Ehlise4076782015-06-24 15:53:07 -06001497 if (!strstr(msgString.c_str(),"Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.")) {
1498 FAIL() << "Error received was not 'Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001499 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001500}
1501
1502TEST_F(VkLayerTest, DSTypeMismatch)
1503{
1504 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001505 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001506 std::string msgString;
1507 VkResult err;
1508
1509 ASSERT_NO_FATAL_FAILURE(InitState());
1510 m_errorMonitor->ClearState();
1511 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001512 VkDescriptorTypeCount ds_type_count = {};
1513 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1514 ds_type_count.count = 1;
1515
1516 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1517 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1518 ds_pool_ci.pNext = NULL;
1519 ds_pool_ci.count = 1;
1520 ds_pool_ci.pTypeCount = &ds_type_count;
1521
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001522 VkDescriptorPool ds_pool;
1523 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1524 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001525 VkDescriptorSetLayoutBinding dsl_binding = {};
1526 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1527 dsl_binding.arraySize = 1;
1528 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1529 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001530
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001531 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1532 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1533 ds_layout_ci.pNext = NULL;
1534 ds_layout_ci.count = 1;
1535 ds_layout_ci.pBinding = &dsl_binding;
1536
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001537 VkDescriptorSetLayout ds_layout;
1538 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1539 ASSERT_VK_SUCCESS(err);
1540
1541 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001542 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001543 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001544
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001545 VkSamplerCreateInfo sampler_ci = {};
1546 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1547 sampler_ci.pNext = NULL;
1548 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1549 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1550 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1551 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1552 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1553 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1554 sampler_ci.mipLodBias = 1.0;
1555 sampler_ci.maxAnisotropy = 1;
1556 sampler_ci.compareEnable = VK_FALSE;
1557 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1558 sampler_ci.minLod = 1.0;
1559 sampler_ci.maxLod = 1.0;
1560 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northrop0bf4e1d2015-08-11 15:50:55 -06001561 sampler_ci.texelCoords = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001562
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001563 VkSampler sampler;
1564 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1565 ASSERT_VK_SUCCESS(err);
1566
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001567 VkDescriptorInfo descriptor_info;
1568 memset(&descriptor_info, 0, sizeof(descriptor_info));
1569 descriptor_info.sampler = sampler;
1570
1571 VkWriteDescriptorSet descriptor_write;
1572 memset(&descriptor_write, 0, sizeof(descriptor_write));
1573 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1574 descriptor_write.destSet = descriptorSet;
1575 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001576 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001577 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1578 descriptor_write.pDescriptors = &descriptor_info;
1579
1580 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1581
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001582 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001583 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating BUFFER Descriptor w/ incorrect type of SAMPLER.";
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001584 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) {
1585 FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match overlapping binding type!'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001586 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001587}
1588
1589TEST_F(VkLayerTest, DSUpdateOutOfBounds)
1590{
1591 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001592 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001593 std::string msgString;
1594 VkResult err;
1595
1596 ASSERT_NO_FATAL_FAILURE(InitState());
1597 m_errorMonitor->ClearState();
1598 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001599 VkDescriptorTypeCount ds_type_count = {};
1600 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1601 ds_type_count.count = 1;
1602
1603 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1604 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1605 ds_pool_ci.pNext = NULL;
1606 ds_pool_ci.count = 1;
1607 ds_pool_ci.pTypeCount = &ds_type_count;
1608
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001609 VkDescriptorPool ds_pool;
1610 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1611 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001612
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001613 VkDescriptorSetLayoutBinding dsl_binding = {};
1614 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1615 dsl_binding.arraySize = 1;
1616 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1617 dsl_binding.pImmutableSamplers = NULL;
1618
1619 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1620 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1621 ds_layout_ci.pNext = NULL;
1622 ds_layout_ci.count = 1;
1623 ds_layout_ci.pBinding = &dsl_binding;
1624
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001625 VkDescriptorSetLayout ds_layout;
1626 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1627 ASSERT_VK_SUCCESS(err);
1628
1629 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001630 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001631 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001632
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001633 VkSamplerCreateInfo sampler_ci = {};
1634 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1635 sampler_ci.pNext = NULL;
1636 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1637 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1638 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1639 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1640 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1641 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1642 sampler_ci.mipLodBias = 1.0;
1643 sampler_ci.maxAnisotropy = 1;
1644 sampler_ci.compareEnable = VK_FALSE;
1645 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1646 sampler_ci.minLod = 1.0;
1647 sampler_ci.maxLod = 1.0;
1648 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northrop0bf4e1d2015-08-11 15:50:55 -06001649 sampler_ci.texelCoords = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001650
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001651 VkSampler sampler;
1652 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1653 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001654
1655 VkDescriptorInfo descriptor_info;
1656 memset(&descriptor_info, 0, sizeof(descriptor_info));
1657 descriptor_info.sampler = sampler;
1658
1659 VkWriteDescriptorSet descriptor_write;
1660 memset(&descriptor_write, 0, sizeof(descriptor_write));
1661 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1662 descriptor_write.destSet = descriptorSet;
1663 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
1664 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001665 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001666 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1667 descriptor_write.pDescriptors = &descriptor_info;
1668
1669 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1670
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001671 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001672 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 +08001673 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
1674 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 -06001675 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001676}
1677
1678TEST_F(VkLayerTest, InvalidDSUpdateIndex)
1679{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001680 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001681 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001682 std::string msgString;
1683 VkResult err;
1684
1685 ASSERT_NO_FATAL_FAILURE(InitState());
1686 m_errorMonitor->ClearState();
1687 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001688 VkDescriptorTypeCount ds_type_count = {};
1689 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1690 ds_type_count.count = 1;
1691
1692 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1693 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1694 ds_pool_ci.pNext = NULL;
1695 ds_pool_ci.count = 1;
1696 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001697 VkDescriptorPool ds_pool;
1698 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1699 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001700
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001701 VkDescriptorSetLayoutBinding dsl_binding = {};
1702 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1703 dsl_binding.arraySize = 1;
1704 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1705 dsl_binding.pImmutableSamplers = NULL;
1706
1707 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1708 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1709 ds_layout_ci.pNext = NULL;
1710 ds_layout_ci.count = 1;
1711 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001712 VkDescriptorSetLayout ds_layout;
1713 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1714 ASSERT_VK_SUCCESS(err);
1715
1716 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001717 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001718 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001719
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001720 VkSamplerCreateInfo sampler_ci = {};
1721 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1722 sampler_ci.pNext = NULL;
1723 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1724 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1725 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1726 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1727 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1728 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1729 sampler_ci.mipLodBias = 1.0;
1730 sampler_ci.maxAnisotropy = 1;
1731 sampler_ci.compareEnable = VK_FALSE;
1732 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1733 sampler_ci.minLod = 1.0;
1734 sampler_ci.maxLod = 1.0;
1735 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northrop0bf4e1d2015-08-11 15:50:55 -06001736 sampler_ci.texelCoords = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001737
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001738 VkSampler sampler;
1739 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1740 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001741
1742 VkDescriptorInfo descriptor_info;
1743 memset(&descriptor_info, 0, sizeof(descriptor_info));
1744 descriptor_info.sampler = sampler;
1745
1746 VkWriteDescriptorSet descriptor_write;
1747 memset(&descriptor_write, 0, sizeof(descriptor_write));
1748 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1749 descriptor_write.destSet = descriptorSet;
1750 descriptor_write.destBinding = 2;
1751 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001752 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001753 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1754 descriptor_write.pDescriptors = &descriptor_info;
1755
1756 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1757
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001758 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001759 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 -06001760 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
1761 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
1762 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001763}
1764
1765TEST_F(VkLayerTest, InvalidDSUpdateStruct)
1766{
1767 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001768 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001769 std::string msgString;
1770 VkResult err;
1771
1772 ASSERT_NO_FATAL_FAILURE(InitState());
1773 m_errorMonitor->ClearState();
1774 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001775
1776 VkDescriptorTypeCount ds_type_count = {};
1777 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1778 ds_type_count.count = 1;
1779
1780 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1781 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1782 ds_pool_ci.pNext = NULL;
1783 ds_pool_ci.count = 1;
1784 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001785 VkDescriptorPool ds_pool;
1786 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1787 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001788 VkDescriptorSetLayoutBinding dsl_binding = {};
1789 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1790 dsl_binding.arraySize = 1;
1791 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1792 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001793
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001794 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1795 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1796 ds_layout_ci.pNext = NULL;
1797 ds_layout_ci.count = 1;
1798 ds_layout_ci.pBinding = &dsl_binding;
1799
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001800 VkDescriptorSetLayout ds_layout;
1801 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1802 ASSERT_VK_SUCCESS(err);
1803
1804 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001805 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001806 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001807
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001808 VkSamplerCreateInfo sampler_ci = {};
1809 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1810 sampler_ci.pNext = NULL;
1811 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1812 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1813 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1814 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1815 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1816 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1817 sampler_ci.mipLodBias = 1.0;
1818 sampler_ci.maxAnisotropy = 1;
1819 sampler_ci.compareEnable = VK_FALSE;
1820 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1821 sampler_ci.minLod = 1.0;
1822 sampler_ci.maxLod = 1.0;
1823 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northrop0bf4e1d2015-08-11 15:50:55 -06001824 sampler_ci.texelCoords = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001825 VkSampler sampler;
1826 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1827 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001828
1829
1830 VkDescriptorInfo descriptor_info;
1831 memset(&descriptor_info, 0, sizeof(descriptor_info));
1832 descriptor_info.sampler = sampler;
1833
1834 VkWriteDescriptorSet descriptor_write;
1835 memset(&descriptor_write, 0, sizeof(descriptor_write));
1836 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
1837 descriptor_write.destSet = descriptorSet;
1838 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001839 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001840 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1841 descriptor_write.pDescriptors = &descriptor_info;
1842
1843 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1844
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001845 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001846 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 -06001847 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
1848 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
1849 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001850}
1851
1852TEST_F(VkLayerTest, NumSamplesMismatch)
1853{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001854 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001855 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001856 std::string msgString;
1857 VkResult err;
1858
1859 ASSERT_NO_FATAL_FAILURE(InitState());
1860 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1861 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001862 VkDescriptorTypeCount ds_type_count = {};
1863 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1864 ds_type_count.count = 1;
1865
1866 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1867 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1868 ds_pool_ci.pNext = NULL;
1869 ds_pool_ci.count = 1;
1870 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001871 VkDescriptorPool ds_pool;
1872 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1873 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001874
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001875 VkDescriptorSetLayoutBinding dsl_binding = {};
1876 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1877 dsl_binding.arraySize = 1;
1878 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1879 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001880
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001881 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1882 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1883 ds_layout_ci.pNext = NULL;
1884 ds_layout_ci.count = 1;
1885 ds_layout_ci.pBinding = &dsl_binding;
1886
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001887 VkDescriptorSetLayout ds_layout;
1888 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1889 ASSERT_VK_SUCCESS(err);
1890
1891 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001892 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001893 ASSERT_VK_SUCCESS(err);
1894
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001895 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1896 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1897 pipe_ms_state_ci.pNext = NULL;
1898 pipe_ms_state_ci.rasterSamples = 4;
1899 pipe_ms_state_ci.sampleShadingEnable = 0;
1900 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06001901 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001902
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001903 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1904 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1905 pipeline_layout_ci.pNext = NULL;
1906 pipeline_layout_ci.descriptorSetCount = 1;
1907 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001908
1909 VkPipelineLayout pipeline_layout;
1910 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1911 ASSERT_VK_SUCCESS(err);
1912
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001913 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001914 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1915 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06001916 VkPipelineObj pipe(m_device);
1917 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001918 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06001919 pipe.SetMSAA(&pipe_ms_state_ci);
1920 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001921
Tony Barbour1490c912015-07-28 10:17:20 -06001922 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06001923 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001924
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001925 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001926 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 -06001927 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
1928 FAIL() << "Error received was not 'Num samples mismatch!...'";
1929 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001930}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001931
Tobin Ehlise4076782015-06-24 15:53:07 -06001932TEST_F(VkLayerTest, PipelineNotBound)
1933{
1934 VkFlags msgFlags;
1935 std::string msgString;
1936 VkResult err;
1937
1938 ASSERT_NO_FATAL_FAILURE(InitState());
1939 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1940 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001941
1942 VkDescriptorTypeCount ds_type_count = {};
1943 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1944 ds_type_count.count = 1;
1945
1946 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1947 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1948 ds_pool_ci.pNext = NULL;
1949 ds_pool_ci.count = 1;
1950 ds_pool_ci.pTypeCount = &ds_type_count;
1951
Tobin Ehlise4076782015-06-24 15:53:07 -06001952 VkDescriptorPool ds_pool;
1953 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1954 ASSERT_VK_SUCCESS(err);
1955
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001956 VkDescriptorSetLayoutBinding dsl_binding = {};
1957 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1958 dsl_binding.arraySize = 1;
1959 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1960 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06001961
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001962 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1963 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1964 ds_layout_ci.pNext = NULL;
1965 ds_layout_ci.count = 1;
1966 ds_layout_ci.pBinding = &dsl_binding;
1967
Tobin Ehlise4076782015-06-24 15:53:07 -06001968 VkDescriptorSetLayout ds_layout;
1969 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1970 ASSERT_VK_SUCCESS(err);
1971
1972 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001973 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06001974 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001975
1976 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1977 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1978 pipeline_layout_ci.pNext = NULL;
1979 pipeline_layout_ci.descriptorSetCount = 1;
1980 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06001981
1982 VkPipelineLayout pipeline_layout;
1983 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1984 ASSERT_VK_SUCCESS(err);
1985
Tobin Ehlise4076782015-06-24 15:53:07 -06001986 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Tony Barbour1490c912015-07-28 10:17:20 -06001987
1988 BeginCommandBuffer();
1989 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06001990
1991 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001992 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 -06001993 if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1994 FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1995 }
1996}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001997
1998TEST_F(VkLayerTest, ClearCmdNoDraw)
1999{
2000 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
2001 VkFlags msgFlags;
2002 std::string msgString;
2003 VkResult err;
2004
2005 ASSERT_NO_FATAL_FAILURE(InitState());
2006 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2007 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002008
2009 VkDescriptorTypeCount ds_type_count = {};
2010 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2011 ds_type_count.count = 1;
2012
2013 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2014 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2015 ds_pool_ci.pNext = NULL;
2016 ds_pool_ci.count = 1;
2017 ds_pool_ci.pTypeCount = &ds_type_count;
2018
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002019 VkDescriptorPool ds_pool;
2020 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
2021 ASSERT_VK_SUCCESS(err);
2022
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002023 VkDescriptorSetLayoutBinding dsl_binding = {};
2024 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2025 dsl_binding.arraySize = 1;
2026 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2027 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002028
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002029 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2030 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2031 ds_layout_ci.pNext = NULL;
2032 ds_layout_ci.count = 1;
2033 ds_layout_ci.pBinding = &dsl_binding;
2034
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002035 VkDescriptorSetLayout ds_layout;
2036 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2037 ASSERT_VK_SUCCESS(err);
2038
2039 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002040 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002041 ASSERT_VK_SUCCESS(err);
2042
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002043 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2044 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2045 pipe_ms_state_ci.pNext = NULL;
2046 pipe_ms_state_ci.rasterSamples = 4;
2047 pipe_ms_state_ci.sampleShadingEnable = 0;
2048 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002049 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002050
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002051 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2052 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2053 pipeline_layout_ci.pNext = NULL;
2054 pipeline_layout_ci.descriptorSetCount = 1;
2055 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002056
2057 VkPipelineLayout pipeline_layout;
2058 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2059 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002060
Tony Barbourd7d828b2015-08-06 10:16:07 -06002061 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002062 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2063 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002064 VkPipelineObj pipe(m_device);
2065 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002066 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002067 pipe.SetMSAA(&pipe_ms_state_ci);
2068 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002069
2070 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002071
2072 m_errorMonitor->ClearState();
2073 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
2074 // Also pass down other dummy params to keep driver and paramchecker happy
2075 VkClearColorValue cCV;
Cody Northrop2563a032015-08-25 15:26:38 -06002076 cCV.float32[0] = 1.0;
2077 cCV.float32[1] = 1.0;
2078 cCV.float32[2] = 1.0;
2079 cCV.float32[3] = 1.0;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002080
Tony Barbour1490c912015-07-28 10:17:20 -06002081 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002082 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002083 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 -06002084 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) {
2085 FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'";
2086 }
2087}
2088
Tobin Ehlise4076782015-06-24 15:53:07 -06002089TEST_F(VkLayerTest, VtxBufferBadIndex)
2090{
2091 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
2092 VkFlags msgFlags;
2093 std::string msgString;
2094 VkResult err;
2095
2096 ASSERT_NO_FATAL_FAILURE(InitState());
2097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2098 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002099
2100 VkDescriptorTypeCount ds_type_count = {};
2101 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2102 ds_type_count.count = 1;
2103
2104 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2105 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2106 ds_pool_ci.pNext = NULL;
2107 ds_pool_ci.count = 1;
2108 ds_pool_ci.pTypeCount = &ds_type_count;
2109
2110 VkDescriptorPool ds_pool;
Tobin Ehlise4076782015-06-24 15:53:07 -06002111 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
2112 ASSERT_VK_SUCCESS(err);
2113
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002114 VkDescriptorSetLayoutBinding dsl_binding = {};
2115 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2116 dsl_binding.arraySize = 1;
2117 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2118 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002119
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002120 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2121 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2122 ds_layout_ci.pNext = NULL;
2123 ds_layout_ci.count = 1;
2124 ds_layout_ci.pBinding = &dsl_binding;
2125
Tobin Ehlise4076782015-06-24 15:53:07 -06002126 VkDescriptorSetLayout ds_layout;
2127 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2128 ASSERT_VK_SUCCESS(err);
2129
2130 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002131 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06002132 ASSERT_VK_SUCCESS(err);
2133
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002134 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2135 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2136 pipe_ms_state_ci.pNext = NULL;
2137 pipe_ms_state_ci.rasterSamples = 1;
2138 pipe_ms_state_ci.sampleShadingEnable = 0;
2139 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002140 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002141
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002142 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2143 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2144 pipeline_layout_ci.pNext = NULL;
2145 pipeline_layout_ci.descriptorSetCount = 1;
2146 pipeline_layout_ci.pSetLayouts = &ds_layout;
2147 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06002148
Tobin Ehlise4076782015-06-24 15:53:07 -06002149 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2150 ASSERT_VK_SUCCESS(err);
2151
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002152 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002153 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2154 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002155 VkPipelineObj pipe(m_device);
2156 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002157 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002158 pipe.SetMSAA(&pipe_ms_state_ci);
2159 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002160
2161 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06002162 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlise4076782015-06-24 15:53:07 -06002163 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06002164 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlise4076782015-06-24 15:53:07 -06002165
2166 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002167 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding Vtx Buffer w/o VBO attached to PSO.";
Tobin Ehlise4076782015-06-24 15:53:07 -06002168 if (!strstr(msgString.c_str(),"Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.")) {
2169 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
2170 }
2171}
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002172#endif
2173#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06002174#if GTEST_IS_THREADSAFE
2175struct thread_data_struct {
2176 VkCmdBuffer cmdBuffer;
2177 VkEvent event;
2178 bool bailout;
2179};
2180
2181extern "C" void *AddToCommandBuffer(void *arg)
2182{
2183 struct thread_data_struct *data = (struct thread_data_struct *) arg;
2184 std::string msgString;
2185
2186 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06002187 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06002188 if (data->bailout) {
2189 break;
2190 }
2191 }
2192 return NULL;
2193}
2194
2195TEST_F(VkLayerTest, ThreadCmdBufferCollision)
2196{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002197 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06002198 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002199 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06002200
2201 ASSERT_NO_FATAL_FAILURE(InitState());
2202 ASSERT_NO_FATAL_FAILURE(InitViewport());
2203 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2204
Mike Stroyan09aae812015-05-12 16:00:45 -06002205 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06002206 BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002207
2208 VkEventCreateInfo event_info;
2209 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06002210 VkResult err;
2211
2212 memset(&event_info, 0, sizeof(event_info));
2213 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2214
2215 err = vkCreateEvent(device(), &event_info, &event);
2216 ASSERT_VK_SUCCESS(err);
2217
Mike Stroyan09aae812015-05-12 16:00:45 -06002218 err = vkResetEvent(device(), event);
2219 ASSERT_VK_SUCCESS(err);
2220
2221 struct thread_data_struct data;
Tony Barbour1490c912015-07-28 10:17:20 -06002222 data.cmdBuffer = m_cmdBuffer->handle();
Mike Stroyan09aae812015-05-12 16:00:45 -06002223 data.event = event;
2224 data.bailout = false;
2225 m_errorMonitor->SetBailout(&data.bailout);
2226 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002227 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06002228 // Add many entries to command buffer from this thread at the same time.
2229 AddToCommandBuffer(&data);
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002230 test_platform_thread_join(thread, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -06002231 EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002232
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002233 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002234 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 -06002235 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05002236 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06002237 }
2238
2239}
2240#endif
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002241#endif
Chris Forbes5af3bf22015-05-25 11:13:08 +12002242#if SHADER_CHECKER_TESTS
2243TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
2244{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002245 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12002246 std::string msgString;
2247 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002248 ScopedUseGlsl useGlsl(false);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002249
2250 char const *vsSource =
2251 "#version 140\n"
2252 "#extension GL_ARB_separate_shader_objects: require\n"
2253 "#extension GL_ARB_shading_language_420pack: require\n"
2254 "\n"
2255 "layout(location=0) out float x;\n"
2256 "void main(){\n"
2257 " gl_Position = vec4(1);\n"
2258 " x = 0;\n"
2259 "}\n";
2260 char const *fsSource =
2261 "#version 140\n"
2262 "#extension GL_ARB_separate_shader_objects: require\n"
2263 "#extension GL_ARB_shading_language_420pack: require\n"
2264 "\n"
2265 "layout(location=0) out vec4 color;\n"
2266 "void main(){\n"
2267 " color = vec4(1);\n"
2268 "}\n";
2269
2270 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2271 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2272
2273 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002274 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12002275 pipe.AddShader(&vs);
2276 pipe.AddShader(&fs);
2277
Chris Forbes5af3bf22015-05-25 11:13:08 +12002278 VkDescriptorSetObj descriptorSet(m_device);
2279 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002280 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002281
2282 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002283 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12002284
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002285 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002286
Cody Northrop1684adb2015-08-05 11:15:02 -06002287 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002288 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
2289 FAIL() << "Incorrect warning: " << msgString;
2290 }
2291}
Chris Forbes5af3bf22015-05-25 11:13:08 +12002292
Chris Forbes3c10b852015-05-25 11:13:13 +12002293TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
2294{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002295 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12002296 std::string msgString;
2297 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002298 ScopedUseGlsl useGlsl(false);
Chris Forbes3c10b852015-05-25 11:13:13 +12002299
2300 char const *vsSource =
2301 "#version 140\n"
2302 "#extension GL_ARB_separate_shader_objects: require\n"
2303 "#extension GL_ARB_shading_language_420pack: require\n"
2304 "\n"
2305 "void main(){\n"
2306 " gl_Position = vec4(1);\n"
2307 "}\n";
2308 char const *fsSource =
2309 "#version 140\n"
2310 "#extension GL_ARB_separate_shader_objects: require\n"
2311 "#extension GL_ARB_shading_language_420pack: require\n"
2312 "\n"
2313 "layout(location=0) in float x;\n"
2314 "layout(location=0) out vec4 color;\n"
2315 "void main(){\n"
2316 " color = vec4(x);\n"
2317 "}\n";
2318
2319 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2320 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2321
2322 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002323 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12002324 pipe.AddShader(&vs);
2325 pipe.AddShader(&fs);
2326
Chris Forbes3c10b852015-05-25 11:13:13 +12002327 VkDescriptorSetObj descriptorSet(m_device);
2328 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002329 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12002330
2331 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002332 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12002333
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002334 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12002335
Cody Northrop1684adb2015-08-05 11:15:02 -06002336 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes3c10b852015-05-25 11:13:13 +12002337 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
2338 FAIL() << "Incorrect error: " << msgString;
2339 }
2340}
2341
Chris Forbescc281692015-05-25 11:13:17 +12002342TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
2343{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002344 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12002345 std::string msgString;
2346 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002347 ScopedUseGlsl useGlsl(false);
Chris Forbescc281692015-05-25 11:13:17 +12002348
2349 char const *vsSource =
2350 "#version 140\n"
2351 "#extension GL_ARB_separate_shader_objects: require\n"
2352 "#extension GL_ARB_shading_language_420pack: require\n"
2353 "\n"
2354 "layout(location=0) out int x;\n"
2355 "void main(){\n"
2356 " x = 0;\n"
2357 " gl_Position = vec4(1);\n"
2358 "}\n";
2359 char const *fsSource =
2360 "#version 140\n"
2361 "#extension GL_ARB_separate_shader_objects: require\n"
2362 "#extension GL_ARB_shading_language_420pack: require\n"
2363 "\n"
2364 "layout(location=0) in float x;\n" /* VS writes int */
2365 "layout(location=0) out vec4 color;\n"
2366 "void main(){\n"
2367 " color = vec4(x);\n"
2368 "}\n";
2369
2370 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2371 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2372
2373 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002374 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12002375 pipe.AddShader(&vs);
2376 pipe.AddShader(&fs);
2377
Chris Forbescc281692015-05-25 11:13:17 +12002378 VkDescriptorSetObj descriptorSet(m_device);
2379 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002380 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12002381
2382 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002383 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12002384
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002385 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12002386
Cody Northrop1684adb2015-08-05 11:15:02 -06002387 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbescc281692015-05-25 11:13:17 +12002388 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
2389 FAIL() << "Incorrect error: " << msgString;
2390 }
2391}
2392
Chris Forbes8291c052015-05-25 11:13:28 +12002393TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
2394{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002395 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12002396 std::string msgString;
2397 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002398 ScopedUseGlsl useGlsl(false);
Chris Forbes8291c052015-05-25 11:13:28 +12002399
2400 VkVertexInputBindingDescription input_binding;
2401 memset(&input_binding, 0, sizeof(input_binding));
2402
2403 VkVertexInputAttributeDescription input_attrib;
2404 memset(&input_attrib, 0, sizeof(input_attrib));
2405 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2406
2407 char const *vsSource =
2408 "#version 140\n"
2409 "#extension GL_ARB_separate_shader_objects: require\n"
2410 "#extension GL_ARB_shading_language_420pack: require\n"
2411 "\n"
2412 "void main(){\n"
2413 " gl_Position = vec4(1);\n"
2414 "}\n";
2415 char const *fsSource =
2416 "#version 140\n"
2417 "#extension GL_ARB_separate_shader_objects: require\n"
2418 "#extension GL_ARB_shading_language_420pack: require\n"
2419 "\n"
2420 "layout(location=0) out vec4 color;\n"
2421 "void main(){\n"
2422 " color = vec4(1);\n"
2423 "}\n";
2424
2425 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2426 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2427
2428 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002429 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12002430 pipe.AddShader(&vs);
2431 pipe.AddShader(&fs);
2432
2433 pipe.AddVertexInputBindings(&input_binding, 1);
2434 pipe.AddVertexInputAttribs(&input_attrib, 1);
2435
Chris Forbes8291c052015-05-25 11:13:28 +12002436 VkDescriptorSetObj descriptorSet(m_device);
2437 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002438 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12002439
2440 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002441 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12002442
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002443 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12002444
Cody Northrop1684adb2015-08-05 11:15:02 -06002445 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12002446 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
2447 FAIL() << "Incorrect warning: " << msgString;
2448 }
2449}
2450
Chris Forbes37367e62015-05-25 11:13:29 +12002451TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
2452{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002453 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12002454 std::string msgString;
2455 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002456 ScopedUseGlsl useGlsl(false);
Chris Forbes37367e62015-05-25 11:13:29 +12002457
2458 char const *vsSource =
2459 "#version 140\n"
2460 "#extension GL_ARB_separate_shader_objects: require\n"
2461 "#extension GL_ARB_shading_language_420pack: require\n"
2462 "\n"
2463 "layout(location=0) in vec4 x;\n" /* not provided */
2464 "void main(){\n"
2465 " gl_Position = x;\n"
2466 "}\n";
2467 char const *fsSource =
2468 "#version 140\n"
2469 "#extension GL_ARB_separate_shader_objects: require\n"
2470 "#extension GL_ARB_shading_language_420pack: require\n"
2471 "\n"
2472 "layout(location=0) out vec4 color;\n"
2473 "void main(){\n"
2474 " color = vec4(1);\n"
2475 "}\n";
2476
2477 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2478 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2479
2480 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002481 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12002482 pipe.AddShader(&vs);
2483 pipe.AddShader(&fs);
2484
Chris Forbes37367e62015-05-25 11:13:29 +12002485 VkDescriptorSetObj descriptorSet(m_device);
2486 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002487 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12002488
2489 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002490 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12002491
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002492 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12002493
Cody Northrop1684adb2015-08-05 11:15:02 -06002494 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes37367e62015-05-25 11:13:29 +12002495 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
2496 FAIL() << "Incorrect warning: " << msgString;
2497 }
2498}
2499
Chris Forbesa4b02322015-05-25 11:13:31 +12002500TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
2501{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002502 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12002503 std::string msgString;
2504 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002505 ScopedUseGlsl useGlsl(false);
Chris Forbesa4b02322015-05-25 11:13:31 +12002506
2507 VkVertexInputBindingDescription input_binding;
2508 memset(&input_binding, 0, sizeof(input_binding));
2509
2510 VkVertexInputAttributeDescription input_attrib;
2511 memset(&input_attrib, 0, sizeof(input_attrib));
2512 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2513
2514 char const *vsSource =
2515 "#version 140\n"
2516 "#extension GL_ARB_separate_shader_objects: require\n"
2517 "#extension GL_ARB_shading_language_420pack: require\n"
2518 "\n"
2519 "layout(location=0) in int x;\n" /* attrib provided float */
2520 "void main(){\n"
2521 " gl_Position = vec4(x);\n"
2522 "}\n";
2523 char const *fsSource =
2524 "#version 140\n"
2525 "#extension GL_ARB_separate_shader_objects: require\n"
2526 "#extension GL_ARB_shading_language_420pack: require\n"
2527 "\n"
2528 "layout(location=0) out vec4 color;\n"
2529 "void main(){\n"
2530 " color = vec4(1);\n"
2531 "}\n";
2532
2533 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2534 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2535
2536 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002537 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12002538 pipe.AddShader(&vs);
2539 pipe.AddShader(&fs);
2540
2541 pipe.AddVertexInputBindings(&input_binding, 1);
2542 pipe.AddVertexInputAttribs(&input_attrib, 1);
2543
Chris Forbesa4b02322015-05-25 11:13:31 +12002544 VkDescriptorSetObj descriptorSet(m_device);
2545 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002546 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12002547
2548 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002549 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12002550
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002551 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12002552
Cody Northrop1684adb2015-08-05 11:15:02 -06002553 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa4b02322015-05-25 11:13:31 +12002554 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
2555 FAIL() << "Incorrect error: " << msgString;
2556 }
2557}
2558
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002559TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
2560{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002561 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002562 std::string msgString;
2563 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002564 ScopedUseGlsl useGlsl(false);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002565
2566 /* Two binding descriptions for binding 0 */
2567 VkVertexInputBindingDescription input_bindings[2];
2568 memset(input_bindings, 0, sizeof(input_bindings));
2569
2570 VkVertexInputAttributeDescription input_attrib;
2571 memset(&input_attrib, 0, sizeof(input_attrib));
2572 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2573
2574 char const *vsSource =
2575 "#version 140\n"
2576 "#extension GL_ARB_separate_shader_objects: require\n"
2577 "#extension GL_ARB_shading_language_420pack: require\n"
2578 "\n"
2579 "layout(location=0) in float x;\n" /* attrib provided float */
2580 "void main(){\n"
2581 " gl_Position = vec4(x);\n"
2582 "}\n";
2583 char const *fsSource =
2584 "#version 140\n"
2585 "#extension GL_ARB_separate_shader_objects: require\n"
2586 "#extension GL_ARB_shading_language_420pack: require\n"
2587 "\n"
2588 "layout(location=0) out vec4 color;\n"
2589 "void main(){\n"
2590 " color = vec4(1);\n"
2591 "}\n";
2592
2593 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2594 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2595
2596 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002597 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002598 pipe.AddShader(&vs);
2599 pipe.AddShader(&fs);
2600
2601 pipe.AddVertexInputBindings(input_bindings, 2);
2602 pipe.AddVertexInputAttribs(&input_attrib, 1);
2603
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002604 VkDescriptorSetObj descriptorSet(m_device);
2605 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002606 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002607
2608 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002609 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002610
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002611 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002612
Cody Northrop1684adb2015-08-05 11:15:02 -06002613 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002614 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
2615 FAIL() << "Incorrect error: " << msgString;
2616 }
2617}
Chris Forbes4c948702015-05-25 11:13:32 +12002618
Chris Forbesc12ef122015-05-25 11:13:40 +12002619/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
2620 * rejects it. */
2621
2622TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
2623{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002624 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12002625 std::string msgString;
2626 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002627 ScopedUseGlsl useGlsl(false);
Chris Forbesc12ef122015-05-25 11:13:40 +12002628
2629 char const *vsSource =
2630 "#version 140\n"
2631 "#extension GL_ARB_separate_shader_objects: require\n"
2632 "#extension GL_ARB_shading_language_420pack: require\n"
2633 "\n"
2634 "void main(){\n"
2635 " gl_Position = vec4(1);\n"
2636 "}\n";
2637 char const *fsSource =
2638 "#version 140\n"
2639 "#extension GL_ARB_separate_shader_objects: require\n"
2640 "#extension GL_ARB_shading_language_420pack: require\n"
2641 "\n"
2642 "void main(){\n"
2643 "}\n";
2644
2645 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2646 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2647
2648 VkPipelineObj pipe(m_device);
2649 pipe.AddShader(&vs);
2650 pipe.AddShader(&fs);
2651
Chia-I Wuc278df82015-07-07 11:50:03 +08002652 /* set up CB 0, not written */
2653 pipe.AddColorAttachment();
2654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12002655
Chris Forbesc12ef122015-05-25 11:13:40 +12002656 VkDescriptorSetObj descriptorSet(m_device);
2657 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002658 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12002659
2660 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002661 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12002662
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002663 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12002664
Cody Northrop1684adb2015-08-05 11:15:02 -06002665 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc12ef122015-05-25 11:13:40 +12002666 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
2667 FAIL() << "Incorrect error: " << msgString;
2668 }
2669}
2670
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002671TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
2672{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002673 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002674 std::string msgString;
2675 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002676 ScopedUseGlsl useGlsl(false);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002677
2678 char const *vsSource =
2679 "#version 140\n"
2680 "#extension GL_ARB_separate_shader_objects: require\n"
2681 "#extension GL_ARB_shading_language_420pack: require\n"
2682 "\n"
2683 "void main(){\n"
2684 " gl_Position = vec4(1);\n"
2685 "}\n";
2686 char const *fsSource =
2687 "#version 140\n"
2688 "#extension GL_ARB_separate_shader_objects: require\n"
2689 "#extension GL_ARB_shading_language_420pack: require\n"
2690 "\n"
2691 "layout(location=0) out vec4 x;\n"
2692 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
2693 "void main(){\n"
2694 " x = vec4(1);\n"
2695 " y = vec4(1);\n"
2696 "}\n";
2697
2698 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2699 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2700
2701 VkPipelineObj pipe(m_device);
2702 pipe.AddShader(&vs);
2703 pipe.AddShader(&fs);
2704
Chia-I Wuc278df82015-07-07 11:50:03 +08002705 /* set up CB 0, not written */
2706 pipe.AddColorAttachment();
2707 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002708 /* FS writes CB 1, but we don't configure it */
2709
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002710 VkDescriptorSetObj descriptorSet(m_device);
2711 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002712 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002713
2714 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002715 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002716
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002717 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002718
Cody Northrop1684adb2015-08-05 11:15:02 -06002719 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002720 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
2721 FAIL() << "Incorrect warning: " << msgString;
2722 }
2723}
2724
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002725TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
2726{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002727 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002728 std::string msgString;
2729 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002730 ScopedUseGlsl useGlsl(false);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002731
2732 char const *vsSource =
2733 "#version 140\n"
2734 "#extension GL_ARB_separate_shader_objects: require\n"
2735 "#extension GL_ARB_shading_language_420pack: require\n"
2736 "\n"
2737 "void main(){\n"
2738 " gl_Position = vec4(1);\n"
2739 "}\n";
2740 char const *fsSource =
2741 "#version 140\n"
2742 "#extension GL_ARB_separate_shader_objects: require\n"
2743 "#extension GL_ARB_shading_language_420pack: require\n"
2744 "\n"
2745 "layout(location=0) out ivec4 x;\n" /* not UNORM */
2746 "void main(){\n"
2747 " x = ivec4(1);\n"
2748 "}\n";
2749
2750 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2751 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2752
2753 VkPipelineObj pipe(m_device);
2754 pipe.AddShader(&vs);
2755 pipe.AddShader(&fs);
2756
Chia-I Wuc278df82015-07-07 11:50:03 +08002757 /* set up CB 0; type is UNORM by default */
2758 pipe.AddColorAttachment();
2759 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002760
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002761 VkDescriptorSetObj descriptorSet(m_device);
2762 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002763 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002764
2765 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002766 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002767
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002768 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002769
Cody Northrop1684adb2015-08-05 11:15:02 -06002770 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002771 if (!strstr(msgString.c_str(),"does not match FS output type")) {
2772 FAIL() << "Incorrect error: " << msgString;
2773 }
2774}
Chris Forbesc2050732015-06-05 14:43:36 +12002775
2776TEST_F(VkLayerTest, CreatePipelineNonSpirvShader)
2777{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002778 VkFlags msgFlags;
Chris Forbesc2050732015-06-05 14:43:36 +12002779 std::string msgString;
2780 ASSERT_NO_FATAL_FAILURE(InitState());
2781 /* Intentionally provided GLSL rather than compiling to SPIRV first */
Cody Northrop1cfbd172015-06-03 16:49:20 -06002782 ScopedUseGlsl useGlsl(true);
Chris Forbesc2050732015-06-05 14:43:36 +12002783
2784 char const *vsSource =
2785 "#version 140\n"
2786 "#extension GL_ARB_separate_shader_objects: require\n"
2787 "#extension GL_ARB_shading_language_420pack: require\n"
2788 "\n"
2789 "void main(){\n"
2790 " gl_Position = vec4(1);\n"
2791 "}\n";
2792 char const *fsSource =
2793 "#version 140\n"
2794 "#extension GL_ARB_separate_shader_objects: require\n"
2795 "#extension GL_ARB_shading_language_420pack: require\n"
2796 "\n"
2797 "layout(location=0) out vec4 x;\n"
2798 "void main(){\n"
2799 " x = vec4(1);\n"
2800 "}\n";
2801
2802 m_errorMonitor->ClearState();
2803
2804 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2805 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2806
2807
2808 VkPipelineObj pipe(m_device);
2809 pipe.AddShader(&vs);
2810 pipe.AddShader(&fs);
2811
Chia-I Wuc278df82015-07-07 11:50:03 +08002812 /* set up CB 0; type is UNORM by default */
2813 pipe.AddColorAttachment();
2814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc2050732015-06-05 14:43:36 +12002815
Chris Forbesc2050732015-06-05 14:43:36 +12002816 VkDescriptorSetObj descriptorSet(m_device);
2817 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002818 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc2050732015-06-05 14:43:36 +12002819
Tony Barboured132432015-08-04 16:23:11 -06002820 VkResult res = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc2050732015-06-05 14:43:36 +12002821 /* pipeline creation should have succeeded */
2822 ASSERT_EQ(VK_SUCCESS, res);
2823
2824 /* should have emitted a warning: the shader is not SPIRV, so we're
2825 * not going to be able to analyze it */
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002826 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002827 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesc2050732015-06-05 14:43:36 +12002828 if (!strstr(msgString.c_str(),"is not SPIR-V")) {
2829 FAIL() << "Incorrect warning: " << msgString;
2830 }
2831}
Chris Forbes01c9db72015-06-04 09:25:25 +12002832#endif
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002833
Tony Barbour30486ea2015-04-07 13:44:53 -06002834int main(int argc, char **argv) {
2835 int result;
2836
2837 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06002838 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06002839
2840 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
2841
2842 result = RUN_ALL_TESTS();
2843
Tony Barbour01999182015-04-09 12:58:51 -06002844 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06002845 return result;
2846}