blob: 5289c280e580783d5ee942c0bb3e1089d9288a44 [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,
30 BsoFailRaster = 0x00000001,
31 BsoFailViewport = 0x00000002,
32 BsoFailColorBlend = 0x00000004,
33 BsoFailDepthStencil = 0x00000008,
34} BsoFailSelect;
35
36struct vktriangle_vs_uniform {
37 // Must start with MVP
38 float mvp[4][4];
39 float position[3][4];
40 float color[3][4];
41};
42
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050043static const char bindStateVertShaderText[] =
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050044 "#version 130\n"
45 "vec2 vertices[3];\n"
46 "void main() {\n"
47 " vertices[0] = vec2(-1.0, -1.0);\n"
48 " vertices[1] = vec2( 1.0, -1.0);\n"
49 " vertices[2] = vec2( 0.0, 1.0);\n"
50 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
51 "}\n";
52
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050053static const char bindStateFragShaderText[] =
Cody Northrop74a2d2c2015-06-16 17:32:04 -060054 "#version 140\n"
55 "#extension GL_ARB_separate_shader_objects: require\n"
56 "#extension GL_ARB_shading_language_420pack: require\n"
57 "\n"
58 "layout(location = 0) out vec4 uFragColor;\n"
59 "void main(){\n"
60 " uFragColor = vec4(0,1,0,1);\n"
61 "}\n";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050062
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060063static void myDbgFunc(
Tony Barboure84a8d62015-07-10 14:10:27 -060064 VkFlags msgFlags,
65 VkDbgObjectType objType,
66 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060067 size_t location,
68 int32_t msgCode,
69 const char* pLayerPrefix,
70 const char* pMsg,
71 void* pUserData);
Tony Barbour30486ea2015-04-07 13:44:53 -060072
73class ErrorMonitor {
74public:
Tony Barbour0c1bdc62015-04-29 17:34:29 -060075 ErrorMonitor()
Tony Barbour30486ea2015-04-07 13:44:53 -060076 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060077 test_platform_thread_create_mutex(&m_mutex);
78 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060079 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mike Stroyan09aae812015-05-12 16:00:45 -060080 m_bailout = NULL;
Mike Stroyan7016f4f2015-07-13 14:45:35 -060081 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060082 }
83 void ClearState()
84 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060085 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060086 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -060087 m_msgString.clear();
Mike Stroyan7016f4f2015-07-13 14:45:35 -060088 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060089 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060090 VkFlags GetState(std::string *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -060091 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060092 test_platform_thread_lock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060093 *msgString = m_msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -060094 test_platform_thread_unlock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060095 return m_msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -060096 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060097 void SetState(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -060098 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060099 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600100 if (m_bailout != NULL) {
101 *m_bailout = true;
102 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600103 m_msgFlags = msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600104 m_msgString.reserve(strlen(msgString));
105 m_msgString = msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600106 test_platform_thread_unlock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600107 }
108 void SetBailout(bool *bailout)
109 {
110 m_bailout = bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600111 }
112
113private:
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600114 VkFlags m_msgFlags;
115 std::string m_msgString;
116 test_platform_thread_mutex m_mutex;
117 bool* m_bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600118};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500119
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600120static void myDbgFunc(
121 VkFlags msgFlags,
Tony Barboure84a8d62015-07-10 14:10:27 -0600122 VkDbgObjectType objType,
123 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600124 size_t location,
125 int32_t msgCode,
126 const char* pLayerPrefix,
127 const char* pMsg,
128 void* pUserData)
Tony Barbour30486ea2015-04-07 13:44:53 -0600129{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600130 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour8508b8e2015-04-09 10:48:04 -0600131 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600132 errMonitor->SetState(msgFlags, pMsg);
Tony Barbour8508b8e2015-04-09 10:48:04 -0600133 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600134}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500135
Tony Barbour01999182015-04-09 12:58:51 -0600136class VkLayerTest : public VkRenderFramework
Tony Barbour30486ea2015-04-07 13:44:53 -0600137{
138public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600139 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
140 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500141 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
142 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbour1490c912015-07-28 10:17:20 -0600143 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
144 { GenericDrawPreparation(m_cmdBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600145
Tony Barbour1490c912015-07-28 10:17:20 -0600146 /* Convenience functions that use built-in command buffer */
147 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_cmdBuffer); }
148 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_cmdBuffer); }
149 void Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
150 { m_cmdBuffer->Draw(firstVertex, vertexCount, firstInstance, instanceCount); }
151 void DrawIndexed(uint32_t firstVertex, uint32_t vertexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
152 { m_cmdBuffer->DrawIndexed(firstVertex, vertexCount, vertexOffset,firstInstance, instanceCount); }
153 void QueueCommandBuffer() { m_cmdBuffer->QueueCommandBuffer(); }
154 void QueueCommandBuffer(const VkFence& fence) { m_cmdBuffer->QueueCommandBuffer(fence); }
155 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
156 { m_cmdBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
157 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
158 { m_cmdBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600159protected:
Tony Barbour01999182015-04-09 12:58:51 -0600160 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600161
162 virtual void SetUp() {
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600163 std::vector<const char *> instance_layer_names;
164 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600165 std::vector<const char *> instance_extension_names;
166 std::vector<const char *> device_extension_names;
Tony Barbour950ebc02015-04-23 12:55:36 -0600167
Courtney Goeltzenleuchter846298c2015-07-30 11:32:46 -0600168 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600169 /*
170 * Since CreateDbgMsgCallback is an instance level extension call
171 * any extension / layer that utilizes that feature also needs
172 * to be enabled at create instance time.
173 */
Mike Stroyaned254572015-06-17 16:32:06 -0600174 // Use Threading layer first to protect others from ThreadCmdBufferCollision test
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600175 instance_layer_names.push_back("Threading");
176 instance_layer_names.push_back("ObjectTracker");
177 instance_layer_names.push_back("MemTracker");
178 instance_layer_names.push_back("DrawState");
179 instance_layer_names.push_back("ShaderChecker");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600180
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600181 device_layer_names.push_back("Threading");
182 device_layer_names.push_back("ObjectTracker");
183 device_layer_names.push_back("MemTracker");
184 device_layer_names.push_back("DrawState");
185 device_layer_names.push_back("ShaderChecker");
Tony Barbour30486ea2015-04-07 13:44:53 -0600186
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600187 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -0600188 this->app_info.pNext = NULL;
189 this->app_info.pAppName = "layer_tests";
190 this->app_info.appVersion = 1;
191 this->app_info.pEngineName = "unittest";
192 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600193 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -0600194
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600195 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600196 InitFramework(instance_layer_names, device_layer_names,
197 instance_extension_names, device_extension_names,
198 myDbgFunc, m_errorMonitor);
Tony Barbour30486ea2015-04-07 13:44:53 -0600199 }
200
201 virtual void TearDown() {
202 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600203 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600204 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600205 }
206};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500207
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600208VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600209{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600210 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600211
212 result = cmdBuffer.BeginCommandBuffer();
213
214 /*
215 * For render test all drawing happens in a single render pass
216 * on a single command buffer.
217 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200218 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wuc278df82015-07-07 11:50:03 +0800219 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour30486ea2015-04-07 13:44:53 -0600220 }
221
222 return result;
223}
224
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600225VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600226{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600227 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600228
Chris Forbesfe133ef2015-06-16 14:05:59 +1200229 if (renderPass()) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800230 cmdBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200231 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600232
233 result = cmdBuffer.EndCommandBuffer();
234
235 return result;
236}
237
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500238void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
239{
240 // Create identity matrix
241 int i;
242 struct vktriangle_vs_uniform data;
243
244 glm::mat4 Projection = glm::mat4(1.0f);
245 glm::mat4 View = glm::mat4(1.0f);
246 glm::mat4 Model = glm::mat4(1.0f);
247 glm::mat4 MVP = Projection * View * Model;
248 const int matrixSize = sizeof(MVP);
249 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
250
251 memcpy(&data.mvp, &MVP[0][0], matrixSize);
252
253 static const Vertex tri_data[] =
254 {
255 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
256 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
257 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
258 };
259
260 for (i=0; i<3; i++) {
261 data.position[i][0] = tri_data[i].posX;
262 data.position[i][1] = tri_data[i].posY;
263 data.position[i][2] = tri_data[i].posZ;
264 data.position[i][3] = tri_data[i].posW;
265 data.color[i][0] = tri_data[i].r;
266 data.color[i][1] = tri_data[i].g;
267 data.color[i][2] = tri_data[i].b;
268 data.color[i][3] = tri_data[i].a;
269 }
270
271 ASSERT_NO_FATAL_FAILURE(InitState());
272 ASSERT_NO_FATAL_FAILURE(InitViewport());
273
274 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
275
276 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
277 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
278
279 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800280 pipelineobj.AddColorAttachment();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500281 pipelineobj.AddShader(&vs);
282 pipelineobj.AddShader(&ps);
283
284 VkDescriptorSetObj descriptorSet(m_device);
285 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
286
287 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600288 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500289
Tony Barbour1490c912015-07-28 10:17:20 -0600290 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500291
292 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -0600293 Draw(0, 3, 0, 1);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500294
295 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600296 EndCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500297
Tony Barbour1490c912015-07-28 10:17:20 -0600298 QueueCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500299}
300
301void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
302{
303 if (m_depthStencil->Initialized()) {
304 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
305 } else {
306 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
307 }
308
309 cmdBuffer->PrepareAttachments();
310 if ((failMask & BsoFailRaster) != BsoFailRaster) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600311 cmdBuffer->BindDynamicRasterState(m_stateRaster);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500312 }
313 if ((failMask & BsoFailViewport) != BsoFailViewport) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600314 cmdBuffer->BindDynamicViewportState(m_stateViewport);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500315 }
316 if ((failMask & BsoFailColorBlend) != BsoFailColorBlend) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600317 cmdBuffer->BindDynamicColorBlendState(m_colorBlend);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500318 }
319 if ((failMask & BsoFailDepthStencil) != BsoFailDepthStencil) {
Tony Barboure84a8d62015-07-10 14:10:27 -0600320 cmdBuffer->BindDynamicDepthStencilState(m_stateDepthStencil);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500321 }
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600322 // Make sure depthWriteEnable is set so that DepthStencil fail test will work correctly
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600323 VkStencilOpState stencil = {};
324 stencil.stencilFailOp = VK_STENCIL_OP_KEEP;
325 stencil.stencilPassOp = VK_STENCIL_OP_KEEP;
326 stencil.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
327 stencil.stencilCompareOp = VK_COMPARE_OP_NEVER;
328
329 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
330 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
331 ds_ci.pNext = NULL;
332 ds_ci.depthTestEnable = VK_FALSE;
333 ds_ci.depthWriteEnable = VK_TRUE;
334 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
335 ds_ci.depthBoundsEnable = VK_FALSE;
336 ds_ci.stencilTestEnable = VK_FALSE;
337 ds_ci.front = stencil;
338 ds_ci.back = stencil;
339
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600340 pipelineobj.SetDepthStencil(&ds_ci);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500341 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Chia-I Wuc278df82015-07-07 11:50:03 +0800342 pipelineobj.CreateVKPipeline(descriptorSet, renderPass());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500343 cmdBuffer->BindPipeline(pipelineobj);
344 cmdBuffer->BindDescriptorSet(descriptorSet);
345}
346
347// ********************************************************************************************************************
348// ********************************************************************************************************************
349// ********************************************************************************************************************
350// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600351#if MEM_TRACKER_TESTS
Mark Lobodzinski81078192015-05-19 10:28:29 -0500352TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
353{
354 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600355 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500356 std::string msgString;
357
358 VkFenceCreateInfo fenceInfo = {};
359 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
360 fenceInfo.pNext = NULL;
361 fenceInfo.flags = 0;
362
363 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barboure389b882015-07-20 13:00:10 -0600364
365 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
366 vk_testing::Buffer buffer;
367 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500368
Tony Barbour1490c912015-07-28 10:17:20 -0600369 BeginCommandBuffer();
370 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
371 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500372
373 testFence.init(*m_device, fenceInfo);
374
375 // Bypass framework since it does the waits automatically
376 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600377 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500378 ASSERT_VK_SUCCESS( err );
379
380 m_errorMonitor->ClearState();
381 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600382 vkResetCommandBuffer(m_cmdBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500383
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600384 msgFlags = m_errorMonitor->GetState(&msgString);
385 ASSERT_TRUE(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 -0500386 if (!strstr(msgString.c_str(),"Resetting CB")) {
387 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
388 }
389}
390
391TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion)
392{
393 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600394 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500395 std::string msgString;
396
397 VkFenceCreateInfo fenceInfo = {};
398 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
399 fenceInfo.pNext = NULL;
400 fenceInfo.flags = 0;
401
402 ASSERT_NO_FATAL_FAILURE(InitState());
403 ASSERT_NO_FATAL_FAILURE(InitViewport());
404 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
405
Tony Barbour1490c912015-07-28 10:17:20 -0600406 BeginCommandBuffer();
407 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
408 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500409
410 testFence.init(*m_device, fenceInfo);
411
412 // Bypass framework since it does the waits automatically
413 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600414 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500415 ASSERT_VK_SUCCESS( err );
416
417 m_errorMonitor->ClearState();
418 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600419 BeginCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500420
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600421 msgFlags = m_errorMonitor->GetState(&msgString);
422 ASSERT_TRUE(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 -0500423 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
424 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
425 }
426}
427
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500428TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
429{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600430 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500431 std::string msgString;
432 VkResult err;
433
434 ASSERT_NO_FATAL_FAILURE(InitState());
435 m_errorMonitor->ClearState();
436
437 // Create an image, allocate memory, free it, and then try to bind it
438 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500439 VkDeviceMemory mem;
440 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500441
442 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
443 const int32_t tex_width = 32;
444 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500445
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600446 VkImageCreateInfo image_create_info = {};
447 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
448 image_create_info.pNext = NULL;
449 image_create_info.imageType = VK_IMAGE_TYPE_2D;
450 image_create_info.format = tex_format;
451 image_create_info.extent.width = tex_width;
452 image_create_info.extent.height = tex_height;
453 image_create_info.extent.depth = 1;
454 image_create_info.mipLevels = 1;
455 image_create_info.arraySize = 1;
456 image_create_info.samples = 1;
457 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
458 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
459 image_create_info.flags = 0;
460
461 VkMemoryAllocInfo mem_alloc = {};
462 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
463 mem_alloc.pNext = NULL;
464 mem_alloc.allocationSize = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500465 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600466 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500467
468 err = vkCreateImage(m_device->device(), &image_create_info, &image);
469 ASSERT_VK_SUCCESS(err);
470
Tony Barboure84a8d62015-07-10 14:10:27 -0600471 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500472 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500473 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500474 ASSERT_VK_SUCCESS(err);
475
Mark Lobodzinski23182612015-05-29 09:32:35 -0500476 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500477
478 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500479 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500480 ASSERT_VK_SUCCESS(err);
481
482 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600483 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500484 ASSERT_VK_SUCCESS(err);
485
486 // Map memory as if to initialize the image
487 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500488 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500489
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600490 msgFlags = m_errorMonitor->GetState(&msgString);
491 ASSERT_TRUE(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 -0500492 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
493 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
494 }
495}
496
497TEST_F(VkLayerTest, BindInvalidMemory)
498{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600499 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500500 std::string msgString;
501 VkResult err;
502
503 ASSERT_NO_FATAL_FAILURE(InitState());
504 m_errorMonitor->ClearState();
505
506 // Create an image, allocate memory, free it, and then try to bind it
507 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500508 VkDeviceMemory mem;
509 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500510
511 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
512 const int32_t tex_width = 32;
513 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500514
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600515 VkImageCreateInfo image_create_info = {};
516 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
517 image_create_info.pNext = NULL;
518 image_create_info.imageType = VK_IMAGE_TYPE_2D;
519 image_create_info.format = tex_format;
520 image_create_info.extent.width = tex_width;
521 image_create_info.extent.height = tex_height;
522 image_create_info.extent.depth = 1;
523 image_create_info.mipLevels = 1;
524 image_create_info.arraySize = 1;
525 image_create_info.samples = 1;
526 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
527 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
528 image_create_info.flags = 0;
529
530 VkMemoryAllocInfo mem_alloc = {};
531 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
532 mem_alloc.pNext = NULL;
533 mem_alloc.allocationSize = 0;
534 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500535
536 err = vkCreateImage(m_device->device(), &image_create_info, &image);
537 ASSERT_VK_SUCCESS(err);
538
Tony Barboure84a8d62015-07-10 14:10:27 -0600539 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500540 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500541 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500542 ASSERT_VK_SUCCESS(err);
543
Mark Lobodzinski23182612015-05-29 09:32:35 -0500544 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500545
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800546 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600547 ASSERT_VK_SUCCESS(err);
548
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500549 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500550 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500551 ASSERT_VK_SUCCESS(err);
552
553 // Introduce validation failure, free memory before binding
Mark Lobodzinski23182612015-05-29 09:32:35 -0500554 vkFreeMemory(m_device->device(), mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500555 ASSERT_VK_SUCCESS(err);
556
557 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600558 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500559 ASSERT_VK_SUCCESS(err);
560
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600561 msgFlags = m_errorMonitor->GetState(&msgString);
562 ASSERT_TRUE(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 -0500563 if (!strstr(msgString.c_str(),"couldn't find info for mem obj")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500564 FAIL() << "Error received did not match expected error message from BindObjectMemory in MemTracker";
565 }
566}
567
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600568// TODO : Is this test still valid. Not sure it is with updates to memory binding model
569// Verify and delete the test of fix the check
570//TEST_F(VkLayerTest, FreeBoundMemory)
571//{
572// VkFlags msgFlags;
573// std::string msgString;
574// VkResult err;
575//
576// ASSERT_NO_FATAL_FAILURE(InitState());
577// m_errorMonitor->ClearState();
578//
579// // Create an image, allocate memory, free it, and then try to bind it
580// VkImage image;
581// VkDeviceMemory mem;
582// VkMemoryRequirements mem_reqs;
583//
584// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
585// const int32_t tex_width = 32;
586// const int32_t tex_height = 32;
587//
588// const VkImageCreateInfo image_create_info = {
589// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
590// .pNext = NULL,
591// .imageType = VK_IMAGE_TYPE_2D,
592// .format = tex_format,
593// .extent = { tex_width, tex_height, 1 },
594// .mipLevels = 1,
595// .arraySize = 1,
596// .samples = 1,
597// .tiling = VK_IMAGE_TILING_LINEAR,
598// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
599// .flags = 0,
600// };
601// VkMemoryAllocInfo mem_alloc = {
602// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
603// .pNext = NULL,
604// .allocationSize = 0,
605// .memoryTypeIndex = 0,
606// };
607//
608// err = vkCreateImage(m_device->device(), &image_create_info, &image);
609// ASSERT_VK_SUCCESS(err);
610//
611// err = vkGetImageMemoryRequirements(m_device->device(),
612// image,
613// &mem_reqs);
614// ASSERT_VK_SUCCESS(err);
615//
616// mem_alloc.allocationSize = mem_reqs.size;
617//
618// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
619// ASSERT_VK_SUCCESS(err);
620//
621// // allocate memory
622// err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
623// ASSERT_VK_SUCCESS(err);
624//
625// // Bind memory to Image object
626// err = vkBindImageMemory(m_device->device(), image, mem, 0);
627// ASSERT_VK_SUCCESS(err);
628//
629// // Introduce validation failure, free memory while still bound to object
630// vkFreeMemory(m_device->device(), mem);
631// ASSERT_VK_SUCCESS(err);
632//
633// msgFlags = m_errorMonitor->GetState(&msgString);
634// ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an warning while tring to free bound memory";
635// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
636// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
637// }
638//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500639
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500640TEST_F(VkLayerTest, RebindMemory)
641{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600642 VkFlags msgFlags;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500643 std::string msgString;
644 VkResult err;
645
646 ASSERT_NO_FATAL_FAILURE(InitState());
647 m_errorMonitor->ClearState();
648
649 // Create an image, allocate memory, free it, and then try to bind it
650 VkImage image;
651 VkDeviceMemory mem1;
652 VkDeviceMemory mem2;
653 VkMemoryRequirements mem_reqs;
654
655 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
656 const int32_t tex_width = 32;
657 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500658
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600659 VkImageCreateInfo image_create_info = {};
660 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
661 image_create_info.pNext = NULL;
662 image_create_info.imageType = VK_IMAGE_TYPE_2D;
663 image_create_info.format = tex_format;
664 image_create_info.extent.width = tex_width;
665 image_create_info.extent.height = tex_height;
666 image_create_info.extent.depth = 1;
667 image_create_info.mipLevels = 1;
668 image_create_info.arraySize = 1;
669 image_create_info.samples = 1;
670 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
671 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
672 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500673
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600674 VkMemoryAllocInfo mem_alloc = {};
675 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
676 mem_alloc.pNext = NULL;
677 mem_alloc.allocationSize = 0;
678 mem_alloc.memoryTypeIndex = 0;
679
680 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
681 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500682 err = vkCreateImage(m_device->device(), &image_create_info, &image);
683 ASSERT_VK_SUCCESS(err);
684
Tony Barboure84a8d62015-07-10 14:10:27 -0600685 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500686 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500687 &mem_reqs);
688 ASSERT_VK_SUCCESS(err);
689
690 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800691 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600692 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500693
694 // allocate 2 memory objects
695 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
696 ASSERT_VK_SUCCESS(err);
697 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
698 ASSERT_VK_SUCCESS(err);
699
700 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600701 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500702 ASSERT_VK_SUCCESS(err);
703
704 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600705 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500706 ASSERT_VK_SUCCESS(err);
707
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600708 msgFlags = m_errorMonitor->GetState(&msgString);
709 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error while tring to rebind an object";
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500710 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
711 FAIL() << "Error received did not match expected message when rebinding memory to an object";
712 }
713}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500714
715TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
716{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600717 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500718 std::string msgString;
719 VkResult err;
720
721 ASSERT_NO_FATAL_FAILURE(InitState());
722 m_errorMonitor->ClearState();
723
724 // Create an image object, allocate memory, destroy the object and then try to bind it
725 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500726 VkDeviceMemory mem;
727 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500728
729 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
730 const int32_t tex_width = 32;
731 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500732
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600733 VkImageCreateInfo image_create_info = {};
734 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
735 image_create_info.pNext = NULL;
736 image_create_info.imageType = VK_IMAGE_TYPE_2D;
737 image_create_info.format = tex_format;
738 image_create_info.extent.width = tex_width;
739 image_create_info.extent.height = tex_height;
740 image_create_info.extent.depth = 1;
741 image_create_info.mipLevels = 1;
742 image_create_info.arraySize = 1;
743 image_create_info.samples = 1;
744 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
745 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
746 image_create_info.flags = 0;
747
748 VkMemoryAllocInfo mem_alloc = {};
749 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
750 mem_alloc.pNext = NULL;
751 mem_alloc.allocationSize = 0;
752 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500753
754 err = vkCreateImage(m_device->device(), &image_create_info, &image);
755 ASSERT_VK_SUCCESS(err);
756
Tony Barboure84a8d62015-07-10 14:10:27 -0600757 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500758 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500759 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500760 ASSERT_VK_SUCCESS(err);
761
Mark Lobodzinski23182612015-05-29 09:32:35 -0500762 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800763 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600764 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500765
766 // Allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500767 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500768 ASSERT_VK_SUCCESS(err);
769
770 // Introduce validation failure, destroy Image object before binding
Tony Barboure84a8d62015-07-10 14:10:27 -0600771 vkDestroyImage(m_device->device(), image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500772 ASSERT_VK_SUCCESS(err);
773
774 // Now Try to bind memory to this destroyted object
Tony Barboure84a8d62015-07-10 14:10:27 -0600775 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500776 ASSERT_VK_SUCCESS(err);
777
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600778 msgFlags = m_errorMonitor->GetState(&msgString);
779 ASSERT_TRUE(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 -0500780 if (!strstr(msgString.c_str(),"that's not in global list")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500781 FAIL() << "Error received did not match expected error message from updateObjectBinding in MemTracker";
782 }
783}
784
Tony Barbour8508b8e2015-04-09 10:48:04 -0600785TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600786{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600787 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600788 VkFlags msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600789 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600790
791 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600792 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
793 fenceInfo.pNext = NULL;
794 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600795
Tony Barbour30486ea2015-04-07 13:44:53 -0600796 ASSERT_NO_FATAL_FAILURE(InitState());
797 ASSERT_NO_FATAL_FAILURE(InitViewport());
798 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
799
Tony Barbour1490c912015-07-28 10:17:20 -0600800 BeginCommandBuffer();
801 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
802 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600803
804 testFence.init(*m_device, fenceInfo);
805 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -0600806 QueueCommandBuffer(testFence.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600807 msgFlags = m_errorMonitor->GetState(&msgString);
808 ASSERT_TRUE(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 -0600809 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500810 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600811 }
812
813}
814
815TEST_F(VkLayerTest, ResetUnsignaledFence)
816{
817 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600818 VkFlags msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600819 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600820 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600821 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
822 fenceInfo.pNext = NULL;
823
Tony Barbour8508b8e2015-04-09 10:48:04 -0600824 ASSERT_NO_FATAL_FAILURE(InitState());
825 testFence.init(*m_device, fenceInfo);
826 m_errorMonitor->ClearState();
Chia-I Wua4992342015-07-03 11:45:55 +0800827 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600828 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600829 msgFlags = m_errorMonitor->GetState(&msgString);
830 ASSERT_TRUE(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 -0600831 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500832 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600833 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600834
835}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600836
Chia-I Wuc278df82015-07-07 11:50:03 +0800837/* TODO: Update for changes due to bug-14075 tiling across render passes */
838#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600839TEST_F(VkLayerTest, InvalidUsageBits)
840{
841 // Initiate Draw w/o a PSO bound
842 VkFlags msgFlags;
843 std::string msgString;
844
845 ASSERT_NO_FATAL_FAILURE(InitState());
846 m_errorMonitor->ClearState();
847 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600848 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600849
850 const VkExtent3D e3d = {
851 .width = 128,
852 .height = 128,
853 .depth = 1,
854 };
855 const VkImageCreateInfo ici = {
856 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
857 .pNext = NULL,
858 .imageType = VK_IMAGE_TYPE_2D,
859 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
860 .extent = e3d,
861 .mipLevels = 1,
862 .arraySize = 1,
863 .samples = 1,
864 .tiling = VK_IMAGE_TILING_LINEAR,
865 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_BIT
866 .flags = 0,
867 };
868
869 VkImage dsi;
870 vkCreateImage(m_device->device(), &ici, &dsi);
871 VkDepthStencilView dsv;
872 const VkDepthStencilViewCreateInfo dsvci = {
873 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
874 .pNext = NULL,
875 .image = dsi,
876 .mipLevel = 0,
877 .baseArraySlice = 0,
878 .arraySize = 1,
879 .flags = 0,
880 };
881 vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv);
882 msgFlags = m_errorMonitor->GetState(&msgString);
883 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after attempting to create DSView w/ image lacking USAGE_DS_BIT flag";
884 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
885 FAIL() << "Error received was not 'Invalid usage flag for image...'";
886 }
887}
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600888#endif
Chia-I Wuc278df82015-07-07 11:50:03 +0800889#endif
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600890#if OBJ_TRACKER_TESTS
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500891TEST_F(VkLayerTest, RasterStateNotBound)
892{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600893 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500894 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600895 ASSERT_NO_FATAL_FAILURE(InitState());
896 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500897 TEST_DESCRIPTION("Simple Draw Call that validates failure when a raster state object is not bound beforehand");
898
899 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailRaster);
900
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600901 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600902 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error from Not Binding a Raster State Object";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500903 if (!strstr(msgString.c_str(),"Raster object not bound to this command buffer")) {
904 FAIL() << "Error received was not 'Raster object not bound to this command buffer'";
905 }
906}
907
908TEST_F(VkLayerTest, ViewportStateNotBound)
909{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600910 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500911 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600912 ASSERT_NO_FATAL_FAILURE(InitState());
913 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500914 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
915
916 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
917
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600918 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600919 ASSERT_TRUE(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 -0500920 if (!strstr(msgString.c_str(),"Viewport object not bound to this command buffer")) {
921 FAIL() << "Error received was not 'Viewport object not bound to this command buffer'";
922 }
923}
924
925TEST_F(VkLayerTest, ColorBlendStateNotBound)
926{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600927 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500928 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600929 ASSERT_NO_FATAL_FAILURE(InitState());
930 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500931 TEST_DESCRIPTION("Simple Draw Call that validates failure when a color-blend state object is not bound beforehand");
932
933 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailColorBlend);
934
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600935 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600936 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error from Not Binding a ColorBlend State Object";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500937 if (!strstr(msgString.c_str(),"Color-blend object not bound to this command buffer")) {
938 FAIL() << "Error received was not 'Color-blend object not bound to this command buffer'";
939 }
940}
941
942TEST_F(VkLayerTest, DepthStencilStateNotBound)
943{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600944 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500945 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600946 ASSERT_NO_FATAL_FAILURE(InitState());
947 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500948 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth-stencil state object is not bound beforehand");
949
950 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthStencil);
951
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600952 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600953 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error from Not Binding a DepthStencil State Object";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500954 if (!strstr(msgString.c_str(),"Depth-stencil object not bound to this command buffer")) {
955 FAIL() << "Error received was not 'Depth-stencil object not bound to this command buffer'";
956 }
Tony Barbourdb686622015-05-06 09:35:56 -0600957}
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600958#endif
959#if DRAW_STATE_TESTS
Tobin Ehlise4076782015-06-24 15:53:07 -0600960TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600961{
962 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600963 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600964 std::string msgString;
965
966 ASSERT_NO_FATAL_FAILURE(InitState());
967 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -0600968 BeginCommandBuffer();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600969 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Tony Barbour1490c912015-07-28 10:17:20 -0600970 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600971 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlise4076782015-06-24 15:53:07 -0600972 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding pipeline to CmdBuffer w/o active RenderPass";
973 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
974 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0xbaadb1be) without an active RenderPass'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600975 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600976}
977
978TEST_F(VkLayerTest, InvalidDescriptorPool)
979{
980 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
981 // The DS check for this is after driver has been called to validate DS internal data struct
982 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600983/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600984 std::string msgString;
985 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
986 vkResetDescriptorPool(device(), badPool);
987
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600988 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600989 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error from Resetting an invalid DescriptorPool Object";
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600990 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
991 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
992 }*/
993}
994
995TEST_F(VkLayerTest, InvalidDescriptorSet)
996{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600997 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
998 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600999 // Create a valid cmd buffer
1000 // call vkCmdBindDescriptorSets w/ false DS
1001}
1002
1003TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1004{
1005 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1006 // The DS check for this is after driver has been called to validate DS internal data struct
1007}
1008
1009TEST_F(VkLayerTest, InvalidPipeline)
1010{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001011 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1012 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001013 // Create a valid cmd buffer
1014 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -06001015// VkFlags msgFlags;
1016// std::string msgString;
1017//
1018// ASSERT_NO_FATAL_FAILURE(InitState());
1019// m_errorMonitor->ClearState();
1020// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001021// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001022// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1023// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1024// msgFlags = m_errorMonitor->GetState(&msgString);
1025// ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding invalid pipeline to CmdBuffer";
1026// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1027// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1028// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001029}
1030
Tobin Ehlis254eca02015-06-25 15:46:59 -06001031TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001032{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001033 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001034 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001035 std::string msgString;
1036 VkResult err;
1037
1038 ASSERT_NO_FATAL_FAILURE(InitState());
1039 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001040 VkDescriptorTypeCount ds_type_count = {};
1041 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1042 ds_type_count.count = 1;
1043
1044 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1045 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1046 ds_pool_ci.pNext = NULL;
1047 ds_pool_ci.count = 1;
1048 ds_pool_ci.pTypeCount = &ds_type_count;
1049
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001050 VkDescriptorPool ds_pool;
1051 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1052 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001053
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001054 VkDescriptorSetLayoutBinding dsl_binding = {};
1055 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1056 dsl_binding.arraySize = 1;
1057 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1058 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001059
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001060 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1061 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1062 ds_layout_ci.pNext = NULL;
1063 ds_layout_ci.count = 1;
1064 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001065 VkDescriptorSetLayout ds_layout;
1066 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1067 ASSERT_VK_SUCCESS(err);
1068
1069 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001070 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001071 ASSERT_VK_SUCCESS(err);
1072
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001073 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1074 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1075 pipeline_layout_ci.pNext = NULL;
1076 pipeline_layout_ci.descriptorSetCount = 1;
1077 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001078
1079 VkPipelineLayout pipeline_layout;
1080 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1081 ASSERT_VK_SUCCESS(err);
1082
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001083 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001084
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001085 VkPipelineShaderStageCreateInfo pipe_vs_ci = {};
1086 pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1087 pipe_vs_ci.pNext = NULL;
1088 pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX;
1089 pipe_vs_ci.shader = vs.handle();
1090 pipe_vs_ci.pSpecializationInfo = NULL;
1091
1092 VkGraphicsPipelineCreateInfo gp_ci = {};
1093 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1094 gp_ci.pNext = NULL;
1095 gp_ci.stageCount = 1;
1096 gp_ci.pStages = &pipe_vs_ci;
1097 gp_ci.pVertexInputState = NULL;
1098 gp_ci.pInputAssemblyState = NULL;
1099 gp_ci.pTessellationState = NULL;
1100 gp_ci.pViewportState = NULL;
1101 gp_ci.pRasterState = NULL;
1102 gp_ci.pMultisampleState = NULL;
1103 gp_ci.pDepthStencilState = NULL;
1104 gp_ci.pColorBlendState = NULL;
1105 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1106 gp_ci.layout = pipeline_layout;
1107
1108 VkPipelineCacheCreateInfo pc_ci = {};
1109 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1110 pc_ci.pNext = NULL;
1111 pc_ci.initialSize = 0;
1112 pc_ci.initialData = 0;
1113 pc_ci.maxSize = 0;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001114
1115 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001116 VkPipelineCache pipelineCache;
1117
1118 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1119 ASSERT_VK_SUCCESS(err);
1120 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001121 ASSERT_VK_SUCCESS(err);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001122 ASSERT_NO_FATAL_FAILURE(InitState());
1123 ASSERT_NO_FATAL_FAILURE(InitViewport());
1124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06001125
1126 BeginCommandBuffer();
1127 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1128 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001129
Tobin Ehlis254eca02015-06-25 15:46:59 -06001130 msgFlags = m_errorMonitor->GetState(&msgString);
1131 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not warn after binding a DescriptorSet that was never updated.";
1132 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1133 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1134 }
1135}
1136
1137TEST_F(VkLayerTest, NoBeginCmdBuffer)
1138{
1139 VkFlags msgFlags;
1140 std::string msgString;
1141
1142 ASSERT_NO_FATAL_FAILURE(InitState());
1143 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001144 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001145 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1146 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1147 msgFlags = m_errorMonitor->GetState(&msgString);
1148 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after ending a CmdBuffer w/o calling BeginCommandBuffer()";
1149 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1150 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1151 }
1152}
1153
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001154TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1155{
1156 VkFlags msgFlags;
1157 std::string msgString;
1158
1159 ASSERT_NO_FATAL_FAILURE(InitState());
1160 m_errorMonitor->ClearState();
1161
1162 // Calls CreateCommandBuffer
1163 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1164
1165 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northrop10d8f982015-08-04 17:35:57 -06001166 VkCmdBufferBeginInfo cmd_buf_info = {};
1167 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1168 cmd_buf_info.pNext = NULL;
1169 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1170 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1171 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1172 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1173
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001174
1175 // The error should be caught by validation of the BeginCommandBuffer call
1176 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1177
1178 msgFlags = m_errorMonitor->GetState(&msgString);
1179 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error passing a non-NULL Framebuffer and Renderpass to BeginCommandBuffer()";
1180 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1181 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1182 }
1183}
1184
1185TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1186{
1187 VkFlags msgFlags;
1188 std::string msgString;
1189 VkResult err;
1190 VkCmdBuffer draw_cmd;
1191 VkCmdPool cmd_pool;
1192
1193 ASSERT_NO_FATAL_FAILURE(InitState());
1194 m_errorMonitor->ClearState();
1195
Cody Northrop10d8f982015-08-04 17:35:57 -06001196 VkCmdBufferCreateInfo cmd = {};
1197 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1198 cmd.pNext = NULL;
1199 cmd.cmdPool = m_cmdPool;
1200 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1201 cmd.flags = 0;
1202
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001203 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
1204 assert(!err);
1205
1206 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northrop10d8f982015-08-04 17:35:57 -06001207 VkCmdBufferBeginInfo cmd_buf_info = {};
1208 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1209 cmd_buf_info.pNext = NULL;
1210 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1211 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001212
1213 // The error should be caught by validation of the BeginCommandBuffer call
1214 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1215
1216 msgFlags = m_errorMonitor->GetState(&msgString);
1217 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error passing NULL Framebuffer/Renderpass to BeginCommandBuffer()";
1218 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1219 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1220 }
1221}
1222
Tobin Ehlis254eca02015-06-25 15:46:59 -06001223TEST_F(VkLayerTest, InvalidPipelineCreateState)
1224{
1225 // Attempt to Create Gfx Pipeline w/o a VS
1226 VkFlags msgFlags;
1227 std::string msgString;
1228 VkResult err;
1229
1230 ASSERT_NO_FATAL_FAILURE(InitState());
1231 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001232
1233 VkDescriptorTypeCount ds_type_count = {};
1234 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1235 ds_type_count.count = 1;
1236
1237 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1238 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1239 ds_pool_ci.pNext = NULL;
1240 ds_pool_ci.count = 1;
1241 ds_pool_ci.pTypeCount = &ds_type_count;
1242
Tobin Ehlis254eca02015-06-25 15:46:59 -06001243 VkDescriptorPool ds_pool;
1244 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1245 ASSERT_VK_SUCCESS(err);
1246
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001247 VkDescriptorSetLayoutBinding dsl_binding = {};
1248 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1249 dsl_binding.arraySize = 1;
1250 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1251 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001252
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001253 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1254 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1255 ds_layout_ci.pNext = NULL;
1256 ds_layout_ci.count = 1;
1257 ds_layout_ci.pBinding = &dsl_binding;
1258
Tobin Ehlis254eca02015-06-25 15:46:59 -06001259 VkDescriptorSetLayout ds_layout;
1260 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1261 ASSERT_VK_SUCCESS(err);
1262
1263 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001264 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001265 ASSERT_VK_SUCCESS(err);
1266
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001267 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1268 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1269 pipeline_layout_ci.pNext = NULL;
1270 pipeline_layout_ci.descriptorSetCount = 1;
1271 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001272
1273 VkPipelineLayout pipeline_layout;
1274 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1275 ASSERT_VK_SUCCESS(err);
1276
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001277 VkGraphicsPipelineCreateInfo gp_ci = {};
1278 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1279 gp_ci.pNext = NULL;
1280 gp_ci.stageCount = 0;
1281 gp_ci.pStages = NULL;
1282 gp_ci.pVertexInputState = NULL;
1283 gp_ci.pInputAssemblyState = NULL;
1284 gp_ci.pTessellationState = NULL;
1285 gp_ci.pViewportState = NULL;
1286 gp_ci.pRasterState = NULL;
1287 gp_ci.pMultisampleState = NULL;
1288 gp_ci.pDepthStencilState = NULL;
1289 gp_ci.pColorBlendState = NULL;
1290 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1291 gp_ci.layout = pipeline_layout;
1292
1293 VkPipelineCacheCreateInfo pc_ci = {};
1294 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1295 pc_ci.pNext = NULL;
1296 pc_ci.initialSize = 0;
1297 pc_ci.initialData = 0;
1298 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001299
1300 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001301 VkPipelineCache pipelineCache;
1302
1303 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1304 ASSERT_VK_SUCCESS(err);
1305 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001306
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001307 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001308 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after creating Gfx Pipeline w/o VS.";
1309 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1310 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1311 }
1312}
1313
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001314TEST_F(VkLayerTest, NullRenderPass)
1315{
1316 // Bind a NULL RenderPass
1317 VkFlags msgFlags;
1318 std::string msgString;
1319
1320 ASSERT_NO_FATAL_FAILURE(InitState());
1321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1322 m_errorMonitor->ClearState();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001323
Tony Barbour1490c912015-07-28 10:17:20 -06001324 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001325 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06001326 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001327
1328 msgFlags = m_errorMonitor->GetState(&msgString);
1329 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding NULL RenderPass.";
1330 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
1331 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
1332 }
1333}
1334
Tobin Ehlis254eca02015-06-25 15:46:59 -06001335TEST_F(VkLayerTest, RenderPassWithinRenderPass)
1336{
1337 // Bind a BeginRenderPass within an active RenderPass
1338 VkFlags msgFlags;
1339 std::string msgString;
1340
1341 ASSERT_NO_FATAL_FAILURE(InitState());
1342 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1343 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001344
Tony Barbour1490c912015-07-28 10:17:20 -06001345 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001346 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001347 VkRenderPassBeginInfo rp_begin = {};
1348 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
1349 rp_begin.pNext = NULL;
1350 rp_begin.renderPass = (VkRenderPass)0xc001d00d;
1351 rp_begin.framebuffer = 0;
1352
Tony Barbour1490c912015-07-28 10:17:20 -06001353 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001354
1355 msgFlags = m_errorMonitor->GetState(&msgString);
1356 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding RenderPass w/i an active RenderPass.";
1357 if (!strstr(msgString.c_str(),"Cannot call vkCmdBeginRenderPass() during an active RenderPass ")) {
1358 FAIL() << "Error received was not 'Cannot call vkCmdBeginRenderPass() during an active RenderPass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001359 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001360}
1361
1362TEST_F(VkLayerTest, InvalidDynamicStateObject)
1363{
1364 // Create a valid cmd buffer
1365 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001366 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1367 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001368}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06001369
Tobin Ehlise4076782015-06-24 15:53:07 -06001370TEST_F(VkLayerTest, VtxBufferNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001371{
1372 // Bind VBO out-of-bounds for given PSO
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001373 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001374 std::string msgString;
1375 VkResult err;
1376
1377 ASSERT_NO_FATAL_FAILURE(InitState());
1378 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001379
1380 VkDescriptorTypeCount ds_type_count = {};
1381 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1382 ds_type_count.count = 1;
1383
1384 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1385 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1386 ds_pool_ci.pNext = NULL;
1387 ds_pool_ci.count = 1;
1388 ds_pool_ci.pTypeCount = &ds_type_count;
1389
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001390 VkDescriptorPool ds_pool;
1391 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1392 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001393
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001394 VkDescriptorSetLayoutBinding dsl_binding = {};
1395 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1396 dsl_binding.arraySize = 1;
1397 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1398 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001399
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001400 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1401 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1402 ds_layout_ci.pNext = NULL;
1403 ds_layout_ci.count = 1;
1404 ds_layout_ci.pBinding = &dsl_binding;
1405
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001406 VkDescriptorSetLayout ds_layout;
1407 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1408 ASSERT_VK_SUCCESS(err);
1409
1410 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001411 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001412 ASSERT_VK_SUCCESS(err);
1413
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001414 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1415 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1416 pipeline_layout_ci.pNext = NULL;
1417 pipeline_layout_ci.descriptorSetCount = 1;
1418 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001419
1420 VkPipelineLayout pipeline_layout;
1421 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1422 ASSERT_VK_SUCCESS(err);
1423
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001424 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001425
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001426 VkPipelineShaderStageCreateInfo pipe_vs_ci = {};
1427 pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1428 pipe_vs_ci.pNext = NULL;
1429 pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX;
1430 pipe_vs_ci.shader = vs.handle();
1431 pipe_vs_ci.pSpecializationInfo = NULL;
1432
1433 VkGraphicsPipelineCreateInfo gp_ci = {};
1434 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1435 gp_ci.pNext = NULL;
1436 gp_ci.stageCount = 1;
1437 gp_ci.pStages = &pipe_vs_ci;
1438 gp_ci.pVertexInputState = NULL;
1439 gp_ci.pInputAssemblyState = NULL;
1440 gp_ci.pTessellationState = NULL;
1441 gp_ci.pViewportState = NULL;
1442 gp_ci.pRasterState = NULL;
1443 gp_ci.pMultisampleState = NULL;
1444 gp_ci.pDepthStencilState = NULL;
1445 gp_ci.pColorBlendState = NULL;
1446 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1447 gp_ci.layout = pipeline_layout;
1448
1449 VkPipelineCacheCreateInfo pc_ci = {};
1450 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1451 pc_ci.pNext = NULL;
1452 pc_ci.initialSize = 0;
1453 pc_ci.initialData = 0;
1454 pc_ci.maxSize = 0;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001455
1456 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001457 VkPipelineCache pipelineCache;
1458
1459 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1460 ASSERT_VK_SUCCESS(err);
1461 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001462 ASSERT_VK_SUCCESS(err);
1463
Tony Barbour1490c912015-07-28 10:17:20 -06001464 BeginCommandBuffer();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001465 ASSERT_VK_SUCCESS(err);
Tony Barbour1490c912015-07-28 10:17:20 -06001466 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001467 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06001468 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001469
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001470 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlise4076782015-06-24 15:53:07 -06001471 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
1472 if (!strstr(msgString.c_str(),"Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.")) {
1473 FAIL() << "Error received was not 'Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001474 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001475}
1476
1477TEST_F(VkLayerTest, DSTypeMismatch)
1478{
1479 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001480 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001481 std::string msgString;
1482 VkResult err;
1483
1484 ASSERT_NO_FATAL_FAILURE(InitState());
1485 m_errorMonitor->ClearState();
1486 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001487 VkDescriptorTypeCount ds_type_count = {};
1488 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1489 ds_type_count.count = 1;
1490
1491 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1492 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1493 ds_pool_ci.pNext = NULL;
1494 ds_pool_ci.count = 1;
1495 ds_pool_ci.pTypeCount = &ds_type_count;
1496
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001497 VkDescriptorPool ds_pool;
1498 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1499 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001500 VkDescriptorSetLayoutBinding dsl_binding = {};
1501 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1502 dsl_binding.arraySize = 1;
1503 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1504 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001505
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001506 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1507 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1508 ds_layout_ci.pNext = NULL;
1509 ds_layout_ci.count = 1;
1510 ds_layout_ci.pBinding = &dsl_binding;
1511
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001512 VkDescriptorSetLayout ds_layout;
1513 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1514 ASSERT_VK_SUCCESS(err);
1515
1516 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001517 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001518 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001519
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001520 VkSamplerCreateInfo sampler_ci = {};
1521 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1522 sampler_ci.pNext = NULL;
1523 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1524 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1525 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1526 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1527 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1528 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1529 sampler_ci.mipLodBias = 1.0;
1530 sampler_ci.maxAnisotropy = 1;
1531 sampler_ci.compareEnable = VK_FALSE;
1532 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1533 sampler_ci.minLod = 1.0;
1534 sampler_ci.maxLod = 1.0;
1535 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1536
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001537 VkSampler sampler;
1538 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1539 ASSERT_VK_SUCCESS(err);
1540
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001541 VkDescriptorInfo descriptor_info;
1542 memset(&descriptor_info, 0, sizeof(descriptor_info));
1543 descriptor_info.sampler = sampler;
1544
1545 VkWriteDescriptorSet descriptor_write;
1546 memset(&descriptor_write, 0, sizeof(descriptor_write));
1547 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1548 descriptor_write.destSet = descriptorSet;
1549 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001550 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001551 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1552 descriptor_write.pDescriptors = &descriptor_info;
1553
1554 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1555
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001556 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001557 ASSERT_TRUE(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 +08001558 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) {
1559 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 -06001560 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001561}
1562
1563TEST_F(VkLayerTest, DSUpdateOutOfBounds)
1564{
1565 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001566 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001567 std::string msgString;
1568 VkResult err;
1569
1570 ASSERT_NO_FATAL_FAILURE(InitState());
1571 m_errorMonitor->ClearState();
1572 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001573 VkDescriptorTypeCount ds_type_count = {};
1574 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1575 ds_type_count.count = 1;
1576
1577 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1578 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1579 ds_pool_ci.pNext = NULL;
1580 ds_pool_ci.count = 1;
1581 ds_pool_ci.pTypeCount = &ds_type_count;
1582
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001583 VkDescriptorPool ds_pool;
1584 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1585 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001586
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001587 VkDescriptorSetLayoutBinding dsl_binding = {};
1588 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1589 dsl_binding.arraySize = 1;
1590 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1591 dsl_binding.pImmutableSamplers = NULL;
1592
1593 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1594 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1595 ds_layout_ci.pNext = NULL;
1596 ds_layout_ci.count = 1;
1597 ds_layout_ci.pBinding = &dsl_binding;
1598
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001599 VkDescriptorSetLayout ds_layout;
1600 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1601 ASSERT_VK_SUCCESS(err);
1602
1603 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001604 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001605 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001606
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001607 VkSamplerCreateInfo sampler_ci = {};
1608 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1609 sampler_ci.pNext = NULL;
1610 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1611 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1612 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1613 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1614 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1615 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1616 sampler_ci.mipLodBias = 1.0;
1617 sampler_ci.maxAnisotropy = 1;
1618 sampler_ci.compareEnable = VK_FALSE;
1619 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1620 sampler_ci.minLod = 1.0;
1621 sampler_ci.maxLod = 1.0;
1622 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1623
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001624 VkSampler sampler;
1625 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1626 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001627
1628 VkDescriptorInfo descriptor_info;
1629 memset(&descriptor_info, 0, sizeof(descriptor_info));
1630 descriptor_info.sampler = sampler;
1631
1632 VkWriteDescriptorSet descriptor_write;
1633 memset(&descriptor_write, 0, sizeof(descriptor_write));
1634 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1635 descriptor_write.destSet = descriptorSet;
1636 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
1637 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001638 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001639 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1640 descriptor_write.pDescriptors = &descriptor_info;
1641
1642 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1643
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001644 msgFlags = m_errorMonitor->GetState(&msgString);
1645 ASSERT_TRUE(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 +08001646 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
1647 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 -06001648 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001649}
1650
1651TEST_F(VkLayerTest, InvalidDSUpdateIndex)
1652{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001653 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001654 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001655 std::string msgString;
1656 VkResult err;
1657
1658 ASSERT_NO_FATAL_FAILURE(InitState());
1659 m_errorMonitor->ClearState();
1660 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001661 VkDescriptorTypeCount ds_type_count = {};
1662 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1663 ds_type_count.count = 1;
1664
1665 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1666 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1667 ds_pool_ci.pNext = NULL;
1668 ds_pool_ci.count = 1;
1669 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001670 VkDescriptorPool ds_pool;
1671 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1672 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001673
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001674 VkDescriptorSetLayoutBinding dsl_binding = {};
1675 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1676 dsl_binding.arraySize = 1;
1677 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1678 dsl_binding.pImmutableSamplers = NULL;
1679
1680 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1681 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1682 ds_layout_ci.pNext = NULL;
1683 ds_layout_ci.count = 1;
1684 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001685 VkDescriptorSetLayout ds_layout;
1686 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1687 ASSERT_VK_SUCCESS(err);
1688
1689 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001690 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001691 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001692
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001693 VkSamplerCreateInfo sampler_ci = {};
1694 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1695 sampler_ci.pNext = NULL;
1696 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1697 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1698 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1699 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1700 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1701 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1702 sampler_ci.mipLodBias = 1.0;
1703 sampler_ci.maxAnisotropy = 1;
1704 sampler_ci.compareEnable = VK_FALSE;
1705 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1706 sampler_ci.minLod = 1.0;
1707 sampler_ci.maxLod = 1.0;
1708 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1709
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001710 VkSampler sampler;
1711 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1712 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001713
1714 VkDescriptorInfo descriptor_info;
1715 memset(&descriptor_info, 0, sizeof(descriptor_info));
1716 descriptor_info.sampler = sampler;
1717
1718 VkWriteDescriptorSet descriptor_write;
1719 memset(&descriptor_write, 0, sizeof(descriptor_write));
1720 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1721 descriptor_write.destSet = descriptorSet;
1722 descriptor_write.destBinding = 2;
1723 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001724 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001725 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1726 descriptor_write.pDescriptors = &descriptor_info;
1727
1728 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1729
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001730 msgFlags = m_errorMonitor->GetState(&msgString);
1731 ASSERT_TRUE(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 -06001732 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
1733 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
1734 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001735}
1736
1737TEST_F(VkLayerTest, InvalidDSUpdateStruct)
1738{
1739 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001740 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001741 std::string msgString;
1742 VkResult err;
1743
1744 ASSERT_NO_FATAL_FAILURE(InitState());
1745 m_errorMonitor->ClearState();
1746 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001747
1748 VkDescriptorTypeCount ds_type_count = {};
1749 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1750 ds_type_count.count = 1;
1751
1752 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1753 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1754 ds_pool_ci.pNext = NULL;
1755 ds_pool_ci.count = 1;
1756 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001757 VkDescriptorPool ds_pool;
1758 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1759 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001760 VkDescriptorSetLayoutBinding dsl_binding = {};
1761 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1762 dsl_binding.arraySize = 1;
1763 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1764 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001765
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001766 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1767 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1768 ds_layout_ci.pNext = NULL;
1769 ds_layout_ci.count = 1;
1770 ds_layout_ci.pBinding = &dsl_binding;
1771
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001772 VkDescriptorSetLayout ds_layout;
1773 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1774 ASSERT_VK_SUCCESS(err);
1775
1776 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001777 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001778 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001779
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001780 VkSamplerCreateInfo sampler_ci = {};
1781 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1782 sampler_ci.pNext = NULL;
1783 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1784 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1785 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1786 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1787 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1788 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1789 sampler_ci.mipLodBias = 1.0;
1790 sampler_ci.maxAnisotropy = 1;
1791 sampler_ci.compareEnable = VK_FALSE;
1792 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1793 sampler_ci.minLod = 1.0;
1794 sampler_ci.maxLod = 1.0;
1795 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001796 VkSampler sampler;
1797 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1798 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001799
1800
1801 VkDescriptorInfo descriptor_info;
1802 memset(&descriptor_info, 0, sizeof(descriptor_info));
1803 descriptor_info.sampler = sampler;
1804
1805 VkWriteDescriptorSet descriptor_write;
1806 memset(&descriptor_write, 0, sizeof(descriptor_write));
1807 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
1808 descriptor_write.destSet = descriptorSet;
1809 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001810 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001811 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1812 descriptor_write.pDescriptors = &descriptor_info;
1813
1814 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1815
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001816 msgFlags = m_errorMonitor->GetState(&msgString);
1817 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after updating Descriptor w/ invalid struct type.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001818 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
1819 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
1820 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001821}
1822
1823TEST_F(VkLayerTest, NumSamplesMismatch)
1824{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001825 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001826 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001827 std::string msgString;
1828 VkResult err;
1829
1830 ASSERT_NO_FATAL_FAILURE(InitState());
1831 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1832 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001833 VkDescriptorTypeCount ds_type_count = {};
1834 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1835 ds_type_count.count = 1;
1836
1837 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1838 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1839 ds_pool_ci.pNext = NULL;
1840 ds_pool_ci.count = 1;
1841 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001842 VkDescriptorPool ds_pool;
1843 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1844 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001845
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001846 VkDescriptorSetLayoutBinding dsl_binding = {};
1847 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1848 dsl_binding.arraySize = 1;
1849 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1850 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001851
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001852 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1853 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1854 ds_layout_ci.pNext = NULL;
1855 ds_layout_ci.count = 1;
1856 ds_layout_ci.pBinding = &dsl_binding;
1857
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001858 VkDescriptorSetLayout ds_layout;
1859 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1860 ASSERT_VK_SUCCESS(err);
1861
1862 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001863 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001864 ASSERT_VK_SUCCESS(err);
1865
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001866 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1867 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1868 pipe_ms_state_ci.pNext = NULL;
1869 pipe_ms_state_ci.rasterSamples = 4;
1870 pipe_ms_state_ci.sampleShadingEnable = 0;
1871 pipe_ms_state_ci.minSampleShading = 1.0;
1872 pipe_ms_state_ci.sampleMask = 15;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001873
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001874 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1875 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1876 pipeline_layout_ci.pNext = NULL;
1877 pipeline_layout_ci.descriptorSetCount = 1;
1878 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001879
1880 VkPipelineLayout pipeline_layout;
1881 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1882 ASSERT_VK_SUCCESS(err);
1883
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001884 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001885 VkPipelineShaderStageCreateInfo pipe_vs_ci = {};
1886 pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1887 pipe_vs_ci.pNext = NULL;
1888 pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX;
1889 pipe_vs_ci.shader = vs.handle();
1890 pipe_vs_ci.pSpecializationInfo = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001891
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001892 VkGraphicsPipelineCreateInfo gp_ci = {};
1893 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1894 gp_ci.pNext = NULL;
1895 gp_ci.stageCount = 1;
1896 gp_ci.pStages = &pipe_vs_ci;
1897 gp_ci.pVertexInputState = NULL;
1898 gp_ci.pInputAssemblyState = NULL;
1899 gp_ci.pTessellationState = NULL;
1900 gp_ci.pViewportState = NULL;
1901 gp_ci.pRasterState = NULL;
1902 gp_ci.pMultisampleState = &pipe_ms_state_ci;
1903 gp_ci.pDepthStencilState = NULL;
1904 gp_ci.pColorBlendState = NULL;
1905 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1906 gp_ci.layout = pipeline_layout;
1907
1908 VkPipelineCacheCreateInfo pc_ci = {};
1909 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1910 pc_ci.pNext = NULL;
1911 pc_ci.initialSize = 0;
1912 pc_ci.initialData = 0;
1913 pc_ci.maxSize = 0;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001914
1915 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001916 VkPipelineCache pipelineCache;
1917
1918 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1919 ASSERT_VK_SUCCESS(err);
1920 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001921 ASSERT_VK_SUCCESS(err);
1922
Tony Barbour1490c912015-07-28 10:17:20 -06001923 BeginCommandBuffer();
1924 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001925
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001926 msgFlags = m_errorMonitor->GetState(&msgString);
1927 ASSERT_TRUE(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 -06001928 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
1929 FAIL() << "Error received was not 'Num samples mismatch!...'";
1930 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001931}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001932
Tobin Ehlise4076782015-06-24 15:53:07 -06001933TEST_F(VkLayerTest, PipelineNotBound)
1934{
1935 VkFlags msgFlags;
1936 std::string msgString;
1937 VkResult err;
1938
1939 ASSERT_NO_FATAL_FAILURE(InitState());
1940 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1941 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001942
1943 VkDescriptorTypeCount ds_type_count = {};
1944 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1945 ds_type_count.count = 1;
1946
1947 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1948 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1949 ds_pool_ci.pNext = NULL;
1950 ds_pool_ci.count = 1;
1951 ds_pool_ci.pTypeCount = &ds_type_count;
1952
Tobin Ehlise4076782015-06-24 15:53:07 -06001953 VkDescriptorPool ds_pool;
1954 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1955 ASSERT_VK_SUCCESS(err);
1956
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001957 VkDescriptorSetLayoutBinding dsl_binding = {};
1958 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1959 dsl_binding.arraySize = 1;
1960 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1961 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06001962
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001963 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1964 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1965 ds_layout_ci.pNext = NULL;
1966 ds_layout_ci.count = 1;
1967 ds_layout_ci.pBinding = &dsl_binding;
1968
Tobin Ehlise4076782015-06-24 15:53:07 -06001969 VkDescriptorSetLayout ds_layout;
1970 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1971 ASSERT_VK_SUCCESS(err);
1972
1973 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001974 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06001975 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001976
1977 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1978 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1979 pipeline_layout_ci.pNext = NULL;
1980 pipeline_layout_ci.descriptorSetCount = 1;
1981 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06001982
1983 VkPipelineLayout pipeline_layout;
1984 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1985 ASSERT_VK_SUCCESS(err);
1986
Tobin Ehlise4076782015-06-24 15:53:07 -06001987 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1988 //err = vkCreateGraphicsPipeline(m_device->device(), &gp_ci, &pipeline);
1989 ASSERT_VK_SUCCESS(err);
1990
Tony Barbour1490c912015-07-28 10:17:20 -06001991
1992 BeginCommandBuffer();
1993 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06001994
1995 msgFlags = m_errorMonitor->GetState(&msgString);
1996 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding invalid pipeline to CmdBuffer";
1997 if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1998 FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1999 }
2000}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002001
2002TEST_F(VkLayerTest, ClearCmdNoDraw)
2003{
2004 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
2005 VkFlags msgFlags;
2006 std::string msgString;
2007 VkResult err;
2008
2009 ASSERT_NO_FATAL_FAILURE(InitState());
2010 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2011 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002012
2013 VkDescriptorTypeCount ds_type_count = {};
2014 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2015 ds_type_count.count = 1;
2016
2017 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2018 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2019 ds_pool_ci.pNext = NULL;
2020 ds_pool_ci.count = 1;
2021 ds_pool_ci.pTypeCount = &ds_type_count;
2022
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002023 VkDescriptorPool ds_pool;
2024 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
2025 ASSERT_VK_SUCCESS(err);
2026
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002027 VkDescriptorSetLayoutBinding dsl_binding = {};
2028 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2029 dsl_binding.arraySize = 1;
2030 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2031 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002032
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002033 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2034 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2035 ds_layout_ci.pNext = NULL;
2036 ds_layout_ci.count = 1;
2037 ds_layout_ci.pBinding = &dsl_binding;
2038
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002039 VkDescriptorSetLayout ds_layout;
2040 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2041 ASSERT_VK_SUCCESS(err);
2042
2043 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002044 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002045 ASSERT_VK_SUCCESS(err);
2046
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002047 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2048 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2049 pipe_ms_state_ci.pNext = NULL;
2050 pipe_ms_state_ci.rasterSamples = 4;
2051 pipe_ms_state_ci.sampleShadingEnable = 0;
2052 pipe_ms_state_ci.minSampleShading = 1.0;
2053 pipe_ms_state_ci.sampleMask = 15;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002054
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002055 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2056 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2057 pipeline_layout_ci.pNext = NULL;
2058 pipeline_layout_ci.descriptorSetCount = 1;
2059 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002060
2061 VkPipelineLayout pipeline_layout;
2062 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2063 ASSERT_VK_SUCCESS(err);
2064
2065 size_t shader_len = strlen(bindStateVertShaderText);
2066 size_t codeSize = 3 * sizeof(uint32_t) + shader_len + 1;
2067 void* pCode = malloc(codeSize);
2068
2069 /* try version 0 first: VkShaderStage followed by GLSL */
2070 ((uint32_t *) pCode)[0] = ICD_SPV_MAGIC;
2071 ((uint32_t *) pCode)[1] = 0;
2072 ((uint32_t *) pCode)[2] = VK_SHADER_STAGE_VERTEX;
2073 memcpy(((uint32_t *) pCode + 3), bindStateVertShaderText, shader_len + 1);
2074
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002075 VkShaderModuleCreateInfo smci = {};
2076 smci.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2077 smci.pNext = NULL;
2078 smci.codeSize = codeSize;
2079 smci.pCode = pCode;
2080 smci.flags = 0;
2081
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002082 VkShaderModule vksm;
2083 err = vkCreateShaderModule(m_device->device(), &smci, &vksm);
2084 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002085 VkShaderCreateInfo vs_ci = {};
2086 vs_ci.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
2087 vs_ci.pNext = NULL;
2088 vs_ci.module = vksm;
2089 vs_ci.pName = "main";
2090 vs_ci.flags = 0;
2091
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002092 VkShader vs;
2093 err = vkCreateShader(m_device->device(), &vs_ci, &vs);
2094 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002095 VkPipelineShaderStageCreateInfo pipe_vs_ci = {};
2096 pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2097 pipe_vs_ci.pNext = NULL;
2098 pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX;
2099 pipe_vs_ci.shader = vs;
2100 pipe_vs_ci.pSpecializationInfo = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002101
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002102 VkGraphicsPipelineCreateInfo gp_ci = {};
2103 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2104 gp_ci.pNext = NULL;
2105 gp_ci.stageCount = 1;
2106 gp_ci.pStages = &pipe_vs_ci;
2107 gp_ci.pVertexInputState = NULL;
2108 gp_ci.pInputAssemblyState = NULL;
2109 gp_ci.pTessellationState = NULL;
2110 gp_ci.pViewportState = NULL;
2111 gp_ci.pRasterState = NULL;
2112 gp_ci.pMultisampleState = &pipe_ms_state_ci;
2113 gp_ci.pDepthStencilState = NULL;
2114 gp_ci.pColorBlendState = NULL;
2115 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2116 gp_ci.layout = pipeline_layout;
2117
2118 VkPipelineCacheCreateInfo pc_ci = {};
2119 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2120 pc_ci.pNext = NULL;
2121 pc_ci.initialSize = 0;
2122 pc_ci.initialData = 0;
2123 pc_ci.maxSize = 0;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002124
2125 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06002126 VkPipelineCache pipelineCache;
2127
2128 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2129 ASSERT_VK_SUCCESS(err);
2130 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002131 ASSERT_VK_SUCCESS(err);
2132
Tony Barbour1490c912015-07-28 10:17:20 -06002133
2134 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002135
2136 m_errorMonitor->ClearState();
2137 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
2138 // Also pass down other dummy params to keep driver and paramchecker happy
2139 VkClearColorValue cCV;
2140 cCV.f32[0] = 1.0;
2141 cCV.f32[1] = 1.0;
2142 cCV.f32[2] = 1.0;
2143 cCV.f32[3] = 1.0;
2144
Tony Barbour1490c912015-07-28 10:17:20 -06002145 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002146 msgFlags = m_errorMonitor->GetState(&msgString);
2147 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not receive error after issuing Clear Cmd on FB color attachment prior to Draw Cmd.";
2148 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) {
2149 FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'";
2150 }
2151}
2152
Tobin Ehlise4076782015-06-24 15:53:07 -06002153TEST_F(VkLayerTest, VtxBufferBadIndex)
2154{
2155 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
2156 VkFlags msgFlags;
2157 std::string msgString;
2158 VkResult err;
2159
2160 ASSERT_NO_FATAL_FAILURE(InitState());
2161 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2162 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002163
2164 VkDescriptorTypeCount ds_type_count = {};
2165 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2166 ds_type_count.count = 1;
2167
2168 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2169 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2170 ds_pool_ci.pNext = NULL;
2171 ds_pool_ci.count = 1;
2172 ds_pool_ci.pTypeCount = &ds_type_count;
2173
2174 VkDescriptorPool ds_pool;
Tobin Ehlise4076782015-06-24 15:53:07 -06002175 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
2176 ASSERT_VK_SUCCESS(err);
2177
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002178 VkDescriptorSetLayoutBinding dsl_binding = {};
2179 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2180 dsl_binding.arraySize = 1;
2181 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2182 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002183
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002184 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2185 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2186 ds_layout_ci.pNext = NULL;
2187 ds_layout_ci.count = 1;
2188 ds_layout_ci.pBinding = &dsl_binding;
2189
Tobin Ehlise4076782015-06-24 15:53:07 -06002190 VkDescriptorSetLayout ds_layout;
2191 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2192 ASSERT_VK_SUCCESS(err);
2193
2194 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002195 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06002196 ASSERT_VK_SUCCESS(err);
2197
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002198 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2199 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2200 pipe_ms_state_ci.pNext = NULL;
2201 pipe_ms_state_ci.rasterSamples = 1;
2202 pipe_ms_state_ci.sampleShadingEnable = 0;
2203 pipe_ms_state_ci.minSampleShading = 1.0;
2204 pipe_ms_state_ci.sampleMask = 15;
Tobin Ehlise4076782015-06-24 15:53:07 -06002205
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002206 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2207 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2208 pipeline_layout_ci.pNext = NULL;
2209 pipeline_layout_ci.descriptorSetCount = 1;
2210 pipeline_layout_ci.pSetLayouts = &ds_layout;
2211 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06002212
Tobin Ehlise4076782015-06-24 15:53:07 -06002213 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2214 ASSERT_VK_SUCCESS(err);
2215
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002216 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tobin Ehlise4076782015-06-24 15:53:07 -06002217
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002218 VkPipelineShaderStageCreateInfo pipe_vs_ci = {};
2219 pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2220 pipe_vs_ci.pNext = NULL;
2221 pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX;
2222 pipe_vs_ci.shader = vs.handle();
2223 pipe_vs_ci.pSpecializationInfo = NULL;
2224
2225 VkGraphicsPipelineCreateInfo gp_ci = {};
2226 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2227 gp_ci.pNext = NULL;
2228 gp_ci.stageCount = 1;
2229 gp_ci.pStages = &pipe_vs_ci;
2230 gp_ci.pVertexInputState = NULL;
2231 gp_ci.pInputAssemblyState = NULL;
2232 gp_ci.pTessellationState = NULL;
2233 gp_ci.pViewportState = NULL;
2234 gp_ci.pRasterState = NULL;
2235 gp_ci.pMultisampleState = &pipe_ms_state_ci;
2236 gp_ci.pDepthStencilState = NULL;
2237 gp_ci.pColorBlendState = NULL;
2238 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2239 gp_ci.layout = pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06002240
Courtney Goeltzenleuchtercdf5e832015-07-10 09:21:02 -06002241 VkPipelineCacheCreateInfo pipelineCache;
2242 VkPipelineCache pipeline_cache;
2243
2244 memset(&pipelineCache, 0, sizeof(pipelineCache));
2245 pipelineCache.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2246 err = vkCreatePipelineCache(m_device->device(), &pipelineCache, &pipeline_cache);
2247
Tobin Ehlise4076782015-06-24 15:53:07 -06002248 VkPipeline pipeline;
Courtney Goeltzenleuchtercdf5e832015-07-10 09:21:02 -06002249 err = vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &gp_ci, &pipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06002250 ASSERT_VK_SUCCESS(err);
2251
Tony Barbour1490c912015-07-28 10:17:20 -06002252
2253 BeginCommandBuffer();
2254 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06002255 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06002256 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlise4076782015-06-24 15:53:07 -06002257
2258 msgFlags = m_errorMonitor->GetState(&msgString);
2259 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding Vtx Buffer w/o VBO attached to PSO.";
2260 if (!strstr(msgString.c_str(),"Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.")) {
2261 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
2262 }
2263}
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002264#endif
2265#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06002266#if GTEST_IS_THREADSAFE
2267struct thread_data_struct {
2268 VkCmdBuffer cmdBuffer;
2269 VkEvent event;
2270 bool bailout;
2271};
2272
2273extern "C" void *AddToCommandBuffer(void *arg)
2274{
2275 struct thread_data_struct *data = (struct thread_data_struct *) arg;
2276 std::string msgString;
2277
2278 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06002279 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06002280 if (data->bailout) {
2281 break;
2282 }
2283 }
2284 return NULL;
2285}
2286
2287TEST_F(VkLayerTest, ThreadCmdBufferCollision)
2288{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002289 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06002290 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002291 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06002292
2293 ASSERT_NO_FATAL_FAILURE(InitState());
2294 ASSERT_NO_FATAL_FAILURE(InitViewport());
2295 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2296
Mike Stroyan09aae812015-05-12 16:00:45 -06002297 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06002298 BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002299
2300 VkEventCreateInfo event_info;
2301 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06002302 VkResult err;
2303
2304 memset(&event_info, 0, sizeof(event_info));
2305 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2306
2307 err = vkCreateEvent(device(), &event_info, &event);
2308 ASSERT_VK_SUCCESS(err);
2309
Mike Stroyan09aae812015-05-12 16:00:45 -06002310 err = vkResetEvent(device(), event);
2311 ASSERT_VK_SUCCESS(err);
2312
2313 struct thread_data_struct data;
Tony Barbour1490c912015-07-28 10:17:20 -06002314 data.cmdBuffer = m_cmdBuffer->handle();
Mike Stroyan09aae812015-05-12 16:00:45 -06002315 data.event = event;
2316 data.bailout = false;
2317 m_errorMonitor->SetBailout(&data.bailout);
2318 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002319 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06002320 // Add many entries to command buffer from this thread at the same time.
2321 AddToCommandBuffer(&data);
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002322 test_platform_thread_join(thread, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -06002323 EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002324
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002325 msgFlags = m_errorMonitor->GetState(&msgString);
Mike Stroyaned254572015-06-17 16:32:06 -06002326 ASSERT_TRUE(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 -06002327 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05002328 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06002329 }
2330
2331}
2332#endif
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002333#endif
Chris Forbes5af3bf22015-05-25 11:13:08 +12002334#if SHADER_CHECKER_TESTS
2335TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
2336{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002337 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12002338 std::string msgString;
2339 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002340 ScopedUseGlsl useGlsl(false);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002341
2342 char const *vsSource =
2343 "#version 140\n"
2344 "#extension GL_ARB_separate_shader_objects: require\n"
2345 "#extension GL_ARB_shading_language_420pack: require\n"
2346 "\n"
2347 "layout(location=0) out float x;\n"
2348 "void main(){\n"
2349 " gl_Position = vec4(1);\n"
2350 " x = 0;\n"
2351 "}\n";
2352 char const *fsSource =
2353 "#version 140\n"
2354 "#extension GL_ARB_separate_shader_objects: require\n"
2355 "#extension GL_ARB_shading_language_420pack: require\n"
2356 "\n"
2357 "layout(location=0) out vec4 color;\n"
2358 "void main(){\n"
2359 " color = vec4(1);\n"
2360 "}\n";
2361
2362 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2363 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2364
2365 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002366 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12002367 pipe.AddShader(&vs);
2368 pipe.AddShader(&fs);
2369
Chris Forbes5af3bf22015-05-25 11:13:08 +12002370 VkDescriptorSetObj descriptorSet(m_device);
2371 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002372 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002373
2374 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002375 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12002376
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002377 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002378
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002379 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002380 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
2381 FAIL() << "Incorrect warning: " << msgString;
2382 }
2383}
Chris Forbes5af3bf22015-05-25 11:13:08 +12002384
Chris Forbes3c10b852015-05-25 11:13:13 +12002385TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
2386{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002387 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12002388 std::string msgString;
2389 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002390 ScopedUseGlsl useGlsl(false);
Chris Forbes3c10b852015-05-25 11:13:13 +12002391
2392 char const *vsSource =
2393 "#version 140\n"
2394 "#extension GL_ARB_separate_shader_objects: require\n"
2395 "#extension GL_ARB_shading_language_420pack: require\n"
2396 "\n"
2397 "void main(){\n"
2398 " gl_Position = vec4(1);\n"
2399 "}\n";
2400 char const *fsSource =
2401 "#version 140\n"
2402 "#extension GL_ARB_separate_shader_objects: require\n"
2403 "#extension GL_ARB_shading_language_420pack: require\n"
2404 "\n"
2405 "layout(location=0) in float x;\n"
2406 "layout(location=0) out vec4 color;\n"
2407 "void main(){\n"
2408 " color = vec4(x);\n"
2409 "}\n";
2410
2411 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2412 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2413
2414 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002415 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12002416 pipe.AddShader(&vs);
2417 pipe.AddShader(&fs);
2418
Chris Forbes3c10b852015-05-25 11:13:13 +12002419 VkDescriptorSetObj descriptorSet(m_device);
2420 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002421 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12002422
2423 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002424 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12002425
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002426 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12002427
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002428 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes3c10b852015-05-25 11:13:13 +12002429 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
2430 FAIL() << "Incorrect error: " << msgString;
2431 }
2432}
2433
Chris Forbescc281692015-05-25 11:13:17 +12002434TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
2435{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002436 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12002437 std::string msgString;
2438 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002439 ScopedUseGlsl useGlsl(false);
Chris Forbescc281692015-05-25 11:13:17 +12002440
2441 char const *vsSource =
2442 "#version 140\n"
2443 "#extension GL_ARB_separate_shader_objects: require\n"
2444 "#extension GL_ARB_shading_language_420pack: require\n"
2445 "\n"
2446 "layout(location=0) out int x;\n"
2447 "void main(){\n"
2448 " x = 0;\n"
2449 " gl_Position = vec4(1);\n"
2450 "}\n";
2451 char const *fsSource =
2452 "#version 140\n"
2453 "#extension GL_ARB_separate_shader_objects: require\n"
2454 "#extension GL_ARB_shading_language_420pack: require\n"
2455 "\n"
2456 "layout(location=0) in float x;\n" /* VS writes int */
2457 "layout(location=0) out vec4 color;\n"
2458 "void main(){\n"
2459 " color = vec4(x);\n"
2460 "}\n";
2461
2462 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2463 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2464
2465 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002466 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12002467 pipe.AddShader(&vs);
2468 pipe.AddShader(&fs);
2469
Chris Forbescc281692015-05-25 11:13:17 +12002470 VkDescriptorSetObj descriptorSet(m_device);
2471 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002472 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12002473
2474 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002475 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12002476
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002477 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12002478
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002479 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbescc281692015-05-25 11:13:17 +12002480 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
2481 FAIL() << "Incorrect error: " << msgString;
2482 }
2483}
2484
Chris Forbes8291c052015-05-25 11:13:28 +12002485TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
2486{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002487 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12002488 std::string msgString;
2489 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002490 ScopedUseGlsl useGlsl(false);
Chris Forbes8291c052015-05-25 11:13:28 +12002491
2492 VkVertexInputBindingDescription input_binding;
2493 memset(&input_binding, 0, sizeof(input_binding));
2494
2495 VkVertexInputAttributeDescription input_attrib;
2496 memset(&input_attrib, 0, sizeof(input_attrib));
2497 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2498
2499 char const *vsSource =
2500 "#version 140\n"
2501 "#extension GL_ARB_separate_shader_objects: require\n"
2502 "#extension GL_ARB_shading_language_420pack: require\n"
2503 "\n"
2504 "void main(){\n"
2505 " gl_Position = vec4(1);\n"
2506 "}\n";
2507 char const *fsSource =
2508 "#version 140\n"
2509 "#extension GL_ARB_separate_shader_objects: require\n"
2510 "#extension GL_ARB_shading_language_420pack: require\n"
2511 "\n"
2512 "layout(location=0) out vec4 color;\n"
2513 "void main(){\n"
2514 " color = vec4(1);\n"
2515 "}\n";
2516
2517 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2518 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2519
2520 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002521 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12002522 pipe.AddShader(&vs);
2523 pipe.AddShader(&fs);
2524
2525 pipe.AddVertexInputBindings(&input_binding, 1);
2526 pipe.AddVertexInputAttribs(&input_attrib, 1);
2527
Chris Forbes8291c052015-05-25 11:13:28 +12002528 VkDescriptorSetObj descriptorSet(m_device);
2529 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002530 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12002531
2532 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002533 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12002534
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002535 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12002536
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002537 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12002538 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
2539 FAIL() << "Incorrect warning: " << msgString;
2540 }
2541}
2542
Chris Forbes37367e62015-05-25 11:13:29 +12002543TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
2544{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002545 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12002546 std::string msgString;
2547 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002548 ScopedUseGlsl useGlsl(false);
Chris Forbes37367e62015-05-25 11:13:29 +12002549
2550 char const *vsSource =
2551 "#version 140\n"
2552 "#extension GL_ARB_separate_shader_objects: require\n"
2553 "#extension GL_ARB_shading_language_420pack: require\n"
2554 "\n"
2555 "layout(location=0) in vec4 x;\n" /* not provided */
2556 "void main(){\n"
2557 " gl_Position = x;\n"
2558 "}\n";
2559 char const *fsSource =
2560 "#version 140\n"
2561 "#extension GL_ARB_separate_shader_objects: require\n"
2562 "#extension GL_ARB_shading_language_420pack: require\n"
2563 "\n"
2564 "layout(location=0) out vec4 color;\n"
2565 "void main(){\n"
2566 " color = vec4(1);\n"
2567 "}\n";
2568
2569 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2570 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2571
2572 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002573 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12002574 pipe.AddShader(&vs);
2575 pipe.AddShader(&fs);
2576
Chris Forbes37367e62015-05-25 11:13:29 +12002577 VkDescriptorSetObj descriptorSet(m_device);
2578 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002579 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12002580
2581 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002582 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12002583
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002584 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12002585
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002586 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes37367e62015-05-25 11:13:29 +12002587 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
2588 FAIL() << "Incorrect warning: " << msgString;
2589 }
2590}
2591
Chris Forbesa4b02322015-05-25 11:13:31 +12002592TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
2593{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002594 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12002595 std::string msgString;
2596 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002597 ScopedUseGlsl useGlsl(false);
Chris Forbesa4b02322015-05-25 11:13:31 +12002598
2599 VkVertexInputBindingDescription input_binding;
2600 memset(&input_binding, 0, sizeof(input_binding));
2601
2602 VkVertexInputAttributeDescription input_attrib;
2603 memset(&input_attrib, 0, sizeof(input_attrib));
2604 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2605
2606 char const *vsSource =
2607 "#version 140\n"
2608 "#extension GL_ARB_separate_shader_objects: require\n"
2609 "#extension GL_ARB_shading_language_420pack: require\n"
2610 "\n"
2611 "layout(location=0) in int x;\n" /* attrib provided float */
2612 "void main(){\n"
2613 " gl_Position = vec4(x);\n"
2614 "}\n";
2615 char const *fsSource =
2616 "#version 140\n"
2617 "#extension GL_ARB_separate_shader_objects: require\n"
2618 "#extension GL_ARB_shading_language_420pack: require\n"
2619 "\n"
2620 "layout(location=0) out vec4 color;\n"
2621 "void main(){\n"
2622 " color = vec4(1);\n"
2623 "}\n";
2624
2625 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2626 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2627
2628 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002629 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12002630 pipe.AddShader(&vs);
2631 pipe.AddShader(&fs);
2632
2633 pipe.AddVertexInputBindings(&input_binding, 1);
2634 pipe.AddVertexInputAttribs(&input_attrib, 1);
2635
Chris Forbesa4b02322015-05-25 11:13:31 +12002636 VkDescriptorSetObj descriptorSet(m_device);
2637 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002638 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12002639
2640 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002641 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12002642
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002643 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12002644
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002645 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbesa4b02322015-05-25 11:13:31 +12002646 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
2647 FAIL() << "Incorrect error: " << msgString;
2648 }
2649}
2650
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002651TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
2652{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002653 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002654 std::string msgString;
2655 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002656 ScopedUseGlsl useGlsl(false);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002657
2658 /* Two binding descriptions for binding 0 */
2659 VkVertexInputBindingDescription input_bindings[2];
2660 memset(input_bindings, 0, sizeof(input_bindings));
2661
2662 VkVertexInputAttributeDescription input_attrib;
2663 memset(&input_attrib, 0, sizeof(input_attrib));
2664 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2665
2666 char const *vsSource =
2667 "#version 140\n"
2668 "#extension GL_ARB_separate_shader_objects: require\n"
2669 "#extension GL_ARB_shading_language_420pack: require\n"
2670 "\n"
2671 "layout(location=0) in float x;\n" /* attrib provided float */
2672 "void main(){\n"
2673 " gl_Position = vec4(x);\n"
2674 "}\n";
2675 char const *fsSource =
2676 "#version 140\n"
2677 "#extension GL_ARB_separate_shader_objects: require\n"
2678 "#extension GL_ARB_shading_language_420pack: require\n"
2679 "\n"
2680 "layout(location=0) out vec4 color;\n"
2681 "void main(){\n"
2682 " color = vec4(1);\n"
2683 "}\n";
2684
2685 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2686 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2687
2688 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002689 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002690 pipe.AddShader(&vs);
2691 pipe.AddShader(&fs);
2692
2693 pipe.AddVertexInputBindings(input_bindings, 2);
2694 pipe.AddVertexInputAttribs(&input_attrib, 1);
2695
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002696 VkDescriptorSetObj descriptorSet(m_device);
2697 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002698 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002699
2700 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002701 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002702
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002703 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002704
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002705 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002706 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
2707 FAIL() << "Incorrect error: " << msgString;
2708 }
2709}
Chris Forbes4c948702015-05-25 11:13:32 +12002710
Chris Forbesc12ef122015-05-25 11:13:40 +12002711/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
2712 * rejects it. */
2713
2714TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
2715{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002716 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12002717 std::string msgString;
2718 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002719 ScopedUseGlsl useGlsl(false);
Chris Forbesc12ef122015-05-25 11:13:40 +12002720
2721 char const *vsSource =
2722 "#version 140\n"
2723 "#extension GL_ARB_separate_shader_objects: require\n"
2724 "#extension GL_ARB_shading_language_420pack: require\n"
2725 "\n"
2726 "void main(){\n"
2727 " gl_Position = vec4(1);\n"
2728 "}\n";
2729 char const *fsSource =
2730 "#version 140\n"
2731 "#extension GL_ARB_separate_shader_objects: require\n"
2732 "#extension GL_ARB_shading_language_420pack: require\n"
2733 "\n"
2734 "void main(){\n"
2735 "}\n";
2736
2737 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2738 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2739
2740 VkPipelineObj pipe(m_device);
2741 pipe.AddShader(&vs);
2742 pipe.AddShader(&fs);
2743
Chia-I Wuc278df82015-07-07 11:50:03 +08002744 /* set up CB 0, not written */
2745 pipe.AddColorAttachment();
2746 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12002747
Chris Forbesc12ef122015-05-25 11:13:40 +12002748 VkDescriptorSetObj descriptorSet(m_device);
2749 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002750 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12002751
2752 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002753 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12002754
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002755 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12002756
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002757 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbesc12ef122015-05-25 11:13:40 +12002758 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
2759 FAIL() << "Incorrect error: " << msgString;
2760 }
2761}
2762
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002763TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
2764{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002765 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002766 std::string msgString;
2767 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002768 ScopedUseGlsl useGlsl(false);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002769
2770 char const *vsSource =
2771 "#version 140\n"
2772 "#extension GL_ARB_separate_shader_objects: require\n"
2773 "#extension GL_ARB_shading_language_420pack: require\n"
2774 "\n"
2775 "void main(){\n"
2776 " gl_Position = vec4(1);\n"
2777 "}\n";
2778 char const *fsSource =
2779 "#version 140\n"
2780 "#extension GL_ARB_separate_shader_objects: require\n"
2781 "#extension GL_ARB_shading_language_420pack: require\n"
2782 "\n"
2783 "layout(location=0) out vec4 x;\n"
2784 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
2785 "void main(){\n"
2786 " x = vec4(1);\n"
2787 " y = vec4(1);\n"
2788 "}\n";
2789
2790 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2791 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2792
2793 VkPipelineObj pipe(m_device);
2794 pipe.AddShader(&vs);
2795 pipe.AddShader(&fs);
2796
Chia-I Wuc278df82015-07-07 11:50:03 +08002797 /* set up CB 0, not written */
2798 pipe.AddColorAttachment();
2799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002800 /* FS writes CB 1, but we don't configure it */
2801
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002802 VkDescriptorSetObj descriptorSet(m_device);
2803 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002804 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002805
2806 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002807 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002808
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002809 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002810
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002811 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002812 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
2813 FAIL() << "Incorrect warning: " << msgString;
2814 }
2815}
2816
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002817TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
2818{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002819 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002820 std::string msgString;
2821 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002822 ScopedUseGlsl useGlsl(false);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002823
2824 char const *vsSource =
2825 "#version 140\n"
2826 "#extension GL_ARB_separate_shader_objects: require\n"
2827 "#extension GL_ARB_shading_language_420pack: require\n"
2828 "\n"
2829 "void main(){\n"
2830 " gl_Position = vec4(1);\n"
2831 "}\n";
2832 char const *fsSource =
2833 "#version 140\n"
2834 "#extension GL_ARB_separate_shader_objects: require\n"
2835 "#extension GL_ARB_shading_language_420pack: require\n"
2836 "\n"
2837 "layout(location=0) out ivec4 x;\n" /* not UNORM */
2838 "void main(){\n"
2839 " x = ivec4(1);\n"
2840 "}\n";
2841
2842 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2843 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2844
2845 VkPipelineObj pipe(m_device);
2846 pipe.AddShader(&vs);
2847 pipe.AddShader(&fs);
2848
Chia-I Wuc278df82015-07-07 11:50:03 +08002849 /* set up CB 0; type is UNORM by default */
2850 pipe.AddColorAttachment();
2851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002852
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002853 VkDescriptorSetObj descriptorSet(m_device);
2854 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002855 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002856
2857 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002858 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002859
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002860 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002861
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002862 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002863 if (!strstr(msgString.c_str(),"does not match FS output type")) {
2864 FAIL() << "Incorrect error: " << msgString;
2865 }
2866}
Chris Forbesc2050732015-06-05 14:43:36 +12002867
2868TEST_F(VkLayerTest, CreatePipelineNonSpirvShader)
2869{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002870 VkFlags msgFlags;
Chris Forbesc2050732015-06-05 14:43:36 +12002871 std::string msgString;
2872 ASSERT_NO_FATAL_FAILURE(InitState());
2873 /* Intentionally provided GLSL rather than compiling to SPIRV first */
Cody Northrop1cfbd172015-06-03 16:49:20 -06002874 ScopedUseGlsl useGlsl(true);
Chris Forbesc2050732015-06-05 14:43:36 +12002875
2876 char const *vsSource =
2877 "#version 140\n"
2878 "#extension GL_ARB_separate_shader_objects: require\n"
2879 "#extension GL_ARB_shading_language_420pack: require\n"
2880 "\n"
2881 "void main(){\n"
2882 " gl_Position = vec4(1);\n"
2883 "}\n";
2884 char const *fsSource =
2885 "#version 140\n"
2886 "#extension GL_ARB_separate_shader_objects: require\n"
2887 "#extension GL_ARB_shading_language_420pack: require\n"
2888 "\n"
2889 "layout(location=0) out vec4 x;\n"
2890 "void main(){\n"
2891 " x = vec4(1);\n"
2892 "}\n";
2893
2894 m_errorMonitor->ClearState();
2895
2896 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2897 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2898
2899
2900 VkPipelineObj pipe(m_device);
2901 pipe.AddShader(&vs);
2902 pipe.AddShader(&fs);
2903
Chia-I Wuc278df82015-07-07 11:50:03 +08002904 /* set up CB 0; type is UNORM by default */
2905 pipe.AddColorAttachment();
2906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc2050732015-06-05 14:43:36 +12002907
Chris Forbesc2050732015-06-05 14:43:36 +12002908 VkDescriptorSetObj descriptorSet(m_device);
2909 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002910 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc2050732015-06-05 14:43:36 +12002911
Chia-I Wuc278df82015-07-07 11:50:03 +08002912 VkResult res = pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbesc2050732015-06-05 14:43:36 +12002913 /* pipeline creation should have succeeded */
2914 ASSERT_EQ(VK_SUCCESS, res);
2915
2916 /* should have emitted a warning: the shader is not SPIRV, so we're
2917 * not going to be able to analyze it */
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002918 msgFlags = m_errorMonitor->GetState(&msgString);
2919 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesc2050732015-06-05 14:43:36 +12002920 if (!strstr(msgString.c_str(),"is not SPIR-V")) {
2921 FAIL() << "Incorrect warning: " << msgString;
2922 }
2923}
Chris Forbes01c9db72015-06-04 09:25:25 +12002924#endif
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002925
Tony Barbour30486ea2015-04-07 13:44:53 -06002926int main(int argc, char **argv) {
2927 int result;
2928
2929 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06002930 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06002931
2932 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
2933
2934 result = RUN_ALL_TESTS();
2935
Tony Barbour01999182015-04-09 12:58:51 -06002936 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06002937 return result;
2938}