blob: 104a75b58e7e31e71e60dd61f65e51b7fadbbc88 [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;
1478
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001479 VkSampler sampler;
1480 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1481 ASSERT_VK_SUCCESS(err);
1482
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001483 VkDescriptorInfo descriptor_info;
1484 memset(&descriptor_info, 0, sizeof(descriptor_info));
1485 descriptor_info.sampler = sampler;
1486
1487 VkWriteDescriptorSet descriptor_write;
1488 memset(&descriptor_write, 0, sizeof(descriptor_write));
1489 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1490 descriptor_write.destSet = descriptorSet;
1491 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001492 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001493 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1494 descriptor_write.pDescriptors = &descriptor_info;
1495
1496 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1497
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001498 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001499 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating BUFFER Descriptor w/ incorrect type of SAMPLER.";
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001500 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) {
1501 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 -06001502 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001503}
1504
1505TEST_F(VkLayerTest, DSUpdateOutOfBounds)
1506{
1507 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001508 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001509 std::string msgString;
1510 VkResult err;
1511
1512 ASSERT_NO_FATAL_FAILURE(InitState());
1513 m_errorMonitor->ClearState();
1514 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001515 VkDescriptorTypeCount ds_type_count = {};
1516 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1517 ds_type_count.count = 1;
1518
1519 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1520 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1521 ds_pool_ci.pNext = NULL;
1522 ds_pool_ci.count = 1;
1523 ds_pool_ci.pTypeCount = &ds_type_count;
1524
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001525 VkDescriptorPool ds_pool;
1526 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1527 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001528
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001529 VkDescriptorSetLayoutBinding dsl_binding = {};
1530 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1531 dsl_binding.arraySize = 1;
1532 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1533 dsl_binding.pImmutableSamplers = NULL;
1534
1535 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1536 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1537 ds_layout_ci.pNext = NULL;
1538 ds_layout_ci.count = 1;
1539 ds_layout_ci.pBinding = &dsl_binding;
1540
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001541 VkDescriptorSetLayout ds_layout;
1542 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1543 ASSERT_VK_SUCCESS(err);
1544
1545 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001546 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001547 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001548
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001549 VkSamplerCreateInfo sampler_ci = {};
1550 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1551 sampler_ci.pNext = NULL;
1552 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1553 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1554 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1555 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1556 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1557 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1558 sampler_ci.mipLodBias = 1.0;
1559 sampler_ci.maxAnisotropy = 1;
1560 sampler_ci.compareEnable = VK_FALSE;
1561 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1562 sampler_ci.minLod = 1.0;
1563 sampler_ci.maxLod = 1.0;
1564 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1565
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001566 VkSampler sampler;
1567 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1568 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001569
1570 VkDescriptorInfo descriptor_info;
1571 memset(&descriptor_info, 0, sizeof(descriptor_info));
1572 descriptor_info.sampler = sampler;
1573
1574 VkWriteDescriptorSet descriptor_write;
1575 memset(&descriptor_write, 0, sizeof(descriptor_write));
1576 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1577 descriptor_write.destSet = descriptorSet;
1578 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
1579 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001580 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001581 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1582 descriptor_write.pDescriptors = &descriptor_info;
1583
1584 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1585
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001586 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001587 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 +08001588 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
1589 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 -06001590 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001591}
1592
1593TEST_F(VkLayerTest, InvalidDSUpdateIndex)
1594{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001595 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001596 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001597 std::string msgString;
1598 VkResult err;
1599
1600 ASSERT_NO_FATAL_FAILURE(InitState());
1601 m_errorMonitor->ClearState();
1602 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001603 VkDescriptorTypeCount ds_type_count = {};
1604 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1605 ds_type_count.count = 1;
1606
1607 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1608 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1609 ds_pool_ci.pNext = NULL;
1610 ds_pool_ci.count = 1;
1611 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001612 VkDescriptorPool ds_pool;
1613 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1614 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001615
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001616 VkDescriptorSetLayoutBinding dsl_binding = {};
1617 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1618 dsl_binding.arraySize = 1;
1619 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1620 dsl_binding.pImmutableSamplers = NULL;
1621
1622 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1623 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1624 ds_layout_ci.pNext = NULL;
1625 ds_layout_ci.count = 1;
1626 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001627 VkDescriptorSetLayout ds_layout;
1628 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1629 ASSERT_VK_SUCCESS(err);
1630
1631 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001632 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001633 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001634
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001635 VkSamplerCreateInfo sampler_ci = {};
1636 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1637 sampler_ci.pNext = NULL;
1638 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1639 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1640 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1641 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1642 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1643 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1644 sampler_ci.mipLodBias = 1.0;
1645 sampler_ci.maxAnisotropy = 1;
1646 sampler_ci.compareEnable = VK_FALSE;
1647 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1648 sampler_ci.minLod = 1.0;
1649 sampler_ci.maxLod = 1.0;
1650 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1651
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001652 VkSampler sampler;
1653 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1654 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001655
1656 VkDescriptorInfo descriptor_info;
1657 memset(&descriptor_info, 0, sizeof(descriptor_info));
1658 descriptor_info.sampler = sampler;
1659
1660 VkWriteDescriptorSet descriptor_write;
1661 memset(&descriptor_write, 0, sizeof(descriptor_write));
1662 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1663 descriptor_write.destSet = descriptorSet;
1664 descriptor_write.destBinding = 2;
1665 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001666 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001667 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1668 descriptor_write.pDescriptors = &descriptor_info;
1669
1670 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1671
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001672 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001673 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 -06001674 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
1675 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
1676 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001677}
1678
1679TEST_F(VkLayerTest, InvalidDSUpdateStruct)
1680{
1681 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001682 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001683 std::string msgString;
1684 VkResult err;
1685
1686 ASSERT_NO_FATAL_FAILURE(InitState());
1687 m_errorMonitor->ClearState();
1688 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001689
1690 VkDescriptorTypeCount ds_type_count = {};
1691 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1692 ds_type_count.count = 1;
1693
1694 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1695 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1696 ds_pool_ci.pNext = NULL;
1697 ds_pool_ci.count = 1;
1698 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001699 VkDescriptorPool ds_pool;
1700 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1701 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001702 VkDescriptorSetLayoutBinding dsl_binding = {};
1703 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1704 dsl_binding.arraySize = 1;
1705 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1706 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001707
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001708 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1709 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1710 ds_layout_ci.pNext = NULL;
1711 ds_layout_ci.count = 1;
1712 ds_layout_ci.pBinding = &dsl_binding;
1713
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001714 VkDescriptorSetLayout ds_layout;
1715 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1716 ASSERT_VK_SUCCESS(err);
1717
1718 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001719 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001720 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001721
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001722 VkSamplerCreateInfo sampler_ci = {};
1723 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1724 sampler_ci.pNext = NULL;
1725 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
1726 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
1727 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
1728 sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP;
1729 sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP;
1730 sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP;
1731 sampler_ci.mipLodBias = 1.0;
1732 sampler_ci.maxAnisotropy = 1;
1733 sampler_ci.compareEnable = VK_FALSE;
1734 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
1735 sampler_ci.minLod = 1.0;
1736 sampler_ci.maxLod = 1.0;
1737 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001738 VkSampler sampler;
1739 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
1740 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001741
1742
1743 VkDescriptorInfo descriptor_info;
1744 memset(&descriptor_info, 0, sizeof(descriptor_info));
1745 descriptor_info.sampler = sampler;
1746
1747 VkWriteDescriptorSet descriptor_write;
1748 memset(&descriptor_write, 0, sizeof(descriptor_write));
1749 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
1750 descriptor_write.destSet = descriptorSet;
1751 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001752 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001753 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1754 descriptor_write.pDescriptors = &descriptor_info;
1755
1756 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1757
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001758 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001759 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ invalid struct type.";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001760 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
1761 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
1762 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001763}
1764
1765TEST_F(VkLayerTest, NumSamplesMismatch)
1766{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001767 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001768 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001769 std::string msgString;
1770 VkResult err;
1771
1772 ASSERT_NO_FATAL_FAILURE(InitState());
1773 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1774 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001775 VkDescriptorTypeCount ds_type_count = {};
1776 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1777 ds_type_count.count = 1;
1778
1779 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1780 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1781 ds_pool_ci.pNext = NULL;
1782 ds_pool_ci.count = 1;
1783 ds_pool_ci.pTypeCount = &ds_type_count;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001784 VkDescriptorPool ds_pool;
1785 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1786 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001787
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001788 VkDescriptorSetLayoutBinding dsl_binding = {};
1789 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1790 dsl_binding.arraySize = 1;
1791 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1792 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001793
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001794 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1795 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1796 ds_layout_ci.pNext = NULL;
1797 ds_layout_ci.count = 1;
1798 ds_layout_ci.pBinding = &dsl_binding;
1799
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001800 VkDescriptorSetLayout ds_layout;
1801 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1802 ASSERT_VK_SUCCESS(err);
1803
1804 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001805 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001806 ASSERT_VK_SUCCESS(err);
1807
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001808 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1809 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1810 pipe_ms_state_ci.pNext = NULL;
1811 pipe_ms_state_ci.rasterSamples = 4;
1812 pipe_ms_state_ci.sampleShadingEnable = 0;
1813 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06001814 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001815
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001816 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1817 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1818 pipeline_layout_ci.pNext = NULL;
1819 pipeline_layout_ci.descriptorSetCount = 1;
1820 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001821
1822 VkPipelineLayout pipeline_layout;
1823 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1824 ASSERT_VK_SUCCESS(err);
1825
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001826 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001827 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1828 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06001829 VkPipelineObj pipe(m_device);
1830 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001831 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06001832 pipe.SetMSAA(&pipe_ms_state_ci);
1833 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001834
Tony Barbour1490c912015-07-28 10:17:20 -06001835 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06001836 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06001837
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001838 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001839 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 -06001840 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
1841 FAIL() << "Error received was not 'Num samples mismatch!...'";
1842 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001843}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001844
Tobin Ehlise4076782015-06-24 15:53:07 -06001845TEST_F(VkLayerTest, PipelineNotBound)
1846{
1847 VkFlags msgFlags;
1848 std::string msgString;
1849 VkResult err;
1850
1851 ASSERT_NO_FATAL_FAILURE(InitState());
1852 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1853 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001854
1855 VkDescriptorTypeCount ds_type_count = {};
1856 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1857 ds_type_count.count = 1;
1858
1859 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1860 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1861 ds_pool_ci.pNext = NULL;
1862 ds_pool_ci.count = 1;
1863 ds_pool_ci.pTypeCount = &ds_type_count;
1864
Tobin Ehlise4076782015-06-24 15:53:07 -06001865 VkDescriptorPool ds_pool;
1866 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1867 ASSERT_VK_SUCCESS(err);
1868
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001869 VkDescriptorSetLayoutBinding dsl_binding = {};
1870 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1871 dsl_binding.arraySize = 1;
1872 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1873 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06001874
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001875 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1876 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1877 ds_layout_ci.pNext = NULL;
1878 ds_layout_ci.count = 1;
1879 ds_layout_ci.pBinding = &dsl_binding;
1880
Tobin Ehlise4076782015-06-24 15:53:07 -06001881 VkDescriptorSetLayout ds_layout;
1882 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1883 ASSERT_VK_SUCCESS(err);
1884
1885 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001886 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06001887 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001888
1889 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1890 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1891 pipeline_layout_ci.pNext = NULL;
1892 pipeline_layout_ci.descriptorSetCount = 1;
1893 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06001894
1895 VkPipelineLayout pipeline_layout;
1896 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1897 ASSERT_VK_SUCCESS(err);
1898
Tobin Ehlise4076782015-06-24 15:53:07 -06001899 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
Tony Barbour1490c912015-07-28 10:17:20 -06001900
1901 BeginCommandBuffer();
1902 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06001903
1904 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001905 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 -06001906 if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1907 FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1908 }
1909}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001910
1911TEST_F(VkLayerTest, ClearCmdNoDraw)
1912{
1913 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
1914 VkFlags msgFlags;
1915 std::string msgString;
1916 VkResult err;
1917
1918 ASSERT_NO_FATAL_FAILURE(InitState());
1919 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1920 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001921
1922 VkDescriptorTypeCount ds_type_count = {};
1923 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1924 ds_type_count.count = 1;
1925
1926 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1927 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1928 ds_pool_ci.pNext = NULL;
1929 ds_pool_ci.count = 1;
1930 ds_pool_ci.pTypeCount = &ds_type_count;
1931
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001932 VkDescriptorPool ds_pool;
1933 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1934 ASSERT_VK_SUCCESS(err);
1935
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001936 VkDescriptorSetLayoutBinding dsl_binding = {};
1937 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1938 dsl_binding.arraySize = 1;
1939 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1940 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001941
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001942 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1943 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1944 ds_layout_ci.pNext = NULL;
1945 ds_layout_ci.count = 1;
1946 ds_layout_ci.pBinding = &dsl_binding;
1947
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001948 VkDescriptorSetLayout ds_layout;
1949 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1950 ASSERT_VK_SUCCESS(err);
1951
1952 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001953 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001954 ASSERT_VK_SUCCESS(err);
1955
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001956 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1957 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1958 pipe_ms_state_ci.pNext = NULL;
1959 pipe_ms_state_ci.rasterSamples = 4;
1960 pipe_ms_state_ci.sampleShadingEnable = 0;
1961 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06001962 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001963
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001964 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1965 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1966 pipeline_layout_ci.pNext = NULL;
1967 pipeline_layout_ci.descriptorSetCount = 1;
1968 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001969
1970 VkPipelineLayout pipeline_layout;
1971 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1972 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001973
Tony Barbourd7d828b2015-08-06 10:16:07 -06001974 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001975 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1976 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06001977 VkPipelineObj pipe(m_device);
1978 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001979 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06001980 pipe.SetMSAA(&pipe_ms_state_ci);
1981 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001982
1983 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001984
1985 m_errorMonitor->ClearState();
1986 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
1987 // Also pass down other dummy params to keep driver and paramchecker happy
1988 VkClearColorValue cCV;
1989 cCV.f32[0] = 1.0;
1990 cCV.f32[1] = 1.0;
1991 cCV.f32[2] = 1.0;
1992 cCV.f32[3] = 1.0;
1993
Tony Barbour1490c912015-07-28 10:17:20 -06001994 vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001995 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001996 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 -06001997 if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) {
1998 FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'";
1999 }
2000}
2001
Tobin Ehlise4076782015-06-24 15:53:07 -06002002TEST_F(VkLayerTest, VtxBufferBadIndex)
2003{
2004 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
2005 VkFlags msgFlags;
2006 std::string msgString;
2007 VkResult err;
2008
2009 ASSERT_NO_FATAL_FAILURE(InitState());
2010 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2011 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002012
2013 VkDescriptorTypeCount ds_type_count = {};
2014 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2015 ds_type_count.count = 1;
2016
2017 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2018 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2019 ds_pool_ci.pNext = NULL;
2020 ds_pool_ci.count = 1;
2021 ds_pool_ci.pTypeCount = &ds_type_count;
2022
2023 VkDescriptorPool ds_pool;
Tobin Ehlise4076782015-06-24 15:53:07 -06002024 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
2025 ASSERT_VK_SUCCESS(err);
2026
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002027 VkDescriptorSetLayoutBinding dsl_binding = {};
2028 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2029 dsl_binding.arraySize = 1;
2030 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2031 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002032
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002033 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2034 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2035 ds_layout_ci.pNext = NULL;
2036 ds_layout_ci.count = 1;
2037 ds_layout_ci.pBinding = &dsl_binding;
2038
Tobin Ehlise4076782015-06-24 15:53:07 -06002039 VkDescriptorSetLayout ds_layout;
2040 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2041 ASSERT_VK_SUCCESS(err);
2042
2043 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002044 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06002045 ASSERT_VK_SUCCESS(err);
2046
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002047 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
2048 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
2049 pipe_ms_state_ci.pNext = NULL;
2050 pipe_ms_state_ci.rasterSamples = 1;
2051 pipe_ms_state_ci.sampleShadingEnable = 0;
2052 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06002053 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06002054
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002055 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2056 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2057 pipeline_layout_ci.pNext = NULL;
2058 pipeline_layout_ci.descriptorSetCount = 1;
2059 pipeline_layout_ci.pSetLayouts = &ds_layout;
2060 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06002061
Tobin Ehlise4076782015-06-24 15:53:07 -06002062 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2063 ASSERT_VK_SUCCESS(err);
2064
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06002065 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002066 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2067 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06002068 VkPipelineObj pipe(m_device);
2069 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06002070 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06002071 pipe.SetMSAA(&pipe_ms_state_ci);
2072 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06002073
2074 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06002075 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlise4076782015-06-24 15:53:07 -06002076 // Should error before calling to driver so don't care about actual data
Tony Barbour1490c912015-07-28 10:17:20 -06002077 vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL);
Tobin Ehlise4076782015-06-24 15:53:07 -06002078
2079 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002080 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 -06002081 if (!strstr(msgString.c_str(),"Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.")) {
2082 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'";
2083 }
2084}
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002085#endif
2086#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06002087#if GTEST_IS_THREADSAFE
2088struct thread_data_struct {
2089 VkCmdBuffer cmdBuffer;
2090 VkEvent event;
2091 bool bailout;
2092};
2093
2094extern "C" void *AddToCommandBuffer(void *arg)
2095{
2096 struct thread_data_struct *data = (struct thread_data_struct *) arg;
2097 std::string msgString;
2098
2099 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06002100 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06002101 if (data->bailout) {
2102 break;
2103 }
2104 }
2105 return NULL;
2106}
2107
2108TEST_F(VkLayerTest, ThreadCmdBufferCollision)
2109{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002110 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06002111 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002112 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06002113
2114 ASSERT_NO_FATAL_FAILURE(InitState());
2115 ASSERT_NO_FATAL_FAILURE(InitViewport());
2116 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2117
Mike Stroyan09aae812015-05-12 16:00:45 -06002118 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06002119 BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002120
2121 VkEventCreateInfo event_info;
2122 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06002123 VkResult err;
2124
2125 memset(&event_info, 0, sizeof(event_info));
2126 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2127
2128 err = vkCreateEvent(device(), &event_info, &event);
2129 ASSERT_VK_SUCCESS(err);
2130
Mike Stroyan09aae812015-05-12 16:00:45 -06002131 err = vkResetEvent(device(), event);
2132 ASSERT_VK_SUCCESS(err);
2133
2134 struct thread_data_struct data;
Tony Barbour1490c912015-07-28 10:17:20 -06002135 data.cmdBuffer = m_cmdBuffer->handle();
Mike Stroyan09aae812015-05-12 16:00:45 -06002136 data.event = event;
2137 data.bailout = false;
2138 m_errorMonitor->SetBailout(&data.bailout);
2139 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002140 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06002141 // Add many entries to command buffer from this thread at the same time.
2142 AddToCommandBuffer(&data);
Mike Stroyan7016f4f2015-07-13 14:45:35 -06002143 test_platform_thread_join(thread, NULL);
Tony Barbour1490c912015-07-28 10:17:20 -06002144 EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06002145
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002146 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002147 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 -06002148 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05002149 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06002150 }
2151
2152}
2153#endif
Tobin Ehlis57e6a612015-05-26 16:11:58 -06002154#endif
Chris Forbes5af3bf22015-05-25 11:13:08 +12002155#if SHADER_CHECKER_TESTS
2156TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
2157{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002158 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12002159 std::string msgString;
2160 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002161 ScopedUseGlsl useGlsl(false);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002162
2163 char const *vsSource =
2164 "#version 140\n"
2165 "#extension GL_ARB_separate_shader_objects: require\n"
2166 "#extension GL_ARB_shading_language_420pack: require\n"
2167 "\n"
2168 "layout(location=0) out float x;\n"
2169 "void main(){\n"
2170 " gl_Position = vec4(1);\n"
2171 " x = 0;\n"
2172 "}\n";
2173 char const *fsSource =
2174 "#version 140\n"
2175 "#extension GL_ARB_separate_shader_objects: require\n"
2176 "#extension GL_ARB_shading_language_420pack: require\n"
2177 "\n"
2178 "layout(location=0) out vec4 color;\n"
2179 "void main(){\n"
2180 " color = vec4(1);\n"
2181 "}\n";
2182
2183 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2184 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2185
2186 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002187 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12002188 pipe.AddShader(&vs);
2189 pipe.AddShader(&fs);
2190
Chris Forbes5af3bf22015-05-25 11:13:08 +12002191 VkDescriptorSetObj descriptorSet(m_device);
2192 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002193 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002194
2195 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002196 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12002197
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002198 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002199
Cody Northrop1684adb2015-08-05 11:15:02 -06002200 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12002201 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
2202 FAIL() << "Incorrect warning: " << msgString;
2203 }
2204}
Chris Forbes5af3bf22015-05-25 11:13:08 +12002205
Chris Forbes3c10b852015-05-25 11:13:13 +12002206TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
2207{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002208 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12002209 std::string msgString;
2210 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002211 ScopedUseGlsl useGlsl(false);
Chris Forbes3c10b852015-05-25 11:13:13 +12002212
2213 char const *vsSource =
2214 "#version 140\n"
2215 "#extension GL_ARB_separate_shader_objects: require\n"
2216 "#extension GL_ARB_shading_language_420pack: require\n"
2217 "\n"
2218 "void main(){\n"
2219 " gl_Position = vec4(1);\n"
2220 "}\n";
2221 char const *fsSource =
2222 "#version 140\n"
2223 "#extension GL_ARB_separate_shader_objects: require\n"
2224 "#extension GL_ARB_shading_language_420pack: require\n"
2225 "\n"
2226 "layout(location=0) in float x;\n"
2227 "layout(location=0) out vec4 color;\n"
2228 "void main(){\n"
2229 " color = vec4(x);\n"
2230 "}\n";
2231
2232 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2233 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2234
2235 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002236 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12002237 pipe.AddShader(&vs);
2238 pipe.AddShader(&fs);
2239
Chris Forbes3c10b852015-05-25 11:13:13 +12002240 VkDescriptorSetObj descriptorSet(m_device);
2241 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002242 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12002243
2244 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002245 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12002246
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002247 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12002248
Cody Northrop1684adb2015-08-05 11:15:02 -06002249 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes3c10b852015-05-25 11:13:13 +12002250 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
2251 FAIL() << "Incorrect error: " << msgString;
2252 }
2253}
2254
Chris Forbescc281692015-05-25 11:13:17 +12002255TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
2256{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002257 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12002258 std::string msgString;
2259 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002260 ScopedUseGlsl useGlsl(false);
Chris Forbescc281692015-05-25 11:13:17 +12002261
2262 char const *vsSource =
2263 "#version 140\n"
2264 "#extension GL_ARB_separate_shader_objects: require\n"
2265 "#extension GL_ARB_shading_language_420pack: require\n"
2266 "\n"
2267 "layout(location=0) out int x;\n"
2268 "void main(){\n"
2269 " x = 0;\n"
2270 " gl_Position = vec4(1);\n"
2271 "}\n";
2272 char const *fsSource =
2273 "#version 140\n"
2274 "#extension GL_ARB_separate_shader_objects: require\n"
2275 "#extension GL_ARB_shading_language_420pack: require\n"
2276 "\n"
2277 "layout(location=0) in float x;\n" /* VS writes int */
2278 "layout(location=0) out vec4 color;\n"
2279 "void main(){\n"
2280 " color = vec4(x);\n"
2281 "}\n";
2282
2283 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2284 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2285
2286 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002287 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12002288 pipe.AddShader(&vs);
2289 pipe.AddShader(&fs);
2290
Chris Forbescc281692015-05-25 11:13:17 +12002291 VkDescriptorSetObj descriptorSet(m_device);
2292 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002293 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12002294
2295 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002296 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12002297
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002298 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12002299
Cody Northrop1684adb2015-08-05 11:15:02 -06002300 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbescc281692015-05-25 11:13:17 +12002301 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
2302 FAIL() << "Incorrect error: " << msgString;
2303 }
2304}
2305
Chris Forbes8291c052015-05-25 11:13:28 +12002306TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
2307{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002308 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12002309 std::string msgString;
2310 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002311 ScopedUseGlsl useGlsl(false);
Chris Forbes8291c052015-05-25 11:13:28 +12002312
2313 VkVertexInputBindingDescription input_binding;
2314 memset(&input_binding, 0, sizeof(input_binding));
2315
2316 VkVertexInputAttributeDescription input_attrib;
2317 memset(&input_attrib, 0, sizeof(input_attrib));
2318 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2319
2320 char const *vsSource =
2321 "#version 140\n"
2322 "#extension GL_ARB_separate_shader_objects: require\n"
2323 "#extension GL_ARB_shading_language_420pack: require\n"
2324 "\n"
2325 "void main(){\n"
2326 " gl_Position = vec4(1);\n"
2327 "}\n";
2328 char const *fsSource =
2329 "#version 140\n"
2330 "#extension GL_ARB_separate_shader_objects: require\n"
2331 "#extension GL_ARB_shading_language_420pack: require\n"
2332 "\n"
2333 "layout(location=0) out vec4 color;\n"
2334 "void main(){\n"
2335 " color = vec4(1);\n"
2336 "}\n";
2337
2338 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2339 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2340
2341 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002342 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12002343 pipe.AddShader(&vs);
2344 pipe.AddShader(&fs);
2345
2346 pipe.AddVertexInputBindings(&input_binding, 1);
2347 pipe.AddVertexInputAttribs(&input_attrib, 1);
2348
Chris Forbes8291c052015-05-25 11:13:28 +12002349 VkDescriptorSetObj descriptorSet(m_device);
2350 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002351 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12002352
2353 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002354 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12002355
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002356 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12002357
Cody Northrop1684adb2015-08-05 11:15:02 -06002358 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12002359 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
2360 FAIL() << "Incorrect warning: " << msgString;
2361 }
2362}
2363
Chris Forbes37367e62015-05-25 11:13:29 +12002364TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
2365{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002366 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12002367 std::string msgString;
2368 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002369 ScopedUseGlsl useGlsl(false);
Chris Forbes37367e62015-05-25 11:13:29 +12002370
2371 char const *vsSource =
2372 "#version 140\n"
2373 "#extension GL_ARB_separate_shader_objects: require\n"
2374 "#extension GL_ARB_shading_language_420pack: require\n"
2375 "\n"
2376 "layout(location=0) in vec4 x;\n" /* not provided */
2377 "void main(){\n"
2378 " gl_Position = x;\n"
2379 "}\n";
2380 char const *fsSource =
2381 "#version 140\n"
2382 "#extension GL_ARB_separate_shader_objects: require\n"
2383 "#extension GL_ARB_shading_language_420pack: require\n"
2384 "\n"
2385 "layout(location=0) out vec4 color;\n"
2386 "void main(){\n"
2387 " color = vec4(1);\n"
2388 "}\n";
2389
2390 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2391 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2392
2393 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002394 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12002395 pipe.AddShader(&vs);
2396 pipe.AddShader(&fs);
2397
Chris Forbes37367e62015-05-25 11:13:29 +12002398 VkDescriptorSetObj descriptorSet(m_device);
2399 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002400 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12002401
2402 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002403 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12002404
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002405 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12002406
Cody Northrop1684adb2015-08-05 11:15:02 -06002407 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes37367e62015-05-25 11:13:29 +12002408 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
2409 FAIL() << "Incorrect warning: " << msgString;
2410 }
2411}
2412
Chris Forbesa4b02322015-05-25 11:13:31 +12002413TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
2414{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002415 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12002416 std::string msgString;
2417 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002418 ScopedUseGlsl useGlsl(false);
Chris Forbesa4b02322015-05-25 11:13:31 +12002419
2420 VkVertexInputBindingDescription input_binding;
2421 memset(&input_binding, 0, sizeof(input_binding));
2422
2423 VkVertexInputAttributeDescription input_attrib;
2424 memset(&input_attrib, 0, sizeof(input_attrib));
2425 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2426
2427 char const *vsSource =
2428 "#version 140\n"
2429 "#extension GL_ARB_separate_shader_objects: require\n"
2430 "#extension GL_ARB_shading_language_420pack: require\n"
2431 "\n"
2432 "layout(location=0) in int x;\n" /* attrib provided float */
2433 "void main(){\n"
2434 " gl_Position = vec4(x);\n"
2435 "}\n";
2436 char const *fsSource =
2437 "#version 140\n"
2438 "#extension GL_ARB_separate_shader_objects: require\n"
2439 "#extension GL_ARB_shading_language_420pack: require\n"
2440 "\n"
2441 "layout(location=0) out vec4 color;\n"
2442 "void main(){\n"
2443 " color = vec4(1);\n"
2444 "}\n";
2445
2446 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2447 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2448
2449 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002450 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12002451 pipe.AddShader(&vs);
2452 pipe.AddShader(&fs);
2453
2454 pipe.AddVertexInputBindings(&input_binding, 1);
2455 pipe.AddVertexInputAttribs(&input_attrib, 1);
2456
Chris Forbesa4b02322015-05-25 11:13:31 +12002457 VkDescriptorSetObj descriptorSet(m_device);
2458 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002459 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12002460
2461 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002462 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12002463
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002464 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12002465
Cody Northrop1684adb2015-08-05 11:15:02 -06002466 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa4b02322015-05-25 11:13:31 +12002467 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
2468 FAIL() << "Incorrect error: " << msgString;
2469 }
2470}
2471
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002472TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
2473{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002474 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002475 std::string msgString;
2476 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002477 ScopedUseGlsl useGlsl(false);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002478
2479 /* Two binding descriptions for binding 0 */
2480 VkVertexInputBindingDescription input_bindings[2];
2481 memset(input_bindings, 0, sizeof(input_bindings));
2482
2483 VkVertexInputAttributeDescription input_attrib;
2484 memset(&input_attrib, 0, sizeof(input_attrib));
2485 input_attrib.format = VK_FORMAT_R32_SFLOAT;
2486
2487 char const *vsSource =
2488 "#version 140\n"
2489 "#extension GL_ARB_separate_shader_objects: require\n"
2490 "#extension GL_ARB_shading_language_420pack: require\n"
2491 "\n"
2492 "layout(location=0) in float x;\n" /* attrib provided float */
2493 "void main(){\n"
2494 " gl_Position = vec4(x);\n"
2495 "}\n";
2496 char const *fsSource =
2497 "#version 140\n"
2498 "#extension GL_ARB_separate_shader_objects: require\n"
2499 "#extension GL_ARB_shading_language_420pack: require\n"
2500 "\n"
2501 "layout(location=0) out vec4 color;\n"
2502 "void main(){\n"
2503 " color = vec4(1);\n"
2504 "}\n";
2505
2506 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2507 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2508
2509 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002510 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002511 pipe.AddShader(&vs);
2512 pipe.AddShader(&fs);
2513
2514 pipe.AddVertexInputBindings(input_bindings, 2);
2515 pipe.AddVertexInputAttribs(&input_attrib, 1);
2516
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002517 VkDescriptorSetObj descriptorSet(m_device);
2518 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002519 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002520
2521 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002522 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002523
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002524 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002525
Cody Northrop1684adb2015-08-05 11:15:02 -06002526 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes0bf8fe12015-06-12 11:16:41 +12002527 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
2528 FAIL() << "Incorrect error: " << msgString;
2529 }
2530}
Chris Forbes4c948702015-05-25 11:13:32 +12002531
Chris Forbesc12ef122015-05-25 11:13:40 +12002532/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
2533 * rejects it. */
2534
2535TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
2536{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002537 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12002538 std::string msgString;
2539 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002540 ScopedUseGlsl useGlsl(false);
Chris Forbesc12ef122015-05-25 11:13:40 +12002541
2542 char const *vsSource =
2543 "#version 140\n"
2544 "#extension GL_ARB_separate_shader_objects: require\n"
2545 "#extension GL_ARB_shading_language_420pack: require\n"
2546 "\n"
2547 "void main(){\n"
2548 " gl_Position = vec4(1);\n"
2549 "}\n";
2550 char const *fsSource =
2551 "#version 140\n"
2552 "#extension GL_ARB_separate_shader_objects: require\n"
2553 "#extension GL_ARB_shading_language_420pack: require\n"
2554 "\n"
2555 "void main(){\n"
2556 "}\n";
2557
2558 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2559 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2560
2561 VkPipelineObj pipe(m_device);
2562 pipe.AddShader(&vs);
2563 pipe.AddShader(&fs);
2564
Chia-I Wuc278df82015-07-07 11:50:03 +08002565 /* set up CB 0, not written */
2566 pipe.AddColorAttachment();
2567 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12002568
Chris Forbesc12ef122015-05-25 11:13:40 +12002569 VkDescriptorSetObj descriptorSet(m_device);
2570 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002571 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12002572
2573 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002574 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12002575
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002576 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12002577
Cody Northrop1684adb2015-08-05 11:15:02 -06002578 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc12ef122015-05-25 11:13:40 +12002579 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
2580 FAIL() << "Incorrect error: " << msgString;
2581 }
2582}
2583
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002584TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
2585{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002586 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002587 std::string msgString;
2588 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002589 ScopedUseGlsl useGlsl(false);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002590
2591 char const *vsSource =
2592 "#version 140\n"
2593 "#extension GL_ARB_separate_shader_objects: require\n"
2594 "#extension GL_ARB_shading_language_420pack: require\n"
2595 "\n"
2596 "void main(){\n"
2597 " gl_Position = vec4(1);\n"
2598 "}\n";
2599 char const *fsSource =
2600 "#version 140\n"
2601 "#extension GL_ARB_separate_shader_objects: require\n"
2602 "#extension GL_ARB_shading_language_420pack: require\n"
2603 "\n"
2604 "layout(location=0) out vec4 x;\n"
2605 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
2606 "void main(){\n"
2607 " x = vec4(1);\n"
2608 " y = vec4(1);\n"
2609 "}\n";
2610
2611 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2612 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2613
2614 VkPipelineObj pipe(m_device);
2615 pipe.AddShader(&vs);
2616 pipe.AddShader(&fs);
2617
Chia-I Wuc278df82015-07-07 11:50:03 +08002618 /* set up CB 0, not written */
2619 pipe.AddColorAttachment();
2620 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002621 /* FS writes CB 1, but we don't configure it */
2622
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002623 VkDescriptorSetObj descriptorSet(m_device);
2624 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002625 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002626
2627 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002628 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002629
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002630 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002631
Cody Northrop1684adb2015-08-05 11:15:02 -06002632 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12002633 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
2634 FAIL() << "Incorrect warning: " << msgString;
2635 }
2636}
2637
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002638TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
2639{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002640 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002641 std::string msgString;
2642 ASSERT_NO_FATAL_FAILURE(InitState());
Cody Northrop1cfbd172015-06-03 16:49:20 -06002643 ScopedUseGlsl useGlsl(false);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002644
2645 char const *vsSource =
2646 "#version 140\n"
2647 "#extension GL_ARB_separate_shader_objects: require\n"
2648 "#extension GL_ARB_shading_language_420pack: require\n"
2649 "\n"
2650 "void main(){\n"
2651 " gl_Position = vec4(1);\n"
2652 "}\n";
2653 char const *fsSource =
2654 "#version 140\n"
2655 "#extension GL_ARB_separate_shader_objects: require\n"
2656 "#extension GL_ARB_shading_language_420pack: require\n"
2657 "\n"
2658 "layout(location=0) out ivec4 x;\n" /* not UNORM */
2659 "void main(){\n"
2660 " x = ivec4(1);\n"
2661 "}\n";
2662
2663 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2664 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2665
2666 VkPipelineObj pipe(m_device);
2667 pipe.AddShader(&vs);
2668 pipe.AddShader(&fs);
2669
Chia-I Wuc278df82015-07-07 11:50:03 +08002670 /* set up CB 0; type is UNORM by default */
2671 pipe.AddColorAttachment();
2672 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002673
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002674 VkDescriptorSetObj descriptorSet(m_device);
2675 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002676 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002677
2678 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06002679 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002680
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002681 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002682
Cody Northrop1684adb2015-08-05 11:15:02 -06002683 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002684 if (!strstr(msgString.c_str(),"does not match FS output type")) {
2685 FAIL() << "Incorrect error: " << msgString;
2686 }
2687}
Chris Forbesc2050732015-06-05 14:43:36 +12002688
2689TEST_F(VkLayerTest, CreatePipelineNonSpirvShader)
2690{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002691 VkFlags msgFlags;
Chris Forbesc2050732015-06-05 14:43:36 +12002692 std::string msgString;
2693 ASSERT_NO_FATAL_FAILURE(InitState());
2694 /* Intentionally provided GLSL rather than compiling to SPIRV first */
Cody Northrop1cfbd172015-06-03 16:49:20 -06002695 ScopedUseGlsl useGlsl(true);
Chris Forbesc2050732015-06-05 14:43:36 +12002696
2697 char const *vsSource =
2698 "#version 140\n"
2699 "#extension GL_ARB_separate_shader_objects: require\n"
2700 "#extension GL_ARB_shading_language_420pack: require\n"
2701 "\n"
2702 "void main(){\n"
2703 " gl_Position = vec4(1);\n"
2704 "}\n";
2705 char const *fsSource =
2706 "#version 140\n"
2707 "#extension GL_ARB_separate_shader_objects: require\n"
2708 "#extension GL_ARB_shading_language_420pack: require\n"
2709 "\n"
2710 "layout(location=0) out vec4 x;\n"
2711 "void main(){\n"
2712 " x = vec4(1);\n"
2713 "}\n";
2714
2715 m_errorMonitor->ClearState();
2716
2717 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
2718 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
2719
2720
2721 VkPipelineObj pipe(m_device);
2722 pipe.AddShader(&vs);
2723 pipe.AddShader(&fs);
2724
Chia-I Wuc278df82015-07-07 11:50:03 +08002725 /* set up CB 0; type is UNORM by default */
2726 pipe.AddColorAttachment();
2727 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc2050732015-06-05 14:43:36 +12002728
Chris Forbesc2050732015-06-05 14:43:36 +12002729 VkDescriptorSetObj descriptorSet(m_device);
2730 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06002731 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc2050732015-06-05 14:43:36 +12002732
Tony Barboured132432015-08-04 16:23:11 -06002733 VkResult res = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc2050732015-06-05 14:43:36 +12002734 /* pipeline creation should have succeeded */
2735 ASSERT_EQ(VK_SUCCESS, res);
2736
2737 /* should have emitted a warning: the shader is not SPIRV, so we're
2738 * not going to be able to analyze it */
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002739 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002740 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbesc2050732015-06-05 14:43:36 +12002741 if (!strstr(msgString.c_str(),"is not SPIR-V")) {
2742 FAIL() << "Incorrect warning: " << msgString;
2743 }
2744}
Chris Forbes01c9db72015-06-04 09:25:25 +12002745#endif
Chris Forbes7d64a4f2015-05-25 11:13:44 +12002746
Tony Barbour30486ea2015-04-07 13:44:53 -06002747int main(int argc, char **argv) {
2748 int result;
2749
2750 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06002751 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06002752
2753 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
2754
2755 result = RUN_ALL_TESTS();
2756
Tony Barbour01999182015-04-09 12:58:51 -06002757 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06002758 return result;
2759}