blob: 9d1d0814207b0c212115977a126662e3b781d619 [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;
Tony Barbour1490c912015-07-28 10:17:20 -0600416 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500417 ASSERT_VK_SUCCESS( err );
418
419 m_errorMonitor->ClearState();
420 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600421 vkResetCommandBuffer(m_cmdBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500422
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600423 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600424 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 -0500425 if (!strstr(msgString.c_str(),"Resetting CB")) {
426 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
427 }
428}
429
430TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion)
431{
432 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600433 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500434 std::string msgString;
435
436 VkFenceCreateInfo fenceInfo = {};
437 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
438 fenceInfo.pNext = NULL;
439 fenceInfo.flags = 0;
440
441 ASSERT_NO_FATAL_FAILURE(InitState());
442 ASSERT_NO_FATAL_FAILURE(InitViewport());
443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
444
Tony Barbour1490c912015-07-28 10:17:20 -0600445 BeginCommandBuffer();
446 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
447 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500448
449 testFence.init(*m_device, fenceInfo);
450
451 // Bypass framework since it does the waits automatically
452 VkResult err = VK_SUCCESS;
Tony Barbour1490c912015-07-28 10:17:20 -0600453 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500454 ASSERT_VK_SUCCESS( err );
455
456 m_errorMonitor->ClearState();
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600457
458 VkCmdBufferBeginInfo info = {};
459 info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT | VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
460 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
461 info.renderPass = VK_NULL_HANDLE;
462 info.subpass = 0;
463 info.framebuffer = VK_NULL_HANDLE;
464
465 // Introduce failure by calling BCB again before checking fence
466 vkBeginCommandBuffer(m_cmdBuffer->handle(), &info);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500467
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600468 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600469 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 -0500470 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
471 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
472 }
473}
474
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500475TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
476{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600477 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500478 std::string msgString;
479 VkResult err;
480
481 ASSERT_NO_FATAL_FAILURE(InitState());
482 m_errorMonitor->ClearState();
483
484 // Create an image, allocate memory, free it, and then try to bind it
485 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500486 VkDeviceMemory mem;
487 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500488
489 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
490 const int32_t tex_width = 32;
491 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500492
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600493 VkImageCreateInfo image_create_info = {};
494 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
495 image_create_info.pNext = NULL;
496 image_create_info.imageType = VK_IMAGE_TYPE_2D;
497 image_create_info.format = tex_format;
498 image_create_info.extent.width = tex_width;
499 image_create_info.extent.height = tex_height;
500 image_create_info.extent.depth = 1;
501 image_create_info.mipLevels = 1;
502 image_create_info.arraySize = 1;
503 image_create_info.samples = 1;
504 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
505 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
506 image_create_info.flags = 0;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600507
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600508 VkMemoryAllocInfo mem_alloc = {};
509 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
510 mem_alloc.pNext = NULL;
511 mem_alloc.allocationSize = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500512 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600513 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500514
515 err = vkCreateImage(m_device->device(), &image_create_info, &image);
516 ASSERT_VK_SUCCESS(err);
517
Tony Barboure84a8d62015-07-10 14:10:27 -0600518 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500519 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500520 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500521 ASSERT_VK_SUCCESS(err);
522
Mark Lobodzinski23182612015-05-29 09:32:35 -0500523 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500524
Mike Stroyan2237f522015-08-18 14:40:24 -0600525 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
526 if(err != VK_SUCCESS) { // If we can't find any unmappable memory this test doesn't make sense
527 vkDestroyImage(m_device->device(), image);
Tony Barbour49a3b652015-08-04 16:13:01 -0600528 return;
Mike Stroyan2237f522015-08-18 14:40:24 -0600529 }
Mike Stroyand72da752015-08-04 10:49:29 -0600530
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500531 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500532 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500533 ASSERT_VK_SUCCESS(err);
534
535 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600536 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500537 ASSERT_VK_SUCCESS(err);
538
539 // Map memory as if to initialize the image
540 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500541 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500542
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600543 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600544 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 -0500545 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
546 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
547 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600548
549 vkDestroyImage(m_device->device(), image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500550}
551
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600552// TODO : Is this test still valid. Not sure it is with updates to memory binding model
553// Verify and delete the test of fix the check
554//TEST_F(VkLayerTest, FreeBoundMemory)
555//{
556// VkFlags msgFlags;
557// std::string msgString;
558// VkResult err;
559//
560// ASSERT_NO_FATAL_FAILURE(InitState());
561// m_errorMonitor->ClearState();
562//
563// // Create an image, allocate memory, free it, and then try to bind it
564// VkImage image;
565// VkDeviceMemory mem;
566// VkMemoryRequirements mem_reqs;
567//
568// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
569// const int32_t tex_width = 32;
570// const int32_t tex_height = 32;
571//
572// const VkImageCreateInfo image_create_info = {
573// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
574// .pNext = NULL,
575// .imageType = VK_IMAGE_TYPE_2D,
576// .format = tex_format,
577// .extent = { tex_width, tex_height, 1 },
578// .mipLevels = 1,
579// .arraySize = 1,
580// .samples = 1,
581// .tiling = VK_IMAGE_TILING_LINEAR,
582// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
583// .flags = 0,
584// };
585// VkMemoryAllocInfo mem_alloc = {
586// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
587// .pNext = NULL,
588// .allocationSize = 0,
589// .memoryTypeIndex = 0,
590// };
591//
592// err = vkCreateImage(m_device->device(), &image_create_info, &image);
593// ASSERT_VK_SUCCESS(err);
594//
595// err = vkGetImageMemoryRequirements(m_device->device(),
596// image,
597// &mem_reqs);
598// ASSERT_VK_SUCCESS(err);
599//
600// mem_alloc.allocationSize = mem_reqs.size;
601//
602// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
603// ASSERT_VK_SUCCESS(err);
604//
605// // allocate memory
606// err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
607// ASSERT_VK_SUCCESS(err);
608//
609// // Bind memory to Image object
610// err = vkBindImageMemory(m_device->device(), image, mem, 0);
611// ASSERT_VK_SUCCESS(err);
612//
613// // Introduce validation failure, free memory while still bound to object
614// vkFreeMemory(m_device->device(), mem);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600615// msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600616//
Cody Northrop1684adb2015-08-05 11:15:02 -0600617// 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 -0600618// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
619// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
620// }
621//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500622
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500623TEST_F(VkLayerTest, RebindMemory)
624{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600625 VkFlags msgFlags;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500626 std::string msgString;
627 VkResult err;
628
629 ASSERT_NO_FATAL_FAILURE(InitState());
630 m_errorMonitor->ClearState();
631
632 // Create an image, allocate memory, free it, and then try to bind it
633 VkImage image;
634 VkDeviceMemory mem1;
635 VkDeviceMemory mem2;
636 VkMemoryRequirements mem_reqs;
637
638 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
639 const int32_t tex_width = 32;
640 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500641
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600642 VkImageCreateInfo image_create_info = {};
643 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
644 image_create_info.pNext = NULL;
645 image_create_info.imageType = VK_IMAGE_TYPE_2D;
646 image_create_info.format = tex_format;
647 image_create_info.extent.width = tex_width;
648 image_create_info.extent.height = tex_height;
649 image_create_info.extent.depth = 1;
650 image_create_info.mipLevels = 1;
651 image_create_info.arraySize = 1;
652 image_create_info.samples = 1;
653 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
654 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
655 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500656
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600657 VkMemoryAllocInfo mem_alloc = {};
658 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
659 mem_alloc.pNext = NULL;
660 mem_alloc.allocationSize = 0;
661 mem_alloc.memoryTypeIndex = 0;
662
663 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
664 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500665 err = vkCreateImage(m_device->device(), &image_create_info, &image);
666 ASSERT_VK_SUCCESS(err);
667
Tony Barboure84a8d62015-07-10 14:10:27 -0600668 err = vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500669 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500670 &mem_reqs);
671 ASSERT_VK_SUCCESS(err);
672
673 mem_alloc.allocationSize = mem_reqs.size;
Chia-I Wuf5fb1092015-07-03 10:32:05 +0800674 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600675 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500676
677 // allocate 2 memory objects
678 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
679 ASSERT_VK_SUCCESS(err);
680 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
681 ASSERT_VK_SUCCESS(err);
682
683 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600684 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500685 ASSERT_VK_SUCCESS(err);
686
687 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600688 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500689
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600690 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600691 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 -0500692 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
693 FAIL() << "Error received did not match expected message when rebinding memory to an object";
694 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600695
696 vkDestroyImage(m_device->device(), image);
697 vkFreeMemory(m_device->device(), mem1);
698 vkFreeMemory(m_device->device(), mem2);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500699}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500700
Tony Barbour8508b8e2015-04-09 10:48:04 -0600701TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600702{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600703 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600704 VkFlags msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600705 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600706
707 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600708 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
709 fenceInfo.pNext = NULL;
710 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600711
Tony Barbour30486ea2015-04-07 13:44:53 -0600712 ASSERT_NO_FATAL_FAILURE(InitState());
713 ASSERT_NO_FATAL_FAILURE(InitViewport());
714 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
715
Tony Barbour1490c912015-07-28 10:17:20 -0600716 BeginCommandBuffer();
717 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
718 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600719
720 testFence.init(*m_device, fenceInfo);
721 m_errorMonitor->ClearState();
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600722
723 vkQueueSubmit(m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
724 vkQueueWaitIdle(m_device->m_queue );
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600725 msgFlags = m_errorMonitor->GetState(&msgString);
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600726
Cody Northrop1684adb2015-08-05 11:15:02 -0600727 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 -0600728 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500729 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600730 }
731
732}
733
734TEST_F(VkLayerTest, ResetUnsignaledFence)
735{
736 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600737 VkFlags msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600738 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600739 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600740 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
741 fenceInfo.pNext = NULL;
742
Tony Barbour8508b8e2015-04-09 10:48:04 -0600743 ASSERT_NO_FATAL_FAILURE(InitState());
744 testFence.init(*m_device, fenceInfo);
745 m_errorMonitor->ClearState();
Chia-I Wua4992342015-07-03 11:45:55 +0800746 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600747 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600748 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlisc2033a02015-10-01 10:14:48 -0600749 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 -0600750 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500751 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600752 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600753
754}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600755
Chia-I Wuc278df82015-07-07 11:50:03 +0800756/* TODO: Update for changes due to bug-14075 tiling across render passes */
757#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600758TEST_F(VkLayerTest, InvalidUsageBits)
759{
760 // Initiate Draw w/o a PSO bound
761 VkFlags msgFlags;
762 std::string msgString;
763
764 ASSERT_NO_FATAL_FAILURE(InitState());
765 m_errorMonitor->ClearState();
766 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600767 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600768
769 const VkExtent3D e3d = {
770 .width = 128,
771 .height = 128,
772 .depth = 1,
773 };
774 const VkImageCreateInfo ici = {
775 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
776 .pNext = NULL,
777 .imageType = VK_IMAGE_TYPE_2D,
778 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
779 .extent = e3d,
780 .mipLevels = 1,
781 .arraySize = 1,
782 .samples = 1,
783 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchterc3b8eea2015-09-10 14:14:11 -0600784 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600785 .flags = 0,
786 };
787
788 VkImage dsi;
789 vkCreateImage(m_device->device(), &ici, &dsi);
790 VkDepthStencilView dsv;
791 const VkDepthStencilViewCreateInfo dsvci = {
792 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
793 .pNext = NULL,
794 .image = dsi,
795 .mipLevel = 0,
Courtney Goeltzenleuchter3dee8082015-09-10 16:38:41 -0600796 .baseArrayLayer = 0,
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600797 .arraySize = 1,
798 .flags = 0,
799 };
800 vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv);
801 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600802 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 -0600803 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
804 FAIL() << "Error received was not 'Invalid usage flag for image...'";
805 }
806}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600807#endif // 0
808#endif // MEM_TRACKER_TESTS
809
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600810#if OBJ_TRACKER_TESTS
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600811TEST_F(VkLayerTest, PipelineNotBound)
812{
813 VkFlags msgFlags;
814 std::string msgString;
815 VkResult err;
816
817 ASSERT_NO_FATAL_FAILURE(InitState());
818 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
819 m_errorMonitor->ClearState();
820
821 VkDescriptorTypeCount ds_type_count = {};
822 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
823 ds_type_count.count = 1;
824
825 VkDescriptorPoolCreateInfo ds_pool_ci = {};
826 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
827 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600828 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
829 ds_pool_ci.maxSets = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600830 ds_pool_ci.count = 1;
831 ds_pool_ci.pTypeCount = &ds_type_count;
832
833 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600834 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600835 ASSERT_VK_SUCCESS(err);
836
837 VkDescriptorSetLayoutBinding dsl_binding = {};
838 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
839 dsl_binding.arraySize = 1;
840 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
841 dsl_binding.pImmutableSamplers = NULL;
842
843 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
844 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
845 ds_layout_ci.pNext = NULL;
846 ds_layout_ci.count = 1;
847 ds_layout_ci.pBinding = &dsl_binding;
848
849 VkDescriptorSetLayout ds_layout;
850 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
851 ASSERT_VK_SUCCESS(err);
852
853 VkDescriptorSet descriptorSet;
854 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
855 ASSERT_VK_SUCCESS(err);
856
857 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
858 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
859 pipeline_layout_ci.pNext = NULL;
860 pipeline_layout_ci.descriptorSetCount = 1;
861 pipeline_layout_ci.pSetLayouts = &ds_layout;
862
863 VkPipelineLayout pipeline_layout;
864 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
865 ASSERT_VK_SUCCESS(err);
866
867 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
868
869 BeginCommandBuffer();
870 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
871
872 msgFlags = m_errorMonitor->GetState(&msgString);
873 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 -0600874 if (!strstr(msgString.c_str(),"Invalid VkPipeline Object ")) {
875 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be' but instead it was '" << msgString.c_str() << "'";
876 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600877
878 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -0600879 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
880 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600881}
882
883TEST_F(VkLayerTest, BindInvalidMemory)
884{
885 VkFlags msgFlags;
886 std::string msgString;
887 VkResult err;
888
889 ASSERT_NO_FATAL_FAILURE(InitState());
890 m_errorMonitor->ClearState();
891
892 // Create an image, allocate memory, free it, and then try to bind it
893 VkImage image;
894 VkDeviceMemory mem;
895 VkMemoryRequirements mem_reqs;
896
897 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
898 const int32_t tex_width = 32;
899 const int32_t tex_height = 32;
900
901 VkImageCreateInfo image_create_info = {};
902 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
903 image_create_info.pNext = NULL;
904 image_create_info.imageType = VK_IMAGE_TYPE_2D;
905 image_create_info.format = tex_format;
906 image_create_info.extent.width = tex_width;
907 image_create_info.extent.height = tex_height;
908 image_create_info.extent.depth = 1;
909 image_create_info.mipLevels = 1;
910 image_create_info.arraySize = 1;
911 image_create_info.samples = 1;
912 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
913 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
914 image_create_info.flags = 0;
915
916 VkMemoryAllocInfo mem_alloc = {};
917 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
918 mem_alloc.pNext = NULL;
919 mem_alloc.allocationSize = 0;
920 mem_alloc.memoryTypeIndex = 0;
921
922 err = vkCreateImage(m_device->device(), &image_create_info, &image);
923 ASSERT_VK_SUCCESS(err);
924
925 err = vkGetImageMemoryRequirements(m_device->device(),
926 image,
927 &mem_reqs);
928 ASSERT_VK_SUCCESS(err);
929
930 mem_alloc.allocationSize = mem_reqs.size;
931
932 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
933 ASSERT_VK_SUCCESS(err);
934
935 // allocate memory
936 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
937 ASSERT_VK_SUCCESS(err);
938
939 // Introduce validation failure, free memory before binding
940 vkFreeMemory(m_device->device(), mem);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600941
942 // Try to bind free memory that has been freed
943 err = vkBindImageMemory(m_device->device(), image, mem, 0);
944 // This may very well return an error.
945 (void)err;
946
947 msgFlags = m_errorMonitor->GetState(&msgString);
948 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to bind a freed memory object";
949 if (!strstr(msgString.c_str(),"Invalid VkDeviceMemory Object ")) {
950 FAIL() << "Error received from BindInvalidMemory was not 'Invalid VkDeviceMemory Object 0x<handle>' but instead '" << msgString.c_str() << "'";
951 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600952
953 vkDestroyImage(m_device->device(), image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600954}
955
956TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
957{
958 VkFlags msgFlags;
959 std::string msgString;
960 VkResult err;
961
962 ASSERT_NO_FATAL_FAILURE(InitState());
963 m_errorMonitor->ClearState();
964
965 // Create an image object, allocate memory, destroy the object and then try to bind it
966 VkImage image;
967 VkDeviceMemory mem;
968 VkMemoryRequirements mem_reqs;
969
970 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
971 const int32_t tex_width = 32;
972 const int32_t tex_height = 32;
973
974 VkImageCreateInfo image_create_info = {};
975 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
976 image_create_info.pNext = NULL;
977 image_create_info.imageType = VK_IMAGE_TYPE_2D;
978 image_create_info.format = tex_format;
979 image_create_info.extent.width = tex_width;
980 image_create_info.extent.height = tex_height;
981 image_create_info.extent.depth = 1;
982 image_create_info.mipLevels = 1;
983 image_create_info.arraySize = 1;
984 image_create_info.samples = 1;
985 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
986 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
987 image_create_info.flags = 0;
988
989 VkMemoryAllocInfo mem_alloc = {};
990 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
991 mem_alloc.pNext = NULL;
992 mem_alloc.allocationSize = 0;
993 mem_alloc.memoryTypeIndex = 0;
994
995 err = vkCreateImage(m_device->device(), &image_create_info, &image);
996 ASSERT_VK_SUCCESS(err);
997
998 err = vkGetImageMemoryRequirements(m_device->device(),
999 image,
1000 &mem_reqs);
1001 ASSERT_VK_SUCCESS(err);
1002
1003 mem_alloc.allocationSize = mem_reqs.size;
1004 err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1005 ASSERT_VK_SUCCESS(err);
1006
1007 // Allocate memory
1008 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
1009 ASSERT_VK_SUCCESS(err);
1010
1011 // Introduce validation failure, destroy Image object before binding
1012 vkDestroyImage(m_device->device(), image);
1013 ASSERT_VK_SUCCESS(err);
1014
1015 // Now Try to bind memory to this destroyed object
1016 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1017 // This may very well return an error.
1018 (void) err;
1019
1020 msgFlags = m_errorMonitor->GetState(&msgString);
1021 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while binding memory to a destroyed object";
1022 if (!strstr(msgString.c_str(),"Invalid VkImage Object ")) {
1023 FAIL() << "Error received from BindMemoryToDestroyedObject was not 'Invalid VkImage Object 0x<handle>' but rather '" << msgString.c_str() << "'";
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001024 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001025
1026 vkFreeMemory(m_device->device(), mem);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001027}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001028#endif // OBJ_TRACKER_TESTS
1029
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001030#if DRAW_STATE_TESTS
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001031TEST_F(VkLayerTest, LineWidthStateNotBound)
1032{
1033 VkFlags msgFlags;
1034 std::string msgString;
1035 m_errorMonitor->ClearState();
1036 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
1037
1038 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
1039
1040 msgFlags = m_errorMonitor->GetState(&msgString);
1041 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Line Width State Object";
1042 if (!strstr(msgString.c_str(),"Dynamic line width state not set for this command buffer")) {
1043 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic line width state not set for this command buffer'";
1044 }
1045}
1046
1047TEST_F(VkLayerTest, DepthBiasStateNotBound)
1048{
1049 VkFlags msgFlags;
1050 std::string msgString;
1051 m_errorMonitor->ClearState();
1052 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
1053
1054 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
1055
1056 msgFlags = m_errorMonitor->GetState(&msgString);
1057 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bias State Object";
1058 if (!strstr(msgString.c_str(),"Dynamic depth bias state not set for this command buffer")) {
1059 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bias state not set for this command buffer'";
1060 }
1061}
1062
1063TEST_F(VkLayerTest, ViewportStateNotBound)
1064{
1065 VkFlags msgFlags;
1066 std::string msgString;
1067 m_errorMonitor->ClearState();
1068 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1069
1070 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1071
1072 msgFlags = m_errorMonitor->GetState(&msgString);
1073 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 -06001074 // TODO : Viewport and scissor currently set as a pair in framework so scissor error masks viewport error
1075 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1076 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001077 }
1078}
1079
1080TEST_F(VkLayerTest, ScissorStateNotBound)
1081{
1082 VkFlags msgFlags;
1083 std::string msgString;
1084 m_errorMonitor->ClearState();
1085 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1086
1087 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1088
1089 msgFlags = m_errorMonitor->GetState(&msgString);
1090 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
1091 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1092 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
1093 }
1094}
1095
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001096TEST_F(VkLayerTest, BlendStateNotBound)
1097{
1098 VkFlags msgFlags;
1099 std::string msgString;
1100 m_errorMonitor->ClearState();
1101 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1102
1103 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1104
1105 msgFlags = m_errorMonitor->GetState(&msgString);
1106 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Blend State Object";
1107 if (!strstr(msgString.c_str(),"Dynamic blend object state not set for this command buffer")) {
1108 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic blend object state not set for this command buffer'";
1109 }
1110}
1111
1112TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1113{
1114 VkFlags msgFlags;
1115 std::string msgString;
1116 m_errorMonitor->ClearState();
1117 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1118
1119 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1120
1121 msgFlags = m_errorMonitor->GetState(&msgString);
1122 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bounds State Object";
1123 if (!strstr(msgString.c_str(),"Dynamic depth bounds state not set for this command buffer")) {
1124 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bounds state not set for this command buffer'";
1125 }
1126}
1127
1128TEST_F(VkLayerTest, StencilReadMaskNotSet)
1129{
1130 VkFlags msgFlags;
1131 std::string msgString;
1132 ASSERT_NO_FATAL_FAILURE(InitState());
1133 m_errorMonitor->ClearState();
1134 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1135
1136 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1137
1138 msgFlags = m_errorMonitor->GetState(&msgString);
1139 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Read Mask";
1140 if (!strstr(msgString.c_str(),"Dynamic stencil read mask state not set for this command buffer")) {
1141 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil read mask state not set for this command buffer'";
1142 }
1143}
1144
1145TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1146{
1147 VkFlags msgFlags;
1148 std::string msgString;
1149 ASSERT_NO_FATAL_FAILURE(InitState());
1150 m_errorMonitor->ClearState();
1151 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1152
1153 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1154
1155 msgFlags = m_errorMonitor->GetState(&msgString);
1156 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Write Mask";
1157 if (!strstr(msgString.c_str(),"Dynamic stencil write mask state not set for this command buffer")) {
1158 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil write mask state not set for this command buffer'";
1159 }
1160}
1161
1162TEST_F(VkLayerTest, StencilReferenceNotSet)
1163{
1164 VkFlags msgFlags;
1165 std::string msgString;
1166 m_errorMonitor->ClearState();
1167 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1168
1169 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1170
1171 msgFlags = m_errorMonitor->GetState(&msgString);
1172 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Reference";
1173 if (!strstr(msgString.c_str(),"Dynamic stencil reference state not set for this command buffer")) {
1174 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil reference state not set for this command buffer'";
1175 }
1176}
1177
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001178TEST_F(VkLayerTest, CmdBufferTwoSubmits)
1179{
1180 vk_testing::Fence testFence;
1181 VkFlags msgFlags;
1182 std::string msgString;
1183
1184 VkFenceCreateInfo fenceInfo = {};
1185 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1186 fenceInfo.pNext = NULL;
1187 fenceInfo.flags = 0;
1188
1189 ASSERT_NO_FATAL_FAILURE(InitState());
1190 ASSERT_NO_FATAL_FAILURE(InitViewport());
1191 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1192
1193 // We luck out b/c by default the framework creates CB w/ the VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set
1194 BeginCommandBuffer();
1195 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
1196 EndCommandBuffer();
1197
1198 testFence.init(*m_device, fenceInfo);
1199
1200 // Bypass framework since it does the waits automatically
1201 VkResult err = VK_SUCCESS;
1202 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
1203 ASSERT_VK_SUCCESS( err );
1204
1205 m_errorMonitor->ClearState();
1206 // Cause validation error by re-submitting cmd buffer that should only be submitted once
1207 err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001208
1209 msgFlags = m_errorMonitor->GetState(&msgString);
1210 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 -06001211 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 -06001212 FAIL() << "Error received was not 'CB (0xaddress) was created w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set...'";
1213 }
1214}
1215
Tobin Ehlise4076782015-06-24 15:53:07 -06001216TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001217{
1218 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001219 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001220 std::string msgString;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001221 VkResult err;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001222
1223 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001224 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001225 m_errorMonitor->ClearState();
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001226
1227 VkDescriptorTypeCount ds_type_count = {};
1228 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1229 ds_type_count.count = 1;
1230
1231 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1232 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1233 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001234 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1235 ds_pool_ci.maxSets = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001236 ds_pool_ci.count = 1;
1237 ds_pool_ci.pTypeCount = &ds_type_count;
1238
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001239 VkDescriptorPool ds_pool;
1240 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001241 ASSERT_VK_SUCCESS(err);
1242
1243 VkDescriptorSetLayoutBinding dsl_binding = {};
1244 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1245 dsl_binding.arraySize = 1;
1246 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1247 dsl_binding.pImmutableSamplers = NULL;
1248
1249 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1250 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1251 ds_layout_ci.pNext = NULL;
1252 ds_layout_ci.count = 1;
1253 ds_layout_ci.pBinding = &dsl_binding;
1254
1255 VkDescriptorSetLayout ds_layout;
1256 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1257 ASSERT_VK_SUCCESS(err);
1258
1259 VkDescriptorSet descriptorSet;
1260 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1261 ASSERT_VK_SUCCESS(err);
1262 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1263 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1264 pipe_ms_state_ci.pNext = NULL;
1265 pipe_ms_state_ci.rasterSamples = 1;
1266 pipe_ms_state_ci.sampleShadingEnable = 0;
1267 pipe_ms_state_ci.minSampleShading = 1.0;
1268 pipe_ms_state_ci.pSampleMask = NULL;
1269
1270 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1271 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1272 pipeline_layout_ci.pNext = NULL;
1273 pipeline_layout_ci.descriptorSetCount = 1;
1274 pipeline_layout_ci.pSetLayouts = &ds_layout;
1275 VkPipelineLayout pipeline_layout;
1276
1277 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1278 ASSERT_VK_SUCCESS(err);
1279
1280 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
1281 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1282 // but add it to be able to run on more devices
1283 VkPipelineObj pipe(m_device);
1284 pipe.AddShader(&vs);
1285 pipe.AddShader(&fs);
1286 pipe.SetMSAA(&pipe_ms_state_ci);
1287 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1288 m_errorMonitor->ClearState();
1289 // Calls CreateCommandBuffer
1290 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1291 VkCmdBufferBeginInfo cmd_buf_info = {};
1292 memset(&cmd_buf_info, 0, sizeof(VkCmdBufferBeginInfo));
1293 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1294 cmd_buf_info.pNext = NULL;
1295 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1296 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1297
1298 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1299 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001300 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001301 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 -06001302 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001303 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 -06001304 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001305
1306 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001307 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1308 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001309}
1310
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001311TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1312{
1313 // Initiate Draw w/o a PSO bound
1314 VkFlags msgFlags;
1315 std::string msgString;
1316 VkResult err;
1317
1318 ASSERT_NO_FATAL_FAILURE(InitState());
1319 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1320 m_errorMonitor->ClearState();
1321
1322 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
1323 VkDescriptorTypeCount ds_type_count = {};
1324 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
1325 ds_type_count.count = 1;
1326
1327 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1328 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1329 ds_pool_ci.pNext = NULL;
1330 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1331 ds_pool_ci.maxSets = 1;
1332 ds_pool_ci.count = 1;
1333 ds_pool_ci.pTypeCount = &ds_type_count;
1334
1335 VkDescriptorPool ds_pool;
1336 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1337 ASSERT_VK_SUCCESS(err);
1338
1339 VkDescriptorSetLayoutBinding dsl_binding = {};
1340 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1341 dsl_binding.arraySize = 1;
1342 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1343 dsl_binding.pImmutableSamplers = NULL;
1344
1345 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1346 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1347 ds_layout_ci.pNext = NULL;
1348 ds_layout_ci.count = 1;
1349 ds_layout_ci.pBinding = &dsl_binding;
1350
1351 VkDescriptorSetLayout ds_layout;
1352 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1353 ASSERT_VK_SUCCESS(err);
1354
1355 VkDescriptorSet descriptorSet;
1356 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1357
1358 msgFlags = m_errorMonitor->GetState(&msgString);
1359 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after alloc descriptor from pool w/o requested type";
1360 if (!strstr(msgString.c_str(),"Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ")) {
1361 FAIL() << "Error received was not 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...' but rather '" << msgString.c_str() << "'";
1362 }
1363
1364 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1365 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1366}
1367
Tobin Ehlis3c543112015-10-08 13:13:50 -06001368TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1369{
1370 VkFlags msgFlags;
1371 std::string msgString;
1372 VkResult err;
1373
1374 ASSERT_NO_FATAL_FAILURE(InitState());
1375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1376 m_errorMonitor->ClearState();
1377
1378 VkDescriptorTypeCount ds_type_count = {};
1379 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1380 ds_type_count.count = 1;
1381
1382 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1383 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1384 ds_pool_ci.pNext = NULL;
1385 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT; // Can't free from ONE_SHOT Pool
1386 ds_pool_ci.maxSets = 1;
1387 ds_pool_ci.count = 1;
1388 ds_pool_ci.pTypeCount = &ds_type_count;
1389
1390 VkDescriptorPool ds_pool;
1391 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1392 ASSERT_VK_SUCCESS(err);
1393
1394 VkDescriptorSetLayoutBinding dsl_binding = {};
1395 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1396 dsl_binding.arraySize = 1;
1397 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1398 dsl_binding.pImmutableSamplers = NULL;
1399
1400 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1401 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1402 ds_layout_ci.pNext = NULL;
1403 ds_layout_ci.count = 1;
1404 ds_layout_ci.pBinding = &dsl_binding;
1405
1406 VkDescriptorSetLayout ds_layout;
1407 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1408 ASSERT_VK_SUCCESS(err);
1409
1410 VkDescriptorSet descriptorSet;
1411 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1412 ASSERT_VK_SUCCESS(err);
1413
1414 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1415 msgFlags = m_errorMonitor->GetState(&msgString);
1416 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after freeing descriptor from ONE_SHOT Pool";
1417 if (!strstr(msgString.c_str(),"It is invalid to call vkFreeDescriptorSets() with a pool created with usage type VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT.")) {
1418 FAIL() << "Error received was not 'It is invalid to call vkFreeDescriptorSets() with a pool created with...' but instead it was '" << msgString.c_str() << "'";
1419 }
1420
1421 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1422 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1423}
1424
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001425TEST_F(VkLayerTest, InvalidDescriptorPool)
1426{
1427 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1428 // The DS check for this is after driver has been called to validate DS internal data struct
1429 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001430/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001431 std::string msgString;
1432 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1433 vkResetDescriptorPool(device(), badPool);
1434
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001435 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001436 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 -06001437 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1438 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1439 }*/
1440}
1441
1442TEST_F(VkLayerTest, InvalidDescriptorSet)
1443{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001444 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1445 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001446 // Create a valid cmd buffer
1447 // call vkCmdBindDescriptorSets w/ false DS
1448}
1449
1450TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1451{
1452 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1453 // The DS check for this is after driver has been called to validate DS internal data struct
1454}
1455
1456TEST_F(VkLayerTest, InvalidPipeline)
1457{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001458 // 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
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001460 // Create a valid cmd buffer
1461 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -06001462// VkFlags msgFlags;
1463// std::string msgString;
1464//
1465// ASSERT_NO_FATAL_FAILURE(InitState());
1466// m_errorMonitor->ClearState();
1467// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001468// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001469// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1470// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1471// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001472// 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 -06001473// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1474// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1475// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001476}
1477
Tobin Ehlis254eca02015-06-25 15:46:59 -06001478TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001479{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001480 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001481 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001482 std::string msgString;
1483 VkResult err;
1484
1485 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001486 ASSERT_NO_FATAL_FAILURE(InitViewport());
1487 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001488 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001489 VkDescriptorTypeCount ds_type_count = {};
1490 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1491 ds_type_count.count = 1;
1492
1493 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1494 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1495 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001496 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1497 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001498 ds_pool_ci.count = 1;
1499 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001500
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001501 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001502 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001503 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001504
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001505 VkDescriptorSetLayoutBinding dsl_binding = {};
1506 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1507 dsl_binding.arraySize = 1;
1508 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1509 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001510
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001511 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1512 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1513 ds_layout_ci.pNext = NULL;
1514 ds_layout_ci.count = 1;
1515 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001516 VkDescriptorSetLayout ds_layout;
1517 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1518 ASSERT_VK_SUCCESS(err);
1519
1520 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001521 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001522 ASSERT_VK_SUCCESS(err);
1523
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001524 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1525 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1526 pipeline_layout_ci.pNext = NULL;
1527 pipeline_layout_ci.descriptorSetCount = 1;
1528 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001529
1530 VkPipelineLayout pipeline_layout;
1531 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1532 ASSERT_VK_SUCCESS(err);
1533
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001534 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001535 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1536 // but add it to be able to run on more devices
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001537
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001538 VkPipelineObj pipe(m_device);
1539 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001540 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001541 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001542
1543 BeginCommandBuffer();
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001544 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbour1490c912015-07-28 10:17:20 -06001545 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001546
Tobin Ehlis254eca02015-06-25 15:46:59 -06001547 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001548 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 -06001549 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1550 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1551 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001552
1553 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001554 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1555 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001556}
1557
1558TEST_F(VkLayerTest, NoBeginCmdBuffer)
1559{
1560 VkFlags msgFlags;
1561 std::string msgString;
1562
1563 ASSERT_NO_FATAL_FAILURE(InitState());
1564 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001565 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001566 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1567 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1568 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001569 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 -06001570 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1571 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1572 }
1573}
1574
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001575TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1576{
1577 VkFlags msgFlags;
1578 std::string msgString;
1579
1580 ASSERT_NO_FATAL_FAILURE(InitState());
1581 m_errorMonitor->ClearState();
1582
1583 // Calls CreateCommandBuffer
1584 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1585
1586 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northrop10d8f982015-08-04 17:35:57 -06001587 VkCmdBufferBeginInfo cmd_buf_info = {};
1588 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1589 cmd_buf_info.pNext = NULL;
1590 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1591 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
1592 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1593 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1594
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001595
1596 // The error should be caught by validation of the BeginCommandBuffer call
1597 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1598
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 passing a non-NULL Framebuffer and Renderpass to BeginCommandBuffer()";
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001601 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
1602 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
1603 }
1604}
1605
1606TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1607{
1608 VkFlags msgFlags;
1609 std::string msgString;
1610 VkResult err;
1611 VkCmdBuffer draw_cmd;
1612 VkCmdPool cmd_pool;
1613
1614 ASSERT_NO_FATAL_FAILURE(InitState());
1615 m_errorMonitor->ClearState();
1616
Cody Northrop10d8f982015-08-04 17:35:57 -06001617 VkCmdBufferCreateInfo cmd = {};
1618 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
1619 cmd.pNext = NULL;
1620 cmd.cmdPool = m_cmdPool;
1621 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
1622 cmd.flags = 0;
1623
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001624 err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd);
Mike Stroyan2237f522015-08-18 14:40:24 -06001625 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001626
1627 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northrop10d8f982015-08-04 17:35:57 -06001628 VkCmdBufferBeginInfo cmd_buf_info = {};
1629 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1630 cmd_buf_info.pNext = NULL;
1631 cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
1632 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001633
1634 // The error should be caught by validation of the BeginCommandBuffer call
1635 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1636
1637 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001638 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 -06001639 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
1640 FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
1641 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001642 vkDestroyCommandBuffer(m_device->device(), draw_cmd);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001643}
1644
Tobin Ehlis254eca02015-06-25 15:46:59 -06001645TEST_F(VkLayerTest, InvalidPipelineCreateState)
1646{
1647 // Attempt to Create Gfx Pipeline w/o a VS
1648 VkFlags msgFlags;
1649 std::string msgString;
1650 VkResult err;
1651
1652 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis254eca02015-06-25 15:46:59 -06001654 m_errorMonitor->ClearState();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001655
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001656 VkDescriptorTypeCount ds_type_count = {};
1657 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1658 ds_type_count.count = 1;
1659
1660 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1661 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1662 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001663 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1664 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001665 ds_pool_ci.count = 1;
1666 ds_pool_ci.pTypeCount = &ds_type_count;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001667
Tobin Ehlis254eca02015-06-25 15:46:59 -06001668 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001669 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001670 ASSERT_VK_SUCCESS(err);
1671
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001672 VkDescriptorSetLayoutBinding dsl_binding = {};
1673 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1674 dsl_binding.arraySize = 1;
1675 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1676 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001677
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001678 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1679 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1680 ds_layout_ci.pNext = NULL;
1681 ds_layout_ci.count = 1;
1682 ds_layout_ci.pBinding = &dsl_binding;
1683
Tobin Ehlis254eca02015-06-25 15:46:59 -06001684 VkDescriptorSetLayout ds_layout;
1685 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1686 ASSERT_VK_SUCCESS(err);
1687
1688 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06001689 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001690 ASSERT_VK_SUCCESS(err);
1691
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001692 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1693 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001694 pipeline_layout_ci.descriptorSetCount = 1;
1695 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001696
1697 VkPipelineLayout pipeline_layout;
1698 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1699 ASSERT_VK_SUCCESS(err);
1700
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001701 VkViewport vp = {}; // Just need dummy vp to point to
1702 VkRect2D sc = {}; // dummy scissor to point to
1703
1704 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1705 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1706 vp_state_ci.scissorCount = 1;
1707 vp_state_ci.pScissors = &sc;
1708 vp_state_ci.viewportCount = 1;
1709 vp_state_ci.pViewports = &vp;
1710
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001711 VkGraphicsPipelineCreateInfo gp_ci = {};
1712 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001713 gp_ci.pViewportState = &vp_state_ci;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001714 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1715 gp_ci.layout = pipeline_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001716 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001717
1718 VkPipelineCacheCreateInfo pc_ci = {};
1719 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001720 pc_ci.initialSize = 0;
1721 pc_ci.initialData = 0;
1722 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001723
1724 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001725 VkPipelineCache pipelineCache;
1726
1727 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1728 ASSERT_VK_SUCCESS(err);
1729 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001730
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001731 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001732 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 -06001733 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1734 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1735 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001736
1737 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1738 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001739 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1740 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001741}
Tobin Ehlis20693172015-09-17 08:46:18 -06001742/*// TODO : This test should be good, but needs Tess support in compiler to run
1743TEST_F(VkLayerTest, InvalidPatchControlPoints)
1744{
1745 // Attempt to Create Gfx Pipeline w/o a VS
1746 VkFlags msgFlags;
1747 std::string msgString;
1748 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001749
Tobin Ehlis20693172015-09-17 08:46:18 -06001750 ASSERT_NO_FATAL_FAILURE(InitState());
1751 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1752 m_errorMonitor->ClearState();
1753
1754 VkDescriptorTypeCount ds_type_count = {};
1755 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1756 ds_type_count.count = 1;
1757
1758 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1759 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1760 ds_pool_ci.pNext = NULL;
1761 ds_pool_ci.count = 1;
1762 ds_pool_ci.pTypeCount = &ds_type_count;
1763
1764 VkDescriptorPool ds_pool;
1765 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool);
1766 ASSERT_VK_SUCCESS(err);
1767
1768 VkDescriptorSetLayoutBinding dsl_binding = {};
1769 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1770 dsl_binding.arraySize = 1;
1771 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1772 dsl_binding.pImmutableSamplers = NULL;
1773
1774 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1775 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1776 ds_layout_ci.pNext = NULL;
1777 ds_layout_ci.count = 1;
1778 ds_layout_ci.pBinding = &dsl_binding;
1779
1780 VkDescriptorSetLayout ds_layout;
1781 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1782 ASSERT_VK_SUCCESS(err);
1783
1784 VkDescriptorSet descriptorSet;
1785 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1786 ASSERT_VK_SUCCESS(err);
1787
1788 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1789 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1790 pipeline_layout_ci.pNext = NULL;
1791 pipeline_layout_ci.descriptorSetCount = 1;
1792 pipeline_layout_ci.pSetLayouts = &ds_layout;
1793
1794 VkPipelineLayout pipeline_layout;
1795 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1796 ASSERT_VK_SUCCESS(err);
1797
1798 VkPipelineShaderStageCreateInfo shaderStages[3];
1799 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
1800
1801 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
1802 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001803 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL, this);
1804 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06001805
1806 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1807 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
1808 shaderStages[0].shader = vs.handle();
1809 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001810 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL;
Tobin Ehlis20693172015-09-17 08:46:18 -06001811 shaderStages[1].shader = tc.handle();
1812 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -06001813 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION;
Tobin Ehlis20693172015-09-17 08:46:18 -06001814 shaderStages[2].shader = te.handle();
1815
1816 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
1817 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
1818 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH;
1819
1820 VkPipelineTessellationStateCreateInfo tsCI = {};
1821 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
1822 tsCI.patchControlPoints = 0; // This will cause an error
1823
1824 VkGraphicsPipelineCreateInfo gp_ci = {};
1825 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1826 gp_ci.pNext = NULL;
1827 gp_ci.stageCount = 3;
1828 gp_ci.pStages = shaderStages;
1829 gp_ci.pVertexInputState = NULL;
1830 gp_ci.pInputAssemblyState = &iaCI;
1831 gp_ci.pTessellationState = &tsCI;
1832 gp_ci.pViewportState = NULL;
1833 gp_ci.pRasterState = NULL;
1834 gp_ci.pMultisampleState = NULL;
1835 gp_ci.pDepthStencilState = NULL;
1836 gp_ci.pColorBlendState = NULL;
1837 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1838 gp_ci.layout = pipeline_layout;
1839 gp_ci.renderPass = renderPass();
1840
1841 VkPipelineCacheCreateInfo pc_ci = {};
1842 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1843 pc_ci.pNext = NULL;
1844 pc_ci.initialSize = 0;
1845 pc_ci.initialData = 0;
1846 pc_ci.maxSize = 0;
1847
1848 VkPipeline pipeline;
1849 VkPipelineCache pipelineCache;
1850
1851 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1852 ASSERT_VK_SUCCESS(err);
1853 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1854
1855 msgFlags = m_errorMonitor->GetState(&msgString);
1856 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Tess Gfx Pipeline w/ 0 patchControlPoints.";
1857 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ")) {
1858 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...' but instead '" << msgString.c_str() << "'";
1859 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001860
1861 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1862 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001863 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1864 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis20693172015-09-17 08:46:18 -06001865}
1866*/
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001867// Set scissor and viewport counts to different numbers
1868TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
1869{
1870 // Attempt to Create Gfx Pipeline w/o a VS
1871 VkFlags msgFlags;
1872 std::string msgString;
1873 VkResult err;
1874
1875 ASSERT_NO_FATAL_FAILURE(InitState());
1876 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1877 m_errorMonitor->ClearState();
1878
1879 VkDescriptorTypeCount ds_type_count = {};
1880 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1881 ds_type_count.count = 1;
1882
1883 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1884 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1885 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1886 ds_pool_ci.maxSets = 1;
1887 ds_pool_ci.count = 1;
1888 ds_pool_ci.pTypeCount = &ds_type_count;
1889
1890 VkDescriptorPool ds_pool;
1891 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1892 ASSERT_VK_SUCCESS(err);
1893
1894 VkDescriptorSetLayoutBinding dsl_binding = {};
1895 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1896 dsl_binding.arraySize = 1;
1897 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1898
1899 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1900 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1901 ds_layout_ci.count = 1;
1902 ds_layout_ci.pBinding = &dsl_binding;
1903
1904 VkDescriptorSetLayout ds_layout;
1905 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1906 ASSERT_VK_SUCCESS(err);
1907
1908 VkDescriptorSet descriptorSet;
1909 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
1910 ASSERT_VK_SUCCESS(err);
1911
1912 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1913 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1914 pipeline_layout_ci.descriptorSetCount = 1;
1915 pipeline_layout_ci.pSetLayouts = &ds_layout;
1916
1917 VkPipelineLayout pipeline_layout;
1918 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1919 ASSERT_VK_SUCCESS(err);
1920
1921 VkViewport vp = {}; // Just need dummy vp to point to
1922
1923 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1924 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1925 vp_state_ci.scissorCount = 0;
1926 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
1927 vp_state_ci.pViewports = &vp;
1928
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001929 VkPipelineShaderStageCreateInfo shaderStages[2];
1930 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001931
1932 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001933 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
1934 // but add it to be able to run on more devices
1935 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1936 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
1937 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001938
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001939 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1940 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT;
1941 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001942
1943 VkGraphicsPipelineCreateInfo gp_ci = {};
1944 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06001945 gp_ci.stageCount = 2;
1946 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001947 gp_ci.pViewportState = &vp_state_ci;
1948 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1949 gp_ci.layout = pipeline_layout;
1950 gp_ci.renderPass = renderPass();
1951
1952 VkPipelineCacheCreateInfo pc_ci = {};
1953 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1954
1955 VkPipeline pipeline;
1956 VkPipelineCache pipelineCache;
1957
1958 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1959 ASSERT_VK_SUCCESS(err);
1960 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1961
1962 msgFlags = m_errorMonitor->GetState(&msgString);
1963 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/ viewport and scissor count mismatch.";
1964 if (!strstr(msgString.c_str(),"Gfx Pipeline viewport count (1) must match scissor count (0).")) {
1965 FAIL() << "Error received was not 'Gfx Pipeline viewport count (1) must match scissor count (0).' but instead it was '" << msgString.c_str() << "'";
1966 }
1967
1968 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1969 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001970 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1971 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1972}
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06001973// Don't set viewport state in PSO. This is an error b/c we always need this state
1974// for the counts even if the data is going to be set dynamically.
1975TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001976{
1977 // Attempt to Create Gfx Pipeline w/o a VS
1978 VkFlags msgFlags;
1979 std::string msgString;
1980 VkResult err;
1981
1982 ASSERT_NO_FATAL_FAILURE(InitState());
1983 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1984 m_errorMonitor->ClearState();
1985
1986 VkDescriptorTypeCount ds_type_count = {};
1987 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1988 ds_type_count.count = 1;
1989
1990 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1991 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1992 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
1993 ds_pool_ci.maxSets = 1;
1994 ds_pool_ci.count = 1;
1995 ds_pool_ci.pTypeCount = &ds_type_count;
1996
1997 VkDescriptorPool ds_pool;
1998 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1999 ASSERT_VK_SUCCESS(err);
2000
2001 VkDescriptorSetLayoutBinding dsl_binding = {};
2002 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2003 dsl_binding.arraySize = 1;
2004 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2005
2006 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2007 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2008 ds_layout_ci.count = 1;
2009 ds_layout_ci.pBinding = &dsl_binding;
2010
2011 VkDescriptorSetLayout ds_layout;
2012 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2013 ASSERT_VK_SUCCESS(err);
2014
2015 VkDescriptorSet descriptorSet;
2016 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
2017 ASSERT_VK_SUCCESS(err);
2018
2019 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2020 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2021 pipeline_layout_ci.descriptorSetCount = 1;
2022 pipeline_layout_ci.pSetLayouts = &ds_layout;
2023
2024 VkPipelineLayout pipeline_layout;
2025 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2026 ASSERT_VK_SUCCESS(err);
2027
2028 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2029 // Set scissor as dynamic to avoid second error
2030 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2031 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2032 dyn_state_ci.dynamicStateCount = 1;
2033 dyn_state_ci.pDynamicStates = &sc_state;
2034
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002035 VkPipelineShaderStageCreateInfo shaderStages[2];
2036 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002037
2038 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002039 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2040 // but add it to be able to run on more devices
2041 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2042 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
2043 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002044
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002045 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2046 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT;
2047 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002048
2049 VkGraphicsPipelineCreateInfo gp_ci = {};
2050 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002051 gp_ci.stageCount = 2;
2052 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002053 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2054 gp_ci.pDynamicState = &dyn_state_ci;
2055 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2056 gp_ci.layout = pipeline_layout;
2057 gp_ci.renderPass = renderPass();
2058
2059 VkPipelineCacheCreateInfo pc_ci = {};
2060 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2061
2062 VkPipeline pipeline;
2063 VkPipelineCache pipelineCache;
2064
2065 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2066 ASSERT_VK_SUCCESS(err);
2067 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2068
2069 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002070 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o viewport state set.";
2071 if (!strstr(msgString.c_str(),"Gfx Pipeline pViewportState is null. Even if ")) {
2072 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 -06002073 }
2074
2075 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2076 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002077 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2078 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2079}
2080// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002081// Then run second test where dynamic scissor count doesn't match PSO scissor count
2082TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002083{
2084 VkFlags msgFlags;
2085 std::string msgString;
2086 VkResult err;
2087
2088 ASSERT_NO_FATAL_FAILURE(InitState());
2089 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2090 m_errorMonitor->ClearState();
2091
2092 VkDescriptorTypeCount ds_type_count = {};
2093 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2094 ds_type_count.count = 1;
2095
2096 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2097 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2098 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2099 ds_pool_ci.maxSets = 1;
2100 ds_pool_ci.count = 1;
2101 ds_pool_ci.pTypeCount = &ds_type_count;
2102
2103 VkDescriptorPool ds_pool;
2104 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2105 ASSERT_VK_SUCCESS(err);
2106
2107 VkDescriptorSetLayoutBinding dsl_binding = {};
2108 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2109 dsl_binding.arraySize = 1;
2110 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2111
2112 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2113 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2114 ds_layout_ci.count = 1;
2115 ds_layout_ci.pBinding = &dsl_binding;
2116
2117 VkDescriptorSetLayout ds_layout;
2118 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2119 ASSERT_VK_SUCCESS(err);
2120
2121 VkDescriptorSet descriptorSet;
2122 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
2123 ASSERT_VK_SUCCESS(err);
2124
2125 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2126 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2127 pipeline_layout_ci.descriptorSetCount = 1;
2128 pipeline_layout_ci.pSetLayouts = &ds_layout;
2129
2130 VkPipelineLayout pipeline_layout;
2131 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2132 ASSERT_VK_SUCCESS(err);
2133
2134 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2135 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2136 vp_state_ci.viewportCount = 1;
2137 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2138 vp_state_ci.scissorCount = 1;
2139 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2140
2141 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2142 // Set scissor as dynamic to avoid that error
2143 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2144 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2145 dyn_state_ci.dynamicStateCount = 1;
2146 dyn_state_ci.pDynamicStates = &sc_state;
2147
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002148 VkPipelineShaderStageCreateInfo shaderStages[2];
2149 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002150
2151 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002152 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2153 // but add it to be able to run on more devices
2154 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2155 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
2156 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002157
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002158 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2159 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT;
2160 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002161
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002162 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2163 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2164 vi_ci.pNext = nullptr;
2165 vi_ci.bindingCount = 0;
2166 vi_ci.pVertexBindingDescriptions = nullptr;
2167 vi_ci.attributeCount = 0;
2168 vi_ci.pVertexAttributeDescriptions = nullptr;
2169
2170 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2171 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2172 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2173
2174 VkPipelineRasterStateCreateInfo rs_ci = {};
2175 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2176 rs_ci.pNext = nullptr;
2177
2178 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2179 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2180 cb_ci.pNext = nullptr;
2181
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002182 VkGraphicsPipelineCreateInfo gp_ci = {};
2183 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002184 gp_ci.stageCount = 2;
2185 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002186 gp_ci.pVertexInputState = &vi_ci;
2187 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002188 gp_ci.pViewportState = &vp_state_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002189 gp_ci.pRasterState = &rs_ci;
2190 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002191 gp_ci.pDynamicState = &dyn_state_ci;
2192 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2193 gp_ci.layout = pipeline_layout;
2194 gp_ci.renderPass = renderPass();
2195
2196 VkPipelineCacheCreateInfo pc_ci = {};
2197 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2198
2199 VkPipeline pipeline;
2200 VkPipelineCache pipelineCache;
2201
2202 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2203 ASSERT_VK_SUCCESS(err);
2204 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2205
2206 msgFlags = m_errorMonitor->GetState(&msgString);
2207 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2208 if (!strstr(msgString.c_str(),"Gfx Pipeline viewportCount is 1, but pViewports is NULL. ")) {
2209 FAIL() << "Error received was not 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...' but instead it was '" << msgString.c_str() << "'";
2210 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002211 m_errorMonitor->ClearState();
2212 // Now hit second fail case where we set scissor w/ different count than PSO
2213 // First need to successfully create the PSO from above by setting pViewports
2214 VkViewport vp = {}; // Just need dummy vp to point to
2215 vp_state_ci.pViewports = &vp;
2216 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2217 ASSERT_VK_SUCCESS(err);
2218 BeginCommandBuffer();
2219 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2220 VkRect2D scissors[2] = {}; // don't care about data
2221 // Count of 2 doesn't match PSO count of 1
2222 vkCmdSetScissor(m_cmdBuffer->GetBufferHandle(), 2, scissors);
2223 Draw(1, 0, 0, 0);
2224
2225 msgFlags = m_errorMonitor->GetState(&msgString);
2226 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic scissorCount different from PSO scissorCount.";
2227 if (!strstr(msgString.c_str(),"Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.")) {
2228 FAIL() << "Error received was not 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...' but instead it was '" << msgString.c_str() << "'";
2229 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002230
2231 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2232 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002233 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2234 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2235}
2236// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002237// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2238TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002239{
2240 VkFlags msgFlags;
2241 std::string msgString;
2242 VkResult err;
2243
2244 ASSERT_NO_FATAL_FAILURE(InitState());
2245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2246 m_errorMonitor->ClearState();
2247
2248 VkDescriptorTypeCount ds_type_count = {};
2249 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2250 ds_type_count.count = 1;
2251
2252 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2253 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2254 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2255 ds_pool_ci.maxSets = 1;
2256 ds_pool_ci.count = 1;
2257 ds_pool_ci.pTypeCount = &ds_type_count;
2258
2259 VkDescriptorPool ds_pool;
2260 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2261 ASSERT_VK_SUCCESS(err);
2262
2263 VkDescriptorSetLayoutBinding dsl_binding = {};
2264 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2265 dsl_binding.arraySize = 1;
2266 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2267
2268 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2269 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2270 ds_layout_ci.count = 1;
2271 ds_layout_ci.pBinding = &dsl_binding;
2272
2273 VkDescriptorSetLayout ds_layout;
2274 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2275 ASSERT_VK_SUCCESS(err);
2276
2277 VkDescriptorSet descriptorSet;
2278 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
2279 ASSERT_VK_SUCCESS(err);
2280
2281 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2282 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2283 pipeline_layout_ci.descriptorSetCount = 1;
2284 pipeline_layout_ci.pSetLayouts = &ds_layout;
2285
2286 VkPipelineLayout pipeline_layout;
2287 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2288 ASSERT_VK_SUCCESS(err);
2289
2290 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2291 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2292 vp_state_ci.scissorCount = 1;
2293 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2294 vp_state_ci.viewportCount = 1;
2295 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2296
2297 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2298 // Set scissor as dynamic to avoid that error
2299 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2300 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2301 dyn_state_ci.dynamicStateCount = 1;
2302 dyn_state_ci.pDynamicStates = &vp_state;
2303
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002304 VkPipelineShaderStageCreateInfo shaderStages[2];
2305 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002306
2307 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX, this);
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002308 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
2309 // but add it to be able to run on more devices
2310 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2311 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX;
2312 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002313
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002314 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
2315 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT;
2316 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002317
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002318 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2319 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2320 vi_ci.pNext = nullptr;
2321 vi_ci.bindingCount = 0;
2322 vi_ci.pVertexBindingDescriptions = nullptr;
2323 vi_ci.attributeCount = 0;
2324 vi_ci.pVertexAttributeDescriptions = nullptr;
2325
2326 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2327 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2328 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2329
2330 VkPipelineRasterStateCreateInfo rs_ci = {};
2331 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2332 rs_ci.pNext = nullptr;
2333
2334 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2335 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2336 cb_ci.pNext = nullptr;
2337
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002338 VkGraphicsPipelineCreateInfo gp_ci = {};
2339 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002340 gp_ci.stageCount = 2;
2341 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002342 gp_ci.pVertexInputState = &vi_ci;
2343 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002344 gp_ci.pViewportState = &vp_state_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002345 gp_ci.pRasterState = &rs_ci;
2346 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002347 gp_ci.pDynamicState = &dyn_state_ci;
2348 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2349 gp_ci.layout = pipeline_layout;
2350 gp_ci.renderPass = renderPass();
2351
2352 VkPipelineCacheCreateInfo pc_ci = {};
2353 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2354
2355 VkPipeline pipeline;
2356 VkPipelineCache pipelineCache;
2357
2358 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2359 ASSERT_VK_SUCCESS(err);
2360 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2361
2362 msgFlags = m_errorMonitor->GetState(&msgString);
2363 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2364 if (!strstr(msgString.c_str(),"Gfx Pipeline scissorCount is 1, but pScissors is NULL. ")) {
2365 FAIL() << "Error received was not 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...' but instead it was '" << msgString.c_str() << "'";
2366 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002367 m_errorMonitor->ClearState();
2368 // Now hit second fail case where we set scissor w/ different count than PSO
2369 // First need to successfully create the PSO from above by setting pViewports
2370 VkRect2D sc = {}; // Just need dummy vp to point to
2371 vp_state_ci.pScissors = &sc;
2372 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2373 ASSERT_VK_SUCCESS(err);
2374 BeginCommandBuffer();
2375 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2376 VkViewport viewports[2] = {}; // don't care about data
2377 // Count of 2 doesn't match PSO count of 1
2378 vkCmdSetViewport(m_cmdBuffer->GetBufferHandle(), 2, viewports);
2379 Draw(1, 0, 0, 0);
2380
2381 msgFlags = m_errorMonitor->GetState(&msgString);
2382 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic viewportCount different from PSO viewportCount.";
2383 if (!strstr(msgString.c_str(),"Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.")) {
2384 FAIL() << "Error received was not 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...' but instead it was '" << msgString.c_str() << "'";
2385 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002386
2387 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2388 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002389 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2390 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2391}
2392
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002393TEST_F(VkLayerTest, NullRenderPass)
2394{
2395 // Bind a NULL RenderPass
2396 VkFlags msgFlags;
2397 std::string msgString;
2398
2399 ASSERT_NO_FATAL_FAILURE(InitState());
2400 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2401 m_errorMonitor->ClearState();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002402
Tony Barbour1490c912015-07-28 10:17:20 -06002403 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002404 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06002405 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002406
2407 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002408 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002409 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
2410 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
2411 }
2412}
2413
Tobin Ehlis254eca02015-06-25 15:46:59 -06002414TEST_F(VkLayerTest, RenderPassWithinRenderPass)
2415{
2416 // Bind a BeginRenderPass within an active RenderPass
2417 VkFlags msgFlags;
2418 std::string msgString;
2419
2420 ASSERT_NO_FATAL_FAILURE(InitState());
2421 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2422 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06002423
Tony Barbour1490c912015-07-28 10:17:20 -06002424 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002425 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002426 VkRenderPassBeginInfo rp_begin = {};
2427 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
2428 rp_begin.pNext = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002429 rp_begin.renderPass = renderPass();
2430 rp_begin.framebuffer = framebuffer();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002431
Tony Barbour1490c912015-07-28 10:17:20 -06002432 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002433
2434 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002435 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 -06002436 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2437 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002438 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002439}
2440
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002441TEST_F(VkLayerTest, FillBufferWithinRenderPass)
2442{
2443 // Call CmdFillBuffer within an active renderpass
2444 VkFlags msgFlags;
2445 std::string msgString;
2446
2447 ASSERT_NO_FATAL_FAILURE(InitState());
2448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2449 m_errorMonitor->ClearState();
2450
2451 // Renderpass is started here
2452 BeginCommandBuffer();
2453
2454 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2455 vk_testing::Buffer destBuffer;
2456 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
2457
2458 m_cmdBuffer->FillBuffer(destBuffer.handle(), 0, 4, 0x11111111);
2459
2460 msgFlags = m_errorMonitor->GetState(&msgString);
2461 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2462 "Did not receive error after calling CmdFillBuffer w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002463 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2464 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002465 }
2466}
2467
2468TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
2469{
2470 // Call CmdUpdateBuffer within an active renderpass
2471 VkFlags msgFlags;
2472 std::string msgString;
2473
2474 ASSERT_NO_FATAL_FAILURE(InitState());
2475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2476 m_errorMonitor->ClearState();
2477
2478 // Renderpass is started here
2479 BeginCommandBuffer();
2480
2481 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2482 vk_testing::Buffer destBuffer;
2483 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
2484
2485 VkDeviceSize destOffset = 0;
2486 VkDeviceSize dataSize = 1024;
2487 const uint32_t *pData = NULL;
2488
2489 vkCmdUpdateBuffer(m_cmdBuffer->GetBufferHandle(), destBuffer.handle(), destOffset, dataSize, pData);
2490
2491 msgFlags = m_errorMonitor->GetState(&msgString);
2492 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2493 "Did not receive error after calling CmdUpdateBuffer 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, ClearColorImageWithinRenderPass)
2500{
2501 // Call CmdClearColorImage 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 VkClearColorValue clear_color = {0};
2513 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2514 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2515 const int32_t tex_width = 32;
2516 const int32_t tex_height = 32;
2517 VkImageCreateInfo image_create_info = {};
2518 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2519 image_create_info.pNext = NULL;
2520 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2521 image_create_info.format = tex_format;
2522 image_create_info.extent.width = tex_width;
2523 image_create_info.extent.height = tex_height;
2524 image_create_info.extent.depth = 1;
2525 image_create_info.mipLevels = 1;
2526 image_create_info.arraySize = 1;
2527 image_create_info.samples = 1;
2528 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2529 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2530
2531 vk_testing::Image destImage;
2532 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
2533
2534 const VkImageSubresourceRange range =
2535 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
2536
2537 vkCmdClearColorImage(m_cmdBuffer->GetBufferHandle(),
2538 destImage.handle(),
2539 VK_IMAGE_LAYOUT_GENERAL,
2540 &clear_color,
2541 1,
2542 &range);
2543
2544 msgFlags = m_errorMonitor->GetState(&msgString);
2545 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2546 "Did not receive error after calling CmdClearColorImage w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002547 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2548 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002549 }
2550}
2551
2552TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
2553{
2554 // Call CmdClearDepthStencilImage within an active RenderPass
2555 VkFlags msgFlags;
2556 std::string msgString;
2557
2558 ASSERT_NO_FATAL_FAILURE(InitState());
2559 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2560 m_errorMonitor->ClearState();
2561
2562 // Renderpass is started here
2563 BeginCommandBuffer();
2564
2565 VkClearDepthStencilValue clear_value = {0};
2566 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2567 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
2568 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2569 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
2570 image_create_info.extent.width = 64;
2571 image_create_info.extent.height = 64;
2572 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2573 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
2574
2575 vk_testing::Image destImage;
2576 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
2577
2578 const VkImageSubresourceRange range =
2579 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
2580
2581 vkCmdClearDepthStencilImage(m_cmdBuffer->GetBufferHandle(),
2582 destImage.handle(),
2583 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2584 &clear_value,
2585 1,
2586 &range);
2587
2588 msgFlags = m_errorMonitor->GetState(&msgString);
2589 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2590 "Did not receive error after calling CmdClearDepthStencilImage w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002591 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2592 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002593 }
2594}
2595
2596TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
2597{
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002598 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002599 VkFlags msgFlags;
2600 std::string msgString;
2601 VkResult err;
2602
2603 ASSERT_NO_FATAL_FAILURE(InitState());
2604 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2605 m_errorMonitor->ClearState();
2606
2607 // Start no RenderPass
2608 err = m_cmdBuffer->BeginCommandBuffer();
2609 ASSERT_VK_SUCCESS(err);
2610
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002611 VkClearAttachment color_attachment;
2612 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2613 color_attachment.clearValue.color.float32[0] = 0;
2614 color_attachment.clearValue.color.float32[1] = 0;
2615 color_attachment.clearValue.color.float32[2] = 0;
2616 color_attachment.clearValue.color.float32[3] = 0;
2617 color_attachment.colorAttachment = 0;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002618 VkRect3D clear_rect = { { 0, 0, 0 }, { 32, 32, 1 } };
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002619 vkCmdClearAttachments(m_cmdBuffer->GetBufferHandle(),
2620 1, &color_attachment,
2621 1, &clear_rect);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002622
2623 msgFlags = m_errorMonitor->GetState(&msgString);
2624 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002625 "Did not receive error after calling CmdClearAttachments outside of an active RenderPass.";
2626 if (!strstr(msgString.c_str(),"vkCmdClearAttachments: This call must be issued inside an active render pass")) {
2627 FAIL() << "Error received was not 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002628 }
2629}
2630
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002631TEST_F(VkLayerTest, InvalidDynamicStateObject)
2632{
2633 // Create a valid cmd buffer
2634 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002635 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
2636 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002637}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06002638
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002639TEST_F(VkLayerTest, IdxBufferAlignmentError)
2640{
2641 // Bind a BeginRenderPass within an active RenderPass
2642 VkFlags msgFlags;
2643 std::string msgString;
2644 VkResult err;
2645
2646 ASSERT_NO_FATAL_FAILURE(InitState());
2647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2648 m_errorMonitor->ClearState();
2649 uint32_t qfi = 0;
2650 VkBufferCreateInfo buffCI = {};
2651 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2652 buffCI.size = 1024;
2653 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
2654 buffCI.queueFamilyCount = 1;
2655 buffCI.pQueueFamilyIndices = &qfi;
2656
2657 VkBuffer ib;
2658 err = vkCreateBuffer(m_device->device(), &buffCI, &ib);
2659 ASSERT_VK_SUCCESS(err);
2660
2661 BeginCommandBuffer();
2662 ASSERT_VK_SUCCESS(err);
2663 //vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2664 // Should error before calling to driver so don't care about actual data
2665 vkCmdBindIndexBuffer(m_cmdBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
2666
2667 msgFlags = m_errorMonitor->GetState(&msgString);
2668 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2669 if (!strstr(msgString.c_str(),"vkCmdBindIndexBuffer() offset (0x7) does not fall on ")) {
2670 FAIL() << "Error received was not 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...' but instead '" << msgString.c_str() << "'";
2671 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002672
2673 vkDestroyBuffer(m_device->device(), ib);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002674}
2675
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002676TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
2677{
2678 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
2679 VkFlags msgFlags;
2680 std::string msgString;
2681
2682 ASSERT_NO_FATAL_FAILURE(InitState());
2683 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2684 m_errorMonitor->ClearState();
2685
2686 BeginCommandBuffer();
2687 //ASSERT_VK_SUCCESS(err);
2688 VkCmdBuffer primCB = m_cmdBuffer->GetBufferHandle();
2689 vkCmdExecuteCommands(m_cmdBuffer->GetBufferHandle(), 1, &primCB);
2690
2691 msgFlags = m_errorMonitor->GetState(&msgString);
2692 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2693 if (!strstr(msgString.c_str(),"vkCmdExecuteCommands() called w/ Primary Cmd Buffer ")) {
2694 FAIL() << "Error received was not 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer ' but instead '" << msgString.c_str() << "'";
2695 }
2696}
2697
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002698TEST_F(VkLayerTest, DSTypeMismatch)
2699{
2700 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002701 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002702 std::string msgString;
2703 VkResult err;
2704
2705 ASSERT_NO_FATAL_FAILURE(InitState());
2706 m_errorMonitor->ClearState();
2707 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002708 VkDescriptorTypeCount ds_type_count = {};
2709 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2710 ds_type_count.count = 1;
2711
2712 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2713 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2714 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002715 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2716 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002717 ds_pool_ci.count = 1;
2718 ds_pool_ci.pTypeCount = &ds_type_count;
2719
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002720 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002721 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002722 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002723 VkDescriptorSetLayoutBinding dsl_binding = {};
2724 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2725 dsl_binding.arraySize = 1;
2726 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2727 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002728
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002729 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2730 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2731 ds_layout_ci.pNext = NULL;
2732 ds_layout_ci.count = 1;
2733 ds_layout_ci.pBinding = &dsl_binding;
2734
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002735 VkDescriptorSetLayout ds_layout;
2736 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2737 ASSERT_VK_SUCCESS(err);
2738
2739 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002740 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002741 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002742
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002743 VkSamplerCreateInfo sampler_ci = {};
2744 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2745 sampler_ci.pNext = NULL;
2746 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2747 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2748 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002749 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2750 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2751 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002752 sampler_ci.mipLodBias = 1.0;
2753 sampler_ci.maxAnisotropy = 1;
2754 sampler_ci.compareEnable = VK_FALSE;
2755 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2756 sampler_ci.minLod = 1.0;
2757 sampler_ci.maxLod = 1.0;
2758 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002759 sampler_ci.unnormalizedCoordinates = VK_FALSE;
2760
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002761 VkSampler sampler;
2762 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2763 ASSERT_VK_SUCCESS(err);
2764
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002765 VkDescriptorInfo descriptor_info;
2766 memset(&descriptor_info, 0, sizeof(descriptor_info));
2767 descriptor_info.sampler = sampler;
2768
2769 VkWriteDescriptorSet descriptor_write;
2770 memset(&descriptor_write, 0, sizeof(descriptor_write));
2771 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2772 descriptor_write.destSet = descriptorSet;
2773 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002774 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002775 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2776 descriptor_write.pDescriptors = &descriptor_info;
2777
2778 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2779
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002780 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002781 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 -06002782 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 ")) {
2783 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 -06002784 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002785
2786 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06002787 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2788 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002789}
2790
2791TEST_F(VkLayerTest, DSUpdateOutOfBounds)
2792{
2793 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002794 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002795 std::string msgString;
2796 VkResult err;
2797
2798 ASSERT_NO_FATAL_FAILURE(InitState());
2799 m_errorMonitor->ClearState();
2800 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002801 VkDescriptorTypeCount ds_type_count = {};
2802 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2803 ds_type_count.count = 1;
2804
2805 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2806 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2807 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002808 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2809 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002810 ds_pool_ci.count = 1;
2811 ds_pool_ci.pTypeCount = &ds_type_count;
2812
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002813 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002814 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002815 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002816
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002817 VkDescriptorSetLayoutBinding dsl_binding = {};
2818 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2819 dsl_binding.arraySize = 1;
2820 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2821 dsl_binding.pImmutableSamplers = NULL;
2822
2823 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2824 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2825 ds_layout_ci.pNext = NULL;
2826 ds_layout_ci.count = 1;
2827 ds_layout_ci.pBinding = &dsl_binding;
2828
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002829 VkDescriptorSetLayout ds_layout;
2830 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2831 ASSERT_VK_SUCCESS(err);
2832
2833 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002834 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002835 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002836
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002837 VkSamplerCreateInfo sampler_ci = {};
2838 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2839 sampler_ci.pNext = NULL;
2840 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2841 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2842 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002843 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2844 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2845 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002846 sampler_ci.mipLodBias = 1.0;
2847 sampler_ci.maxAnisotropy = 1;
2848 sampler_ci.compareEnable = VK_FALSE;
2849 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2850 sampler_ci.minLod = 1.0;
2851 sampler_ci.maxLod = 1.0;
2852 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002853 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002854
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002855 VkSampler sampler;
2856 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2857 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002858
2859 VkDescriptorInfo descriptor_info;
2860 memset(&descriptor_info, 0, sizeof(descriptor_info));
2861 descriptor_info.sampler = sampler;
2862
2863 VkWriteDescriptorSet descriptor_write;
2864 memset(&descriptor_write, 0, sizeof(descriptor_write));
2865 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2866 descriptor_write.destSet = descriptorSet;
2867 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
2868 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002869 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002870 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2871 descriptor_write.pDescriptors = &descriptor_info;
2872
2873 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2874
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002875 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002876 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 +08002877 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
2878 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 -06002879 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002880
2881 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06002882 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2883 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002884}
2885
2886TEST_F(VkLayerTest, InvalidDSUpdateIndex)
2887{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002888 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002889 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002890 std::string msgString;
2891 VkResult err;
2892
2893 ASSERT_NO_FATAL_FAILURE(InitState());
2894 m_errorMonitor->ClearState();
2895 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002896 VkDescriptorTypeCount ds_type_count = {};
2897 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2898 ds_type_count.count = 1;
2899
2900 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2901 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2902 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002903 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2904 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002905 ds_pool_ci.count = 1;
2906 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002907
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002908 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002909 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002910 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002911
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002912 VkDescriptorSetLayoutBinding dsl_binding = {};
2913 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2914 dsl_binding.arraySize = 1;
2915 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2916 dsl_binding.pImmutableSamplers = NULL;
2917
2918 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2919 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2920 ds_layout_ci.pNext = NULL;
2921 ds_layout_ci.count = 1;
2922 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002923 VkDescriptorSetLayout ds_layout;
2924 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2925 ASSERT_VK_SUCCESS(err);
2926
2927 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06002928 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002929 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002930
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002931 VkSamplerCreateInfo sampler_ci = {};
2932 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2933 sampler_ci.pNext = NULL;
2934 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2935 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2936 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002937 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2938 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2939 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002940 sampler_ci.mipLodBias = 1.0;
2941 sampler_ci.maxAnisotropy = 1;
2942 sampler_ci.compareEnable = VK_FALSE;
2943 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2944 sampler_ci.minLod = 1.0;
2945 sampler_ci.maxLod = 1.0;
2946 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002947 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002948
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002949 VkSampler sampler;
2950 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2951 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002952
2953 VkDescriptorInfo descriptor_info;
2954 memset(&descriptor_info, 0, sizeof(descriptor_info));
2955 descriptor_info.sampler = sampler;
2956
2957 VkWriteDescriptorSet descriptor_write;
2958 memset(&descriptor_write, 0, sizeof(descriptor_write));
2959 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2960 descriptor_write.destSet = descriptorSet;
2961 descriptor_write.destBinding = 2;
2962 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002963 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002964 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2965 descriptor_write.pDescriptors = &descriptor_info;
2966
2967 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2968
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002969 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002970 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 -06002971 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
2972 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
2973 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002974
2975 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06002976 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2977 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002978}
2979
2980TEST_F(VkLayerTest, InvalidDSUpdateStruct)
2981{
2982 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002983 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002984 std::string msgString;
2985 VkResult err;
2986
2987 ASSERT_NO_FATAL_FAILURE(InitState());
2988 m_errorMonitor->ClearState();
2989 //VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002990
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002991 VkDescriptorTypeCount ds_type_count = {};
2992 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2993 ds_type_count.count = 1;
2994
2995 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2996 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2997 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002998 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
2999 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003000 ds_pool_ci.count = 1;
3001 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003002
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003003 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003004 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003005 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003006 VkDescriptorSetLayoutBinding dsl_binding = {};
3007 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3008 dsl_binding.arraySize = 1;
3009 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3010 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003011
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003012 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3013 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3014 ds_layout_ci.pNext = NULL;
3015 ds_layout_ci.count = 1;
3016 ds_layout_ci.pBinding = &dsl_binding;
3017
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003018 VkDescriptorSetLayout ds_layout;
3019 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3020 ASSERT_VK_SUCCESS(err);
3021
3022 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06003023 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003024 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003025
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003026 VkSamplerCreateInfo sampler_ci = {};
3027 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3028 sampler_ci.pNext = NULL;
3029 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
3030 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
3031 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06003032 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
3033 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
3034 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003035 sampler_ci.mipLodBias = 1.0;
3036 sampler_ci.maxAnisotropy = 1;
3037 sampler_ci.compareEnable = VK_FALSE;
3038 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3039 sampler_ci.minLod = 1.0;
3040 sampler_ci.maxLod = 1.0;
3041 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003042 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003043 VkSampler sampler;
3044 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
3045 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003046
3047
3048 VkDescriptorInfo descriptor_info;
3049 memset(&descriptor_info, 0, sizeof(descriptor_info));
3050 descriptor_info.sampler = sampler;
3051
3052 VkWriteDescriptorSet descriptor_write;
3053 memset(&descriptor_write, 0, sizeof(descriptor_write));
3054 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
3055 descriptor_write.destSet = descriptorSet;
3056 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003057 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003058 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3059 descriptor_write.pDescriptors = &descriptor_info;
3060
3061 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3062
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003063 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003064 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 -06003065 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
3066 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
3067 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003068
3069 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06003070 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3071 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003072}
3073
3074TEST_F(VkLayerTest, NumSamplesMismatch)
3075{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003076 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003077 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003078 std::string msgString;
3079 VkResult err;
3080
3081 ASSERT_NO_FATAL_FAILURE(InitState());
3082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3083 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003084 VkDescriptorTypeCount ds_type_count = {};
3085 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3086 ds_type_count.count = 1;
3087
3088 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003089 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3090 ds_pool_ci.pNext = NULL;
3091 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
3092 ds_pool_ci.maxSets = 1;
3093 ds_pool_ci.count = 1;
3094 ds_pool_ci.pTypeCount = &ds_type_count;
3095
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003096 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003097 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003098 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003099
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003100 VkDescriptorSetLayoutBinding dsl_binding = {};
3101 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3102 dsl_binding.arraySize = 1;
3103 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3104 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003105
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003106 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3107 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3108 ds_layout_ci.pNext = NULL;
3109 ds_layout_ci.count = 1;
3110 ds_layout_ci.pBinding = &dsl_binding;
3111
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003112 VkDescriptorSetLayout ds_layout;
3113 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3114 ASSERT_VK_SUCCESS(err);
3115
3116 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06003117 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003118 ASSERT_VK_SUCCESS(err);
3119
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003120 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3121 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3122 pipe_ms_state_ci.pNext = NULL;
3123 pipe_ms_state_ci.rasterSamples = 4;
3124 pipe_ms_state_ci.sampleShadingEnable = 0;
3125 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003126 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003127
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003128 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3129 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3130 pipeline_layout_ci.pNext = NULL;
3131 pipeline_layout_ci.descriptorSetCount = 1;
3132 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003133
3134 VkPipelineLayout pipeline_layout;
3135 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3136 ASSERT_VK_SUCCESS(err);
3137
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06003138 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003139 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
3140 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003141 VkPipelineObj pipe(m_device);
3142 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003143 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003144 pipe.SetMSAA(&pipe_ms_state_ci);
3145 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003146
Tony Barbour1490c912015-07-28 10:17:20 -06003147 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06003148 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003149
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003150 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003151 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 -06003152 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
3153 FAIL() << "Error received was not 'Num samples mismatch!...'";
3154 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003155
3156 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06003157 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3158 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003159}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003160
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003161TEST_F(VkLayerTest, ClearCmdNoDraw)
3162{
3163 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
3164 VkFlags msgFlags;
3165 std::string msgString;
3166 VkResult err;
3167
3168 ASSERT_NO_FATAL_FAILURE(InitState());
3169 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3170 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003171
3172 VkDescriptorTypeCount ds_type_count = {};
3173 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3174 ds_type_count.count = 1;
3175
3176 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3177 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3178 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003179 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
3180 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003181 ds_pool_ci.count = 1;
3182 ds_pool_ci.pTypeCount = &ds_type_count;
3183
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003184 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003185 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003186 ASSERT_VK_SUCCESS(err);
3187
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003188 VkDescriptorSetLayoutBinding dsl_binding = {};
3189 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3190 dsl_binding.arraySize = 1;
3191 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3192 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003193
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003194 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3195 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3196 ds_layout_ci.pNext = NULL;
3197 ds_layout_ci.count = 1;
3198 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003199
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003200 VkDescriptorSetLayout ds_layout;
3201 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3202 ASSERT_VK_SUCCESS(err);
3203
3204 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06003205 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003206 ASSERT_VK_SUCCESS(err);
3207
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003208 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3209 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3210 pipe_ms_state_ci.pNext = NULL;
3211 pipe_ms_state_ci.rasterSamples = 4;
3212 pipe_ms_state_ci.sampleShadingEnable = 0;
3213 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003214 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003215
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003216 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3217 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3218 pipeline_layout_ci.pNext = NULL;
3219 pipeline_layout_ci.descriptorSetCount = 1;
3220 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003221
3222 VkPipelineLayout pipeline_layout;
3223 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3224 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003225
Tony Barbourd7d828b2015-08-06 10:16:07 -06003226 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003227 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
3228 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003229 VkPipelineObj pipe(m_device);
3230 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003231 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003232 pipe.SetMSAA(&pipe_ms_state_ci);
3233 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003234
3235 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003236
3237 m_errorMonitor->ClearState();
3238 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
3239 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003240 VkClearAttachment color_attachment;
3241 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3242 color_attachment.clearValue.color.float32[0] = 1.0;
3243 color_attachment.clearValue.color.float32[1] = 1.0;
3244 color_attachment.clearValue.color.float32[2] = 1.0;
3245 color_attachment.clearValue.color.float32[3] = 1.0;
3246 color_attachment.colorAttachment = 0;
3247 VkRect3D clear_rect = { { 0, 0, 0 }, { (int)m_width, (int)m_height, 1 } };
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003248
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003249 vkCmdClearAttachments(m_cmdBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003250 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003251 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 -06003252 if (!strstr(msgString.c_str(),"vkCmdClearAttachments() issued on CB object ")) {
3253 FAIL() << "Error received was not 'vkCmdClearAttachments() issued on CB object...'";
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003254 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003255
3256 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06003257 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3258 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003259}
3260
Tobin Ehlise4076782015-06-24 15:53:07 -06003261TEST_F(VkLayerTest, VtxBufferBadIndex)
3262{
3263 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
3264 VkFlags msgFlags;
3265 std::string msgString;
3266 VkResult err;
3267
3268 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003269 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlise4076782015-06-24 15:53:07 -06003270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3271 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003272
3273 VkDescriptorTypeCount ds_type_count = {};
3274 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3275 ds_type_count.count = 1;
3276
3277 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3278 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3279 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003280 ds_pool_ci.poolUsage = VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT;
3281 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003282 ds_pool_ci.count = 1;
3283 ds_pool_ci.pTypeCount = &ds_type_count;
3284
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003285 VkDescriptorPool ds_pool;
3286 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06003287 ASSERT_VK_SUCCESS(err);
3288
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003289 VkDescriptorSetLayoutBinding dsl_binding = {};
3290 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3291 dsl_binding.arraySize = 1;
3292 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3293 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003294
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003295 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3296 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3297 ds_layout_ci.pNext = NULL;
3298 ds_layout_ci.count = 1;
3299 ds_layout_ci.pBinding = &dsl_binding;
3300
Tobin Ehlise4076782015-06-24 15:53:07 -06003301 VkDescriptorSetLayout ds_layout;
3302 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3303 ASSERT_VK_SUCCESS(err);
3304
3305 VkDescriptorSet descriptorSet;
Cody Northropc8aa4a52015-08-03 12:47:29 -06003306 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06003307 ASSERT_VK_SUCCESS(err);
3308
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003309 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3310 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3311 pipe_ms_state_ci.pNext = NULL;
3312 pipe_ms_state_ci.rasterSamples = 1;
3313 pipe_ms_state_ci.sampleShadingEnable = 0;
3314 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003315 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003316
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003317 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3318 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3319 pipeline_layout_ci.pNext = NULL;
3320 pipeline_layout_ci.descriptorSetCount = 1;
3321 pipeline_layout_ci.pSetLayouts = &ds_layout;
3322 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06003323
Tobin Ehlise4076782015-06-24 15:53:07 -06003324 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3325 ASSERT_VK_SUCCESS(err);
3326
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06003327 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003328 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT, this); // TODO - We shouldn't need a fragment shader
3329 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003330 VkPipelineObj pipe(m_device);
3331 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003332 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003333 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003334 pipe.SetViewport(m_viewports);
3335 pipe.SetScissor(m_scissors);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003336 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003337
3338 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06003339 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06003340 // Don't care about actual data, just need to get to draw to flag error
3341 static const float vbo_data[3] = {1.f, 0.f, 1.f};
3342 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
3343 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003344 Draw(1, 0, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06003345
3346 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003347 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 -06003348 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 -06003349 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 -06003350 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003351
3352 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06003353 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3354 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06003355}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003356#endif // DRAW_STATE_TESTS
3357
Tobin Ehlis57e6a612015-05-26 16:11:58 -06003358#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06003359#if GTEST_IS_THREADSAFE
3360struct thread_data_struct {
3361 VkCmdBuffer cmdBuffer;
3362 VkEvent event;
3363 bool bailout;
3364};
3365
3366extern "C" void *AddToCommandBuffer(void *arg)
3367{
3368 struct thread_data_struct *data = (struct thread_data_struct *) arg;
3369 std::string msgString;
3370
3371 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06003372 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06003373 if (data->bailout) {
3374 break;
3375 }
3376 }
3377 return NULL;
3378}
3379
3380TEST_F(VkLayerTest, ThreadCmdBufferCollision)
3381{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003382 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06003383 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003384 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06003385
3386 ASSERT_NO_FATAL_FAILURE(InitState());
3387 ASSERT_NO_FATAL_FAILURE(InitViewport());
3388 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3389
Mike Stroyan09aae812015-05-12 16:00:45 -06003390 m_errorMonitor->ClearState();
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003391
3392 // Calls CreateCommandBuffer
3393 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
3394
3395 // Avoid creating RenderPass
3396 cmdBuffer.BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06003397
3398 VkEventCreateInfo event_info;
3399 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06003400 VkResult err;
3401
3402 memset(&event_info, 0, sizeof(event_info));
3403 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3404
3405 err = vkCreateEvent(device(), &event_info, &event);
3406 ASSERT_VK_SUCCESS(err);
3407
Mike Stroyan09aae812015-05-12 16:00:45 -06003408 err = vkResetEvent(device(), event);
3409 ASSERT_VK_SUCCESS(err);
3410
3411 struct thread_data_struct data;
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003412 data.cmdBuffer = cmdBuffer.GetBufferHandle();
Mike Stroyan09aae812015-05-12 16:00:45 -06003413 data.event = event;
3414 data.bailout = false;
3415 m_errorMonitor->SetBailout(&data.bailout);
3416 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003417 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06003418 // Add many entries to command buffer from this thread at the same time.
3419 AddToCommandBuffer(&data);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003420
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003421 test_platform_thread_join(thread, NULL);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003422 cmdBuffer.EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06003423
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003424 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003425 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 -06003426 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05003427 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06003428 }
3429
Mike Stroyan2237f522015-08-18 14:40:24 -06003430 vkDestroyEvent(device(), event);
Mike Stroyan09aae812015-05-12 16:00:45 -06003431}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003432#endif // GTEST_IS_THREADSAFE
3433#endif // THREADING_TESTS
3434
Chris Forbes5af3bf22015-05-25 11:13:08 +12003435#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003436TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
3437{
3438 VkFlags msgFlags;
3439 std::string msgString;
3440 ASSERT_NO_FATAL_FAILURE(InitState());
3441 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3442
3443 m_errorMonitor->ClearState();
3444
3445 VkShaderModule module;
3446 VkShaderModuleCreateInfo moduleCreateInfo;
3447 struct icd_spv_header spv;
3448
3449 spv.magic = ICD_SPV_MAGIC;
3450 spv.version = ICD_SPV_VERSION;
3451 spv.gen_magic = 0;
3452
3453 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3454 moduleCreateInfo.pNext = NULL;
3455 moduleCreateInfo.pCode = &spv;
3456 moduleCreateInfo.codeSize = 4;
3457 moduleCreateInfo.flags = 0;
3458 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3459
3460 msgFlags = m_errorMonitor->GetState(&msgString);
3461
Chris Forbes96b81762015-09-18 11:40:23 +12003462 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003463 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3464 FAIL() << "Incorrect warning: " << msgString;
3465 }
3466}
3467
3468TEST_F(VkLayerTest, InvalidSPIRVMagic)
3469{
3470 VkFlags msgFlags;
3471 std::string msgString;
3472 ASSERT_NO_FATAL_FAILURE(InitState());
3473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3474
3475 m_errorMonitor->ClearState();
3476
3477 VkShaderModule module;
3478 VkShaderModuleCreateInfo moduleCreateInfo;
3479 struct icd_spv_header spv;
3480
3481 spv.magic = ~ICD_SPV_MAGIC;
3482 spv.version = ICD_SPV_VERSION;
3483 spv.gen_magic = 0;
3484
3485 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3486 moduleCreateInfo.pNext = NULL;
3487 moduleCreateInfo.pCode = &spv;
3488 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3489 moduleCreateInfo.flags = 0;
3490 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3491
3492 msgFlags = m_errorMonitor->GetState(&msgString);
3493
Chris Forbes96b81762015-09-18 11:40:23 +12003494 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003495 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3496 FAIL() << "Incorrect warning: " << msgString;
3497 }
3498}
3499
3500TEST_F(VkLayerTest, InvalidSPIRVVersion)
3501{
3502 VkFlags msgFlags;
3503 std::string msgString;
3504 ASSERT_NO_FATAL_FAILURE(InitState());
3505 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3506
3507 m_errorMonitor->ClearState();
3508
3509 VkShaderModule module;
3510 VkShaderModuleCreateInfo moduleCreateInfo;
3511 struct icd_spv_header spv;
3512
3513 spv.magic = ICD_SPV_MAGIC;
3514 spv.version = ~ICD_SPV_VERSION;
3515 spv.gen_magic = 0;
3516
3517 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3518 moduleCreateInfo.pNext = NULL;
3519
3520 moduleCreateInfo.pCode = &spv;
3521 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3522 moduleCreateInfo.flags = 0;
3523 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3524
3525 msgFlags = m_errorMonitor->GetState(&msgString);
3526
Chris Forbes96b81762015-09-18 11:40:23 +12003527 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003528 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3529 FAIL() << "Incorrect warning: " << msgString;
3530 }
3531}
3532
Chris Forbes5af3bf22015-05-25 11:13:08 +12003533TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
3534{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003535 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12003536 std::string msgString;
3537 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12003539
3540 char const *vsSource =
3541 "#version 140\n"
3542 "#extension GL_ARB_separate_shader_objects: require\n"
3543 "#extension GL_ARB_shading_language_420pack: require\n"
3544 "\n"
3545 "layout(location=0) out float x;\n"
3546 "void main(){\n"
3547 " gl_Position = vec4(1);\n"
3548 " x = 0;\n"
3549 "}\n";
3550 char const *fsSource =
3551 "#version 140\n"
3552 "#extension GL_ARB_separate_shader_objects: require\n"
3553 "#extension GL_ARB_shading_language_420pack: require\n"
3554 "\n"
3555 "layout(location=0) out vec4 color;\n"
3556 "void main(){\n"
3557 " color = vec4(1);\n"
3558 "}\n";
3559
3560 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3561 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3562
3563 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003564 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12003565 pipe.AddShader(&vs);
3566 pipe.AddShader(&fs);
3567
Chris Forbes5af3bf22015-05-25 11:13:08 +12003568 VkDescriptorSetObj descriptorSet(m_device);
3569 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003570 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003571
3572 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003573 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12003574
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003575 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003576
Cody Northrop1684adb2015-08-05 11:15:02 -06003577 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003578 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
3579 FAIL() << "Incorrect warning: " << msgString;
3580 }
3581}
Chris Forbes5af3bf22015-05-25 11:13:08 +12003582
Chris Forbes3c10b852015-05-25 11:13:13 +12003583TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
3584{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003585 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12003586 std::string msgString;
3587 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003588 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12003589
3590 char const *vsSource =
3591 "#version 140\n"
3592 "#extension GL_ARB_separate_shader_objects: require\n"
3593 "#extension GL_ARB_shading_language_420pack: require\n"
3594 "\n"
3595 "void main(){\n"
3596 " gl_Position = vec4(1);\n"
3597 "}\n";
3598 char const *fsSource =
3599 "#version 140\n"
3600 "#extension GL_ARB_separate_shader_objects: require\n"
3601 "#extension GL_ARB_shading_language_420pack: require\n"
3602 "\n"
3603 "layout(location=0) in float x;\n"
3604 "layout(location=0) out vec4 color;\n"
3605 "void main(){\n"
3606 " color = vec4(x);\n"
3607 "}\n";
3608
3609 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3610 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3611
3612 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003613 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12003614 pipe.AddShader(&vs);
3615 pipe.AddShader(&fs);
3616
Chris Forbes3c10b852015-05-25 11:13:13 +12003617 VkDescriptorSetObj descriptorSet(m_device);
3618 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003619 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12003620
3621 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003622 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12003623
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003624 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12003625
Cody Northrop1684adb2015-08-05 11:15:02 -06003626 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes3c10b852015-05-25 11:13:13 +12003627 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
3628 FAIL() << "Incorrect error: " << msgString;
3629 }
3630}
3631
Chris Forbescc281692015-05-25 11:13:17 +12003632TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
3633{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003634 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12003635 std::string msgString;
3636 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003637 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12003638
3639 char const *vsSource =
3640 "#version 140\n"
3641 "#extension GL_ARB_separate_shader_objects: require\n"
3642 "#extension GL_ARB_shading_language_420pack: require\n"
3643 "\n"
3644 "layout(location=0) out int x;\n"
3645 "void main(){\n"
3646 " x = 0;\n"
3647 " gl_Position = vec4(1);\n"
3648 "}\n";
3649 char const *fsSource =
3650 "#version 140\n"
3651 "#extension GL_ARB_separate_shader_objects: require\n"
3652 "#extension GL_ARB_shading_language_420pack: require\n"
3653 "\n"
3654 "layout(location=0) in float x;\n" /* VS writes int */
3655 "layout(location=0) out vec4 color;\n"
3656 "void main(){\n"
3657 " color = vec4(x);\n"
3658 "}\n";
3659
3660 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3661 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3662
3663 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003664 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12003665 pipe.AddShader(&vs);
3666 pipe.AddShader(&fs);
3667
Chris Forbescc281692015-05-25 11:13:17 +12003668 VkDescriptorSetObj descriptorSet(m_device);
3669 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003670 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12003671
3672 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003673 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12003674
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003675 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12003676
Cody Northrop1684adb2015-08-05 11:15:02 -06003677 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbescc281692015-05-25 11:13:17 +12003678 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
3679 FAIL() << "Incorrect error: " << msgString;
3680 }
3681}
3682
Chris Forbes8291c052015-05-25 11:13:28 +12003683TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
3684{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003685 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12003686 std::string msgString;
3687 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003688 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12003689
3690 VkVertexInputBindingDescription input_binding;
3691 memset(&input_binding, 0, sizeof(input_binding));
3692
3693 VkVertexInputAttributeDescription input_attrib;
3694 memset(&input_attrib, 0, sizeof(input_attrib));
3695 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3696
3697 char const *vsSource =
3698 "#version 140\n"
3699 "#extension GL_ARB_separate_shader_objects: require\n"
3700 "#extension GL_ARB_shading_language_420pack: require\n"
3701 "\n"
3702 "void main(){\n"
3703 " gl_Position = vec4(1);\n"
3704 "}\n";
3705 char const *fsSource =
3706 "#version 140\n"
3707 "#extension GL_ARB_separate_shader_objects: require\n"
3708 "#extension GL_ARB_shading_language_420pack: require\n"
3709 "\n"
3710 "layout(location=0) out vec4 color;\n"
3711 "void main(){\n"
3712 " color = vec4(1);\n"
3713 "}\n";
3714
3715 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3716 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3717
3718 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003719 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12003720 pipe.AddShader(&vs);
3721 pipe.AddShader(&fs);
3722
3723 pipe.AddVertexInputBindings(&input_binding, 1);
3724 pipe.AddVertexInputAttribs(&input_attrib, 1);
3725
Chris Forbes8291c052015-05-25 11:13:28 +12003726 VkDescriptorSetObj descriptorSet(m_device);
3727 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003728 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12003729
3730 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003731 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12003732
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003733 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12003734
Cody Northrop1684adb2015-08-05 11:15:02 -06003735 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12003736 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
3737 FAIL() << "Incorrect warning: " << msgString;
3738 }
3739}
3740
Chris Forbes37367e62015-05-25 11:13:29 +12003741TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
3742{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003743 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12003744 std::string msgString;
3745 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003746 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12003747
3748 char const *vsSource =
3749 "#version 140\n"
3750 "#extension GL_ARB_separate_shader_objects: require\n"
3751 "#extension GL_ARB_shading_language_420pack: require\n"
3752 "\n"
3753 "layout(location=0) in vec4 x;\n" /* not provided */
3754 "void main(){\n"
3755 " gl_Position = x;\n"
3756 "}\n";
3757 char const *fsSource =
3758 "#version 140\n"
3759 "#extension GL_ARB_separate_shader_objects: require\n"
3760 "#extension GL_ARB_shading_language_420pack: require\n"
3761 "\n"
3762 "layout(location=0) out vec4 color;\n"
3763 "void main(){\n"
3764 " color = vec4(1);\n"
3765 "}\n";
3766
3767 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3768 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3769
3770 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003771 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12003772 pipe.AddShader(&vs);
3773 pipe.AddShader(&fs);
3774
Chris Forbes37367e62015-05-25 11:13:29 +12003775 VkDescriptorSetObj descriptorSet(m_device);
3776 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003777 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12003778
3779 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003780 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12003781
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003782 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12003783
Cody Northrop1684adb2015-08-05 11:15:02 -06003784 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes37367e62015-05-25 11:13:29 +12003785 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
3786 FAIL() << "Incorrect warning: " << msgString;
3787 }
3788}
3789
Chris Forbesa4b02322015-05-25 11:13:31 +12003790TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
3791{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003792 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12003793 std::string msgString;
3794 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003795 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12003796
3797 VkVertexInputBindingDescription input_binding;
3798 memset(&input_binding, 0, sizeof(input_binding));
3799
3800 VkVertexInputAttributeDescription input_attrib;
3801 memset(&input_attrib, 0, sizeof(input_attrib));
3802 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3803
3804 char const *vsSource =
3805 "#version 140\n"
3806 "#extension GL_ARB_separate_shader_objects: require\n"
3807 "#extension GL_ARB_shading_language_420pack: require\n"
3808 "\n"
3809 "layout(location=0) in int x;\n" /* attrib provided float */
3810 "void main(){\n"
3811 " gl_Position = vec4(x);\n"
3812 "}\n";
3813 char const *fsSource =
3814 "#version 140\n"
3815 "#extension GL_ARB_separate_shader_objects: require\n"
3816 "#extension GL_ARB_shading_language_420pack: require\n"
3817 "\n"
3818 "layout(location=0) out vec4 color;\n"
3819 "void main(){\n"
3820 " color = vec4(1);\n"
3821 "}\n";
3822
3823 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3824 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3825
3826 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003827 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12003828 pipe.AddShader(&vs);
3829 pipe.AddShader(&fs);
3830
3831 pipe.AddVertexInputBindings(&input_binding, 1);
3832 pipe.AddVertexInputAttribs(&input_attrib, 1);
3833
Chris Forbesa4b02322015-05-25 11:13:31 +12003834 VkDescriptorSetObj descriptorSet(m_device);
3835 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003836 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12003837
3838 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003839 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12003840
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003841 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12003842
Cody Northrop1684adb2015-08-05 11:15:02 -06003843 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa4b02322015-05-25 11:13:31 +12003844 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
3845 FAIL() << "Incorrect error: " << msgString;
3846 }
3847}
3848
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003849TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
3850{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003851 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003852 std::string msgString;
3853 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003854 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003855
3856 /* Two binding descriptions for binding 0 */
3857 VkVertexInputBindingDescription input_bindings[2];
3858 memset(input_bindings, 0, sizeof(input_bindings));
3859
3860 VkVertexInputAttributeDescription input_attrib;
3861 memset(&input_attrib, 0, sizeof(input_attrib));
3862 input_attrib.format = VK_FORMAT_R32_SFLOAT;
3863
3864 char const *vsSource =
3865 "#version 140\n"
3866 "#extension GL_ARB_separate_shader_objects: require\n"
3867 "#extension GL_ARB_shading_language_420pack: require\n"
3868 "\n"
3869 "layout(location=0) in float x;\n" /* attrib provided float */
3870 "void main(){\n"
3871 " gl_Position = vec4(x);\n"
3872 "}\n";
3873 char const *fsSource =
3874 "#version 140\n"
3875 "#extension GL_ARB_separate_shader_objects: require\n"
3876 "#extension GL_ARB_shading_language_420pack: require\n"
3877 "\n"
3878 "layout(location=0) out vec4 color;\n"
3879 "void main(){\n"
3880 " color = vec4(1);\n"
3881 "}\n";
3882
3883 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3884 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3885
3886 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003887 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003888 pipe.AddShader(&vs);
3889 pipe.AddShader(&fs);
3890
3891 pipe.AddVertexInputBindings(input_bindings, 2);
3892 pipe.AddVertexInputAttribs(&input_attrib, 1);
3893
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003894 VkDescriptorSetObj descriptorSet(m_device);
3895 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003896 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003897
3898 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003899 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003900
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003901 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003902
Cody Northrop1684adb2015-08-05 11:15:02 -06003903 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes0bf8fe12015-06-12 11:16:41 +12003904 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
3905 FAIL() << "Incorrect error: " << msgString;
3906 }
3907}
Chris Forbes4c948702015-05-25 11:13:32 +12003908
Chris Forbesc12ef122015-05-25 11:13:40 +12003909/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
3910 * rejects it. */
3911
3912TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
3913{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003914 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12003915 std::string msgString;
3916 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12003917
3918 char const *vsSource =
3919 "#version 140\n"
3920 "#extension GL_ARB_separate_shader_objects: require\n"
3921 "#extension GL_ARB_shading_language_420pack: require\n"
3922 "\n"
3923 "void main(){\n"
3924 " gl_Position = vec4(1);\n"
3925 "}\n";
3926 char const *fsSource =
3927 "#version 140\n"
3928 "#extension GL_ARB_separate_shader_objects: require\n"
3929 "#extension GL_ARB_shading_language_420pack: require\n"
3930 "\n"
3931 "void main(){\n"
3932 "}\n";
3933
3934 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3935 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3936
3937 VkPipelineObj pipe(m_device);
3938 pipe.AddShader(&vs);
3939 pipe.AddShader(&fs);
3940
Chia-I Wuc278df82015-07-07 11:50:03 +08003941 /* set up CB 0, not written */
3942 pipe.AddColorAttachment();
3943 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12003944
Chris Forbesc12ef122015-05-25 11:13:40 +12003945 VkDescriptorSetObj descriptorSet(m_device);
3946 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003947 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12003948
3949 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003950 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12003951
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003952 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12003953
Cody Northrop1684adb2015-08-05 11:15:02 -06003954 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc12ef122015-05-25 11:13:40 +12003955 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
3956 FAIL() << "Incorrect error: " << msgString;
3957 }
3958}
3959
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003960TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
3961{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003962 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003963 std::string msgString;
3964 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003965
3966 char const *vsSource =
3967 "#version 140\n"
3968 "#extension GL_ARB_separate_shader_objects: require\n"
3969 "#extension GL_ARB_shading_language_420pack: require\n"
3970 "\n"
3971 "void main(){\n"
3972 " gl_Position = vec4(1);\n"
3973 "}\n";
3974 char const *fsSource =
3975 "#version 140\n"
3976 "#extension GL_ARB_separate_shader_objects: require\n"
3977 "#extension GL_ARB_shading_language_420pack: require\n"
3978 "\n"
3979 "layout(location=0) out vec4 x;\n"
3980 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
3981 "void main(){\n"
3982 " x = vec4(1);\n"
3983 " y = vec4(1);\n"
3984 "}\n";
3985
3986 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
3987 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
3988
3989 VkPipelineObj pipe(m_device);
3990 pipe.AddShader(&vs);
3991 pipe.AddShader(&fs);
3992
Chia-I Wuc278df82015-07-07 11:50:03 +08003993 /* set up CB 0, not written */
3994 pipe.AddColorAttachment();
3995 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003996 /* FS writes CB 1, but we don't configure it */
3997
Chris Forbes5d15a4f2015-05-25 11:13:43 +12003998 VkDescriptorSetObj descriptorSet(m_device);
3999 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004000 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004001
4002 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004003 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004004
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004005 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004006
Cody Northrop1684adb2015-08-05 11:15:02 -06004007 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004008 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
4009 FAIL() << "Incorrect warning: " << msgString;
4010 }
4011}
4012
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004013TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
4014{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004015 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004016 std::string msgString;
4017 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004018
4019 char const *vsSource =
4020 "#version 140\n"
4021 "#extension GL_ARB_separate_shader_objects: require\n"
4022 "#extension GL_ARB_shading_language_420pack: require\n"
4023 "\n"
4024 "void main(){\n"
4025 " gl_Position = vec4(1);\n"
4026 "}\n";
4027 char const *fsSource =
4028 "#version 140\n"
4029 "#extension GL_ARB_separate_shader_objects: require\n"
4030 "#extension GL_ARB_shading_language_420pack: require\n"
4031 "\n"
4032 "layout(location=0) out ivec4 x;\n" /* not UNORM */
4033 "void main(){\n"
4034 " x = ivec4(1);\n"
4035 "}\n";
4036
4037 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
4038 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
4039
4040 VkPipelineObj pipe(m_device);
4041 pipe.AddShader(&vs);
4042 pipe.AddShader(&fs);
4043
Chia-I Wuc278df82015-07-07 11:50:03 +08004044 /* set up CB 0; type is UNORM by default */
4045 pipe.AddColorAttachment();
4046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004047
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004048 VkDescriptorSetObj descriptorSet(m_device);
4049 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004050 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004051
4052 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004053 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004054
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004055 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004056
Cody Northrop1684adb2015-08-05 11:15:02 -06004057 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004058 if (!strstr(msgString.c_str(),"does not match FS output type")) {
4059 FAIL() << "Incorrect error: " << msgString;
4060 }
4061}
Chris Forbesc2050732015-06-05 14:43:36 +12004062
Chris Forbes76ce7882015-08-14 12:04:59 +12004063TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
4064{
4065 VkFlags msgFlags;
4066 std::string msgString;
4067 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +12004068
4069 char const *vsSource =
4070 "#version 140\n"
4071 "#extension GL_ARB_separate_shader_objects: require\n"
4072 "#extension GL_ARB_shading_language_420pack: require\n"
4073 "\n"
4074 "void main(){\n"
4075 " gl_Position = vec4(1);\n"
4076 "}\n";
4077 char const *fsSource =
4078 "#version 140\n"
4079 "#extension GL_ARB_separate_shader_objects: require\n"
4080 "#extension GL_ARB_shading_language_420pack: require\n"
4081 "\n"
4082 "layout(location=0) out vec4 x;\n"
4083 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4084 "void main(){\n"
4085 " x = vec4(bar.y);\n"
4086 "}\n";
4087
4088 m_errorMonitor->ClearState();
4089
4090 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this);
4091 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this);
4092
4093
4094 VkPipelineObj pipe(m_device);
4095 pipe.AddShader(&vs);
4096 pipe.AddShader(&fs);
4097
4098 /* set up CB 0; type is UNORM by default */
4099 pipe.AddColorAttachment();
4100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4101
4102 VkDescriptorSetObj descriptorSet(m_device);
4103 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
4104
4105 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4106
4107 /* should have generated an error -- pipeline layout does not
4108 * provide a uniform buffer in 0.0
4109 */
4110 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter0abdb662015-10-07 13:28:58 -06004111 ASSERT_TRUE((msgFlags & VK_DBG_REPORT_ERROR_BIT) == VK_DBG_REPORT_ERROR_BIT);
Chris Forbes76ce7882015-08-14 12:04:59 +12004112 if (!strstr(msgString.c_str(),"not declared in pipeline layout")) {
4113 FAIL() << "Incorrect error: " << msgString;
4114 }
4115}
4116
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004117#endif // SHADER_CHECKER_TESTS
4118
4119#if DEVICE_LIMITS_TESTS
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004120TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
4121{
4122 VkFlags msgFlags;
4123 std::string msgString;
4124
4125 ASSERT_NO_FATAL_FAILURE(InitState());
4126 m_errorMonitor->ClearState();
4127
4128 // Create an image
4129 VkImage image;
4130
4131 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4132 const int32_t tex_width = 32;
4133 const int32_t tex_height = 32;
4134
4135 VkImageCreateInfo image_create_info = {};
4136 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4137 image_create_info.pNext = NULL;
4138 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4139 image_create_info.format = tex_format;
4140 image_create_info.extent.width = tex_width;
4141 image_create_info.extent.height = tex_height;
4142 image_create_info.extent.depth = 1;
4143 image_create_info.mipLevels = 1;
4144 image_create_info.arraySize = 1;
4145 image_create_info.samples = 1;
4146 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4147 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4148 image_create_info.flags = 0;
4149
4150 // Introduce error by sending down a bogus width extent
4151 image_create_info.extent.width = 65536;
4152 vkCreateImage(m_device->device(), &image_create_info, &image);
4153
4154 msgFlags = m_errorMonitor->GetState(&msgString);
4155 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4156 "with extents outside the queried limits";
4157 if (!strstr(msgString.c_str(),"CreateImage extents exceed allowable limits for format")) {
4158 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4159 }
4160}
4161
4162TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
4163{
4164 VkFlags msgFlags;
4165 std::string msgString;
4166
4167 ASSERT_NO_FATAL_FAILURE(InitState());
4168 m_errorMonitor->ClearState();
4169
4170 // Create an image
4171 VkImage image;
4172
4173 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4174 const int32_t tex_width = 32;
4175 const int32_t tex_height = 32;
4176
4177 VkImageCreateInfo image_create_info = {};
4178 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4179 image_create_info.pNext = NULL;
4180 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4181 image_create_info.format = tex_format;
4182 image_create_info.extent.width = tex_width;
4183 image_create_info.extent.height = tex_height;
4184 image_create_info.extent.depth = 1;
4185 image_create_info.mipLevels = 1;
4186 image_create_info.arraySize = 1;
4187 image_create_info.samples = 1;
4188 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4189 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4190 image_create_info.flags = 0;
4191
4192 // Introduce error by sending down individually allowable values that result in a surface size
4193 // exceeding the device maximum
4194 image_create_info.extent.width = 8192;
4195 image_create_info.extent.height = 8192;
4196 image_create_info.extent.depth = 16;
4197 image_create_info.arraySize = 4;
4198 image_create_info.samples = 2;
4199 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
4200 vkCreateImage(m_device->device(), &image_create_info, &image);
4201
4202 msgFlags = m_errorMonitor->GetState(&msgString);
4203 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4204 "with resource size exceeding queried limit";
4205 if (!strstr(msgString.c_str(),"CreateImage resource size exceeds allowable maximum")) {
4206 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4207 }
4208}
4209
Mike Stroyan43909d82015-09-25 13:39:21 -06004210TEST_F(VkLayerTest, UpdateBufferAlignment)
4211{
4212 VkFlags msgFlags;
4213 std::string msgString;
4214 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
4215
4216 ASSERT_NO_FATAL_FAILURE(InitState());
4217
4218 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4219 vk_testing::Buffer buffer;
4220 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4221
4222 BeginCommandBuffer();
4223 // Introduce failure by using offset that is not multiple of 4
4224 m_cmdBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
4225 msgFlags = m_errorMonitor->GetState(&msgString);
4226 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad offset";
4227 if (!strstr(msgString.c_str(),"destOffset, is not a multiple of 4")) {
4228 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4'";
4229 }
4230 // Introduce failure by using size that is not multiple of 4
4231 m_cmdBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
4232 msgFlags = m_errorMonitor->GetState(&msgString);
4233 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad size";
4234 if (!strstr(msgString.c_str(),"dataSize, is not a multiple of 4")) {
4235 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
4236 }
4237 EndCommandBuffer();
4238}
4239
4240TEST_F(VkLayerTest, FillBufferAlignment)
4241{
4242 VkFlags msgFlags;
4243 std::string msgString;
4244
4245 ASSERT_NO_FATAL_FAILURE(InitState());
4246
4247 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4248 vk_testing::Buffer buffer;
4249 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4250
4251 BeginCommandBuffer();
4252 // Introduce failure by using offset that is not multiple of 4
4253 m_cmdBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
4254 msgFlags = m_errorMonitor->GetState(&msgString);
4255 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad offset";
4256 if (!strstr(msgString.c_str(),"destOffset, is not a multiple of 4")) {
4257 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4'";
4258 }
4259 // Introduce failure by using size that is not multiple of 4
4260 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
4261 msgFlags = m_errorMonitor->GetState(&msgString);
4262 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad size";
4263 if (!strstr(msgString.c_str(),"fillSize, is not a multiple of 4")) {
4264 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize fillSize, is not a multiple of 4'";
4265 }
4266 EndCommandBuffer();
4267}
4268
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004269#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004270
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004271#if IMAGE_TESTS
4272TEST_F(VkLayerTest, InvalidImageView)
4273{
4274 VkFlags msgFlags;
4275 std::string msgString;
4276 VkResult err;
4277
4278 ASSERT_NO_FATAL_FAILURE(InitState());
4279 m_errorMonitor->ClearState();
4280
Mike Stroyan43909d82015-09-25 13:39:21 -06004281 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004282 VkImage image;
4283
4284 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4285 const int32_t tex_width = 32;
4286 const int32_t tex_height = 32;
4287
4288 VkImageCreateInfo image_create_info = {};
4289 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4290 image_create_info.pNext = NULL;
4291 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4292 image_create_info.format = tex_format;
4293 image_create_info.extent.width = tex_width;
4294 image_create_info.extent.height = tex_height;
4295 image_create_info.extent.depth = 1;
4296 image_create_info.mipLevels = 1;
4297 image_create_info.arraySize = 1;
4298 image_create_info.samples = 1;
4299 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4300 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4301 image_create_info.flags = 0;
4302
4303 err = vkCreateImage(m_device->device(), &image_create_info, &image);
4304 ASSERT_VK_SUCCESS(err);
4305
4306 VkImageViewCreateInfo image_view_create_info = {};
4307 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4308 image_view_create_info.image = image;
4309 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4310 image_view_create_info.format = tex_format;
4311 image_view_create_info.subresourceRange.arraySize = 1;
4312 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
4313 image_view_create_info.subresourceRange.mipLevels = 1;
4314
4315 VkImageView view;
4316 err = vkCreateImageView(m_device->device(), &image_view_create_info, &view);
4317
4318 msgFlags = m_errorMonitor->GetState(&msgString);
4319 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an invalid ImageView";
4320 if (!strstr(msgString.c_str(),"vkCreateImageView called with baseMipLevel 10 ")) {
Mike Stroyan43909d82015-09-25 13:39:21 -06004321 FAIL() << "Error received was not 'vkCreateImageView called with baseMipLevel 10...' but instead '" << msgString.c_str() << "'";
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004322 }
4323}
Mike Stroyan43909d82015-09-25 13:39:21 -06004324
4325TEST_F(VkLayerTest, CopyImageTypeMismatch)
4326{
4327 VkFlags msgFlags;
4328 std::string msgString;
4329 VkResult err;
4330
4331 ASSERT_NO_FATAL_FAILURE(InitState());
4332 m_errorMonitor->ClearState();
4333
4334 // Create two images of different types and try to copy between them
4335 VkImage srcImage;
4336 VkImage destImage;
4337 VkDeviceMemory srcMem;
4338 VkDeviceMemory destMem;
4339 VkMemoryRequirements memReqs;
4340
4341 VkImageCreateInfo image_create_info = {};
4342 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4343 image_create_info.pNext = NULL;
4344 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4345 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4346 image_create_info.extent.width = 32;
4347 image_create_info.extent.height = 32;
4348 image_create_info.extent.depth = 1;
4349 image_create_info.mipLevels = 1;
4350 image_create_info.arraySize = 1;
4351 image_create_info.samples = 1;
4352 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4353 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4354 image_create_info.flags = 0;
4355
4356 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4357 ASSERT_VK_SUCCESS(err);
4358
4359 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4360 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4361
4362 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4363 ASSERT_VK_SUCCESS(err);
4364
4365 // Allocate memory
4366 VkMemoryAllocInfo memAlloc = {};
4367 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4368 memAlloc.pNext = NULL;
4369 memAlloc.allocationSize = 0;
4370 memAlloc.memoryTypeIndex = 0;
4371
4372 err = vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
4373 ASSERT_VK_SUCCESS(err);
4374 memAlloc.allocationSize = memReqs.size;
4375 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4376 ASSERT_VK_SUCCESS(err);
4377 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4378 ASSERT_VK_SUCCESS(err);
4379
4380 err = vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
4381 ASSERT_VK_SUCCESS(err);
4382 memAlloc.allocationSize = memReqs.size;
4383 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4384 ASSERT_VK_SUCCESS(err);
4385 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4386 ASSERT_VK_SUCCESS(err);
4387
4388 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4389 ASSERT_VK_SUCCESS(err);
4390 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4391 ASSERT_VK_SUCCESS(err);
4392
4393 BeginCommandBuffer();
4394 VkImageCopy copyRegion;
4395 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4396 copyRegion.srcSubresource.mipLevel = 0;
4397 copyRegion.srcSubresource.arrayLayer = 0;
4398 copyRegion.srcSubresource.arraySize = 0;
4399 copyRegion.srcOffset.x = 0;
4400 copyRegion.srcOffset.y = 0;
4401 copyRegion.srcOffset.z = 0;
4402 copyRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4403 copyRegion.destSubresource.mipLevel = 0;
4404 copyRegion.destSubresource.arrayLayer = 0;
4405 copyRegion.destSubresource.arraySize = 0;
4406 copyRegion.destOffset.x = 0;
4407 copyRegion.destOffset.y = 0;
4408 copyRegion.destOffset.z = 0;
4409 copyRegion.extent.width = 1;
4410 copyRegion.extent.height = 1;
4411 copyRegion.extent.depth = 1;
4412 m_cmdBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
4413 EndCommandBuffer();
4414
4415 msgFlags = m_errorMonitor->GetState(&msgString);
4416 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
4417 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
4418 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
4419 }
4420
4421 vkDestroyImage(m_device->device(), srcImage);
4422 vkDestroyImage(m_device->device(), destImage);
4423 vkFreeMemory(m_device->device(), srcMem);
4424 vkFreeMemory(m_device->device(), destMem);
4425}
4426
4427TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
4428{
4429 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
4430}
4431
4432TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
4433{
4434 VkFlags msgFlags;
4435 std::string msgString;
4436 VkResult err;
4437
4438 ASSERT_NO_FATAL_FAILURE(InitState());
4439 m_errorMonitor->ClearState();
4440
4441 // Create two images of different types and try to copy between them
4442 VkImage srcImage;
4443 VkImage destImage;
4444 VkDeviceMemory srcMem;
4445 VkDeviceMemory destMem;
4446 VkMemoryRequirements memReqs;
4447
4448 VkImageCreateInfo image_create_info = {};
4449 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4450 image_create_info.pNext = NULL;
4451 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4452 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4453 image_create_info.extent.width = 32;
4454 image_create_info.extent.height = 32;
4455 image_create_info.extent.depth = 1;
4456 image_create_info.mipLevels = 1;
4457 image_create_info.arraySize = 1;
4458 image_create_info.samples = 1;
4459 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4460 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4461 image_create_info.flags = 0;
4462
4463 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4464 ASSERT_VK_SUCCESS(err);
4465
4466 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4467 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4468
4469 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4470 ASSERT_VK_SUCCESS(err);
4471
4472 // Allocate memory
4473 VkMemoryAllocInfo memAlloc = {};
4474 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4475 memAlloc.pNext = NULL;
4476 memAlloc.allocationSize = 0;
4477 memAlloc.memoryTypeIndex = 0;
4478
4479 err = vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
4480 ASSERT_VK_SUCCESS(err);
4481 memAlloc.allocationSize = memReqs.size;
4482 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4483 ASSERT_VK_SUCCESS(err);
4484 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4485 ASSERT_VK_SUCCESS(err);
4486
4487 err = vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
4488 ASSERT_VK_SUCCESS(err);
4489 memAlloc.allocationSize = memReqs.size;
4490 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4491 ASSERT_VK_SUCCESS(err);
4492 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4493 ASSERT_VK_SUCCESS(err);
4494
4495 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4496 ASSERT_VK_SUCCESS(err);
4497 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4498 ASSERT_VK_SUCCESS(err);
4499
4500 BeginCommandBuffer();
4501 VkImageCopy copyRegion;
4502 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4503 copyRegion.srcSubresource.mipLevel = 0;
4504 copyRegion.srcSubresource.arrayLayer = 0;
4505 copyRegion.srcSubresource.arraySize = 0;
4506 copyRegion.srcOffset.x = 0;
4507 copyRegion.srcOffset.y = 0;
4508 copyRegion.srcOffset.z = 0;
4509 copyRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4510 copyRegion.destSubresource.mipLevel = 0;
4511 copyRegion.destSubresource.arrayLayer = 0;
4512 copyRegion.destSubresource.arraySize = 0;
4513 copyRegion.destOffset.x = 0;
4514 copyRegion.destOffset.y = 0;
4515 copyRegion.destOffset.z = 0;
4516 copyRegion.extent.width = 1;
4517 copyRegion.extent.height = 1;
4518 copyRegion.extent.depth = 1;
4519 m_cmdBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
4520 EndCommandBuffer();
4521
4522 msgFlags = m_errorMonitor->GetState(&msgString);
4523 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
4524 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
4525 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
4526 }
4527
4528 vkDestroyImage(m_device->device(), srcImage);
4529 vkDestroyImage(m_device->device(), destImage);
4530 vkFreeMemory(m_device->device(), srcMem);
4531 vkFreeMemory(m_device->device(), destMem);
4532}
4533
4534TEST_F(VkLayerTest, ResolveImageLowSampleCount)
4535{
4536 VkFlags msgFlags;
4537 std::string msgString;
4538 VkResult err;
4539
4540 ASSERT_NO_FATAL_FAILURE(InitState());
4541 m_errorMonitor->ClearState();
4542
4543 // Create two images of sample count 1 and try to Resolve between them
4544 VkImage srcImage;
4545 VkImage destImage;
4546 VkDeviceMemory srcMem;
4547 VkDeviceMemory destMem;
4548 VkMemoryRequirements memReqs;
4549
4550 VkImageCreateInfo image_create_info = {};
4551 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4552 image_create_info.pNext = NULL;
4553 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4554 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4555 image_create_info.extent.width = 32;
4556 image_create_info.extent.height = 1;
4557 image_create_info.extent.depth = 1;
4558 image_create_info.mipLevels = 1;
4559 image_create_info.arraySize = 1;
4560 image_create_info.samples = 1;
4561 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4562 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4563 image_create_info.flags = 0;
4564
4565 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4566 ASSERT_VK_SUCCESS(err);
4567
4568 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4569 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4570
4571 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4572 ASSERT_VK_SUCCESS(err);
4573
4574 // Allocate memory
4575 VkMemoryAllocInfo memAlloc = {};
4576 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4577 memAlloc.pNext = NULL;
4578 memAlloc.allocationSize = 0;
4579 memAlloc.memoryTypeIndex = 0;
4580
4581 err = vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
4582 ASSERT_VK_SUCCESS(err);
4583 memAlloc.allocationSize = memReqs.size;
4584 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4585 ASSERT_VK_SUCCESS(err);
4586 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4587 ASSERT_VK_SUCCESS(err);
4588
4589 err = vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
4590 ASSERT_VK_SUCCESS(err);
4591 memAlloc.allocationSize = memReqs.size;
4592 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4593 ASSERT_VK_SUCCESS(err);
4594 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4595 ASSERT_VK_SUCCESS(err);
4596
4597 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4598 ASSERT_VK_SUCCESS(err);
4599 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4600 ASSERT_VK_SUCCESS(err);
4601
4602 BeginCommandBuffer();
4603 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4604 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4605 //VK_IMAGE_LAYOUT_GENERAL = 1,
4606 VkImageResolve resolveRegion;
4607 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4608 resolveRegion.srcSubresource.mipLevel = 0;
4609 resolveRegion.srcSubresource.arrayLayer = 0;
4610 resolveRegion.srcSubresource.arraySize = 0;
4611 resolveRegion.srcOffset.x = 0;
4612 resolveRegion.srcOffset.y = 0;
4613 resolveRegion.srcOffset.z = 0;
4614 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4615 resolveRegion.destSubresource.mipLevel = 0;
4616 resolveRegion.destSubresource.arrayLayer = 0;
4617 resolveRegion.destSubresource.arraySize = 0;
4618 resolveRegion.destOffset.x = 0;
4619 resolveRegion.destOffset.y = 0;
4620 resolveRegion.destOffset.z = 0;
4621 resolveRegion.extent.width = 1;
4622 resolveRegion.extent.height = 1;
4623 resolveRegion.extent.depth = 1;
4624 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4625 EndCommandBuffer();
4626
4627 msgFlags = m_errorMonitor->GetState(&msgString);
4628 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
4629 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with source sample count less than 2.")) {
4630 FAIL() << "Error received was not 'vkCmdResolveImage called with source sample count less than 2.' but instead '" << msgString.c_str() << "'";
4631 }
4632
4633 vkDestroyImage(m_device->device(), srcImage);
4634 vkDestroyImage(m_device->device(), destImage);
4635 vkFreeMemory(m_device->device(), srcMem);
4636 vkFreeMemory(m_device->device(), destMem);
4637}
4638
4639TEST_F(VkLayerTest, ResolveImageHighSampleCount)
4640{
4641 VkFlags msgFlags;
4642 std::string msgString;
4643 VkResult err;
4644
4645 ASSERT_NO_FATAL_FAILURE(InitState());
4646 m_errorMonitor->ClearState();
4647
4648 // Create two images of sample count 2 and try to Resolve between them
4649 VkImage srcImage;
4650 VkImage destImage;
4651 VkDeviceMemory srcMem;
4652 VkDeviceMemory destMem;
4653 VkMemoryRequirements memReqs;
4654
4655 VkImageCreateInfo image_create_info = {};
4656 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4657 image_create_info.pNext = NULL;
4658 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4659 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4660 image_create_info.extent.width = 32;
4661 image_create_info.extent.height = 1;
4662 image_create_info.extent.depth = 1;
4663 image_create_info.mipLevels = 1;
4664 image_create_info.arraySize = 1;
4665 image_create_info.samples = 2;
4666 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4667 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4668 image_create_info.flags = 0;
4669
4670 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4671 ASSERT_VK_SUCCESS(err);
4672
4673 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4674 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4675
4676 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4677 ASSERT_VK_SUCCESS(err);
4678
4679 // Allocate memory
4680 VkMemoryAllocInfo memAlloc = {};
4681 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4682 memAlloc.pNext = NULL;
4683 memAlloc.allocationSize = 0;
4684 memAlloc.memoryTypeIndex = 0;
4685
4686 err = vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
4687 ASSERT_VK_SUCCESS(err);
4688 memAlloc.allocationSize = memReqs.size;
4689 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4690 ASSERT_VK_SUCCESS(err);
4691 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4692 ASSERT_VK_SUCCESS(err);
4693
4694 err = vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
4695 ASSERT_VK_SUCCESS(err);
4696 memAlloc.allocationSize = memReqs.size;
4697 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4698 ASSERT_VK_SUCCESS(err);
4699 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4700 ASSERT_VK_SUCCESS(err);
4701
4702 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4703 ASSERT_VK_SUCCESS(err);
4704 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4705 ASSERT_VK_SUCCESS(err);
4706
4707 BeginCommandBuffer();
4708 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4709 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4710 //VK_IMAGE_LAYOUT_GENERAL = 1,
4711 VkImageResolve resolveRegion;
4712 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4713 resolveRegion.srcSubresource.mipLevel = 0;
4714 resolveRegion.srcSubresource.arrayLayer = 0;
4715 resolveRegion.srcSubresource.arraySize = 0;
4716 resolveRegion.srcOffset.x = 0;
4717 resolveRegion.srcOffset.y = 0;
4718 resolveRegion.srcOffset.z = 0;
4719 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4720 resolveRegion.destSubresource.mipLevel = 0;
4721 resolveRegion.destSubresource.arrayLayer = 0;
4722 resolveRegion.destSubresource.arraySize = 0;
4723 resolveRegion.destOffset.x = 0;
4724 resolveRegion.destOffset.y = 0;
4725 resolveRegion.destOffset.z = 0;
4726 resolveRegion.extent.width = 1;
4727 resolveRegion.extent.height = 1;
4728 resolveRegion.extent.depth = 1;
4729 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4730 EndCommandBuffer();
4731
4732 msgFlags = m_errorMonitor->GetState(&msgString);
4733 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
4734 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with dest sample count greater than 1.")) {
4735 FAIL() << "Error received was not 'vkCmdResolveImage called with dest sample count greater than 1.' but instead '" << msgString.c_str() << "'";
4736 }
4737
4738 vkDestroyImage(m_device->device(), srcImage);
4739 vkDestroyImage(m_device->device(), destImage);
4740 vkFreeMemory(m_device->device(), srcMem);
4741 vkFreeMemory(m_device->device(), destMem);
4742}
4743
4744TEST_F(VkLayerTest, ResolveImageFormatMismatch)
4745{
4746 VkFlags msgFlags;
4747 std::string msgString;
4748 VkResult err;
4749
4750 ASSERT_NO_FATAL_FAILURE(InitState());
4751 m_errorMonitor->ClearState();
4752
4753 // Create two images of different types and try to copy between them
4754 VkImage srcImage;
4755 VkImage destImage;
4756 VkDeviceMemory srcMem;
4757 VkDeviceMemory destMem;
4758 VkMemoryRequirements memReqs;
4759
4760 VkImageCreateInfo image_create_info = {};
4761 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4762 image_create_info.pNext = NULL;
4763 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4764 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4765 image_create_info.extent.width = 32;
4766 image_create_info.extent.height = 1;
4767 image_create_info.extent.depth = 1;
4768 image_create_info.mipLevels = 1;
4769 image_create_info.arraySize = 1;
4770 image_create_info.samples = 2;
4771 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4772 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4773 image_create_info.flags = 0;
4774
4775 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4776 ASSERT_VK_SUCCESS(err);
4777
4778 image_create_info.format = VK_FORMAT_B8G8R8_SRGB;
4779 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4780 image_create_info.samples = 1;
4781
4782 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4783 ASSERT_VK_SUCCESS(err);
4784
4785 // Allocate memory
4786 VkMemoryAllocInfo memAlloc = {};
4787 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4788 memAlloc.pNext = NULL;
4789 memAlloc.allocationSize = 0;
4790 memAlloc.memoryTypeIndex = 0;
4791
4792 err = vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
4793 ASSERT_VK_SUCCESS(err);
4794 memAlloc.allocationSize = memReqs.size;
4795 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4796 ASSERT_VK_SUCCESS(err);
4797 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4798 ASSERT_VK_SUCCESS(err);
4799
4800 err = vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
4801 ASSERT_VK_SUCCESS(err);
4802 memAlloc.allocationSize = memReqs.size;
4803 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4804 ASSERT_VK_SUCCESS(err);
4805 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4806 ASSERT_VK_SUCCESS(err);
4807
4808 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4809 ASSERT_VK_SUCCESS(err);
4810 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4811 ASSERT_VK_SUCCESS(err);
4812
4813 BeginCommandBuffer();
4814 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4815 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4816 //VK_IMAGE_LAYOUT_GENERAL = 1,
4817 VkImageResolve resolveRegion;
4818 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4819 resolveRegion.srcSubresource.mipLevel = 0;
4820 resolveRegion.srcSubresource.arrayLayer = 0;
4821 resolveRegion.srcSubresource.arraySize = 0;
4822 resolveRegion.srcOffset.x = 0;
4823 resolveRegion.srcOffset.y = 0;
4824 resolveRegion.srcOffset.z = 0;
4825 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4826 resolveRegion.destSubresource.mipLevel = 0;
4827 resolveRegion.destSubresource.arrayLayer = 0;
4828 resolveRegion.destSubresource.arraySize = 0;
4829 resolveRegion.destOffset.x = 0;
4830 resolveRegion.destOffset.y = 0;
4831 resolveRegion.destOffset.z = 0;
4832 resolveRegion.extent.width = 1;
4833 resolveRegion.extent.height = 1;
4834 resolveRegion.extent.depth = 1;
4835 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4836 EndCommandBuffer();
4837
4838 msgFlags = m_errorMonitor->GetState(&msgString);
4839 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage format mismatch";
4840 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest formats.")) {
4841 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest formats.' but instead '" << msgString.c_str() << "'";
4842 }
4843
4844 vkDestroyImage(m_device->device(), srcImage);
4845 vkDestroyImage(m_device->device(), destImage);
4846 vkFreeMemory(m_device->device(), srcMem);
4847 vkFreeMemory(m_device->device(), destMem);
4848}
4849
4850TEST_F(VkLayerTest, ResolveImageTypeMismatch)
4851{
4852 VkFlags msgFlags;
4853 std::string msgString;
4854 VkResult err;
4855
4856 ASSERT_NO_FATAL_FAILURE(InitState());
4857 m_errorMonitor->ClearState();
4858
4859 // Create two images of different types and try to copy between them
4860 VkImage srcImage;
4861 VkImage destImage;
4862 VkDeviceMemory srcMem;
4863 VkDeviceMemory destMem;
4864 VkMemoryRequirements memReqs;
4865
4866 VkImageCreateInfo image_create_info = {};
4867 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4868 image_create_info.pNext = NULL;
4869 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4870 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4871 image_create_info.extent.width = 32;
4872 image_create_info.extent.height = 1;
4873 image_create_info.extent.depth = 1;
4874 image_create_info.mipLevels = 1;
4875 image_create_info.arraySize = 1;
4876 image_create_info.samples = 2;
4877 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4878 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4879 image_create_info.flags = 0;
4880
4881 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4882 ASSERT_VK_SUCCESS(err);
4883
4884 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4885 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4886 image_create_info.samples = 1;
4887
4888 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4889 ASSERT_VK_SUCCESS(err);
4890
4891 // Allocate memory
4892 VkMemoryAllocInfo memAlloc = {};
4893 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4894 memAlloc.pNext = NULL;
4895 memAlloc.allocationSize = 0;
4896 memAlloc.memoryTypeIndex = 0;
4897
4898 err = vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
4899 ASSERT_VK_SUCCESS(err);
4900 memAlloc.allocationSize = memReqs.size;
4901 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4902 ASSERT_VK_SUCCESS(err);
4903 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4904 ASSERT_VK_SUCCESS(err);
4905
4906 err = vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
4907 ASSERT_VK_SUCCESS(err);
4908 memAlloc.allocationSize = memReqs.size;
4909 err = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4910 ASSERT_VK_SUCCESS(err);
4911 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4912 ASSERT_VK_SUCCESS(err);
4913
4914 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4915 ASSERT_VK_SUCCESS(err);
4916 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4917 ASSERT_VK_SUCCESS(err);
4918
4919 BeginCommandBuffer();
4920 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
4921 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
4922 //VK_IMAGE_LAYOUT_GENERAL = 1,
4923 VkImageResolve resolveRegion;
4924 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4925 resolveRegion.srcSubresource.mipLevel = 0;
4926 resolveRegion.srcSubresource.arrayLayer = 0;
4927 resolveRegion.srcSubresource.arraySize = 0;
4928 resolveRegion.srcOffset.x = 0;
4929 resolveRegion.srcOffset.y = 0;
4930 resolveRegion.srcOffset.z = 0;
4931 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
4932 resolveRegion.destSubresource.mipLevel = 0;
4933 resolveRegion.destSubresource.arrayLayer = 0;
4934 resolveRegion.destSubresource.arraySize = 0;
4935 resolveRegion.destOffset.x = 0;
4936 resolveRegion.destOffset.y = 0;
4937 resolveRegion.destOffset.z = 0;
4938 resolveRegion.extent.width = 1;
4939 resolveRegion.extent.height = 1;
4940 resolveRegion.extent.depth = 1;
4941 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
4942 EndCommandBuffer();
4943
4944 msgFlags = m_errorMonitor->GetState(&msgString);
4945 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
4946 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest image types.")) {
4947 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest image types.' but instead '" << msgString.c_str() << "'";
4948 }
4949
4950 vkDestroyImage(m_device->device(), srcImage);
4951 vkDestroyImage(m_device->device(), destImage);
4952 vkFreeMemory(m_device->device(), srcMem);
4953 vkFreeMemory(m_device->device(), destMem);
4954}
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004955#endif // IMAGE_TESTS
4956
Tony Barbour30486ea2015-04-07 13:44:53 -06004957int main(int argc, char **argv) {
4958 int result;
4959
4960 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004961 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06004962
4963 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
4964
4965 result = RUN_ALL_TESTS();
4966
Tony Barbour01999182015-04-09 12:58:51 -06004967 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06004968 return result;
4969}