blob: 4d78f0dfcbe2d7f0bef512abab155725ec9571a2 [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 Goeltzenleuchter0d6857f2015-09-04 13:52:24 -060065static VkBool32 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 Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600122static VkBool32 myDbgFunc(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600123 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);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600135 return true;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600136 }
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600137
138 return false;
Tony Barbour30486ea2015-04-07 13:44:53 -0600139}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500140
Tony Barbour01999182015-04-09 12:58:51 -0600141class VkLayerTest : public VkRenderFramework
Tony Barbour30486ea2015-04-07 13:44:53 -0600142{
143public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600144 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
145 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500146 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
147 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbour1490c912015-07-28 10:17:20 -0600148 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
149 { GenericDrawPreparation(m_cmdBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600150
Tony Barbour1490c912015-07-28 10:17:20 -0600151 /* Convenience functions that use built-in command buffer */
152 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_cmdBuffer); }
153 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_cmdBuffer); }
154 void Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
155 { m_cmdBuffer->Draw(firstVertex, vertexCount, firstInstance, instanceCount); }
156 void DrawIndexed(uint32_t firstVertex, uint32_t vertexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
157 { m_cmdBuffer->DrawIndexed(firstVertex, vertexCount, vertexOffset,firstInstance, instanceCount); }
158 void QueueCommandBuffer() { m_cmdBuffer->QueueCommandBuffer(); }
159 void QueueCommandBuffer(const VkFence& fence) { m_cmdBuffer->QueueCommandBuffer(fence); }
160 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
161 { m_cmdBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
162 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
163 { m_cmdBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600164protected:
Tony Barbour01999182015-04-09 12:58:51 -0600165 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600166
167 virtual void SetUp() {
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600168 std::vector<const char *> instance_layer_names;
169 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600170 std::vector<const char *> instance_extension_names;
171 std::vector<const char *> device_extension_names;
Tony Barbour950ebc02015-04-23 12:55:36 -0600172
Courtney Goeltzenleuchter846298c2015-07-30 11:32:46 -0600173 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600174 /*
175 * Since CreateDbgMsgCallback is an instance level extension call
176 * any extension / layer that utilizes that feature also needs
177 * to be enabled at create instance time.
178 */
Mike Stroyaned254572015-06-17 16:32:06 -0600179 // Use Threading layer first to protect others from ThreadCmdBufferCollision test
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600180 instance_layer_names.push_back("Threading");
181 instance_layer_names.push_back("ObjectTracker");
182 instance_layer_names.push_back("MemTracker");
183 instance_layer_names.push_back("DrawState");
184 instance_layer_names.push_back("ShaderChecker");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600185
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600186 device_layer_names.push_back("Threading");
187 device_layer_names.push_back("ObjectTracker");
188 device_layer_names.push_back("MemTracker");
189 device_layer_names.push_back("DrawState");
190 device_layer_names.push_back("ShaderChecker");
Tony Barbour30486ea2015-04-07 13:44:53 -0600191
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600192 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -0600193 this->app_info.pNext = NULL;
194 this->app_info.pAppName = "layer_tests";
195 this->app_info.appVersion = 1;
196 this->app_info.pEngineName = "unittest";
197 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600198 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -0600199
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600200 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600201 InitFramework(instance_layer_names, device_layer_names,
202 instance_extension_names, device_extension_names,
203 myDbgFunc, m_errorMonitor);
Tony Barbour30486ea2015-04-07 13:44:53 -0600204 }
205
206 virtual void TearDown() {
207 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600208 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600209 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600210 }
211};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500212
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600213VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600214{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600215 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600216
217 result = cmdBuffer.BeginCommandBuffer();
218
219 /*
220 * For render test all drawing happens in a single render pass
221 * on a single command buffer.
222 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200223 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wuc278df82015-07-07 11:50:03 +0800224 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour30486ea2015-04-07 13:44:53 -0600225 }
226
227 return result;
228}
229
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600230VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600231{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600232 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600233
Chris Forbesfe133ef2015-06-16 14:05:59 +1200234 if (renderPass()) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800235 cmdBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200236 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600237
238 result = cmdBuffer.EndCommandBuffer();
239
240 return result;
241}
242
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500243void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
244{
245 // Create identity matrix
246 int i;
247 struct vktriangle_vs_uniform data;
248
249 glm::mat4 Projection = glm::mat4(1.0f);
250 glm::mat4 View = glm::mat4(1.0f);
251 glm::mat4 Model = glm::mat4(1.0f);
252 glm::mat4 MVP = Projection * View * Model;
253 const int matrixSize = sizeof(MVP);
254 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
255
256 memcpy(&data.mvp, &MVP[0][0], matrixSize);
257
258 static const Vertex tri_data[] =
259 {
260 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
261 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
262 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
263 };
264
265 for (i=0; i<3; i++) {
266 data.position[i][0] = tri_data[i].posX;
267 data.position[i][1] = tri_data[i].posY;
268 data.position[i][2] = tri_data[i].posZ;
269 data.position[i][3] = tri_data[i].posW;
270 data.color[i][0] = tri_data[i].r;
271 data.color[i][1] = tri_data[i].g;
272 data.color[i][2] = tri_data[i].b;
273 data.color[i][3] = tri_data[i].a;
274 }
275
276 ASSERT_NO_FATAL_FAILURE(InitState());
277 ASSERT_NO_FATAL_FAILURE(InitViewport());
278
279 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
280
281 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
282 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
283
284 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800285 pipelineobj.AddColorAttachment();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500286 pipelineobj.AddShader(&vs);
287 pipelineobj.AddShader(&ps);
288
289 VkDescriptorSetObj descriptorSet(m_device);
290 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
291
292 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600293 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500294
Tony Barbour1490c912015-07-28 10:17:20 -0600295 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500296
297 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -0600298 Draw(0, 3, 0, 1);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500299
300 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600301 EndCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500302
Tony Barbour1490c912015-07-28 10:17:20 -0600303 QueueCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500304}
305
306void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
307{
308 if (m_depthStencil->Initialized()) {
309 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
310 } else {
311 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
312 }
313
314 cmdBuffer->PrepareAttachments();
Cody Northrope4bc6942015-08-26 10:01:32 -0600315 if ((failMask & BsoFailLineWidth) != BsoFailLineWidth) {
316 cmdBuffer->BindDynamicLineWidthState(m_stateLineWidth);
Cody Northropf5bd2252015-08-17 11:10:49 -0600317 }
Cody Northrope4bc6942015-08-26 10:01:32 -0600318 if ((failMask & BsoFailDepthBias) != BsoFailDepthBias) {
319 cmdBuffer->BindDynamicDepthBiasState(m_stateDepthBias);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500320 }
321 if ((failMask & BsoFailViewport) != BsoFailViewport) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600322 cmdBuffer->BindDynamicViewportState(m_stateViewport);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500323 }
Cody Northrope4bc6942015-08-26 10:01:32 -0600324 if ((failMask & BsoFailBlend) != BsoFailBlend) {
325 cmdBuffer->BindDynamicBlendState(m_stateBlend);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500326 }
Cody Northrope4bc6942015-08-26 10:01:32 -0600327 if ((failMask & BsoFailDepthBounds) != BsoFailDepthBounds) {
328 cmdBuffer->BindDynamicDepthBoundsState(m_stateDepthBounds);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500329 }
Cody Northrop2605cb02015-08-18 15:21:16 -0600330 if ((failMask & BsoFailStencil) != BsoFailStencil) {
331 cmdBuffer->BindDynamicStencilState(m_stateStencil);
332 }
333 // Make sure depthWriteEnable is set so that Depth fail test will work correctly
334 // Make sure stencilTestEnable is set so that Stencil fail test will work correctly
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600335 VkStencilOpState stencil = {};
336 stencil.stencilFailOp = VK_STENCIL_OP_KEEP;
337 stencil.stencilPassOp = VK_STENCIL_OP_KEEP;
338 stencil.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
339 stencil.stencilCompareOp = VK_COMPARE_OP_NEVER;
340
341 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
342 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
343 ds_ci.pNext = NULL;
344 ds_ci.depthTestEnable = VK_FALSE;
345 ds_ci.depthWriteEnable = VK_TRUE;
346 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
Cody Northrope4bc6942015-08-26 10:01:32 -0600347 ds_ci.depthBoundsTestEnable = VK_FALSE;
Cody Northrop2605cb02015-08-18 15:21:16 -0600348 ds_ci.stencilTestEnable = VK_TRUE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600349 ds_ci.front = stencil;
350 ds_ci.back = stencil;
351
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600352 pipelineobj.SetDepthStencil(&ds_ci);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500353 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Cody Northropccfa96d2015-08-27 10:20:35 -0600354 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
355 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500356 cmdBuffer->BindPipeline(pipelineobj);
357 cmdBuffer->BindDescriptorSet(descriptorSet);
358}
359
360// ********************************************************************************************************************
361// ********************************************************************************************************************
362// ********************************************************************************************************************
363// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600364#if MEM_TRACKER_TESTS
Mark Lobodzinski81078192015-05-19 10:28:29 -0500365TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
366{
367 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600368 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500369 std::string msgString;
370
371 VkFenceCreateInfo fenceInfo = {};
372 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
373 fenceInfo.pNext = NULL;
374 fenceInfo.flags = 0;
375
376 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barboure389b882015-07-20 13:00:10 -0600377
378 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
379 vk_testing::Buffer buffer;
380 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500381
Tony Barbour1490c912015-07-28 10:17:20 -0600382 BeginCommandBuffer();
383 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
384 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500385
386 testFence.init(*m_device, fenceInfo);
387
388 // Bypass framework since it does the waits automatically
389 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600390 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500391 ASSERT_VK_SUCCESS( err );
392
393 m_errorMonitor->ClearState();
394 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600395 vkResetCommandBuffer(m_cmdBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500396
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600397 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600398 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 -0500399 if (!strstr(msgString.c_str(),"Resetting CB")) {
400 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
401 }
402}
403
404TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion)
405{
406 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600407 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500408 std::string msgString;
409
410 VkFenceCreateInfo fenceInfo = {};
411 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
412 fenceInfo.pNext = NULL;
413 fenceInfo.flags = 0;
414
415 ASSERT_NO_FATAL_FAILURE(InitState());
416 ASSERT_NO_FATAL_FAILURE(InitViewport());
417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
418
Tony Barbour1490c912015-07-28 10:17:20 -0600419 BeginCommandBuffer();
420 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
421 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500422
423 testFence.init(*m_device, fenceInfo);
424
425 // Bypass framework since it does the waits automatically
426 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600427 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500428 ASSERT_VK_SUCCESS( err );
429
430 m_errorMonitor->ClearState();
431 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600432 BeginCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500433
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600434 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600435 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 -0500436 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
437 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
438 }
439}
440
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500441TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
442{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600443 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500444 std::string msgString;
445 VkResult err;
446
447 ASSERT_NO_FATAL_FAILURE(InitState());
448 m_errorMonitor->ClearState();
449
450 // Create an image, allocate memory, free it, and then try to bind it
451 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500452 VkDeviceMemory mem;
453 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500454
455 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
456 const int32_t tex_width = 32;
457 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500458
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600459 VkImageCreateInfo image_create_info = {};
460 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
461 image_create_info.pNext = NULL;
462 image_create_info.imageType = VK_IMAGE_TYPE_2D;
463 image_create_info.format = tex_format;
464 image_create_info.extent.width = tex_width;
465 image_create_info.extent.height = tex_height;
466 image_create_info.extent.depth = 1;
467 image_create_info.mipLevels = 1;
468 image_create_info.arraySize = 1;
469 image_create_info.samples = 1;
470 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
471 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
472 image_create_info.flags = 0;
473
474 VkMemoryAllocInfo mem_alloc = {};
475 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
476 mem_alloc.pNext = NULL;
477 mem_alloc.allocationSize = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500478 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600479 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500480
481 err = vkCreateImage(m_device->device(), &image_create_info, &image);
482 ASSERT_VK_SUCCESS(err);
483
Tony Barboure84a8d62015-07-10 14:10:27 -0600484 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500485 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500486 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500487 ASSERT_VK_SUCCESS(err);
488
Mark Lobodzinski23182612015-05-29 09:32:35 -0500489 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500490
Mike Stroyand72da752015-08-04 10:49:29 -0600491 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 -0600492 if(err != VK_SUCCESS) // If we can't find any unmappable memory this test doesn't make sense
493 return;
Mike Stroyand72da752015-08-04 10:49:29 -0600494
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500495 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500496 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500497 ASSERT_VK_SUCCESS(err);
498
499 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600500 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500501 ASSERT_VK_SUCCESS(err);
502
503 // Map memory as if to initialize the image
504 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500505 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500506
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600507 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600508 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 -0500509 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
510 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
511 }
512}
513
514TEST_F(VkLayerTest, BindInvalidMemory)
515{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600516 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500517 std::string msgString;
518 VkResult err;
519
520 ASSERT_NO_FATAL_FAILURE(InitState());
521 m_errorMonitor->ClearState();
522
523 // Create an image, allocate memory, free it, and then try to bind it
524 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500525 VkDeviceMemory mem;
526 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500527
528 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
529 const int32_t tex_width = 32;
530 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500531
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600532 VkImageCreateInfo image_create_info = {};
533 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
534 image_create_info.pNext = NULL;
535 image_create_info.imageType = VK_IMAGE_TYPE_2D;
536 image_create_info.format = tex_format;
537 image_create_info.extent.width = tex_width;
538 image_create_info.extent.height = tex_height;
539 image_create_info.extent.depth = 1;
540 image_create_info.mipLevels = 1;
541 image_create_info.arraySize = 1;
542 image_create_info.samples = 1;
543 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
544 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
545 image_create_info.flags = 0;
546
547 VkMemoryAllocInfo mem_alloc = {};
548 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
549 mem_alloc.pNext = NULL;
550 mem_alloc.allocationSize = 0;
551 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500552
553 err = vkCreateImage(m_device->device(), &image_create_info, &image);
554 ASSERT_VK_SUCCESS(err);
555
Tony Barboure84a8d62015-07-10 14:10:27 -0600556 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500557 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500558 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500559 ASSERT_VK_SUCCESS(err);
560
Mark Lobodzinski23182612015-05-29 09:32:35 -0500561 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500562
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800563 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600564 ASSERT_VK_SUCCESS(err);
565
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500566 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500567 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500568 ASSERT_VK_SUCCESS(err);
569
570 // Introduce validation failure, free memory before binding
Mark Lobodzinski23182612015-05-29 09:32:35 -0500571 vkFreeMemory(m_device->device(), mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500572 ASSERT_VK_SUCCESS(err);
573
574 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600575 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Cody Northrop87333892015-08-06 12:40:01 -0600576 // This may very well return an error.
577 (void)err;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500578
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600579 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600580 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 -0500581 if (!strstr(msgString.c_str(),"couldn't find info for mem obj")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500582 FAIL() << "Error received did not match expected error message from BindObjectMemory in MemTracker";
583 }
584}
585
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600586// TODO : Is this test still valid. Not sure it is with updates to memory binding model
587// Verify and delete the test of fix the check
588//TEST_F(VkLayerTest, FreeBoundMemory)
589//{
590// VkFlags msgFlags;
591// std::string msgString;
592// VkResult err;
593//
594// ASSERT_NO_FATAL_FAILURE(InitState());
595// m_errorMonitor->ClearState();
596//
597// // Create an image, allocate memory, free it, and then try to bind it
598// VkImage image;
599// VkDeviceMemory mem;
600// VkMemoryRequirements mem_reqs;
601//
602// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
603// const int32_t tex_width = 32;
604// const int32_t tex_height = 32;
605//
606// const VkImageCreateInfo image_create_info = {
607// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
608// .pNext = NULL,
609// .imageType = VK_IMAGE_TYPE_2D,
610// .format = tex_format,
611// .extent = { tex_width, tex_height, 1 },
612// .mipLevels = 1,
613// .arraySize = 1,
614// .samples = 1,
615// .tiling = VK_IMAGE_TILING_LINEAR,
616// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
617// .flags = 0,
618// };
619// VkMemoryAllocInfo mem_alloc = {
620// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
621// .pNext = NULL,
622// .allocationSize = 0,
623// .memoryTypeIndex = 0,
624// };
625//
626// err = vkCreateImage(m_device->device(), &image_create_info, &image);
627// ASSERT_VK_SUCCESS(err);
628//
629// err = vkGetImageMemoryRequirements(m_device->device(),
630// image,
631// &mem_reqs);
632// ASSERT_VK_SUCCESS(err);
633//
634// mem_alloc.allocationSize = mem_reqs.size;
635//
636// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
637// ASSERT_VK_SUCCESS(err);
638//
639// // allocate memory
640// err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
641// ASSERT_VK_SUCCESS(err);
642//
643// // Bind memory to Image object
644// err = vkBindImageMemory(m_device->device(), image, mem, 0);
645// ASSERT_VK_SUCCESS(err);
646//
647// // Introduce validation failure, free memory while still bound to object
648// vkFreeMemory(m_device->device(), mem);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600649// msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600650//
Cody Northrop1684adb2015-08-05 11:15:02 -0600651// 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 -0600652// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
653// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
654// }
655//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500656
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500657TEST_F(VkLayerTest, RebindMemory)
658{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600659 VkFlags msgFlags;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500660 std::string msgString;
661 VkResult err;
662
663 ASSERT_NO_FATAL_FAILURE(InitState());
664 m_errorMonitor->ClearState();
665
666 // Create an image, allocate memory, free it, and then try to bind it
667 VkImage image;
668 VkDeviceMemory mem1;
669 VkDeviceMemory mem2;
670 VkMemoryRequirements mem_reqs;
671
672 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
673 const int32_t tex_width = 32;
674 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500675
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600676 VkImageCreateInfo image_create_info = {};
677 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
678 image_create_info.pNext = NULL;
679 image_create_info.imageType = VK_IMAGE_TYPE_2D;
680 image_create_info.format = tex_format;
681 image_create_info.extent.width = tex_width;
682 image_create_info.extent.height = tex_height;
683 image_create_info.extent.depth = 1;
684 image_create_info.mipLevels = 1;
685 image_create_info.arraySize = 1;
686 image_create_info.samples = 1;
687 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
688 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
689 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500690
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600691 VkMemoryAllocInfo mem_alloc = {};
692 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
693 mem_alloc.pNext = NULL;
694 mem_alloc.allocationSize = 0;
695 mem_alloc.memoryTypeIndex = 0;
696
697 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
698 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500699 err = vkCreateImage(m_device->device(), &image_create_info, &image);
700 ASSERT_VK_SUCCESS(err);
701
Tony Barboure84a8d62015-07-10 14:10:27 -0600702 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500703 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500704 &mem_reqs);
705 ASSERT_VK_SUCCESS(err);
706
707 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800708 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600709 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500710
711 // allocate 2 memory objects
712 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
713 ASSERT_VK_SUCCESS(err);
714 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
715 ASSERT_VK_SUCCESS(err);
716
717 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600718 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500719 ASSERT_VK_SUCCESS(err);
720
721 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600722 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500723 ASSERT_VK_SUCCESS(err);
724
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600725 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600726 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 -0500727 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
728 FAIL() << "Error received did not match expected message when rebinding memory to an object";
729 }
730}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500731
732TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
733{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600734 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500735 std::string msgString;
736 VkResult err;
737
738 ASSERT_NO_FATAL_FAILURE(InitState());
739 m_errorMonitor->ClearState();
740
741 // Create an image object, allocate memory, destroy the object and then try to bind it
742 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500743 VkDeviceMemory mem;
744 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500745
746 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
747 const int32_t tex_width = 32;
748 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500749
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600750 VkImageCreateInfo image_create_info = {};
751 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
752 image_create_info.pNext = NULL;
753 image_create_info.imageType = VK_IMAGE_TYPE_2D;
754 image_create_info.format = tex_format;
755 image_create_info.extent.width = tex_width;
756 image_create_info.extent.height = tex_height;
757 image_create_info.extent.depth = 1;
758 image_create_info.mipLevels = 1;
759 image_create_info.arraySize = 1;
760 image_create_info.samples = 1;
761 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
762 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
763 image_create_info.flags = 0;
764
765 VkMemoryAllocInfo mem_alloc = {};
766 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
767 mem_alloc.pNext = NULL;
768 mem_alloc.allocationSize = 0;
769 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500770
771 err = vkCreateImage(m_device->device(), &image_create_info, &image);
772 ASSERT_VK_SUCCESS(err);
773
Tony Barboure84a8d62015-07-10 14:10:27 -0600774 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500775 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500776 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500777 ASSERT_VK_SUCCESS(err);
778
Mark Lobodzinski23182612015-05-29 09:32:35 -0500779 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800780 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600781 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500782
783 // Allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500784 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500785 ASSERT_VK_SUCCESS(err);
786
787 // Introduce validation failure, destroy Image object before binding
Tony Barboure84a8d62015-07-10 14:10:27 -0600788 vkDestroyImage(m_device->device(), image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500789 ASSERT_VK_SUCCESS(err);
790
Mike Stroyand72da752015-08-04 10:49:29 -0600791 // Now Try to bind memory to this destroyed object
Tony Barboure84a8d62015-07-10 14:10:27 -0600792 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mike Stroyand72da752015-08-04 10:49:29 -0600793 // This may very well return an error.
794 (void) err;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500795
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600796 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600797 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 -0500798 if (!strstr(msgString.c_str(),"that's not in global list")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500799 FAIL() << "Error received did not match expected error message from updateObjectBinding in MemTracker";
800 }
801}
802
Tony Barbour8508b8e2015-04-09 10:48:04 -0600803TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600804{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600805 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600806 VkFlags msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600807 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600808
809 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600810 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
811 fenceInfo.pNext = NULL;
812 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600813
Tony Barbour30486ea2015-04-07 13:44:53 -0600814 ASSERT_NO_FATAL_FAILURE(InitState());
815 ASSERT_NO_FATAL_FAILURE(InitViewport());
816 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
817
Tony Barbour1490c912015-07-28 10:17:20 -0600818 BeginCommandBuffer();
819 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
820 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600821
822 testFence.init(*m_device, fenceInfo);
823 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -0600824 QueueCommandBuffer(testFence.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600825 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600826 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 -0600827 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500828 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600829 }
830
831}
832
833TEST_F(VkLayerTest, ResetUnsignaledFence)
834{
835 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600836 VkFlags msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600837 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600838 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600839 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
840 fenceInfo.pNext = NULL;
841
Tony Barbour8508b8e2015-04-09 10:48:04 -0600842 ASSERT_NO_FATAL_FAILURE(InitState());
843 testFence.init(*m_device, fenceInfo);
844 m_errorMonitor->ClearState();
Chia-I Wua4992342015-07-03 11:45:55 +0800845 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600846 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600847 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600848 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 -0600849 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500850 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600851 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600852
853}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600854
Chia-I Wuc278df82015-07-07 11:50:03 +0800855/* TODO: Update for changes due to bug-14075 tiling across render passes */
856#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600857TEST_F(VkLayerTest, InvalidUsageBits)
858{
859 // Initiate Draw w/o a PSO bound
860 VkFlags msgFlags;
861 std::string msgString;
862
863 ASSERT_NO_FATAL_FAILURE(InitState());
864 m_errorMonitor->ClearState();
865 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600866 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600867
868 const VkExtent3D e3d = {
869 .width = 128,
870 .height = 128,
871 .depth = 1,
872 };
873 const VkImageCreateInfo ici = {
874 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
875 .pNext = NULL,
876 .imageType = VK_IMAGE_TYPE_2D,
877 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
878 .extent = e3d,
879 .mipLevels = 1,
880 .arraySize = 1,
881 .samples = 1,
882 .tiling = VK_IMAGE_TILING_LINEAR,
883 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_BIT
884 .flags = 0,
885 };
886
887 VkImage dsi;
888 vkCreateImage(m_device->device(), &ici, &dsi);
889 VkDepthStencilView dsv;
890 const VkDepthStencilViewCreateInfo dsvci = {
891 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
892 .pNext = NULL,
893 .image = dsi,
894 .mipLevel = 0,
895 .baseArraySlice = 0,
896 .arraySize = 1,
897 .flags = 0,
898 };
899 vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv);
900 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600901 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 -0600902 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
903 FAIL() << "Error received was not 'Invalid usage flag for image...'";
904 }
905}
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600906#endif
Chia-I Wuc278df82015-07-07 11:50:03 +0800907#endif
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600908#if OBJ_TRACKER_TESTS
Cody Northrope4bc6942015-08-26 10:01:32 -0600909TEST_F(VkLayerTest, LineWidthStateNotBound)
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500910{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600911 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500912 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600913 ASSERT_NO_FATAL_FAILURE(InitState());
914 m_errorMonitor->ClearState();
Cody Northrope4bc6942015-08-26 10:01:32 -0600915 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 -0500916
Cody Northrope4bc6942015-08-26 10:01:32 -0600917 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500918
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600919 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrope4bc6942015-08-26 10:01:32 -0600920 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Line Width State Object";
921 if (!strstr(msgString.c_str(),"Line width object not bound to this command buffer")) {
922 FAIL() << "Error received was not 'Line Width object not bound to this command buffer'";
Cody Northropf5bd2252015-08-17 11:10:49 -0600923 }
924}
925
Cody Northrope4bc6942015-08-26 10:01:32 -0600926TEST_F(VkLayerTest, DepthBiasStateNotBound)
Cody Northropf5bd2252015-08-17 11:10:49 -0600927{
928 VkFlags msgFlags;
929 std::string msgString;
930 ASSERT_NO_FATAL_FAILURE(InitState());
931 m_errorMonitor->ClearState();
Cody Northrope4bc6942015-08-26 10:01:32 -0600932 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 -0600933
Cody Northrope4bc6942015-08-26 10:01:32 -0600934 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Cody Northropf5bd2252015-08-17 11:10:49 -0600935
936 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrope4bc6942015-08-26 10:01:32 -0600937 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bias State Object";
938 if (!strstr(msgString.c_str(),"Depth bias object not bound to this command buffer")) {
939 FAIL() << "Error received was not 'Depth bias object not bound to this command buffer'";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500940 }
941}
942
943TEST_F(VkLayerTest, ViewportStateNotBound)
944{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600945 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500946 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600947 ASSERT_NO_FATAL_FAILURE(InitState());
948 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500949 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
950
951 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
952
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600953 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600954 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 -0500955 if (!strstr(msgString.c_str(),"Viewport object not bound to this command buffer")) {
956 FAIL() << "Error received was not 'Viewport object not bound to this command buffer'";
957 }
958}
959
Cody Northrope4bc6942015-08-26 10:01:32 -0600960TEST_F(VkLayerTest, BlendStateNotBound)
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500961{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600962 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500963 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600964 ASSERT_NO_FATAL_FAILURE(InitState());
965 m_errorMonitor->ClearState();
Cody Northrope4bc6942015-08-26 10:01:32 -0600966 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500967
Cody Northrope4bc6942015-08-26 10:01:32 -0600968 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500969
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600970 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrope4bc6942015-08-26 10:01:32 -0600971 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Blend State Object";
972 if (!strstr(msgString.c_str(),"Blend object not bound to this command buffer")) {
973 FAIL() << "Error received was not 'Blend object not bound to this command buffer'";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500974 }
975}
976
Cody Northrope4bc6942015-08-26 10:01:32 -0600977TEST_F(VkLayerTest, DepthBoundsStateNotBound)
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500978{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600979 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500980 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600981 ASSERT_NO_FATAL_FAILURE(InitState());
982 m_errorMonitor->ClearState();
Cody Northrope4bc6942015-08-26 10:01:32 -0600983 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 -0500984
Cody Northrope4bc6942015-08-26 10:01:32 -0600985 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500986
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600987 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrope4bc6942015-08-26 10:01:32 -0600988 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bounds State Object";
989 if (!strstr(msgString.c_str(),"Depth bounds object not bound to this command buffer")) {
990 FAIL() << "Error received was not 'Depth bounds object not bound to this command buffer'";
Cody Northrop2605cb02015-08-18 15:21:16 -0600991 }
992}
993
994TEST_F(VkLayerTest, StencilStateNotBound)
995{
996 VkFlags msgFlags;
997 std::string msgString;
998 ASSERT_NO_FATAL_FAILURE(InitState());
999 m_errorMonitor->ClearState();
1000 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil state object is not bound beforehand");
1001
1002 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencil);
1003
1004 msgFlags = m_errorMonitor->GetState(&msgString);
1005 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Stencil State Object";
1006 if (!strstr(msgString.c_str(),"Stencil object not bound to this command buffer")) {
1007 FAIL() << "Error received was not 'Stencil object not bound to this command buffer'";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05001008 }
Tony Barbourdb686622015-05-06 09:35:56 -06001009}
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001010#endif
1011#if DRAW_STATE_TESTS
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001012TEST_F(VkLayerTest, CmdBufferTwoSubmits)
1013{
1014 vk_testing::Fence testFence;
1015 VkFlags msgFlags;
1016 std::string msgString;
1017
1018 VkFenceCreateInfo fenceInfo = {};
1019 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1020 fenceInfo.pNext = NULL;
1021 fenceInfo.flags = 0;
1022
1023 ASSERT_NO_FATAL_FAILURE(InitState());
1024 ASSERT_NO_FATAL_FAILURE(InitViewport());
1025 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1026
1027 // We luck out b/c by default the framework creates CB w/ the VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set
1028 BeginCommandBuffer();
1029 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
1030 EndCommandBuffer();
1031
1032 testFence.init(*m_device, fenceInfo);
1033
1034 // Bypass framework since it does the waits automatically
1035 VkResult err = VK_SUCCESS;
1036 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
1037 ASSERT_VK_SUCCESS( err );
1038
1039 m_errorMonitor->ClearState();
1040 // Cause validation error by re-submitting cmd buffer that should only be submitted once
1041 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
1042 ASSERT_VK_SUCCESS( err );
1043
1044 msgFlags = m_errorMonitor->GetState(&msgString);
1045 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 -06001046 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 -06001047 FAIL() << "Error received was not 'CB (0xaddress) was created w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set...'";
1048 }
1049}
1050
1051
Tobin Ehlise4076782015-06-24 15:53:07 -06001052TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001053{
1054 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001055 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001056 std::string msgString;
1057
1058 ASSERT_NO_FATAL_FAILURE(InitState());
1059 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001060 BeginCommandBuffer();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001061 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Tony Barbour1490c912015-07-28 10:17:20 -06001062 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001063 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001064 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 -06001065 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
1066 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0xbaadb1be) without an active RenderPass'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001067 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001068}
1069
1070TEST_F(VkLayerTest, InvalidDescriptorPool)
1071{
1072 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1073 // The DS check for this is after driver has been called to validate DS internal data struct
1074 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001075/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001076 std::string msgString;
1077 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1078 vkResetDescriptorPool(device(), badPool);
1079
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001080 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001081 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 -06001082 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1083 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1084 }*/
1085}
1086
1087TEST_F(VkLayerTest, InvalidDescriptorSet)
1088{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001089 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1090 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001091 // Create a valid cmd buffer
1092 // call vkCmdBindDescriptorSets w/ false DS
1093}
1094
1095TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1096{
1097 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1098 // The DS check for this is after driver has been called to validate DS internal data struct
1099}
1100
1101TEST_F(VkLayerTest, InvalidPipeline)
1102{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001103 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1104 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001105 // Create a valid cmd buffer
1106 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -06001107// VkFlags msgFlags;
1108// std::string msgString;
1109//
1110// ASSERT_NO_FATAL_FAILURE(InitState());
1111// m_errorMonitor->ClearState();
1112// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001113// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001114// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1115// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1116// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001117// 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 -06001118// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1119// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1120// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001121}
1122
Tobin Ehlis254eca02015-06-25 15:46:59 -06001123TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001124{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001125 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001126 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001127 std::string msgString;
1128 VkResult err;
1129
1130 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001131 ASSERT_NO_FATAL_FAILURE(InitViewport());
1132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001133 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001134 VkDescriptorTypeCount ds_type_count = {};
1135 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1136 ds_type_count.count = 1;
1137
1138 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1139 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1140 ds_pool_ci.pNext = NULL;
1141 ds_pool_ci.count = 1;
1142 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001143
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001144 VkDescriptorPool ds_pool;
1145 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1146 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001147
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001148 VkDescriptorSetLayoutBinding dsl_binding = {};
1149 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1150 dsl_binding.arraySize = 1;
1151 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1152 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001153
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001154 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1155 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1156 ds_layout_ci.pNext = NULL;
1157 ds_layout_ci.count = 1;
1158 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001159 VkDescriptorSetLayout ds_layout;
1160 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1161 ASSERT_VK_SUCCESS(err);
1162
1163 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001164 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001165 ASSERT_VK_SUCCESS(err);
1166
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001167 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1168 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1169 pipeline_layout_ci.pNext = NULL;
1170 pipeline_layout_ci.descriptorSetCount = 1;
1171 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001172
1173 VkPipelineLayout pipeline_layout;
1174 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1175 ASSERT_VK_SUCCESS(err);
1176
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001177 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001178 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1179 // but add it to be able to run on more devices
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001180
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001181 VkPipelineObj pipe(m_device);
1182 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001183 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001184 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001185
1186 BeginCommandBuffer();
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001187 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbour1490c912015-07-28 10:17:20 -06001188 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001189
Tobin Ehlis254eca02015-06-25 15:46:59 -06001190 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001191 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 -06001192 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1193 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1194 }
1195}
1196
1197TEST_F(VkLayerTest, NoBeginCmdBuffer)
1198{
1199 VkFlags msgFlags;
1200 std::string msgString;
1201
1202 ASSERT_NO_FATAL_FAILURE(InitState());
1203 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001204 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001205 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1206 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1207 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001208 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 -06001209 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1210 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1211 }
1212}
1213
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001214TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1215{
1216 VkFlags msgFlags;
1217 std::string msgString;
1218
1219 ASSERT_NO_FATAL_FAILURE(InitState());
1220 m_errorMonitor->ClearState();
1221
1222 // Calls CreateCommandBuffer
1223 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1224
1225 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northrop10d8f982015-08-04 17:35:57 -06001226 VkCmdBufferBeginInfo cmd_buf_info = {};
1227 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1228 cmd_buf_info.pNext = NULL;
1229 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1230 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1231 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1232 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1233
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001234
1235 // The error should be caught by validation of the BeginCommandBuffer call
1236 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1237
1238 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001239 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 -06001240 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1241 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1242 }
1243}
1244
1245TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1246{
1247 VkFlags msgFlags;
1248 std::string msgString;
1249 VkResult err;
1250 VkCmdBuffer draw_cmd;
1251 VkCmdPool cmd_pool;
1252
1253 ASSERT_NO_FATAL_FAILURE(InitState());
1254 m_errorMonitor->ClearState();
1255
Cody Northrop10d8f982015-08-04 17:35:57 -06001256 VkCmdBufferCreateInfo cmd = {};
1257 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1258 cmd.pNext = NULL;
1259 cmd.cmdPool = m_cmdPool;
1260 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1261 cmd.flags = 0;
1262
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001263 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
1264 assert(!err);
1265
1266 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northrop10d8f982015-08-04 17:35:57 -06001267 VkCmdBufferBeginInfo cmd_buf_info = {};
1268 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1269 cmd_buf_info.pNext = NULL;
1270 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1271 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001272
1273 // The error should be caught by validation of the BeginCommandBuffer call
1274 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1275
1276 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001277 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 -06001278 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1279 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1280 }
1281}
1282
Tobin Ehlis254eca02015-06-25 15:46:59 -06001283TEST_F(VkLayerTest, InvalidPipelineCreateState)
1284{
1285 // Attempt to Create Gfx Pipeline w/o a VS
1286 VkFlags msgFlags;
1287 std::string msgString;
1288 VkResult err;
1289
1290 ASSERT_NO_FATAL_FAILURE(InitState());
1291 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001292
1293 VkDescriptorTypeCount ds_type_count = {};
1294 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1295 ds_type_count.count = 1;
1296
1297 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1298 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1299 ds_pool_ci.pNext = NULL;
1300 ds_pool_ci.count = 1;
1301 ds_pool_ci.pTypeCount = &ds_type_count;
1302
Tobin Ehlis254eca02015-06-25 15:46:59 -06001303 VkDescriptorPool ds_pool;
1304 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1305 ASSERT_VK_SUCCESS(err);
1306
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001307 VkDescriptorSetLayoutBinding dsl_binding = {};
1308 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1309 dsl_binding.arraySize = 1;
1310 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1311 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001312
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001313 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1314 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1315 ds_layout_ci.pNext = NULL;
1316 ds_layout_ci.count = 1;
1317 ds_layout_ci.pBinding = &dsl_binding;
1318
Tobin Ehlis254eca02015-06-25 15:46:59 -06001319 VkDescriptorSetLayout ds_layout;
1320 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1321 ASSERT_VK_SUCCESS(err);
1322
1323 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001324 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001325 ASSERT_VK_SUCCESS(err);
1326
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001327 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1328 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1329 pipeline_layout_ci.pNext = NULL;
1330 pipeline_layout_ci.descriptorSetCount = 1;
1331 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001332
1333 VkPipelineLayout pipeline_layout;
1334 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1335 ASSERT_VK_SUCCESS(err);
1336
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001337 VkGraphicsPipelineCreateInfo gp_ci = {};
1338 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1339 gp_ci.pNext = NULL;
1340 gp_ci.stageCount = 0;
1341 gp_ci.pStages = NULL;
1342 gp_ci.pVertexInputState = NULL;
1343 gp_ci.pInputAssemblyState = NULL;
1344 gp_ci.pTessellationState = NULL;
1345 gp_ci.pViewportState = NULL;
1346 gp_ci.pRasterState = NULL;
1347 gp_ci.pMultisampleState = NULL;
1348 gp_ci.pDepthStencilState = NULL;
1349 gp_ci.pColorBlendState = NULL;
1350 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1351 gp_ci.layout = pipeline_layout;
1352
1353 VkPipelineCacheCreateInfo pc_ci = {};
1354 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1355 pc_ci.pNext = NULL;
1356 pc_ci.initialSize = 0;
1357 pc_ci.initialData = 0;
1358 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001359
1360 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001361 VkPipelineCache pipelineCache;
1362
1363 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1364 ASSERT_VK_SUCCESS(err);
1365 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001366
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001367 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001368 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 -06001369 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1370 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1371 }
1372}
1373
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001374TEST_F(VkLayerTest, NullRenderPass)
1375{
1376 // Bind a NULL RenderPass
1377 VkFlags msgFlags;
1378 std::string msgString;
1379
1380 ASSERT_NO_FATAL_FAILURE(InitState());
1381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1382 m_errorMonitor->ClearState();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001383
Tony Barbour1490c912015-07-28 10:17:20 -06001384 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001385 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06001386 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001387
1388 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001389 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001390 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
1391 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
1392 }
1393}
1394
Tobin Ehlis254eca02015-06-25 15:46:59 -06001395TEST_F(VkLayerTest, RenderPassWithinRenderPass)
1396{
1397 // Bind a BeginRenderPass within an active RenderPass
1398 VkFlags msgFlags;
1399 std::string msgString;
1400
1401 ASSERT_NO_FATAL_FAILURE(InitState());
1402 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1403 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001404
Tony Barbour1490c912015-07-28 10:17:20 -06001405 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001406 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001407 VkRenderPassBeginInfo rp_begin = {};
1408 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
1409 rp_begin.pNext = NULL;
1410 rp_begin.renderPass = (VkRenderPass)0xc001d00d;
1411 rp_begin.framebuffer = 0;
1412
Tony Barbour1490c912015-07-28 10:17:20 -06001413 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001414
1415 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001416 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 -06001417 if (!strstr(msgString.c_str(),"Cannot call vkCmdBeginRenderPass() during an active RenderPass ")) {
1418 FAIL() << "Error received was not 'Cannot call vkCmdBeginRenderPass() during an active RenderPass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001419 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001420}
1421
1422TEST_F(VkLayerTest, InvalidDynamicStateObject)
1423{
1424 // Create a valid cmd buffer
1425 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001426 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1427 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001428}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06001429
Tobin Ehlise4076782015-06-24 15:53:07 -06001430TEST_F(VkLayerTest, VtxBufferNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001431{
1432 // Bind VBO out-of-bounds for given PSO
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001433 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001434 std::string msgString;
1435 VkResult err;
1436
1437 ASSERT_NO_FATAL_FAILURE(InitState());
1438 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001439
1440 VkDescriptorTypeCount ds_type_count = {};
1441 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1442 ds_type_count.count = 1;
1443
1444 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1445 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1446 ds_pool_ci.pNext = NULL;
1447 ds_pool_ci.count = 1;
1448 ds_pool_ci.pTypeCount = &ds_type_count;
1449
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001450 VkDescriptorPool ds_pool;
1451 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1452 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001453
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001454 VkDescriptorSetLayoutBinding dsl_binding = {};
1455 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1456 dsl_binding.arraySize = 1;
1457 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1458 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001459
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001460 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1461 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1462 ds_layout_ci.pNext = NULL;
1463 ds_layout_ci.count = 1;
1464 ds_layout_ci.pBinding = &dsl_binding;
1465
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001466 VkDescriptorSetLayout ds_layout;
1467 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1468 ASSERT_VK_SUCCESS(err);
1469
1470 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001471 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001472 ASSERT_VK_SUCCESS(err);
1473
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001474 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1475 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1476 pipeline_layout_ci.pNext = NULL;
1477 pipeline_layout_ci.descriptorSetCount = 1;
1478 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001479
1480 VkPipelineLayout pipeline_layout;
1481 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1482 ASSERT_VK_SUCCESS(err);
1483
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001484 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001485 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1486 // but add it to be able to run on more devices
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001487 VkPipelineObj pipe(m_device);
1488 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001489 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001490 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001491
Tony Barbour1490c912015-07-28 10:17:20 -06001492 BeginCommandBuffer();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001493 ASSERT_VK_SUCCESS(err);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001494 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001495 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06001496 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001497
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001498 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001499 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 -06001500 if (!strstr(msgString.c_str(),"Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.")) {
1501 FAIL() << "Error received was not 'Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001502 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001503}
1504
1505TEST_F(VkLayerTest, DSTypeMismatch)
1506{
1507 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001508 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001509 std::string msgString;
1510 VkResult err;
1511
1512 ASSERT_NO_FATAL_FAILURE(InitState());
1513 m_errorMonitor->ClearState();
1514 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001515 VkDescriptorTypeCount ds_type_count = {};
1516 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1517 ds_type_count.count = 1;
1518
1519 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1520 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1521 ds_pool_ci.pNext = NULL;
1522 ds_pool_ci.count = 1;
1523 ds_pool_ci.pTypeCount = &ds_type_count;
1524
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001525 VkDescriptorPool ds_pool;
1526 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1527 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001528 VkDescriptorSetLayoutBinding dsl_binding = {};
1529 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1530 dsl_binding.arraySize = 1;
1531 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1532 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001533
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001534 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1535 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1536 ds_layout_ci.pNext = NULL;
1537 ds_layout_ci.count = 1;
1538 ds_layout_ci.pBinding = &dsl_binding;
1539
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001540 VkDescriptorSetLayout ds_layout;
1541 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1542 ASSERT_VK_SUCCESS(err);
1543
1544 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001545 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001546 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001547
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001548 VkSamplerCreateInfo sampler_ci = {};
1549 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1550 sampler_ci.pNext = NULL;
1551 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1552 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1553 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06001554 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
1555 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
1556 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001557 sampler_ci.mipLodBias = 1.0;
1558 sampler_ci.maxAnisotropy = 1;
1559 sampler_ci.compareEnable = VK_FALSE;
1560 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1561 sampler_ci.minLod = 1.0;
1562 sampler_ci.maxLod = 1.0;
1563 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06001564 sampler_ci.unnormalizedCoordinates = VK_FALSE;
1565
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001566 VkSampler sampler;
1567 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1568 ASSERT_VK_SUCCESS(err);
1569
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001570 VkDescriptorInfo descriptor_info;
1571 memset(&descriptor_info, 0, sizeof(descriptor_info));
1572 descriptor_info.sampler = sampler;
1573
1574 VkWriteDescriptorSet descriptor_write;
1575 memset(&descriptor_write, 0, sizeof(descriptor_write));
1576 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1577 descriptor_write.destSet = descriptorSet;
1578 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001579 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001580 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1581 descriptor_write.pDescriptors = &descriptor_info;
1582
1583 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1584
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001585 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001586 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 +08001587 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) {
1588 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 -06001589 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001590}
1591
1592TEST_F(VkLayerTest, DSUpdateOutOfBounds)
1593{
1594 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001595 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001596 std::string msgString;
1597 VkResult err;
1598
1599 ASSERT_NO_FATAL_FAILURE(InitState());
1600 m_errorMonitor->ClearState();
1601 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001602 VkDescriptorTypeCount ds_type_count = {};
1603 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1604 ds_type_count.count = 1;
1605
1606 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1607 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1608 ds_pool_ci.pNext = NULL;
1609 ds_pool_ci.count = 1;
1610 ds_pool_ci.pTypeCount = &ds_type_count;
1611
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001612 VkDescriptorPool ds_pool;
1613 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1614 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001615
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001616 VkDescriptorSetLayoutBinding dsl_binding = {};
1617 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1618 dsl_binding.arraySize = 1;
1619 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1620 dsl_binding.pImmutableSamplers = NULL;
1621
1622 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1623 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1624 ds_layout_ci.pNext = NULL;
1625 ds_layout_ci.count = 1;
1626 ds_layout_ci.pBinding = &dsl_binding;
1627
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001628 VkDescriptorSetLayout ds_layout;
1629 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1630 ASSERT_VK_SUCCESS(err);
1631
1632 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001633 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001634 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001635
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001636 VkSamplerCreateInfo sampler_ci = {};
1637 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1638 sampler_ci.pNext = NULL;
1639 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1640 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1641 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06001642 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
1643 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
1644 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001645 sampler_ci.mipLodBias = 1.0;
1646 sampler_ci.maxAnisotropy = 1;
1647 sampler_ci.compareEnable = VK_FALSE;
1648 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1649 sampler_ci.minLod = 1.0;
1650 sampler_ci.maxLod = 1.0;
1651 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06001652 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001653
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001654 VkSampler sampler;
1655 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1656 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001657
1658 VkDescriptorInfo descriptor_info;
1659 memset(&descriptor_info, 0, sizeof(descriptor_info));
1660 descriptor_info.sampler = sampler;
1661
1662 VkWriteDescriptorSet descriptor_write;
1663 memset(&descriptor_write, 0, sizeof(descriptor_write));
1664 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1665 descriptor_write.destSet = descriptorSet;
1666 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
1667 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001668 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001669 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1670 descriptor_write.pDescriptors = &descriptor_info;
1671
1672 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1673
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001674 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001675 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 +08001676 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
1677 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 -06001678 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001679}
1680
1681TEST_F(VkLayerTest, InvalidDSUpdateIndex)
1682{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001683 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001684 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001685 std::string msgString;
1686 VkResult err;
1687
1688 ASSERT_NO_FATAL_FAILURE(InitState());
1689 m_errorMonitor->ClearState();
1690 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001691 VkDescriptorTypeCount ds_type_count = {};
1692 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1693 ds_type_count.count = 1;
1694
1695 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1696 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1697 ds_pool_ci.pNext = NULL;
1698 ds_pool_ci.count = 1;
1699 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001700 VkDescriptorPool ds_pool;
1701 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1702 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001703
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001704 VkDescriptorSetLayoutBinding dsl_binding = {};
1705 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1706 dsl_binding.arraySize = 1;
1707 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1708 dsl_binding.pImmutableSamplers = NULL;
1709
1710 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1711 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1712 ds_layout_ci.pNext = NULL;
1713 ds_layout_ci.count = 1;
1714 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001715 VkDescriptorSetLayout ds_layout;
1716 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1717 ASSERT_VK_SUCCESS(err);
1718
1719 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001720 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001721 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001722
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001723 VkSamplerCreateInfo sampler_ci = {};
1724 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1725 sampler_ci.pNext = NULL;
1726 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1727 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1728 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06001729 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
1730 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
1731 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001732 sampler_ci.mipLodBias = 1.0;
1733 sampler_ci.maxAnisotropy = 1;
1734 sampler_ci.compareEnable = VK_FALSE;
1735 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1736 sampler_ci.minLod = 1.0;
1737 sampler_ci.maxLod = 1.0;
1738 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06001739 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001740
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001741 VkSampler sampler;
1742 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1743 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001744
1745 VkDescriptorInfo descriptor_info;
1746 memset(&descriptor_info, 0, sizeof(descriptor_info));
1747 descriptor_info.sampler = sampler;
1748
1749 VkWriteDescriptorSet descriptor_write;
1750 memset(&descriptor_write, 0, sizeof(descriptor_write));
1751 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1752 descriptor_write.destSet = descriptorSet;
1753 descriptor_write.destBinding = 2;
1754 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001755 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001756 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1757 descriptor_write.pDescriptors = &descriptor_info;
1758
1759 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1760
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001761 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001762 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 -06001763 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
1764 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
1765 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001766}
1767
1768TEST_F(VkLayerTest, InvalidDSUpdateStruct)
1769{
1770 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001771 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001772 std::string msgString;
1773 VkResult err;
1774
1775 ASSERT_NO_FATAL_FAILURE(InitState());
1776 m_errorMonitor->ClearState();
1777 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001778
1779 VkDescriptorTypeCount ds_type_count = {};
1780 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1781 ds_type_count.count = 1;
1782
1783 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1784 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1785 ds_pool_ci.pNext = NULL;
1786 ds_pool_ci.count = 1;
1787 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001788 VkDescriptorPool ds_pool;
1789 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1790 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001791 VkDescriptorSetLayoutBinding dsl_binding = {};
1792 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1793 dsl_binding.arraySize = 1;
1794 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1795 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001796
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001797 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1798 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1799 ds_layout_ci.pNext = NULL;
1800 ds_layout_ci.count = 1;
1801 ds_layout_ci.pBinding = &dsl_binding;
1802
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001803 VkDescriptorSetLayout ds_layout;
1804 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1805 ASSERT_VK_SUCCESS(err);
1806
1807 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001808 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001809 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001810
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001811 VkSamplerCreateInfo sampler_ci = {};
1812 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1813 sampler_ci.pNext = NULL;
1814 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1815 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1816 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06001817 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
1818 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
1819 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001820 sampler_ci.mipLodBias = 1.0;
1821 sampler_ci.maxAnisotropy = 1;
1822 sampler_ci.compareEnable = VK_FALSE;
1823 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1824 sampler_ci.minLod = 1.0;
1825 sampler_ci.maxLod = 1.0;
1826 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06001827 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001828 VkSampler sampler;
1829 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1830 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001831
1832
1833 VkDescriptorInfo descriptor_info;
1834 memset(&descriptor_info, 0, sizeof(descriptor_info));
1835 descriptor_info.sampler = sampler;
1836
1837 VkWriteDescriptorSet descriptor_write;
1838 memset(&descriptor_write, 0, sizeof(descriptor_write));
1839 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
1840 descriptor_write.destSet = descriptorSet;
1841 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001842 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001843 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1844 descriptor_write.pDescriptors = &descriptor_info;
1845
1846 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1847
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001848 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001849 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 -06001850 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
1851 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
1852 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001853}
1854
1855TEST_F(VkLayerTest, NumSamplesMismatch)
1856{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001857 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001858 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001859 std::string msgString;
1860 VkResult err;
1861
1862 ASSERT_NO_FATAL_FAILURE(InitState());
1863 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1864 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001865 VkDescriptorTypeCount ds_type_count = {};
1866 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1867 ds_type_count.count = 1;
1868
1869 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1870 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1871 ds_pool_ci.pNext = NULL;
1872 ds_pool_ci.count = 1;
1873 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001874 VkDescriptorPool ds_pool;
1875 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1876 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001877
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001878 VkDescriptorSetLayoutBinding dsl_binding = {};
1879 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1880 dsl_binding.arraySize = 1;
1881 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1882 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001883
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001884 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1885 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1886 ds_layout_ci.pNext = NULL;
1887 ds_layout_ci.count = 1;
1888 ds_layout_ci.pBinding = &dsl_binding;
1889
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001890 VkDescriptorSetLayout ds_layout;
1891 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1892 ASSERT_VK_SUCCESS(err);
1893
1894 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001895 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001896 ASSERT_VK_SUCCESS(err);
1897
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001898 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1899 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1900 pipe_ms_state_ci.pNext = NULL;
1901 pipe_ms_state_ci.rasterSamples = 4;
1902 pipe_ms_state_ci.sampleShadingEnable = 0;
1903 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06001904 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001905
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001906 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1907 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1908 pipeline_layout_ci.pNext = NULL;
1909 pipeline_layout_ci.descriptorSetCount = 1;
1910 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001911
1912 VkPipelineLayout pipeline_layout;
1913 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1914 ASSERT_VK_SUCCESS(err);
1915
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001916 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001917 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1918 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06001919 VkPipelineObj pipe(m_device);
1920 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001921 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06001922 pipe.SetMSAA(&pipe_ms_state_ci);
1923 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001924
Tony Barbour1490c912015-07-28 10:17:20 -06001925 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06001926 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001927
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001928 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001929 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 -06001930 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
1931 FAIL() << "Error received was not 'Num samples mismatch!...'";
1932 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001933}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001934
Tobin Ehlise4076782015-06-24 15:53:07 -06001935TEST_F(VkLayerTest, PipelineNotBound)
1936{
1937 VkFlags msgFlags;
1938 std::string msgString;
1939 VkResult err;
1940
1941 ASSERT_NO_FATAL_FAILURE(InitState());
1942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1943 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001944
1945 VkDescriptorTypeCount ds_type_count = {};
1946 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1947 ds_type_count.count = 1;
1948
1949 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1950 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1951 ds_pool_ci.pNext = NULL;
1952 ds_pool_ci.count = 1;
1953 ds_pool_ci.pTypeCount = &ds_type_count;
1954
Tobin Ehlise4076782015-06-24 15:53:07 -06001955 VkDescriptorPool ds_pool;
1956 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1957 ASSERT_VK_SUCCESS(err);
1958
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001959 VkDescriptorSetLayoutBinding dsl_binding = {};
1960 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1961 dsl_binding.arraySize = 1;
1962 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1963 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06001964
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001965 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1966 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1967 ds_layout_ci.pNext = NULL;
1968 ds_layout_ci.count = 1;
1969 ds_layout_ci.pBinding = &dsl_binding;
1970
Tobin Ehlise4076782015-06-24 15:53:07 -06001971 VkDescriptorSetLayout ds_layout;
1972 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1973 ASSERT_VK_SUCCESS(err);
1974
1975 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001976 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06001977 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001978
1979 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1980 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1981 pipeline_layout_ci.pNext = NULL;
1982 pipeline_layout_ci.descriptorSetCount = 1;
1983 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06001984
1985 VkPipelineLayout pipeline_layout;
1986 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1987 ASSERT_VK_SUCCESS(err);
1988
Tobin Ehlise4076782015-06-24 15:53:07 -06001989 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Tony Barbour1490c912015-07-28 10:17:20 -06001990
1991 BeginCommandBuffer();
1992 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06001993
1994 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001995 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 -06001996 if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1997 FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1998 }
1999}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002000
2001TEST_F(VkLayerTest, ClearCmdNoDraw)
2002{
2003 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
2004 VkFlags msgFlags;
2005 std::string msgString;
2006 VkResult err;
2007
2008 ASSERT_NO_FATAL_FAILURE(InitState());
2009 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2010 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002011
2012 VkDescriptorTypeCount ds_type_count = {};
2013 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2014 ds_type_count.count = 1;
2015
2016 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2017 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2018 ds_pool_ci.pNext = NULL;
2019 ds_pool_ci.count = 1;
2020 ds_pool_ci.pTypeCount = &ds_type_count;
2021
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002022 VkDescriptorPool ds_pool;
2023 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
2024 ASSERT_VK_SUCCESS(err);
2025
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002026 VkDescriptorSetLayoutBinding dsl_binding = {};
2027 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2028 dsl_binding.arraySize = 1;
2029 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2030 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002031
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002032 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2033 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2034 ds_layout_ci.pNext = NULL;
2035 ds_layout_ci.count = 1;
2036 ds_layout_ci.pBinding = &dsl_binding;
2037
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002038 VkDescriptorSetLayout ds_layout;
2039 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2040 ASSERT_VK_SUCCESS(err);
2041
2042 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002043 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002044 ASSERT_VK_SUCCESS(err);
2045
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002046 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2047 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2048 pipe_ms_state_ci.pNext = NULL;
2049 pipe_ms_state_ci.rasterSamples = 4;
2050 pipe_ms_state_ci.sampleShadingEnable = 0;
2051 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002052 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002053
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002054 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2055 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2056 pipeline_layout_ci.pNext = NULL;
2057 pipeline_layout_ci.descriptorSetCount = 1;
2058 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002059
2060 VkPipelineLayout pipeline_layout;
2061 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2062 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002063
Tony Barbourd7d828b2015-08-06 10:16:07 -06002064 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002065 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2066 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002067 VkPipelineObj pipe(m_device);
2068 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002069 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002070 pipe.SetMSAA(&pipe_ms_state_ci);
2071 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002072
2073 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002074
2075 m_errorMonitor->ClearState();
2076 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
2077 // Also pass down other dummy params to keep driver and paramchecker happy
2078 VkClearColorValue cCV;
Cody Northrop2563a032015-08-25 15:26:38 -06002079 cCV.float32[0] = 1.0;
2080 cCV.float32[1] = 1.0;
2081 cCV.float32[2] = 1.0;
2082 cCV.float32[3] = 1.0;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002083
Tony Barbour1490c912015-07-28 10:17:20 -06002084 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002085 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002086 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 -06002087 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) {
2088 FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'";
2089 }
2090}
2091
Tobin Ehlise4076782015-06-24 15:53:07 -06002092TEST_F(VkLayerTest, VtxBufferBadIndex)
2093{
2094 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
2095 VkFlags msgFlags;
2096 std::string msgString;
2097 VkResult err;
2098
2099 ASSERT_NO_FATAL_FAILURE(InitState());
2100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2101 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002102
2103 VkDescriptorTypeCount ds_type_count = {};
2104 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2105 ds_type_count.count = 1;
2106
2107 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2108 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2109 ds_pool_ci.pNext = NULL;
2110 ds_pool_ci.count = 1;
2111 ds_pool_ci.pTypeCount = &ds_type_count;
2112
2113 VkDescriptorPool ds_pool;
Tobin Ehlise4076782015-06-24 15:53:07 -06002114 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
2115 ASSERT_VK_SUCCESS(err);
2116
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002117 VkDescriptorSetLayoutBinding dsl_binding = {};
2118 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2119 dsl_binding.arraySize = 1;
2120 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2121 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002122
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002123 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2124 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2125 ds_layout_ci.pNext = NULL;
2126 ds_layout_ci.count = 1;
2127 ds_layout_ci.pBinding = &dsl_binding;
2128
Tobin Ehlise4076782015-06-24 15:53:07 -06002129 VkDescriptorSetLayout ds_layout;
2130 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2131 ASSERT_VK_SUCCESS(err);
2132
2133 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002134 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06002135 ASSERT_VK_SUCCESS(err);
2136
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002137 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2138 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2139 pipe_ms_state_ci.pNext = NULL;
2140 pipe_ms_state_ci.rasterSamples = 1;
2141 pipe_ms_state_ci.sampleShadingEnable = 0;
2142 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002143 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002144
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002145 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2146 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2147 pipeline_layout_ci.pNext = NULL;
2148 pipeline_layout_ci.descriptorSetCount = 1;
2149 pipeline_layout_ci.pSetLayouts = &ds_layout;
2150 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06002151
Tobin Ehlise4076782015-06-24 15:53:07 -06002152 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2153 ASSERT_VK_SUCCESS(err);
2154
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002155 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002156 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2157 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002158 VkPipelineObj pipe(m_device);
2159 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002160 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002161 pipe.SetMSAA(&pipe_ms_state_ci);
2162 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002163
2164 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06002165 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002166 // Don't care about actual data, just need to get to draw to flag error
2167 static const float vbo_data[3] = {1.f, 0.f, 1.f};
2168 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
2169 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
2170 Draw(0, 1, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06002171
2172 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002173 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding Vtx Buffer w/o VBO attached to PSO.";
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002174 if (!strstr(msgString.c_str(),"Vtx Buffer Index 1 was bound, but no vtx buffers are attached to PSO.")) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002175 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
2176 }
2177}
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002178#endif
2179#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06002180#if GTEST_IS_THREADSAFE
2181struct thread_data_struct {
2182 VkCmdBuffer cmdBuffer;
2183 VkEvent event;
2184 bool bailout;
2185};
2186
2187extern "C" void *AddToCommandBuffer(void *arg)
2188{
2189 struct thread_data_struct *data = (struct thread_data_struct *) arg;
2190 std::string msgString;
2191
2192 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06002193 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06002194 if (data->bailout) {
2195 break;
2196 }
2197 }
2198 return NULL;
2199}
2200
2201TEST_F(VkLayerTest, ThreadCmdBufferCollision)
2202{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002203 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06002204 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002205 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06002206
2207 ASSERT_NO_FATAL_FAILURE(InitState());
2208 ASSERT_NO_FATAL_FAILURE(InitViewport());
2209 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2210
Mike Stroyan09aae812015-05-12 16:00:45 -06002211 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06002212 BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002213
2214 VkEventCreateInfo event_info;
2215 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06002216 VkResult err;
2217
2218 memset(&event_info, 0, sizeof(event_info));
2219 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2220
2221 err = vkCreateEvent(device(), &event_info, &event);
2222 ASSERT_VK_SUCCESS(err);
2223
Mike Stroyan09aae812015-05-12 16:00:45 -06002224 err = vkResetEvent(device(), event);
2225 ASSERT_VK_SUCCESS(err);
2226
2227 struct thread_data_struct data;
Tony Barbour1490c912015-07-28 10:17:20 -06002228 data.cmdBuffer = m_cmdBuffer->handle();
Mike Stroyan09aae812015-05-12 16:00:45 -06002229 data.event = event;
2230 data.bailout = false;
2231 m_errorMonitor->SetBailout(&data.bailout);
2232 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002233 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06002234 // Add many entries to command buffer from this thread at the same time.
2235 AddToCommandBuffer(&data);
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002236 test_platform_thread_join(thread, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -06002237 EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002238
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002239 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002240 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 -06002241 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05002242 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06002243 }
2244
2245}
2246#endif
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002247#endif
Chris Forbes5af3bf22015-05-25 11:13:08 +12002248#if SHADER_CHECKER_TESTS
2249TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
2250{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002251 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12002252 std::string msgString;
2253 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002254 ScopedUseGlsl useGlsl(false);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002255
2256 char const *vsSource =
2257 "#version 140\n"
2258 "#extension GL_ARB_separate_shader_objects: require\n"
2259 "#extension GL_ARB_shading_language_420pack: require\n"
2260 "\n"
2261 "layout(location=0) out float x;\n"
2262 "void main(){\n"
2263 " gl_Position = vec4(1);\n"
2264 " x = 0;\n"
2265 "}\n";
2266 char const *fsSource =
2267 "#version 140\n"
2268 "#extension GL_ARB_separate_shader_objects: require\n"
2269 "#extension GL_ARB_shading_language_420pack: require\n"
2270 "\n"
2271 "layout(location=0) out vec4 color;\n"
2272 "void main(){\n"
2273 " color = vec4(1);\n"
2274 "}\n";
2275
2276 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2277 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2278
2279 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002280 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12002281 pipe.AddShader(&vs);
2282 pipe.AddShader(&fs);
2283
Chris Forbes5af3bf22015-05-25 11:13:08 +12002284 VkDescriptorSetObj descriptorSet(m_device);
2285 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002286 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002287
2288 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002289 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12002290
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002291 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002292
Cody Northrop1684adb2015-08-05 11:15:02 -06002293 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002294 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
2295 FAIL() << "Incorrect warning: " << msgString;
2296 }
2297}
Chris Forbes5af3bf22015-05-25 11:13:08 +12002298
Chris Forbes3c10b852015-05-25 11:13:13 +12002299TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
2300{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002301 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12002302 std::string msgString;
2303 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002304 ScopedUseGlsl useGlsl(false);
Chris Forbes3c10b852015-05-25 11:13:13 +12002305
2306 char const *vsSource =
2307 "#version 140\n"
2308 "#extension GL_ARB_separate_shader_objects: require\n"
2309 "#extension GL_ARB_shading_language_420pack: require\n"
2310 "\n"
2311 "void main(){\n"
2312 " gl_Position = vec4(1);\n"
2313 "}\n";
2314 char const *fsSource =
2315 "#version 140\n"
2316 "#extension GL_ARB_separate_shader_objects: require\n"
2317 "#extension GL_ARB_shading_language_420pack: require\n"
2318 "\n"
2319 "layout(location=0) in float x;\n"
2320 "layout(location=0) out vec4 color;\n"
2321 "void main(){\n"
2322 " color = vec4(x);\n"
2323 "}\n";
2324
2325 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2326 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2327
2328 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002329 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12002330 pipe.AddShader(&vs);
2331 pipe.AddShader(&fs);
2332
Chris Forbes3c10b852015-05-25 11:13:13 +12002333 VkDescriptorSetObj descriptorSet(m_device);
2334 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002335 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12002336
2337 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002338 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12002339
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002340 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12002341
Cody Northrop1684adb2015-08-05 11:15:02 -06002342 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes3c10b852015-05-25 11:13:13 +12002343 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
2344 FAIL() << "Incorrect error: " << msgString;
2345 }
2346}
2347
Chris Forbescc281692015-05-25 11:13:17 +12002348TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
2349{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002350 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12002351 std::string msgString;
2352 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002353 ScopedUseGlsl useGlsl(false);
Chris Forbescc281692015-05-25 11:13:17 +12002354
2355 char const *vsSource =
2356 "#version 140\n"
2357 "#extension GL_ARB_separate_shader_objects: require\n"
2358 "#extension GL_ARB_shading_language_420pack: require\n"
2359 "\n"
2360 "layout(location=0) out int x;\n"
2361 "void main(){\n"
2362 " x = 0;\n"
2363 " gl_Position = vec4(1);\n"
2364 "}\n";
2365 char const *fsSource =
2366 "#version 140\n"
2367 "#extension GL_ARB_separate_shader_objects: require\n"
2368 "#extension GL_ARB_shading_language_420pack: require\n"
2369 "\n"
2370 "layout(location=0) in float x;\n" /* VS writes int */
2371 "layout(location=0) out vec4 color;\n"
2372 "void main(){\n"
2373 " color = vec4(x);\n"
2374 "}\n";
2375
2376 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2377 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2378
2379 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002380 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12002381 pipe.AddShader(&vs);
2382 pipe.AddShader(&fs);
2383
Chris Forbescc281692015-05-25 11:13:17 +12002384 VkDescriptorSetObj descriptorSet(m_device);
2385 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002386 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12002387
2388 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002389 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12002390
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002391 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12002392
Cody Northrop1684adb2015-08-05 11:15:02 -06002393 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbescc281692015-05-25 11:13:17 +12002394 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
2395 FAIL() << "Incorrect error: " << msgString;
2396 }
2397}
2398
Chris Forbes8291c052015-05-25 11:13:28 +12002399TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
2400{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002401 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12002402 std::string msgString;
2403 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002404 ScopedUseGlsl useGlsl(false);
Chris Forbes8291c052015-05-25 11:13:28 +12002405
2406 VkVertexInputBindingDescription input_binding;
2407 memset(&input_binding, 0, sizeof(input_binding));
2408
2409 VkVertexInputAttributeDescription input_attrib;
2410 memset(&input_attrib, 0, sizeof(input_attrib));
2411 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2412
2413 char const *vsSource =
2414 "#version 140\n"
2415 "#extension GL_ARB_separate_shader_objects: require\n"
2416 "#extension GL_ARB_shading_language_420pack: require\n"
2417 "\n"
2418 "void main(){\n"
2419 " gl_Position = vec4(1);\n"
2420 "}\n";
2421 char const *fsSource =
2422 "#version 140\n"
2423 "#extension GL_ARB_separate_shader_objects: require\n"
2424 "#extension GL_ARB_shading_language_420pack: require\n"
2425 "\n"
2426 "layout(location=0) out vec4 color;\n"
2427 "void main(){\n"
2428 " color = vec4(1);\n"
2429 "}\n";
2430
2431 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2432 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2433
2434 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002435 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12002436 pipe.AddShader(&vs);
2437 pipe.AddShader(&fs);
2438
2439 pipe.AddVertexInputBindings(&input_binding, 1);
2440 pipe.AddVertexInputAttribs(&input_attrib, 1);
2441
Chris Forbes8291c052015-05-25 11:13:28 +12002442 VkDescriptorSetObj descriptorSet(m_device);
2443 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002444 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12002445
2446 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002447 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12002448
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002449 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12002450
Cody Northrop1684adb2015-08-05 11:15:02 -06002451 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12002452 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
2453 FAIL() << "Incorrect warning: " << msgString;
2454 }
2455}
2456
Chris Forbes37367e62015-05-25 11:13:29 +12002457TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
2458{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002459 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12002460 std::string msgString;
2461 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002462 ScopedUseGlsl useGlsl(false);
Chris Forbes37367e62015-05-25 11:13:29 +12002463
2464 char const *vsSource =
2465 "#version 140\n"
2466 "#extension GL_ARB_separate_shader_objects: require\n"
2467 "#extension GL_ARB_shading_language_420pack: require\n"
2468 "\n"
2469 "layout(location=0) in vec4 x;\n" /* not provided */
2470 "void main(){\n"
2471 " gl_Position = x;\n"
2472 "}\n";
2473 char const *fsSource =
2474 "#version 140\n"
2475 "#extension GL_ARB_separate_shader_objects: require\n"
2476 "#extension GL_ARB_shading_language_420pack: require\n"
2477 "\n"
2478 "layout(location=0) out vec4 color;\n"
2479 "void main(){\n"
2480 " color = vec4(1);\n"
2481 "}\n";
2482
2483 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2484 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2485
2486 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002487 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12002488 pipe.AddShader(&vs);
2489 pipe.AddShader(&fs);
2490
Chris Forbes37367e62015-05-25 11:13:29 +12002491 VkDescriptorSetObj descriptorSet(m_device);
2492 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002493 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12002494
2495 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002496 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12002497
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002498 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12002499
Cody Northrop1684adb2015-08-05 11:15:02 -06002500 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes37367e62015-05-25 11:13:29 +12002501 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
2502 FAIL() << "Incorrect warning: " << msgString;
2503 }
2504}
2505
Chris Forbesa4b02322015-05-25 11:13:31 +12002506TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
2507{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002508 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12002509 std::string msgString;
2510 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002511 ScopedUseGlsl useGlsl(false);
Chris Forbesa4b02322015-05-25 11:13:31 +12002512
2513 VkVertexInputBindingDescription input_binding;
2514 memset(&input_binding, 0, sizeof(input_binding));
2515
2516 VkVertexInputAttributeDescription input_attrib;
2517 memset(&input_attrib, 0, sizeof(input_attrib));
2518 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2519
2520 char const *vsSource =
2521 "#version 140\n"
2522 "#extension GL_ARB_separate_shader_objects: require\n"
2523 "#extension GL_ARB_shading_language_420pack: require\n"
2524 "\n"
2525 "layout(location=0) in int x;\n" /* attrib provided float */
2526 "void main(){\n"
2527 " gl_Position = vec4(x);\n"
2528 "}\n";
2529 char const *fsSource =
2530 "#version 140\n"
2531 "#extension GL_ARB_separate_shader_objects: require\n"
2532 "#extension GL_ARB_shading_language_420pack: require\n"
2533 "\n"
2534 "layout(location=0) out vec4 color;\n"
2535 "void main(){\n"
2536 " color = vec4(1);\n"
2537 "}\n";
2538
2539 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2540 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2541
2542 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002543 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12002544 pipe.AddShader(&vs);
2545 pipe.AddShader(&fs);
2546
2547 pipe.AddVertexInputBindings(&input_binding, 1);
2548 pipe.AddVertexInputAttribs(&input_attrib, 1);
2549
Chris Forbesa4b02322015-05-25 11:13:31 +12002550 VkDescriptorSetObj descriptorSet(m_device);
2551 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002552 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12002553
2554 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002555 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12002556
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002557 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12002558
Cody Northrop1684adb2015-08-05 11:15:02 -06002559 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa4b02322015-05-25 11:13:31 +12002560 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
2561 FAIL() << "Incorrect error: " << msgString;
2562 }
2563}
2564
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002565TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
2566{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002567 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002568 std::string msgString;
2569 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002570 ScopedUseGlsl useGlsl(false);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002571
2572 /* Two binding descriptions for binding 0 */
2573 VkVertexInputBindingDescription input_bindings[2];
2574 memset(input_bindings, 0, sizeof(input_bindings));
2575
2576 VkVertexInputAttributeDescription input_attrib;
2577 memset(&input_attrib, 0, sizeof(input_attrib));
2578 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2579
2580 char const *vsSource =
2581 "#version 140\n"
2582 "#extension GL_ARB_separate_shader_objects: require\n"
2583 "#extension GL_ARB_shading_language_420pack: require\n"
2584 "\n"
2585 "layout(location=0) in float x;\n" /* attrib provided float */
2586 "void main(){\n"
2587 " gl_Position = vec4(x);\n"
2588 "}\n";
2589 char const *fsSource =
2590 "#version 140\n"
2591 "#extension GL_ARB_separate_shader_objects: require\n"
2592 "#extension GL_ARB_shading_language_420pack: require\n"
2593 "\n"
2594 "layout(location=0) out vec4 color;\n"
2595 "void main(){\n"
2596 " color = vec4(1);\n"
2597 "}\n";
2598
2599 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2600 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2601
2602 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002603 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002604 pipe.AddShader(&vs);
2605 pipe.AddShader(&fs);
2606
2607 pipe.AddVertexInputBindings(input_bindings, 2);
2608 pipe.AddVertexInputAttribs(&input_attrib, 1);
2609
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002610 VkDescriptorSetObj descriptorSet(m_device);
2611 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002612 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002613
2614 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002615 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002616
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002617 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002618
Cody Northrop1684adb2015-08-05 11:15:02 -06002619 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002620 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
2621 FAIL() << "Incorrect error: " << msgString;
2622 }
2623}
Chris Forbes4c948702015-05-25 11:13:32 +12002624
Chris Forbesc12ef122015-05-25 11:13:40 +12002625/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
2626 * rejects it. */
2627
2628TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
2629{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002630 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12002631 std::string msgString;
2632 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002633 ScopedUseGlsl useGlsl(false);
Chris Forbesc12ef122015-05-25 11:13:40 +12002634
2635 char const *vsSource =
2636 "#version 140\n"
2637 "#extension GL_ARB_separate_shader_objects: require\n"
2638 "#extension GL_ARB_shading_language_420pack: require\n"
2639 "\n"
2640 "void main(){\n"
2641 " gl_Position = vec4(1);\n"
2642 "}\n";
2643 char const *fsSource =
2644 "#version 140\n"
2645 "#extension GL_ARB_separate_shader_objects: require\n"
2646 "#extension GL_ARB_shading_language_420pack: require\n"
2647 "\n"
2648 "void main(){\n"
2649 "}\n";
2650
2651 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2652 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2653
2654 VkPipelineObj pipe(m_device);
2655 pipe.AddShader(&vs);
2656 pipe.AddShader(&fs);
2657
Chia-I Wuc278df82015-07-07 11:50:03 +08002658 /* set up CB 0, not written */
2659 pipe.AddColorAttachment();
2660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12002661
Chris Forbesc12ef122015-05-25 11:13:40 +12002662 VkDescriptorSetObj descriptorSet(m_device);
2663 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002664 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12002665
2666 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002667 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12002668
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002669 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12002670
Cody Northrop1684adb2015-08-05 11:15:02 -06002671 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc12ef122015-05-25 11:13:40 +12002672 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
2673 FAIL() << "Incorrect error: " << msgString;
2674 }
2675}
2676
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002677TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
2678{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002679 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002680 std::string msgString;
2681 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002682 ScopedUseGlsl useGlsl(false);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002683
2684 char const *vsSource =
2685 "#version 140\n"
2686 "#extension GL_ARB_separate_shader_objects: require\n"
2687 "#extension GL_ARB_shading_language_420pack: require\n"
2688 "\n"
2689 "void main(){\n"
2690 " gl_Position = vec4(1);\n"
2691 "}\n";
2692 char const *fsSource =
2693 "#version 140\n"
2694 "#extension GL_ARB_separate_shader_objects: require\n"
2695 "#extension GL_ARB_shading_language_420pack: require\n"
2696 "\n"
2697 "layout(location=0) out vec4 x;\n"
2698 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
2699 "void main(){\n"
2700 " x = vec4(1);\n"
2701 " y = vec4(1);\n"
2702 "}\n";
2703
2704 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2705 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2706
2707 VkPipelineObj pipe(m_device);
2708 pipe.AddShader(&vs);
2709 pipe.AddShader(&fs);
2710
Chia-I Wuc278df82015-07-07 11:50:03 +08002711 /* set up CB 0, not written */
2712 pipe.AddColorAttachment();
2713 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002714 /* FS writes CB 1, but we don't configure it */
2715
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002716 VkDescriptorSetObj descriptorSet(m_device);
2717 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002718 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002719
2720 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002721 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002722
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002723 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002724
Cody Northrop1684adb2015-08-05 11:15:02 -06002725 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002726 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
2727 FAIL() << "Incorrect warning: " << msgString;
2728 }
2729}
2730
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002731TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
2732{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002733 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002734 std::string msgString;
2735 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002736 ScopedUseGlsl useGlsl(false);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002737
2738 char const *vsSource =
2739 "#version 140\n"
2740 "#extension GL_ARB_separate_shader_objects: require\n"
2741 "#extension GL_ARB_shading_language_420pack: require\n"
2742 "\n"
2743 "void main(){\n"
2744 " gl_Position = vec4(1);\n"
2745 "}\n";
2746 char const *fsSource =
2747 "#version 140\n"
2748 "#extension GL_ARB_separate_shader_objects: require\n"
2749 "#extension GL_ARB_shading_language_420pack: require\n"
2750 "\n"
2751 "layout(location=0) out ivec4 x;\n" /* not UNORM */
2752 "void main(){\n"
2753 " x = ivec4(1);\n"
2754 "}\n";
2755
2756 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2757 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2758
2759 VkPipelineObj pipe(m_device);
2760 pipe.AddShader(&vs);
2761 pipe.AddShader(&fs);
2762
Chia-I Wuc278df82015-07-07 11:50:03 +08002763 /* set up CB 0; type is UNORM by default */
2764 pipe.AddColorAttachment();
2765 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002766
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002767 VkDescriptorSetObj descriptorSet(m_device);
2768 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002769 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002770
2771 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002772 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002773
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002774 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002775
Cody Northrop1684adb2015-08-05 11:15:02 -06002776 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002777 if (!strstr(msgString.c_str(),"does not match FS output type")) {
2778 FAIL() << "Incorrect error: " << msgString;
2779 }
2780}
Chris Forbesc2050732015-06-05 14:43:36 +12002781
2782TEST_F(VkLayerTest, CreatePipelineNonSpirvShader)
2783{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002784 VkFlags msgFlags;
Chris Forbesc2050732015-06-05 14:43:36 +12002785 std::string msgString;
2786 ASSERT_NO_FATAL_FAILURE(InitState());
2787 /* Intentionally provided GLSL rather than compiling to SPIRV first */
Cody Northrop1cfbd172015-06-03 16:49:20 -06002788 ScopedUseGlsl useGlsl(true);
Chris Forbesc2050732015-06-05 14:43:36 +12002789
2790 char const *vsSource =
2791 "#version 140\n"
2792 "#extension GL_ARB_separate_shader_objects: require\n"
2793 "#extension GL_ARB_shading_language_420pack: require\n"
2794 "\n"
2795 "void main(){\n"
2796 " gl_Position = vec4(1);\n"
2797 "}\n";
2798 char const *fsSource =
2799 "#version 140\n"
2800 "#extension GL_ARB_separate_shader_objects: require\n"
2801 "#extension GL_ARB_shading_language_420pack: require\n"
2802 "\n"
2803 "layout(location=0) out vec4 x;\n"
2804 "void main(){\n"
2805 " x = vec4(1);\n"
2806 "}\n";
2807
2808 m_errorMonitor->ClearState();
2809
2810 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2811 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2812
2813
2814 VkPipelineObj pipe(m_device);
2815 pipe.AddShader(&vs);
2816 pipe.AddShader(&fs);
2817
Chia-I Wuc278df82015-07-07 11:50:03 +08002818 /* set up CB 0; type is UNORM by default */
2819 pipe.AddColorAttachment();
2820 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc2050732015-06-05 14:43:36 +12002821
Chris Forbesc2050732015-06-05 14:43:36 +12002822 VkDescriptorSetObj descriptorSet(m_device);
2823 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002824 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc2050732015-06-05 14:43:36 +12002825
Tony Barboured132432015-08-04 16:23:11 -06002826 VkResult res = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc2050732015-06-05 14:43:36 +12002827 /* pipeline creation should have succeeded */
2828 ASSERT_EQ(VK_SUCCESS, res);
2829
2830 /* should have emitted a warning: the shader is not SPIRV, so we're
2831 * not going to be able to analyze it */
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002832 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002833 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesc2050732015-06-05 14:43:36 +12002834 if (!strstr(msgString.c_str(),"is not SPIR-V")) {
2835 FAIL() << "Incorrect warning: " << msgString;
2836 }
2837}
Chris Forbes01c9db72015-06-04 09:25:25 +12002838#endif
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002839
Tony Barbour30486ea2015-04-07 13:44:53 -06002840int main(int argc, char **argv) {
2841 int result;
2842
2843 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06002844 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06002845
2846 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
2847
2848 result = RUN_ALL_TESTS();
2849
Tony Barbour01999182015-04-09 12:58:51 -06002850 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06002851 return result;
2852}