blob: 122fb00063a6c4865045cb1dbdfaf85051bb1c32 [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;
1070 uint32_t ds_count = 0;
1071 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1072 ASSERT_VK_SUCCESS(err);
1073
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001074 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1075 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1076 pipeline_layout_ci.pNext = NULL;
1077 pipeline_layout_ci.descriptorSetCount = 1;
1078 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001079
1080 VkPipelineLayout pipeline_layout;
1081 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1082 ASSERT_VK_SUCCESS(err);
1083
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001084 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001085
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001086 VkPipelineShaderStageCreateInfo pipe_vs_ci = {};
1087 pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1088 pipe_vs_ci.pNext = NULL;
1089 pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX;
1090 pipe_vs_ci.shader = vs.handle();
1091 pipe_vs_ci.pSpecializationInfo = NULL;
1092
1093 VkGraphicsPipelineCreateInfo gp_ci = {};
1094 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1095 gp_ci.pNext = NULL;
1096 gp_ci.stageCount = 1;
1097 gp_ci.pStages = &pipe_vs_ci;
1098 gp_ci.pVertexInputState = NULL;
1099 gp_ci.pInputAssemblyState = NULL;
1100 gp_ci.pTessellationState = NULL;
1101 gp_ci.pViewportState = NULL;
1102 gp_ci.pRasterState = NULL;
1103 gp_ci.pMultisampleState = NULL;
1104 gp_ci.pDepthStencilState = NULL;
1105 gp_ci.pColorBlendState = NULL;
1106 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1107 gp_ci.layout = pipeline_layout;
1108
1109 VkPipelineCacheCreateInfo pc_ci = {};
1110 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1111 pc_ci.pNext = NULL;
1112 pc_ci.initialSize = 0;
1113 pc_ci.initialData = 0;
1114 pc_ci.maxSize = 0;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001115
1116 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001117 VkPipelineCache pipelineCache;
1118
1119 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1120 ASSERT_VK_SUCCESS(err);
1121 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001122 ASSERT_VK_SUCCESS(err);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001123 ASSERT_NO_FATAL_FAILURE(InitState());
1124 ASSERT_NO_FATAL_FAILURE(InitViewport());
1125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06001126
1127 BeginCommandBuffer();
1128 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1129 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001130
Tobin Ehlis254eca02015-06-25 15:46:59 -06001131 msgFlags = m_errorMonitor->GetState(&msgString);
1132 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not warn after binding a DescriptorSet that was never updated.";
1133 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1134 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1135 }
1136}
1137
1138TEST_F(VkLayerTest, NoBeginCmdBuffer)
1139{
1140 VkFlags msgFlags;
1141 std::string msgString;
1142
1143 ASSERT_NO_FATAL_FAILURE(InitState());
1144 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001145 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001146 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1147 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1148 msgFlags = m_errorMonitor->GetState(&msgString);
1149 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after ending a CmdBuffer w/o calling BeginCommandBuffer()";
1150 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1151 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1152 }
1153}
1154
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001155TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1156{
1157 VkFlags msgFlags;
1158 std::string msgString;
1159
1160 ASSERT_NO_FATAL_FAILURE(InitState());
1161 m_errorMonitor->ClearState();
1162
1163 // Calls CreateCommandBuffer
1164 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1165
1166 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northrop10d8f982015-08-04 17:35:57 -06001167 VkCmdBufferBeginInfo cmd_buf_info = {};
1168 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1169 cmd_buf_info.pNext = NULL;
1170 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1171 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1172 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1173 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1174
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001175
1176 // The error should be caught by validation of the BeginCommandBuffer call
1177 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1178
1179 msgFlags = m_errorMonitor->GetState(&msgString);
1180 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error passing a non-NULL Framebuffer and Renderpass to BeginCommandBuffer()";
1181 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1182 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1183 }
1184}
1185
1186TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1187{
1188 VkFlags msgFlags;
1189 std::string msgString;
1190 VkResult err;
1191 VkCmdBuffer draw_cmd;
1192 VkCmdPool cmd_pool;
1193
1194 ASSERT_NO_FATAL_FAILURE(InitState());
1195 m_errorMonitor->ClearState();
1196
Cody Northrop10d8f982015-08-04 17:35:57 -06001197 VkCmdBufferCreateInfo cmd = {};
1198 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1199 cmd.pNext = NULL;
1200 cmd.cmdPool = m_cmdPool;
1201 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1202 cmd.flags = 0;
1203
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001204 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
1205 assert(!err);
1206
1207 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northrop10d8f982015-08-04 17:35:57 -06001208 VkCmdBufferBeginInfo cmd_buf_info = {};
1209 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1210 cmd_buf_info.pNext = NULL;
1211 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1212 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001213
1214 // The error should be caught by validation of the BeginCommandBuffer call
1215 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1216
1217 msgFlags = m_errorMonitor->GetState(&msgString);
1218 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error passing NULL Framebuffer/Renderpass to BeginCommandBuffer()";
1219 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1220 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1221 }
1222}
1223
Tobin Ehlis254eca02015-06-25 15:46:59 -06001224TEST_F(VkLayerTest, InvalidPipelineCreateState)
1225{
1226 // Attempt to Create Gfx Pipeline w/o a VS
1227 VkFlags msgFlags;
1228 std::string msgString;
1229 VkResult err;
1230
1231 ASSERT_NO_FATAL_FAILURE(InitState());
1232 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001233
1234 VkDescriptorTypeCount ds_type_count = {};
1235 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1236 ds_type_count.count = 1;
1237
1238 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1239 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1240 ds_pool_ci.pNext = NULL;
1241 ds_pool_ci.count = 1;
1242 ds_pool_ci.pTypeCount = &ds_type_count;
1243
Tobin Ehlis254eca02015-06-25 15:46:59 -06001244 VkDescriptorPool ds_pool;
1245 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1246 ASSERT_VK_SUCCESS(err);
1247
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001248 VkDescriptorSetLayoutBinding dsl_binding = {};
1249 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1250 dsl_binding.arraySize = 1;
1251 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1252 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001253
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001254 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1255 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1256 ds_layout_ci.pNext = NULL;
1257 ds_layout_ci.count = 1;
1258 ds_layout_ci.pBinding = &dsl_binding;
1259
Tobin Ehlis254eca02015-06-25 15:46:59 -06001260 VkDescriptorSetLayout ds_layout;
1261 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1262 ASSERT_VK_SUCCESS(err);
1263
1264 VkDescriptorSet descriptorSet;
1265 uint32_t ds_count = 0;
1266 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1267 ASSERT_VK_SUCCESS(err);
1268
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001269 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1270 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1271 pipeline_layout_ci.pNext = NULL;
1272 pipeline_layout_ci.descriptorSetCount = 1;
1273 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001274
1275 VkPipelineLayout pipeline_layout;
1276 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1277 ASSERT_VK_SUCCESS(err);
1278
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001279 VkGraphicsPipelineCreateInfo gp_ci = {};
1280 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1281 gp_ci.pNext = NULL;
1282 gp_ci.stageCount = 0;
1283 gp_ci.pStages = NULL;
1284 gp_ci.pVertexInputState = NULL;
1285 gp_ci.pInputAssemblyState = NULL;
1286 gp_ci.pTessellationState = NULL;
1287 gp_ci.pViewportState = NULL;
1288 gp_ci.pRasterState = NULL;
1289 gp_ci.pMultisampleState = NULL;
1290 gp_ci.pDepthStencilState = NULL;
1291 gp_ci.pColorBlendState = NULL;
1292 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1293 gp_ci.layout = pipeline_layout;
1294
1295 VkPipelineCacheCreateInfo pc_ci = {};
1296 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1297 pc_ci.pNext = NULL;
1298 pc_ci.initialSize = 0;
1299 pc_ci.initialData = 0;
1300 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001301
1302 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001303 VkPipelineCache pipelineCache;
1304
1305 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1306 ASSERT_VK_SUCCESS(err);
1307 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001308
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001309 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001310 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after creating Gfx Pipeline w/o VS.";
1311 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1312 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1313 }
1314}
1315
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001316TEST_F(VkLayerTest, NullRenderPass)
1317{
1318 // Bind a NULL RenderPass
1319 VkFlags msgFlags;
1320 std::string msgString;
1321
1322 ASSERT_NO_FATAL_FAILURE(InitState());
1323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1324 m_errorMonitor->ClearState();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001325
Tony Barbour1490c912015-07-28 10:17:20 -06001326 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001327 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06001328 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001329
1330 msgFlags = m_errorMonitor->GetState(&msgString);
1331 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding NULL RenderPass.";
1332 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
1333 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
1334 }
1335}
1336
Tobin Ehlis254eca02015-06-25 15:46:59 -06001337TEST_F(VkLayerTest, RenderPassWithinRenderPass)
1338{
1339 // Bind a BeginRenderPass within an active RenderPass
1340 VkFlags msgFlags;
1341 std::string msgString;
1342
1343 ASSERT_NO_FATAL_FAILURE(InitState());
1344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1345 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001346
Tony Barbour1490c912015-07-28 10:17:20 -06001347 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001348 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001349 VkRenderPassBeginInfo rp_begin = {};
1350 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
1351 rp_begin.pNext = NULL;
1352 rp_begin.renderPass = (VkRenderPass)0xc001d00d;
1353 rp_begin.framebuffer = 0;
1354
Tony Barbour1490c912015-07-28 10:17:20 -06001355 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001356
1357 msgFlags = m_errorMonitor->GetState(&msgString);
1358 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding RenderPass w/i an active RenderPass.";
1359 if (!strstr(msgString.c_str(),"Cannot call vkCmdBeginRenderPass() during an active RenderPass ")) {
1360 FAIL() << "Error received was not 'Cannot call vkCmdBeginRenderPass() during an active RenderPass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001361 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001362}
1363
1364TEST_F(VkLayerTest, InvalidDynamicStateObject)
1365{
1366 // Create a valid cmd buffer
1367 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001368 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1369 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001370}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06001371
Tobin Ehlise4076782015-06-24 15:53:07 -06001372TEST_F(VkLayerTest, VtxBufferNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001373{
1374 // Bind VBO out-of-bounds for given PSO
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001375 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001376 std::string msgString;
1377 VkResult err;
1378
1379 ASSERT_NO_FATAL_FAILURE(InitState());
1380 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001381
1382 VkDescriptorTypeCount ds_type_count = {};
1383 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1384 ds_type_count.count = 1;
1385
1386 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1387 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1388 ds_pool_ci.pNext = NULL;
1389 ds_pool_ci.count = 1;
1390 ds_pool_ci.pTypeCount = &ds_type_count;
1391
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001392 VkDescriptorPool ds_pool;
1393 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1394 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001395
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001396 VkDescriptorSetLayoutBinding dsl_binding = {};
1397 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1398 dsl_binding.arraySize = 1;
1399 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1400 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001401
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001402 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1403 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1404 ds_layout_ci.pNext = NULL;
1405 ds_layout_ci.count = 1;
1406 ds_layout_ci.pBinding = &dsl_binding;
1407
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001408 VkDescriptorSetLayout ds_layout;
1409 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1410 ASSERT_VK_SUCCESS(err);
1411
1412 VkDescriptorSet descriptorSet;
1413 uint32_t ds_count = 0;
1414 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1415 ASSERT_VK_SUCCESS(err);
1416
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001417 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1418 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1419 pipeline_layout_ci.pNext = NULL;
1420 pipeline_layout_ci.descriptorSetCount = 1;
1421 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001422
1423 VkPipelineLayout pipeline_layout;
1424 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1425 ASSERT_VK_SUCCESS(err);
1426
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001427 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001428
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001429 VkPipelineShaderStageCreateInfo pipe_vs_ci = {};
1430 pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1431 pipe_vs_ci.pNext = NULL;
1432 pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX;
1433 pipe_vs_ci.shader = vs.handle();
1434 pipe_vs_ci.pSpecializationInfo = NULL;
1435
1436 VkGraphicsPipelineCreateInfo gp_ci = {};
1437 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1438 gp_ci.pNext = NULL;
1439 gp_ci.stageCount = 1;
1440 gp_ci.pStages = &pipe_vs_ci;
1441 gp_ci.pVertexInputState = NULL;
1442 gp_ci.pInputAssemblyState = NULL;
1443 gp_ci.pTessellationState = NULL;
1444 gp_ci.pViewportState = NULL;
1445 gp_ci.pRasterState = NULL;
1446 gp_ci.pMultisampleState = NULL;
1447 gp_ci.pDepthStencilState = NULL;
1448 gp_ci.pColorBlendState = NULL;
1449 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1450 gp_ci.layout = pipeline_layout;
1451
1452 VkPipelineCacheCreateInfo pc_ci = {};
1453 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1454 pc_ci.pNext = NULL;
1455 pc_ci.initialSize = 0;
1456 pc_ci.initialData = 0;
1457 pc_ci.maxSize = 0;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001458
1459 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001460 VkPipelineCache pipelineCache;
1461
1462 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1463 ASSERT_VK_SUCCESS(err);
1464 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001465 ASSERT_VK_SUCCESS(err);
1466
Tony Barbour1490c912015-07-28 10:17:20 -06001467 BeginCommandBuffer();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001468 ASSERT_VK_SUCCESS(err);
Tony Barbour1490c912015-07-28 10:17:20 -06001469 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001470 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06001471 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001472
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001473 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlise4076782015-06-24 15:53:07 -06001474 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
1475 if (!strstr(msgString.c_str(),"Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.")) {
1476 FAIL() << "Error received was not 'Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001477 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001478}
1479
1480TEST_F(VkLayerTest, DSTypeMismatch)
1481{
1482 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001483 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001484 std::string msgString;
1485 VkResult err;
1486
1487 ASSERT_NO_FATAL_FAILURE(InitState());
1488 m_errorMonitor->ClearState();
1489 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001490 VkDescriptorTypeCount ds_type_count = {};
1491 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1492 ds_type_count.count = 1;
1493
1494 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1495 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1496 ds_pool_ci.pNext = NULL;
1497 ds_pool_ci.count = 1;
1498 ds_pool_ci.pTypeCount = &ds_type_count;
1499
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001500 VkDescriptorPool ds_pool;
1501 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1502 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001503 VkDescriptorSetLayoutBinding dsl_binding = {};
1504 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1505 dsl_binding.arraySize = 1;
1506 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1507 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001508
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001509 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1510 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1511 ds_layout_ci.pNext = NULL;
1512 ds_layout_ci.count = 1;
1513 ds_layout_ci.pBinding = &dsl_binding;
1514
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001515 VkDescriptorSetLayout ds_layout;
1516 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1517 ASSERT_VK_SUCCESS(err);
1518
1519 VkDescriptorSet descriptorSet;
1520 uint32_t ds_count = 0;
1521 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1522 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001523
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001524 VkSamplerCreateInfo sampler_ci = {};
1525 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1526 sampler_ci.pNext = NULL;
1527 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1528 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1529 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1530 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1531 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1532 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1533 sampler_ci.mipLodBias = 1.0;
1534 sampler_ci.maxAnisotropy = 1;
1535 sampler_ci.compareEnable = VK_FALSE;
1536 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1537 sampler_ci.minLod = 1.0;
1538 sampler_ci.maxLod = 1.0;
1539 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1540
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001541 VkSampler sampler;
1542 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1543 ASSERT_VK_SUCCESS(err);
1544
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001545 VkDescriptorInfo descriptor_info;
1546 memset(&descriptor_info, 0, sizeof(descriptor_info));
1547 descriptor_info.sampler = sampler;
1548
1549 VkWriteDescriptorSet descriptor_write;
1550 memset(&descriptor_write, 0, sizeof(descriptor_write));
1551 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1552 descriptor_write.destSet = descriptorSet;
1553 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001554 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001555 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1556 descriptor_write.pDescriptors = &descriptor_info;
1557
1558 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1559
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001560 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001561 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 +08001562 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) {
1563 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 -06001564 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001565}
1566
1567TEST_F(VkLayerTest, DSUpdateOutOfBounds)
1568{
1569 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001570 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001571 std::string msgString;
1572 VkResult err;
1573
1574 ASSERT_NO_FATAL_FAILURE(InitState());
1575 m_errorMonitor->ClearState();
1576 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001577 VkDescriptorTypeCount ds_type_count = {};
1578 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1579 ds_type_count.count = 1;
1580
1581 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1582 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1583 ds_pool_ci.pNext = NULL;
1584 ds_pool_ci.count = 1;
1585 ds_pool_ci.pTypeCount = &ds_type_count;
1586
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001587 VkDescriptorPool ds_pool;
1588 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1589 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001590
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001591 VkDescriptorSetLayoutBinding dsl_binding = {};
1592 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1593 dsl_binding.arraySize = 1;
1594 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1595 dsl_binding.pImmutableSamplers = NULL;
1596
1597 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1598 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1599 ds_layout_ci.pNext = NULL;
1600 ds_layout_ci.count = 1;
1601 ds_layout_ci.pBinding = &dsl_binding;
1602
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001603 VkDescriptorSetLayout ds_layout;
1604 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1605 ASSERT_VK_SUCCESS(err);
1606
1607 VkDescriptorSet descriptorSet;
1608 uint32_t ds_count = 0;
1609 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1610 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001611
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001612 VkSamplerCreateInfo sampler_ci = {};
1613 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1614 sampler_ci.pNext = NULL;
1615 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1616 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1617 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1618 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1619 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1620 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1621 sampler_ci.mipLodBias = 1.0;
1622 sampler_ci.maxAnisotropy = 1;
1623 sampler_ci.compareEnable = VK_FALSE;
1624 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1625 sampler_ci.minLod = 1.0;
1626 sampler_ci.maxLod = 1.0;
1627 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1628
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001629 VkSampler sampler;
1630 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1631 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001632
1633 VkDescriptorInfo descriptor_info;
1634 memset(&descriptor_info, 0, sizeof(descriptor_info));
1635 descriptor_info.sampler = sampler;
1636
1637 VkWriteDescriptorSet descriptor_write;
1638 memset(&descriptor_write, 0, sizeof(descriptor_write));
1639 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1640 descriptor_write.destSet = descriptorSet;
1641 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
1642 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001643 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001644 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1645 descriptor_write.pDescriptors = &descriptor_info;
1646
1647 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1648
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001649 msgFlags = m_errorMonitor->GetState(&msgString);
1650 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 +08001651 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
1652 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 -06001653 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001654}
1655
1656TEST_F(VkLayerTest, InvalidDSUpdateIndex)
1657{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001658 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001659 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001660 std::string msgString;
1661 VkResult err;
1662
1663 ASSERT_NO_FATAL_FAILURE(InitState());
1664 m_errorMonitor->ClearState();
1665 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001666 VkDescriptorTypeCount ds_type_count = {};
1667 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1668 ds_type_count.count = 1;
1669
1670 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1671 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1672 ds_pool_ci.pNext = NULL;
1673 ds_pool_ci.count = 1;
1674 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001675 VkDescriptorPool ds_pool;
1676 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1677 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001678
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001679 VkDescriptorSetLayoutBinding dsl_binding = {};
1680 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1681 dsl_binding.arraySize = 1;
1682 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1683 dsl_binding.pImmutableSamplers = NULL;
1684
1685 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1686 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1687 ds_layout_ci.pNext = NULL;
1688 ds_layout_ci.count = 1;
1689 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001690 VkDescriptorSetLayout ds_layout;
1691 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1692 ASSERT_VK_SUCCESS(err);
1693
1694 VkDescriptorSet descriptorSet;
1695 uint32_t ds_count = 0;
1696 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1697 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001698
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001699 VkSamplerCreateInfo sampler_ci = {};
1700 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1701 sampler_ci.pNext = NULL;
1702 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1703 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1704 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1705 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1706 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1707 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1708 sampler_ci.mipLodBias = 1.0;
1709 sampler_ci.maxAnisotropy = 1;
1710 sampler_ci.compareEnable = VK_FALSE;
1711 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1712 sampler_ci.minLod = 1.0;
1713 sampler_ci.maxLod = 1.0;
1714 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1715
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001716 VkSampler sampler;
1717 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1718 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001719
1720 VkDescriptorInfo descriptor_info;
1721 memset(&descriptor_info, 0, sizeof(descriptor_info));
1722 descriptor_info.sampler = sampler;
1723
1724 VkWriteDescriptorSet descriptor_write;
1725 memset(&descriptor_write, 0, sizeof(descriptor_write));
1726 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1727 descriptor_write.destSet = descriptorSet;
1728 descriptor_write.destBinding = 2;
1729 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001730 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001731 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1732 descriptor_write.pDescriptors = &descriptor_info;
1733
1734 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1735
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001736 msgFlags = m_errorMonitor->GetState(&msgString);
1737 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 -06001738 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
1739 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
1740 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001741}
1742
1743TEST_F(VkLayerTest, InvalidDSUpdateStruct)
1744{
1745 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001746 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001747 std::string msgString;
1748 VkResult err;
1749
1750 ASSERT_NO_FATAL_FAILURE(InitState());
1751 m_errorMonitor->ClearState();
1752 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001753
1754 VkDescriptorTypeCount ds_type_count = {};
1755 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1756 ds_type_count.count = 1;
1757
1758 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1759 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1760 ds_pool_ci.pNext = NULL;
1761 ds_pool_ci.count = 1;
1762 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001763 VkDescriptorPool ds_pool;
1764 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1765 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001766 VkDescriptorSetLayoutBinding dsl_binding = {};
1767 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1768 dsl_binding.arraySize = 1;
1769 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1770 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001771
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001772 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1773 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1774 ds_layout_ci.pNext = NULL;
1775 ds_layout_ci.count = 1;
1776 ds_layout_ci.pBinding = &dsl_binding;
1777
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001778 VkDescriptorSetLayout ds_layout;
1779 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1780 ASSERT_VK_SUCCESS(err);
1781
1782 VkDescriptorSet descriptorSet;
1783 uint32_t ds_count = 0;
1784 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1785 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001786
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001787 VkSamplerCreateInfo sampler_ci = {};
1788 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1789 sampler_ci.pNext = NULL;
1790 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1791 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1792 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1793 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1794 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1795 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1796 sampler_ci.mipLodBias = 1.0;
1797 sampler_ci.maxAnisotropy = 1;
1798 sampler_ci.compareEnable = VK_FALSE;
1799 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1800 sampler_ci.minLod = 1.0;
1801 sampler_ci.maxLod = 1.0;
1802 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001803 VkSampler sampler;
1804 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1805 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001806
1807
1808 VkDescriptorInfo descriptor_info;
1809 memset(&descriptor_info, 0, sizeof(descriptor_info));
1810 descriptor_info.sampler = sampler;
1811
1812 VkWriteDescriptorSet descriptor_write;
1813 memset(&descriptor_write, 0, sizeof(descriptor_write));
1814 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
1815 descriptor_write.destSet = descriptorSet;
1816 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001817 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001818 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1819 descriptor_write.pDescriptors = &descriptor_info;
1820
1821 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1822
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001823 msgFlags = m_errorMonitor->GetState(&msgString);
1824 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 -06001825 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
1826 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
1827 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001828}
1829
1830TEST_F(VkLayerTest, NumSamplesMismatch)
1831{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001832 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001833 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001834 std::string msgString;
1835 VkResult err;
1836
1837 ASSERT_NO_FATAL_FAILURE(InitState());
1838 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1839 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001840 VkDescriptorTypeCount ds_type_count = {};
1841 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1842 ds_type_count.count = 1;
1843
1844 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1845 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1846 ds_pool_ci.pNext = NULL;
1847 ds_pool_ci.count = 1;
1848 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001849 VkDescriptorPool ds_pool;
1850 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1851 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001852
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001853 VkDescriptorSetLayoutBinding dsl_binding = {};
1854 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1855 dsl_binding.arraySize = 1;
1856 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1857 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001858
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001859 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1860 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1861 ds_layout_ci.pNext = NULL;
1862 ds_layout_ci.count = 1;
1863 ds_layout_ci.pBinding = &dsl_binding;
1864
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001865 VkDescriptorSetLayout ds_layout;
1866 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1867 ASSERT_VK_SUCCESS(err);
1868
1869 VkDescriptorSet descriptorSet;
1870 uint32_t ds_count = 0;
1871 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1872 ASSERT_VK_SUCCESS(err);
1873
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001874 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1875 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1876 pipe_ms_state_ci.pNext = NULL;
1877 pipe_ms_state_ci.rasterSamples = 4;
1878 pipe_ms_state_ci.sampleShadingEnable = 0;
1879 pipe_ms_state_ci.minSampleShading = 1.0;
1880 pipe_ms_state_ci.sampleMask = 15;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001881
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001882 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1883 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1884 pipeline_layout_ci.pNext = NULL;
1885 pipeline_layout_ci.descriptorSetCount = 1;
1886 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001887
1888 VkPipelineLayout pipeline_layout;
1889 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1890 ASSERT_VK_SUCCESS(err);
1891
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001892 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001893 VkPipelineShaderStageCreateInfo pipe_vs_ci = {};
1894 pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1895 pipe_vs_ci.pNext = NULL;
1896 pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX;
1897 pipe_vs_ci.shader = vs.handle();
1898 pipe_vs_ci.pSpecializationInfo = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001899
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001900 VkGraphicsPipelineCreateInfo gp_ci = {};
1901 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1902 gp_ci.pNext = NULL;
1903 gp_ci.stageCount = 1;
1904 gp_ci.pStages = &pipe_vs_ci;
1905 gp_ci.pVertexInputState = NULL;
1906 gp_ci.pInputAssemblyState = NULL;
1907 gp_ci.pTessellationState = NULL;
1908 gp_ci.pViewportState = NULL;
1909 gp_ci.pRasterState = NULL;
1910 gp_ci.pMultisampleState = &pipe_ms_state_ci;
1911 gp_ci.pDepthStencilState = NULL;
1912 gp_ci.pColorBlendState = NULL;
1913 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1914 gp_ci.layout = pipeline_layout;
1915
1916 VkPipelineCacheCreateInfo pc_ci = {};
1917 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1918 pc_ci.pNext = NULL;
1919 pc_ci.initialSize = 0;
1920 pc_ci.initialData = 0;
1921 pc_ci.maxSize = 0;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001922
1923 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001924 VkPipelineCache pipelineCache;
1925
1926 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1927 ASSERT_VK_SUCCESS(err);
1928 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001929 ASSERT_VK_SUCCESS(err);
1930
Tony Barbour1490c912015-07-28 10:17:20 -06001931 BeginCommandBuffer();
1932 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001933
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001934 msgFlags = m_errorMonitor->GetState(&msgString);
1935 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 -06001936 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
1937 FAIL() << "Error received was not 'Num samples mismatch!...'";
1938 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001939}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001940
Tobin Ehlise4076782015-06-24 15:53:07 -06001941TEST_F(VkLayerTest, PipelineNotBound)
1942{
1943 VkFlags msgFlags;
1944 std::string msgString;
1945 VkResult err;
1946
1947 ASSERT_NO_FATAL_FAILURE(InitState());
1948 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1949 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001950
1951 VkDescriptorTypeCount ds_type_count = {};
1952 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1953 ds_type_count.count = 1;
1954
1955 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1956 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1957 ds_pool_ci.pNext = NULL;
1958 ds_pool_ci.count = 1;
1959 ds_pool_ci.pTypeCount = &ds_type_count;
1960
Tobin Ehlise4076782015-06-24 15:53:07 -06001961 VkDescriptorPool ds_pool;
1962 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1963 ASSERT_VK_SUCCESS(err);
1964
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001965 VkDescriptorSetLayoutBinding dsl_binding = {};
1966 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1967 dsl_binding.arraySize = 1;
1968 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1969 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06001970
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001971 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1972 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1973 ds_layout_ci.pNext = NULL;
1974 ds_layout_ci.count = 1;
1975 ds_layout_ci.pBinding = &dsl_binding;
1976
Tobin Ehlise4076782015-06-24 15:53:07 -06001977 VkDescriptorSetLayout ds_layout;
1978 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1979 ASSERT_VK_SUCCESS(err);
1980
1981 VkDescriptorSet descriptorSet;
1982 uint32_t ds_count = 0;
1983 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
1984 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001985
1986 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1987 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1988 pipeline_layout_ci.pNext = NULL;
1989 pipeline_layout_ci.descriptorSetCount = 1;
1990 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06001991
1992 VkPipelineLayout pipeline_layout;
1993 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1994 ASSERT_VK_SUCCESS(err);
1995
Tobin Ehlise4076782015-06-24 15:53:07 -06001996 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1997 //err = vkCreateGraphicsPipeline(m_device->device(), &gp_ci, &pipeline);
1998 ASSERT_VK_SUCCESS(err);
1999
Tony Barbour1490c912015-07-28 10:17:20 -06002000
2001 BeginCommandBuffer();
2002 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06002003
2004 msgFlags = m_errorMonitor->GetState(&msgString);
2005 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding invalid pipeline to CmdBuffer";
2006 if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
2007 FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
2008 }
2009}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002010
2011TEST_F(VkLayerTest, ClearCmdNoDraw)
2012{
2013 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
2014 VkFlags msgFlags;
2015 std::string msgString;
2016 VkResult err;
2017
2018 ASSERT_NO_FATAL_FAILURE(InitState());
2019 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2020 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002021
2022 VkDescriptorTypeCount ds_type_count = {};
2023 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2024 ds_type_count.count = 1;
2025
2026 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2027 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2028 ds_pool_ci.pNext = NULL;
2029 ds_pool_ci.count = 1;
2030 ds_pool_ci.pTypeCount = &ds_type_count;
2031
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002032 VkDescriptorPool ds_pool;
2033 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
2034 ASSERT_VK_SUCCESS(err);
2035
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002036 VkDescriptorSetLayoutBinding dsl_binding = {};
2037 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2038 dsl_binding.arraySize = 1;
2039 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2040 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002041
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002042 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2043 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2044 ds_layout_ci.pNext = NULL;
2045 ds_layout_ci.count = 1;
2046 ds_layout_ci.pBinding = &dsl_binding;
2047
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002048 VkDescriptorSetLayout ds_layout;
2049 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2050 ASSERT_VK_SUCCESS(err);
2051
2052 VkDescriptorSet descriptorSet;
2053 uint32_t ds_count = 0;
2054 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
2055 ASSERT_VK_SUCCESS(err);
2056
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002057 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2058 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2059 pipe_ms_state_ci.pNext = NULL;
2060 pipe_ms_state_ci.rasterSamples = 4;
2061 pipe_ms_state_ci.sampleShadingEnable = 0;
2062 pipe_ms_state_ci.minSampleShading = 1.0;
2063 pipe_ms_state_ci.sampleMask = 15;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002064
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002065 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2066 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2067 pipeline_layout_ci.pNext = NULL;
2068 pipeline_layout_ci.descriptorSetCount = 1;
2069 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002070
2071 VkPipelineLayout pipeline_layout;
2072 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2073 ASSERT_VK_SUCCESS(err);
2074
2075 size_t shader_len = strlen(bindStateVertShaderText);
2076 size_t codeSize = 3 * sizeof(uint32_t) + shader_len + 1;
2077 void* pCode = malloc(codeSize);
2078
2079 /* try version 0 first: VkShaderStage followed by GLSL */
2080 ((uint32_t *) pCode)[0] = ICD_SPV_MAGIC;
2081 ((uint32_t *) pCode)[1] = 0;
2082 ((uint32_t *) pCode)[2] = VK_SHADER_STAGE_VERTEX;
2083 memcpy(((uint32_t *) pCode + 3), bindStateVertShaderText, shader_len + 1);
2084
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002085 VkShaderModuleCreateInfo smci = {};
2086 smci.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
2087 smci.pNext = NULL;
2088 smci.codeSize = codeSize;
2089 smci.pCode = pCode;
2090 smci.flags = 0;
2091
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002092 VkShaderModule vksm;
2093 err = vkCreateShaderModule(m_device->device(), &smci, &vksm);
2094 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002095 VkShaderCreateInfo vs_ci = {};
2096 vs_ci.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
2097 vs_ci.pNext = NULL;
2098 vs_ci.module = vksm;
2099 vs_ci.pName = "main";
2100 vs_ci.flags = 0;
2101
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002102 VkShader vs;
2103 err = vkCreateShader(m_device->device(), &vs_ci, &vs);
2104 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002105 VkPipelineShaderStageCreateInfo pipe_vs_ci = {};
2106 pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2107 pipe_vs_ci.pNext = NULL;
2108 pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX;
2109 pipe_vs_ci.shader = vs;
2110 pipe_vs_ci.pSpecializationInfo = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002111
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002112 VkGraphicsPipelineCreateInfo gp_ci = {};
2113 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2114 gp_ci.pNext = NULL;
2115 gp_ci.stageCount = 1;
2116 gp_ci.pStages = &pipe_vs_ci;
2117 gp_ci.pVertexInputState = NULL;
2118 gp_ci.pInputAssemblyState = NULL;
2119 gp_ci.pTessellationState = NULL;
2120 gp_ci.pViewportState = NULL;
2121 gp_ci.pRasterState = NULL;
2122 gp_ci.pMultisampleState = &pipe_ms_state_ci;
2123 gp_ci.pDepthStencilState = NULL;
2124 gp_ci.pColorBlendState = NULL;
2125 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2126 gp_ci.layout = pipeline_layout;
2127
2128 VkPipelineCacheCreateInfo pc_ci = {};
2129 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2130 pc_ci.pNext = NULL;
2131 pc_ci.initialSize = 0;
2132 pc_ci.initialData = 0;
2133 pc_ci.maxSize = 0;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002134
2135 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06002136 VkPipelineCache pipelineCache;
2137
2138 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2139 ASSERT_VK_SUCCESS(err);
2140 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002141 ASSERT_VK_SUCCESS(err);
2142
Tony Barbour1490c912015-07-28 10:17:20 -06002143
2144 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002145
2146 m_errorMonitor->ClearState();
2147 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
2148 // Also pass down other dummy params to keep driver and paramchecker happy
2149 VkClearColorValue cCV;
2150 cCV.f32[0] = 1.0;
2151 cCV.f32[1] = 1.0;
2152 cCV.f32[2] = 1.0;
2153 cCV.f32[3] = 1.0;
2154
Tony Barbour1490c912015-07-28 10:17:20 -06002155 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002156 msgFlags = m_errorMonitor->GetState(&msgString);
2157 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not receive error after issuing Clear Cmd on FB color attachment prior to Draw Cmd.";
2158 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) {
2159 FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'";
2160 }
2161}
2162
Tobin Ehlise4076782015-06-24 15:53:07 -06002163TEST_F(VkLayerTest, VtxBufferBadIndex)
2164{
2165 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
2166 VkFlags msgFlags;
2167 std::string msgString;
2168 VkResult err;
2169
2170 ASSERT_NO_FATAL_FAILURE(InitState());
2171 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2172 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002173
2174 VkDescriptorTypeCount ds_type_count = {};
2175 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2176 ds_type_count.count = 1;
2177
2178 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2179 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2180 ds_pool_ci.pNext = NULL;
2181 ds_pool_ci.count = 1;
2182 ds_pool_ci.pTypeCount = &ds_type_count;
2183
2184 VkDescriptorPool ds_pool;
Tobin Ehlise4076782015-06-24 15:53:07 -06002185 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
2186 ASSERT_VK_SUCCESS(err);
2187
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002188 VkDescriptorSetLayoutBinding dsl_binding = {};
2189 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2190 dsl_binding.arraySize = 1;
2191 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2192 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002193
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002194 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2195 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2196 ds_layout_ci.pNext = NULL;
2197 ds_layout_ci.count = 1;
2198 ds_layout_ci.pBinding = &dsl_binding;
2199
Tobin Ehlise4076782015-06-24 15:53:07 -06002200 VkDescriptorSetLayout ds_layout;
2201 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2202 ASSERT_VK_SUCCESS(err);
2203
2204 VkDescriptorSet descriptorSet;
2205 uint32_t ds_count = 0;
2206 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count);
2207 ASSERT_VK_SUCCESS(err);
2208
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002209 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2210 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2211 pipe_ms_state_ci.pNext = NULL;
2212 pipe_ms_state_ci.rasterSamples = 1;
2213 pipe_ms_state_ci.sampleShadingEnable = 0;
2214 pipe_ms_state_ci.minSampleShading = 1.0;
2215 pipe_ms_state_ci.sampleMask = 15;
Tobin Ehlise4076782015-06-24 15:53:07 -06002216
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002217 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2218 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2219 pipeline_layout_ci.pNext = NULL;
2220 pipeline_layout_ci.descriptorSetCount = 1;
2221 pipeline_layout_ci.pSetLayouts = &ds_layout;
2222 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06002223
Tobin Ehlise4076782015-06-24 15:53:07 -06002224 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2225 ASSERT_VK_SUCCESS(err);
2226
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002227 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tobin Ehlise4076782015-06-24 15:53:07 -06002228
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002229 VkPipelineShaderStageCreateInfo pipe_vs_ci = {};
2230 pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2231 pipe_vs_ci.pNext = NULL;
2232 pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX;
2233 pipe_vs_ci.shader = vs.handle();
2234 pipe_vs_ci.pSpecializationInfo = NULL;
2235
2236 VkGraphicsPipelineCreateInfo gp_ci = {};
2237 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
2238 gp_ci.pNext = NULL;
2239 gp_ci.stageCount = 1;
2240 gp_ci.pStages = &pipe_vs_ci;
2241 gp_ci.pVertexInputState = NULL;
2242 gp_ci.pInputAssemblyState = NULL;
2243 gp_ci.pTessellationState = NULL;
2244 gp_ci.pViewportState = NULL;
2245 gp_ci.pRasterState = NULL;
2246 gp_ci.pMultisampleState = &pipe_ms_state_ci;
2247 gp_ci.pDepthStencilState = NULL;
2248 gp_ci.pColorBlendState = NULL;
2249 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2250 gp_ci.layout = pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06002251
Courtney Goeltzenleuchtercdf5e832015-07-10 09:21:02 -06002252 VkPipelineCacheCreateInfo pipelineCache;
2253 VkPipelineCache pipeline_cache;
2254
2255 memset(&pipelineCache, 0, sizeof(pipelineCache));
2256 pipelineCache.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2257 err = vkCreatePipelineCache(m_device->device(), &pipelineCache, &pipeline_cache);
2258
Tobin Ehlise4076782015-06-24 15:53:07 -06002259 VkPipeline pipeline;
Courtney Goeltzenleuchtercdf5e832015-07-10 09:21:02 -06002260 err = vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &gp_ci, &pipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06002261 ASSERT_VK_SUCCESS(err);
2262
Tony Barbour1490c912015-07-28 10:17:20 -06002263
2264 BeginCommandBuffer();
2265 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06002266 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06002267 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlise4076782015-06-24 15:53:07 -06002268
2269 msgFlags = m_errorMonitor->GetState(&msgString);
2270 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding Vtx Buffer w/o VBO attached to PSO.";
2271 if (!strstr(msgString.c_str(),"Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.")) {
2272 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
2273 }
2274}
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002275#endif
2276#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06002277#if GTEST_IS_THREADSAFE
2278struct thread_data_struct {
2279 VkCmdBuffer cmdBuffer;
2280 VkEvent event;
2281 bool bailout;
2282};
2283
2284extern "C" void *AddToCommandBuffer(void *arg)
2285{
2286 struct thread_data_struct *data = (struct thread_data_struct *) arg;
2287 std::string msgString;
2288
2289 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06002290 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06002291 if (data->bailout) {
2292 break;
2293 }
2294 }
2295 return NULL;
2296}
2297
2298TEST_F(VkLayerTest, ThreadCmdBufferCollision)
2299{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002300 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06002301 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002302 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06002303
2304 ASSERT_NO_FATAL_FAILURE(InitState());
2305 ASSERT_NO_FATAL_FAILURE(InitViewport());
2306 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2307
Mike Stroyan09aae812015-05-12 16:00:45 -06002308 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06002309 BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002310
2311 VkEventCreateInfo event_info;
2312 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06002313 VkResult err;
2314
2315 memset(&event_info, 0, sizeof(event_info));
2316 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2317
2318 err = vkCreateEvent(device(), &event_info, &event);
2319 ASSERT_VK_SUCCESS(err);
2320
Mike Stroyan09aae812015-05-12 16:00:45 -06002321 err = vkResetEvent(device(), event);
2322 ASSERT_VK_SUCCESS(err);
2323
2324 struct thread_data_struct data;
Tony Barbour1490c912015-07-28 10:17:20 -06002325 data.cmdBuffer = m_cmdBuffer->handle();
Mike Stroyan09aae812015-05-12 16:00:45 -06002326 data.event = event;
2327 data.bailout = false;
2328 m_errorMonitor->SetBailout(&data.bailout);
2329 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002330 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06002331 // Add many entries to command buffer from this thread at the same time.
2332 AddToCommandBuffer(&data);
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002333 test_platform_thread_join(thread, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -06002334 EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002335
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002336 msgFlags = m_errorMonitor->GetState(&msgString);
Mike Stroyaned254572015-06-17 16:32:06 -06002337 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 -06002338 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05002339 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06002340 }
2341
2342}
2343#endif
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002344#endif
Chris Forbes5af3bf22015-05-25 11:13:08 +12002345#if SHADER_CHECKER_TESTS
2346TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
2347{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002348 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12002349 std::string msgString;
2350 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002351 ScopedUseGlsl useGlsl(false);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002352
2353 char const *vsSource =
2354 "#version 140\n"
2355 "#extension GL_ARB_separate_shader_objects: require\n"
2356 "#extension GL_ARB_shading_language_420pack: require\n"
2357 "\n"
2358 "layout(location=0) out float x;\n"
2359 "void main(){\n"
2360 " gl_Position = vec4(1);\n"
2361 " x = 0;\n"
2362 "}\n";
2363 char const *fsSource =
2364 "#version 140\n"
2365 "#extension GL_ARB_separate_shader_objects: require\n"
2366 "#extension GL_ARB_shading_language_420pack: require\n"
2367 "\n"
2368 "layout(location=0) out vec4 color;\n"
2369 "void main(){\n"
2370 " color = vec4(1);\n"
2371 "}\n";
2372
2373 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2374 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2375
2376 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002377 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12002378 pipe.AddShader(&vs);
2379 pipe.AddShader(&fs);
2380
Chris Forbes5af3bf22015-05-25 11:13:08 +12002381 VkDescriptorSetObj descriptorSet(m_device);
2382 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002383 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002384
2385 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002386 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12002387
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002388 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002389
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002390 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002391 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
2392 FAIL() << "Incorrect warning: " << msgString;
2393 }
2394}
Chris Forbes5af3bf22015-05-25 11:13:08 +12002395
Chris Forbes3c10b852015-05-25 11:13:13 +12002396TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
2397{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002398 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12002399 std::string msgString;
2400 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002401 ScopedUseGlsl useGlsl(false);
Chris Forbes3c10b852015-05-25 11:13:13 +12002402
2403 char const *vsSource =
2404 "#version 140\n"
2405 "#extension GL_ARB_separate_shader_objects: require\n"
2406 "#extension GL_ARB_shading_language_420pack: require\n"
2407 "\n"
2408 "void main(){\n"
2409 " gl_Position = vec4(1);\n"
2410 "}\n";
2411 char const *fsSource =
2412 "#version 140\n"
2413 "#extension GL_ARB_separate_shader_objects: require\n"
2414 "#extension GL_ARB_shading_language_420pack: require\n"
2415 "\n"
2416 "layout(location=0) in float x;\n"
2417 "layout(location=0) out vec4 color;\n"
2418 "void main(){\n"
2419 " color = vec4(x);\n"
2420 "}\n";
2421
2422 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2423 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2424
2425 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002426 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12002427 pipe.AddShader(&vs);
2428 pipe.AddShader(&fs);
2429
Chris Forbes3c10b852015-05-25 11:13:13 +12002430 VkDescriptorSetObj descriptorSet(m_device);
2431 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002432 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12002433
2434 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002435 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12002436
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002437 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12002438
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002439 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes3c10b852015-05-25 11:13:13 +12002440 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
2441 FAIL() << "Incorrect error: " << msgString;
2442 }
2443}
2444
Chris Forbescc281692015-05-25 11:13:17 +12002445TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
2446{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002447 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12002448 std::string msgString;
2449 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002450 ScopedUseGlsl useGlsl(false);
Chris Forbescc281692015-05-25 11:13:17 +12002451
2452 char const *vsSource =
2453 "#version 140\n"
2454 "#extension GL_ARB_separate_shader_objects: require\n"
2455 "#extension GL_ARB_shading_language_420pack: require\n"
2456 "\n"
2457 "layout(location=0) out int x;\n"
2458 "void main(){\n"
2459 " x = 0;\n"
2460 " gl_Position = vec4(1);\n"
2461 "}\n";
2462 char const *fsSource =
2463 "#version 140\n"
2464 "#extension GL_ARB_separate_shader_objects: require\n"
2465 "#extension GL_ARB_shading_language_420pack: require\n"
2466 "\n"
2467 "layout(location=0) in float x;\n" /* VS writes int */
2468 "layout(location=0) out vec4 color;\n"
2469 "void main(){\n"
2470 " color = vec4(x);\n"
2471 "}\n";
2472
2473 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2474 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2475
2476 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002477 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12002478 pipe.AddShader(&vs);
2479 pipe.AddShader(&fs);
2480
Chris Forbescc281692015-05-25 11:13:17 +12002481 VkDescriptorSetObj descriptorSet(m_device);
2482 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002483 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12002484
2485 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002486 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12002487
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002488 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12002489
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002490 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbescc281692015-05-25 11:13:17 +12002491 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
2492 FAIL() << "Incorrect error: " << msgString;
2493 }
2494}
2495
Chris Forbes8291c052015-05-25 11:13:28 +12002496TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
2497{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002498 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12002499 std::string msgString;
2500 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002501 ScopedUseGlsl useGlsl(false);
Chris Forbes8291c052015-05-25 11:13:28 +12002502
2503 VkVertexInputBindingDescription input_binding;
2504 memset(&input_binding, 0, sizeof(input_binding));
2505
2506 VkVertexInputAttributeDescription input_attrib;
2507 memset(&input_attrib, 0, sizeof(input_attrib));
2508 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2509
2510 char const *vsSource =
2511 "#version 140\n"
2512 "#extension GL_ARB_separate_shader_objects: require\n"
2513 "#extension GL_ARB_shading_language_420pack: require\n"
2514 "\n"
2515 "void main(){\n"
2516 " gl_Position = vec4(1);\n"
2517 "}\n";
2518 char const *fsSource =
2519 "#version 140\n"
2520 "#extension GL_ARB_separate_shader_objects: require\n"
2521 "#extension GL_ARB_shading_language_420pack: require\n"
2522 "\n"
2523 "layout(location=0) out vec4 color;\n"
2524 "void main(){\n"
2525 " color = vec4(1);\n"
2526 "}\n";
2527
2528 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2529 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2530
2531 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002532 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12002533 pipe.AddShader(&vs);
2534 pipe.AddShader(&fs);
2535
2536 pipe.AddVertexInputBindings(&input_binding, 1);
2537 pipe.AddVertexInputAttribs(&input_attrib, 1);
2538
Chris Forbes8291c052015-05-25 11:13:28 +12002539 VkDescriptorSetObj descriptorSet(m_device);
2540 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002541 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12002542
2543 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002544 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12002545
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002546 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12002547
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002548 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12002549 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
2550 FAIL() << "Incorrect warning: " << msgString;
2551 }
2552}
2553
Chris Forbes37367e62015-05-25 11:13:29 +12002554TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
2555{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002556 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12002557 std::string msgString;
2558 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002559 ScopedUseGlsl useGlsl(false);
Chris Forbes37367e62015-05-25 11:13:29 +12002560
2561 char const *vsSource =
2562 "#version 140\n"
2563 "#extension GL_ARB_separate_shader_objects: require\n"
2564 "#extension GL_ARB_shading_language_420pack: require\n"
2565 "\n"
2566 "layout(location=0) in vec4 x;\n" /* not provided */
2567 "void main(){\n"
2568 " gl_Position = x;\n"
2569 "}\n";
2570 char const *fsSource =
2571 "#version 140\n"
2572 "#extension GL_ARB_separate_shader_objects: require\n"
2573 "#extension GL_ARB_shading_language_420pack: require\n"
2574 "\n"
2575 "layout(location=0) out vec4 color;\n"
2576 "void main(){\n"
2577 " color = vec4(1);\n"
2578 "}\n";
2579
2580 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2581 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2582
2583 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002584 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12002585 pipe.AddShader(&vs);
2586 pipe.AddShader(&fs);
2587
Chris Forbes37367e62015-05-25 11:13:29 +12002588 VkDescriptorSetObj descriptorSet(m_device);
2589 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002590 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12002591
2592 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002593 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12002594
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002595 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12002596
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002597 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes37367e62015-05-25 11:13:29 +12002598 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
2599 FAIL() << "Incorrect warning: " << msgString;
2600 }
2601}
2602
Chris Forbesa4b02322015-05-25 11:13:31 +12002603TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
2604{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002605 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12002606 std::string msgString;
2607 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002608 ScopedUseGlsl useGlsl(false);
Chris Forbesa4b02322015-05-25 11:13:31 +12002609
2610 VkVertexInputBindingDescription input_binding;
2611 memset(&input_binding, 0, sizeof(input_binding));
2612
2613 VkVertexInputAttributeDescription input_attrib;
2614 memset(&input_attrib, 0, sizeof(input_attrib));
2615 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2616
2617 char const *vsSource =
2618 "#version 140\n"
2619 "#extension GL_ARB_separate_shader_objects: require\n"
2620 "#extension GL_ARB_shading_language_420pack: require\n"
2621 "\n"
2622 "layout(location=0) in int x;\n" /* attrib provided float */
2623 "void main(){\n"
2624 " gl_Position = vec4(x);\n"
2625 "}\n";
2626 char const *fsSource =
2627 "#version 140\n"
2628 "#extension GL_ARB_separate_shader_objects: require\n"
2629 "#extension GL_ARB_shading_language_420pack: require\n"
2630 "\n"
2631 "layout(location=0) out vec4 color;\n"
2632 "void main(){\n"
2633 " color = vec4(1);\n"
2634 "}\n";
2635
2636 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2637 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2638
2639 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002640 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12002641 pipe.AddShader(&vs);
2642 pipe.AddShader(&fs);
2643
2644 pipe.AddVertexInputBindings(&input_binding, 1);
2645 pipe.AddVertexInputAttribs(&input_attrib, 1);
2646
Chris Forbesa4b02322015-05-25 11:13:31 +12002647 VkDescriptorSetObj descriptorSet(m_device);
2648 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002649 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12002650
2651 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002652 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12002653
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002654 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12002655
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002656 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbesa4b02322015-05-25 11:13:31 +12002657 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
2658 FAIL() << "Incorrect error: " << msgString;
2659 }
2660}
2661
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002662TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
2663{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002664 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002665 std::string msgString;
2666 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002667 ScopedUseGlsl useGlsl(false);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002668
2669 /* Two binding descriptions for binding 0 */
2670 VkVertexInputBindingDescription input_bindings[2];
2671 memset(input_bindings, 0, sizeof(input_bindings));
2672
2673 VkVertexInputAttributeDescription input_attrib;
2674 memset(&input_attrib, 0, sizeof(input_attrib));
2675 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2676
2677 char const *vsSource =
2678 "#version 140\n"
2679 "#extension GL_ARB_separate_shader_objects: require\n"
2680 "#extension GL_ARB_shading_language_420pack: require\n"
2681 "\n"
2682 "layout(location=0) in float x;\n" /* attrib provided float */
2683 "void main(){\n"
2684 " gl_Position = vec4(x);\n"
2685 "}\n";
2686 char const *fsSource =
2687 "#version 140\n"
2688 "#extension GL_ARB_separate_shader_objects: require\n"
2689 "#extension GL_ARB_shading_language_420pack: require\n"
2690 "\n"
2691 "layout(location=0) out vec4 color;\n"
2692 "void main(){\n"
2693 " color = vec4(1);\n"
2694 "}\n";
2695
2696 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2697 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2698
2699 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002700 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002701 pipe.AddShader(&vs);
2702 pipe.AddShader(&fs);
2703
2704 pipe.AddVertexInputBindings(input_bindings, 2);
2705 pipe.AddVertexInputAttribs(&input_attrib, 1);
2706
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002707 VkDescriptorSetObj descriptorSet(m_device);
2708 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002709 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002710
2711 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002712 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002713
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002714 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002715
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002716 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002717 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
2718 FAIL() << "Incorrect error: " << msgString;
2719 }
2720}
Chris Forbes4c948702015-05-25 11:13:32 +12002721
Chris Forbesc12ef122015-05-25 11:13:40 +12002722/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
2723 * rejects it. */
2724
2725TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
2726{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002727 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12002728 std::string msgString;
2729 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002730 ScopedUseGlsl useGlsl(false);
Chris Forbesc12ef122015-05-25 11:13:40 +12002731
2732 char const *vsSource =
2733 "#version 140\n"
2734 "#extension GL_ARB_separate_shader_objects: require\n"
2735 "#extension GL_ARB_shading_language_420pack: require\n"
2736 "\n"
2737 "void main(){\n"
2738 " gl_Position = vec4(1);\n"
2739 "}\n";
2740 char const *fsSource =
2741 "#version 140\n"
2742 "#extension GL_ARB_separate_shader_objects: require\n"
2743 "#extension GL_ARB_shading_language_420pack: require\n"
2744 "\n"
2745 "void main(){\n"
2746 "}\n";
2747
2748 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2749 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2750
2751 VkPipelineObj pipe(m_device);
2752 pipe.AddShader(&vs);
2753 pipe.AddShader(&fs);
2754
Chia-I Wuc278df82015-07-07 11:50:03 +08002755 /* set up CB 0, not written */
2756 pipe.AddColorAttachment();
2757 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12002758
Chris Forbesc12ef122015-05-25 11:13:40 +12002759 VkDescriptorSetObj descriptorSet(m_device);
2760 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002761 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12002762
2763 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002764 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12002765
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002766 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12002767
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002768 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbesc12ef122015-05-25 11:13:40 +12002769 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
2770 FAIL() << "Incorrect error: " << msgString;
2771 }
2772}
2773
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002774TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
2775{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002776 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002777 std::string msgString;
2778 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002779 ScopedUseGlsl useGlsl(false);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002780
2781 char const *vsSource =
2782 "#version 140\n"
2783 "#extension GL_ARB_separate_shader_objects: require\n"
2784 "#extension GL_ARB_shading_language_420pack: require\n"
2785 "\n"
2786 "void main(){\n"
2787 " gl_Position = vec4(1);\n"
2788 "}\n";
2789 char const *fsSource =
2790 "#version 140\n"
2791 "#extension GL_ARB_separate_shader_objects: require\n"
2792 "#extension GL_ARB_shading_language_420pack: require\n"
2793 "\n"
2794 "layout(location=0) out vec4 x;\n"
2795 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
2796 "void main(){\n"
2797 " x = vec4(1);\n"
2798 " y = vec4(1);\n"
2799 "}\n";
2800
2801 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2802 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2803
2804 VkPipelineObj pipe(m_device);
2805 pipe.AddShader(&vs);
2806 pipe.AddShader(&fs);
2807
Chia-I Wuc278df82015-07-07 11:50:03 +08002808 /* set up CB 0, not written */
2809 pipe.AddColorAttachment();
2810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002811 /* FS writes CB 1, but we don't configure it */
2812
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002813 VkDescriptorSetObj descriptorSet(m_device);
2814 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002815 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002816
2817 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002818 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002819
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002820 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002821
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002822 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002823 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
2824 FAIL() << "Incorrect warning: " << msgString;
2825 }
2826}
2827
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002828TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
2829{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002830 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002831 std::string msgString;
2832 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002833 ScopedUseGlsl useGlsl(false);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002834
2835 char const *vsSource =
2836 "#version 140\n"
2837 "#extension GL_ARB_separate_shader_objects: require\n"
2838 "#extension GL_ARB_shading_language_420pack: require\n"
2839 "\n"
2840 "void main(){\n"
2841 " gl_Position = vec4(1);\n"
2842 "}\n";
2843 char const *fsSource =
2844 "#version 140\n"
2845 "#extension GL_ARB_separate_shader_objects: require\n"
2846 "#extension GL_ARB_shading_language_420pack: require\n"
2847 "\n"
2848 "layout(location=0) out ivec4 x;\n" /* not UNORM */
2849 "void main(){\n"
2850 " x = ivec4(1);\n"
2851 "}\n";
2852
2853 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2854 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2855
2856 VkPipelineObj pipe(m_device);
2857 pipe.AddShader(&vs);
2858 pipe.AddShader(&fs);
2859
Chia-I Wuc278df82015-07-07 11:50:03 +08002860 /* set up CB 0; type is UNORM by default */
2861 pipe.AddColorAttachment();
2862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002863
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002864 VkDescriptorSetObj descriptorSet(m_device);
2865 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002866 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002867
2868 m_errorMonitor->ClearState();
Chia-I Wuc278df82015-07-07 11:50:03 +08002869 pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002870
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002871 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002872
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002873 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002874 if (!strstr(msgString.c_str(),"does not match FS output type")) {
2875 FAIL() << "Incorrect error: " << msgString;
2876 }
2877}
Chris Forbesc2050732015-06-05 14:43:36 +12002878
2879TEST_F(VkLayerTest, CreatePipelineNonSpirvShader)
2880{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002881 VkFlags msgFlags;
Chris Forbesc2050732015-06-05 14:43:36 +12002882 std::string msgString;
2883 ASSERT_NO_FATAL_FAILURE(InitState());
2884 /* Intentionally provided GLSL rather than compiling to SPIRV first */
Cody Northrop1cfbd172015-06-03 16:49:20 -06002885 ScopedUseGlsl useGlsl(true);
Chris Forbesc2050732015-06-05 14:43:36 +12002886
2887 char const *vsSource =
2888 "#version 140\n"
2889 "#extension GL_ARB_separate_shader_objects: require\n"
2890 "#extension GL_ARB_shading_language_420pack: require\n"
2891 "\n"
2892 "void main(){\n"
2893 " gl_Position = vec4(1);\n"
2894 "}\n";
2895 char const *fsSource =
2896 "#version 140\n"
2897 "#extension GL_ARB_separate_shader_objects: require\n"
2898 "#extension GL_ARB_shading_language_420pack: require\n"
2899 "\n"
2900 "layout(location=0) out vec4 x;\n"
2901 "void main(){\n"
2902 " x = vec4(1);\n"
2903 "}\n";
2904
2905 m_errorMonitor->ClearState();
2906
2907 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2908 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2909
2910
2911 VkPipelineObj pipe(m_device);
2912 pipe.AddShader(&vs);
2913 pipe.AddShader(&fs);
2914
Chia-I Wuc278df82015-07-07 11:50:03 +08002915 /* set up CB 0; type is UNORM by default */
2916 pipe.AddColorAttachment();
2917 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc2050732015-06-05 14:43:36 +12002918
Chris Forbesc2050732015-06-05 14:43:36 +12002919 VkDescriptorSetObj descriptorSet(m_device);
2920 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002921 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc2050732015-06-05 14:43:36 +12002922
Chia-I Wuc278df82015-07-07 11:50:03 +08002923 VkResult res = pipe.CreateVKPipeline(descriptorSet, renderPass());
Chris Forbesc2050732015-06-05 14:43:36 +12002924 /* pipeline creation should have succeeded */
2925 ASSERT_EQ(VK_SUCCESS, res);
2926
2927 /* should have emitted a warning: the shader is not SPIRV, so we're
2928 * not going to be able to analyze it */
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002929 msgFlags = m_errorMonitor->GetState(&msgString);
2930 ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesc2050732015-06-05 14:43:36 +12002931 if (!strstr(msgString.c_str(),"is not SPIR-V")) {
2932 FAIL() << "Incorrect warning: " << msgString;
2933 }
2934}
Chris Forbes01c9db72015-06-04 09:25:25 +12002935#endif
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002936
Tony Barbour30486ea2015-04-07 13:44:53 -06002937int main(int argc, char **argv) {
2938 int result;
2939
2940 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06002941 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06002942
2943 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
2944
2945 result = RUN_ALL_TESTS();
2946
Tony Barbour01999182015-04-09 12:58:51 -06002947 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06002948 return result;
2949}