blob: 6f62d9fe8ce043531bb7d0d879818099adb3cb55 [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"
Courtney Goeltzenleuchter0abdb662015-10-07 13:28:58 -06003#include "test_common.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"
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06006#include "../icd/common/icd-spv.h"
Tony Barbour30486ea2015-04-07 13:44:53 -06007
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05008#define GLM_FORCE_RADIANS
9#include "glm/glm.hpp"
10#include <glm/gtc/matrix_transform.hpp>
11
Tobin Ehlis57e6a612015-05-26 16:11:58 -060012#define MEM_TRACKER_TESTS 1
13#define OBJ_TRACKER_TESTS 1
14#define DRAW_STATE_TESTS 1
15#define THREADING_TESTS 1
Chris Forbes5af3bf22015-05-25 11:13:08 +120016#define SHADER_CHECKER_TESTS 1
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -060017#define DEVICE_LIMITS_TESTS 1
Tobin Ehlis342b9bf2015-09-22 10:11:37 -060018#define IMAGE_TESTS 1
Tobin Ehlis57e6a612015-05-26 16:11:58 -060019
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050020//--------------------------------------------------------------------------------------
21// Mesh and VertexFormat Data
22//--------------------------------------------------------------------------------------
23struct Vertex
24{
25 float posX, posY, posZ, posW; // Position data
26 float r, g, b, a; // Color
27};
28
29#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
30
31typedef enum _BsoFailSelect {
32 BsoFailNone = 0x00000000,
Cody Northrope4bc6942015-08-26 10:01:32 -060033 BsoFailLineWidth = 0x00000001,
34 BsoFailDepthBias = 0x00000002,
Cody Northropf5bd2252015-08-17 11:10:49 -060035 BsoFailViewport = 0x00000004,
Tobin Ehlisf6cb4672015-09-29 08:18:34 -060036 BsoFailScissor = 0x00000008,
37 BsoFailBlend = 0x00000010,
38 BsoFailDepthBounds = 0x00000020,
39 BsoFailStencilReadMask = 0x00000040,
40 BsoFailStencilWriteMask = 0x00000080,
41 BsoFailStencilReference = 0x00000100,
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050042} BsoFailSelect;
43
44struct vktriangle_vs_uniform {
45 // Must start with MVP
46 float mvp[4][4];
47 float position[3][4];
48 float color[3][4];
49};
50
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050051static const char bindStateVertShaderText[] =
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050052 "#version 130\n"
53 "vec2 vertices[3];\n"
54 "void main() {\n"
55 " vertices[0] = vec2(-1.0, -1.0);\n"
56 " vertices[1] = vec2( 1.0, -1.0);\n"
57 " vertices[2] = vec2( 0.0, 1.0);\n"
58 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
59 "}\n";
60
Mark Lobodzinski6bbdff12015-06-02 09:41:30 -050061static const char bindStateFragShaderText[] =
Cody Northrop74a2d2c2015-06-16 17:32:04 -060062 "#version 140\n"
63 "#extension GL_ARB_separate_shader_objects: require\n"
64 "#extension GL_ARB_shading_language_420pack: require\n"
65 "\n"
66 "layout(location = 0) out vec4 uFragColor;\n"
67 "void main(){\n"
68 " uFragColor = vec4(0,1,0,1);\n"
69 "}\n";
Mark Lobodzinski5f25be42015-05-14 15:08:13 -050070
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -060071static VkBool32 myDbgFunc(
Tony Barboure84a8d62015-07-10 14:10:27 -060072 VkFlags msgFlags,
73 VkDbgObjectType objType,
74 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060075 size_t location,
76 int32_t msgCode,
77 const char* pLayerPrefix,
78 const char* pMsg,
79 void* pUserData);
Tony Barbour30486ea2015-04-07 13:44:53 -060080
81class ErrorMonitor {
82public:
Tony Barbour0c1bdc62015-04-29 17:34:29 -060083 ErrorMonitor()
Tony Barbour30486ea2015-04-07 13:44:53 -060084 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060085 test_platform_thread_create_mutex(&m_mutex);
86 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060087 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Mike Stroyan09aae812015-05-12 16:00:45 -060088 m_bailout = NULL;
Mike Stroyan7016f4f2015-07-13 14:45:35 -060089 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060090 }
91 void ClearState()
92 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -060093 test_platform_thread_lock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060094 m_msgFlags = VK_DBG_REPORT_INFO_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -060095 m_msgString.clear();
Mike Stroyan7016f4f2015-07-13 14:45:35 -060096 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -060097 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060098 VkFlags GetState(std::string *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -060099 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600100 test_platform_thread_lock_mutex(&m_mutex);
Tony Barbour30486ea2015-04-07 13:44:53 -0600101 *msgString = m_msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600102 test_platform_thread_unlock_mutex(&m_mutex);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600103 return m_msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600104 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600105 void SetState(VkFlags msgFlags, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -0600106 {
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600107 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600108 if (m_bailout != NULL) {
109 *m_bailout = true;
110 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600111 m_msgFlags = msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600112 m_msgString.reserve(strlen(msgString));
113 m_msgString = msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600114 test_platform_thread_unlock_mutex(&m_mutex);
Mike Stroyan09aae812015-05-12 16:00:45 -0600115 }
116 void SetBailout(bool *bailout)
117 {
118 m_bailout = bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600119 }
120
121private:
Mike Stroyan7016f4f2015-07-13 14:45:35 -0600122 VkFlags m_msgFlags;
123 std::string m_msgString;
124 test_platform_thread_mutex m_mutex;
125 bool* m_bailout;
Tony Barbour30486ea2015-04-07 13:44:53 -0600126};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500127
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600128static VkBool32 myDbgFunc(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600129 VkFlags msgFlags,
Tony Barboure84a8d62015-07-10 14:10:27 -0600130 VkDbgObjectType objType,
131 uint64_t srcObject,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600132 size_t location,
133 int32_t msgCode,
134 const char* pLayerPrefix,
135 const char* pMsg,
136 void* pUserData)
Tony Barbour30486ea2015-04-07 13:44:53 -0600137{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600138 if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) {
Tony Barbour8508b8e2015-04-09 10:48:04 -0600139 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600140 errMonitor->SetState(msgFlags, pMsg);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600141 return true;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600142 }
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600143
144 return false;
Tony Barbour30486ea2015-04-07 13:44:53 -0600145}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500146
Tony Barbour01999182015-04-09 12:58:51 -0600147class VkLayerTest : public VkRenderFramework
Tony Barbour30486ea2015-04-07 13:44:53 -0600148{
149public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600150 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
151 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500152 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
153 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask);
Tony Barbour1490c912015-07-28 10:17:20 -0600154 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
155 { GenericDrawPreparation(m_cmdBuffer, pipelineobj, descriptorSet, failMask); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600156
Tony Barbour1490c912015-07-28 10:17:20 -0600157 /* Convenience functions that use built-in command buffer */
158 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_cmdBuffer); }
159 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_cmdBuffer); }
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600160 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
161 { m_cmdBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance); }
162 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
163 { m_cmdBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); }
Tony Barbour1490c912015-07-28 10:17:20 -0600164 void QueueCommandBuffer() { m_cmdBuffer->QueueCommandBuffer(); }
165 void QueueCommandBuffer(const VkFence& fence) { m_cmdBuffer->QueueCommandBuffer(fence); }
166 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
167 { m_cmdBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
168 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
169 { m_cmdBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbour30486ea2015-04-07 13:44:53 -0600170protected:
Tony Barbour01999182015-04-09 12:58:51 -0600171 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600172
173 virtual void SetUp() {
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600174 std::vector<const char *> instance_layer_names;
175 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600176 std::vector<const char *> instance_extension_names;
177 std::vector<const char *> device_extension_names;
Tony Barbour950ebc02015-04-23 12:55:36 -0600178
Courtney Goeltzenleuchter846298c2015-07-30 11:32:46 -0600179 instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterde53c5b2015-06-16 15:59:11 -0600180 /*
181 * Since CreateDbgMsgCallback is an instance level extension call
182 * any extension / layer that utilizes that feature also needs
183 * to be enabled at create instance time.
184 */
Mike Stroyan2237f522015-08-18 14:40:24 -0600185 // Use Threading layer first to protect others from ThreadCmdBufferCollision test
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600186 instance_layer_names.push_back("Threading");
187 instance_layer_names.push_back("ObjectTracker");
188 instance_layer_names.push_back("MemTracker");
189 instance_layer_names.push_back("DrawState");
190 instance_layer_names.push_back("ShaderChecker");
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600191 instance_layer_names.push_back("DeviceLimits");
Tobin Ehlis342b9bf2015-09-22 10:11:37 -0600192 instance_layer_names.push_back("Image");
Courtney Goeltzenleuchter23b5f8d2015-06-17 20:51:59 -0600193
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600194 device_layer_names.push_back("Threading");
195 device_layer_names.push_back("ObjectTracker");
196 device_layer_names.push_back("MemTracker");
197 device_layer_names.push_back("DrawState");
198 device_layer_names.push_back("ShaderChecker");
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600199 device_layer_names.push_back("DeviceLimits");
Tobin Ehlis342b9bf2015-09-22 10:11:37 -0600200 device_layer_names.push_back("Image");
Tony Barbour30486ea2015-04-07 13:44:53 -0600201
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600202 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -0600203 this->app_info.pNext = NULL;
204 this->app_info.pAppName = "layer_tests";
205 this->app_info.appVersion = 1;
206 this->app_info.pEngineName = "unittest";
207 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600208 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -0600209
Tony Barbour0c1bdc62015-04-29 17:34:29 -0600210 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchterf5c61952015-07-06 09:10:47 -0600211 InitFramework(instance_layer_names, device_layer_names,
212 instance_extension_names, device_extension_names,
213 myDbgFunc, m_errorMonitor);
Tony Barbour30486ea2015-04-07 13:44:53 -0600214 }
215
216 virtual void TearDown() {
217 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600218 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600219 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600220 }
221};
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500222
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600223VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600224{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600225 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600226
227 result = cmdBuffer.BeginCommandBuffer();
228
229 /*
230 * For render test all drawing happens in a single render pass
231 * on a single command buffer.
232 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200233 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wuc278df82015-07-07 11:50:03 +0800234 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour30486ea2015-04-07 13:44:53 -0600235 }
236
237 return result;
238}
239
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600240VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600241{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600242 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600243
Chris Forbesfe133ef2015-06-16 14:05:59 +1200244 if (renderPass()) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800245 cmdBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200246 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600247
248 result = cmdBuffer.EndCommandBuffer();
249
250 return result;
251}
252
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500253void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask)
254{
255 // Create identity matrix
256 int i;
257 struct vktriangle_vs_uniform data;
258
259 glm::mat4 Projection = glm::mat4(1.0f);
260 glm::mat4 View = glm::mat4(1.0f);
261 glm::mat4 Model = glm::mat4(1.0f);
262 glm::mat4 MVP = Projection * View * Model;
263 const int matrixSize = sizeof(MVP);
264 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
265
266 memcpy(&data.mvp, &MVP[0][0], matrixSize);
267
268 static const Vertex tri_data[] =
269 {
270 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
271 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
272 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
273 };
274
275 for (i=0; i<3; i++) {
276 data.position[i][0] = tri_data[i].posX;
277 data.position[i][1] = tri_data[i].posY;
278 data.position[i][2] = tri_data[i].posZ;
279 data.position[i][3] = tri_data[i].posW;
280 data.color[i][0] = tri_data[i].r;
281 data.color[i][1] = tri_data[i].g;
282 data.color[i][2] = tri_data[i].b;
283 data.color[i][3] = tri_data[i].a;
284 }
285
286 ASSERT_NO_FATAL_FAILURE(InitState());
287 ASSERT_NO_FATAL_FAILURE(InitViewport());
288
289 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
290
291 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
292 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
293
294 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800295 pipelineobj.AddColorAttachment();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500296 pipelineobj.AddShader(&vs);
297 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600298 if (failMask & BsoFailLineWidth) {
299 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
300 }
301 if (failMask & BsoFailDepthBias) {
302 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
303 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600304 // Viewport and scissors must stay in synch or other errors will occur than the ones we want
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600305 if (failMask & BsoFailViewport) {
306 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600307 m_viewports.clear();
308 m_scissors.clear();
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600309 }
310 if (failMask & BsoFailScissor) {
311 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600312 m_scissors.clear();
313 m_viewports.clear();
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600314 }
315 if (failMask & BsoFailBlend) {
316 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
317 }
318 if (failMask & BsoFailDepthBounds) {
319 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
320 }
321 if (failMask & BsoFailStencilReadMask) {
322 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
323 }
324 if (failMask & BsoFailStencilWriteMask) {
325 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
326 }
327 if (failMask & BsoFailStencilReference) {
328 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
329 }
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500330
331 VkDescriptorSetObj descriptorSet(m_device);
332 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
333
334 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600335 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500336
Tony Barbour1490c912015-07-28 10:17:20 -0600337 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500338
339 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600340 Draw(3, 1, 0, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500341
342 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600343 EndCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500344
Tony Barbour1490c912015-07-28 10:17:20 -0600345 QueueCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500346}
347
348void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
349{
350 if (m_depthStencil->Initialized()) {
351 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
352 } else {
353 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
354 }
355
356 cmdBuffer->PrepareAttachments();
Cody Northrop2605cb02015-08-18 15:21:16 -0600357 // Make sure depthWriteEnable is set so that Depth fail test will work correctly
358 // Make sure stencilTestEnable is set so that Stencil fail test will work correctly
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600359 VkStencilOpState stencil = {};
360 stencil.stencilFailOp = VK_STENCIL_OP_KEEP;
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600361 stencil.stencilPassOp = VK_STENCIL_OP_KEEP;
362 stencil.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
363 stencil.stencilCompareOp = VK_COMPARE_OP_NEVER;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600364
365 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
366 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600367 ds_ci.pNext = NULL;
368 ds_ci.depthTestEnable = VK_FALSE;
369 ds_ci.depthWriteEnable = VK_TRUE;
370 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
371 ds_ci.depthBoundsTestEnable = VK_FALSE;
372 ds_ci.stencilTestEnable = VK_TRUE;
373 ds_ci.front = stencil;
374 ds_ci.back = stencil;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600375
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600376 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600377 pipelineobj.SetViewport(m_viewports);
378 pipelineobj.SetScissor(m_scissors);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500379 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Cody Northropccfa96d2015-08-27 10:20:35 -0600380 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
381 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500382 cmdBuffer->BindPipeline(pipelineobj);
383 cmdBuffer->BindDescriptorSet(descriptorSet);
384}
385
386// ********************************************************************************************************************
387// ********************************************************************************************************************
388// ********************************************************************************************************************
389// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600390#if MEM_TRACKER_TESTS
Mark Lobodzinski81078192015-05-19 10:28:29 -0500391TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
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());
Tony Barboure389b882015-07-20 13:00:10 -0600403
404 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
405 vk_testing::Buffer buffer;
406 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500407
Tony Barbour1490c912015-07-28 10:17:20 -0600408 BeginCommandBuffer();
409 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
410 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500411
412 testFence.init(*m_device, fenceInfo);
413
414 // Bypass framework since it does the waits automatically
415 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600416 VkSubmitInfo submit_info = {
417 .waitSemCount = 0,
418 .pWaitSemaphores = NULL,
419 .cmdBufferCount = 1,
420 .pCommandBuffers = &m_cmdBuffer->handle(),
421 .signalSemCount = 0,
422 .pSignalSemaphores = NULL
423 };
424
425 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500426 ASSERT_VK_SUCCESS( err );
427
428 m_errorMonitor->ClearState();
429 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600430 vkResetCommandBuffer(m_cmdBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500431
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600432 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600433 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 -0500434 if (!strstr(msgString.c_str(),"Resetting CB")) {
435 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
436 }
437}
438
439TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion)
440{
441 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600442 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500443 std::string msgString;
444
445 VkFenceCreateInfo fenceInfo = {};
446 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
447 fenceInfo.pNext = NULL;
448 fenceInfo.flags = 0;
449
450 ASSERT_NO_FATAL_FAILURE(InitState());
451 ASSERT_NO_FATAL_FAILURE(InitViewport());
452 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
453
Tony Barbour1490c912015-07-28 10:17:20 -0600454 BeginCommandBuffer();
455 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
456 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500457
458 testFence.init(*m_device, fenceInfo);
459
460 // Bypass framework since it does the waits automatically
461 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600462 VkSubmitInfo submit_info = {
463 .waitSemCount = 0,
464 .pWaitSemaphores = NULL,
465 .cmdBufferCount = 1,
466 .pCommandBuffers = &m_cmdBuffer->handle(),
467 .signalSemCount = 0,
468 .pSignalSemaphores = NULL
469 };
470
471 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500472 ASSERT_VK_SUCCESS( err );
473
474 m_errorMonitor->ClearState();
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600475
476 VkCmdBufferBeginInfo info = {};
477 info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT | VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
478 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
479 info.renderPass = VK_NULL_HANDLE;
480 info.subpass = 0;
481 info.framebuffer = VK_NULL_HANDLE;
482
483 // Introduce failure by calling BCB again before checking fence
484 vkBeginCommandBuffer(m_cmdBuffer->handle(), &info);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500485
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600486 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600487 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 -0500488 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
489 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
490 }
491}
492
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500493TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
494{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600495 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500496 std::string msgString;
497 VkResult err;
498
499 ASSERT_NO_FATAL_FAILURE(InitState());
500 m_errorMonitor->ClearState();
501
502 // Create an image, allocate memory, free it, and then try to bind it
503 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500504 VkDeviceMemory mem;
505 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500506
507 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
508 const int32_t tex_width = 32;
509 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500510
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600511 VkImageCreateInfo image_create_info = {};
512 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
513 image_create_info.pNext = NULL;
514 image_create_info.imageType = VK_IMAGE_TYPE_2D;
515 image_create_info.format = tex_format;
516 image_create_info.extent.width = tex_width;
517 image_create_info.extent.height = tex_height;
518 image_create_info.extent.depth = 1;
519 image_create_info.mipLevels = 1;
520 image_create_info.arraySize = 1;
521 image_create_info.samples = 1;
522 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
523 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
524 image_create_info.flags = 0;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600525
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600526 VkMemoryAllocInfo mem_alloc = {};
527 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
528 mem_alloc.pNext = NULL;
529 mem_alloc.allocationSize = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500530 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600531 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500532
533 err = vkCreateImage(m_device->device(), &image_create_info, &image);
534 ASSERT_VK_SUCCESS(err);
535
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600536 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500537 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500538 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500539
Mark Lobodzinski23182612015-05-29 09:32:35 -0500540 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500541
Mike Stroyan2237f522015-08-18 14:40:24 -0600542 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
543 if(err != VK_SUCCESS) { // If we can't find any unmappable memory this test doesn't make sense
544 vkDestroyImage(m_device->device(), image);
Tony Barbour49a3b652015-08-04 16:13:01 -0600545 return;
Mike Stroyan2237f522015-08-18 14:40:24 -0600546 }
Mike Stroyand72da752015-08-04 10:49:29 -0600547
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500548 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500549 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500550 ASSERT_VK_SUCCESS(err);
551
552 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600553 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500554 ASSERT_VK_SUCCESS(err);
555
556 // Map memory as if to initialize the image
557 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500558 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500559
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600560 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600561 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 -0500562 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
563 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
564 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600565
566 vkDestroyImage(m_device->device(), image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500567}
568
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600569// TODO : Is this test still valid. Not sure it is with updates to memory binding model
570// Verify and delete the test of fix the check
571//TEST_F(VkLayerTest, FreeBoundMemory)
572//{
573// VkFlags msgFlags;
574// std::string msgString;
575// VkResult err;
576//
577// ASSERT_NO_FATAL_FAILURE(InitState());
578// m_errorMonitor->ClearState();
579//
580// // Create an image, allocate memory, free it, and then try to bind it
581// VkImage image;
582// VkDeviceMemory mem;
583// VkMemoryRequirements mem_reqs;
584//
585// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
586// const int32_t tex_width = 32;
587// const int32_t tex_height = 32;
588//
589// const VkImageCreateInfo image_create_info = {
590// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
591// .pNext = NULL,
592// .imageType = VK_IMAGE_TYPE_2D,
593// .format = tex_format,
594// .extent = { tex_width, tex_height, 1 },
595// .mipLevels = 1,
596// .arraySize = 1,
597// .samples = 1,
598// .tiling = VK_IMAGE_TILING_LINEAR,
599// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
600// .flags = 0,
601// };
602// VkMemoryAllocInfo mem_alloc = {
603// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
604// .pNext = NULL,
605// .allocationSize = 0,
606// .memoryTypeIndex = 0,
607// };
608//
609// err = vkCreateImage(m_device->device(), &image_create_info, &image);
610// ASSERT_VK_SUCCESS(err);
611//
612// err = vkGetImageMemoryRequirements(m_device->device(),
613// image,
614// &mem_reqs);
615// ASSERT_VK_SUCCESS(err);
616//
617// mem_alloc.allocationSize = mem_reqs.size;
618//
619// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
620// ASSERT_VK_SUCCESS(err);
621//
622// // allocate memory
623// err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
624// ASSERT_VK_SUCCESS(err);
625//
626// // Bind memory to Image object
627// err = vkBindImageMemory(m_device->device(), image, mem, 0);
628// ASSERT_VK_SUCCESS(err);
629//
630// // Introduce validation failure, free memory while still bound to object
631// vkFreeMemory(m_device->device(), mem);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600632// msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600633//
Cody Northrop1684adb2015-08-05 11:15:02 -0600634// 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 -0600635// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
636// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
637// }
638//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500639
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500640TEST_F(VkLayerTest, RebindMemory)
641{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600642 VkFlags msgFlags;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500643 std::string msgString;
644 VkResult err;
645
646 ASSERT_NO_FATAL_FAILURE(InitState());
647 m_errorMonitor->ClearState();
648
649 // Create an image, allocate memory, free it, and then try to bind it
650 VkImage image;
651 VkDeviceMemory mem1;
652 VkDeviceMemory mem2;
653 VkMemoryRequirements mem_reqs;
654
655 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
656 const int32_t tex_width = 32;
657 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500658
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600659 VkImageCreateInfo image_create_info = {};
660 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
661 image_create_info.pNext = NULL;
662 image_create_info.imageType = VK_IMAGE_TYPE_2D;
663 image_create_info.format = tex_format;
664 image_create_info.extent.width = tex_width;
665 image_create_info.extent.height = tex_height;
666 image_create_info.extent.depth = 1;
667 image_create_info.mipLevels = 1;
668 image_create_info.arraySize = 1;
669 image_create_info.samples = 1;
670 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
671 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
672 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500673
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600674 VkMemoryAllocInfo mem_alloc = {};
675 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
676 mem_alloc.pNext = NULL;
677 mem_alloc.allocationSize = 0;
678 mem_alloc.memoryTypeIndex = 0;
679
680 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
681 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500682 err = vkCreateImage(m_device->device(), &image_create_info, &image);
683 ASSERT_VK_SUCCESS(err);
684
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600685 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500686 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500687 &mem_reqs);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500688
689 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800690 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600691 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500692
693 // allocate 2 memory objects
694 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
695 ASSERT_VK_SUCCESS(err);
696 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
697 ASSERT_VK_SUCCESS(err);
698
699 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600700 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500701 ASSERT_VK_SUCCESS(err);
702
703 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600704 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500705
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600706 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600707 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 -0500708 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
709 FAIL() << "Error received did not match expected message when rebinding memory to an object";
710 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600711
712 vkDestroyImage(m_device->device(), image);
713 vkFreeMemory(m_device->device(), mem1);
714 vkFreeMemory(m_device->device(), mem2);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500715}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500716
Tony Barbour8508b8e2015-04-09 10:48:04 -0600717TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600718{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600719 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600720 VkFlags msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600721 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600722
723 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600724 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
725 fenceInfo.pNext = NULL;
726 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600727
Tony Barbour30486ea2015-04-07 13:44:53 -0600728 ASSERT_NO_FATAL_FAILURE(InitState());
729 ASSERT_NO_FATAL_FAILURE(InitViewport());
730 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
731
Tony Barbour1490c912015-07-28 10:17:20 -0600732 BeginCommandBuffer();
733 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
734 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600735
736 testFence.init(*m_device, fenceInfo);
737 m_errorMonitor->ClearState();
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600738
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600739 VkSubmitInfo submit_info = {
740 .waitSemCount = 0,
741 .pWaitSemaphores = NULL,
742 .cmdBufferCount = 1,
743 .pCommandBuffers = &m_cmdBuffer->handle(),
744 .signalSemCount = 0,
745 .pSignalSemaphores = NULL
746 };
747
748 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600749 vkQueueWaitIdle(m_device->m_queue );
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600750 msgFlags = m_errorMonitor->GetState(&msgString);
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600751
Cody Northrop1684adb2015-08-05 11:15:02 -0600752 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 -0600753 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500754 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600755 }
756
757}
758
759TEST_F(VkLayerTest, ResetUnsignaledFence)
760{
761 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600762 VkFlags msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600763 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600764 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600765 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
766 fenceInfo.pNext = NULL;
767
Tony Barbour8508b8e2015-04-09 10:48:04 -0600768 ASSERT_NO_FATAL_FAILURE(InitState());
769 testFence.init(*m_device, fenceInfo);
770 m_errorMonitor->ClearState();
Chia-I Wua4992342015-07-03 11:45:55 +0800771 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600772 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600773 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlisc2033a02015-10-01 10:14:48 -0600774 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_WARN_BIT)) << "Did not receive an error from submitting fence with UNSIGNALED state to vkResetFences";
Tony Barbour01999182015-04-09 12:58:51 -0600775 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500776 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600777 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600778
779}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600780
Chia-I Wuc278df82015-07-07 11:50:03 +0800781/* TODO: Update for changes due to bug-14075 tiling across render passes */
782#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600783TEST_F(VkLayerTest, InvalidUsageBits)
784{
785 // Initiate Draw w/o a PSO bound
786 VkFlags msgFlags;
787 std::string msgString;
788
789 ASSERT_NO_FATAL_FAILURE(InitState());
790 m_errorMonitor->ClearState();
791 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600792 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600793
794 const VkExtent3D e3d = {
795 .width = 128,
796 .height = 128,
797 .depth = 1,
798 };
799 const VkImageCreateInfo ici = {
800 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
801 .pNext = NULL,
802 .imageType = VK_IMAGE_TYPE_2D,
803 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
804 .extent = e3d,
805 .mipLevels = 1,
806 .arraySize = 1,
807 .samples = 1,
808 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchterc3b8eea2015-09-10 14:14:11 -0600809 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600810 .flags = 0,
811 };
812
813 VkImage dsi;
814 vkCreateImage(m_device->device(), &ici, &dsi);
815 VkDepthStencilView dsv;
816 const VkDepthStencilViewCreateInfo dsvci = {
817 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
818 .pNext = NULL,
819 .image = dsi,
820 .mipLevel = 0,
Courtney Goeltzenleuchter3dee8082015-09-10 16:38:41 -0600821 .baseArrayLayer = 0,
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600822 .arraySize = 1,
823 .flags = 0,
824 };
825 vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv);
826 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600827 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 -0600828 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
829 FAIL() << "Error received was not 'Invalid usage flag for image...'";
830 }
831}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600832#endif // 0
833#endif // MEM_TRACKER_TESTS
834
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600835#if OBJ_TRACKER_TESTS
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600836TEST_F(VkLayerTest, PipelineNotBound)
837{
838 VkFlags msgFlags;
839 std::string msgString;
840 VkResult err;
841
842 ASSERT_NO_FATAL_FAILURE(InitState());
843 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
844 m_errorMonitor->ClearState();
845
846 VkDescriptorTypeCount ds_type_count = {};
847 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
848 ds_type_count.count = 1;
849
850 VkDescriptorPoolCreateInfo ds_pool_ci = {};
851 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
852 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600853 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
854 ds_pool_ci.maxSets = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600855 ds_pool_ci.count = 1;
856 ds_pool_ci.pTypeCount = &ds_type_count;
857
858 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600859 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600860 ASSERT_VK_SUCCESS(err);
861
862 VkDescriptorSetLayoutBinding dsl_binding = {};
863 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
864 dsl_binding.arraySize = 1;
865 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
866 dsl_binding.pImmutableSamplers = NULL;
867
868 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
869 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
870 ds_layout_ci.pNext = NULL;
871 ds_layout_ci.count = 1;
872 ds_layout_ci.pBinding = &dsl_binding;
873
874 VkDescriptorSetLayout ds_layout;
875 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
876 ASSERT_VK_SUCCESS(err);
877
878 VkDescriptorSet descriptorSet;
879 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
880 ASSERT_VK_SUCCESS(err);
881
882 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
883 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
884 pipeline_layout_ci.pNext = NULL;
885 pipeline_layout_ci.descriptorSetCount = 1;
886 pipeline_layout_ci.pSetLayouts = &ds_layout;
887
888 VkPipelineLayout pipeline_layout;
889 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
890 ASSERT_VK_SUCCESS(err);
891
892 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
893
894 BeginCommandBuffer();
895 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
896
897 msgFlags = m_errorMonitor->GetState(&msgString);
898 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding invalid pipeline to CmdBuffer";
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600899 if (!strstr(msgString.c_str(),"Invalid VkPipeline Object ")) {
900 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be' but instead it was '" << msgString.c_str() << "'";
901 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600902
903 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -0600904 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
905 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600906}
907
908TEST_F(VkLayerTest, BindInvalidMemory)
909{
910 VkFlags msgFlags;
911 std::string msgString;
912 VkResult err;
913
914 ASSERT_NO_FATAL_FAILURE(InitState());
915 m_errorMonitor->ClearState();
916
917 // Create an image, allocate memory, free it, and then try to bind it
918 VkImage image;
919 VkDeviceMemory mem;
920 VkMemoryRequirements mem_reqs;
921
922 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
923 const int32_t tex_width = 32;
924 const int32_t tex_height = 32;
925
926 VkImageCreateInfo image_create_info = {};
927 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
928 image_create_info.pNext = NULL;
929 image_create_info.imageType = VK_IMAGE_TYPE_2D;
930 image_create_info.format = tex_format;
931 image_create_info.extent.width = tex_width;
932 image_create_info.extent.height = tex_height;
933 image_create_info.extent.depth = 1;
934 image_create_info.mipLevels = 1;
935 image_create_info.arraySize = 1;
936 image_create_info.samples = 1;
937 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
938 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
939 image_create_info.flags = 0;
940
941 VkMemoryAllocInfo mem_alloc = {};
942 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
943 mem_alloc.pNext = NULL;
944 mem_alloc.allocationSize = 0;
945 mem_alloc.memoryTypeIndex = 0;
946
947 err = vkCreateImage(m_device->device(), &image_create_info, &image);
948 ASSERT_VK_SUCCESS(err);
949
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600950 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600951 image,
952 &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600953
954 mem_alloc.allocationSize = mem_reqs.size;
955
956 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
957 ASSERT_VK_SUCCESS(err);
958
959 // allocate memory
960 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
961 ASSERT_VK_SUCCESS(err);
962
963 // Introduce validation failure, free memory before binding
964 vkFreeMemory(m_device->device(), mem);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600965
966 // Try to bind free memory that has been freed
967 err = vkBindImageMemory(m_device->device(), image, mem, 0);
968 // This may very well return an error.
969 (void)err;
970
971 msgFlags = m_errorMonitor->GetState(&msgString);
972 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to bind a freed memory object";
973 if (!strstr(msgString.c_str(),"Invalid VkDeviceMemory Object ")) {
974 FAIL() << "Error received from BindInvalidMemory was not 'Invalid VkDeviceMemory Object 0x<handle>' but instead '" << msgString.c_str() << "'";
975 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600976
977 vkDestroyImage(m_device->device(), image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600978}
979
980TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
981{
982 VkFlags msgFlags;
983 std::string msgString;
984 VkResult err;
985
986 ASSERT_NO_FATAL_FAILURE(InitState());
987 m_errorMonitor->ClearState();
988
989 // Create an image object, allocate memory, destroy the object and then try to bind it
990 VkImage image;
991 VkDeviceMemory mem;
992 VkMemoryRequirements mem_reqs;
993
994 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
995 const int32_t tex_width = 32;
996 const int32_t tex_height = 32;
997
998 VkImageCreateInfo image_create_info = {};
999 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1000 image_create_info.pNext = NULL;
1001 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1002 image_create_info.format = tex_format;
1003 image_create_info.extent.width = tex_width;
1004 image_create_info.extent.height = tex_height;
1005 image_create_info.extent.depth = 1;
1006 image_create_info.mipLevels = 1;
1007 image_create_info.arraySize = 1;
1008 image_create_info.samples = 1;
1009 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1010 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1011 image_create_info.flags = 0;
1012
1013 VkMemoryAllocInfo mem_alloc = {};
1014 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
1015 mem_alloc.pNext = NULL;
1016 mem_alloc.allocationSize = 0;
1017 mem_alloc.memoryTypeIndex = 0;
1018
1019 err = vkCreateImage(m_device->device(), &image_create_info, &image);
1020 ASSERT_VK_SUCCESS(err);
1021
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06001022 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001023 image,
1024 &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001025
1026 mem_alloc.allocationSize = mem_reqs.size;
1027 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1028 ASSERT_VK_SUCCESS(err);
1029
1030 // Allocate memory
1031 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
1032 ASSERT_VK_SUCCESS(err);
1033
1034 // Introduce validation failure, destroy Image object before binding
1035 vkDestroyImage(m_device->device(), image);
1036 ASSERT_VK_SUCCESS(err);
1037
1038 // Now Try to bind memory to this destroyed object
1039 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1040 // This may very well return an error.
1041 (void) err;
1042
1043 msgFlags = m_errorMonitor->GetState(&msgString);
1044 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while binding memory to a destroyed object";
1045 if (!strstr(msgString.c_str(),"Invalid VkImage Object ")) {
1046 FAIL() << "Error received from BindMemoryToDestroyedObject was not 'Invalid VkImage Object 0x<handle>' but rather '" << msgString.c_str() << "'";
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001047 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001048
1049 vkFreeMemory(m_device->device(), mem);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001050}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001051#endif // OBJ_TRACKER_TESTS
1052
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001053#if DRAW_STATE_TESTS
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001054TEST_F(VkLayerTest, LineWidthStateNotBound)
1055{
1056 VkFlags msgFlags;
1057 std::string msgString;
1058 m_errorMonitor->ClearState();
1059 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
1060
1061 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
1062
1063 msgFlags = m_errorMonitor->GetState(&msgString);
1064 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Line Width State Object";
1065 if (!strstr(msgString.c_str(),"Dynamic line width state not set for this command buffer")) {
1066 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic line width state not set for this command buffer'";
1067 }
1068}
1069
1070TEST_F(VkLayerTest, DepthBiasStateNotBound)
1071{
1072 VkFlags msgFlags;
1073 std::string msgString;
1074 m_errorMonitor->ClearState();
1075 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
1076
1077 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
1078
1079 msgFlags = m_errorMonitor->GetState(&msgString);
1080 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bias State Object";
1081 if (!strstr(msgString.c_str(),"Dynamic depth bias state not set for this command buffer")) {
1082 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bias state not set for this command buffer'";
1083 }
1084}
1085
1086TEST_F(VkLayerTest, ViewportStateNotBound)
1087{
1088 VkFlags msgFlags;
1089 std::string msgString;
1090 m_errorMonitor->ClearState();
1091 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1092
1093 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1094
1095 msgFlags = m_errorMonitor->GetState(&msgString);
1096 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06001097 // TODO : Viewport and scissor currently set as a pair in framework so scissor error masks viewport error
1098 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1099 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001100 }
1101}
1102
1103TEST_F(VkLayerTest, ScissorStateNotBound)
1104{
1105 VkFlags msgFlags;
1106 std::string msgString;
1107 m_errorMonitor->ClearState();
1108 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1109
1110 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1111
1112 msgFlags = m_errorMonitor->GetState(&msgString);
1113 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
1114 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1115 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
1116 }
1117}
1118
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001119TEST_F(VkLayerTest, BlendStateNotBound)
1120{
1121 VkFlags msgFlags;
1122 std::string msgString;
1123 m_errorMonitor->ClearState();
1124 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1125
1126 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1127
1128 msgFlags = m_errorMonitor->GetState(&msgString);
1129 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Blend State Object";
1130 if (!strstr(msgString.c_str(),"Dynamic blend object state not set for this command buffer")) {
1131 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic blend object state not set for this command buffer'";
1132 }
1133}
1134
1135TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1136{
1137 VkFlags msgFlags;
1138 std::string msgString;
1139 m_errorMonitor->ClearState();
1140 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1141
1142 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1143
1144 msgFlags = m_errorMonitor->GetState(&msgString);
1145 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bounds State Object";
1146 if (!strstr(msgString.c_str(),"Dynamic depth bounds state not set for this command buffer")) {
1147 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bounds state not set for this command buffer'";
1148 }
1149}
1150
1151TEST_F(VkLayerTest, StencilReadMaskNotSet)
1152{
1153 VkFlags msgFlags;
1154 std::string msgString;
1155 ASSERT_NO_FATAL_FAILURE(InitState());
1156 m_errorMonitor->ClearState();
1157 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1158
1159 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1160
1161 msgFlags = m_errorMonitor->GetState(&msgString);
1162 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Read Mask";
1163 if (!strstr(msgString.c_str(),"Dynamic stencil read mask state not set for this command buffer")) {
1164 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil read mask state not set for this command buffer'";
1165 }
1166}
1167
1168TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1169{
1170 VkFlags msgFlags;
1171 std::string msgString;
1172 ASSERT_NO_FATAL_FAILURE(InitState());
1173 m_errorMonitor->ClearState();
1174 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1175
1176 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1177
1178 msgFlags = m_errorMonitor->GetState(&msgString);
1179 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Write Mask";
1180 if (!strstr(msgString.c_str(),"Dynamic stencil write mask state not set for this command buffer")) {
1181 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil write mask state not set for this command buffer'";
1182 }
1183}
1184
1185TEST_F(VkLayerTest, StencilReferenceNotSet)
1186{
1187 VkFlags msgFlags;
1188 std::string msgString;
1189 m_errorMonitor->ClearState();
1190 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1191
1192 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1193
1194 msgFlags = m_errorMonitor->GetState(&msgString);
1195 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Reference";
1196 if (!strstr(msgString.c_str(),"Dynamic stencil reference state not set for this command buffer")) {
1197 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil reference state not set for this command buffer'";
1198 }
1199}
1200
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001201TEST_F(VkLayerTest, CmdBufferTwoSubmits)
1202{
1203 vk_testing::Fence testFence;
1204 VkFlags msgFlags;
1205 std::string msgString;
1206
1207 VkFenceCreateInfo fenceInfo = {};
1208 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1209 fenceInfo.pNext = NULL;
1210 fenceInfo.flags = 0;
1211
1212 ASSERT_NO_FATAL_FAILURE(InitState());
1213 ASSERT_NO_FATAL_FAILURE(InitViewport());
1214 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1215
1216 // We luck out b/c by default the framework creates CB w/ the VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set
1217 BeginCommandBuffer();
1218 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
1219 EndCommandBuffer();
1220
1221 testFence.init(*m_device, fenceInfo);
1222
1223 // Bypass framework since it does the waits automatically
1224 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06001225 VkSubmitInfo submit_info = {
1226 .waitSemCount = 0,
1227 .pWaitSemaphores = NULL,
1228 .cmdBufferCount = 1,
1229 .pCommandBuffers = &m_cmdBuffer->handle(),
1230 .signalSemCount = 0,
1231 .pSignalSemaphores = NULL
1232 };
1233 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001234 ASSERT_VK_SUCCESS( err );
1235
1236 m_errorMonitor->ClearState();
1237 // Cause validation error by re-submitting cmd buffer that should only be submitted once
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06001238 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001239
1240 msgFlags = m_errorMonitor->GetState(&msgString);
1241 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after re-submitting Command Buffer that was created with one-time submit flag";
Tobin Ehlis7f7b4422015-08-18 14:24:32 -06001242 if (!strstr(msgString.c_str(),"was begun w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set, but has been submitted")) {
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001243 FAIL() << "Error received was not 'CB (0xaddress) was created w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set...'";
1244 }
1245}
1246
Tobin Ehlise4076782015-06-24 15:53:07 -06001247TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001248{
1249 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001250 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001251 std::string msgString;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001252 VkResult err;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001253
1254 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001255 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001256 m_errorMonitor->ClearState();
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001257
1258 VkDescriptorTypeCount ds_type_count = {};
1259 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1260 ds_type_count.count = 1;
1261
1262 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1263 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1264 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001265 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1266 ds_pool_ci.maxSets = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001267 ds_pool_ci.count = 1;
1268 ds_pool_ci.pTypeCount = &ds_type_count;
1269
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001270 VkDescriptorPool ds_pool;
1271 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001272 ASSERT_VK_SUCCESS(err);
1273
1274 VkDescriptorSetLayoutBinding dsl_binding = {};
1275 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1276 dsl_binding.arraySize = 1;
1277 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1278 dsl_binding.pImmutableSamplers = NULL;
1279
1280 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1281 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1282 ds_layout_ci.pNext = NULL;
1283 ds_layout_ci.count = 1;
1284 ds_layout_ci.pBinding = &dsl_binding;
1285
1286 VkDescriptorSetLayout ds_layout;
1287 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1288 ASSERT_VK_SUCCESS(err);
1289
1290 VkDescriptorSet descriptorSet;
1291 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1292 ASSERT_VK_SUCCESS(err);
1293 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1294 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1295 pipe_ms_state_ci.pNext = NULL;
1296 pipe_ms_state_ci.rasterSamples = 1;
1297 pipe_ms_state_ci.sampleShadingEnable = 0;
1298 pipe_ms_state_ci.minSampleShading = 1.0;
1299 pipe_ms_state_ci.pSampleMask = NULL;
1300
1301 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1302 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1303 pipeline_layout_ci.pNext = NULL;
1304 pipeline_layout_ci.descriptorSetCount = 1;
1305 pipeline_layout_ci.pSetLayouts = &ds_layout;
1306 VkPipelineLayout pipeline_layout;
1307
1308 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1309 ASSERT_VK_SUCCESS(err);
1310
1311 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
1312 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1313 // but add it to be able to run on more devices
1314 VkPipelineObj pipe(m_device);
1315 pipe.AddShader(&vs);
1316 pipe.AddShader(&fs);
1317 pipe.SetMSAA(&pipe_ms_state_ci);
1318 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1319 m_errorMonitor->ClearState();
1320 // Calls CreateCommandBuffer
1321 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1322 VkCmdBufferBeginInfo cmd_buf_info = {};
1323 memset(&cmd_buf_info, 0, sizeof(VkCmdBufferBeginInfo));
1324 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1325 cmd_buf_info.pNext = NULL;
1326 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1327 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1328
1329 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1330 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001331 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001332 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 -06001333 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001334 FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0x<handle>) without an active RenderPass' but rather '" << msgString.c_str() << "'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001335 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001336
1337 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001338 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1339 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001340}
1341
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001342TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1343{
1344 // Initiate Draw w/o a PSO bound
1345 VkFlags msgFlags;
1346 std::string msgString;
1347 VkResult err;
1348
1349 ASSERT_NO_FATAL_FAILURE(InitState());
1350 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1351 m_errorMonitor->ClearState();
1352
1353 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
1354 VkDescriptorTypeCount ds_type_count = {};
1355 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
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.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1362 ds_pool_ci.maxSets = 1;
1363 ds_pool_ci.count = 1;
1364 ds_pool_ci.pTypeCount = &ds_type_count;
1365
1366 VkDescriptorPool ds_pool;
1367 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1368 ASSERT_VK_SUCCESS(err);
1369
1370 VkDescriptorSetLayoutBinding dsl_binding = {};
1371 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1372 dsl_binding.arraySize = 1;
1373 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1374 dsl_binding.pImmutableSamplers = NULL;
1375
1376 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1377 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1378 ds_layout_ci.pNext = NULL;
1379 ds_layout_ci.count = 1;
1380 ds_layout_ci.pBinding = &dsl_binding;
1381
1382 VkDescriptorSetLayout ds_layout;
1383 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1384 ASSERT_VK_SUCCESS(err);
1385
1386 VkDescriptorSet descriptorSet;
1387 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1388
1389 msgFlags = m_errorMonitor->GetState(&msgString);
1390 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after alloc descriptor from pool w/o requested type";
1391 if (!strstr(msgString.c_str(),"Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ")) {
1392 FAIL() << "Error received was not 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...' but rather '" << msgString.c_str() << "'";
1393 }
1394
1395 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1396 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1397}
1398
Tobin Ehlis3c543112015-10-08 13:13:50 -06001399TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1400{
1401 VkFlags msgFlags;
1402 std::string msgString;
1403 VkResult err;
1404
1405 ASSERT_NO_FATAL_FAILURE(InitState());
1406 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1407 m_errorMonitor->ClearState();
1408
1409 VkDescriptorTypeCount ds_type_count = {};
1410 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1411 ds_type_count.count = 1;
1412
1413 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1414 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1415 ds_pool_ci.pNext = NULL;
1416 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT; // Can't free from ONE_SHOT Pool
1417 ds_pool_ci.maxSets = 1;
1418 ds_pool_ci.count = 1;
1419 ds_pool_ci.pTypeCount = &ds_type_count;
1420
1421 VkDescriptorPool ds_pool;
1422 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1423 ASSERT_VK_SUCCESS(err);
1424
1425 VkDescriptorSetLayoutBinding dsl_binding = {};
1426 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1427 dsl_binding.arraySize = 1;
1428 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1429 dsl_binding.pImmutableSamplers = NULL;
1430
1431 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1432 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1433 ds_layout_ci.pNext = NULL;
1434 ds_layout_ci.count = 1;
1435 ds_layout_ci.pBinding = &dsl_binding;
1436
1437 VkDescriptorSetLayout ds_layout;
1438 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1439 ASSERT_VK_SUCCESS(err);
1440
1441 VkDescriptorSet descriptorSet;
1442 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1443 ASSERT_VK_SUCCESS(err);
1444
1445 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1446 msgFlags = m_errorMonitor->GetState(&msgString);
1447 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after freeing descriptor from ONE_SHOT Pool";
1448 if (!strstr(msgString.c_str(),"It is invalid to call vkFreeDescriptorSets() with a pool created with usage type VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT.")) {
1449 FAIL() << "Error received was not 'It is invalid to call vkFreeDescriptorSets() with a pool created with...' but instead it was '" << msgString.c_str() << "'";
1450 }
1451
1452 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1453 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1454}
1455
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001456TEST_F(VkLayerTest, InvalidDescriptorPool)
1457{
1458 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1459 // The DS check for this is after driver has been called to validate DS internal data struct
1460 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001461/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001462 std::string msgString;
1463 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1464 vkResetDescriptorPool(device(), badPool);
1465
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001466 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001467 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 -06001468 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1469 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1470 }*/
1471}
1472
1473TEST_F(VkLayerTest, InvalidDescriptorSet)
1474{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001475 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1476 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001477 // Create a valid cmd buffer
1478 // call vkCmdBindDescriptorSets w/ false DS
1479}
1480
1481TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1482{
1483 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1484 // The DS check for this is after driver has been called to validate DS internal data struct
1485}
1486
1487TEST_F(VkLayerTest, InvalidPipeline)
1488{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001489 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1490 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001491 // Create a valid cmd buffer
1492 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -06001493// VkFlags msgFlags;
1494// std::string msgString;
1495//
1496// ASSERT_NO_FATAL_FAILURE(InitState());
1497// m_errorMonitor->ClearState();
1498// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001499// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001500// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1501// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1502// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001503// 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 -06001504// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1505// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1506// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001507}
1508
Tobin Ehlis254eca02015-06-25 15:46:59 -06001509TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001510{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001511 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001512 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001513 std::string msgString;
1514 VkResult err;
1515
1516 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001517 ASSERT_NO_FATAL_FAILURE(InitViewport());
1518 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001519 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001520 VkDescriptorTypeCount ds_type_count = {};
1521 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1522 ds_type_count.count = 1;
1523
1524 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1525 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1526 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001527 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1528 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001529 ds_pool_ci.count = 1;
1530 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001531
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001532 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001533 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001534 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001535
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001536 VkDescriptorSetLayoutBinding dsl_binding = {};
1537 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1538 dsl_binding.arraySize = 1;
1539 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1540 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001541
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001542 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1543 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1544 ds_layout_ci.pNext = NULL;
1545 ds_layout_ci.count = 1;
1546 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001547 VkDescriptorSetLayout ds_layout;
1548 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1549 ASSERT_VK_SUCCESS(err);
1550
1551 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001552 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001553 ASSERT_VK_SUCCESS(err);
1554
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001555 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1556 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1557 pipeline_layout_ci.pNext = NULL;
1558 pipeline_layout_ci.descriptorSetCount = 1;
1559 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001560
1561 VkPipelineLayout pipeline_layout;
1562 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1563 ASSERT_VK_SUCCESS(err);
1564
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001565 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001566 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1567 // but add it to be able to run on more devices
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001568
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001569 VkPipelineObj pipe(m_device);
1570 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001571 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001572 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001573
1574 BeginCommandBuffer();
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001575 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbour1490c912015-07-28 10:17:20 -06001576 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001577
Tobin Ehlis254eca02015-06-25 15:46:59 -06001578 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001579 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 -06001580 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1581 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1582 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001583
1584 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001585 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1586 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001587}
1588
1589TEST_F(VkLayerTest, NoBeginCmdBuffer)
1590{
1591 VkFlags msgFlags;
1592 std::string msgString;
1593
1594 ASSERT_NO_FATAL_FAILURE(InitState());
1595 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001596 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001597 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1598 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1599 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001600 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 -06001601 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1602 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1603 }
1604}
1605
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001606TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1607{
1608 VkFlags msgFlags;
1609 std::string msgString;
1610
1611 ASSERT_NO_FATAL_FAILURE(InitState());
1612 m_errorMonitor->ClearState();
1613
1614 // Calls CreateCommandBuffer
1615 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1616
1617 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northrop10d8f982015-08-04 17:35:57 -06001618 VkCmdBufferBeginInfo cmd_buf_info = {};
1619 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1620 cmd_buf_info.pNext = NULL;
1621 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1622 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1623 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1624 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1625
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001626
1627 // The error should be caught by validation of the BeginCommandBuffer call
1628 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1629
1630 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001631 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 -06001632 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1633 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1634 }
1635}
1636
1637TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1638{
1639 VkFlags msgFlags;
1640 std::string msgString;
1641 VkResult err;
1642 VkCmdBuffer draw_cmd;
1643 VkCmdPool cmd_pool;
1644
1645 ASSERT_NO_FATAL_FAILURE(InitState());
1646 m_errorMonitor->ClearState();
1647
Cody Northrop10d8f982015-08-04 17:35:57 -06001648 VkCmdBufferCreateInfo cmd = {};
1649 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1650 cmd.pNext = NULL;
1651 cmd.cmdPool = m_cmdPool;
1652 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1653 cmd.flags = 0;
1654
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001655 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
Mike Stroyan2237f522015-08-18 14:40:24 -06001656 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001657
1658 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northrop10d8f982015-08-04 17:35:57 -06001659 VkCmdBufferBeginInfo cmd_buf_info = {};
1660 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1661 cmd_buf_info.pNext = NULL;
1662 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1663 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001664
1665 // The error should be caught by validation of the BeginCommandBuffer call
1666 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1667
1668 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001669 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 -06001670 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1671 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1672 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001673 vkDestroyCommandBuffer(m_device->device(), draw_cmd);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001674}
1675
Tobin Ehlis254eca02015-06-25 15:46:59 -06001676TEST_F(VkLayerTest, InvalidPipelineCreateState)
1677{
1678 // Attempt to Create Gfx Pipeline w/o a VS
1679 VkFlags msgFlags;
1680 std::string msgString;
1681 VkResult err;
1682
1683 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001684 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis254eca02015-06-25 15:46:59 -06001685 m_errorMonitor->ClearState();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001686
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001687 VkDescriptorTypeCount ds_type_count = {};
1688 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1689 ds_type_count.count = 1;
1690
1691 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1692 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1693 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001694 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1695 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001696 ds_pool_ci.count = 1;
1697 ds_pool_ci.pTypeCount = &ds_type_count;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001698
Tobin Ehlis254eca02015-06-25 15:46:59 -06001699 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001700 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001701 ASSERT_VK_SUCCESS(err);
1702
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001703 VkDescriptorSetLayoutBinding dsl_binding = {};
1704 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1705 dsl_binding.arraySize = 1;
1706 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1707 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001708
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001709 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1710 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1711 ds_layout_ci.pNext = NULL;
1712 ds_layout_ci.count = 1;
1713 ds_layout_ci.pBinding = &dsl_binding;
1714
Tobin Ehlis254eca02015-06-25 15:46:59 -06001715 VkDescriptorSetLayout ds_layout;
1716 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1717 ASSERT_VK_SUCCESS(err);
1718
1719 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001720 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001721 ASSERT_VK_SUCCESS(err);
1722
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001723 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1724 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001725 pipeline_layout_ci.descriptorSetCount = 1;
1726 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001727
1728 VkPipelineLayout pipeline_layout;
1729 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1730 ASSERT_VK_SUCCESS(err);
1731
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001732 VkViewport vp = {}; // Just need dummy vp to point to
1733 VkRect2D sc = {}; // dummy scissor to point to
1734
1735 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1736 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1737 vp_state_ci.scissorCount = 1;
1738 vp_state_ci.pScissors = &sc;
1739 vp_state_ci.viewportCount = 1;
1740 vp_state_ci.pViewports = &vp;
1741
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001742 VkGraphicsPipelineCreateInfo gp_ci = {};
1743 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001744 gp_ci.pViewportState = &vp_state_ci;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001745 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1746 gp_ci.layout = pipeline_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001747 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001748
1749 VkPipelineCacheCreateInfo pc_ci = {};
1750 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001751 pc_ci.initialSize = 0;
1752 pc_ci.initialData = 0;
1753 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001754
1755 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001756 VkPipelineCache pipelineCache;
1757
1758 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1759 ASSERT_VK_SUCCESS(err);
1760 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001761
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001762 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001763 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o VS.";
Tobin Ehlis254eca02015-06-25 15:46:59 -06001764 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1765 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1766 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001767
1768 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1769 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001770 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1771 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001772}
Tobin Ehlis20693172015-09-17 08:46:18 -06001773/*// TODO : This test should be good, but needs Tess support in compiler to run
1774TEST_F(VkLayerTest, InvalidPatchControlPoints)
1775{
1776 // Attempt to Create Gfx Pipeline w/o a VS
1777 VkFlags msgFlags;
1778 std::string msgString;
1779 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001780
Tobin Ehlis20693172015-09-17 08:46:18 -06001781 ASSERT_NO_FATAL_FAILURE(InitState());
1782 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1783 m_errorMonitor->ClearState();
1784
1785 VkDescriptorTypeCount ds_type_count = {};
1786 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1787 ds_type_count.count = 1;
1788
1789 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1790 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1791 ds_pool_ci.pNext = NULL;
1792 ds_pool_ci.count = 1;
1793 ds_pool_ci.pTypeCount = &ds_type_count;
1794
1795 VkDescriptorPool ds_pool;
1796 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1797 ASSERT_VK_SUCCESS(err);
1798
1799 VkDescriptorSetLayoutBinding dsl_binding = {};
1800 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1801 dsl_binding.arraySize = 1;
1802 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1803 dsl_binding.pImmutableSamplers = NULL;
1804
1805 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1806 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1807 ds_layout_ci.pNext = NULL;
1808 ds_layout_ci.count = 1;
1809 ds_layout_ci.pBinding = &dsl_binding;
1810
1811 VkDescriptorSetLayout ds_layout;
1812 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1813 ASSERT_VK_SUCCESS(err);
1814
1815 VkDescriptorSet descriptorSet;
1816 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1817 ASSERT_VK_SUCCESS(err);
1818
1819 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1820 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1821 pipeline_layout_ci.pNext = NULL;
1822 pipeline_layout_ci.descriptorSetCount = 1;
1823 pipeline_layout_ci.pSetLayouts = &ds_layout;
1824
1825 VkPipelineLayout pipeline_layout;
1826 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1827 ASSERT_VK_SUCCESS(err);
1828
1829 VkPipelineShaderStageCreateInfo shaderStages[3];
1830 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
1831
1832 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
1833 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001834 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL, this);
1835 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06001836
1837 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1838 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
1839 shaderStages[0].shader = vs.handle();
1840 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001841 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL;
Tobin Ehlis20693172015-09-17 08:46:18 -06001842 shaderStages[1].shader = tc.handle();
1843 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001844 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION;
Tobin Ehlis20693172015-09-17 08:46:18 -06001845 shaderStages[2].shader = te.handle();
1846
1847 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
1848 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
1849 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH;
1850
1851 VkPipelineTessellationStateCreateInfo tsCI = {};
1852 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
1853 tsCI.patchControlPoints = 0; // This will cause an error
1854
1855 VkGraphicsPipelineCreateInfo gp_ci = {};
1856 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1857 gp_ci.pNext = NULL;
1858 gp_ci.stageCount = 3;
1859 gp_ci.pStages = shaderStages;
1860 gp_ci.pVertexInputState = NULL;
1861 gp_ci.pInputAssemblyState = &iaCI;
1862 gp_ci.pTessellationState = &tsCI;
1863 gp_ci.pViewportState = NULL;
1864 gp_ci.pRasterState = NULL;
1865 gp_ci.pMultisampleState = NULL;
1866 gp_ci.pDepthStencilState = NULL;
1867 gp_ci.pColorBlendState = NULL;
1868 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1869 gp_ci.layout = pipeline_layout;
1870 gp_ci.renderPass = renderPass();
1871
1872 VkPipelineCacheCreateInfo pc_ci = {};
1873 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1874 pc_ci.pNext = NULL;
1875 pc_ci.initialSize = 0;
1876 pc_ci.initialData = 0;
1877 pc_ci.maxSize = 0;
1878
1879 VkPipeline pipeline;
1880 VkPipelineCache pipelineCache;
1881
1882 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1883 ASSERT_VK_SUCCESS(err);
1884 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1885
1886 msgFlags = m_errorMonitor->GetState(&msgString);
1887 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Tess Gfx Pipeline w/ 0 patchControlPoints.";
1888 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ")) {
1889 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...' but instead '" << msgString.c_str() << "'";
1890 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001891
1892 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1893 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001894 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1895 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis20693172015-09-17 08:46:18 -06001896}
1897*/
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001898// Set scissor and viewport counts to different numbers
1899TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
1900{
1901 // Attempt to Create Gfx Pipeline w/o a VS
1902 VkFlags msgFlags;
1903 std::string msgString;
1904 VkResult err;
1905
1906 ASSERT_NO_FATAL_FAILURE(InitState());
1907 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1908 m_errorMonitor->ClearState();
1909
1910 VkDescriptorTypeCount ds_type_count = {};
1911 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1912 ds_type_count.count = 1;
1913
1914 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1915 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1916 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1917 ds_pool_ci.maxSets = 1;
1918 ds_pool_ci.count = 1;
1919 ds_pool_ci.pTypeCount = &ds_type_count;
1920
1921 VkDescriptorPool ds_pool;
1922 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1923 ASSERT_VK_SUCCESS(err);
1924
1925 VkDescriptorSetLayoutBinding dsl_binding = {};
1926 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1927 dsl_binding.arraySize = 1;
1928 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1929
1930 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1931 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1932 ds_layout_ci.count = 1;
1933 ds_layout_ci.pBinding = &dsl_binding;
1934
1935 VkDescriptorSetLayout ds_layout;
1936 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1937 ASSERT_VK_SUCCESS(err);
1938
1939 VkDescriptorSet descriptorSet;
1940 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1941 ASSERT_VK_SUCCESS(err);
1942
1943 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1944 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1945 pipeline_layout_ci.descriptorSetCount = 1;
1946 pipeline_layout_ci.pSetLayouts = &ds_layout;
1947
1948 VkPipelineLayout pipeline_layout;
1949 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1950 ASSERT_VK_SUCCESS(err);
1951
1952 VkViewport vp = {}; // Just need dummy vp to point to
1953
1954 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1955 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1956 vp_state_ci.scissorCount = 0;
1957 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
1958 vp_state_ci.pViewports = &vp;
1959
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001960 VkPipelineShaderStageCreateInfo shaderStages[2];
1961 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001962
1963 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001964 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1965 // but add it to be able to run on more devices
1966 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1967 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
1968 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001969
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001970 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1971 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT;
1972 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001973
1974 VkGraphicsPipelineCreateInfo gp_ci = {};
1975 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001976 gp_ci.stageCount = 2;
1977 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001978 gp_ci.pViewportState = &vp_state_ci;
1979 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1980 gp_ci.layout = pipeline_layout;
1981 gp_ci.renderPass = renderPass();
1982
1983 VkPipelineCacheCreateInfo pc_ci = {};
1984 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1985
1986 VkPipeline pipeline;
1987 VkPipelineCache pipelineCache;
1988
1989 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1990 ASSERT_VK_SUCCESS(err);
1991 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1992
1993 msgFlags = m_errorMonitor->GetState(&msgString);
1994 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/ viewport and scissor count mismatch.";
1995 if (!strstr(msgString.c_str(),"Gfx Pipeline viewport count (1) must match scissor count (0).")) {
1996 FAIL() << "Error received was not 'Gfx Pipeline viewport count (1) must match scissor count (0).' but instead it was '" << msgString.c_str() << "'";
1997 }
1998
1999 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2000 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002001 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2002 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2003}
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002004// Don't set viewport state in PSO. This is an error b/c we always need this state
2005// for the counts even if the data is going to be set dynamically.
2006TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002007{
2008 // Attempt to Create Gfx Pipeline w/o a VS
2009 VkFlags msgFlags;
2010 std::string msgString;
2011 VkResult err;
2012
2013 ASSERT_NO_FATAL_FAILURE(InitState());
2014 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2015 m_errorMonitor->ClearState();
2016
2017 VkDescriptorTypeCount ds_type_count = {};
2018 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2019 ds_type_count.count = 1;
2020
2021 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2022 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2023 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2024 ds_pool_ci.maxSets = 1;
2025 ds_pool_ci.count = 1;
2026 ds_pool_ci.pTypeCount = &ds_type_count;
2027
2028 VkDescriptorPool ds_pool;
2029 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2030 ASSERT_VK_SUCCESS(err);
2031
2032 VkDescriptorSetLayoutBinding dsl_binding = {};
2033 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2034 dsl_binding.arraySize = 1;
2035 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2036
2037 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2038 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2039 ds_layout_ci.count = 1;
2040 ds_layout_ci.pBinding = &dsl_binding;
2041
2042 VkDescriptorSetLayout ds_layout;
2043 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2044 ASSERT_VK_SUCCESS(err);
2045
2046 VkDescriptorSet descriptorSet;
2047 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
2048 ASSERT_VK_SUCCESS(err);
2049
2050 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2051 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2052 pipeline_layout_ci.descriptorSetCount = 1;
2053 pipeline_layout_ci.pSetLayouts = &ds_layout;
2054
2055 VkPipelineLayout pipeline_layout;
2056 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2057 ASSERT_VK_SUCCESS(err);
2058
2059 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2060 // Set scissor as dynamic to avoid second error
2061 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2062 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2063 dyn_state_ci.dynamicStateCount = 1;
2064 dyn_state_ci.pDynamicStates = &sc_state;
2065
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002066 VkPipelineShaderStageCreateInfo shaderStages[2];
2067 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002068
2069 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002070 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2071 // but add it to be able to run on more devices
2072 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2073 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
2074 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002075
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002076 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2077 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT;
2078 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002079
2080 VkGraphicsPipelineCreateInfo gp_ci = {};
2081 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002082 gp_ci.stageCount = 2;
2083 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002084 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2085 gp_ci.pDynamicState = &dyn_state_ci;
2086 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2087 gp_ci.layout = pipeline_layout;
2088 gp_ci.renderPass = renderPass();
2089
2090 VkPipelineCacheCreateInfo pc_ci = {};
2091 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2092
2093 VkPipeline pipeline;
2094 VkPipelineCache pipelineCache;
2095
2096 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2097 ASSERT_VK_SUCCESS(err);
2098 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2099
2100 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002101 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o viewport state set.";
2102 if (!strstr(msgString.c_str(),"Gfx Pipeline pViewportState is null. Even if ")) {
2103 FAIL() << "Error received was not 'Gfx Pipeline pViewportState is null. Even if...' but instead it was '" << msgString.c_str() << "'";
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002104 }
2105
2106 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2107 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002108 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2109 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2110}
2111// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002112// Then run second test where dynamic scissor count doesn't match PSO scissor count
2113TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002114{
2115 VkFlags msgFlags;
2116 std::string msgString;
2117 VkResult err;
2118
2119 ASSERT_NO_FATAL_FAILURE(InitState());
2120 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2121 m_errorMonitor->ClearState();
2122
2123 VkDescriptorTypeCount ds_type_count = {};
2124 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2125 ds_type_count.count = 1;
2126
2127 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2128 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2129 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2130 ds_pool_ci.maxSets = 1;
2131 ds_pool_ci.count = 1;
2132 ds_pool_ci.pTypeCount = &ds_type_count;
2133
2134 VkDescriptorPool ds_pool;
2135 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2136 ASSERT_VK_SUCCESS(err);
2137
2138 VkDescriptorSetLayoutBinding dsl_binding = {};
2139 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2140 dsl_binding.arraySize = 1;
2141 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2142
2143 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2144 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2145 ds_layout_ci.count = 1;
2146 ds_layout_ci.pBinding = &dsl_binding;
2147
2148 VkDescriptorSetLayout ds_layout;
2149 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2150 ASSERT_VK_SUCCESS(err);
2151
2152 VkDescriptorSet descriptorSet;
2153 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
2154 ASSERT_VK_SUCCESS(err);
2155
2156 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2157 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2158 pipeline_layout_ci.descriptorSetCount = 1;
2159 pipeline_layout_ci.pSetLayouts = &ds_layout;
2160
2161 VkPipelineLayout pipeline_layout;
2162 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2163 ASSERT_VK_SUCCESS(err);
2164
2165 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2166 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2167 vp_state_ci.viewportCount = 1;
2168 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2169 vp_state_ci.scissorCount = 1;
2170 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2171
2172 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2173 // Set scissor as dynamic to avoid that error
2174 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2175 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2176 dyn_state_ci.dynamicStateCount = 1;
2177 dyn_state_ci.pDynamicStates = &sc_state;
2178
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002179 VkPipelineShaderStageCreateInfo shaderStages[2];
2180 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002181
2182 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002183 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2184 // but add it to be able to run on more devices
2185 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2186 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
2187 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002188
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002189 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2190 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT;
2191 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002192
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002193 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2194 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2195 vi_ci.pNext = nullptr;
2196 vi_ci.bindingCount = 0;
2197 vi_ci.pVertexBindingDescriptions = nullptr;
2198 vi_ci.attributeCount = 0;
2199 vi_ci.pVertexAttributeDescriptions = nullptr;
2200
2201 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2202 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2203 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2204
2205 VkPipelineRasterStateCreateInfo rs_ci = {};
2206 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2207 rs_ci.pNext = nullptr;
2208
2209 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2210 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2211 cb_ci.pNext = nullptr;
2212
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002213 VkGraphicsPipelineCreateInfo gp_ci = {};
2214 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002215 gp_ci.stageCount = 2;
2216 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002217 gp_ci.pVertexInputState = &vi_ci;
2218 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002219 gp_ci.pViewportState = &vp_state_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002220 gp_ci.pRasterState = &rs_ci;
2221 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002222 gp_ci.pDynamicState = &dyn_state_ci;
2223 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2224 gp_ci.layout = pipeline_layout;
2225 gp_ci.renderPass = renderPass();
2226
2227 VkPipelineCacheCreateInfo pc_ci = {};
2228 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2229
2230 VkPipeline pipeline;
2231 VkPipelineCache pipelineCache;
2232
2233 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2234 ASSERT_VK_SUCCESS(err);
2235 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2236
2237 msgFlags = m_errorMonitor->GetState(&msgString);
2238 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2239 if (!strstr(msgString.c_str(),"Gfx Pipeline viewportCount is 1, but pViewports is NULL. ")) {
2240 FAIL() << "Error received was not 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...' but instead it was '" << msgString.c_str() << "'";
2241 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002242 m_errorMonitor->ClearState();
2243 // Now hit second fail case where we set scissor w/ different count than PSO
2244 // First need to successfully create the PSO from above by setting pViewports
2245 VkViewport vp = {}; // Just need dummy vp to point to
2246 vp_state_ci.pViewports = &vp;
2247 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2248 ASSERT_VK_SUCCESS(err);
2249 BeginCommandBuffer();
2250 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2251 VkRect2D scissors[2] = {}; // don't care about data
2252 // Count of 2 doesn't match PSO count of 1
2253 vkCmdSetScissor(m_cmdBuffer->GetBufferHandle(), 2, scissors);
2254 Draw(1, 0, 0, 0);
2255
2256 msgFlags = m_errorMonitor->GetState(&msgString);
2257 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic scissorCount different from PSO scissorCount.";
2258 if (!strstr(msgString.c_str(),"Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.")) {
2259 FAIL() << "Error received was not 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...' but instead it was '" << msgString.c_str() << "'";
2260 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002261
2262 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2263 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002264 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2265 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2266}
2267// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002268// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2269TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002270{
2271 VkFlags msgFlags;
2272 std::string msgString;
2273 VkResult err;
2274
2275 ASSERT_NO_FATAL_FAILURE(InitState());
2276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2277 m_errorMonitor->ClearState();
2278
2279 VkDescriptorTypeCount ds_type_count = {};
2280 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2281 ds_type_count.count = 1;
2282
2283 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2284 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2285 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2286 ds_pool_ci.maxSets = 1;
2287 ds_pool_ci.count = 1;
2288 ds_pool_ci.pTypeCount = &ds_type_count;
2289
2290 VkDescriptorPool ds_pool;
2291 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2292 ASSERT_VK_SUCCESS(err);
2293
2294 VkDescriptorSetLayoutBinding dsl_binding = {};
2295 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2296 dsl_binding.arraySize = 1;
2297 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2298
2299 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2300 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2301 ds_layout_ci.count = 1;
2302 ds_layout_ci.pBinding = &dsl_binding;
2303
2304 VkDescriptorSetLayout ds_layout;
2305 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2306 ASSERT_VK_SUCCESS(err);
2307
2308 VkDescriptorSet descriptorSet;
2309 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
2310 ASSERT_VK_SUCCESS(err);
2311
2312 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2313 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2314 pipeline_layout_ci.descriptorSetCount = 1;
2315 pipeline_layout_ci.pSetLayouts = &ds_layout;
2316
2317 VkPipelineLayout pipeline_layout;
2318 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2319 ASSERT_VK_SUCCESS(err);
2320
2321 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2322 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2323 vp_state_ci.scissorCount = 1;
2324 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2325 vp_state_ci.viewportCount = 1;
2326 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2327
2328 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2329 // Set scissor as dynamic to avoid that error
2330 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2331 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2332 dyn_state_ci.dynamicStateCount = 1;
2333 dyn_state_ci.pDynamicStates = &vp_state;
2334
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002335 VkPipelineShaderStageCreateInfo shaderStages[2];
2336 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002337
2338 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002339 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2340 // but add it to be able to run on more devices
2341 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2342 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
2343 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002344
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002345 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2346 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT;
2347 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002348
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002349 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2350 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2351 vi_ci.pNext = nullptr;
2352 vi_ci.bindingCount = 0;
2353 vi_ci.pVertexBindingDescriptions = nullptr;
2354 vi_ci.attributeCount = 0;
2355 vi_ci.pVertexAttributeDescriptions = nullptr;
2356
2357 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2358 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2359 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2360
2361 VkPipelineRasterStateCreateInfo rs_ci = {};
2362 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2363 rs_ci.pNext = nullptr;
2364
2365 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2366 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2367 cb_ci.pNext = nullptr;
2368
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002369 VkGraphicsPipelineCreateInfo gp_ci = {};
2370 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002371 gp_ci.stageCount = 2;
2372 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002373 gp_ci.pVertexInputState = &vi_ci;
2374 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002375 gp_ci.pViewportState = &vp_state_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002376 gp_ci.pRasterState = &rs_ci;
2377 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002378 gp_ci.pDynamicState = &dyn_state_ci;
2379 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2380 gp_ci.layout = pipeline_layout;
2381 gp_ci.renderPass = renderPass();
2382
2383 VkPipelineCacheCreateInfo pc_ci = {};
2384 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2385
2386 VkPipeline pipeline;
2387 VkPipelineCache pipelineCache;
2388
2389 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2390 ASSERT_VK_SUCCESS(err);
2391 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2392
2393 msgFlags = m_errorMonitor->GetState(&msgString);
2394 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2395 if (!strstr(msgString.c_str(),"Gfx Pipeline scissorCount is 1, but pScissors is NULL. ")) {
2396 FAIL() << "Error received was not 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...' but instead it was '" << msgString.c_str() << "'";
2397 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002398 m_errorMonitor->ClearState();
2399 // Now hit second fail case where we set scissor w/ different count than PSO
2400 // First need to successfully create the PSO from above by setting pViewports
2401 VkRect2D sc = {}; // Just need dummy vp to point to
2402 vp_state_ci.pScissors = &sc;
2403 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2404 ASSERT_VK_SUCCESS(err);
2405 BeginCommandBuffer();
2406 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2407 VkViewport viewports[2] = {}; // don't care about data
2408 // Count of 2 doesn't match PSO count of 1
2409 vkCmdSetViewport(m_cmdBuffer->GetBufferHandle(), 2, viewports);
2410 Draw(1, 0, 0, 0);
2411
2412 msgFlags = m_errorMonitor->GetState(&msgString);
2413 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic viewportCount different from PSO viewportCount.";
2414 if (!strstr(msgString.c_str(),"Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.")) {
2415 FAIL() << "Error received was not 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...' but instead it was '" << msgString.c_str() << "'";
2416 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002417
2418 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2419 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002420 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2421 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2422}
2423
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002424TEST_F(VkLayerTest, NullRenderPass)
2425{
2426 // Bind a NULL RenderPass
2427 VkFlags msgFlags;
2428 std::string msgString;
2429
2430 ASSERT_NO_FATAL_FAILURE(InitState());
2431 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2432 m_errorMonitor->ClearState();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002433
Tony Barbour1490c912015-07-28 10:17:20 -06002434 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002435 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06002436 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002437
2438 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002439 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002440 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
2441 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
2442 }
2443}
2444
Tobin Ehlis254eca02015-06-25 15:46:59 -06002445TEST_F(VkLayerTest, RenderPassWithinRenderPass)
2446{
2447 // Bind a BeginRenderPass within an active RenderPass
2448 VkFlags msgFlags;
2449 std::string msgString;
2450
2451 ASSERT_NO_FATAL_FAILURE(InitState());
2452 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2453 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06002454
Tony Barbour1490c912015-07-28 10:17:20 -06002455 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002456 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002457 VkRenderPassBeginInfo rp_begin = {};
2458 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
2459 rp_begin.pNext = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002460 rp_begin.renderPass = renderPass();
2461 rp_begin.framebuffer = framebuffer();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002462
Tony Barbour1490c912015-07-28 10:17:20 -06002463 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002464
2465 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002466 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding RenderPass w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002467 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2468 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002469 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002470}
2471
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002472TEST_F(VkLayerTest, FillBufferWithinRenderPass)
2473{
2474 // Call CmdFillBuffer within an active renderpass
2475 VkFlags msgFlags;
2476 std::string msgString;
2477
2478 ASSERT_NO_FATAL_FAILURE(InitState());
2479 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2480 m_errorMonitor->ClearState();
2481
2482 // Renderpass is started here
2483 BeginCommandBuffer();
2484
2485 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2486 vk_testing::Buffer destBuffer;
2487 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
2488
2489 m_cmdBuffer->FillBuffer(destBuffer.handle(), 0, 4, 0x11111111);
2490
2491 msgFlags = m_errorMonitor->GetState(&msgString);
2492 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2493 "Did not receive error after calling CmdFillBuffer w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002494 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2495 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002496 }
2497}
2498
2499TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
2500{
2501 // Call CmdUpdateBuffer within an active renderpass
2502 VkFlags msgFlags;
2503 std::string msgString;
2504
2505 ASSERT_NO_FATAL_FAILURE(InitState());
2506 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2507 m_errorMonitor->ClearState();
2508
2509 // Renderpass is started here
2510 BeginCommandBuffer();
2511
2512 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2513 vk_testing::Buffer destBuffer;
2514 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
2515
2516 VkDeviceSize destOffset = 0;
2517 VkDeviceSize dataSize = 1024;
2518 const uint32_t *pData = NULL;
2519
2520 vkCmdUpdateBuffer(m_cmdBuffer->GetBufferHandle(), destBuffer.handle(), destOffset, dataSize, pData);
2521
2522 msgFlags = m_errorMonitor->GetState(&msgString);
2523 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2524 "Did not receive error after calling CmdUpdateBuffer w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002525 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2526 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002527 }
2528}
2529
2530TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
2531{
2532 // Call CmdClearColorImage within an active RenderPass
2533 VkFlags msgFlags;
2534 std::string msgString;
2535
2536 ASSERT_NO_FATAL_FAILURE(InitState());
2537 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2538 m_errorMonitor->ClearState();
2539
2540 // Renderpass is started here
2541 BeginCommandBuffer();
2542
2543 VkClearColorValue clear_color = {0};
2544 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2545 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2546 const int32_t tex_width = 32;
2547 const int32_t tex_height = 32;
2548 VkImageCreateInfo image_create_info = {};
2549 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2550 image_create_info.pNext = NULL;
2551 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2552 image_create_info.format = tex_format;
2553 image_create_info.extent.width = tex_width;
2554 image_create_info.extent.height = tex_height;
2555 image_create_info.extent.depth = 1;
2556 image_create_info.mipLevels = 1;
2557 image_create_info.arraySize = 1;
2558 image_create_info.samples = 1;
2559 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2560 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2561
2562 vk_testing::Image destImage;
2563 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
2564
2565 const VkImageSubresourceRange range =
2566 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
2567
2568 vkCmdClearColorImage(m_cmdBuffer->GetBufferHandle(),
2569 destImage.handle(),
2570 VK_IMAGE_LAYOUT_GENERAL,
2571 &clear_color,
2572 1,
2573 &range);
2574
2575 msgFlags = m_errorMonitor->GetState(&msgString);
2576 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2577 "Did not receive error after calling CmdClearColorImage w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002578 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2579 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002580 }
2581}
2582
2583TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
2584{
2585 // Call CmdClearDepthStencilImage within an active RenderPass
2586 VkFlags msgFlags;
2587 std::string msgString;
2588
2589 ASSERT_NO_FATAL_FAILURE(InitState());
2590 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2591 m_errorMonitor->ClearState();
2592
2593 // Renderpass is started here
2594 BeginCommandBuffer();
2595
2596 VkClearDepthStencilValue clear_value = {0};
2597 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2598 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
2599 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2600 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
2601 image_create_info.extent.width = 64;
2602 image_create_info.extent.height = 64;
2603 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2604 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
2605
2606 vk_testing::Image destImage;
2607 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
2608
2609 const VkImageSubresourceRange range =
2610 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
2611
2612 vkCmdClearDepthStencilImage(m_cmdBuffer->GetBufferHandle(),
2613 destImage.handle(),
2614 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2615 &clear_value,
2616 1,
2617 &range);
2618
2619 msgFlags = m_errorMonitor->GetState(&msgString);
2620 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2621 "Did not receive error after calling CmdClearDepthStencilImage w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002622 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2623 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002624 }
2625}
2626
2627TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
2628{
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002629 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002630 VkFlags msgFlags;
2631 std::string msgString;
2632 VkResult err;
2633
2634 ASSERT_NO_FATAL_FAILURE(InitState());
2635 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2636 m_errorMonitor->ClearState();
2637
2638 // Start no RenderPass
2639 err = m_cmdBuffer->BeginCommandBuffer();
2640 ASSERT_VK_SUCCESS(err);
2641
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002642 VkClearAttachment color_attachment;
2643 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2644 color_attachment.clearValue.color.float32[0] = 0;
2645 color_attachment.clearValue.color.float32[1] = 0;
2646 color_attachment.clearValue.color.float32[2] = 0;
2647 color_attachment.clearValue.color.float32[3] = 0;
2648 color_attachment.colorAttachment = 0;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002649 VkRect3D clear_rect = { { 0, 0, 0 }, { 32, 32, 1 } };
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002650 vkCmdClearAttachments(m_cmdBuffer->GetBufferHandle(),
2651 1, &color_attachment,
2652 1, &clear_rect);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002653
2654 msgFlags = m_errorMonitor->GetState(&msgString);
2655 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002656 "Did not receive error after calling CmdClearAttachments outside of an active RenderPass.";
2657 if (!strstr(msgString.c_str(),"vkCmdClearAttachments: This call must be issued inside an active render pass")) {
2658 FAIL() << "Error received was not 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002659 }
2660}
2661
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002662TEST_F(VkLayerTest, InvalidDynamicStateObject)
2663{
2664 // Create a valid cmd buffer
2665 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002666 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
2667 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002668}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06002669
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002670TEST_F(VkLayerTest, IdxBufferAlignmentError)
2671{
2672 // Bind a BeginRenderPass within an active RenderPass
2673 VkFlags msgFlags;
2674 std::string msgString;
2675 VkResult err;
2676
2677 ASSERT_NO_FATAL_FAILURE(InitState());
2678 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2679 m_errorMonitor->ClearState();
2680 uint32_t qfi = 0;
2681 VkBufferCreateInfo buffCI = {};
2682 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2683 buffCI.size = 1024;
2684 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
2685 buffCI.queueFamilyCount = 1;
2686 buffCI.pQueueFamilyIndices = &qfi;
2687
2688 VkBuffer ib;
2689 err = vkCreateBuffer(m_device->device(), &buffCI, &ib);
2690 ASSERT_VK_SUCCESS(err);
2691
2692 BeginCommandBuffer();
2693 ASSERT_VK_SUCCESS(err);
2694 //vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2695 // Should error before calling to driver so don't care about actual data
2696 vkCmdBindIndexBuffer(m_cmdBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
2697
2698 msgFlags = m_errorMonitor->GetState(&msgString);
2699 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2700 if (!strstr(msgString.c_str(),"vkCmdBindIndexBuffer() offset (0x7) does not fall on ")) {
2701 FAIL() << "Error received was not 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...' but instead '" << msgString.c_str() << "'";
2702 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002703
2704 vkDestroyBuffer(m_device->device(), ib);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002705}
2706
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002707TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
2708{
2709 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
2710 VkFlags msgFlags;
2711 std::string msgString;
2712
2713 ASSERT_NO_FATAL_FAILURE(InitState());
2714 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2715 m_errorMonitor->ClearState();
2716
2717 BeginCommandBuffer();
2718 //ASSERT_VK_SUCCESS(err);
2719 VkCmdBuffer primCB = m_cmdBuffer->GetBufferHandle();
2720 vkCmdExecuteCommands(m_cmdBuffer->GetBufferHandle(), 1, &primCB);
2721
2722 msgFlags = m_errorMonitor->GetState(&msgString);
2723 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2724 if (!strstr(msgString.c_str(),"vkCmdExecuteCommands() called w/ Primary Cmd Buffer ")) {
2725 FAIL() << "Error received was not 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer ' but instead '" << msgString.c_str() << "'";
2726 }
2727}
2728
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002729TEST_F(VkLayerTest, DSTypeMismatch)
2730{
2731 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002732 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002733 std::string msgString;
2734 VkResult err;
2735
2736 ASSERT_NO_FATAL_FAILURE(InitState());
2737 m_errorMonitor->ClearState();
2738 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002739 VkDescriptorTypeCount ds_type_count = {};
2740 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2741 ds_type_count.count = 1;
2742
2743 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2744 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2745 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002746 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2747 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002748 ds_pool_ci.count = 1;
2749 ds_pool_ci.pTypeCount = &ds_type_count;
2750
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002751 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002752 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002753 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002754 VkDescriptorSetLayoutBinding dsl_binding = {};
2755 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2756 dsl_binding.arraySize = 1;
2757 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2758 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002759
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002760 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2761 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2762 ds_layout_ci.pNext = NULL;
2763 ds_layout_ci.count = 1;
2764 ds_layout_ci.pBinding = &dsl_binding;
2765
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002766 VkDescriptorSetLayout ds_layout;
2767 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2768 ASSERT_VK_SUCCESS(err);
2769
2770 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002771 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002772 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002773
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002774 VkSamplerCreateInfo sampler_ci = {};
2775 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2776 sampler_ci.pNext = NULL;
2777 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2778 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2779 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002780 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2781 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2782 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002783 sampler_ci.mipLodBias = 1.0;
2784 sampler_ci.maxAnisotropy = 1;
2785 sampler_ci.compareEnable = VK_FALSE;
2786 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2787 sampler_ci.minLod = 1.0;
2788 sampler_ci.maxLod = 1.0;
2789 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002790 sampler_ci.unnormalizedCoordinates = VK_FALSE;
2791
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002792 VkSampler sampler;
2793 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2794 ASSERT_VK_SUCCESS(err);
2795
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002796 VkDescriptorInfo descriptor_info;
2797 memset(&descriptor_info, 0, sizeof(descriptor_info));
2798 descriptor_info.sampler = sampler;
2799
2800 VkWriteDescriptorSet descriptor_write;
2801 memset(&descriptor_write, 0, sizeof(descriptor_write));
2802 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2803 descriptor_write.destSet = descriptorSet;
2804 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002805 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002806 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2807 descriptor_write.pDescriptors = &descriptor_info;
2808
2809 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2810
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002811 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002812 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating BUFFER Descriptor w/ incorrect type of SAMPLER.";
Tobin Ehlis3b341092015-09-30 08:30:20 -06002813 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match ")) {
2814 FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET has descriptor type VK_DESCRIPTOR_TYPE_SAMPLER that does not match...' but instead '" << msgString.c_str() << "'";
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002815 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002816
2817 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06002818 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2819 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002820}
2821
2822TEST_F(VkLayerTest, DSUpdateOutOfBounds)
2823{
2824 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002825 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002826 std::string msgString;
2827 VkResult err;
2828
2829 ASSERT_NO_FATAL_FAILURE(InitState());
2830 m_errorMonitor->ClearState();
2831 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002832 VkDescriptorTypeCount ds_type_count = {};
2833 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2834 ds_type_count.count = 1;
2835
2836 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2837 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2838 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002839 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2840 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002841 ds_pool_ci.count = 1;
2842 ds_pool_ci.pTypeCount = &ds_type_count;
2843
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002844 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002845 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002846 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002847
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002848 VkDescriptorSetLayoutBinding dsl_binding = {};
2849 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2850 dsl_binding.arraySize = 1;
2851 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2852 dsl_binding.pImmutableSamplers = NULL;
2853
2854 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2855 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2856 ds_layout_ci.pNext = NULL;
2857 ds_layout_ci.count = 1;
2858 ds_layout_ci.pBinding = &dsl_binding;
2859
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002860 VkDescriptorSetLayout ds_layout;
2861 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2862 ASSERT_VK_SUCCESS(err);
2863
2864 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002865 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002866 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002867
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002868 VkSamplerCreateInfo sampler_ci = {};
2869 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2870 sampler_ci.pNext = NULL;
2871 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2872 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2873 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002874 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2875 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2876 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002877 sampler_ci.mipLodBias = 1.0;
2878 sampler_ci.maxAnisotropy = 1;
2879 sampler_ci.compareEnable = VK_FALSE;
2880 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2881 sampler_ci.minLod = 1.0;
2882 sampler_ci.maxLod = 1.0;
2883 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002884 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002885
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002886 VkSampler sampler;
2887 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2888 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002889
2890 VkDescriptorInfo descriptor_info;
2891 memset(&descriptor_info, 0, sizeof(descriptor_info));
2892 descriptor_info.sampler = sampler;
2893
2894 VkWriteDescriptorSet descriptor_write;
2895 memset(&descriptor_write, 0, sizeof(descriptor_write));
2896 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2897 descriptor_write.destSet = descriptorSet;
2898 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
2899 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002900 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002901 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2902 descriptor_write.pDescriptors = &descriptor_info;
2903
2904 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2905
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002906 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002907 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 +08002908 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
2909 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 -06002910 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002911
2912 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06002913 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2914 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002915}
2916
2917TEST_F(VkLayerTest, InvalidDSUpdateIndex)
2918{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002919 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002920 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002921 std::string msgString;
2922 VkResult err;
2923
2924 ASSERT_NO_FATAL_FAILURE(InitState());
2925 m_errorMonitor->ClearState();
2926 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002927 VkDescriptorTypeCount ds_type_count = {};
2928 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2929 ds_type_count.count = 1;
2930
2931 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2932 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2933 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002934 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2935 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002936 ds_pool_ci.count = 1;
2937 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002938
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002939 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002940 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002941 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002942
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002943 VkDescriptorSetLayoutBinding dsl_binding = {};
2944 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2945 dsl_binding.arraySize = 1;
2946 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2947 dsl_binding.pImmutableSamplers = NULL;
2948
2949 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2950 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2951 ds_layout_ci.pNext = NULL;
2952 ds_layout_ci.count = 1;
2953 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002954 VkDescriptorSetLayout ds_layout;
2955 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2956 ASSERT_VK_SUCCESS(err);
2957
2958 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002959 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002960 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002961
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002962 VkSamplerCreateInfo sampler_ci = {};
2963 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2964 sampler_ci.pNext = NULL;
2965 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2966 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2967 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002968 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2969 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2970 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002971 sampler_ci.mipLodBias = 1.0;
2972 sampler_ci.maxAnisotropy = 1;
2973 sampler_ci.compareEnable = VK_FALSE;
2974 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2975 sampler_ci.minLod = 1.0;
2976 sampler_ci.maxLod = 1.0;
2977 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002978 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002979
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002980 VkSampler sampler;
2981 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2982 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002983
2984 VkDescriptorInfo descriptor_info;
2985 memset(&descriptor_info, 0, sizeof(descriptor_info));
2986 descriptor_info.sampler = sampler;
2987
2988 VkWriteDescriptorSet descriptor_write;
2989 memset(&descriptor_write, 0, sizeof(descriptor_write));
2990 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2991 descriptor_write.destSet = descriptorSet;
2992 descriptor_write.destBinding = 2;
2993 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002994 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002995 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2996 descriptor_write.pDescriptors = &descriptor_info;
2997
2998 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2999
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003000 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003001 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 -06003002 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
3003 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
3004 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003005
3006 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06003007 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3008 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003009}
3010
3011TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3012{
3013 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003014 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003015 std::string msgString;
3016 VkResult err;
3017
3018 ASSERT_NO_FATAL_FAILURE(InitState());
3019 m_errorMonitor->ClearState();
3020 //VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003021
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003022 VkDescriptorTypeCount ds_type_count = {};
3023 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3024 ds_type_count.count = 1;
3025
3026 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3027 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3028 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003029 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
3030 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003031 ds_pool_ci.count = 1;
3032 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003033
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003034 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003035 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003036 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003037 VkDescriptorSetLayoutBinding dsl_binding = {};
3038 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3039 dsl_binding.arraySize = 1;
3040 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3041 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003042
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003043 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3044 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3045 ds_layout_ci.pNext = NULL;
3046 ds_layout_ci.count = 1;
3047 ds_layout_ci.pBinding = &dsl_binding;
3048
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003049 VkDescriptorSetLayout ds_layout;
3050 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3051 ASSERT_VK_SUCCESS(err);
3052
3053 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06003054 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003055 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003056
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003057 VkSamplerCreateInfo sampler_ci = {};
3058 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3059 sampler_ci.pNext = NULL;
3060 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
3061 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
3062 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06003063 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
3064 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
3065 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003066 sampler_ci.mipLodBias = 1.0;
3067 sampler_ci.maxAnisotropy = 1;
3068 sampler_ci.compareEnable = VK_FALSE;
3069 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3070 sampler_ci.minLod = 1.0;
3071 sampler_ci.maxLod = 1.0;
3072 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003073 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003074 VkSampler sampler;
3075 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
3076 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003077
3078
3079 VkDescriptorInfo descriptor_info;
3080 memset(&descriptor_info, 0, sizeof(descriptor_info));
3081 descriptor_info.sampler = sampler;
3082
3083 VkWriteDescriptorSet descriptor_write;
3084 memset(&descriptor_write, 0, sizeof(descriptor_write));
3085 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
3086 descriptor_write.destSet = descriptorSet;
3087 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003088 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003089 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3090 descriptor_write.pDescriptors = &descriptor_info;
3091
3092 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3093
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003094 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003095 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 -06003096 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
3097 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
3098 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003099
3100 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06003101 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3102 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003103}
3104
3105TEST_F(VkLayerTest, NumSamplesMismatch)
3106{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003107 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003108 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003109 std::string msgString;
3110 VkResult err;
3111
3112 ASSERT_NO_FATAL_FAILURE(InitState());
3113 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3114 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003115 VkDescriptorTypeCount ds_type_count = {};
3116 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3117 ds_type_count.count = 1;
3118
3119 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003120 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3121 ds_pool_ci.pNext = NULL;
3122 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
3123 ds_pool_ci.maxSets = 1;
3124 ds_pool_ci.count = 1;
3125 ds_pool_ci.pTypeCount = &ds_type_count;
3126
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003127 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003128 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003129 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003130
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003131 VkDescriptorSetLayoutBinding dsl_binding = {};
3132 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3133 dsl_binding.arraySize = 1;
3134 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3135 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003136
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003137 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3138 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3139 ds_layout_ci.pNext = NULL;
3140 ds_layout_ci.count = 1;
3141 ds_layout_ci.pBinding = &dsl_binding;
3142
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003143 VkDescriptorSetLayout ds_layout;
3144 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3145 ASSERT_VK_SUCCESS(err);
3146
3147 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06003148 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003149 ASSERT_VK_SUCCESS(err);
3150
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003151 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3152 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3153 pipe_ms_state_ci.pNext = NULL;
3154 pipe_ms_state_ci.rasterSamples = 4;
3155 pipe_ms_state_ci.sampleShadingEnable = 0;
3156 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003157 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003158
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003159 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3160 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3161 pipeline_layout_ci.pNext = NULL;
3162 pipeline_layout_ci.descriptorSetCount = 1;
3163 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003164
3165 VkPipelineLayout pipeline_layout;
3166 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3167 ASSERT_VK_SUCCESS(err);
3168
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06003169 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003170 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
3171 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003172 VkPipelineObj pipe(m_device);
3173 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003174 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003175 pipe.SetMSAA(&pipe_ms_state_ci);
3176 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003177
Tony Barbour1490c912015-07-28 10:17:20 -06003178 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06003179 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003180
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003181 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003182 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 -06003183 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
3184 FAIL() << "Error received was not 'Num samples mismatch!...'";
3185 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003186
3187 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06003188 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3189 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003190}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003191
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003192TEST_F(VkLayerTest, ClearCmdNoDraw)
3193{
3194 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
3195 VkFlags msgFlags;
3196 std::string msgString;
3197 VkResult err;
3198
3199 ASSERT_NO_FATAL_FAILURE(InitState());
3200 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3201 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003202
3203 VkDescriptorTypeCount ds_type_count = {};
3204 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3205 ds_type_count.count = 1;
3206
3207 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3208 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3209 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003210 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
3211 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003212 ds_pool_ci.count = 1;
3213 ds_pool_ci.pTypeCount = &ds_type_count;
3214
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003215 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003216 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003217 ASSERT_VK_SUCCESS(err);
3218
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003219 VkDescriptorSetLayoutBinding dsl_binding = {};
3220 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3221 dsl_binding.arraySize = 1;
3222 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3223 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003224
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003225 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3226 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3227 ds_layout_ci.pNext = NULL;
3228 ds_layout_ci.count = 1;
3229 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003230
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003231 VkDescriptorSetLayout ds_layout;
3232 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3233 ASSERT_VK_SUCCESS(err);
3234
3235 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06003236 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003237 ASSERT_VK_SUCCESS(err);
3238
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003239 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3240 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3241 pipe_ms_state_ci.pNext = NULL;
3242 pipe_ms_state_ci.rasterSamples = 4;
3243 pipe_ms_state_ci.sampleShadingEnable = 0;
3244 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003245 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003246
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003247 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3248 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3249 pipeline_layout_ci.pNext = NULL;
3250 pipeline_layout_ci.descriptorSetCount = 1;
3251 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003252
3253 VkPipelineLayout pipeline_layout;
3254 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3255 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003256
Tony Barbourd7d828b2015-08-06 10:16:07 -06003257 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003258 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
3259 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003260 VkPipelineObj pipe(m_device);
3261 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003262 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003263 pipe.SetMSAA(&pipe_ms_state_ci);
3264 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003265
3266 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003267
3268 m_errorMonitor->ClearState();
3269 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
3270 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003271 VkClearAttachment color_attachment;
3272 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3273 color_attachment.clearValue.color.float32[0] = 1.0;
3274 color_attachment.clearValue.color.float32[1] = 1.0;
3275 color_attachment.clearValue.color.float32[2] = 1.0;
3276 color_attachment.clearValue.color.float32[3] = 1.0;
3277 color_attachment.colorAttachment = 0;
3278 VkRect3D clear_rect = { { 0, 0, 0 }, { (int)m_width, (int)m_height, 1 } };
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003279
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003280 vkCmdClearAttachments(m_cmdBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003281 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003282 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.";
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003283 if (!strstr(msgString.c_str(),"vkCmdClearAttachments() issued on CB object ")) {
3284 FAIL() << "Error received was not 'vkCmdClearAttachments() issued on CB object...'";
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003285 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003286
3287 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06003288 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3289 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003290}
3291
Tobin Ehlise4076782015-06-24 15:53:07 -06003292TEST_F(VkLayerTest, VtxBufferBadIndex)
3293{
3294 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
3295 VkFlags msgFlags;
3296 std::string msgString;
3297 VkResult err;
3298
3299 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003300 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlise4076782015-06-24 15:53:07 -06003301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3302 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003303
3304 VkDescriptorTypeCount ds_type_count = {};
3305 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3306 ds_type_count.count = 1;
3307
3308 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3309 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3310 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003311 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
3312 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003313 ds_pool_ci.count = 1;
3314 ds_pool_ci.pTypeCount = &ds_type_count;
3315
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003316 VkDescriptorPool ds_pool;
3317 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06003318 ASSERT_VK_SUCCESS(err);
3319
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003320 VkDescriptorSetLayoutBinding dsl_binding = {};
3321 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3322 dsl_binding.arraySize = 1;
3323 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3324 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003325
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003326 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3327 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3328 ds_layout_ci.pNext = NULL;
3329 ds_layout_ci.count = 1;
3330 ds_layout_ci.pBinding = &dsl_binding;
3331
Tobin Ehlise4076782015-06-24 15:53:07 -06003332 VkDescriptorSetLayout ds_layout;
3333 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3334 ASSERT_VK_SUCCESS(err);
3335
3336 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06003337 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06003338 ASSERT_VK_SUCCESS(err);
3339
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003340 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3341 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3342 pipe_ms_state_ci.pNext = NULL;
3343 pipe_ms_state_ci.rasterSamples = 1;
3344 pipe_ms_state_ci.sampleShadingEnable = 0;
3345 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003346 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003347
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003348 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3349 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3350 pipeline_layout_ci.pNext = NULL;
3351 pipeline_layout_ci.descriptorSetCount = 1;
3352 pipeline_layout_ci.pSetLayouts = &ds_layout;
3353 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06003354
Tobin Ehlise4076782015-06-24 15:53:07 -06003355 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3356 ASSERT_VK_SUCCESS(err);
3357
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06003358 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003359 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
3360 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003361 VkPipelineObj pipe(m_device);
3362 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003363 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003364 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003365 pipe.SetViewport(m_viewports);
3366 pipe.SetScissor(m_scissors);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003367 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003368
3369 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06003370 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06003371 // Don't care about actual data, just need to get to draw to flag error
3372 static const float vbo_data[3] = {1.f, 0.f, 1.f};
3373 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
3374 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003375 Draw(1, 0, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06003376
3377 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003378 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding Vtx Buffer w/o VBO attached to PSO.";
Tobin Ehlisd28acef2015-09-09 15:12:35 -06003379 if (!strstr(msgString.c_str(),"Vtx Buffer Index 1 was bound, but no vtx buffers are attached to PSO.")) {
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003380 FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.' but instead was '" << msgString.c_str() << "'";
Tobin Ehlise4076782015-06-24 15:53:07 -06003381 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003382
3383 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06003384 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3385 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06003386}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003387#endif // DRAW_STATE_TESTS
3388
Tobin Ehlis57e6a612015-05-26 16:11:58 -06003389#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06003390#if GTEST_IS_THREADSAFE
3391struct thread_data_struct {
3392 VkCmdBuffer cmdBuffer;
3393 VkEvent event;
3394 bool bailout;
3395};
3396
3397extern "C" void *AddToCommandBuffer(void *arg)
3398{
3399 struct thread_data_struct *data = (struct thread_data_struct *) arg;
3400 std::string msgString;
3401
3402 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06003403 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06003404 if (data->bailout) {
3405 break;
3406 }
3407 }
3408 return NULL;
3409}
3410
3411TEST_F(VkLayerTest, ThreadCmdBufferCollision)
3412{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003413 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06003414 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003415 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06003416
3417 ASSERT_NO_FATAL_FAILURE(InitState());
3418 ASSERT_NO_FATAL_FAILURE(InitViewport());
3419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3420
Mike Stroyan09aae812015-05-12 16:00:45 -06003421 m_errorMonitor->ClearState();
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003422
3423 // Calls CreateCommandBuffer
3424 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
3425
3426 // Avoid creating RenderPass
3427 cmdBuffer.BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06003428
3429 VkEventCreateInfo event_info;
3430 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06003431 VkResult err;
3432
3433 memset(&event_info, 0, sizeof(event_info));
3434 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3435
3436 err = vkCreateEvent(device(), &event_info, &event);
3437 ASSERT_VK_SUCCESS(err);
3438
Mike Stroyan09aae812015-05-12 16:00:45 -06003439 err = vkResetEvent(device(), event);
3440 ASSERT_VK_SUCCESS(err);
3441
3442 struct thread_data_struct data;
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003443 data.cmdBuffer = cmdBuffer.GetBufferHandle();
Mike Stroyan09aae812015-05-12 16:00:45 -06003444 data.event = event;
3445 data.bailout = false;
3446 m_errorMonitor->SetBailout(&data.bailout);
3447 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003448 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06003449 // Add many entries to command buffer from this thread at the same time.
3450 AddToCommandBuffer(&data);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003451
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003452 test_platform_thread_join(thread, NULL);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003453 cmdBuffer.EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06003454
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003455 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003456 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 -06003457 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05003458 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06003459 }
3460
Mike Stroyan2237f522015-08-18 14:40:24 -06003461 vkDestroyEvent(device(), event);
Mike Stroyan09aae812015-05-12 16:00:45 -06003462}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003463#endif // GTEST_IS_THREADSAFE
3464#endif // THREADING_TESTS
3465
Chris Forbes5af3bf22015-05-25 11:13:08 +12003466#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003467TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
3468{
3469 VkFlags msgFlags;
3470 std::string msgString;
3471 ASSERT_NO_FATAL_FAILURE(InitState());
3472 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3473
3474 m_errorMonitor->ClearState();
3475
3476 VkShaderModule module;
3477 VkShaderModuleCreateInfo moduleCreateInfo;
3478 struct icd_spv_header spv;
3479
3480 spv.magic = ICD_SPV_MAGIC;
3481 spv.version = ICD_SPV_VERSION;
3482 spv.gen_magic = 0;
3483
3484 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3485 moduleCreateInfo.pNext = NULL;
3486 moduleCreateInfo.pCode = &spv;
3487 moduleCreateInfo.codeSize = 4;
3488 moduleCreateInfo.flags = 0;
3489 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3490
3491 msgFlags = m_errorMonitor->GetState(&msgString);
3492
Chris Forbes96b81762015-09-18 11:40:23 +12003493 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003494 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3495 FAIL() << "Incorrect warning: " << msgString;
3496 }
3497}
3498
3499TEST_F(VkLayerTest, InvalidSPIRVMagic)
3500{
3501 VkFlags msgFlags;
3502 std::string msgString;
3503 ASSERT_NO_FATAL_FAILURE(InitState());
3504 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3505
3506 m_errorMonitor->ClearState();
3507
3508 VkShaderModule module;
3509 VkShaderModuleCreateInfo moduleCreateInfo;
3510 struct icd_spv_header spv;
3511
3512 spv.magic = ~ICD_SPV_MAGIC;
3513 spv.version = ICD_SPV_VERSION;
3514 spv.gen_magic = 0;
3515
3516 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3517 moduleCreateInfo.pNext = NULL;
3518 moduleCreateInfo.pCode = &spv;
3519 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3520 moduleCreateInfo.flags = 0;
3521 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3522
3523 msgFlags = m_errorMonitor->GetState(&msgString);
3524
Chris Forbes96b81762015-09-18 11:40:23 +12003525 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003526 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3527 FAIL() << "Incorrect warning: " << msgString;
3528 }
3529}
3530
3531TEST_F(VkLayerTest, InvalidSPIRVVersion)
3532{
3533 VkFlags msgFlags;
3534 std::string msgString;
3535 ASSERT_NO_FATAL_FAILURE(InitState());
3536 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3537
3538 m_errorMonitor->ClearState();
3539
3540 VkShaderModule module;
3541 VkShaderModuleCreateInfo moduleCreateInfo;
3542 struct icd_spv_header spv;
3543
3544 spv.magic = ICD_SPV_MAGIC;
3545 spv.version = ~ICD_SPV_VERSION;
3546 spv.gen_magic = 0;
3547
3548 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3549 moduleCreateInfo.pNext = NULL;
3550
3551 moduleCreateInfo.pCode = &spv;
3552 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3553 moduleCreateInfo.flags = 0;
3554 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3555
3556 msgFlags = m_errorMonitor->GetState(&msgString);
3557
Chris Forbes96b81762015-09-18 11:40:23 +12003558 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003559 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3560 FAIL() << "Incorrect warning: " << msgString;
3561 }
3562}
3563
Chris Forbes5af3bf22015-05-25 11:13:08 +12003564TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
3565{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003566 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12003567 std::string msgString;
3568 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003569 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12003570
3571 char const *vsSource =
3572 "#version 140\n"
3573 "#extension GL_ARB_separate_shader_objects: require\n"
3574 "#extension GL_ARB_shading_language_420pack: require\n"
3575 "\n"
3576 "layout(location=0) out float x;\n"
3577 "void main(){\n"
3578 " gl_Position = vec4(1);\n"
3579 " x = 0;\n"
3580 "}\n";
3581 char const *fsSource =
3582 "#version 140\n"
3583 "#extension GL_ARB_separate_shader_objects: require\n"
3584 "#extension GL_ARB_shading_language_420pack: require\n"
3585 "\n"
3586 "layout(location=0) out vec4 color;\n"
3587 "void main(){\n"
3588 " color = vec4(1);\n"
3589 "}\n";
3590
3591 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3592 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3593
3594 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003595 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12003596 pipe.AddShader(&vs);
3597 pipe.AddShader(&fs);
3598
Chris Forbes5af3bf22015-05-25 11:13:08 +12003599 VkDescriptorSetObj descriptorSet(m_device);
3600 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003601 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003602
3603 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003604 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12003605
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003606 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003607
Cody Northrop1684adb2015-08-05 11:15:02 -06003608 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003609 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
3610 FAIL() << "Incorrect warning: " << msgString;
3611 }
3612}
Chris Forbes5af3bf22015-05-25 11:13:08 +12003613
Chris Forbes3c10b852015-05-25 11:13:13 +12003614TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
3615{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003616 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12003617 std::string msgString;
3618 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003619 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12003620
3621 char const *vsSource =
3622 "#version 140\n"
3623 "#extension GL_ARB_separate_shader_objects: require\n"
3624 "#extension GL_ARB_shading_language_420pack: require\n"
3625 "\n"
3626 "void main(){\n"
3627 " gl_Position = vec4(1);\n"
3628 "}\n";
3629 char const *fsSource =
3630 "#version 140\n"
3631 "#extension GL_ARB_separate_shader_objects: require\n"
3632 "#extension GL_ARB_shading_language_420pack: require\n"
3633 "\n"
3634 "layout(location=0) in float x;\n"
3635 "layout(location=0) out vec4 color;\n"
3636 "void main(){\n"
3637 " color = vec4(x);\n"
3638 "}\n";
3639
3640 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3641 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3642
3643 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003644 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12003645 pipe.AddShader(&vs);
3646 pipe.AddShader(&fs);
3647
Chris Forbes3c10b852015-05-25 11:13:13 +12003648 VkDescriptorSetObj descriptorSet(m_device);
3649 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003650 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12003651
3652 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003653 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12003654
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003655 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12003656
Cody Northrop1684adb2015-08-05 11:15:02 -06003657 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes3c10b852015-05-25 11:13:13 +12003658 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
3659 FAIL() << "Incorrect error: " << msgString;
3660 }
3661}
3662
Chris Forbescc281692015-05-25 11:13:17 +12003663TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
3664{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003665 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12003666 std::string msgString;
3667 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003668 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12003669
3670 char const *vsSource =
3671 "#version 140\n"
3672 "#extension GL_ARB_separate_shader_objects: require\n"
3673 "#extension GL_ARB_shading_language_420pack: require\n"
3674 "\n"
3675 "layout(location=0) out int x;\n"
3676 "void main(){\n"
3677 " x = 0;\n"
3678 " gl_Position = vec4(1);\n"
3679 "}\n";
3680 char const *fsSource =
3681 "#version 140\n"
3682 "#extension GL_ARB_separate_shader_objects: require\n"
3683 "#extension GL_ARB_shading_language_420pack: require\n"
3684 "\n"
3685 "layout(location=0) in float x;\n" /* VS writes int */
3686 "layout(location=0) out vec4 color;\n"
3687 "void main(){\n"
3688 " color = vec4(x);\n"
3689 "}\n";
3690
3691 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3692 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3693
3694 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003695 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12003696 pipe.AddShader(&vs);
3697 pipe.AddShader(&fs);
3698
Chris Forbescc281692015-05-25 11:13:17 +12003699 VkDescriptorSetObj descriptorSet(m_device);
3700 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003701 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12003702
3703 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003704 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12003705
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003706 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12003707
Cody Northrop1684adb2015-08-05 11:15:02 -06003708 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbescc281692015-05-25 11:13:17 +12003709 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
3710 FAIL() << "Incorrect error: " << msgString;
3711 }
3712}
3713
Chris Forbes8291c052015-05-25 11:13:28 +12003714TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
3715{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003716 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12003717 std::string msgString;
3718 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003719 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12003720
3721 VkVertexInputBindingDescription input_binding;
3722 memset(&input_binding, 0, sizeof(input_binding));
3723
3724 VkVertexInputAttributeDescription input_attrib;
3725 memset(&input_attrib, 0, sizeof(input_attrib));
3726 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3727
3728 char const *vsSource =
3729 "#version 140\n"
3730 "#extension GL_ARB_separate_shader_objects: require\n"
3731 "#extension GL_ARB_shading_language_420pack: require\n"
3732 "\n"
3733 "void main(){\n"
3734 " gl_Position = vec4(1);\n"
3735 "}\n";
3736 char const *fsSource =
3737 "#version 140\n"
3738 "#extension GL_ARB_separate_shader_objects: require\n"
3739 "#extension GL_ARB_shading_language_420pack: require\n"
3740 "\n"
3741 "layout(location=0) out vec4 color;\n"
3742 "void main(){\n"
3743 " color = vec4(1);\n"
3744 "}\n";
3745
3746 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3747 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3748
3749 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003750 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12003751 pipe.AddShader(&vs);
3752 pipe.AddShader(&fs);
3753
3754 pipe.AddVertexInputBindings(&input_binding, 1);
3755 pipe.AddVertexInputAttribs(&input_attrib, 1);
3756
Chris Forbes8291c052015-05-25 11:13:28 +12003757 VkDescriptorSetObj descriptorSet(m_device);
3758 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003759 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12003760
3761 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003762 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12003763
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003764 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12003765
Cody Northrop1684adb2015-08-05 11:15:02 -06003766 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12003767 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
3768 FAIL() << "Incorrect warning: " << msgString;
3769 }
3770}
3771
Chris Forbes37367e62015-05-25 11:13:29 +12003772TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
3773{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003774 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12003775 std::string msgString;
3776 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12003778
3779 char const *vsSource =
3780 "#version 140\n"
3781 "#extension GL_ARB_separate_shader_objects: require\n"
3782 "#extension GL_ARB_shading_language_420pack: require\n"
3783 "\n"
3784 "layout(location=0) in vec4 x;\n" /* not provided */
3785 "void main(){\n"
3786 " gl_Position = x;\n"
3787 "}\n";
3788 char const *fsSource =
3789 "#version 140\n"
3790 "#extension GL_ARB_separate_shader_objects: require\n"
3791 "#extension GL_ARB_shading_language_420pack: require\n"
3792 "\n"
3793 "layout(location=0) out vec4 color;\n"
3794 "void main(){\n"
3795 " color = vec4(1);\n"
3796 "}\n";
3797
3798 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3799 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3800
3801 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003802 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12003803 pipe.AddShader(&vs);
3804 pipe.AddShader(&fs);
3805
Chris Forbes37367e62015-05-25 11:13:29 +12003806 VkDescriptorSetObj descriptorSet(m_device);
3807 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003808 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12003809
3810 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003811 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12003812
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003813 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12003814
Cody Northrop1684adb2015-08-05 11:15:02 -06003815 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes37367e62015-05-25 11:13:29 +12003816 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
3817 FAIL() << "Incorrect warning: " << msgString;
3818 }
3819}
3820
Chris Forbesa4b02322015-05-25 11:13:31 +12003821TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
3822{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003823 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12003824 std::string msgString;
3825 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003826 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12003827
3828 VkVertexInputBindingDescription input_binding;
3829 memset(&input_binding, 0, sizeof(input_binding));
3830
3831 VkVertexInputAttributeDescription input_attrib;
3832 memset(&input_attrib, 0, sizeof(input_attrib));
3833 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3834
3835 char const *vsSource =
3836 "#version 140\n"
3837 "#extension GL_ARB_separate_shader_objects: require\n"
3838 "#extension GL_ARB_shading_language_420pack: require\n"
3839 "\n"
3840 "layout(location=0) in int x;\n" /* attrib provided float */
3841 "void main(){\n"
3842 " gl_Position = vec4(x);\n"
3843 "}\n";
3844 char const *fsSource =
3845 "#version 140\n"
3846 "#extension GL_ARB_separate_shader_objects: require\n"
3847 "#extension GL_ARB_shading_language_420pack: require\n"
3848 "\n"
3849 "layout(location=0) out vec4 color;\n"
3850 "void main(){\n"
3851 " color = vec4(1);\n"
3852 "}\n";
3853
3854 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3855 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3856
3857 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003858 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12003859 pipe.AddShader(&vs);
3860 pipe.AddShader(&fs);
3861
3862 pipe.AddVertexInputBindings(&input_binding, 1);
3863 pipe.AddVertexInputAttribs(&input_attrib, 1);
3864
Chris Forbesa4b02322015-05-25 11:13:31 +12003865 VkDescriptorSetObj descriptorSet(m_device);
3866 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003867 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12003868
3869 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003870 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12003871
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003872 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12003873
Cody Northrop1684adb2015-08-05 11:15:02 -06003874 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa4b02322015-05-25 11:13:31 +12003875 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
3876 FAIL() << "Incorrect error: " << msgString;
3877 }
3878}
3879
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003880TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
3881{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003882 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003883 std::string msgString;
3884 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003885 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003886
3887 /* Two binding descriptions for binding 0 */
3888 VkVertexInputBindingDescription input_bindings[2];
3889 memset(input_bindings, 0, sizeof(input_bindings));
3890
3891 VkVertexInputAttributeDescription input_attrib;
3892 memset(&input_attrib, 0, sizeof(input_attrib));
3893 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3894
3895 char const *vsSource =
3896 "#version 140\n"
3897 "#extension GL_ARB_separate_shader_objects: require\n"
3898 "#extension GL_ARB_shading_language_420pack: require\n"
3899 "\n"
3900 "layout(location=0) in float x;\n" /* attrib provided float */
3901 "void main(){\n"
3902 " gl_Position = vec4(x);\n"
3903 "}\n";
3904 char const *fsSource =
3905 "#version 140\n"
3906 "#extension GL_ARB_separate_shader_objects: require\n"
3907 "#extension GL_ARB_shading_language_420pack: require\n"
3908 "\n"
3909 "layout(location=0) out vec4 color;\n"
3910 "void main(){\n"
3911 " color = vec4(1);\n"
3912 "}\n";
3913
3914 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3915 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3916
3917 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003918 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003919 pipe.AddShader(&vs);
3920 pipe.AddShader(&fs);
3921
3922 pipe.AddVertexInputBindings(input_bindings, 2);
3923 pipe.AddVertexInputAttribs(&input_attrib, 1);
3924
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003925 VkDescriptorSetObj descriptorSet(m_device);
3926 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003927 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003928
3929 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003930 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003931
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003932 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003933
Cody Northrop1684adb2015-08-05 11:15:02 -06003934 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003935 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
3936 FAIL() << "Incorrect error: " << msgString;
3937 }
3938}
Chris Forbes4c948702015-05-25 11:13:32 +12003939
Chris Forbesc12ef122015-05-25 11:13:40 +12003940/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
3941 * rejects it. */
3942
3943TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
3944{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003945 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12003946 std::string msgString;
3947 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12003948
3949 char const *vsSource =
3950 "#version 140\n"
3951 "#extension GL_ARB_separate_shader_objects: require\n"
3952 "#extension GL_ARB_shading_language_420pack: require\n"
3953 "\n"
3954 "void main(){\n"
3955 " gl_Position = vec4(1);\n"
3956 "}\n";
3957 char const *fsSource =
3958 "#version 140\n"
3959 "#extension GL_ARB_separate_shader_objects: require\n"
3960 "#extension GL_ARB_shading_language_420pack: require\n"
3961 "\n"
3962 "void main(){\n"
3963 "}\n";
3964
3965 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3966 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3967
3968 VkPipelineObj pipe(m_device);
3969 pipe.AddShader(&vs);
3970 pipe.AddShader(&fs);
3971
Chia-I Wuc278df82015-07-07 11:50:03 +08003972 /* set up CB 0, not written */
3973 pipe.AddColorAttachment();
3974 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12003975
Chris Forbesc12ef122015-05-25 11:13:40 +12003976 VkDescriptorSetObj descriptorSet(m_device);
3977 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003978 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12003979
3980 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003981 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12003982
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003983 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12003984
Cody Northrop1684adb2015-08-05 11:15:02 -06003985 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc12ef122015-05-25 11:13:40 +12003986 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
3987 FAIL() << "Incorrect error: " << msgString;
3988 }
3989}
3990
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003991TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
3992{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003993 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003994 std::string msgString;
3995 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003996
3997 char const *vsSource =
3998 "#version 140\n"
3999 "#extension GL_ARB_separate_shader_objects: require\n"
4000 "#extension GL_ARB_shading_language_420pack: require\n"
4001 "\n"
4002 "void main(){\n"
4003 " gl_Position = vec4(1);\n"
4004 "}\n";
4005 char const *fsSource =
4006 "#version 140\n"
4007 "#extension GL_ARB_separate_shader_objects: require\n"
4008 "#extension GL_ARB_shading_language_420pack: require\n"
4009 "\n"
4010 "layout(location=0) out vec4 x;\n"
4011 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
4012 "void main(){\n"
4013 " x = vec4(1);\n"
4014 " y = vec4(1);\n"
4015 "}\n";
4016
4017 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
4018 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
4019
4020 VkPipelineObj pipe(m_device);
4021 pipe.AddShader(&vs);
4022 pipe.AddShader(&fs);
4023
Chia-I Wuc278df82015-07-07 11:50:03 +08004024 /* set up CB 0, not written */
4025 pipe.AddColorAttachment();
4026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004027 /* FS writes CB 1, but we don't configure it */
4028
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004029 VkDescriptorSetObj descriptorSet(m_device);
4030 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004031 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004032
4033 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004034 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004035
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004036 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004037
Cody Northrop1684adb2015-08-05 11:15:02 -06004038 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004039 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
4040 FAIL() << "Incorrect warning: " << msgString;
4041 }
4042}
4043
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004044TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
4045{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004046 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004047 std::string msgString;
4048 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004049
4050 char const *vsSource =
4051 "#version 140\n"
4052 "#extension GL_ARB_separate_shader_objects: require\n"
4053 "#extension GL_ARB_shading_language_420pack: require\n"
4054 "\n"
4055 "void main(){\n"
4056 " gl_Position = vec4(1);\n"
4057 "}\n";
4058 char const *fsSource =
4059 "#version 140\n"
4060 "#extension GL_ARB_separate_shader_objects: require\n"
4061 "#extension GL_ARB_shading_language_420pack: require\n"
4062 "\n"
4063 "layout(location=0) out ivec4 x;\n" /* not UNORM */
4064 "void main(){\n"
4065 " x = ivec4(1);\n"
4066 "}\n";
4067
4068 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
4069 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
4070
4071 VkPipelineObj pipe(m_device);
4072 pipe.AddShader(&vs);
4073 pipe.AddShader(&fs);
4074
Chia-I Wuc278df82015-07-07 11:50:03 +08004075 /* set up CB 0; type is UNORM by default */
4076 pipe.AddColorAttachment();
4077 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004078
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004079 VkDescriptorSetObj descriptorSet(m_device);
4080 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004081 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004082
4083 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004084 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004085
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004086 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004087
Cody Northrop1684adb2015-08-05 11:15:02 -06004088 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004089 if (!strstr(msgString.c_str(),"does not match FS output type")) {
4090 FAIL() << "Incorrect error: " << msgString;
4091 }
4092}
Chris Forbesc2050732015-06-05 14:43:36 +12004093
Chris Forbes76ce7882015-08-14 12:04:59 +12004094TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
4095{
4096 VkFlags msgFlags;
4097 std::string msgString;
4098 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +12004099
4100 char const *vsSource =
4101 "#version 140\n"
4102 "#extension GL_ARB_separate_shader_objects: require\n"
4103 "#extension GL_ARB_shading_language_420pack: require\n"
4104 "\n"
4105 "void main(){\n"
4106 " gl_Position = vec4(1);\n"
4107 "}\n";
4108 char const *fsSource =
4109 "#version 140\n"
4110 "#extension GL_ARB_separate_shader_objects: require\n"
4111 "#extension GL_ARB_shading_language_420pack: require\n"
4112 "\n"
4113 "layout(location=0) out vec4 x;\n"
4114 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4115 "void main(){\n"
4116 " x = vec4(bar.y);\n"
4117 "}\n";
4118
4119 m_errorMonitor->ClearState();
4120
4121 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
4122 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
4123
4124
4125 VkPipelineObj pipe(m_device);
4126 pipe.AddShader(&vs);
4127 pipe.AddShader(&fs);
4128
4129 /* set up CB 0; type is UNORM by default */
4130 pipe.AddColorAttachment();
4131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4132
4133 VkDescriptorSetObj descriptorSet(m_device);
4134 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
4135
4136 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4137
4138 /* should have generated an error -- pipeline layout does not
4139 * provide a uniform buffer in 0.0
4140 */
4141 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter0abdb662015-10-07 13:28:58 -06004142 ASSERT_TRUE((msgFlags & VK_DBG_REPORT_ERROR_BIT) == VK_DBG_REPORT_ERROR_BIT);
Chris Forbes76ce7882015-08-14 12:04:59 +12004143 if (!strstr(msgString.c_str(),"not declared in pipeline layout")) {
4144 FAIL() << "Incorrect error: " << msgString;
4145 }
4146}
4147
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004148#endif // SHADER_CHECKER_TESTS
4149
4150#if DEVICE_LIMITS_TESTS
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004151TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
4152{
4153 VkFlags msgFlags;
4154 std::string msgString;
4155
4156 ASSERT_NO_FATAL_FAILURE(InitState());
4157 m_errorMonitor->ClearState();
4158
4159 // Create an image
4160 VkImage image;
4161
4162 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4163 const int32_t tex_width = 32;
4164 const int32_t tex_height = 32;
4165
4166 VkImageCreateInfo image_create_info = {};
4167 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4168 image_create_info.pNext = NULL;
4169 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4170 image_create_info.format = tex_format;
4171 image_create_info.extent.width = tex_width;
4172 image_create_info.extent.height = tex_height;
4173 image_create_info.extent.depth = 1;
4174 image_create_info.mipLevels = 1;
4175 image_create_info.arraySize = 1;
4176 image_create_info.samples = 1;
4177 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4178 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4179 image_create_info.flags = 0;
4180
4181 // Introduce error by sending down a bogus width extent
4182 image_create_info.extent.width = 65536;
4183 vkCreateImage(m_device->device(), &image_create_info, &image);
4184
4185 msgFlags = m_errorMonitor->GetState(&msgString);
4186 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4187 "with extents outside the queried limits";
4188 if (!strstr(msgString.c_str(),"CreateImage extents exceed allowable limits for format")) {
4189 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4190 }
4191}
4192
4193TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
4194{
4195 VkFlags msgFlags;
4196 std::string msgString;
4197
4198 ASSERT_NO_FATAL_FAILURE(InitState());
4199 m_errorMonitor->ClearState();
4200
4201 // Create an image
4202 VkImage image;
4203
4204 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4205 const int32_t tex_width = 32;
4206 const int32_t tex_height = 32;
4207
4208 VkImageCreateInfo image_create_info = {};
4209 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4210 image_create_info.pNext = NULL;
4211 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4212 image_create_info.format = tex_format;
4213 image_create_info.extent.width = tex_width;
4214 image_create_info.extent.height = tex_height;
4215 image_create_info.extent.depth = 1;
4216 image_create_info.mipLevels = 1;
4217 image_create_info.arraySize = 1;
4218 image_create_info.samples = 1;
4219 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4220 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4221 image_create_info.flags = 0;
4222
4223 // Introduce error by sending down individually allowable values that result in a surface size
4224 // exceeding the device maximum
4225 image_create_info.extent.width = 8192;
4226 image_create_info.extent.height = 8192;
4227 image_create_info.extent.depth = 16;
4228 image_create_info.arraySize = 4;
4229 image_create_info.samples = 2;
4230 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
4231 vkCreateImage(m_device->device(), &image_create_info, &image);
4232
4233 msgFlags = m_errorMonitor->GetState(&msgString);
4234 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4235 "with resource size exceeding queried limit";
4236 if (!strstr(msgString.c_str(),"CreateImage resource size exceeds allowable maximum")) {
4237 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4238 }
4239}
4240
Mike Stroyan43909d82015-09-25 13:39:21 -06004241TEST_F(VkLayerTest, UpdateBufferAlignment)
4242{
4243 VkFlags msgFlags;
4244 std::string msgString;
4245 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
4246
4247 ASSERT_NO_FATAL_FAILURE(InitState());
4248
4249 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4250 vk_testing::Buffer buffer;
4251 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4252
4253 BeginCommandBuffer();
4254 // Introduce failure by using offset that is not multiple of 4
4255 m_cmdBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
4256 msgFlags = m_errorMonitor->GetState(&msgString);
4257 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad offset";
4258 if (!strstr(msgString.c_str(),"destOffset, is not a multiple of 4")) {
4259 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4'";
4260 }
4261 // Introduce failure by using size that is not multiple of 4
4262 m_cmdBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
4263 msgFlags = m_errorMonitor->GetState(&msgString);
4264 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad size";
4265 if (!strstr(msgString.c_str(),"dataSize, is not a multiple of 4")) {
4266 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
4267 }
4268 EndCommandBuffer();
4269}
4270
4271TEST_F(VkLayerTest, FillBufferAlignment)
4272{
4273 VkFlags msgFlags;
4274 std::string msgString;
4275
4276 ASSERT_NO_FATAL_FAILURE(InitState());
4277
4278 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4279 vk_testing::Buffer buffer;
4280 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4281
4282 BeginCommandBuffer();
4283 // Introduce failure by using offset that is not multiple of 4
4284 m_cmdBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
4285 msgFlags = m_errorMonitor->GetState(&msgString);
4286 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad offset";
4287 if (!strstr(msgString.c_str(),"destOffset, is not a multiple of 4")) {
4288 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4'";
4289 }
4290 // Introduce failure by using size that is not multiple of 4
4291 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
4292 msgFlags = m_errorMonitor->GetState(&msgString);
4293 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad size";
4294 if (!strstr(msgString.c_str(),"fillSize, is not a multiple of 4")) {
4295 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize fillSize, is not a multiple of 4'";
4296 }
4297 EndCommandBuffer();
4298}
4299
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004300#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004301
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004302#if IMAGE_TESTS
4303TEST_F(VkLayerTest, InvalidImageView)
4304{
4305 VkFlags msgFlags;
4306 std::string msgString;
4307 VkResult err;
4308
4309 ASSERT_NO_FATAL_FAILURE(InitState());
4310 m_errorMonitor->ClearState();
4311
Mike Stroyan43909d82015-09-25 13:39:21 -06004312 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004313 VkImage image;
4314
4315 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4316 const int32_t tex_width = 32;
4317 const int32_t tex_height = 32;
4318
4319 VkImageCreateInfo image_create_info = {};
4320 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4321 image_create_info.pNext = NULL;
4322 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4323 image_create_info.format = tex_format;
4324 image_create_info.extent.width = tex_width;
4325 image_create_info.extent.height = tex_height;
4326 image_create_info.extent.depth = 1;
4327 image_create_info.mipLevels = 1;
4328 image_create_info.arraySize = 1;
4329 image_create_info.samples = 1;
4330 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4331 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4332 image_create_info.flags = 0;
4333
4334 err = vkCreateImage(m_device->device(), &image_create_info, &image);
4335 ASSERT_VK_SUCCESS(err);
4336
4337 VkImageViewCreateInfo image_view_create_info = {};
4338 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4339 image_view_create_info.image = image;
4340 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4341 image_view_create_info.format = tex_format;
4342 image_view_create_info.subresourceRange.arraySize = 1;
4343 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
4344 image_view_create_info.subresourceRange.mipLevels = 1;
4345
4346 VkImageView view;
4347 err = vkCreateImageView(m_device->device(), &image_view_create_info, &view);
4348
4349 msgFlags = m_errorMonitor->GetState(&msgString);
4350 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an invalid ImageView";
4351 if (!strstr(msgString.c_str(),"vkCreateImageView called with baseMipLevel 10 ")) {
Mike Stroyan43909d82015-09-25 13:39:21 -06004352 FAIL() << "Error received was not 'vkCreateImageView called with baseMipLevel 10...' but instead '" << msgString.c_str() << "'";
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004353 }
4354}
Mike Stroyan43909d82015-09-25 13:39:21 -06004355
4356TEST_F(VkLayerTest, CopyImageTypeMismatch)
4357{
4358 VkFlags msgFlags;
4359 std::string msgString;
4360 VkResult err;
4361
4362 ASSERT_NO_FATAL_FAILURE(InitState());
4363 m_errorMonitor->ClearState();
4364
4365 // Create two images of different types and try to copy between them
4366 VkImage srcImage;
4367 VkImage destImage;
4368 VkDeviceMemory srcMem;
4369 VkDeviceMemory destMem;
4370 VkMemoryRequirements memReqs;
4371
4372 VkImageCreateInfo image_create_info = {};
4373 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4374 image_create_info.pNext = NULL;
4375 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4376 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4377 image_create_info.extent.width = 32;
4378 image_create_info.extent.height = 32;
4379 image_create_info.extent.depth = 1;
4380 image_create_info.mipLevels = 1;
4381 image_create_info.arraySize = 1;
4382 image_create_info.samples = 1;
4383 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4384 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4385 image_create_info.flags = 0;
4386
4387 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4388 ASSERT_VK_SUCCESS(err);
4389
4390 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4391 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4392
4393 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4394 ASSERT_VK_SUCCESS(err);
4395
4396 // Allocate memory
4397 VkMemoryAllocInfo memAlloc = {};
4398 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4399 memAlloc.pNext = NULL;
4400 memAlloc.allocationSize = 0;
4401 memAlloc.memoryTypeIndex = 0;
4402
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004403 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004404 memAlloc.allocationSize = memReqs.size;
4405 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4406 ASSERT_VK_SUCCESS(err);
4407 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4408 ASSERT_VK_SUCCESS(err);
4409
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004410 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004411 memAlloc.allocationSize = memReqs.size;
4412 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4413 ASSERT_VK_SUCCESS(err);
4414 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4415 ASSERT_VK_SUCCESS(err);
4416
4417 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4418 ASSERT_VK_SUCCESS(err);
4419 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4420 ASSERT_VK_SUCCESS(err);
4421
4422 BeginCommandBuffer();
4423 VkImageCopy copyRegion;
4424 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4425 copyRegion.srcSubresource.mipLevel = 0;
4426 copyRegion.srcSubresource.arrayLayer = 0;
4427 copyRegion.srcSubresource.arraySize = 0;
4428 copyRegion.srcOffset.x = 0;
4429 copyRegion.srcOffset.y = 0;
4430 copyRegion.srcOffset.z = 0;
4431 copyRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4432 copyRegion.destSubresource.mipLevel = 0;
4433 copyRegion.destSubresource.arrayLayer = 0;
4434 copyRegion.destSubresource.arraySize = 0;
4435 copyRegion.destOffset.x = 0;
4436 copyRegion.destOffset.y = 0;
4437 copyRegion.destOffset.z = 0;
4438 copyRegion.extent.width = 1;
4439 copyRegion.extent.height = 1;
4440 copyRegion.extent.depth = 1;
4441 m_cmdBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
4442 EndCommandBuffer();
4443
4444 msgFlags = m_errorMonitor->GetState(&msgString);
4445 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
4446 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
4447 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
4448 }
4449
4450 vkDestroyImage(m_device->device(), srcImage);
4451 vkDestroyImage(m_device->device(), destImage);
4452 vkFreeMemory(m_device->device(), srcMem);
4453 vkFreeMemory(m_device->device(), destMem);
4454}
4455
4456TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
4457{
4458 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
4459}
4460
4461TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
4462{
4463 VkFlags msgFlags;
4464 std::string msgString;
4465 VkResult err;
4466
4467 ASSERT_NO_FATAL_FAILURE(InitState());
4468 m_errorMonitor->ClearState();
4469
4470 // Create two images of different types and try to copy between them
4471 VkImage srcImage;
4472 VkImage destImage;
4473 VkDeviceMemory srcMem;
4474 VkDeviceMemory destMem;
4475 VkMemoryRequirements memReqs;
4476
4477 VkImageCreateInfo image_create_info = {};
4478 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4479 image_create_info.pNext = NULL;
4480 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4481 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4482 image_create_info.extent.width = 32;
4483 image_create_info.extent.height = 32;
4484 image_create_info.extent.depth = 1;
4485 image_create_info.mipLevels = 1;
4486 image_create_info.arraySize = 1;
4487 image_create_info.samples = 1;
4488 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4489 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4490 image_create_info.flags = 0;
4491
4492 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4493 ASSERT_VK_SUCCESS(err);
4494
4495 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4496 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4497
4498 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4499 ASSERT_VK_SUCCESS(err);
4500
4501 // Allocate memory
4502 VkMemoryAllocInfo memAlloc = {};
4503 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4504 memAlloc.pNext = NULL;
4505 memAlloc.allocationSize = 0;
4506 memAlloc.memoryTypeIndex = 0;
4507
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004508 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004509 memAlloc.allocationSize = memReqs.size;
4510 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4511 ASSERT_VK_SUCCESS(err);
4512 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4513 ASSERT_VK_SUCCESS(err);
4514
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004515 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004516 memAlloc.allocationSize = memReqs.size;
4517 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4518 ASSERT_VK_SUCCESS(err);
4519 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4520 ASSERT_VK_SUCCESS(err);
4521
4522 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4523 ASSERT_VK_SUCCESS(err);
4524 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4525 ASSERT_VK_SUCCESS(err);
4526
4527 BeginCommandBuffer();
4528 VkImageCopy copyRegion;
4529 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4530 copyRegion.srcSubresource.mipLevel = 0;
4531 copyRegion.srcSubresource.arrayLayer = 0;
4532 copyRegion.srcSubresource.arraySize = 0;
4533 copyRegion.srcOffset.x = 0;
4534 copyRegion.srcOffset.y = 0;
4535 copyRegion.srcOffset.z = 0;
4536 copyRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4537 copyRegion.destSubresource.mipLevel = 0;
4538 copyRegion.destSubresource.arrayLayer = 0;
4539 copyRegion.destSubresource.arraySize = 0;
4540 copyRegion.destOffset.x = 0;
4541 copyRegion.destOffset.y = 0;
4542 copyRegion.destOffset.z = 0;
4543 copyRegion.extent.width = 1;
4544 copyRegion.extent.height = 1;
4545 copyRegion.extent.depth = 1;
4546 m_cmdBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
4547 EndCommandBuffer();
4548
4549 msgFlags = m_errorMonitor->GetState(&msgString);
4550 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
4551 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
4552 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
4553 }
4554
4555 vkDestroyImage(m_device->device(), srcImage);
4556 vkDestroyImage(m_device->device(), destImage);
4557 vkFreeMemory(m_device->device(), srcMem);
4558 vkFreeMemory(m_device->device(), destMem);
4559}
4560
4561TEST_F(VkLayerTest, ResolveImageLowSampleCount)
4562{
4563 VkFlags msgFlags;
4564 std::string msgString;
4565 VkResult err;
4566
4567 ASSERT_NO_FATAL_FAILURE(InitState());
4568 m_errorMonitor->ClearState();
4569
4570 // Create two images of sample count 1 and try to Resolve between them
4571 VkImage srcImage;
4572 VkImage destImage;
4573 VkDeviceMemory srcMem;
4574 VkDeviceMemory destMem;
4575 VkMemoryRequirements memReqs;
4576
4577 VkImageCreateInfo image_create_info = {};
4578 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4579 image_create_info.pNext = NULL;
4580 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4581 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4582 image_create_info.extent.width = 32;
4583 image_create_info.extent.height = 1;
4584 image_create_info.extent.depth = 1;
4585 image_create_info.mipLevels = 1;
4586 image_create_info.arraySize = 1;
4587 image_create_info.samples = 1;
4588 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4589 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4590 image_create_info.flags = 0;
4591
4592 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4593 ASSERT_VK_SUCCESS(err);
4594
4595 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4596 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4597
4598 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4599 ASSERT_VK_SUCCESS(err);
4600
4601 // Allocate memory
4602 VkMemoryAllocInfo memAlloc = {};
4603 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4604 memAlloc.pNext = NULL;
4605 memAlloc.allocationSize = 0;
4606 memAlloc.memoryTypeIndex = 0;
4607
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004608 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004609 memAlloc.allocationSize = memReqs.size;
4610 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4611 ASSERT_VK_SUCCESS(err);
4612 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4613 ASSERT_VK_SUCCESS(err);
4614
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004615 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004616 memAlloc.allocationSize = memReqs.size;
4617 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4618 ASSERT_VK_SUCCESS(err);
4619 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4620 ASSERT_VK_SUCCESS(err);
4621
4622 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4623 ASSERT_VK_SUCCESS(err);
4624 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4625 ASSERT_VK_SUCCESS(err);
4626
4627 BeginCommandBuffer();
4628 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4629 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4630 //VK_IMAGE_LAYOUT_GENERAL = 1,
4631 VkImageResolve resolveRegion;
4632 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4633 resolveRegion.srcSubresource.mipLevel = 0;
4634 resolveRegion.srcSubresource.arrayLayer = 0;
4635 resolveRegion.srcSubresource.arraySize = 0;
4636 resolveRegion.srcOffset.x = 0;
4637 resolveRegion.srcOffset.y = 0;
4638 resolveRegion.srcOffset.z = 0;
4639 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4640 resolveRegion.destSubresource.mipLevel = 0;
4641 resolveRegion.destSubresource.arrayLayer = 0;
4642 resolveRegion.destSubresource.arraySize = 0;
4643 resolveRegion.destOffset.x = 0;
4644 resolveRegion.destOffset.y = 0;
4645 resolveRegion.destOffset.z = 0;
4646 resolveRegion.extent.width = 1;
4647 resolveRegion.extent.height = 1;
4648 resolveRegion.extent.depth = 1;
4649 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4650 EndCommandBuffer();
4651
4652 msgFlags = m_errorMonitor->GetState(&msgString);
4653 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
4654 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with source sample count less than 2.")) {
4655 FAIL() << "Error received was not 'vkCmdResolveImage called with source sample count less than 2.' but instead '" << msgString.c_str() << "'";
4656 }
4657
4658 vkDestroyImage(m_device->device(), srcImage);
4659 vkDestroyImage(m_device->device(), destImage);
4660 vkFreeMemory(m_device->device(), srcMem);
4661 vkFreeMemory(m_device->device(), destMem);
4662}
4663
4664TEST_F(VkLayerTest, ResolveImageHighSampleCount)
4665{
4666 VkFlags msgFlags;
4667 std::string msgString;
4668 VkResult err;
4669
4670 ASSERT_NO_FATAL_FAILURE(InitState());
4671 m_errorMonitor->ClearState();
4672
4673 // Create two images of sample count 2 and try to Resolve between them
4674 VkImage srcImage;
4675 VkImage destImage;
4676 VkDeviceMemory srcMem;
4677 VkDeviceMemory destMem;
4678 VkMemoryRequirements memReqs;
4679
4680 VkImageCreateInfo image_create_info = {};
4681 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4682 image_create_info.pNext = NULL;
4683 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4684 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4685 image_create_info.extent.width = 32;
4686 image_create_info.extent.height = 1;
4687 image_create_info.extent.depth = 1;
4688 image_create_info.mipLevels = 1;
4689 image_create_info.arraySize = 1;
4690 image_create_info.samples = 2;
4691 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4692 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4693 image_create_info.flags = 0;
4694
4695 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4696 ASSERT_VK_SUCCESS(err);
4697
4698 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4699 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4700
4701 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4702 ASSERT_VK_SUCCESS(err);
4703
4704 // Allocate memory
4705 VkMemoryAllocInfo memAlloc = {};
4706 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4707 memAlloc.pNext = NULL;
4708 memAlloc.allocationSize = 0;
4709 memAlloc.memoryTypeIndex = 0;
4710
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004711 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004712 memAlloc.allocationSize = memReqs.size;
4713 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4714 ASSERT_VK_SUCCESS(err);
4715 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4716 ASSERT_VK_SUCCESS(err);
4717
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004718 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004719 memAlloc.allocationSize = memReqs.size;
4720 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4721 ASSERT_VK_SUCCESS(err);
4722 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4723 ASSERT_VK_SUCCESS(err);
4724
4725 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4726 ASSERT_VK_SUCCESS(err);
4727 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4728 ASSERT_VK_SUCCESS(err);
4729
4730 BeginCommandBuffer();
4731 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4732 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4733 //VK_IMAGE_LAYOUT_GENERAL = 1,
4734 VkImageResolve resolveRegion;
4735 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4736 resolveRegion.srcSubresource.mipLevel = 0;
4737 resolveRegion.srcSubresource.arrayLayer = 0;
4738 resolveRegion.srcSubresource.arraySize = 0;
4739 resolveRegion.srcOffset.x = 0;
4740 resolveRegion.srcOffset.y = 0;
4741 resolveRegion.srcOffset.z = 0;
4742 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4743 resolveRegion.destSubresource.mipLevel = 0;
4744 resolveRegion.destSubresource.arrayLayer = 0;
4745 resolveRegion.destSubresource.arraySize = 0;
4746 resolveRegion.destOffset.x = 0;
4747 resolveRegion.destOffset.y = 0;
4748 resolveRegion.destOffset.z = 0;
4749 resolveRegion.extent.width = 1;
4750 resolveRegion.extent.height = 1;
4751 resolveRegion.extent.depth = 1;
4752 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4753 EndCommandBuffer();
4754
4755 msgFlags = m_errorMonitor->GetState(&msgString);
4756 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
4757 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with dest sample count greater than 1.")) {
4758 FAIL() << "Error received was not 'vkCmdResolveImage called with dest sample count greater than 1.' but instead '" << msgString.c_str() << "'";
4759 }
4760
4761 vkDestroyImage(m_device->device(), srcImage);
4762 vkDestroyImage(m_device->device(), destImage);
4763 vkFreeMemory(m_device->device(), srcMem);
4764 vkFreeMemory(m_device->device(), destMem);
4765}
4766
4767TEST_F(VkLayerTest, ResolveImageFormatMismatch)
4768{
4769 VkFlags msgFlags;
4770 std::string msgString;
4771 VkResult err;
4772
4773 ASSERT_NO_FATAL_FAILURE(InitState());
4774 m_errorMonitor->ClearState();
4775
4776 // Create two images of different types and try to copy between them
4777 VkImage srcImage;
4778 VkImage destImage;
4779 VkDeviceMemory srcMem;
4780 VkDeviceMemory destMem;
4781 VkMemoryRequirements memReqs;
4782
4783 VkImageCreateInfo image_create_info = {};
4784 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4785 image_create_info.pNext = NULL;
4786 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4787 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4788 image_create_info.extent.width = 32;
4789 image_create_info.extent.height = 1;
4790 image_create_info.extent.depth = 1;
4791 image_create_info.mipLevels = 1;
4792 image_create_info.arraySize = 1;
4793 image_create_info.samples = 2;
4794 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4795 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4796 image_create_info.flags = 0;
4797
4798 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4799 ASSERT_VK_SUCCESS(err);
4800
4801 image_create_info.format = VK_FORMAT_B8G8R8_SRGB;
4802 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4803 image_create_info.samples = 1;
4804
4805 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4806 ASSERT_VK_SUCCESS(err);
4807
4808 // Allocate memory
4809 VkMemoryAllocInfo memAlloc = {};
4810 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4811 memAlloc.pNext = NULL;
4812 memAlloc.allocationSize = 0;
4813 memAlloc.memoryTypeIndex = 0;
4814
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004815 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004816 memAlloc.allocationSize = memReqs.size;
4817 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4818 ASSERT_VK_SUCCESS(err);
4819 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4820 ASSERT_VK_SUCCESS(err);
4821
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004822 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004823 memAlloc.allocationSize = memReqs.size;
4824 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4825 ASSERT_VK_SUCCESS(err);
4826 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4827 ASSERT_VK_SUCCESS(err);
4828
4829 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4830 ASSERT_VK_SUCCESS(err);
4831 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4832 ASSERT_VK_SUCCESS(err);
4833
4834 BeginCommandBuffer();
4835 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4836 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4837 //VK_IMAGE_LAYOUT_GENERAL = 1,
4838 VkImageResolve resolveRegion;
4839 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4840 resolveRegion.srcSubresource.mipLevel = 0;
4841 resolveRegion.srcSubresource.arrayLayer = 0;
4842 resolveRegion.srcSubresource.arraySize = 0;
4843 resolveRegion.srcOffset.x = 0;
4844 resolveRegion.srcOffset.y = 0;
4845 resolveRegion.srcOffset.z = 0;
4846 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4847 resolveRegion.destSubresource.mipLevel = 0;
4848 resolveRegion.destSubresource.arrayLayer = 0;
4849 resolveRegion.destSubresource.arraySize = 0;
4850 resolveRegion.destOffset.x = 0;
4851 resolveRegion.destOffset.y = 0;
4852 resolveRegion.destOffset.z = 0;
4853 resolveRegion.extent.width = 1;
4854 resolveRegion.extent.height = 1;
4855 resolveRegion.extent.depth = 1;
4856 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4857 EndCommandBuffer();
4858
4859 msgFlags = m_errorMonitor->GetState(&msgString);
4860 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage format mismatch";
4861 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest formats.")) {
4862 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest formats.' but instead '" << msgString.c_str() << "'";
4863 }
4864
4865 vkDestroyImage(m_device->device(), srcImage);
4866 vkDestroyImage(m_device->device(), destImage);
4867 vkFreeMemory(m_device->device(), srcMem);
4868 vkFreeMemory(m_device->device(), destMem);
4869}
4870
4871TEST_F(VkLayerTest, ResolveImageTypeMismatch)
4872{
4873 VkFlags msgFlags;
4874 std::string msgString;
4875 VkResult err;
4876
4877 ASSERT_NO_FATAL_FAILURE(InitState());
4878 m_errorMonitor->ClearState();
4879
4880 // Create two images of different types and try to copy between them
4881 VkImage srcImage;
4882 VkImage destImage;
4883 VkDeviceMemory srcMem;
4884 VkDeviceMemory destMem;
4885 VkMemoryRequirements memReqs;
4886
4887 VkImageCreateInfo image_create_info = {};
4888 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4889 image_create_info.pNext = NULL;
4890 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4891 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4892 image_create_info.extent.width = 32;
4893 image_create_info.extent.height = 1;
4894 image_create_info.extent.depth = 1;
4895 image_create_info.mipLevels = 1;
4896 image_create_info.arraySize = 1;
4897 image_create_info.samples = 2;
4898 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4899 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4900 image_create_info.flags = 0;
4901
4902 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4903 ASSERT_VK_SUCCESS(err);
4904
4905 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4906 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4907 image_create_info.samples = 1;
4908
4909 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4910 ASSERT_VK_SUCCESS(err);
4911
4912 // Allocate memory
4913 VkMemoryAllocInfo memAlloc = {};
4914 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4915 memAlloc.pNext = NULL;
4916 memAlloc.allocationSize = 0;
4917 memAlloc.memoryTypeIndex = 0;
4918
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004919 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004920 memAlloc.allocationSize = memReqs.size;
4921 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4922 ASSERT_VK_SUCCESS(err);
4923 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4924 ASSERT_VK_SUCCESS(err);
4925
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004926 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004927 memAlloc.allocationSize = memReqs.size;
4928 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4929 ASSERT_VK_SUCCESS(err);
4930 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4931 ASSERT_VK_SUCCESS(err);
4932
4933 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4934 ASSERT_VK_SUCCESS(err);
4935 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4936 ASSERT_VK_SUCCESS(err);
4937
4938 BeginCommandBuffer();
4939 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4940 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4941 //VK_IMAGE_LAYOUT_GENERAL = 1,
4942 VkImageResolve resolveRegion;
4943 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4944 resolveRegion.srcSubresource.mipLevel = 0;
4945 resolveRegion.srcSubresource.arrayLayer = 0;
4946 resolveRegion.srcSubresource.arraySize = 0;
4947 resolveRegion.srcOffset.x = 0;
4948 resolveRegion.srcOffset.y = 0;
4949 resolveRegion.srcOffset.z = 0;
4950 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4951 resolveRegion.destSubresource.mipLevel = 0;
4952 resolveRegion.destSubresource.arrayLayer = 0;
4953 resolveRegion.destSubresource.arraySize = 0;
4954 resolveRegion.destOffset.x = 0;
4955 resolveRegion.destOffset.y = 0;
4956 resolveRegion.destOffset.z = 0;
4957 resolveRegion.extent.width = 1;
4958 resolveRegion.extent.height = 1;
4959 resolveRegion.extent.depth = 1;
4960 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4961 EndCommandBuffer();
4962
4963 msgFlags = m_errorMonitor->GetState(&msgString);
4964 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
4965 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest image types.")) {
4966 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest image types.' but instead '" << msgString.c_str() << "'";
4967 }
4968
4969 vkDestroyImage(m_device->device(), srcImage);
4970 vkDestroyImage(m_device->device(), destImage);
4971 vkFreeMemory(m_device->device(), srcMem);
4972 vkFreeMemory(m_device->device(), destMem);
4973}
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004974#endif // IMAGE_TESTS
4975
Tony Barbour30486ea2015-04-07 13:44:53 -06004976int main(int argc, char **argv) {
4977 int result;
4978
4979 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004980 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06004981
4982 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
4983
4984 result = RUN_ALL_TESTS();
4985
Tony Barbour01999182015-04-09 12:58:51 -06004986 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06004987 return result;
4988}