blob: 66f13055f7d0086e8d5ab1eae388f9dd0fb51e13 [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);
Tony Barboured132432015-08-04 16:23:11 -0600342 pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), 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);
Cody Northrop1684adb2015-08-05 11:15:02 -0600385 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling ResetCommandBuffer on an active Command Buffer";
Mark Lobodzinski81078192015-05-19 10:28:29 -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);
Cody Northrop1684adb2015-08-05 11:15:02 -0600422 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling BeginCommandBuffer on an active Command Buffer";
Mark Lobodzinski81078192015-05-19 10:28:29 -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
Mike Stroyand72da752015-08-04 10:49:29 -0600478 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tony Barbour49a3b652015-08-04 16:13:01 -0600479 if(err != VK_SUCCESS) // If we can't find any unmappable memory this test doesn't make sense
480 return;
Mike Stroyand72da752015-08-04 10:49:29 -0600481
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500482 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500483 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500484 ASSERT_VK_SUCCESS(err);
485
486 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600487 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500488 ASSERT_VK_SUCCESS(err);
489
490 // Map memory as if to initialize the image
491 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500492 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500493
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600494 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600495 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to map memory not visible to CPU";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500496 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
497 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
498 }
499}
500
501TEST_F(VkLayerTest, BindInvalidMemory)
502{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600503 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500504 std::string msgString;
505 VkResult err;
506
507 ASSERT_NO_FATAL_FAILURE(InitState());
508 m_errorMonitor->ClearState();
509
510 // Create an image, allocate memory, free it, and then try to bind it
511 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500512 VkDeviceMemory mem;
513 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500514
515 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
516 const int32_t tex_width = 32;
517 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500518
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600519 VkImageCreateInfo image_create_info = {};
520 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
521 image_create_info.pNext = NULL;
522 image_create_info.imageType = VK_IMAGE_TYPE_2D;
523 image_create_info.format = tex_format;
524 image_create_info.extent.width = tex_width;
525 image_create_info.extent.height = tex_height;
526 image_create_info.extent.depth = 1;
527 image_create_info.mipLevels = 1;
528 image_create_info.arraySize = 1;
529 image_create_info.samples = 1;
530 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
531 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
532 image_create_info.flags = 0;
533
534 VkMemoryAllocInfo mem_alloc = {};
535 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
536 mem_alloc.pNext = NULL;
537 mem_alloc.allocationSize = 0;
538 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500539
540 err = vkCreateImage(m_device->device(), &image_create_info, &image);
541 ASSERT_VK_SUCCESS(err);
542
Tony Barboure84a8d62015-07-10 14:10:27 -0600543 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500544 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500545 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500546 ASSERT_VK_SUCCESS(err);
547
Mark Lobodzinski23182612015-05-29 09:32:35 -0500548 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500549
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800550 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600551 ASSERT_VK_SUCCESS(err);
552
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500553 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500554 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500555 ASSERT_VK_SUCCESS(err);
556
557 // Introduce validation failure, free memory before binding
Mark Lobodzinski23182612015-05-29 09:32:35 -0500558 vkFreeMemory(m_device->device(), mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500559 ASSERT_VK_SUCCESS(err);
560
561 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600562 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Cody Northrop87333892015-08-06 12:40:01 -0600563 // This may very well return an error.
564 (void)err;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500565
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600566 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600567 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to bind a freed memory object";
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500568 if (!strstr(msgString.c_str(),"couldn't find info for mem obj")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500569 FAIL() << "Error received did not match expected error message from BindObjectMemory in MemTracker";
570 }
571}
572
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600573// TODO : Is this test still valid. Not sure it is with updates to memory binding model
574// Verify and delete the test of fix the check
575//TEST_F(VkLayerTest, FreeBoundMemory)
576//{
577// VkFlags msgFlags;
578// std::string msgString;
579// VkResult err;
580//
581// ASSERT_NO_FATAL_FAILURE(InitState());
582// m_errorMonitor->ClearState();
583//
584// // Create an image, allocate memory, free it, and then try to bind it
585// VkImage image;
586// VkDeviceMemory mem;
587// VkMemoryRequirements mem_reqs;
588//
589// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
590// const int32_t tex_width = 32;
591// const int32_t tex_height = 32;
592//
593// const VkImageCreateInfo image_create_info = {
594// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
595// .pNext = NULL,
596// .imageType = VK_IMAGE_TYPE_2D,
597// .format = tex_format,
598// .extent = { tex_width, tex_height, 1 },
599// .mipLevels = 1,
600// .arraySize = 1,
601// .samples = 1,
602// .tiling = VK_IMAGE_TILING_LINEAR,
603// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
604// .flags = 0,
605// };
606// VkMemoryAllocInfo mem_alloc = {
607// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
608// .pNext = NULL,
609// .allocationSize = 0,
610// .memoryTypeIndex = 0,
611// };
612//
613// err = vkCreateImage(m_device->device(), &image_create_info, &image);
614// ASSERT_VK_SUCCESS(err);
615//
616// err = vkGetImageMemoryRequirements(m_device->device(),
617// image,
618// &mem_reqs);
619// ASSERT_VK_SUCCESS(err);
620//
621// mem_alloc.allocationSize = mem_reqs.size;
622//
623// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
624// ASSERT_VK_SUCCESS(err);
625//
626// // allocate memory
627// err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
628// ASSERT_VK_SUCCESS(err);
629//
630// // Bind memory to Image object
631// err = vkBindImageMemory(m_device->device(), image, mem, 0);
632// ASSERT_VK_SUCCESS(err);
633//
634// // Introduce validation failure, free memory while still bound to object
635// vkFreeMemory(m_device->device(), mem);
636// ASSERT_VK_SUCCESS(err);
637//
638// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600639// ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an warning while tring to free bound memory";
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600640// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
641// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
642// }
643//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500644
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500645TEST_F(VkLayerTest, RebindMemory)
646{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600647 VkFlags msgFlags;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500648 std::string msgString;
649 VkResult err;
650
651 ASSERT_NO_FATAL_FAILURE(InitState());
652 m_errorMonitor->ClearState();
653
654 // Create an image, allocate memory, free it, and then try to bind it
655 VkImage image;
656 VkDeviceMemory mem1;
657 VkDeviceMemory mem2;
658 VkMemoryRequirements mem_reqs;
659
660 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
661 const int32_t tex_width = 32;
662 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500663
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600664 VkImageCreateInfo image_create_info = {};
665 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
666 image_create_info.pNext = NULL;
667 image_create_info.imageType = VK_IMAGE_TYPE_2D;
668 image_create_info.format = tex_format;
669 image_create_info.extent.width = tex_width;
670 image_create_info.extent.height = tex_height;
671 image_create_info.extent.depth = 1;
672 image_create_info.mipLevels = 1;
673 image_create_info.arraySize = 1;
674 image_create_info.samples = 1;
675 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
676 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
677 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500678
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600679 VkMemoryAllocInfo mem_alloc = {};
680 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
681 mem_alloc.pNext = NULL;
682 mem_alloc.allocationSize = 0;
683 mem_alloc.memoryTypeIndex = 0;
684
685 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
686 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500687 err = vkCreateImage(m_device->device(), &image_create_info, &image);
688 ASSERT_VK_SUCCESS(err);
689
Tony Barboure84a8d62015-07-10 14:10:27 -0600690 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500691 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500692 &mem_reqs);
693 ASSERT_VK_SUCCESS(err);
694
695 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800696 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600697 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500698
699 // allocate 2 memory objects
700 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
701 ASSERT_VK_SUCCESS(err);
702 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
703 ASSERT_VK_SUCCESS(err);
704
705 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600706 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500707 ASSERT_VK_SUCCESS(err);
708
709 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600710 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500711 ASSERT_VK_SUCCESS(err);
712
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600713 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600714 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to rebind an object";
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500715 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
716 FAIL() << "Error received did not match expected message when rebinding memory to an object";
717 }
718}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500719
720TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
721{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600722 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500723 std::string msgString;
724 VkResult err;
725
726 ASSERT_NO_FATAL_FAILURE(InitState());
727 m_errorMonitor->ClearState();
728
729 // Create an image object, allocate memory, destroy the object and then try to bind it
730 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500731 VkDeviceMemory mem;
732 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500733
734 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
735 const int32_t tex_width = 32;
736 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500737
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600738 VkImageCreateInfo image_create_info = {};
739 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
740 image_create_info.pNext = NULL;
741 image_create_info.imageType = VK_IMAGE_TYPE_2D;
742 image_create_info.format = tex_format;
743 image_create_info.extent.width = tex_width;
744 image_create_info.extent.height = tex_height;
745 image_create_info.extent.depth = 1;
746 image_create_info.mipLevels = 1;
747 image_create_info.arraySize = 1;
748 image_create_info.samples = 1;
749 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
750 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
751 image_create_info.flags = 0;
752
753 VkMemoryAllocInfo mem_alloc = {};
754 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
755 mem_alloc.pNext = NULL;
756 mem_alloc.allocationSize = 0;
757 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500758
759 err = vkCreateImage(m_device->device(), &image_create_info, &image);
760 ASSERT_VK_SUCCESS(err);
761
Tony Barboure84a8d62015-07-10 14:10:27 -0600762 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500763 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500764 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500765 ASSERT_VK_SUCCESS(err);
766
Mark Lobodzinski23182612015-05-29 09:32:35 -0500767 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800768 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600769 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500770
771 // Allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500772 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500773 ASSERT_VK_SUCCESS(err);
774
775 // Introduce validation failure, destroy Image object before binding
Tony Barboure84a8d62015-07-10 14:10:27 -0600776 vkDestroyImage(m_device->device(), image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500777 ASSERT_VK_SUCCESS(err);
778
Mike Stroyand72da752015-08-04 10:49:29 -0600779 // Now Try to bind memory to this destroyed object
Tony Barboure84a8d62015-07-10 14:10:27 -0600780 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mike Stroyand72da752015-08-04 10:49:29 -0600781 // This may very well return an error.
782 (void) err;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500783
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600784 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600785 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while binding memory to a destroyed object";
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500786 if (!strstr(msgString.c_str(),"that's not in global list")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500787 FAIL() << "Error received did not match expected error message from updateObjectBinding in MemTracker";
788 }
789}
790
Tony Barbour8508b8e2015-04-09 10:48:04 -0600791TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600792{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600793 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600794 VkFlags msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600795 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600796
797 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600798 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
799 fenceInfo.pNext = NULL;
800 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600801
Tony Barbour30486ea2015-04-07 13:44:53 -0600802 ASSERT_NO_FATAL_FAILURE(InitState());
803 ASSERT_NO_FATAL_FAILURE(InitViewport());
804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
805
Tony Barbour1490c912015-07-28 10:17:20 -0600806 BeginCommandBuffer();
807 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
808 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600809
810 testFence.init(*m_device, fenceInfo);
811 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -0600812 QueueCommandBuffer(testFence.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600813 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600814 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err from using a fence in SIGNALED state in call to vkQueueSubmit";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600815 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500816 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600817 }
818
819}
820
821TEST_F(VkLayerTest, ResetUnsignaledFence)
822{
823 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600824 VkFlags msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600825 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600826 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600827 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
828 fenceInfo.pNext = NULL;
829
Tony Barbour8508b8e2015-04-09 10:48:04 -0600830 ASSERT_NO_FATAL_FAILURE(InitState());
831 testFence.init(*m_device, fenceInfo);
832 m_errorMonitor->ClearState();
Chia-I Wua4992342015-07-03 11:45:55 +0800833 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600834 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600835 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600836 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from submitting fence with UNSIGNALED state to vkResetFences";
Tony Barbour01999182015-04-09 12:58:51 -0600837 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500838 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600839 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600840
841}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600842
Chia-I Wuc278df82015-07-07 11:50:03 +0800843/* TODO: Update for changes due to bug-14075 tiling across render passes */
844#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600845TEST_F(VkLayerTest, InvalidUsageBits)
846{
847 // Initiate Draw w/o a PSO bound
848 VkFlags msgFlags;
849 std::string msgString;
850
851 ASSERT_NO_FATAL_FAILURE(InitState());
852 m_errorMonitor->ClearState();
853 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600854 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600855
856 const VkExtent3D e3d = {
857 .width = 128,
858 .height = 128,
859 .depth = 1,
860 };
861 const VkImageCreateInfo ici = {
862 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
863 .pNext = NULL,
864 .imageType = VK_IMAGE_TYPE_2D,
865 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
866 .extent = e3d,
867 .mipLevels = 1,
868 .arraySize = 1,
869 .samples = 1,
870 .tiling = VK_IMAGE_TILING_LINEAR,
871 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_BIT
872 .flags = 0,
873 };
874
875 VkImage dsi;
876 vkCreateImage(m_device->device(), &ici, &dsi);
877 VkDepthStencilView dsv;
878 const VkDepthStencilViewCreateInfo dsvci = {
879 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
880 .pNext = NULL,
881 .image = dsi,
882 .mipLevel = 0,
883 .baseArraySlice = 0,
884 .arraySize = 1,
885 .flags = 0,
886 };
887 vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv);
888 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600889 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after attempting to create DSView w/ image lacking USAGE_DS_BIT flag";
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600890 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
891 FAIL() << "Error received was not 'Invalid usage flag for image...'";
892 }
893}
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600894#endif
Chia-I Wuc278df82015-07-07 11:50:03 +0800895#endif
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600896#if OBJ_TRACKER_TESTS
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500897TEST_F(VkLayerTest, RasterStateNotBound)
898{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600899 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500900 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600901 ASSERT_NO_FATAL_FAILURE(InitState());
902 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500903 TEST_DESCRIPTION("Simple Draw Call that validates failure when a raster state object is not bound beforehand");
904
905 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailRaster);
906
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600907 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600908 ASSERT_TRUE(0 != (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 -0500909 if (!strstr(msgString.c_str(),"Raster object not bound to this command buffer")) {
910 FAIL() << "Error received was not 'Raster object not bound to this command buffer'";
911 }
912}
913
914TEST_F(VkLayerTest, ViewportStateNotBound)
915{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600916 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500917 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600918 ASSERT_NO_FATAL_FAILURE(InitState());
919 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500920 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
921
922 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
923
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600924 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600925 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500926 if (!strstr(msgString.c_str(),"Viewport object not bound to this command buffer")) {
927 FAIL() << "Error received was not 'Viewport object not bound to this command buffer'";
928 }
929}
930
931TEST_F(VkLayerTest, ColorBlendStateNotBound)
932{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600933 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500934 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600935 ASSERT_NO_FATAL_FAILURE(InitState());
936 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500937 TEST_DESCRIPTION("Simple Draw Call that validates failure when a color-blend state object is not bound beforehand");
938
939 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailColorBlend);
940
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600941 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600942 ASSERT_TRUE(0 != (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 -0500943 if (!strstr(msgString.c_str(),"Color-blend object not bound to this command buffer")) {
944 FAIL() << "Error received was not 'Color-blend object not bound to this command buffer'";
945 }
946}
947
948TEST_F(VkLayerTest, DepthStencilStateNotBound)
949{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600950 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500951 std::string msgString;
Tobin Ehlis254eca02015-06-25 15:46:59 -0600952 ASSERT_NO_FATAL_FAILURE(InitState());
953 m_errorMonitor->ClearState();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500954 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth-stencil state object is not bound beforehand");
955
956 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthStencil);
957
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600958 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600959 ASSERT_TRUE(0 != (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 -0500960 if (!strstr(msgString.c_str(),"Depth-stencil object not bound to this command buffer")) {
961 FAIL() << "Error received was not 'Depth-stencil object not bound to this command buffer'";
962 }
Tony Barbourdb686622015-05-06 09:35:56 -0600963}
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600964#endif
965#if DRAW_STATE_TESTS
Tobin Ehlise4076782015-06-24 15:53:07 -0600966TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600967{
968 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600969 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600970 std::string msgString;
971
972 ASSERT_NO_FATAL_FAILURE(InitState());
973 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -0600974 BeginCommandBuffer();
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600975 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Tony Barbour1490c912015-07-28 10:17:20 -0600976 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600977 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600978 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding pipeline to CmdBuffer w/o active RenderPass";
Tobin Ehlise4076782015-06-24 15:53:07 -0600979 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
980 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0xbaadb1be) without an active RenderPass'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -0600981 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600982}
983
984TEST_F(VkLayerTest, InvalidDescriptorPool)
985{
986 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
987 // The DS check for this is after driver has been called to validate DS internal data struct
988 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600989/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600990 std::string msgString;
991 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
992 vkResetDescriptorPool(device(), badPool);
993
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600994 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600995 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Resetting an invalid DescriptorPool Object";
Tobin Ehlis138b7f12015-05-22 12:38:55 -0600996 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
997 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
998 }*/
999}
1000
1001TEST_F(VkLayerTest, InvalidDescriptorSet)
1002{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001003 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1004 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001005 // Create a valid cmd buffer
1006 // call vkCmdBindDescriptorSets w/ false DS
1007}
1008
1009TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1010{
1011 // 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
1013}
1014
1015TEST_F(VkLayerTest, InvalidPipeline)
1016{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001017 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1018 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001019 // Create a valid cmd buffer
1020 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -06001021// VkFlags msgFlags;
1022// std::string msgString;
1023//
1024// ASSERT_NO_FATAL_FAILURE(InitState());
1025// m_errorMonitor->ClearState();
1026// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001027// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001028// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1029// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1030// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001031// ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Tobin Ehlise4076782015-06-24 15:53:07 -06001032// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1033// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1034// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001035}
1036
Tobin Ehlis254eca02015-06-25 15:46:59 -06001037TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001038{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001039 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001040 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001041 std::string msgString;
1042 VkResult err;
1043
1044 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001045 ASSERT_NO_FATAL_FAILURE(InitViewport());
1046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001047 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001048 VkDescriptorTypeCount ds_type_count = {};
1049 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1050 ds_type_count.count = 1;
1051
1052 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1053 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1054 ds_pool_ci.pNext = NULL;
1055 ds_pool_ci.count = 1;
1056 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001057
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001058 VkDescriptorPool ds_pool;
1059 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1060 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001061
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001062 VkDescriptorSetLayoutBinding dsl_binding = {};
1063 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1064 dsl_binding.arraySize = 1;
1065 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1066 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001067
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001068 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1069 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1070 ds_layout_ci.pNext = NULL;
1071 ds_layout_ci.count = 1;
1072 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001073 VkDescriptorSetLayout ds_layout;
1074 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1075 ASSERT_VK_SUCCESS(err);
1076
1077 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001078 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001079 ASSERT_VK_SUCCESS(err);
1080
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001081 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1082 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1083 pipeline_layout_ci.pNext = NULL;
1084 pipeline_layout_ci.descriptorSetCount = 1;
1085 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001086
1087 VkPipelineLayout pipeline_layout;
1088 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1089 ASSERT_VK_SUCCESS(err);
1090
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001091 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001092 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1093 // but add it to be able to run on more devices
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001094
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001095 VkPipelineObj pipe(m_device);
1096 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001097 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001098 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001099
1100 BeginCommandBuffer();
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001101 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbour1490c912015-07-28 10:17:20 -06001102 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001103
Tobin Ehlis254eca02015-06-25 15:46:59 -06001104 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001105 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not warn after binding a DescriptorSet that was never updated.";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001106 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1107 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1108 }
1109}
1110
1111TEST_F(VkLayerTest, NoBeginCmdBuffer)
1112{
1113 VkFlags msgFlags;
1114 std::string msgString;
1115
1116 ASSERT_NO_FATAL_FAILURE(InitState());
1117 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001118 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001119 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1120 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1121 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001122 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after ending a CmdBuffer w/o calling BeginCommandBuffer()";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001123 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1124 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1125 }
1126}
1127
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001128TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1129{
1130 VkFlags msgFlags;
1131 std::string msgString;
1132
1133 ASSERT_NO_FATAL_FAILURE(InitState());
1134 m_errorMonitor->ClearState();
1135
1136 // Calls CreateCommandBuffer
1137 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1138
1139 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northrop10d8f982015-08-04 17:35:57 -06001140 VkCmdBufferBeginInfo cmd_buf_info = {};
1141 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1142 cmd_buf_info.pNext = NULL;
1143 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1144 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1145 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1146 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1147
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001148
1149 // The error should be caught by validation of the BeginCommandBuffer call
1150 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1151
1152 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001153 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error passing a non-NULL Framebuffer and Renderpass to BeginCommandBuffer()";
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001154 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1155 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1156 }
1157}
1158
1159TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1160{
1161 VkFlags msgFlags;
1162 std::string msgString;
1163 VkResult err;
1164 VkCmdBuffer draw_cmd;
1165 VkCmdPool cmd_pool;
1166
1167 ASSERT_NO_FATAL_FAILURE(InitState());
1168 m_errorMonitor->ClearState();
1169
Cody Northrop10d8f982015-08-04 17:35:57 -06001170 VkCmdBufferCreateInfo cmd = {};
1171 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1172 cmd.pNext = NULL;
1173 cmd.cmdPool = m_cmdPool;
1174 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1175 cmd.flags = 0;
1176
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001177 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
1178 assert(!err);
1179
1180 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northrop10d8f982015-08-04 17:35:57 -06001181 VkCmdBufferBeginInfo cmd_buf_info = {};
1182 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1183 cmd_buf_info.pNext = NULL;
1184 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1185 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001186
1187 // The error should be caught by validation of the BeginCommandBuffer call
1188 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1189
1190 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001191 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error passing NULL Framebuffer/Renderpass to BeginCommandBuffer()";
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001192 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1193 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1194 }
1195}
1196
Tobin Ehlis254eca02015-06-25 15:46:59 -06001197TEST_F(VkLayerTest, InvalidPipelineCreateState)
1198{
1199 // Attempt to Create Gfx Pipeline w/o a VS
1200 VkFlags msgFlags;
1201 std::string msgString;
1202 VkResult err;
1203
1204 ASSERT_NO_FATAL_FAILURE(InitState());
1205 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001206
1207 VkDescriptorTypeCount ds_type_count = {};
1208 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1209 ds_type_count.count = 1;
1210
1211 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1212 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1213 ds_pool_ci.pNext = NULL;
1214 ds_pool_ci.count = 1;
1215 ds_pool_ci.pTypeCount = &ds_type_count;
1216
Tobin Ehlis254eca02015-06-25 15:46:59 -06001217 VkDescriptorPool ds_pool;
1218 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1219 ASSERT_VK_SUCCESS(err);
1220
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001221 VkDescriptorSetLayoutBinding dsl_binding = {};
1222 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1223 dsl_binding.arraySize = 1;
1224 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1225 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001226
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001227 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1228 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1229 ds_layout_ci.pNext = NULL;
1230 ds_layout_ci.count = 1;
1231 ds_layout_ci.pBinding = &dsl_binding;
1232
Tobin Ehlis254eca02015-06-25 15:46:59 -06001233 VkDescriptorSetLayout ds_layout;
1234 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1235 ASSERT_VK_SUCCESS(err);
1236
1237 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001238 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001239 ASSERT_VK_SUCCESS(err);
1240
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001241 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1242 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1243 pipeline_layout_ci.pNext = NULL;
1244 pipeline_layout_ci.descriptorSetCount = 1;
1245 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001246
1247 VkPipelineLayout pipeline_layout;
1248 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1249 ASSERT_VK_SUCCESS(err);
1250
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001251 VkGraphicsPipelineCreateInfo gp_ci = {};
1252 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1253 gp_ci.pNext = NULL;
1254 gp_ci.stageCount = 0;
1255 gp_ci.pStages = NULL;
1256 gp_ci.pVertexInputState = NULL;
1257 gp_ci.pInputAssemblyState = NULL;
1258 gp_ci.pTessellationState = NULL;
1259 gp_ci.pViewportState = NULL;
1260 gp_ci.pRasterState = NULL;
1261 gp_ci.pMultisampleState = NULL;
1262 gp_ci.pDepthStencilState = NULL;
1263 gp_ci.pColorBlendState = NULL;
1264 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1265 gp_ci.layout = pipeline_layout;
1266
1267 VkPipelineCacheCreateInfo pc_ci = {};
1268 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1269 pc_ci.pNext = NULL;
1270 pc_ci.initialSize = 0;
1271 pc_ci.initialData = 0;
1272 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001273
1274 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001275 VkPipelineCache pipelineCache;
1276
1277 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1278 ASSERT_VK_SUCCESS(err);
1279 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001280
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001281 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001282 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o VS.";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001283 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1284 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1285 }
1286}
1287
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001288TEST_F(VkLayerTest, NullRenderPass)
1289{
1290 // Bind a NULL RenderPass
1291 VkFlags msgFlags;
1292 std::string msgString;
1293
1294 ASSERT_NO_FATAL_FAILURE(InitState());
1295 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1296 m_errorMonitor->ClearState();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001297
Tony Barbour1490c912015-07-28 10:17:20 -06001298 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001299 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06001300 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001301
1302 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001303 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001304 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
1305 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
1306 }
1307}
1308
Tobin Ehlis254eca02015-06-25 15:46:59 -06001309TEST_F(VkLayerTest, RenderPassWithinRenderPass)
1310{
1311 // Bind a BeginRenderPass within an active RenderPass
1312 VkFlags msgFlags;
1313 std::string msgString;
1314
1315 ASSERT_NO_FATAL_FAILURE(InitState());
1316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1317 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06001318
Tony Barbour1490c912015-07-28 10:17:20 -06001319 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06001320 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001321 VkRenderPassBeginInfo rp_begin = {};
1322 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
1323 rp_begin.pNext = NULL;
1324 rp_begin.renderPass = (VkRenderPass)0xc001d00d;
1325 rp_begin.framebuffer = 0;
1326
Tony Barbour1490c912015-07-28 10:17:20 -06001327 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001328
1329 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001330 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding RenderPass w/i an active RenderPass.";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001331 if (!strstr(msgString.c_str(),"Cannot call vkCmdBeginRenderPass() during an active RenderPass ")) {
1332 FAIL() << "Error received was not 'Cannot call vkCmdBeginRenderPass() during an active RenderPass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001333 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001334}
1335
1336TEST_F(VkLayerTest, InvalidDynamicStateObject)
1337{
1338 // Create a valid cmd buffer
1339 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001340 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1341 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001342}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06001343
Tobin Ehlise4076782015-06-24 15:53:07 -06001344TEST_F(VkLayerTest, VtxBufferNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001345{
1346 // Bind VBO out-of-bounds for given PSO
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001347 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001348 std::string msgString;
1349 VkResult err;
1350
1351 ASSERT_NO_FATAL_FAILURE(InitState());
1352 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001353
1354 VkDescriptorTypeCount ds_type_count = {};
1355 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1356 ds_type_count.count = 1;
1357
1358 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1359 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1360 ds_pool_ci.pNext = NULL;
1361 ds_pool_ci.count = 1;
1362 ds_pool_ci.pTypeCount = &ds_type_count;
1363
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001364 VkDescriptorPool ds_pool;
1365 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1366 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001367
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001368 VkDescriptorSetLayoutBinding dsl_binding = {};
1369 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1370 dsl_binding.arraySize = 1;
1371 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1372 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001373
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001374 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1375 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1376 ds_layout_ci.pNext = NULL;
1377 ds_layout_ci.count = 1;
1378 ds_layout_ci.pBinding = &dsl_binding;
1379
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001380 VkDescriptorSetLayout ds_layout;
1381 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1382 ASSERT_VK_SUCCESS(err);
1383
1384 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001385 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001386 ASSERT_VK_SUCCESS(err);
1387
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001388 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1389 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1390 pipeline_layout_ci.pNext = NULL;
1391 pipeline_layout_ci.descriptorSetCount = 1;
1392 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001393
1394 VkPipelineLayout pipeline_layout;
1395 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1396 ASSERT_VK_SUCCESS(err);
1397
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001398 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001399 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1400 // but add it to be able to run on more devices
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001401 VkPipelineObj pipe(m_device);
1402 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001403 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001404 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001405
Tony Barbour1490c912015-07-28 10:17:20 -06001406 BeginCommandBuffer();
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001407 ASSERT_VK_SUCCESS(err);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001408 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001409 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06001410 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001411
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001412 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001413 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
Tobin Ehlise4076782015-06-24 15:53:07 -06001414 if (!strstr(msgString.c_str(),"Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.")) {
1415 FAIL() << "Error received was not 'Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001416 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001417}
1418
1419TEST_F(VkLayerTest, DSTypeMismatch)
1420{
1421 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001422 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001423 std::string msgString;
1424 VkResult err;
1425
1426 ASSERT_NO_FATAL_FAILURE(InitState());
1427 m_errorMonitor->ClearState();
1428 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001429 VkDescriptorTypeCount ds_type_count = {};
1430 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1431 ds_type_count.count = 1;
1432
1433 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1434 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1435 ds_pool_ci.pNext = NULL;
1436 ds_pool_ci.count = 1;
1437 ds_pool_ci.pTypeCount = &ds_type_count;
1438
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001439 VkDescriptorPool ds_pool;
1440 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1441 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001442 VkDescriptorSetLayoutBinding dsl_binding = {};
1443 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1444 dsl_binding.arraySize = 1;
1445 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1446 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001447
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001448 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1449 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1450 ds_layout_ci.pNext = NULL;
1451 ds_layout_ci.count = 1;
1452 ds_layout_ci.pBinding = &dsl_binding;
1453
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001454 VkDescriptorSetLayout ds_layout;
1455 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1456 ASSERT_VK_SUCCESS(err);
1457
1458 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001459 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001460 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001461
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001462 VkSamplerCreateInfo sampler_ci = {};
1463 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1464 sampler_ci.pNext = NULL;
1465 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1466 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1467 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1468 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1469 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1470 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1471 sampler_ci.mipLodBias = 1.0;
1472 sampler_ci.maxAnisotropy = 1;
1473 sampler_ci.compareEnable = VK_FALSE;
1474 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1475 sampler_ci.minLod = 1.0;
1476 sampler_ci.maxLod = 1.0;
1477 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northrop0bf4e1d2015-08-11 15:50:55 -06001478 sampler_ci.texelCoords = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001479
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001480 VkSampler sampler;
1481 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1482 ASSERT_VK_SUCCESS(err);
1483
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001484 VkDescriptorInfo descriptor_info;
1485 memset(&descriptor_info, 0, sizeof(descriptor_info));
1486 descriptor_info.sampler = sampler;
1487
1488 VkWriteDescriptorSet descriptor_write;
1489 memset(&descriptor_write, 0, sizeof(descriptor_write));
1490 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1491 descriptor_write.destSet = descriptorSet;
1492 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001493 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001494 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1495 descriptor_write.pDescriptors = &descriptor_info;
1496
1497 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1498
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001499 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001500 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating BUFFER Descriptor w/ incorrect type of SAMPLER.";
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001501 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) {
1502 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 -06001503 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001504}
1505
1506TEST_F(VkLayerTest, DSUpdateOutOfBounds)
1507{
1508 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001509 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001510 std::string msgString;
1511 VkResult err;
1512
1513 ASSERT_NO_FATAL_FAILURE(InitState());
1514 m_errorMonitor->ClearState();
1515 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001516 VkDescriptorTypeCount ds_type_count = {};
1517 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1518 ds_type_count.count = 1;
1519
1520 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1521 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1522 ds_pool_ci.pNext = NULL;
1523 ds_pool_ci.count = 1;
1524 ds_pool_ci.pTypeCount = &ds_type_count;
1525
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001526 VkDescriptorPool ds_pool;
1527 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1528 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001529
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001530 VkDescriptorSetLayoutBinding dsl_binding = {};
1531 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1532 dsl_binding.arraySize = 1;
1533 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1534 dsl_binding.pImmutableSamplers = NULL;
1535
1536 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1537 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1538 ds_layout_ci.pNext = NULL;
1539 ds_layout_ci.count = 1;
1540 ds_layout_ci.pBinding = &dsl_binding;
1541
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001542 VkDescriptorSetLayout ds_layout;
1543 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1544 ASSERT_VK_SUCCESS(err);
1545
1546 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001547 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001548 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001549
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001550 VkSamplerCreateInfo sampler_ci = {};
1551 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1552 sampler_ci.pNext = NULL;
1553 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1554 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1555 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1556 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1557 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1558 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1559 sampler_ci.mipLodBias = 1.0;
1560 sampler_ci.maxAnisotropy = 1;
1561 sampler_ci.compareEnable = VK_FALSE;
1562 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1563 sampler_ci.minLod = 1.0;
1564 sampler_ci.maxLod = 1.0;
1565 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northrop0bf4e1d2015-08-11 15:50:55 -06001566 sampler_ci.texelCoords = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001567
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001568 VkSampler sampler;
1569 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1570 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001571
1572 VkDescriptorInfo descriptor_info;
1573 memset(&descriptor_info, 0, sizeof(descriptor_info));
1574 descriptor_info.sampler = sampler;
1575
1576 VkWriteDescriptorSet descriptor_write;
1577 memset(&descriptor_write, 0, sizeof(descriptor_write));
1578 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1579 descriptor_write.destSet = descriptorSet;
1580 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
1581 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001582 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001583 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1584 descriptor_write.pDescriptors = &descriptor_info;
1585
1586 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1587
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001588 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001589 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ index out of bounds.";
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001590 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
1591 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 -06001592 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001593}
1594
1595TEST_F(VkLayerTest, InvalidDSUpdateIndex)
1596{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001597 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001598 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001599 std::string msgString;
1600 VkResult err;
1601
1602 ASSERT_NO_FATAL_FAILURE(InitState());
1603 m_errorMonitor->ClearState();
1604 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001605 VkDescriptorTypeCount ds_type_count = {};
1606 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1607 ds_type_count.count = 1;
1608
1609 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1610 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1611 ds_pool_ci.pNext = NULL;
1612 ds_pool_ci.count = 1;
1613 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001614 VkDescriptorPool ds_pool;
1615 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1616 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001617
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001618 VkDescriptorSetLayoutBinding dsl_binding = {};
1619 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1620 dsl_binding.arraySize = 1;
1621 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1622 dsl_binding.pImmutableSamplers = NULL;
1623
1624 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1625 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1626 ds_layout_ci.pNext = NULL;
1627 ds_layout_ci.count = 1;
1628 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001629 VkDescriptorSetLayout ds_layout;
1630 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1631 ASSERT_VK_SUCCESS(err);
1632
1633 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001634 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001635 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001636
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001637 VkSamplerCreateInfo sampler_ci = {};
1638 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1639 sampler_ci.pNext = NULL;
1640 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1641 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1642 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1643 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1644 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1645 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1646 sampler_ci.mipLodBias = 1.0;
1647 sampler_ci.maxAnisotropy = 1;
1648 sampler_ci.compareEnable = VK_FALSE;
1649 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1650 sampler_ci.minLod = 1.0;
1651 sampler_ci.maxLod = 1.0;
1652 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northrop0bf4e1d2015-08-11 15:50:55 -06001653 sampler_ci.texelCoords = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001654
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001655 VkSampler sampler;
1656 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1657 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001658
1659 VkDescriptorInfo descriptor_info;
1660 memset(&descriptor_info, 0, sizeof(descriptor_info));
1661 descriptor_info.sampler = sampler;
1662
1663 VkWriteDescriptorSet descriptor_write;
1664 memset(&descriptor_write, 0, sizeof(descriptor_write));
1665 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1666 descriptor_write.destSet = descriptorSet;
1667 descriptor_write.destBinding = 2;
1668 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001669 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001670 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1671 descriptor_write.pDescriptors = &descriptor_info;
1672
1673 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1674
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001675 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001676 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ count too large for layout.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001677 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
1678 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
1679 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001680}
1681
1682TEST_F(VkLayerTest, InvalidDSUpdateStruct)
1683{
1684 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001685 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001686 std::string msgString;
1687 VkResult err;
1688
1689 ASSERT_NO_FATAL_FAILURE(InitState());
1690 m_errorMonitor->ClearState();
1691 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001692
1693 VkDescriptorTypeCount ds_type_count = {};
1694 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1695 ds_type_count.count = 1;
1696
1697 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1698 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1699 ds_pool_ci.pNext = NULL;
1700 ds_pool_ci.count = 1;
1701 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001702 VkDescriptorPool ds_pool;
1703 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1704 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001705 VkDescriptorSetLayoutBinding dsl_binding = {};
1706 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1707 dsl_binding.arraySize = 1;
1708 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1709 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001710
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001711 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1712 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1713 ds_layout_ci.pNext = NULL;
1714 ds_layout_ci.count = 1;
1715 ds_layout_ci.pBinding = &dsl_binding;
1716
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001717 VkDescriptorSetLayout ds_layout;
1718 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1719 ASSERT_VK_SUCCESS(err);
1720
1721 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001722 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001723 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001724
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001725 VkSamplerCreateInfo sampler_ci = {};
1726 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1727 sampler_ci.pNext = NULL;
1728 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1729 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1730 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1731 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1732 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1733 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1734 sampler_ci.mipLodBias = 1.0;
1735 sampler_ci.maxAnisotropy = 1;
1736 sampler_ci.compareEnable = VK_FALSE;
1737 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1738 sampler_ci.minLod = 1.0;
1739 sampler_ci.maxLod = 1.0;
1740 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northrop0bf4e1d2015-08-11 15:50:55 -06001741 sampler_ci.texelCoords = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001742 VkSampler sampler;
1743 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1744 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001745
1746
1747 VkDescriptorInfo descriptor_info;
1748 memset(&descriptor_info, 0, sizeof(descriptor_info));
1749 descriptor_info.sampler = sampler;
1750
1751 VkWriteDescriptorSet descriptor_write;
1752 memset(&descriptor_write, 0, sizeof(descriptor_write));
1753 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
1754 descriptor_write.destSet = descriptorSet;
1755 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001756 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001757 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1758 descriptor_write.pDescriptors = &descriptor_info;
1759
1760 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1761
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001762 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001763 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ invalid struct type.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001764 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
1765 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
1766 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001767}
1768
1769TEST_F(VkLayerTest, NumSamplesMismatch)
1770{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001771 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001772 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001773 std::string msgString;
1774 VkResult err;
1775
1776 ASSERT_NO_FATAL_FAILURE(InitState());
1777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1778 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001779 VkDescriptorTypeCount ds_type_count = {};
1780 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1781 ds_type_count.count = 1;
1782
1783 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1784 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1785 ds_pool_ci.pNext = NULL;
1786 ds_pool_ci.count = 1;
1787 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001788 VkDescriptorPool ds_pool;
1789 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1790 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001791
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001792 VkDescriptorSetLayoutBinding dsl_binding = {};
1793 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1794 dsl_binding.arraySize = 1;
1795 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1796 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001797
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001798 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1799 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1800 ds_layout_ci.pNext = NULL;
1801 ds_layout_ci.count = 1;
1802 ds_layout_ci.pBinding = &dsl_binding;
1803
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001804 VkDescriptorSetLayout ds_layout;
1805 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1806 ASSERT_VK_SUCCESS(err);
1807
1808 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001809 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001810 ASSERT_VK_SUCCESS(err);
1811
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001812 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1813 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1814 pipe_ms_state_ci.pNext = NULL;
1815 pipe_ms_state_ci.rasterSamples = 4;
1816 pipe_ms_state_ci.sampleShadingEnable = 0;
1817 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06001818 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001819
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001820 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1821 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1822 pipeline_layout_ci.pNext = NULL;
1823 pipeline_layout_ci.descriptorSetCount = 1;
1824 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001825
1826 VkPipelineLayout pipeline_layout;
1827 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1828 ASSERT_VK_SUCCESS(err);
1829
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001830 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001831 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1832 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06001833 VkPipelineObj pipe(m_device);
1834 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001835 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06001836 pipe.SetMSAA(&pipe_ms_state_ci);
1837 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001838
Tony Barbour1490c912015-07-28 10:17:20 -06001839 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06001840 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001841
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001842 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001843 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding RenderPass w/ mismatched MSAA from PSO.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001844 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
1845 FAIL() << "Error received was not 'Num samples mismatch!...'";
1846 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001847}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001848
Tobin Ehlise4076782015-06-24 15:53:07 -06001849TEST_F(VkLayerTest, PipelineNotBound)
1850{
1851 VkFlags msgFlags;
1852 std::string msgString;
1853 VkResult err;
1854
1855 ASSERT_NO_FATAL_FAILURE(InitState());
1856 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1857 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001858
1859 VkDescriptorTypeCount ds_type_count = {};
1860 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1861 ds_type_count.count = 1;
1862
1863 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1864 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1865 ds_pool_ci.pNext = NULL;
1866 ds_pool_ci.count = 1;
1867 ds_pool_ci.pTypeCount = &ds_type_count;
1868
Tobin Ehlise4076782015-06-24 15:53:07 -06001869 VkDescriptorPool ds_pool;
1870 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1871 ASSERT_VK_SUCCESS(err);
1872
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001873 VkDescriptorSetLayoutBinding dsl_binding = {};
1874 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1875 dsl_binding.arraySize = 1;
1876 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1877 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06001878
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001879 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1880 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1881 ds_layout_ci.pNext = NULL;
1882 ds_layout_ci.count = 1;
1883 ds_layout_ci.pBinding = &dsl_binding;
1884
Tobin Ehlise4076782015-06-24 15:53:07 -06001885 VkDescriptorSetLayout ds_layout;
1886 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1887 ASSERT_VK_SUCCESS(err);
1888
1889 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001890 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06001891 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001892
1893 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1894 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1895 pipeline_layout_ci.pNext = NULL;
1896 pipeline_layout_ci.descriptorSetCount = 1;
1897 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06001898
1899 VkPipelineLayout pipeline_layout;
1900 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1901 ASSERT_VK_SUCCESS(err);
1902
Tobin Ehlise4076782015-06-24 15:53:07 -06001903 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Tony Barbour1490c912015-07-28 10:17:20 -06001904
1905 BeginCommandBuffer();
1906 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06001907
1908 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001909 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Tobin Ehlise4076782015-06-24 15:53:07 -06001910 if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1911 FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1912 }
1913}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001914
1915TEST_F(VkLayerTest, ClearCmdNoDraw)
1916{
1917 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
1918 VkFlags msgFlags;
1919 std::string msgString;
1920 VkResult err;
1921
1922 ASSERT_NO_FATAL_FAILURE(InitState());
1923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1924 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001925
1926 VkDescriptorTypeCount ds_type_count = {};
1927 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1928 ds_type_count.count = 1;
1929
1930 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1931 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1932 ds_pool_ci.pNext = NULL;
1933 ds_pool_ci.count = 1;
1934 ds_pool_ci.pTypeCount = &ds_type_count;
1935
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001936 VkDescriptorPool ds_pool;
1937 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1938 ASSERT_VK_SUCCESS(err);
1939
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001940 VkDescriptorSetLayoutBinding dsl_binding = {};
1941 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1942 dsl_binding.arraySize = 1;
1943 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1944 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001945
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001946 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1947 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1948 ds_layout_ci.pNext = NULL;
1949 ds_layout_ci.count = 1;
1950 ds_layout_ci.pBinding = &dsl_binding;
1951
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001952 VkDescriptorSetLayout ds_layout;
1953 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1954 ASSERT_VK_SUCCESS(err);
1955
1956 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001957 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001958 ASSERT_VK_SUCCESS(err);
1959
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001960 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1961 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1962 pipe_ms_state_ci.pNext = NULL;
1963 pipe_ms_state_ci.rasterSamples = 4;
1964 pipe_ms_state_ci.sampleShadingEnable = 0;
1965 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06001966 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001967
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001968 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1969 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1970 pipeline_layout_ci.pNext = NULL;
1971 pipeline_layout_ci.descriptorSetCount = 1;
1972 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001973
1974 VkPipelineLayout pipeline_layout;
1975 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1976 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001977
Tony Barbourd7d828b2015-08-06 10:16:07 -06001978 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001979 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1980 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06001981 VkPipelineObj pipe(m_device);
1982 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001983 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06001984 pipe.SetMSAA(&pipe_ms_state_ci);
1985 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001986
1987 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001988
1989 m_errorMonitor->ClearState();
1990 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
1991 // Also pass down other dummy params to keep driver and paramchecker happy
1992 VkClearColorValue cCV;
1993 cCV.f32[0] = 1.0;
1994 cCV.f32[1] = 1.0;
1995 cCV.f32[2] = 1.0;
1996 cCV.f32[3] = 1.0;
1997
Tony Barbour1490c912015-07-28 10:17:20 -06001998 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001999 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002000 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not receive error after issuing Clear Cmd on FB color attachment prior to Draw Cmd.";
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002001 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) {
2002 FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'";
2003 }
2004}
2005
Tobin Ehlise4076782015-06-24 15:53:07 -06002006TEST_F(VkLayerTest, VtxBufferBadIndex)
2007{
2008 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
2009 VkFlags msgFlags;
2010 std::string msgString;
2011 VkResult err;
2012
2013 ASSERT_NO_FATAL_FAILURE(InitState());
2014 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2015 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002016
2017 VkDescriptorTypeCount ds_type_count = {};
2018 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2019 ds_type_count.count = 1;
2020
2021 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2022 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2023 ds_pool_ci.pNext = NULL;
2024 ds_pool_ci.count = 1;
2025 ds_pool_ci.pTypeCount = &ds_type_count;
2026
2027 VkDescriptorPool ds_pool;
Tobin Ehlise4076782015-06-24 15:53:07 -06002028 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
2029 ASSERT_VK_SUCCESS(err);
2030
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002031 VkDescriptorSetLayoutBinding dsl_binding = {};
2032 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2033 dsl_binding.arraySize = 1;
2034 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2035 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002036
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002037 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2038 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2039 ds_layout_ci.pNext = NULL;
2040 ds_layout_ci.count = 1;
2041 ds_layout_ci.pBinding = &dsl_binding;
2042
Tobin Ehlise4076782015-06-24 15:53:07 -06002043 VkDescriptorSetLayout ds_layout;
2044 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2045 ASSERT_VK_SUCCESS(err);
2046
2047 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002048 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06002049 ASSERT_VK_SUCCESS(err);
2050
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002051 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2052 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2053 pipe_ms_state_ci.pNext = NULL;
2054 pipe_ms_state_ci.rasterSamples = 1;
2055 pipe_ms_state_ci.sampleShadingEnable = 0;
2056 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002057 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002058
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002059 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2060 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2061 pipeline_layout_ci.pNext = NULL;
2062 pipeline_layout_ci.descriptorSetCount = 1;
2063 pipeline_layout_ci.pSetLayouts = &ds_layout;
2064 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06002065
Tobin Ehlise4076782015-06-24 15:53:07 -06002066 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2067 ASSERT_VK_SUCCESS(err);
2068
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002069 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002070 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2071 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002072 VkPipelineObj pipe(m_device);
2073 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002074 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002075 pipe.SetMSAA(&pipe_ms_state_ci);
2076 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002077
2078 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06002079 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlise4076782015-06-24 15:53:07 -06002080 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06002081 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlise4076782015-06-24 15:53:07 -06002082
2083 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002084 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding Vtx Buffer w/o VBO attached to PSO.";
Tobin Ehlise4076782015-06-24 15:53:07 -06002085 if (!strstr(msgString.c_str(),"Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.")) {
2086 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
2087 }
2088}
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002089#endif
2090#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06002091#if GTEST_IS_THREADSAFE
2092struct thread_data_struct {
2093 VkCmdBuffer cmdBuffer;
2094 VkEvent event;
2095 bool bailout;
2096};
2097
2098extern "C" void *AddToCommandBuffer(void *arg)
2099{
2100 struct thread_data_struct *data = (struct thread_data_struct *) arg;
2101 std::string msgString;
2102
2103 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06002104 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06002105 if (data->bailout) {
2106 break;
2107 }
2108 }
2109 return NULL;
2110}
2111
2112TEST_F(VkLayerTest, ThreadCmdBufferCollision)
2113{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002114 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06002115 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002116 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06002117
2118 ASSERT_NO_FATAL_FAILURE(InitState());
2119 ASSERT_NO_FATAL_FAILURE(InitViewport());
2120 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2121
Mike Stroyan09aae812015-05-12 16:00:45 -06002122 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06002123 BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002124
2125 VkEventCreateInfo event_info;
2126 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06002127 VkResult err;
2128
2129 memset(&event_info, 0, sizeof(event_info));
2130 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2131
2132 err = vkCreateEvent(device(), &event_info, &event);
2133 ASSERT_VK_SUCCESS(err);
2134
Mike Stroyan09aae812015-05-12 16:00:45 -06002135 err = vkResetEvent(device(), event);
2136 ASSERT_VK_SUCCESS(err);
2137
2138 struct thread_data_struct data;
Tony Barbour1490c912015-07-28 10:17:20 -06002139 data.cmdBuffer = m_cmdBuffer->handle();
Mike Stroyan09aae812015-05-12 16:00:45 -06002140 data.event = event;
2141 data.bailout = false;
2142 m_errorMonitor->SetBailout(&data.bailout);
2143 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002144 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06002145 // Add many entries to command buffer from this thread at the same time.
2146 AddToCommandBuffer(&data);
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002147 test_platform_thread_join(thread, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -06002148 EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002149
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002150 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002151 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err from using one VkCommandBufferObj in two threads";
Mike Stroyan09aae812015-05-12 16:00:45 -06002152 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05002153 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06002154 }
2155
2156}
2157#endif
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002158#endif
Chris Forbes5af3bf22015-05-25 11:13:08 +12002159#if SHADER_CHECKER_TESTS
2160TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
2161{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002162 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12002163 std::string msgString;
2164 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002165 ScopedUseGlsl useGlsl(false);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002166
2167 char const *vsSource =
2168 "#version 140\n"
2169 "#extension GL_ARB_separate_shader_objects: require\n"
2170 "#extension GL_ARB_shading_language_420pack: require\n"
2171 "\n"
2172 "layout(location=0) out float x;\n"
2173 "void main(){\n"
2174 " gl_Position = vec4(1);\n"
2175 " x = 0;\n"
2176 "}\n";
2177 char const *fsSource =
2178 "#version 140\n"
2179 "#extension GL_ARB_separate_shader_objects: require\n"
2180 "#extension GL_ARB_shading_language_420pack: require\n"
2181 "\n"
2182 "layout(location=0) out vec4 color;\n"
2183 "void main(){\n"
2184 " color = vec4(1);\n"
2185 "}\n";
2186
2187 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2188 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2189
2190 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002191 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12002192 pipe.AddShader(&vs);
2193 pipe.AddShader(&fs);
2194
Chris Forbes5af3bf22015-05-25 11:13:08 +12002195 VkDescriptorSetObj descriptorSet(m_device);
2196 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002197 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002198
2199 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002200 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12002201
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002202 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002203
Cody Northrop1684adb2015-08-05 11:15:02 -06002204 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002205 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
2206 FAIL() << "Incorrect warning: " << msgString;
2207 }
2208}
Chris Forbes5af3bf22015-05-25 11:13:08 +12002209
Chris Forbes3c10b852015-05-25 11:13:13 +12002210TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
2211{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002212 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12002213 std::string msgString;
2214 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002215 ScopedUseGlsl useGlsl(false);
Chris Forbes3c10b852015-05-25 11:13:13 +12002216
2217 char const *vsSource =
2218 "#version 140\n"
2219 "#extension GL_ARB_separate_shader_objects: require\n"
2220 "#extension GL_ARB_shading_language_420pack: require\n"
2221 "\n"
2222 "void main(){\n"
2223 " gl_Position = vec4(1);\n"
2224 "}\n";
2225 char const *fsSource =
2226 "#version 140\n"
2227 "#extension GL_ARB_separate_shader_objects: require\n"
2228 "#extension GL_ARB_shading_language_420pack: require\n"
2229 "\n"
2230 "layout(location=0) in float x;\n"
2231 "layout(location=0) out vec4 color;\n"
2232 "void main(){\n"
2233 " color = vec4(x);\n"
2234 "}\n";
2235
2236 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2237 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2238
2239 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002240 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12002241 pipe.AddShader(&vs);
2242 pipe.AddShader(&fs);
2243
Chris Forbes3c10b852015-05-25 11:13:13 +12002244 VkDescriptorSetObj descriptorSet(m_device);
2245 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002246 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12002247
2248 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002249 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12002250
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002251 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12002252
Cody Northrop1684adb2015-08-05 11:15:02 -06002253 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes3c10b852015-05-25 11:13:13 +12002254 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
2255 FAIL() << "Incorrect error: " << msgString;
2256 }
2257}
2258
Chris Forbescc281692015-05-25 11:13:17 +12002259TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
2260{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002261 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12002262 std::string msgString;
2263 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002264 ScopedUseGlsl useGlsl(false);
Chris Forbescc281692015-05-25 11:13:17 +12002265
2266 char const *vsSource =
2267 "#version 140\n"
2268 "#extension GL_ARB_separate_shader_objects: require\n"
2269 "#extension GL_ARB_shading_language_420pack: require\n"
2270 "\n"
2271 "layout(location=0) out int x;\n"
2272 "void main(){\n"
2273 " x = 0;\n"
2274 " gl_Position = vec4(1);\n"
2275 "}\n";
2276 char const *fsSource =
2277 "#version 140\n"
2278 "#extension GL_ARB_separate_shader_objects: require\n"
2279 "#extension GL_ARB_shading_language_420pack: require\n"
2280 "\n"
2281 "layout(location=0) in float x;\n" /* VS writes int */
2282 "layout(location=0) out vec4 color;\n"
2283 "void main(){\n"
2284 " color = vec4(x);\n"
2285 "}\n";
2286
2287 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2288 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2289
2290 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002291 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12002292 pipe.AddShader(&vs);
2293 pipe.AddShader(&fs);
2294
Chris Forbescc281692015-05-25 11:13:17 +12002295 VkDescriptorSetObj descriptorSet(m_device);
2296 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002297 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12002298
2299 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002300 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12002301
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002302 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12002303
Cody Northrop1684adb2015-08-05 11:15:02 -06002304 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbescc281692015-05-25 11:13:17 +12002305 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
2306 FAIL() << "Incorrect error: " << msgString;
2307 }
2308}
2309
Chris Forbes8291c052015-05-25 11:13:28 +12002310TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
2311{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002312 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12002313 std::string msgString;
2314 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002315 ScopedUseGlsl useGlsl(false);
Chris Forbes8291c052015-05-25 11:13:28 +12002316
2317 VkVertexInputBindingDescription input_binding;
2318 memset(&input_binding, 0, sizeof(input_binding));
2319
2320 VkVertexInputAttributeDescription input_attrib;
2321 memset(&input_attrib, 0, sizeof(input_attrib));
2322 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2323
2324 char const *vsSource =
2325 "#version 140\n"
2326 "#extension GL_ARB_separate_shader_objects: require\n"
2327 "#extension GL_ARB_shading_language_420pack: require\n"
2328 "\n"
2329 "void main(){\n"
2330 " gl_Position = vec4(1);\n"
2331 "}\n";
2332 char const *fsSource =
2333 "#version 140\n"
2334 "#extension GL_ARB_separate_shader_objects: require\n"
2335 "#extension GL_ARB_shading_language_420pack: require\n"
2336 "\n"
2337 "layout(location=0) out vec4 color;\n"
2338 "void main(){\n"
2339 " color = vec4(1);\n"
2340 "}\n";
2341
2342 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2343 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2344
2345 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002346 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12002347 pipe.AddShader(&vs);
2348 pipe.AddShader(&fs);
2349
2350 pipe.AddVertexInputBindings(&input_binding, 1);
2351 pipe.AddVertexInputAttribs(&input_attrib, 1);
2352
Chris Forbes8291c052015-05-25 11:13:28 +12002353 VkDescriptorSetObj descriptorSet(m_device);
2354 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002355 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12002356
2357 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002358 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12002359
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002360 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12002361
Cody Northrop1684adb2015-08-05 11:15:02 -06002362 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12002363 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
2364 FAIL() << "Incorrect warning: " << msgString;
2365 }
2366}
2367
Chris Forbes37367e62015-05-25 11:13:29 +12002368TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
2369{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002370 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12002371 std::string msgString;
2372 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002373 ScopedUseGlsl useGlsl(false);
Chris Forbes37367e62015-05-25 11:13:29 +12002374
2375 char const *vsSource =
2376 "#version 140\n"
2377 "#extension GL_ARB_separate_shader_objects: require\n"
2378 "#extension GL_ARB_shading_language_420pack: require\n"
2379 "\n"
2380 "layout(location=0) in vec4 x;\n" /* not provided */
2381 "void main(){\n"
2382 " gl_Position = x;\n"
2383 "}\n";
2384 char const *fsSource =
2385 "#version 140\n"
2386 "#extension GL_ARB_separate_shader_objects: require\n"
2387 "#extension GL_ARB_shading_language_420pack: require\n"
2388 "\n"
2389 "layout(location=0) out vec4 color;\n"
2390 "void main(){\n"
2391 " color = vec4(1);\n"
2392 "}\n";
2393
2394 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2395 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2396
2397 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002398 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12002399 pipe.AddShader(&vs);
2400 pipe.AddShader(&fs);
2401
Chris Forbes37367e62015-05-25 11:13:29 +12002402 VkDescriptorSetObj descriptorSet(m_device);
2403 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002404 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12002405
2406 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002407 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12002408
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002409 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12002410
Cody Northrop1684adb2015-08-05 11:15:02 -06002411 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes37367e62015-05-25 11:13:29 +12002412 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
2413 FAIL() << "Incorrect warning: " << msgString;
2414 }
2415}
2416
Chris Forbesa4b02322015-05-25 11:13:31 +12002417TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
2418{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002419 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12002420 std::string msgString;
2421 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002422 ScopedUseGlsl useGlsl(false);
Chris Forbesa4b02322015-05-25 11:13:31 +12002423
2424 VkVertexInputBindingDescription input_binding;
2425 memset(&input_binding, 0, sizeof(input_binding));
2426
2427 VkVertexInputAttributeDescription input_attrib;
2428 memset(&input_attrib, 0, sizeof(input_attrib));
2429 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2430
2431 char const *vsSource =
2432 "#version 140\n"
2433 "#extension GL_ARB_separate_shader_objects: require\n"
2434 "#extension GL_ARB_shading_language_420pack: require\n"
2435 "\n"
2436 "layout(location=0) in int x;\n" /* attrib provided float */
2437 "void main(){\n"
2438 " gl_Position = vec4(x);\n"
2439 "}\n";
2440 char const *fsSource =
2441 "#version 140\n"
2442 "#extension GL_ARB_separate_shader_objects: require\n"
2443 "#extension GL_ARB_shading_language_420pack: require\n"
2444 "\n"
2445 "layout(location=0) out vec4 color;\n"
2446 "void main(){\n"
2447 " color = vec4(1);\n"
2448 "}\n";
2449
2450 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2451 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2452
2453 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002454 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12002455 pipe.AddShader(&vs);
2456 pipe.AddShader(&fs);
2457
2458 pipe.AddVertexInputBindings(&input_binding, 1);
2459 pipe.AddVertexInputAttribs(&input_attrib, 1);
2460
Chris Forbesa4b02322015-05-25 11:13:31 +12002461 VkDescriptorSetObj descriptorSet(m_device);
2462 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002463 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12002464
2465 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002466 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12002467
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002468 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12002469
Cody Northrop1684adb2015-08-05 11:15:02 -06002470 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa4b02322015-05-25 11:13:31 +12002471 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
2472 FAIL() << "Incorrect error: " << msgString;
2473 }
2474}
2475
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002476TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
2477{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002478 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002479 std::string msgString;
2480 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002481 ScopedUseGlsl useGlsl(false);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002482
2483 /* Two binding descriptions for binding 0 */
2484 VkVertexInputBindingDescription input_bindings[2];
2485 memset(input_bindings, 0, sizeof(input_bindings));
2486
2487 VkVertexInputAttributeDescription input_attrib;
2488 memset(&input_attrib, 0, sizeof(input_attrib));
2489 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2490
2491 char const *vsSource =
2492 "#version 140\n"
2493 "#extension GL_ARB_separate_shader_objects: require\n"
2494 "#extension GL_ARB_shading_language_420pack: require\n"
2495 "\n"
2496 "layout(location=0) in float x;\n" /* attrib provided float */
2497 "void main(){\n"
2498 " gl_Position = vec4(x);\n"
2499 "}\n";
2500 char const *fsSource =
2501 "#version 140\n"
2502 "#extension GL_ARB_separate_shader_objects: require\n"
2503 "#extension GL_ARB_shading_language_420pack: require\n"
2504 "\n"
2505 "layout(location=0) out vec4 color;\n"
2506 "void main(){\n"
2507 " color = vec4(1);\n"
2508 "}\n";
2509
2510 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2511 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2512
2513 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002514 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002515 pipe.AddShader(&vs);
2516 pipe.AddShader(&fs);
2517
2518 pipe.AddVertexInputBindings(input_bindings, 2);
2519 pipe.AddVertexInputAttribs(&input_attrib, 1);
2520
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002521 VkDescriptorSetObj descriptorSet(m_device);
2522 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002523 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002524
2525 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002526 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002527
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002528 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002529
Cody Northrop1684adb2015-08-05 11:15:02 -06002530 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002531 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
2532 FAIL() << "Incorrect error: " << msgString;
2533 }
2534}
Chris Forbes4c948702015-05-25 11:13:32 +12002535
Chris Forbesc12ef122015-05-25 11:13:40 +12002536/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
2537 * rejects it. */
2538
2539TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
2540{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002541 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12002542 std::string msgString;
2543 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002544 ScopedUseGlsl useGlsl(false);
Chris Forbesc12ef122015-05-25 11:13:40 +12002545
2546 char const *vsSource =
2547 "#version 140\n"
2548 "#extension GL_ARB_separate_shader_objects: require\n"
2549 "#extension GL_ARB_shading_language_420pack: require\n"
2550 "\n"
2551 "void main(){\n"
2552 " gl_Position = vec4(1);\n"
2553 "}\n";
2554 char const *fsSource =
2555 "#version 140\n"
2556 "#extension GL_ARB_separate_shader_objects: require\n"
2557 "#extension GL_ARB_shading_language_420pack: require\n"
2558 "\n"
2559 "void main(){\n"
2560 "}\n";
2561
2562 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2563 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2564
2565 VkPipelineObj pipe(m_device);
2566 pipe.AddShader(&vs);
2567 pipe.AddShader(&fs);
2568
Chia-I Wuc278df82015-07-07 11:50:03 +08002569 /* set up CB 0, not written */
2570 pipe.AddColorAttachment();
2571 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12002572
Chris Forbesc12ef122015-05-25 11:13:40 +12002573 VkDescriptorSetObj descriptorSet(m_device);
2574 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002575 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12002576
2577 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002578 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12002579
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002580 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12002581
Cody Northrop1684adb2015-08-05 11:15:02 -06002582 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc12ef122015-05-25 11:13:40 +12002583 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
2584 FAIL() << "Incorrect error: " << msgString;
2585 }
2586}
2587
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002588TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
2589{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002590 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002591 std::string msgString;
2592 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002593 ScopedUseGlsl useGlsl(false);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002594
2595 char const *vsSource =
2596 "#version 140\n"
2597 "#extension GL_ARB_separate_shader_objects: require\n"
2598 "#extension GL_ARB_shading_language_420pack: require\n"
2599 "\n"
2600 "void main(){\n"
2601 " gl_Position = vec4(1);\n"
2602 "}\n";
2603 char const *fsSource =
2604 "#version 140\n"
2605 "#extension GL_ARB_separate_shader_objects: require\n"
2606 "#extension GL_ARB_shading_language_420pack: require\n"
2607 "\n"
2608 "layout(location=0) out vec4 x;\n"
2609 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
2610 "void main(){\n"
2611 " x = vec4(1);\n"
2612 " y = vec4(1);\n"
2613 "}\n";
2614
2615 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2616 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2617
2618 VkPipelineObj pipe(m_device);
2619 pipe.AddShader(&vs);
2620 pipe.AddShader(&fs);
2621
Chia-I Wuc278df82015-07-07 11:50:03 +08002622 /* set up CB 0, not written */
2623 pipe.AddColorAttachment();
2624 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002625 /* FS writes CB 1, but we don't configure it */
2626
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002627 VkDescriptorSetObj descriptorSet(m_device);
2628 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002629 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002630
2631 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002632 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002633
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002634 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002635
Cody Northrop1684adb2015-08-05 11:15:02 -06002636 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002637 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
2638 FAIL() << "Incorrect warning: " << msgString;
2639 }
2640}
2641
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002642TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
2643{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002644 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002645 std::string msgString;
2646 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002647 ScopedUseGlsl useGlsl(false);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002648
2649 char const *vsSource =
2650 "#version 140\n"
2651 "#extension GL_ARB_separate_shader_objects: require\n"
2652 "#extension GL_ARB_shading_language_420pack: require\n"
2653 "\n"
2654 "void main(){\n"
2655 " gl_Position = vec4(1);\n"
2656 "}\n";
2657 char const *fsSource =
2658 "#version 140\n"
2659 "#extension GL_ARB_separate_shader_objects: require\n"
2660 "#extension GL_ARB_shading_language_420pack: require\n"
2661 "\n"
2662 "layout(location=0) out ivec4 x;\n" /* not UNORM */
2663 "void main(){\n"
2664 " x = ivec4(1);\n"
2665 "}\n";
2666
2667 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2668 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2669
2670 VkPipelineObj pipe(m_device);
2671 pipe.AddShader(&vs);
2672 pipe.AddShader(&fs);
2673
Chia-I Wuc278df82015-07-07 11:50:03 +08002674 /* set up CB 0; type is UNORM by default */
2675 pipe.AddColorAttachment();
2676 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002677
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002678 VkDescriptorSetObj descriptorSet(m_device);
2679 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002680 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002681
2682 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002683 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002684
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002685 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002686
Cody Northrop1684adb2015-08-05 11:15:02 -06002687 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002688 if (!strstr(msgString.c_str(),"does not match FS output type")) {
2689 FAIL() << "Incorrect error: " << msgString;
2690 }
2691}
Chris Forbesc2050732015-06-05 14:43:36 +12002692
2693TEST_F(VkLayerTest, CreatePipelineNonSpirvShader)
2694{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002695 VkFlags msgFlags;
Chris Forbesc2050732015-06-05 14:43:36 +12002696 std::string msgString;
2697 ASSERT_NO_FATAL_FAILURE(InitState());
2698 /* Intentionally provided GLSL rather than compiling to SPIRV first */
Cody Northrop1cfbd172015-06-03 16:49:20 -06002699 ScopedUseGlsl useGlsl(true);
Chris Forbesc2050732015-06-05 14:43:36 +12002700
2701 char const *vsSource =
2702 "#version 140\n"
2703 "#extension GL_ARB_separate_shader_objects: require\n"
2704 "#extension GL_ARB_shading_language_420pack: require\n"
2705 "\n"
2706 "void main(){\n"
2707 " gl_Position = vec4(1);\n"
2708 "}\n";
2709 char const *fsSource =
2710 "#version 140\n"
2711 "#extension GL_ARB_separate_shader_objects: require\n"
2712 "#extension GL_ARB_shading_language_420pack: require\n"
2713 "\n"
2714 "layout(location=0) out vec4 x;\n"
2715 "void main(){\n"
2716 " x = vec4(1);\n"
2717 "}\n";
2718
2719 m_errorMonitor->ClearState();
2720
2721 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2722 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2723
2724
2725 VkPipelineObj pipe(m_device);
2726 pipe.AddShader(&vs);
2727 pipe.AddShader(&fs);
2728
Chia-I Wuc278df82015-07-07 11:50:03 +08002729 /* set up CB 0; type is UNORM by default */
2730 pipe.AddColorAttachment();
2731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc2050732015-06-05 14:43:36 +12002732
Chris Forbesc2050732015-06-05 14:43:36 +12002733 VkDescriptorSetObj descriptorSet(m_device);
2734 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002735 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc2050732015-06-05 14:43:36 +12002736
Tony Barboured132432015-08-04 16:23:11 -06002737 VkResult res = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc2050732015-06-05 14:43:36 +12002738 /* pipeline creation should have succeeded */
2739 ASSERT_EQ(VK_SUCCESS, res);
2740
2741 /* should have emitted a warning: the shader is not SPIRV, so we're
2742 * not going to be able to analyze it */
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002743 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002744 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesc2050732015-06-05 14:43:36 +12002745 if (!strstr(msgString.c_str(),"is not SPIR-V")) {
2746 FAIL() << "Incorrect warning: " << msgString;
2747 }
2748}
Chris Forbes01c9db72015-06-04 09:25:25 +12002749#endif
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002750
Tony Barbour30486ea2015-04-07 13:44:53 -06002751int main(int argc, char **argv) {
2752 int result;
2753
2754 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06002755 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06002756
2757 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
2758
2759 result = RUN_ALL_TESTS();
2760
Tony Barbour01999182015-04-09 12:58:51 -06002761 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06002762 return result;
2763}