blob: c37e8e8a48d805cdd23540c62279c3140e7959e1 [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
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600291 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
292 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500293
294 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800295 pipelineobj.AddColorAttachment();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500296 pipelineobj.AddShader(&vs);
297 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600298 if (failMask & BsoFailLineWidth) {
299 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
300 }
301 if (failMask & BsoFailDepthBias) {
302 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
303 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600304 // Viewport and scissors must stay in synch or other errors will occur than the ones we want
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600305 if (failMask & BsoFailViewport) {
306 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600307 m_viewports.clear();
308 m_scissors.clear();
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600309 }
310 if (failMask & BsoFailScissor) {
311 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600312 m_scissors.clear();
313 m_viewports.clear();
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600314 }
315 if (failMask & BsoFailBlend) {
316 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
317 }
318 if (failMask & BsoFailDepthBounds) {
319 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
320 }
321 if (failMask & BsoFailStencilReadMask) {
322 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
323 }
324 if (failMask & BsoFailStencilWriteMask) {
325 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
326 }
327 if (failMask & BsoFailStencilReference) {
328 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
329 }
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500330
331 VkDescriptorSetObj descriptorSet(m_device);
332 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
333
334 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600335 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500336
Tony Barbour1490c912015-07-28 10:17:20 -0600337 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500338
339 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600340 Draw(3, 1, 0, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500341
342 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600343 EndCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500344
Tony Barbour1490c912015-07-28 10:17:20 -0600345 QueueCommandBuffer();
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500346}
347
348void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask)
349{
350 if (m_depthStencil->Initialized()) {
351 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
352 } else {
353 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
354 }
355
356 cmdBuffer->PrepareAttachments();
Cody Northrop2605cb02015-08-18 15:21:16 -0600357 // Make sure depthWriteEnable is set so that Depth fail test will work correctly
358 // Make sure stencilTestEnable is set so that Stencil fail test will work correctly
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600359 VkStencilOpState stencil = {};
360 stencil.stencilFailOp = VK_STENCIL_OP_KEEP;
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600361 stencil.stencilPassOp = VK_STENCIL_OP_KEEP;
362 stencil.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
363 stencil.stencilCompareOp = VK_COMPARE_OP_NEVER;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600364
365 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
366 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter2f5deb52015-09-30 16:16:57 -0600367 ds_ci.pNext = NULL;
368 ds_ci.depthTestEnable = VK_FALSE;
369 ds_ci.depthWriteEnable = VK_TRUE;
370 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
371 ds_ci.depthBoundsTestEnable = VK_FALSE;
372 ds_ci.stencilTestEnable = VK_TRUE;
373 ds_ci.front = stencil;
374 ds_ci.back = stencil;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600375
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600376 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -0600377 pipelineobj.SetViewport(m_viewports);
378 pipelineobj.SetScissor(m_scissors);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500379 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Cody Northropccfa96d2015-08-27 10:20:35 -0600380 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
381 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500382 cmdBuffer->BindPipeline(pipelineobj);
383 cmdBuffer->BindDescriptorSet(descriptorSet);
384}
385
386// ********************************************************************************************************************
387// ********************************************************************************************************************
388// ********************************************************************************************************************
389// ********************************************************************************************************************
Tobin Ehlis57e6a612015-05-26 16:11:58 -0600390#if MEM_TRACKER_TESTS
Mark Lobodzinski81078192015-05-19 10:28:29 -0500391TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion)
392{
393 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600394 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500395 std::string msgString;
396
397 VkFenceCreateInfo fenceInfo = {};
398 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
399 fenceInfo.pNext = NULL;
400 fenceInfo.flags = 0;
401
402 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barboure389b882015-07-20 13:00:10 -0600403
404 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
405 vk_testing::Buffer buffer;
406 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500407
Tony Barbour1490c912015-07-28 10:17:20 -0600408 BeginCommandBuffer();
409 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
410 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500411
412 testFence.init(*m_device, fenceInfo);
413
414 // Bypass framework since it does the waits automatically
415 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600416 VkSubmitInfo submit_info;
417 submit_info.waitSemCount = 0;
418 submit_info.pWaitSemaphores = NULL;
419 submit_info.cmdBufferCount = 1;
420 submit_info.pCommandBuffers = &m_cmdBuffer->handle();
421 submit_info.signalSemCount = 0;
422 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600423
424 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500425 ASSERT_VK_SUCCESS( err );
426
427 m_errorMonitor->ClearState();
428 // Introduce failure by calling begin again before checking fence
Tony Barbour1490c912015-07-28 10:17:20 -0600429 vkResetCommandBuffer(m_cmdBuffer->handle(), 0);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500430
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600431 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600432 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 -0500433 if (!strstr(msgString.c_str(),"Resetting CB")) {
434 FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'";
435 }
436}
437
438TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion)
439{
440 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600441 VkFlags msgFlags;
Mark Lobodzinski81078192015-05-19 10:28:29 -0500442 std::string msgString;
443
444 VkFenceCreateInfo fenceInfo = {};
445 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
446 fenceInfo.pNext = NULL;
447 fenceInfo.flags = 0;
448
449 ASSERT_NO_FATAL_FAILURE(InitState());
450 ASSERT_NO_FATAL_FAILURE(InitViewport());
451 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
452
Tony Barbour1490c912015-07-28 10:17:20 -0600453 BeginCommandBuffer();
454 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
455 EndCommandBuffer();
Mark Lobodzinski81078192015-05-19 10:28:29 -0500456
457 testFence.init(*m_device, fenceInfo);
458
459 // Bypass framework since it does the waits automatically
460 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600461 VkSubmitInfo submit_info;
462 submit_info.waitSemCount = 0;
463 submit_info.pWaitSemaphores = NULL;
464 submit_info.cmdBufferCount = 1;
465 submit_info.pCommandBuffers = &m_cmdBuffer->handle();
466 submit_info.signalSemCount = 0;
467 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600468
469 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski81078192015-05-19 10:28:29 -0500470 ASSERT_VK_SUCCESS( err );
471
472 m_errorMonitor->ClearState();
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600473
474 VkCmdBufferBeginInfo info = {};
Courtney Goeltzenleuchtera32436b2015-10-21 18:11:04 -0600475 info.flags = VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600476 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
477 info.renderPass = VK_NULL_HANDLE;
478 info.subpass = 0;
479 info.framebuffer = VK_NULL_HANDLE;
480
481 // Introduce failure by calling BCB again before checking fence
482 vkBeginCommandBuffer(m_cmdBuffer->handle(), &info);
Mark Lobodzinski81078192015-05-19 10:28:29 -0500483
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600484 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600485 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 -0500486 if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) {
487 FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'";
488 }
489}
490
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500491TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit)
492{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600493 VkFlags msgFlags;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500494 std::string msgString;
495 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600496 bool pass;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500497
498 ASSERT_NO_FATAL_FAILURE(InitState());
499 m_errorMonitor->ClearState();
500
501 // Create an image, allocate memory, free it, and then try to bind it
502 VkImage image;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500503 VkDeviceMemory mem;
504 VkMemoryRequirements mem_reqs;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500505
506 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
507 const int32_t tex_width = 32;
508 const int32_t tex_height = 32;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500509
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600510 VkImageCreateInfo image_create_info = {};
511 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
512 image_create_info.pNext = NULL;
513 image_create_info.imageType = VK_IMAGE_TYPE_2D;
514 image_create_info.format = tex_format;
515 image_create_info.extent.width = tex_width;
516 image_create_info.extent.height = tex_height;
517 image_create_info.extent.depth = 1;
518 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600519 image_create_info.arrayLayers = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600520 image_create_info.samples = 1;
521 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
522 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
523 image_create_info.flags = 0;
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600524
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600525 VkMemoryAllocInfo mem_alloc = {};
526 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
527 mem_alloc.pNext = NULL;
528 mem_alloc.allocationSize = 0;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500529 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600530 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500531
532 err = vkCreateImage(m_device->device(), &image_create_info, &image);
533 ASSERT_VK_SUCCESS(err);
534
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600535 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500536 image,
Mark Lobodzinski23182612015-05-29 09:32:35 -0500537 &mem_reqs);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500538
Mark Lobodzinski23182612015-05-29 09:32:35 -0500539 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500540
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600541 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
542 if(!pass) { // If we can't find any unmappable memory this test doesn't make sense
Mike Stroyan2237f522015-08-18 14:40:24 -0600543 vkDestroyImage(m_device->device(), image);
Tony Barbour49a3b652015-08-04 16:13:01 -0600544 return;
Mike Stroyan2237f522015-08-18 14:40:24 -0600545 }
Mike Stroyand72da752015-08-04 10:49:29 -0600546
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500547 // allocate memory
Mark Lobodzinski23182612015-05-29 09:32:35 -0500548 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500549 ASSERT_VK_SUCCESS(err);
550
551 // Try to bind free memory that has been freed
Tony Barboure84a8d62015-07-10 14:10:27 -0600552 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500553 ASSERT_VK_SUCCESS(err);
554
555 // Map memory as if to initialize the image
556 void *mappedAddress = NULL;
Mark Lobodzinski23182612015-05-29 09:32:35 -0500557 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500558
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600559 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600560 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 -0500561 if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) {
562 FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker";
563 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600564
565 vkDestroyImage(m_device->device(), image);
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500566}
567
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600568// TODO : Is this test still valid. Not sure it is with updates to memory binding model
569// Verify and delete the test of fix the check
570//TEST_F(VkLayerTest, FreeBoundMemory)
571//{
572// VkFlags msgFlags;
573// std::string msgString;
574// VkResult err;
575//
576// ASSERT_NO_FATAL_FAILURE(InitState());
577// m_errorMonitor->ClearState();
578//
579// // Create an image, allocate memory, free it, and then try to bind it
580// VkImage image;
581// VkDeviceMemory mem;
582// VkMemoryRequirements mem_reqs;
583//
584// const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
585// const int32_t tex_width = 32;
586// const int32_t tex_height = 32;
587//
588// const VkImageCreateInfo image_create_info = {
589// .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
590// .pNext = NULL,
591// .imageType = VK_IMAGE_TYPE_2D,
592// .format = tex_format,
593// .extent = { tex_width, tex_height, 1 },
594// .mipLevels = 1,
595// .arraySize = 1,
596// .samples = 1,
597// .tiling = VK_IMAGE_TILING_LINEAR,
598// .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
599// .flags = 0,
600// };
601// VkMemoryAllocInfo mem_alloc = {
602// .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
603// .pNext = NULL,
604// .allocationSize = 0,
605// .memoryTypeIndex = 0,
606// };
607//
608// err = vkCreateImage(m_device->device(), &image_create_info, &image);
609// ASSERT_VK_SUCCESS(err);
610//
611// err = vkGetImageMemoryRequirements(m_device->device(),
612// image,
613// &mem_reqs);
614// ASSERT_VK_SUCCESS(err);
615//
616// mem_alloc.allocationSize = mem_reqs.size;
617//
618// err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
619// ASSERT_VK_SUCCESS(err);
620//
621// // allocate memory
622// err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
623// ASSERT_VK_SUCCESS(err);
624//
625// // Bind memory to Image object
626// err = vkBindImageMemory(m_device->device(), image, mem, 0);
627// ASSERT_VK_SUCCESS(err);
628//
629// // Introduce validation failure, free memory while still bound to object
630// vkFreeMemory(m_device->device(), mem);
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -0600631// msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter0d6857f2015-09-04 13:52:24 -0600632//
Cody Northrop1684adb2015-08-05 11:15:02 -0600633// 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 -0600634// if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) {
635// FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker";
636// }
637//}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500638
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500639TEST_F(VkLayerTest, RebindMemory)
640{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600641 VkFlags msgFlags;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500642 std::string msgString;
643 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600644 bool pass;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500645
646 ASSERT_NO_FATAL_FAILURE(InitState());
647 m_errorMonitor->ClearState();
648
649 // Create an image, allocate memory, free it, and then try to bind it
650 VkImage image;
651 VkDeviceMemory mem1;
652 VkDeviceMemory mem2;
653 VkMemoryRequirements mem_reqs;
654
655 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
656 const int32_t tex_width = 32;
657 const int32_t tex_height = 32;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500658
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600659 VkImageCreateInfo image_create_info = {};
660 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
661 image_create_info.pNext = NULL;
662 image_create_info.imageType = VK_IMAGE_TYPE_2D;
663 image_create_info.format = tex_format;
664 image_create_info.extent.width = tex_width;
665 image_create_info.extent.height = tex_height;
666 image_create_info.extent.depth = 1;
667 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600668 image_create_info.arrayLayers = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600669 image_create_info.samples = 1;
670 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
671 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
672 image_create_info.flags = 0;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500673
Tony Barbourefbe9ca2015-07-15 12:50:33 -0600674 VkMemoryAllocInfo mem_alloc = {};
675 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
676 mem_alloc.pNext = NULL;
677 mem_alloc.allocationSize = 0;
678 mem_alloc.memoryTypeIndex = 0;
679
680 // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
681 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500682 err = vkCreateImage(m_device->device(), &image_create_info, &image);
683 ASSERT_VK_SUCCESS(err);
684
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600685 vkGetImageMemoryRequirements(m_device->device(),
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500686 image,
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500687 &mem_reqs);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500688
689 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600690 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
691 ASSERT_TRUE(pass);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500692
693 // allocate 2 memory objects
694 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1);
695 ASSERT_VK_SUCCESS(err);
696 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2);
697 ASSERT_VK_SUCCESS(err);
698
699 // Bind first memory object to Image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600700 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500701 ASSERT_VK_SUCCESS(err);
702
703 // Introduce validation failure, try to bind a different memory object to the same image object
Tony Barboure84a8d62015-07-10 14:10:27 -0600704 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500705
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600706 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600707 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to rebind an object";
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500708 if (!strstr(msgString.c_str(),"which has already been bound to mem object")) {
709 FAIL() << "Error received did not match expected message when rebinding memory to an object";
710 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600711
712 vkDestroyImage(m_device->device(), image);
713 vkFreeMemory(m_device->device(), mem1);
714 vkFreeMemory(m_device->device(), mem2);
Mark Lobodzinskic66c6712015-06-05 13:59:04 -0500715}
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500716
Tony Barbour8508b8e2015-04-09 10:48:04 -0600717TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600718{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600719 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600720 VkFlags msgFlags;
Tony Barbour30486ea2015-04-07 13:44:53 -0600721 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600722
723 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600724 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
725 fenceInfo.pNext = NULL;
726 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600727
Tony Barbour30486ea2015-04-07 13:44:53 -0600728 ASSERT_NO_FATAL_FAILURE(InitState());
729 ASSERT_NO_FATAL_FAILURE(InitViewport());
730 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
731
Tony Barbour1490c912015-07-28 10:17:20 -0600732 BeginCommandBuffer();
733 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
734 EndCommandBuffer();
Tony Barbour30486ea2015-04-07 13:44:53 -0600735
736 testFence.init(*m_device, fenceInfo);
737 m_errorMonitor->ClearState();
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600738
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -0600739 VkSubmitInfo submit_info;
740 submit_info.waitSemCount = 0;
741 submit_info.pWaitSemaphores = NULL;
742 submit_info.cmdBufferCount = 1;
743 submit_info.pCommandBuffers = &m_cmdBuffer->handle();
744 submit_info.signalSemCount = 0;
745 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -0600746
747 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600748 vkQueueWaitIdle(m_device->m_queue );
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600749 msgFlags = m_errorMonitor->GetState(&msgString);
Mark Lobodzinski87db5012015-09-14 17:43:42 -0600750
Cody Northrop1684adb2015-08-05 11:15:02 -0600751 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 -0600752 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500753 FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600754 }
755
756}
757
758TEST_F(VkLayerTest, ResetUnsignaledFence)
759{
760 vk_testing::Fence testFence;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600761 VkFlags msgFlags;
Tony Barbour8508b8e2015-04-09 10:48:04 -0600762 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600763 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600764 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
765 fenceInfo.pNext = NULL;
766
Tony Barbour8508b8e2015-04-09 10:48:04 -0600767 ASSERT_NO_FATAL_FAILURE(InitState());
768 testFence.init(*m_device, fenceInfo);
769 m_errorMonitor->ClearState();
Chia-I Wua4992342015-07-03 11:45:55 +0800770 VkFence fences[1] = {testFence.handle()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600771 vkResetFences(m_device->device(), 1, fences);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600772 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlisc2033a02015-10-01 10:14:48 -0600773 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 -0600774 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -0500775 FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600776 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600777
778}
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600779
Chia-I Wuc278df82015-07-07 11:50:03 +0800780/* TODO: Update for changes due to bug-14075 tiling across render passes */
781#if 0
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600782TEST_F(VkLayerTest, InvalidUsageBits)
783{
784 // Initiate Draw w/o a PSO bound
785 VkFlags msgFlags;
786 std::string msgString;
787
788 ASSERT_NO_FATAL_FAILURE(InitState());
789 m_errorMonitor->ClearState();
790 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -0600791 BeginCommandBuffer();
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600792
793 const VkExtent3D e3d = {
794 .width = 128,
795 .height = 128,
796 .depth = 1,
797 };
798 const VkImageCreateInfo ici = {
799 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
800 .pNext = NULL,
801 .imageType = VK_IMAGE_TYPE_2D,
802 .format = VK_FORMAT_D32_SFLOAT_S8_UINT,
803 .extent = e3d,
804 .mipLevels = 1,
805 .arraySize = 1,
806 .samples = 1,
807 .tiling = VK_IMAGE_TILING_LINEAR,
Courtney Goeltzenleuchterc3b8eea2015-09-10 14:14:11 -0600808 .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600809 .flags = 0,
810 };
811
812 VkImage dsi;
813 vkCreateImage(m_device->device(), &ici, &dsi);
814 VkDepthStencilView dsv;
815 const VkDepthStencilViewCreateInfo dsvci = {
816 .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO,
817 .pNext = NULL,
818 .image = dsi,
819 .mipLevel = 0,
Courtney Goeltzenleuchter3dee8082015-09-10 16:38:41 -0600820 .baseArrayLayer = 0,
Tobin Ehlisd94ba722015-07-03 08:45:14 -0600821 .arraySize = 1,
822 .flags = 0,
823 };
824 vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv);
825 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -0600826 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 -0600827 if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) {
828 FAIL() << "Error received was not 'Invalid usage flag for image...'";
829 }
830}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -0600831#endif // 0
832#endif // MEM_TRACKER_TESTS
833
Tobin Ehlis40e9f522015-06-25 11:58:41 -0600834#if OBJ_TRACKER_TESTS
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600835TEST_F(VkLayerTest, PipelineNotBound)
836{
837 VkFlags msgFlags;
838 std::string msgString;
839 VkResult err;
840
841 ASSERT_NO_FATAL_FAILURE(InitState());
842 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
843 m_errorMonitor->ClearState();
844
845 VkDescriptorTypeCount ds_type_count = {};
846 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
847 ds_type_count.count = 1;
848
849 VkDescriptorPoolCreateInfo ds_pool_ci = {};
850 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
851 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600852 ds_pool_ci.maxSets = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600853 ds_pool_ci.count = 1;
854 ds_pool_ci.pTypeCount = &ds_type_count;
855
856 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -0600857 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600858 ASSERT_VK_SUCCESS(err);
859
860 VkDescriptorSetLayoutBinding dsl_binding = {};
861 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
862 dsl_binding.arraySize = 1;
863 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
864 dsl_binding.pImmutableSamplers = NULL;
865
866 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
867 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
868 ds_layout_ci.pNext = NULL;
869 ds_layout_ci.count = 1;
870 ds_layout_ci.pBinding = &dsl_binding;
871
872 VkDescriptorSetLayout ds_layout;
873 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
874 ASSERT_VK_SUCCESS(err);
875
876 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -0600877 VkDescriptorSetAllocInfo alloc_info = {};
878 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
879 alloc_info.count = 1;
880 alloc_info.descriptorPool = ds_pool;
881 alloc_info.pSetLayouts = &ds_layout;
882 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf2f97402015-09-11 12:57:55 -0600883 ASSERT_VK_SUCCESS(err);
884
885 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
886 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
887 pipeline_layout_ci.pNext = NULL;
888 pipeline_layout_ci.descriptorSetCount = 1;
889 pipeline_layout_ci.pSetLayouts = &ds_layout;
890
891 VkPipelineLayout pipeline_layout;
892 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
893 ASSERT_VK_SUCCESS(err);
894
895 VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
896
897 BeginCommandBuffer();
898 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
899
900 msgFlags = m_errorMonitor->GetState(&msgString);
901 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 -0600902 if (!strstr(msgString.c_str(),"Invalid VkPipeline Object ")) {
903 FAIL() << "Error received was not 'Invalid VkPipeline Object 0xbaadb1be' but instead it was '" << msgString.c_str() << "'";
904 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600905
906 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -0600907 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
908 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600909}
910
911TEST_F(VkLayerTest, BindInvalidMemory)
912{
913 VkFlags msgFlags;
914 std::string msgString;
915 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600916 bool pass;
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600917
918 ASSERT_NO_FATAL_FAILURE(InitState());
919 m_errorMonitor->ClearState();
920
921 // Create an image, allocate memory, free it, and then try to bind it
922 VkImage image;
923 VkDeviceMemory mem;
924 VkMemoryRequirements mem_reqs;
925
926 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
927 const int32_t tex_width = 32;
928 const int32_t tex_height = 32;
929
930 VkImageCreateInfo image_create_info = {};
931 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
932 image_create_info.pNext = NULL;
933 image_create_info.imageType = VK_IMAGE_TYPE_2D;
934 image_create_info.format = tex_format;
935 image_create_info.extent.width = tex_width;
936 image_create_info.extent.height = tex_height;
937 image_create_info.extent.depth = 1;
938 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600939 image_create_info.arrayLayers = 1;
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600940 image_create_info.samples = 1;
941 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
942 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
943 image_create_info.flags = 0;
944
945 VkMemoryAllocInfo mem_alloc = {};
946 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
947 mem_alloc.pNext = NULL;
948 mem_alloc.allocationSize = 0;
949 mem_alloc.memoryTypeIndex = 0;
950
951 err = vkCreateImage(m_device->device(), &image_create_info, &image);
952 ASSERT_VK_SUCCESS(err);
953
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600954 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600955 image,
956 &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600957
958 mem_alloc.allocationSize = mem_reqs.size;
959
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600960 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
961 ASSERT_TRUE(pass);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600962
963 // allocate memory
964 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
965 ASSERT_VK_SUCCESS(err);
966
967 // Introduce validation failure, free memory before binding
968 vkFreeMemory(m_device->device(), mem);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600969
970 // Try to bind free memory that has been freed
971 err = vkBindImageMemory(m_device->device(), image, mem, 0);
972 // This may very well return an error.
973 (void)err;
974
975 msgFlags = m_errorMonitor->GetState(&msgString);
976 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while tring to bind a freed memory object";
977 if (!strstr(msgString.c_str(),"Invalid VkDeviceMemory Object ")) {
978 FAIL() << "Error received from BindInvalidMemory was not 'Invalid VkDeviceMemory Object 0x<handle>' but instead '" << msgString.c_str() << "'";
979 }
Mike Stroyan2237f522015-08-18 14:40:24 -0600980
981 vkDestroyImage(m_device->device(), image);
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600982}
983
984TEST_F(VkLayerTest, BindMemoryToDestroyedObject)
985{
986 VkFlags msgFlags;
987 std::string msgString;
988 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -0600989 bool pass;
Tobin Ehlis87f115c2015-09-15 15:02:17 -0600990
991 ASSERT_NO_FATAL_FAILURE(InitState());
992 m_errorMonitor->ClearState();
993
994 // Create an image object, allocate memory, destroy the object and then try to bind it
995 VkImage image;
996 VkDeviceMemory mem;
997 VkMemoryRequirements mem_reqs;
998
999 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1000 const int32_t tex_width = 32;
1001 const int32_t tex_height = 32;
1002
1003 VkImageCreateInfo image_create_info = {};
1004 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1005 image_create_info.pNext = NULL;
1006 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1007 image_create_info.format = tex_format;
1008 image_create_info.extent.width = tex_width;
1009 image_create_info.extent.height = tex_height;
1010 image_create_info.extent.depth = 1;
1011 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06001012 image_create_info.arrayLayers = 1;
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001013 image_create_info.samples = 1;
1014 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1015 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1016 image_create_info.flags = 0;
1017
1018 VkMemoryAllocInfo mem_alloc = {};
1019 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
1020 mem_alloc.pNext = NULL;
1021 mem_alloc.allocationSize = 0;
1022 mem_alloc.memoryTypeIndex = 0;
1023
1024 err = vkCreateImage(m_device->device(), &image_create_info, &image);
1025 ASSERT_VK_SUCCESS(err);
1026
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06001027 vkGetImageMemoryRequirements(m_device->device(),
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001028 image,
1029 &mem_reqs);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001030
1031 mem_alloc.allocationSize = mem_reqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06001032 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1033 ASSERT_TRUE(pass);
Tobin Ehlis87f115c2015-09-15 15:02:17 -06001034
1035 // Allocate memory
1036 err = vkAllocMemory(m_device->device(), &mem_alloc, &mem);
1037 ASSERT_VK_SUCCESS(err);
1038
1039 // Introduce validation failure, destroy Image object before binding
1040 vkDestroyImage(m_device->device(), image);
1041 ASSERT_VK_SUCCESS(err);
1042
1043 // Now Try to bind memory to this destroyed object
1044 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1045 // This may very well return an error.
1046 (void) err;
1047
1048 msgFlags = m_errorMonitor->GetState(&msgString);
1049 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while binding memory to a destroyed object";
1050 if (!strstr(msgString.c_str(),"Invalid VkImage Object ")) {
1051 FAIL() << "Error received from BindMemoryToDestroyedObject was not 'Invalid VkImage Object 0x<handle>' but rather '" << msgString.c_str() << "'";
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001052 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001053
1054 vkFreeMemory(m_device->device(), mem);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001055}
Tobin Ehlisb46be812015-10-23 16:00:08 -06001056
1057TEST_F(VkLayerTest, InvalidBufferViewObject)
1058{
1059 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
1060 VkFlags msgFlags;
1061 std::string msgString;
1062 VkResult err;
1063
1064 ASSERT_NO_FATAL_FAILURE(InitState());
1065 m_errorMonitor->ClearState();
1066 VkDescriptorTypeCount ds_type_count = {};
1067 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1068 ds_type_count.count = 1;
1069
1070 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1071 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1072 ds_pool_ci.pNext = NULL;
1073 ds_pool_ci.maxSets = 1;
1074 ds_pool_ci.count = 1;
1075 ds_pool_ci.pTypeCount = &ds_type_count;
1076
1077 VkDescriptorPool ds_pool;
1078 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1079 ASSERT_VK_SUCCESS(err);
1080
1081 VkDescriptorSetLayoutBinding dsl_binding = {};
1082 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1083 dsl_binding.arraySize = 1;
1084 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1085 dsl_binding.pImmutableSamplers = NULL;
1086
1087 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1088 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1089 ds_layout_ci.pNext = NULL;
1090 ds_layout_ci.count = 1;
1091 ds_layout_ci.pBinding = &dsl_binding;
1092 VkDescriptorSetLayout ds_layout;
1093 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1094 ASSERT_VK_SUCCESS(err);
1095
1096 VkDescriptorSet descriptorSet;
1097 VkDescriptorSetAllocInfo alloc_info = {};
1098 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1099 alloc_info.count = 1;
1100 alloc_info.descriptorPool = ds_pool;
1101 alloc_info.pSetLayouts = &ds_layout;
1102 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
1103 ASSERT_VK_SUCCESS(err);
1104
1105 VkBufferView view;
1106 view.handle = 0xbaadbeef; // invalid bufferView object
1107
1108 VkWriteDescriptorSet descriptor_write;
1109 memset(&descriptor_write, 0, sizeof(descriptor_write));
1110 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1111 descriptor_write.destSet = descriptorSet;
1112 descriptor_write.destBinding = 0;
1113 descriptor_write.count = 1;
1114 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
1115 descriptor_write.pTexelBufferView = &view;
1116
1117 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
1118
1119 msgFlags = m_errorMonitor->GetState(&msgString);
1120 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ invalid VkDescriptorBufferInfo.";
1121 if (!strstr(msgString.c_str(),"Invalid VkBufferView Object 0xbaadbeef")) {
1122 FAIL() << "Error received was not 'Invalid VkBufferView Object 0xbaadbeef' but instead '" << msgString.c_str() << "'";
1123 }
1124
1125 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1126 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1127}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001128#endif // OBJ_TRACKER_TESTS
1129
Tobin Ehlis57e6a612015-05-26 16:11:58 -06001130#if DRAW_STATE_TESTS
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001131TEST_F(VkLayerTest, LineWidthStateNotBound)
1132{
1133 VkFlags msgFlags;
1134 std::string msgString;
1135 m_errorMonitor->ClearState();
1136 TEST_DESCRIPTION("Simple Draw Call that validates failure when a line width state object is not bound beforehand");
1137
1138 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
1139
1140 msgFlags = m_errorMonitor->GetState(&msgString);
1141 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Line Width State Object";
1142 if (!strstr(msgString.c_str(),"Dynamic line width state not set for this command buffer")) {
1143 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic line width state not set for this command buffer'";
1144 }
1145}
1146
1147TEST_F(VkLayerTest, DepthBiasStateNotBound)
1148{
1149 VkFlags msgFlags;
1150 std::string msgString;
1151 m_errorMonitor->ClearState();
1152 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bias state object is not bound beforehand");
1153
1154 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
1155
1156 msgFlags = m_errorMonitor->GetState(&msgString);
1157 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bias State Object";
1158 if (!strstr(msgString.c_str(),"Dynamic depth bias state not set for this command buffer")) {
1159 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bias state not set for this command buffer'";
1160 }
1161}
1162
1163TEST_F(VkLayerTest, ViewportStateNotBound)
1164{
1165 VkFlags msgFlags;
1166 std::string msgString;
1167 m_errorMonitor->ClearState();
1168 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1169
1170 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
1171
1172 msgFlags = m_errorMonitor->GetState(&msgString);
1173 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 -06001174 // TODO : Viewport and scissor currently set as a pair in framework so scissor error masks viewport error
1175 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1176 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001177 }
1178}
1179
1180TEST_F(VkLayerTest, ScissorStateNotBound)
1181{
1182 VkFlags msgFlags;
1183 std::string msgString;
1184 m_errorMonitor->ClearState();
1185 TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand");
1186
1187 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
1188
1189 msgFlags = m_errorMonitor->GetState(&msgString);
1190 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Viewport State Object";
1191 if (!strstr(msgString.c_str(),"Dynamic scissor state not set for this command buffer")) {
1192 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic scissor state not set for this command buffer'";
1193 }
1194}
1195
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001196TEST_F(VkLayerTest, BlendStateNotBound)
1197{
1198 VkFlags msgFlags;
1199 std::string msgString;
1200 m_errorMonitor->ClearState();
1201 TEST_DESCRIPTION("Simple Draw Call that validates failure when a blend state object is not bound beforehand");
1202
1203 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
1204
1205 msgFlags = m_errorMonitor->GetState(&msgString);
1206 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Blend State Object";
1207 if (!strstr(msgString.c_str(),"Dynamic blend object state not set for this command buffer")) {
1208 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic blend object state not set for this command buffer'";
1209 }
1210}
1211
1212TEST_F(VkLayerTest, DepthBoundsStateNotBound)
1213{
1214 VkFlags msgFlags;
1215 std::string msgString;
1216 m_errorMonitor->ClearState();
1217 TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth bounds state object is not bound beforehand");
1218
1219 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
1220
1221 msgFlags = m_errorMonitor->GetState(&msgString);
1222 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Binding a Depth Bounds State Object";
1223 if (!strstr(msgString.c_str(),"Dynamic depth bounds state not set for this command buffer")) {
1224 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic depth bounds state not set for this command buffer'";
1225 }
1226}
1227
1228TEST_F(VkLayerTest, StencilReadMaskNotSet)
1229{
1230 VkFlags msgFlags;
1231 std::string msgString;
1232 ASSERT_NO_FATAL_FAILURE(InitState());
1233 m_errorMonitor->ClearState();
1234 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil read mask is not set beforehand");
1235
1236 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
1237
1238 msgFlags = m_errorMonitor->GetState(&msgString);
1239 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Read Mask";
1240 if (!strstr(msgString.c_str(),"Dynamic stencil read mask state not set for this command buffer")) {
1241 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil read mask state not set for this command buffer'";
1242 }
1243}
1244
1245TEST_F(VkLayerTest, StencilWriteMaskNotSet)
1246{
1247 VkFlags msgFlags;
1248 std::string msgString;
1249 ASSERT_NO_FATAL_FAILURE(InitState());
1250 m_errorMonitor->ClearState();
1251 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil write mask is not set beforehand");
1252
1253 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
1254
1255 msgFlags = m_errorMonitor->GetState(&msgString);
1256 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Write Mask";
1257 if (!strstr(msgString.c_str(),"Dynamic stencil write mask state not set for this command buffer")) {
1258 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil write mask state not set for this command buffer'";
1259 }
1260}
1261
1262TEST_F(VkLayerTest, StencilReferenceNotSet)
1263{
1264 VkFlags msgFlags;
1265 std::string msgString;
1266 m_errorMonitor->ClearState();
1267 TEST_DESCRIPTION("Simple Draw Call that validates failure when a stencil reference is not set beforehand");
1268
1269 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
1270
1271 msgFlags = m_errorMonitor->GetState(&msgString);
1272 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from Not Setting a Stencil Reference";
1273 if (!strstr(msgString.c_str(),"Dynamic stencil reference state not set for this command buffer")) {
1274 FAIL() << "Received: '" << msgString.c_str() << "' Expected: 'Dynamic stencil reference state not set for this command buffer'";
1275 }
1276}
1277
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001278TEST_F(VkLayerTest, CmdBufferTwoSubmits)
1279{
1280 vk_testing::Fence testFence;
1281 VkFlags msgFlags;
1282 std::string msgString;
1283
1284 VkFenceCreateInfo fenceInfo = {};
1285 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1286 fenceInfo.pNext = NULL;
1287 fenceInfo.flags = 0;
1288
1289 ASSERT_NO_FATAL_FAILURE(InitState());
1290 ASSERT_NO_FATAL_FAILURE(InitViewport());
1291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1292
Courtney Goeltzenleuchtera32436b2015-10-21 18:11:04 -06001293 // We luck out b/c by default the framework creates CB w/ the VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001294 BeginCommandBuffer();
1295 m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
1296 EndCommandBuffer();
1297
1298 testFence.init(*m_device, fenceInfo);
1299
1300 // Bypass framework since it does the waits automatically
1301 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter1a748e92015-10-27 11:22:14 -06001302 VkSubmitInfo submit_info;
1303 submit_info.waitSemCount = 0;
1304 submit_info.pWaitSemaphores = NULL;
1305 submit_info.cmdBufferCount = 1;
1306 submit_info.pCommandBuffers = &m_cmdBuffer->handle();
1307 submit_info.signalSemCount = 0;
1308 submit_info.pSignalSemaphores = NULL;
1309
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06001310 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001311 ASSERT_VK_SUCCESS( err );
1312
1313 m_errorMonitor->ClearState();
1314 // Cause validation error by re-submitting cmd buffer that should only be submitted once
Courtney Goeltzenleuchter3ec31622015-10-20 18:04:07 -06001315 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001316
1317 msgFlags = m_errorMonitor->GetState(&msgString);
1318 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";
Courtney Goeltzenleuchtera32436b2015-10-21 18:11:04 -06001319 if (!strstr(msgString.c_str(),"was begun w/ VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted")) {
1320 FAIL() << "Error received was not 'CB (0xaddress) was created w/ VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set...'";
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001321 }
1322}
1323
Tobin Ehlise4076782015-06-24 15:53:07 -06001324TEST_F(VkLayerTest, BindPipelineNoRenderPass)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001325{
1326 // Initiate Draw w/o a PSO bound
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001327 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001328 std::string msgString;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001329 VkResult err;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001330
1331 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001332 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001333 m_errorMonitor->ClearState();
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001334
1335 VkDescriptorTypeCount ds_type_count = {};
1336 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1337 ds_type_count.count = 1;
1338
1339 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1340 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1341 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001342 ds_pool_ci.maxSets = 1;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001343 ds_pool_ci.count = 1;
1344 ds_pool_ci.pTypeCount = &ds_type_count;
1345
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001346 VkDescriptorPool ds_pool;
1347 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001348 ASSERT_VK_SUCCESS(err);
1349
1350 VkDescriptorSetLayoutBinding dsl_binding = {};
1351 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1352 dsl_binding.arraySize = 1;
1353 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1354 dsl_binding.pImmutableSamplers = NULL;
1355
1356 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1357 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1358 ds_layout_ci.pNext = NULL;
1359 ds_layout_ci.count = 1;
1360 ds_layout_ci.pBinding = &dsl_binding;
1361
1362 VkDescriptorSetLayout ds_layout;
1363 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1364 ASSERT_VK_SUCCESS(err);
1365
1366 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001367 VkDescriptorSetAllocInfo alloc_info = {};
1368 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1369 alloc_info.count = 1;
1370 alloc_info.descriptorPool = ds_pool;
1371 alloc_info.pSetLayouts = &ds_layout;
1372 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001373 ASSERT_VK_SUCCESS(err);
1374 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
1375 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
1376 pipe_ms_state_ci.pNext = NULL;
1377 pipe_ms_state_ci.rasterSamples = 1;
1378 pipe_ms_state_ci.sampleShadingEnable = 0;
1379 pipe_ms_state_ci.minSampleShading = 1.0;
1380 pipe_ms_state_ci.pSampleMask = NULL;
1381
1382 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1383 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1384 pipeline_layout_ci.pNext = NULL;
1385 pipeline_layout_ci.descriptorSetCount = 1;
1386 pipeline_layout_ci.pSetLayouts = &ds_layout;
1387 VkPipelineLayout pipeline_layout;
1388
1389 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1390 ASSERT_VK_SUCCESS(err);
1391
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001392 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1393 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001394 // but add it to be able to run on more devices
1395 VkPipelineObj pipe(m_device);
1396 pipe.AddShader(&vs);
1397 pipe.AddShader(&fs);
1398 pipe.SetMSAA(&pipe_ms_state_ci);
1399 pipe.CreateVKPipeline(pipeline_layout, renderPass());
1400 m_errorMonitor->ClearState();
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001401 // Calls AllocCommandBuffers
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001402 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1403 VkCmdBufferBeginInfo cmd_buf_info = {};
1404 memset(&cmd_buf_info, 0, sizeof(VkCmdBufferBeginInfo));
1405 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1406 cmd_buf_info.pNext = NULL;
Courtney Goeltzenleuchtera32436b2015-10-21 18:11:04 -06001407 cmd_buf_info.flags = VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001408
1409 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1410 vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001411 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001412 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 -06001413 if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) {
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001414 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 -06001415 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001416
1417 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001418 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1419 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001420}
1421
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001422TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool)
1423{
1424 // Initiate Draw w/o a PSO bound
1425 VkFlags msgFlags;
1426 std::string msgString;
1427 VkResult err;
1428
1429 ASSERT_NO_FATAL_FAILURE(InitState());
1430 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1431 m_errorMonitor->ClearState();
1432
1433 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer descriptor from it
1434 VkDescriptorTypeCount ds_type_count = {};
1435 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
1436 ds_type_count.count = 1;
1437
1438 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1439 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1440 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001441 ds_pool_ci.flags = 0;
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001442 ds_pool_ci.maxSets = 1;
1443 ds_pool_ci.count = 1;
1444 ds_pool_ci.pTypeCount = &ds_type_count;
1445
1446 VkDescriptorPool ds_pool;
1447 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1448 ASSERT_VK_SUCCESS(err);
1449
1450 VkDescriptorSetLayoutBinding dsl_binding = {};
1451 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1452 dsl_binding.arraySize = 1;
1453 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1454 dsl_binding.pImmutableSamplers = NULL;
1455
1456 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1457 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1458 ds_layout_ci.pNext = NULL;
1459 ds_layout_ci.count = 1;
1460 ds_layout_ci.pBinding = &dsl_binding;
1461
1462 VkDescriptorSetLayout ds_layout;
1463 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1464 ASSERT_VK_SUCCESS(err);
1465
1466 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001467 VkDescriptorSetAllocInfo alloc_info = {};
1468 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1469 alloc_info.count = 1;
1470 alloc_info.descriptorPool = ds_pool;
1471 alloc_info.pSetLayouts = &ds_layout;
1472 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc6457d22015-10-20 16:16:04 -06001473
1474 msgFlags = m_errorMonitor->GetState(&msgString);
1475 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after alloc descriptor from pool w/o requested type";
1476 if (!strstr(msgString.c_str(),"Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ")) {
1477 FAIL() << "Error received was not 'Unable to allocate 1 descriptors of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER...' but rather '" << msgString.c_str() << "'";
1478 }
1479
1480 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1481 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1482}
1483
Tobin Ehlis3c543112015-10-08 13:13:50 -06001484TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool)
1485{
1486 VkFlags msgFlags;
1487 std::string msgString;
1488 VkResult err;
1489
1490 ASSERT_NO_FATAL_FAILURE(InitState());
1491 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1492 m_errorMonitor->ClearState();
1493
1494 VkDescriptorTypeCount ds_type_count = {};
1495 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1496 ds_type_count.count = 1;
1497
1498 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1499 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1500 ds_pool_ci.pNext = NULL;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001501 ds_pool_ci.maxSets = 1;
1502 ds_pool_ci.count = 1;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001503 ds_pool_ci.flags = 0;
1504 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
1505 // app can only call vkResetDescriptorPool on this pool.;
Tobin Ehlis3c543112015-10-08 13:13:50 -06001506 ds_pool_ci.pTypeCount = &ds_type_count;
1507
1508 VkDescriptorPool ds_pool;
1509 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
1510 ASSERT_VK_SUCCESS(err);
1511
1512 VkDescriptorSetLayoutBinding dsl_binding = {};
1513 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1514 dsl_binding.arraySize = 1;
1515 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1516 dsl_binding.pImmutableSamplers = NULL;
1517
1518 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1519 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1520 ds_layout_ci.pNext = NULL;
1521 ds_layout_ci.count = 1;
1522 ds_layout_ci.pBinding = &dsl_binding;
1523
1524 VkDescriptorSetLayout ds_layout;
1525 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1526 ASSERT_VK_SUCCESS(err);
1527
1528 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001529 VkDescriptorSetAllocInfo alloc_info = {};
1530 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1531 alloc_info.count = 1;
1532 alloc_info.descriptorPool = ds_pool;
1533 alloc_info.pSetLayouts = &ds_layout;
1534 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3c543112015-10-08 13:13:50 -06001535 ASSERT_VK_SUCCESS(err);
1536
1537 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
1538 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001539 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after freeing descriptor from non-free Pool";
1540
1541 if (!strstr(msgString.c_str(),"It is invalid to call vkFreeDescriptorSets() with a pool created without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.")) {
Tobin Ehlis3c543112015-10-08 13:13:50 -06001542 FAIL() << "Error received was not 'It is invalid to call vkFreeDescriptorSets() with a pool created with...' but instead it was '" << msgString.c_str() << "'";
1543 }
1544
1545 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1546 vkDestroyDescriptorPool(m_device->device(), ds_pool);
1547}
1548
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001549TEST_F(VkLayerTest, InvalidDescriptorPool)
1550{
1551 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1552 // The DS check for this is after driver has been called to validate DS internal data struct
1553 // Attempt to clear DS Pool with bad object
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001554/* VkFlags msgFlags;
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001555 std::string msgString;
1556 VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001;
1557 vkResetDescriptorPool(device(), badPool);
1558
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001559 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001560 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 -06001561 if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) {
1562 FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'";
1563 }*/
1564}
1565
1566TEST_F(VkLayerTest, InvalidDescriptorSet)
1567{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001568 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1569 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001570 // Create a valid cmd buffer
1571 // call vkCmdBindDescriptorSets w/ false DS
1572}
1573
1574TEST_F(VkLayerTest, InvalidDescriptorSetLayout)
1575{
1576 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1577 // The DS check for this is after driver has been called to validate DS internal data struct
1578}
1579
1580TEST_F(VkLayerTest, InvalidPipeline)
1581{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001582 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
1583 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001584 // Create a valid cmd buffer
1585 // call vkCmdBindPipeline w/ false Pipeline
Tobin Ehlise4076782015-06-24 15:53:07 -06001586// VkFlags msgFlags;
1587// std::string msgString;
1588//
1589// ASSERT_NO_FATAL_FAILURE(InitState());
1590// m_errorMonitor->ClearState();
1591// VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1490c912015-07-28 10:17:20 -06001592// BeginCommandBuffer();
Tobin Ehlise4076782015-06-24 15:53:07 -06001593// VkPipeline badPipeline = (VkPipeline)0xbaadb1be;
1594// vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
1595// msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001596// 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 -06001597// if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) {
1598// FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'";
1599// }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001600}
1601
Tobin Ehlis254eca02015-06-25 15:46:59 -06001602TEST_F(VkLayerTest, DescriptorSetNotUpdated)
Tobin Ehlis138b7f12015-05-22 12:38:55 -06001603{
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001604 // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001605 VkFlags msgFlags;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001606 std::string msgString;
1607 VkResult err;
1608
1609 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyand72da752015-08-04 10:49:29 -06001610 ASSERT_NO_FATAL_FAILURE(InitViewport());
1611 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001612 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001613 VkDescriptorTypeCount ds_type_count = {};
1614 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1615 ds_type_count.count = 1;
1616
1617 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1618 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1619 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001620 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001621 ds_pool_ci.count = 1;
1622 ds_pool_ci.pTypeCount = &ds_type_count;
Mike Stroyand72da752015-08-04 10:49:29 -06001623
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001624 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001625 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001626 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001627
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001628 VkDescriptorSetLayoutBinding dsl_binding = {};
1629 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1630 dsl_binding.arraySize = 1;
1631 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1632 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001633
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001634 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1635 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1636 ds_layout_ci.pNext = NULL;
1637 ds_layout_ci.count = 1;
1638 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001639 VkDescriptorSetLayout ds_layout;
1640 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1641 ASSERT_VK_SUCCESS(err);
1642
1643 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001644 VkDescriptorSetAllocInfo alloc_info = {};
1645 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1646 alloc_info.count = 1;
1647 alloc_info.descriptorPool = ds_pool;
1648 alloc_info.pSetLayouts = &ds_layout;
1649 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001650 ASSERT_VK_SUCCESS(err);
1651
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001652 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1653 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1654 pipeline_layout_ci.pNext = NULL;
1655 pipeline_layout_ci.descriptorSetCount = 1;
1656 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001657
1658 VkPipelineLayout pipeline_layout;
1659 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1660 ASSERT_VK_SUCCESS(err);
1661
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001662 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1663 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001664 // but add it to be able to run on more devices
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001665
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001666 VkPipelineObj pipe(m_device);
1667 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06001668 pipe.AddShader(&fs);
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001669 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06001670
1671 BeginCommandBuffer();
Tony Barbour4e8d1b12015-08-04 17:05:26 -06001672 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tony Barbour1490c912015-07-28 10:17:20 -06001673 vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001674
Tobin Ehlis254eca02015-06-25 15:46:59 -06001675 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001676 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 -06001677 if (!strstr(msgString.c_str()," bound but it was never updated. ")) {
1678 FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'";
1679 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001680
1681 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001682 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1683 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001684}
1685
1686TEST_F(VkLayerTest, NoBeginCmdBuffer)
1687{
1688 VkFlags msgFlags;
1689 std::string msgString;
1690
1691 ASSERT_NO_FATAL_FAILURE(InitState());
1692 m_errorMonitor->ClearState();
Tony Barbour1490c912015-07-28 10:17:20 -06001693 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001694 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
1695 vkEndCommandBuffer(cmdBuffer.GetBufferHandle());
1696 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001697 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 -06001698 if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) {
1699 FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'";
1700 }
1701}
1702
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001703TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass)
1704{
1705 VkFlags msgFlags;
1706 std::string msgString;
1707
1708 ASSERT_NO_FATAL_FAILURE(InitState());
1709 m_errorMonitor->ClearState();
1710
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001711 // Calls AllocCommandBuffers
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001712 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
1713
1714 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Cody Northrop10d8f982015-08-04 17:35:57 -06001715 VkCmdBufferBeginInfo cmd_buf_info = {};
1716 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1717 cmd_buf_info.pNext = NULL;
Courtney Goeltzenleuchtera32436b2015-10-21 18:11:04 -06001718 cmd_buf_info.flags = VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Cody Northrop10d8f982015-08-04 17:35:57 -06001719 cmd_buf_info.renderPass = (VkRenderPass)0xcadecade;
1720 cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade;
1721
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001722
1723 // The error should be caught by validation of the BeginCommandBuffer call
1724 vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info);
1725
1726 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001727 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 -06001728 if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) {
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001729 FAIL() << "Error received was not 'vkAllocCommandBuffers(): Primary Command Buffer may not specify framebuffer or renderpass parameters'";
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001730 }
1731}
1732
1733TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass)
1734{
1735 VkFlags msgFlags;
1736 std::string msgString;
1737 VkResult err;
1738 VkCmdBuffer draw_cmd;
1739 VkCmdPool cmd_pool;
1740
1741 ASSERT_NO_FATAL_FAILURE(InitState());
1742 m_errorMonitor->ClearState();
1743
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001744 VkCmdBufferAllocInfo cmd = {};
1745 cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_ALLOC_INFO;
Cody Northrop10d8f982015-08-04 17:35:57 -06001746 cmd.pNext = NULL;
1747 cmd.cmdPool = m_cmdPool;
1748 cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001749 cmd.count = 1;
Cody Northrop10d8f982015-08-04 17:35:57 -06001750
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001751 err = vkAllocCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyan2237f522015-08-18 14:40:24 -06001752 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001753
1754 // Force the failure by not setting the Renderpass and Framebuffer fields
Cody Northrop10d8f982015-08-04 17:35:57 -06001755 VkCmdBufferBeginInfo cmd_buf_info = {};
1756 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1757 cmd_buf_info.pNext = NULL;
Courtney Goeltzenleuchtera32436b2015-10-21 18:11:04 -06001758 cmd_buf_info.flags = VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001759
1760 // The error should be caught by validation of the BeginCommandBuffer call
1761 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
1762
1763 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001764 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 -06001765 if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) {
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001766 FAIL() << "Error received was not 'vkAllocCommandBuffers(): Secondary Command Buffer must specify framebuffer and renderpass parameters'";
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001767 }
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001768 vkFreeCommandBuffers(m_device->device(), m_cmdPool, 1, &draw_cmd);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001769}
1770
Tobin Ehlis254eca02015-06-25 15:46:59 -06001771TEST_F(VkLayerTest, InvalidPipelineCreateState)
1772{
1773 // Attempt to Create Gfx Pipeline w/o a VS
1774 VkFlags msgFlags;
1775 std::string msgString;
1776 VkResult err;
1777
1778 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001779 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis254eca02015-06-25 15:46:59 -06001780 m_errorMonitor->ClearState();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001781
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001782 VkDescriptorTypeCount ds_type_count = {};
1783 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1784 ds_type_count.count = 1;
1785
1786 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1787 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1788 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001789 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001790 ds_pool_ci.count = 1;
1791 ds_pool_ci.pTypeCount = &ds_type_count;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06001792
Tobin Ehlis254eca02015-06-25 15:46:59 -06001793 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001794 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001795 ASSERT_VK_SUCCESS(err);
1796
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001797 VkDescriptorSetLayoutBinding dsl_binding = {};
1798 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1799 dsl_binding.arraySize = 1;
1800 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1801 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001802
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001803 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1804 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1805 ds_layout_ci.pNext = NULL;
1806 ds_layout_ci.count = 1;
1807 ds_layout_ci.pBinding = &dsl_binding;
1808
Tobin Ehlis254eca02015-06-25 15:46:59 -06001809 VkDescriptorSetLayout ds_layout;
1810 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1811 ASSERT_VK_SUCCESS(err);
1812
1813 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001814 VkDescriptorSetAllocInfo alloc_info = {};
1815 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
1816 alloc_info.count = 1;
1817 alloc_info.descriptorPool = ds_pool;
1818 alloc_info.pSetLayouts = &ds_layout;
1819 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001820 ASSERT_VK_SUCCESS(err);
1821
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001822 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1823 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001824 pipeline_layout_ci.descriptorSetCount = 1;
1825 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001826
1827 VkPipelineLayout pipeline_layout;
1828 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1829 ASSERT_VK_SUCCESS(err);
1830
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001831 VkViewport vp = {}; // Just need dummy vp to point to
1832 VkRect2D sc = {}; // dummy scissor to point to
1833
1834 VkPipelineViewportStateCreateInfo vp_state_ci = {};
1835 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
1836 vp_state_ci.scissorCount = 1;
1837 vp_state_ci.pScissors = &sc;
1838 vp_state_ci.viewportCount = 1;
1839 vp_state_ci.pViewports = &vp;
1840
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001841 VkGraphicsPipelineCreateInfo gp_ci = {};
1842 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001843 gp_ci.pViewportState = &vp_state_ci;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001844 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1845 gp_ci.layout = pipeline_layout;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06001846 gp_ci.renderPass = renderPass();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001847
1848 VkPipelineCacheCreateInfo pc_ci = {};
1849 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06001850 pc_ci.initialSize = 0;
1851 pc_ci.initialData = 0;
1852 pc_ci.maxSize = 0;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001853
1854 VkPipeline pipeline;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001855 VkPipelineCache pipelineCache;
1856
1857 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1858 ASSERT_VK_SUCCESS(err);
1859 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06001860
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001861 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06001862 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 -06001863 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) {
1864 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'";
1865 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001866
1867 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1868 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001869 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1870 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis254eca02015-06-25 15:46:59 -06001871}
Tobin Ehlis20693172015-09-17 08:46:18 -06001872/*// TODO : This test should be good, but needs Tess support in compiler to run
1873TEST_F(VkLayerTest, InvalidPatchControlPoints)
1874{
1875 // Attempt to Create Gfx Pipeline w/o a VS
1876 VkFlags msgFlags;
1877 std::string msgString;
1878 VkResult err;
Tobin Ehlis254eca02015-06-25 15:46:59 -06001879
Tobin Ehlis20693172015-09-17 08:46:18 -06001880 ASSERT_NO_FATAL_FAILURE(InitState());
1881 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1882 m_errorMonitor->ClearState();
1883
1884 VkDescriptorTypeCount ds_type_count = {};
1885 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1886 ds_type_count.count = 1;
1887
1888 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1889 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1890 ds_pool_ci.pNext = NULL;
1891 ds_pool_ci.count = 1;
1892 ds_pool_ci.pTypeCount = &ds_type_count;
1893
1894 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001895 err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, &ds_pool);
Tobin Ehlis20693172015-09-17 08:46:18 -06001896 ASSERT_VK_SUCCESS(err);
1897
1898 VkDescriptorSetLayoutBinding dsl_binding = {};
1899 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1900 dsl_binding.arraySize = 1;
1901 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1902 dsl_binding.pImmutableSamplers = NULL;
1903
1904 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1905 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1906 ds_layout_ci.pNext = NULL;
1907 ds_layout_ci.count = 1;
1908 ds_layout_ci.pBinding = &dsl_binding;
1909
1910 VkDescriptorSetLayout ds_layout;
1911 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
1912 ASSERT_VK_SUCCESS(err);
1913
1914 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06001915 err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis20693172015-09-17 08:46:18 -06001916 ASSERT_VK_SUCCESS(err);
1917
1918 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1919 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1920 pipeline_layout_ci.pNext = NULL;
1921 pipeline_layout_ci.descriptorSetCount = 1;
1922 pipeline_layout_ci.pSetLayouts = &ds_layout;
1923
1924 VkPipelineLayout pipeline_layout;
1925 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
1926 ASSERT_VK_SUCCESS(err);
1927
1928 VkPipelineShaderStageCreateInfo shaderStages[3];
1929 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
1930
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001931 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06001932 // Just using VS txt for Tess shaders as we don't care about functionality
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001933 VkShaderObj tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
1934 VkShaderObj te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
Tobin Ehlis20693172015-09-17 08:46:18 -06001935
1936 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001937 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06001938 shaderStages[0].shader = vs.handle();
1939 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001940 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06001941 shaderStages[1].shader = tc.handle();
1942 shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001943 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis20693172015-09-17 08:46:18 -06001944 shaderStages[2].shader = te.handle();
1945
1946 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
1947 iaCI.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
1948 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH;
1949
1950 VkPipelineTessellationStateCreateInfo tsCI = {};
1951 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
1952 tsCI.patchControlPoints = 0; // This will cause an error
1953
1954 VkGraphicsPipelineCreateInfo gp_ci = {};
1955 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1956 gp_ci.pNext = NULL;
1957 gp_ci.stageCount = 3;
1958 gp_ci.pStages = shaderStages;
1959 gp_ci.pVertexInputState = NULL;
1960 gp_ci.pInputAssemblyState = &iaCI;
1961 gp_ci.pTessellationState = &tsCI;
1962 gp_ci.pViewportState = NULL;
1963 gp_ci.pRasterState = NULL;
1964 gp_ci.pMultisampleState = NULL;
1965 gp_ci.pDepthStencilState = NULL;
1966 gp_ci.pColorBlendState = NULL;
1967 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
1968 gp_ci.layout = pipeline_layout;
1969 gp_ci.renderPass = renderPass();
1970
1971 VkPipelineCacheCreateInfo pc_ci = {};
1972 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1973 pc_ci.pNext = NULL;
1974 pc_ci.initialSize = 0;
1975 pc_ci.initialData = 0;
1976 pc_ci.maxSize = 0;
1977
1978 VkPipeline pipeline;
1979 VkPipelineCache pipelineCache;
1980
1981 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
1982 ASSERT_VK_SUCCESS(err);
1983 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
1984
1985 msgFlags = m_errorMonitor->GetState(&msgString);
1986 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Tess Gfx Pipeline w/ 0 patchControlPoints.";
1987 if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive ")) {
1988 FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive...' but instead '" << msgString.c_str() << "'";
1989 }
Mike Stroyan2237f522015-08-18 14:40:24 -06001990
1991 vkDestroyPipelineCache(m_device->device(), pipelineCache);
1992 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06001993 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
1994 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis20693172015-09-17 08:46:18 -06001995}
1996*/
Tobin Ehlis9e839e52015-10-01 11:15:13 -06001997// Set scissor and viewport counts to different numbers
1998TEST_F(VkLayerTest, PSOViewportScissorCountMismatch)
1999{
2000 // Attempt to Create Gfx Pipeline w/o a VS
2001 VkFlags msgFlags;
2002 std::string msgString;
2003 VkResult err;
2004
2005 ASSERT_NO_FATAL_FAILURE(InitState());
2006 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2007 m_errorMonitor->ClearState();
2008
2009 VkDescriptorTypeCount ds_type_count = {};
2010 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2011 ds_type_count.count = 1;
2012
2013 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2014 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002015 ds_pool_ci.maxSets = 1;
2016 ds_pool_ci.count = 1;
2017 ds_pool_ci.pTypeCount = &ds_type_count;
2018
2019 VkDescriptorPool ds_pool;
2020 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2021 ASSERT_VK_SUCCESS(err);
2022
2023 VkDescriptorSetLayoutBinding dsl_binding = {};
2024 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2025 dsl_binding.arraySize = 1;
2026 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2027
2028 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2029 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2030 ds_layout_ci.count = 1;
2031 ds_layout_ci.pBinding = &dsl_binding;
2032
2033 VkDescriptorSetLayout ds_layout;
2034 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2035 ASSERT_VK_SUCCESS(err);
2036
2037 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002038 VkDescriptorSetAllocInfo alloc_info = {};
2039 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2040 alloc_info.count = 1;
2041 alloc_info.descriptorPool = ds_pool;
2042 alloc_info.pSetLayouts = &ds_layout;
2043 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002044 ASSERT_VK_SUCCESS(err);
2045
2046 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2047 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2048 pipeline_layout_ci.descriptorSetCount = 1;
2049 pipeline_layout_ci.pSetLayouts = &ds_layout;
2050
2051 VkPipelineLayout pipeline_layout;
2052 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2053 ASSERT_VK_SUCCESS(err);
2054
2055 VkViewport vp = {}; // Just need dummy vp to point to
2056
2057 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2058 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2059 vp_state_ci.scissorCount = 0;
2060 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
2061 vp_state_ci.pViewports = &vp;
2062
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002063 VkPipelineShaderStageCreateInfo shaderStages[2];
2064 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002065
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002066 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2067 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002068 // but add it to be able to run on more devices
2069 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002070 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002071 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002072
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002073 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002074 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002075 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002076
2077 VkGraphicsPipelineCreateInfo gp_ci = {};
2078 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002079 gp_ci.stageCount = 2;
2080 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002081 gp_ci.pViewportState = &vp_state_ci;
2082 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2083 gp_ci.layout = pipeline_layout;
2084 gp_ci.renderPass = renderPass();
2085
2086 VkPipelineCacheCreateInfo pc_ci = {};
2087 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2088
2089 VkPipeline pipeline;
2090 VkPipelineCache pipelineCache;
2091
2092 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2093 ASSERT_VK_SUCCESS(err);
2094 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2095
2096 msgFlags = m_errorMonitor->GetState(&msgString);
2097 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/ viewport and scissor count mismatch.";
2098 if (!strstr(msgString.c_str(),"Gfx Pipeline viewport count (1) must match scissor count (0).")) {
2099 FAIL() << "Error received was not 'Gfx Pipeline viewport count (1) must match scissor count (0).' but instead it was '" << msgString.c_str() << "'";
2100 }
2101
2102 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2103 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002104 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2105 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2106}
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002107// Don't set viewport state in PSO. This is an error b/c we always need this state
2108// for the counts even if the data is going to be set dynamically.
2109TEST_F(VkLayerTest, PSOViewportStateNotSet)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002110{
2111 // Attempt to Create Gfx Pipeline w/o a VS
2112 VkFlags msgFlags;
2113 std::string msgString;
2114 VkResult err;
2115
2116 ASSERT_NO_FATAL_FAILURE(InitState());
2117 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2118 m_errorMonitor->ClearState();
2119
2120 VkDescriptorTypeCount ds_type_count = {};
2121 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2122 ds_type_count.count = 1;
2123
2124 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2125 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002126 ds_pool_ci.maxSets = 1;
2127 ds_pool_ci.count = 1;
2128 ds_pool_ci.pTypeCount = &ds_type_count;
2129
2130 VkDescriptorPool ds_pool;
2131 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2132 ASSERT_VK_SUCCESS(err);
2133
2134 VkDescriptorSetLayoutBinding dsl_binding = {};
2135 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2136 dsl_binding.arraySize = 1;
2137 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2138
2139 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2140 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2141 ds_layout_ci.count = 1;
2142 ds_layout_ci.pBinding = &dsl_binding;
2143
2144 VkDescriptorSetLayout ds_layout;
2145 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2146 ASSERT_VK_SUCCESS(err);
2147
2148 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002149 VkDescriptorSetAllocInfo alloc_info = {};
2150 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2151 alloc_info.count = 1;
2152 alloc_info.descriptorPool = ds_pool;
2153 alloc_info.pSetLayouts = &ds_layout;
2154 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002155 ASSERT_VK_SUCCESS(err);
2156
2157 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2158 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2159 pipeline_layout_ci.descriptorSetCount = 1;
2160 pipeline_layout_ci.pSetLayouts = &ds_layout;
2161
2162 VkPipelineLayout pipeline_layout;
2163 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2164 ASSERT_VK_SUCCESS(err);
2165
2166 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2167 // Set scissor as dynamic to avoid second error
2168 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2169 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2170 dyn_state_ci.dynamicStateCount = 1;
2171 dyn_state_ci.pDynamicStates = &sc_state;
2172
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002173 VkPipelineShaderStageCreateInfo shaderStages[2];
2174 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002175
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002176 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2177 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002178 // but add it to be able to run on more devices
2179 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002180 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002181 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002182
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002183 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002184 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002185 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002186
2187 VkGraphicsPipelineCreateInfo gp_ci = {};
2188 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002189 gp_ci.stageCount = 2;
2190 gp_ci.pStages = shaderStages;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002191 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state should cause validation error
2192 gp_ci.pDynamicState = &dyn_state_ci;
2193 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2194 gp_ci.layout = pipeline_layout;
2195 gp_ci.renderPass = renderPass();
2196
2197 VkPipelineCacheCreateInfo pc_ci = {};
2198 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2199
2200 VkPipeline pipeline;
2201 VkPipelineCache pipelineCache;
2202
2203 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2204 ASSERT_VK_SUCCESS(err);
2205 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2206
2207 msgFlags = m_errorMonitor->GetState(&msgString);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002208 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o viewport state set.";
2209 if (!strstr(msgString.c_str(),"Gfx Pipeline pViewportState is null. Even if ")) {
2210 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 -06002211 }
2212
2213 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2214 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002215 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2216 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2217}
2218// Create PSO w/o non-zero viewportCount but no viewport data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002219// Then run second test where dynamic scissor count doesn't match PSO scissor count
2220TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002221{
2222 VkFlags msgFlags;
2223 std::string msgString;
2224 VkResult err;
2225
2226 ASSERT_NO_FATAL_FAILURE(InitState());
2227 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2228 m_errorMonitor->ClearState();
2229
2230 VkDescriptorTypeCount ds_type_count = {};
2231 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2232 ds_type_count.count = 1;
2233
2234 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2235 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002236 ds_pool_ci.maxSets = 1;
2237 ds_pool_ci.count = 1;
2238 ds_pool_ci.pTypeCount = &ds_type_count;
2239
2240 VkDescriptorPool ds_pool;
2241 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2242 ASSERT_VK_SUCCESS(err);
2243
2244 VkDescriptorSetLayoutBinding dsl_binding = {};
2245 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2246 dsl_binding.arraySize = 1;
2247 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2248
2249 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2250 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2251 ds_layout_ci.count = 1;
2252 ds_layout_ci.pBinding = &dsl_binding;
2253
2254 VkDescriptorSetLayout ds_layout;
2255 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2256 ASSERT_VK_SUCCESS(err);
2257
2258 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002259 VkDescriptorSetAllocInfo alloc_info = {};
2260 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2261 alloc_info.count = 1;
2262 alloc_info.descriptorPool = ds_pool;
2263 alloc_info.pSetLayouts = &ds_layout;
2264 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002265 ASSERT_VK_SUCCESS(err);
2266
2267 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2268 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2269 pipeline_layout_ci.descriptorSetCount = 1;
2270 pipeline_layout_ci.pSetLayouts = &ds_layout;
2271
2272 VkPipelineLayout pipeline_layout;
2273 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2274 ASSERT_VK_SUCCESS(err);
2275
2276 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2277 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2278 vp_state_ci.viewportCount = 1;
2279 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
2280 vp_state_ci.scissorCount = 1;
2281 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
2282
2283 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
2284 // Set scissor as dynamic to avoid that error
2285 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2286 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2287 dyn_state_ci.dynamicStateCount = 1;
2288 dyn_state_ci.pDynamicStates = &sc_state;
2289
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002290 VkPipelineShaderStageCreateInfo shaderStages[2];
2291 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002292
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002293 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2294 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002295 // but add it to be able to run on more devices
2296 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002297 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002298 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002299
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002300 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002301 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002302 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002303
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002304 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2305 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2306 vi_ci.pNext = nullptr;
2307 vi_ci.bindingCount = 0;
2308 vi_ci.pVertexBindingDescriptions = nullptr;
2309 vi_ci.attributeCount = 0;
2310 vi_ci.pVertexAttributeDescriptions = nullptr;
2311
2312 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2313 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2314 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2315
2316 VkPipelineRasterStateCreateInfo rs_ci = {};
2317 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2318 rs_ci.pNext = nullptr;
2319
2320 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2321 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2322 cb_ci.pNext = nullptr;
2323
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002324 VkGraphicsPipelineCreateInfo gp_ci = {};
2325 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002326 gp_ci.stageCount = 2;
2327 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002328 gp_ci.pVertexInputState = &vi_ci;
2329 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002330 gp_ci.pViewportState = &vp_state_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002331 gp_ci.pRasterState = &rs_ci;
2332 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002333 gp_ci.pDynamicState = &dyn_state_ci;
2334 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2335 gp_ci.layout = pipeline_layout;
2336 gp_ci.renderPass = renderPass();
2337
2338 VkPipelineCacheCreateInfo pc_ci = {};
2339 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2340
2341 VkPipeline pipeline;
2342 VkPipelineCache pipelineCache;
2343
2344 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2345 ASSERT_VK_SUCCESS(err);
2346 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2347
2348 msgFlags = m_errorMonitor->GetState(&msgString);
2349 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2350 if (!strstr(msgString.c_str(),"Gfx Pipeline viewportCount is 1, but pViewports is NULL. ")) {
2351 FAIL() << "Error received was not 'Gfx Pipeline viewportCount is 1, but pViewports is NULL...' but instead it was '" << msgString.c_str() << "'";
2352 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002353 m_errorMonitor->ClearState();
2354 // Now hit second fail case where we set scissor w/ different count than PSO
2355 // First need to successfully create the PSO from above by setting pViewports
2356 VkViewport vp = {}; // Just need dummy vp to point to
2357 vp_state_ci.pViewports = &vp;
2358 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2359 ASSERT_VK_SUCCESS(err);
2360 BeginCommandBuffer();
2361 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2362 VkRect2D scissors[2] = {}; // don't care about data
2363 // Count of 2 doesn't match PSO count of 1
2364 vkCmdSetScissor(m_cmdBuffer->GetBufferHandle(), 2, scissors);
2365 Draw(1, 0, 0, 0);
2366
2367 msgFlags = m_errorMonitor->GetState(&msgString);
2368 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic scissorCount different from PSO scissorCount.";
2369 if (!strstr(msgString.c_str(),"Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1. These counts must match.")) {
2370 FAIL() << "Error received was not 'Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO scissorCount is 1...' but instead it was '" << msgString.c_str() << "'";
2371 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002372
2373 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2374 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002375 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2376 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2377}
2378// Create PSO w/o non-zero scissorCount but no scissor data
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002379// Then run second test where dynamic viewportCount doesn't match PSO viewportCount
2380TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch)
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002381{
2382 VkFlags msgFlags;
2383 std::string msgString;
2384 VkResult err;
2385
2386 ASSERT_NO_FATAL_FAILURE(InitState());
2387 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2388 m_errorMonitor->ClearState();
2389
2390 VkDescriptorTypeCount ds_type_count = {};
2391 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2392 ds_type_count.count = 1;
2393
2394 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2395 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002396 ds_pool_ci.maxSets = 1;
2397 ds_pool_ci.count = 1;
2398 ds_pool_ci.pTypeCount = &ds_type_count;
2399
2400 VkDescriptorPool ds_pool;
2401 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
2402 ASSERT_VK_SUCCESS(err);
2403
2404 VkDescriptorSetLayoutBinding dsl_binding = {};
2405 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2406 dsl_binding.arraySize = 1;
2407 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2408
2409 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2410 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2411 ds_layout_ci.count = 1;
2412 ds_layout_ci.pBinding = &dsl_binding;
2413
2414 VkDescriptorSetLayout ds_layout;
2415 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2416 ASSERT_VK_SUCCESS(err);
2417
2418 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002419 VkDescriptorSetAllocInfo alloc_info = {};
2420 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2421 alloc_info.count = 1;
2422 alloc_info.descriptorPool = ds_pool;
2423 alloc_info.pSetLayouts = &ds_layout;
2424 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002425 ASSERT_VK_SUCCESS(err);
2426
2427 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
2428 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2429 pipeline_layout_ci.descriptorSetCount = 1;
2430 pipeline_layout_ci.pSetLayouts = &ds_layout;
2431
2432 VkPipelineLayout pipeline_layout;
2433 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
2434 ASSERT_VK_SUCCESS(err);
2435
2436 VkPipelineViewportStateCreateInfo vp_state_ci = {};
2437 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
2438 vp_state_ci.scissorCount = 1;
2439 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
2440 vp_state_ci.viewportCount = 1;
2441 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
2442
2443 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
2444 // Set scissor as dynamic to avoid that error
2445 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
2446 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
2447 dyn_state_ci.dynamicStateCount = 1;
2448 dyn_state_ci.pDynamicStates = &vp_state;
2449
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002450 VkPipelineShaderStageCreateInfo shaderStages[2];
2451 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002452
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002453 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2454 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002455 // but add it to be able to run on more devices
2456 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002457 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002458 shaderStages[0].shader = vs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002459
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002460 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002461 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002462 shaderStages[1].shader = fs.handle();
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002463
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002464 VkPipelineVertexInputStateCreateInfo vi_ci = {};
2465 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
2466 vi_ci.pNext = nullptr;
2467 vi_ci.bindingCount = 0;
2468 vi_ci.pVertexBindingDescriptions = nullptr;
2469 vi_ci.attributeCount = 0;
2470 vi_ci.pVertexAttributeDescriptions = nullptr;
2471
2472 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
2473 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
2474 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
2475
2476 VkPipelineRasterStateCreateInfo rs_ci = {};
2477 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
2478 rs_ci.pNext = nullptr;
2479
2480 VkPipelineColorBlendStateCreateInfo cb_ci = {};
2481 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
2482 cb_ci.pNext = nullptr;
2483
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002484 VkGraphicsPipelineCreateInfo gp_ci = {};
2485 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Cody Northrop1a0f3e62015-10-05 14:44:45 -06002486 gp_ci.stageCount = 2;
2487 gp_ci.pStages = shaderStages;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002488 gp_ci.pVertexInputState = &vi_ci;
2489 gp_ci.pInputAssemblyState = &ia_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002490 gp_ci.pViewportState = &vp_state_ci;
Cody Northrop42cbe3b2015-10-06 10:33:21 -06002491 gp_ci.pRasterState = &rs_ci;
2492 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002493 gp_ci.pDynamicState = &dyn_state_ci;
2494 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
2495 gp_ci.layout = pipeline_layout;
2496 gp_ci.renderPass = renderPass();
2497
2498 VkPipelineCacheCreateInfo pc_ci = {};
2499 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
2500
2501 VkPipeline pipeline;
2502 VkPipelineCache pipelineCache;
2503
2504 err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache);
2505 ASSERT_VK_SUCCESS(err);
2506 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2507
2508 msgFlags = m_errorMonitor->GetState(&msgString);
2509 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating Gfx Pipeline w/o scissor set.";
2510 if (!strstr(msgString.c_str(),"Gfx Pipeline scissorCount is 1, but pScissors is NULL. ")) {
2511 FAIL() << "Error received was not 'Gfx Pipeline scissorCount is 1, but pScissors is NULL...' but instead it was '" << msgString.c_str() << "'";
2512 }
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06002513 m_errorMonitor->ClearState();
2514 // Now hit second fail case where we set scissor w/ different count than PSO
2515 // First need to successfully create the PSO from above by setting pViewports
2516 VkRect2D sc = {}; // Just need dummy vp to point to
2517 vp_state_ci.pScissors = &sc;
2518 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline);
2519 ASSERT_VK_SUCCESS(err);
2520 BeginCommandBuffer();
2521 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2522 VkViewport viewports[2] = {}; // don't care about data
2523 // Count of 2 doesn't match PSO count of 1
2524 vkCmdSetViewport(m_cmdBuffer->GetBufferHandle(), 2, viewports);
2525 Draw(1, 0, 0, 0);
2526
2527 msgFlags = m_errorMonitor->GetState(&msgString);
2528 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after setting dynamic viewportCount different from PSO viewportCount.";
2529 if (!strstr(msgString.c_str(),"Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1. These counts must match.")) {
2530 FAIL() << "Error received was not 'Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO viewportCount is 1...' but instead it was '" << msgString.c_str() << "'";
2531 }
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002532
2533 vkDestroyPipelineCache(m_device->device(), pipelineCache);
2534 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Tobin Ehlis9e839e52015-10-01 11:15:13 -06002535 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2536 vkDestroyDescriptorPool(m_device->device(), ds_pool);
2537}
2538
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002539TEST_F(VkLayerTest, NullRenderPass)
2540{
2541 // Bind a NULL RenderPass
2542 VkFlags msgFlags;
2543 std::string msgString;
2544
2545 ASSERT_NO_FATAL_FAILURE(InitState());
2546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2547 m_errorMonitor->ClearState();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002548
Tony Barbour1490c912015-07-28 10:17:20 -06002549 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002550 // Don't care about RenderPass handle b/c error should be flagged before that
Tony Barbour1490c912015-07-28 10:17:20 -06002551 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002552
2553 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002554 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after binding NULL RenderPass.";
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002555 if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) {
2556 FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'";
2557 }
2558}
2559
Tobin Ehlis254eca02015-06-25 15:46:59 -06002560TEST_F(VkLayerTest, RenderPassWithinRenderPass)
2561{
2562 // Bind a BeginRenderPass within an active RenderPass
2563 VkFlags msgFlags;
2564 std::string msgString;
2565
2566 ASSERT_NO_FATAL_FAILURE(InitState());
2567 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2568 m_errorMonitor->ClearState();
Tobin Ehlis254eca02015-06-25 15:46:59 -06002569
Tony Barbour1490c912015-07-28 10:17:20 -06002570 BeginCommandBuffer();
Tobin Ehlisb8b06b52015-06-25 16:27:19 -06002571 // Just create a dummy Renderpass that's non-NULL so we can get to the proper error
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002572 VkRenderPassBeginInfo rp_begin = {};
2573 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
2574 rp_begin.pNext = NULL;
Tobin Ehlisf2f97402015-09-11 12:57:55 -06002575 rp_begin.renderPass = renderPass();
2576 rp_begin.framebuffer = framebuffer();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06002577
Tony Barbour1490c912015-07-28 10:17:20 -06002578 vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE);
Tobin Ehlis254eca02015-06-25 15:46:59 -06002579
2580 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002581 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 -06002582 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2583 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002584 }
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002585}
2586
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002587TEST_F(VkLayerTest, FillBufferWithinRenderPass)
2588{
2589 // Call CmdFillBuffer within an active renderpass
2590 VkFlags msgFlags;
2591 std::string msgString;
2592
2593 ASSERT_NO_FATAL_FAILURE(InitState());
2594 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2595 m_errorMonitor->ClearState();
2596
2597 // Renderpass is started here
2598 BeginCommandBuffer();
2599
2600 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2601 vk_testing::Buffer destBuffer;
2602 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
2603
2604 m_cmdBuffer->FillBuffer(destBuffer.handle(), 0, 4, 0x11111111);
2605
2606 msgFlags = m_errorMonitor->GetState(&msgString);
2607 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2608 "Did not receive error after calling CmdFillBuffer w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002609 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2610 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002611 }
2612}
2613
2614TEST_F(VkLayerTest, UpdateBufferWithinRenderPass)
2615{
2616 // Call CmdUpdateBuffer within an active renderpass
2617 VkFlags msgFlags;
2618 std::string msgString;
2619
2620 ASSERT_NO_FATAL_FAILURE(InitState());
2621 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2622 m_errorMonitor->ClearState();
2623
2624 // Renderpass is started here
2625 BeginCommandBuffer();
2626
2627 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2628 vk_testing::Buffer destBuffer;
2629 destBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
2630
2631 VkDeviceSize destOffset = 0;
2632 VkDeviceSize dataSize = 1024;
2633 const uint32_t *pData = NULL;
2634
2635 vkCmdUpdateBuffer(m_cmdBuffer->GetBufferHandle(), destBuffer.handle(), destOffset, dataSize, pData);
2636
2637 msgFlags = m_errorMonitor->GetState(&msgString);
2638 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2639 "Did not receive error after calling CmdUpdateBuffer w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002640 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2641 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002642 }
2643}
2644
2645TEST_F(VkLayerTest, ClearColorImageWithinRenderPass)
2646{
2647 // Call CmdClearColorImage within an active RenderPass
2648 VkFlags msgFlags;
2649 std::string msgString;
2650
2651 ASSERT_NO_FATAL_FAILURE(InitState());
2652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2653 m_errorMonitor->ClearState();
2654
2655 // Renderpass is started here
2656 BeginCommandBuffer();
2657
2658 VkClearColorValue clear_color = {0};
2659 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2660 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2661 const int32_t tex_width = 32;
2662 const int32_t tex_height = 32;
2663 VkImageCreateInfo image_create_info = {};
2664 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2665 image_create_info.pNext = NULL;
2666 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2667 image_create_info.format = tex_format;
2668 image_create_info.extent.width = tex_width;
2669 image_create_info.extent.height = tex_height;
2670 image_create_info.extent.depth = 1;
2671 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06002672 image_create_info.arrayLayers = 1;
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002673 image_create_info.samples = 1;
2674 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2675 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2676
2677 vk_testing::Image destImage;
2678 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
2679
2680 const VkImageSubresourceRange range =
2681 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
2682
2683 vkCmdClearColorImage(m_cmdBuffer->GetBufferHandle(),
2684 destImage.handle(),
2685 VK_IMAGE_LAYOUT_GENERAL,
2686 &clear_color,
2687 1,
2688 &range);
2689
2690 msgFlags = m_errorMonitor->GetState(&msgString);
2691 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2692 "Did not receive error after calling CmdClearColorImage w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002693 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2694 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002695 }
2696}
2697
2698TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass)
2699{
2700 // Call CmdClearDepthStencilImage within an active RenderPass
2701 VkFlags msgFlags;
2702 std::string msgString;
2703
2704 ASSERT_NO_FATAL_FAILURE(InitState());
2705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2706 m_errorMonitor->ClearState();
2707
2708 // Renderpass is started here
2709 BeginCommandBuffer();
2710
2711 VkClearDepthStencilValue clear_value = {0};
2712 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2713 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
2714 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2715 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
2716 image_create_info.extent.width = 64;
2717 image_create_info.extent.height = 64;
2718 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2719 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
2720
2721 vk_testing::Image destImage;
2722 destImage.init(*m_device, (const VkImageCreateInfo&)image_create_info, reqs);
2723
2724 const VkImageSubresourceRange range =
2725 vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
2726
2727 vkCmdClearDepthStencilImage(m_cmdBuffer->GetBufferHandle(),
2728 destImage.handle(),
2729 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2730 &clear_value,
2731 1,
2732 &range);
2733
2734 msgFlags = m_errorMonitor->GetState(&msgString);
2735 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
2736 "Did not receive error after calling CmdClearDepthStencilImage w/i an active RenderPass.";
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06002737 if (!strstr(msgString.c_str(),"It is invalid to issue this call inside an active render pass")) {
2738 FAIL() << "Error received was not 'It is invalid to issue this call inside an active render pass...'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002739 }
2740}
2741
2742TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass)
2743{
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002744 // Call CmdClearAttachmentss outside of an active RenderPass
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002745 VkFlags msgFlags;
2746 std::string msgString;
2747 VkResult err;
2748
2749 ASSERT_NO_FATAL_FAILURE(InitState());
2750 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2751 m_errorMonitor->ClearState();
2752
2753 // Start no RenderPass
2754 err = m_cmdBuffer->BeginCommandBuffer();
2755 ASSERT_VK_SUCCESS(err);
2756
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002757 VkClearAttachment color_attachment;
2758 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2759 color_attachment.clearValue.color.float32[0] = 0;
2760 color_attachment.clearValue.color.float32[1] = 0;
2761 color_attachment.clearValue.color.float32[2] = 0;
2762 color_attachment.clearValue.color.float32[3] = 0;
2763 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06002764 VkClearRect clear_rect = { { { 0, 0 }, { 32, 32 } } };
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002765 vkCmdClearAttachments(m_cmdBuffer->GetBufferHandle(),
2766 1, &color_attachment,
2767 1, &clear_rect);
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002768
2769 msgFlags = m_errorMonitor->GetState(&msgString);
2770 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) <<
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06002771 "Did not receive error after calling CmdClearAttachments outside of an active RenderPass.";
2772 if (!strstr(msgString.c_str(),"vkCmdClearAttachments: This call must be issued inside an active render pass")) {
2773 FAIL() << "Error received was not 'vkCmdClearAttachments: This call must be issued inside an active render pass.'";
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002774 }
2775}
2776
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002777TEST_F(VkLayerTest, InvalidDynamicStateObject)
2778{
2779 // Create a valid cmd buffer
2780 // call vkCmdBindDynamicStateObject w/ false DS Obj
Tobin Ehlis6bdfa372015-05-27 14:32:28 -06002781 // TODO : Simple check for bad object should be added to ObjectTracker to catch this case
2782 // The DS check for this is after driver has been called to validate DS internal data struct
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002783}
Tobin Ehlis201b1ba2015-05-27 14:55:35 -06002784
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002785TEST_F(VkLayerTest, IdxBufferAlignmentError)
2786{
2787 // Bind a BeginRenderPass within an active RenderPass
2788 VkFlags msgFlags;
2789 std::string msgString;
2790 VkResult err;
2791
2792 ASSERT_NO_FATAL_FAILURE(InitState());
2793 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2794 m_errorMonitor->ClearState();
2795 uint32_t qfi = 0;
2796 VkBufferCreateInfo buffCI = {};
2797 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2798 buffCI.size = 1024;
2799 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
2800 buffCI.queueFamilyCount = 1;
2801 buffCI.pQueueFamilyIndices = &qfi;
2802
2803 VkBuffer ib;
2804 err = vkCreateBuffer(m_device->device(), &buffCI, &ib);
2805 ASSERT_VK_SUCCESS(err);
2806
2807 BeginCommandBuffer();
2808 ASSERT_VK_SUCCESS(err);
2809 //vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2810 // Should error before calling to driver so don't care about actual data
2811 vkCmdBindIndexBuffer(m_cmdBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
2812
2813 msgFlags = m_errorMonitor->GetState(&msgString);
2814 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2815 if (!strstr(msgString.c_str(),"vkCmdBindIndexBuffer() offset (0x7) does not fall on ")) {
2816 FAIL() << "Error received was not 'vkCmdBindIndexBuffer() offset (0x7) does not fall on ...' but instead '" << msgString.c_str() << "'";
2817 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002818
2819 vkDestroyBuffer(m_device->device(), ib);
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002820}
2821
Tobin Ehlis5f728d32015-09-17 14:18:16 -06002822TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB)
2823{
2824 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be secondary)
2825 VkFlags msgFlags;
2826 std::string msgString;
2827
2828 ASSERT_NO_FATAL_FAILURE(InitState());
2829 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2830 m_errorMonitor->ClearState();
2831
2832 BeginCommandBuffer();
2833 //ASSERT_VK_SUCCESS(err);
2834 VkCmdBuffer primCB = m_cmdBuffer->GetBufferHandle();
2835 vkCmdExecuteCommands(m_cmdBuffer->GetBufferHandle(), 1, &primCB);
2836
2837 msgFlags = m_errorMonitor->GetState(&msgString);
2838 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass.";
2839 if (!strstr(msgString.c_str(),"vkCmdExecuteCommands() called w/ Primary Cmd Buffer ")) {
2840 FAIL() << "Error received was not 'vkCmdExecuteCommands() called w/ Primary Cmd Buffer ' but instead '" << msgString.c_str() << "'";
2841 }
2842}
2843
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002844TEST_F(VkLayerTest, DSTypeMismatch)
2845{
2846 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002847 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002848 std::string msgString;
2849 VkResult err;
2850
2851 ASSERT_NO_FATAL_FAILURE(InitState());
2852 m_errorMonitor->ClearState();
2853 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002854 VkDescriptorTypeCount ds_type_count = {};
2855 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2856 ds_type_count.count = 1;
2857
2858 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2859 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2860 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002861 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002862 ds_pool_ci.count = 1;
2863 ds_pool_ci.pTypeCount = &ds_type_count;
2864
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002865 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002866 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002867 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002868 VkDescriptorSetLayoutBinding dsl_binding = {};
2869 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2870 dsl_binding.arraySize = 1;
2871 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2872 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002873
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002874 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2875 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2876 ds_layout_ci.pNext = NULL;
2877 ds_layout_ci.count = 1;
2878 ds_layout_ci.pBinding = &dsl_binding;
2879
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002880 VkDescriptorSetLayout ds_layout;
2881 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2882 ASSERT_VK_SUCCESS(err);
2883
2884 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002885 VkDescriptorSetAllocInfo alloc_info = {};
2886 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2887 alloc_info.count = 1;
2888 alloc_info.descriptorPool = ds_pool;
2889 alloc_info.pSetLayouts = &ds_layout;
2890 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002891 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002892
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002893 VkSamplerCreateInfo sampler_ci = {};
2894 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2895 sampler_ci.pNext = NULL;
2896 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2897 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2898 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002899 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2900 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2901 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002902 sampler_ci.mipLodBias = 1.0;
2903 sampler_ci.maxAnisotropy = 1;
2904 sampler_ci.compareEnable = VK_FALSE;
2905 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
2906 sampler_ci.minLod = 1.0;
2907 sampler_ci.maxLod = 1.0;
2908 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06002909 sampler_ci.unnormalizedCoordinates = VK_FALSE;
2910
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002911 VkSampler sampler;
2912 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
2913 ASSERT_VK_SUCCESS(err);
2914
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06002915 VkDescriptorImageInfo info = {};
2916 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002917
2918 VkWriteDescriptorSet descriptor_write;
2919 memset(&descriptor_write, 0, sizeof(descriptor_write));
2920 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
2921 descriptor_write.destSet = descriptorSet;
2922 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002923 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002924 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06002925 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002926
2927 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
2928
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002929 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06002930 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 -06002931 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 ")) {
2932 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 -06002933 }
Mike Stroyan2237f522015-08-18 14:40:24 -06002934
2935 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06002936 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
2937 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06002938}
2939
2940TEST_F(VkLayerTest, DSUpdateOutOfBounds)
2941{
2942 // For overlapping Update, have arrayIndex exceed that of layout
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002943 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002944 std::string msgString;
2945 VkResult err;
2946
2947 ASSERT_NO_FATAL_FAILURE(InitState());
2948 m_errorMonitor->ClearState();
2949 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002950 VkDescriptorTypeCount ds_type_count = {};
2951 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2952 ds_type_count.count = 1;
2953
2954 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2955 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2956 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002957 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002958 ds_pool_ci.count = 1;
2959 ds_pool_ci.pTypeCount = &ds_type_count;
2960
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002961 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06002962 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002963 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002964
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002965 VkDescriptorSetLayoutBinding dsl_binding = {};
2966 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2967 dsl_binding.arraySize = 1;
2968 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2969 dsl_binding.pImmutableSamplers = NULL;
2970
2971 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2972 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2973 ds_layout_ci.pNext = NULL;
2974 ds_layout_ci.count = 1;
2975 ds_layout_ci.pBinding = &dsl_binding;
2976
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002977 VkDescriptorSetLayout ds_layout;
2978 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
2979 ASSERT_VK_SUCCESS(err);
2980
2981 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06002982 VkDescriptorSetAllocInfo alloc_info = {};
2983 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
2984 alloc_info.count = 1;
2985 alloc_info.descriptorPool = ds_pool;
2986 alloc_info.pSetLayouts = &ds_layout;
2987 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002988 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06002989
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002990 VkSamplerCreateInfo sampler_ci = {};
2991 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
2992 sampler_ci.pNext = NULL;
2993 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
2994 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
2995 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06002996 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
2997 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
2998 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06002999 sampler_ci.mipLodBias = 1.0;
3000 sampler_ci.maxAnisotropy = 1;
3001 sampler_ci.compareEnable = VK_FALSE;
3002 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3003 sampler_ci.minLod = 1.0;
3004 sampler_ci.maxLod = 1.0;
3005 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003006 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003007
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003008 VkSampler sampler;
3009 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
3010 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003011
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003012 VkDescriptorImageInfo info = {};
3013 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003014
3015 VkWriteDescriptorSet descriptor_write;
3016 memset(&descriptor_write, 0, sizeof(descriptor_write));
3017 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3018 descriptor_write.destSet = descriptorSet;
3019 descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */
3020 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003021 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003022 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003023 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003024
3025 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3026
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003027 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003028 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 +08003029 if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) {
3030 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 -06003031 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003032
3033 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06003034 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3035 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003036}
3037
3038TEST_F(VkLayerTest, InvalidDSUpdateIndex)
3039{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003040 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003041 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003042 std::string msgString;
3043 VkResult err;
3044
3045 ASSERT_NO_FATAL_FAILURE(InitState());
3046 m_errorMonitor->ClearState();
3047 //VkDescriptorSetObj descriptorSet(m_device);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003048 VkDescriptorTypeCount ds_type_count = {};
3049 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3050 ds_type_count.count = 1;
3051
3052 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3053 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3054 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003055 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003056 ds_pool_ci.count = 1;
3057 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003058
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003059 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003060 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003061 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003062
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003063 VkDescriptorSetLayoutBinding dsl_binding = {};
3064 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3065 dsl_binding.arraySize = 1;
3066 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3067 dsl_binding.pImmutableSamplers = NULL;
3068
3069 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3070 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3071 ds_layout_ci.pNext = NULL;
3072 ds_layout_ci.count = 1;
3073 ds_layout_ci.pBinding = &dsl_binding;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003074 VkDescriptorSetLayout ds_layout;
3075 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3076 ASSERT_VK_SUCCESS(err);
3077
3078 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003079 VkDescriptorSetAllocInfo alloc_info = {};
3080 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3081 alloc_info.count = 1;
3082 alloc_info.descriptorPool = ds_pool;
3083 alloc_info.pSetLayouts = &ds_layout;
3084 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003085 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003086
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003087 VkSamplerCreateInfo sampler_ci = {};
3088 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3089 sampler_ci.pNext = NULL;
3090 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
3091 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
3092 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06003093 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
3094 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
3095 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003096 sampler_ci.mipLodBias = 1.0;
3097 sampler_ci.maxAnisotropy = 1;
3098 sampler_ci.compareEnable = VK_FALSE;
3099 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3100 sampler_ci.minLod = 1.0;
3101 sampler_ci.maxLod = 1.0;
3102 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003103 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003104
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003105 VkSampler sampler;
3106 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
3107 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003108
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003109 VkDescriptorImageInfo info = {};
3110 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003111
3112 VkWriteDescriptorSet descriptor_write;
3113 memset(&descriptor_write, 0, sizeof(descriptor_write));
3114 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3115 descriptor_write.destSet = descriptorSet;
3116 descriptor_write.destBinding = 2;
3117 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003118 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003119 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003120 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003121
3122 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3123
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003124 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003125 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 -06003126 if (!strstr(msgString.c_str()," does not have binding to match update binding ")) {
3127 FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '";
3128 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003129
3130 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06003131 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3132 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003133}
3134
3135TEST_F(VkLayerTest, InvalidDSUpdateStruct)
3136{
3137 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003138 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003139 std::string msgString;
3140 VkResult err;
3141
3142 ASSERT_NO_FATAL_FAILURE(InitState());
3143 m_errorMonitor->ClearState();
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003144
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003145 VkDescriptorTypeCount ds_type_count = {};
3146 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3147 ds_type_count.count = 1;
3148
3149 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3150 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3151 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003152 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003153 ds_pool_ci.count = 1;
3154 ds_pool_ci.pTypeCount = &ds_type_count;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003155
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003156 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003157 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003158 ASSERT_VK_SUCCESS(err);
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003159 VkDescriptorSetLayoutBinding dsl_binding = {};
3160 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3161 dsl_binding.arraySize = 1;
3162 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3163 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003164
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003165 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3166 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3167 ds_layout_ci.pNext = NULL;
3168 ds_layout_ci.count = 1;
3169 ds_layout_ci.pBinding = &dsl_binding;
3170
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003171 VkDescriptorSetLayout ds_layout;
3172 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3173 ASSERT_VK_SUCCESS(err);
3174
3175 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003176 VkDescriptorSetAllocInfo alloc_info = {};
3177 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3178 alloc_info.count = 1;
3179 alloc_info.descriptorPool = ds_pool;
3180 alloc_info.pSetLayouts = &ds_layout;
3181 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003182 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003183
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003184 VkSamplerCreateInfo sampler_ci = {};
3185 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3186 sampler_ci.pNext = NULL;
3187 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
3188 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
3189 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchter51624412015-09-10 14:08:50 -06003190 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
3191 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
3192 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003193 sampler_ci.mipLodBias = 1.0;
3194 sampler_ci.maxAnisotropy = 1;
3195 sampler_ci.compareEnable = VK_FALSE;
3196 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3197 sampler_ci.minLod = 1.0;
3198 sampler_ci.maxLod = 1.0;
3199 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Mark Lobodzinski513acdf2015-09-01 15:42:56 -06003200 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003201 VkSampler sampler;
3202 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
3203 ASSERT_VK_SUCCESS(err);
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003204
3205
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003206 VkDescriptorImageInfo info = {};
3207 info.sampler = sampler;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003208
3209 VkWriteDescriptorSet descriptor_write;
3210 memset(&descriptor_write, 0, sizeof(descriptor_write));
3211 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
3212 descriptor_write.destSet = descriptorSet;
3213 descriptor_write.count = 1;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003214 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003215 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter34aa5c82015-10-23 13:38:14 -06003216 descriptor_write.pImageInfo = &info;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003217
3218 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3219
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003220 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003221 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 -06003222 if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) {
3223 FAIL() << "Error received was not 'Unexpected UPDATE struct of type '";
3224 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003225
3226 vkDestroySampler(m_device->device(), sampler);
Mike Stroyan2237f522015-08-18 14:40:24 -06003227 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3228 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003229}
3230
Tobin Ehlisb46be812015-10-23 16:00:08 -06003231TEST_F(VkLayerTest, SampleDescriptorUpdateError)
3232{
3233 // Create a single Sampler descriptor and send it an invalid Sampler
3234 VkFlags msgFlags;
3235 std::string msgString;
3236 VkResult err;
3237
3238 ASSERT_NO_FATAL_FAILURE(InitState());
3239 m_errorMonitor->ClearState();
3240 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied code
3241 VkDescriptorTypeCount ds_type_count = {};
3242 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3243 ds_type_count.count = 1;
3244
3245 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3246 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3247 ds_pool_ci.pNext = NULL;
3248 ds_pool_ci.maxSets = 1;
3249 ds_pool_ci.count = 1;
3250 ds_pool_ci.pTypeCount = &ds_type_count;
3251
3252 VkDescriptorPool ds_pool;
3253 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
3254 ASSERT_VK_SUCCESS(err);
3255
3256 VkDescriptorSetLayoutBinding dsl_binding = {};
3257 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3258 dsl_binding.arraySize = 1;
3259 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3260 dsl_binding.pImmutableSamplers = NULL;
3261
3262 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3263 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3264 ds_layout_ci.pNext = NULL;
3265 ds_layout_ci.count = 1;
3266 ds_layout_ci.pBinding = &dsl_binding;
3267 VkDescriptorSetLayout ds_layout;
3268 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3269 ASSERT_VK_SUCCESS(err);
3270
3271 VkDescriptorSet descriptorSet;
3272 VkDescriptorSetAllocInfo alloc_info = {};
3273 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3274 alloc_info.count = 1;
3275 alloc_info.descriptorPool = ds_pool;
3276 alloc_info.pSetLayouts = &ds_layout;
3277 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3278 ASSERT_VK_SUCCESS(err);
3279
3280 VkSampler sampler;
3281 sampler.handle = 0xbaadbeef; // Sampler with invalid handle
3282
3283 VkDescriptorImageInfo descriptor_info;
3284 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3285 descriptor_info.sampler = sampler;
3286
3287 VkWriteDescriptorSet descriptor_write;
3288 memset(&descriptor_write, 0, sizeof(descriptor_write));
3289 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3290 descriptor_write.destSet = descriptorSet;
3291 descriptor_write.destBinding = 0;
3292 descriptor_write.count = 1;
3293 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3294 descriptor_write.pImageInfo = &descriptor_info;
3295
3296 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3297
3298 msgFlags = m_errorMonitor->GetState(&msgString);
3299 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ invalid VkSampler.";
3300 if (!strstr(msgString.c_str(),"Attempt to update descriptor with invalid sampler 0xbaadbeef")) {
3301 FAIL() << "Error received was not 'Attempt to update descriptor with invalid sampler...' but instead '" << msgString.c_str() << "'";
3302 }
3303
3304 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3305 vkDestroyDescriptorPool(m_device->device(), ds_pool);
3306}
3307
3308TEST_F(VkLayerTest, ImageViewDescriptorUpdateError)
3309{
3310 // Create a single combined Image/Sampler descriptor and send it an invalid imageView
3311 VkFlags msgFlags;
3312 std::string msgString;
3313 VkResult err;
3314
3315 ASSERT_NO_FATAL_FAILURE(InitState());
3316 m_errorMonitor->ClearState();
3317 VkDescriptorTypeCount ds_type_count = {};
3318 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3319 ds_type_count.count = 1;
3320
3321 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3322 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3323 ds_pool_ci.pNext = NULL;
3324 ds_pool_ci.maxSets = 1;
3325 ds_pool_ci.count = 1;
3326 ds_pool_ci.pTypeCount = &ds_type_count;
3327
3328 VkDescriptorPool ds_pool;
3329 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
3330 ASSERT_VK_SUCCESS(err);
3331
3332 VkDescriptorSetLayoutBinding dsl_binding = {};
3333 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3334 dsl_binding.arraySize = 1;
3335 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3336 dsl_binding.pImmutableSamplers = NULL;
3337
3338 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3339 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3340 ds_layout_ci.pNext = NULL;
3341 ds_layout_ci.count = 1;
3342 ds_layout_ci.pBinding = &dsl_binding;
3343 VkDescriptorSetLayout ds_layout;
3344 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3345 ASSERT_VK_SUCCESS(err);
3346
3347 VkDescriptorSet descriptorSet;
3348 VkDescriptorSetAllocInfo alloc_info = {};
3349 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3350 alloc_info.count = 1;
3351 alloc_info.descriptorPool = ds_pool;
3352 alloc_info.pSetLayouts = &ds_layout;
3353 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3354 ASSERT_VK_SUCCESS(err);
3355
3356 VkSamplerCreateInfo sampler_ci = {};
3357 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3358 sampler_ci.pNext = NULL;
3359 sampler_ci.magFilter = VK_TEX_FILTER_NEAREST;
3360 sampler_ci.minFilter = VK_TEX_FILTER_NEAREST;
3361 sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE;
3362 sampler_ci.addressModeU = VK_TEX_ADDRESS_MODE_CLAMP;
3363 sampler_ci.addressModeV = VK_TEX_ADDRESS_MODE_CLAMP;
3364 sampler_ci.addressModeW = VK_TEX_ADDRESS_MODE_CLAMP;
3365 sampler_ci.mipLodBias = 1.0;
3366 sampler_ci.maxAnisotropy = 1;
3367 sampler_ci.compareEnable = VK_FALSE;
3368 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3369 sampler_ci.minLod = 1.0;
3370 sampler_ci.maxLod = 1.0;
3371 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3372 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3373
3374 VkSampler sampler;
3375 err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler);
3376 ASSERT_VK_SUCCESS(err);
3377
3378 VkImageView view;
3379 view.handle = 0xbaadbeef; // invalid imageView object
3380
3381 VkDescriptorImageInfo descriptor_info;
3382 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
3383 descriptor_info.sampler = sampler;
3384 descriptor_info.imageView = view;
3385
3386 VkWriteDescriptorSet descriptor_write;
3387 memset(&descriptor_write, 0, sizeof(descriptor_write));
3388 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3389 descriptor_write.destSet = descriptorSet;
3390 descriptor_write.destBinding = 0;
3391 descriptor_write.count = 1;
3392 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3393 descriptor_write.pImageInfo = &descriptor_info;
3394
3395 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3396
3397 msgFlags = m_errorMonitor->GetState(&msgString);
3398 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after updating Descriptor w/ invalid VkImageView.";
3399 if (!strstr(msgString.c_str(),"Attempt to update descriptor with invalid imageView 0xbaadbeef")) {
3400 FAIL() << "Error received was not 'Attempt to update descriptor with invalid imageView...' but instead '" << msgString.c_str() << "'";
3401 }
3402
3403 vkDestroySampler(m_device->device(), sampler);
3404 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3405 vkDestroyDescriptorPool(m_device->device(), ds_pool);
3406}
3407
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003408TEST_F(VkLayerTest, NumSamplesMismatch)
3409{
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003410 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003411 VkFlags msgFlags;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003412 std::string msgString;
3413 VkResult err;
3414
3415 ASSERT_NO_FATAL_FAILURE(InitState());
3416 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3417 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003418 VkDescriptorTypeCount ds_type_count = {};
3419 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3420 ds_type_count.count = 1;
3421
3422 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003423 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3424 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003425 ds_pool_ci.maxSets = 1;
3426 ds_pool_ci.count = 1;
3427 ds_pool_ci.pTypeCount = &ds_type_count;
3428
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003429 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003430 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003431 ASSERT_VK_SUCCESS(err);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003432
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003433 VkDescriptorSetLayoutBinding dsl_binding = {};
3434 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3435 dsl_binding.arraySize = 1;
3436 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3437 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003438
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003439 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3440 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3441 ds_layout_ci.pNext = NULL;
3442 ds_layout_ci.count = 1;
3443 ds_layout_ci.pBinding = &dsl_binding;
3444
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003445 VkDescriptorSetLayout ds_layout;
3446 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3447 ASSERT_VK_SUCCESS(err);
3448
3449 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003450 VkDescriptorSetAllocInfo alloc_info = {};
3451 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3452 alloc_info.count = 1;
3453 alloc_info.descriptorPool = ds_pool;
3454 alloc_info.pSetLayouts = &ds_layout;
3455 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003456 ASSERT_VK_SUCCESS(err);
3457
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003458 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3459 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3460 pipe_ms_state_ci.pNext = NULL;
3461 pipe_ms_state_ci.rasterSamples = 4;
3462 pipe_ms_state_ci.sampleShadingEnable = 0;
3463 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003464 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003465
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003466 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3467 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3468 pipeline_layout_ci.pNext = NULL;
3469 pipeline_layout_ci.descriptorSetCount = 1;
3470 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003471
3472 VkPipelineLayout pipeline_layout;
3473 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3474 ASSERT_VK_SUCCESS(err);
3475
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003476 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3477 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003478 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003479 VkPipelineObj pipe(m_device);
3480 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003481 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003482 pipe.SetMSAA(&pipe_ms_state_ci);
3483 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003484
Tony Barbour1490c912015-07-28 10:17:20 -06003485 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06003486 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis2f87d2d2015-05-28 12:11:26 -06003487
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003488 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003489 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 -06003490 if (!strstr(msgString.c_str(),"Num samples mismatch! ")) {
3491 FAIL() << "Error received was not 'Num samples mismatch!...'";
3492 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003493
3494 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06003495 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3496 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis138b7f12015-05-22 12:38:55 -06003497}
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003498
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003499TEST_F(VkLayerTest, ClearCmdNoDraw)
3500{
3501 // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw
3502 VkFlags msgFlags;
3503 std::string msgString;
3504 VkResult err;
3505
3506 ASSERT_NO_FATAL_FAILURE(InitState());
3507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3508 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003509
3510 VkDescriptorTypeCount ds_type_count = {};
3511 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3512 ds_type_count.count = 1;
3513
3514 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3515 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3516 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003517 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003518 ds_pool_ci.count = 1;
3519 ds_pool_ci.pTypeCount = &ds_type_count;
3520
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003521 VkDescriptorPool ds_pool;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003522 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003523 ASSERT_VK_SUCCESS(err);
3524
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003525 VkDescriptorSetLayoutBinding dsl_binding = {};
3526 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3527 dsl_binding.arraySize = 1;
3528 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3529 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003530
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003531 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3532 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3533 ds_layout_ci.pNext = NULL;
3534 ds_layout_ci.count = 1;
3535 ds_layout_ci.pBinding = &dsl_binding;
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003536
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003537 VkDescriptorSetLayout ds_layout;
3538 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3539 ASSERT_VK_SUCCESS(err);
3540
3541 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003542 VkDescriptorSetAllocInfo alloc_info = {};
3543 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3544 alloc_info.count = 1;
3545 alloc_info.descriptorPool = ds_pool;
3546 alloc_info.pSetLayouts = &ds_layout;
3547 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003548 ASSERT_VK_SUCCESS(err);
3549
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003550 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3551 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3552 pipe_ms_state_ci.pNext = NULL;
3553 pipe_ms_state_ci.rasterSamples = 4;
3554 pipe_ms_state_ci.sampleShadingEnable = 0;
3555 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003556 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003557
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003558 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3559 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3560 pipeline_layout_ci.pNext = NULL;
3561 pipeline_layout_ci.descriptorSetCount = 1;
3562 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003563
3564 VkPipelineLayout pipeline_layout;
3565 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3566 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003567
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003568 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3569 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003570 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003571 VkPipelineObj pipe(m_device);
3572 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003573 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003574 pipe.SetMSAA(&pipe_ms_state_ci);
3575 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003576
3577 BeginCommandBuffer();
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003578
3579 m_errorMonitor->ClearState();
3580 // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB
3581 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003582 VkClearAttachment color_attachment;
3583 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3584 color_attachment.clearValue.color.float32[0] = 1.0;
3585 color_attachment.clearValue.color.float32[1] = 1.0;
3586 color_attachment.clearValue.color.float32[2] = 1.0;
3587 color_attachment.clearValue.color.float32[3] = 1.0;
3588 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06003589 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003590
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06003591 vkCmdClearAttachments(m_cmdBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003592 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003593 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 -06003594 if (!strstr(msgString.c_str(),"vkCmdClearAttachments() issued on CB object ")) {
3595 FAIL() << "Error received was not 'vkCmdClearAttachments() issued on CB object...'";
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003596 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003597
3598 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06003599 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3600 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003601}
3602
Tobin Ehlise4076782015-06-24 15:53:07 -06003603TEST_F(VkLayerTest, VtxBufferBadIndex)
3604{
3605 // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount
3606 VkFlags msgFlags;
3607 std::string msgString;
3608 VkResult err;
3609
3610 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003611 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlise4076782015-06-24 15:53:07 -06003612 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3613 m_errorMonitor->ClearState();
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003614
3615 VkDescriptorTypeCount ds_type_count = {};
3616 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3617 ds_type_count.count = 1;
3618
3619 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3620 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3621 ds_pool_ci.pNext = NULL;
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003622 ds_pool_ci.maxSets = 1;
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003623 ds_pool_ci.count = 1;
3624 ds_pool_ci.pTypeCount = &ds_type_count;
3625
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06003626 VkDescriptorPool ds_pool;
3627 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06003628 ASSERT_VK_SUCCESS(err);
3629
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003630 VkDescriptorSetLayoutBinding dsl_binding = {};
3631 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3632 dsl_binding.arraySize = 1;
3633 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3634 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003635
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003636 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3637 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3638 ds_layout_ci.pNext = NULL;
3639 ds_layout_ci.count = 1;
3640 ds_layout_ci.pBinding = &dsl_binding;
3641
Tobin Ehlise4076782015-06-24 15:53:07 -06003642 VkDescriptorSetLayout ds_layout;
3643 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
3644 ASSERT_VK_SUCCESS(err);
3645
3646 VkDescriptorSet descriptorSet;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003647 VkDescriptorSetAllocInfo alloc_info = {};
3648 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
3649 alloc_info.count = 1;
3650 alloc_info.descriptorPool = ds_pool;
3651 alloc_info.pSetLayouts = &ds_layout;
3652 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise4076782015-06-24 15:53:07 -06003653 ASSERT_VK_SUCCESS(err);
3654
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003655 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
3656 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
3657 pipe_ms_state_ci.pNext = NULL;
3658 pipe_ms_state_ci.rasterSamples = 1;
3659 pipe_ms_state_ci.sampleShadingEnable = 0;
3660 pipe_ms_state_ci.minSampleShading = 1.0;
Cody Northrope9825b72015-08-04 14:34:54 -06003661 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlise4076782015-06-24 15:53:07 -06003662
Tony Barbourefbe9ca2015-07-15 12:50:33 -06003663 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3664 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3665 pipeline_layout_ci.pNext = NULL;
3666 pipeline_layout_ci.descriptorSetCount = 1;
3667 pipeline_layout_ci.pSetLayouts = &ds_layout;
3668 VkPipelineLayout pipeline_layout;
Tobin Ehlise4076782015-06-24 15:53:07 -06003669
Tobin Ehlise4076782015-06-24 15:53:07 -06003670 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout);
3671 ASSERT_VK_SUCCESS(err);
3672
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003673 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3674 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // TODO - We shouldn't need a fragment shader
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003675 // but add it to be able to run on more devices
Tony Barbourd7d828b2015-08-06 10:16:07 -06003676 VkPipelineObj pipe(m_device);
3677 pipe.AddShader(&vs);
Tony Barbour3c9e3b12015-08-06 11:21:08 -06003678 pipe.AddShader(&fs);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003679 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisa88e2f52015-10-02 11:00:56 -06003680 pipe.SetViewport(m_viewports);
3681 pipe.SetScissor(m_scissors);
Tony Barbourd7d828b2015-08-06 10:16:07 -06003682 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbour1490c912015-07-28 10:17:20 -06003683
3684 BeginCommandBuffer();
Tony Barbourd7d828b2015-08-06 10:16:07 -06003685 vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisd28acef2015-09-09 15:12:35 -06003686 // Don't care about actual data, just need to get to draw to flag error
3687 static const float vbo_data[3] = {1.f, 0.f, 1.f};
3688 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void*) &vbo_data);
3689 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003690 Draw(1, 0, 0, 0);
Tobin Ehlise4076782015-06-24 15:53:07 -06003691
3692 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003693 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 -06003694 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 -06003695 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 -06003696 }
Mike Stroyan2237f522015-08-18 14:40:24 -06003697
3698 vkDestroyPipelineLayout(m_device->device(), pipeline_layout);
Mike Stroyan2237f522015-08-18 14:40:24 -06003699 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
3700 vkDestroyDescriptorPool(m_device->device(), ds_pool);
Tobin Ehlise4076782015-06-24 15:53:07 -06003701}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003702#endif // DRAW_STATE_TESTS
3703
Tobin Ehlis57e6a612015-05-26 16:11:58 -06003704#if THREADING_TESTS
Mike Stroyan09aae812015-05-12 16:00:45 -06003705#if GTEST_IS_THREADSAFE
3706struct thread_data_struct {
3707 VkCmdBuffer cmdBuffer;
3708 VkEvent event;
3709 bool bailout;
3710};
3711
3712extern "C" void *AddToCommandBuffer(void *arg)
3713{
3714 struct thread_data_struct *data = (struct thread_data_struct *) arg;
3715 std::string msgString;
3716
3717 for (int i = 0; i<10000; i++) {
Tony Barbourc2e987e2015-06-29 16:20:35 -06003718 vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS);
Mike Stroyan09aae812015-05-12 16:00:45 -06003719 if (data->bailout) {
3720 break;
3721 }
3722 }
3723 return NULL;
3724}
3725
3726TEST_F(VkLayerTest, ThreadCmdBufferCollision)
3727{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003728 VkFlags msgFlags;
Mike Stroyan09aae812015-05-12 16:00:45 -06003729 std::string msgString;
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003730 test_platform_thread thread;
Mike Stroyan09aae812015-05-12 16:00:45 -06003731
3732 ASSERT_NO_FATAL_FAILURE(InitState());
3733 ASSERT_NO_FATAL_FAILURE(InitViewport());
3734 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3735
Mike Stroyan09aae812015-05-12 16:00:45 -06003736 m_errorMonitor->ClearState();
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003737
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -06003738 // Calls AllocCommandBuffers
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003739 VkCommandBufferObj cmdBuffer(m_device, m_cmdPool);
3740
3741 // Avoid creating RenderPass
3742 cmdBuffer.BeginCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06003743
3744 VkEventCreateInfo event_info;
3745 VkEvent event;
Mike Stroyan09aae812015-05-12 16:00:45 -06003746 VkResult err;
3747
3748 memset(&event_info, 0, sizeof(event_info));
3749 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3750
3751 err = vkCreateEvent(device(), &event_info, &event);
3752 ASSERT_VK_SUCCESS(err);
3753
Mike Stroyan09aae812015-05-12 16:00:45 -06003754 err = vkResetEvent(device(), event);
3755 ASSERT_VK_SUCCESS(err);
3756
3757 struct thread_data_struct data;
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003758 data.cmdBuffer = cmdBuffer.GetBufferHandle();
Mike Stroyan09aae812015-05-12 16:00:45 -06003759 data.event = event;
3760 data.bailout = false;
3761 m_errorMonitor->SetBailout(&data.bailout);
3762 // Add many entries to command buffer from another thread.
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003763 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyan09aae812015-05-12 16:00:45 -06003764 // Add many entries to command buffer from this thread at the same time.
3765 AddToCommandBuffer(&data);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003766
Mike Stroyan7016f4f2015-07-13 14:45:35 -06003767 test_platform_thread_join(thread, NULL);
Mark Lobodzinskia0f061c2015-09-30 16:19:16 -06003768 cmdBuffer.EndCommandBuffer();
Mike Stroyan09aae812015-05-12 16:00:45 -06003769
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003770 msgFlags = m_errorMonitor->GetState(&msgString);
Cody Northrop1684adb2015-08-05 11:15:02 -06003771 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 -06003772 if (!strstr(msgString.c_str(),"THREADING ERROR")) {
Mark Lobodzinski5f25be42015-05-14 15:08:13 -05003773 FAIL() << "Error received was not 'THREADING ERROR'";
Mike Stroyan09aae812015-05-12 16:00:45 -06003774 }
3775
Mike Stroyan2237f522015-08-18 14:40:24 -06003776 vkDestroyEvent(device(), event);
Mike Stroyan09aae812015-05-12 16:00:45 -06003777}
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06003778#endif // GTEST_IS_THREADSAFE
3779#endif // THREADING_TESTS
3780
Chris Forbes5af3bf22015-05-25 11:13:08 +12003781#if SHADER_CHECKER_TESTS
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003782TEST_F(VkLayerTest, InvalidSPIRVCodeSize)
3783{
3784 VkFlags msgFlags;
3785 std::string msgString;
3786 ASSERT_NO_FATAL_FAILURE(InitState());
3787 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3788
3789 m_errorMonitor->ClearState();
3790
3791 VkShaderModule module;
3792 VkShaderModuleCreateInfo moduleCreateInfo;
3793 struct icd_spv_header spv;
3794
3795 spv.magic = ICD_SPV_MAGIC;
3796 spv.version = ICD_SPV_VERSION;
3797 spv.gen_magic = 0;
3798
3799 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3800 moduleCreateInfo.pNext = NULL;
3801 moduleCreateInfo.pCode = &spv;
3802 moduleCreateInfo.codeSize = 4;
3803 moduleCreateInfo.flags = 0;
3804 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3805
3806 msgFlags = m_errorMonitor->GetState(&msgString);
3807
Chris Forbes96b81762015-09-18 11:40:23 +12003808 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003809 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3810 FAIL() << "Incorrect warning: " << msgString;
3811 }
3812}
3813
3814TEST_F(VkLayerTest, InvalidSPIRVMagic)
3815{
3816 VkFlags msgFlags;
3817 std::string msgString;
3818 ASSERT_NO_FATAL_FAILURE(InitState());
3819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3820
3821 m_errorMonitor->ClearState();
3822
3823 VkShaderModule module;
3824 VkShaderModuleCreateInfo moduleCreateInfo;
3825 struct icd_spv_header spv;
3826
3827 spv.magic = ~ICD_SPV_MAGIC;
3828 spv.version = ICD_SPV_VERSION;
3829 spv.gen_magic = 0;
3830
3831 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3832 moduleCreateInfo.pNext = NULL;
3833 moduleCreateInfo.pCode = &spv;
3834 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3835 moduleCreateInfo.flags = 0;
3836 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3837
3838 msgFlags = m_errorMonitor->GetState(&msgString);
3839
Chris Forbes96b81762015-09-18 11:40:23 +12003840 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003841 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3842 FAIL() << "Incorrect warning: " << msgString;
3843 }
3844}
3845
3846TEST_F(VkLayerTest, InvalidSPIRVVersion)
3847{
3848 VkFlags msgFlags;
3849 std::string msgString;
3850 ASSERT_NO_FATAL_FAILURE(InitState());
3851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3852
3853 m_errorMonitor->ClearState();
3854
3855 VkShaderModule module;
3856 VkShaderModuleCreateInfo moduleCreateInfo;
3857 struct icd_spv_header spv;
3858
3859 spv.magic = ICD_SPV_MAGIC;
3860 spv.version = ~ICD_SPV_VERSION;
3861 spv.gen_magic = 0;
3862
3863 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
3864 moduleCreateInfo.pNext = NULL;
3865
3866 moduleCreateInfo.pCode = &spv;
3867 moduleCreateInfo.codeSize = sizeof(spv) + 10;
3868 moduleCreateInfo.flags = 0;
3869 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, &module);
3870
3871 msgFlags = m_errorMonitor->GetState(&msgString);
3872
Chris Forbes96b81762015-09-18 11:40:23 +12003873 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_ERROR_BIT);
Courtney Goeltzenleuchter201387f2015-09-16 12:58:29 -06003874 if (!strstr(msgString.c_str(),"Shader is not SPIR-V")) {
3875 FAIL() << "Incorrect warning: " << msgString;
3876 }
3877}
3878
Chris Forbes5af3bf22015-05-25 11:13:08 +12003879TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed)
3880{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003881 VkFlags msgFlags;
Chris Forbes5af3bf22015-05-25 11:13:08 +12003882 std::string msgString;
3883 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003884 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5af3bf22015-05-25 11:13:08 +12003885
3886 char const *vsSource =
3887 "#version 140\n"
3888 "#extension GL_ARB_separate_shader_objects: require\n"
3889 "#extension GL_ARB_shading_language_420pack: require\n"
3890 "\n"
3891 "layout(location=0) out float x;\n"
3892 "void main(){\n"
3893 " gl_Position = vec4(1);\n"
3894 " x = 0;\n"
3895 "}\n";
3896 char const *fsSource =
3897 "#version 140\n"
3898 "#extension GL_ARB_separate_shader_objects: require\n"
3899 "#extension GL_ARB_shading_language_420pack: require\n"
3900 "\n"
3901 "layout(location=0) out vec4 color;\n"
3902 "void main(){\n"
3903 " color = vec4(1);\n"
3904 "}\n";
3905
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003906 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3907 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003908
3909 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003910 pipe.AddColorAttachment();
Chris Forbes5af3bf22015-05-25 11:13:08 +12003911 pipe.AddShader(&vs);
3912 pipe.AddShader(&fs);
3913
Chris Forbes5af3bf22015-05-25 11:13:08 +12003914 VkDescriptorSetObj descriptorSet(m_device);
3915 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003916 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003917
3918 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003919 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5af3bf22015-05-25 11:13:08 +12003920
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003921 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003922
Cody Northrop1684adb2015-08-05 11:15:02 -06003923 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5af3bf22015-05-25 11:13:08 +12003924 if (!strstr(msgString.c_str(),"not consumed by fragment shader")) {
3925 FAIL() << "Incorrect warning: " << msgString;
3926 }
3927}
Chris Forbes5af3bf22015-05-25 11:13:08 +12003928
Chris Forbes3c10b852015-05-25 11:13:13 +12003929TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided)
3930{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003931 VkFlags msgFlags;
Chris Forbes3c10b852015-05-25 11:13:13 +12003932 std::string msgString;
3933 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003934 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes3c10b852015-05-25 11:13:13 +12003935
3936 char const *vsSource =
3937 "#version 140\n"
3938 "#extension GL_ARB_separate_shader_objects: require\n"
3939 "#extension GL_ARB_shading_language_420pack: require\n"
3940 "\n"
3941 "void main(){\n"
3942 " gl_Position = vec4(1);\n"
3943 "}\n";
3944 char const *fsSource =
3945 "#version 140\n"
3946 "#extension GL_ARB_separate_shader_objects: require\n"
3947 "#extension GL_ARB_shading_language_420pack: require\n"
3948 "\n"
3949 "layout(location=0) in float x;\n"
3950 "layout(location=0) out vec4 color;\n"
3951 "void main(){\n"
3952 " color = vec4(x);\n"
3953 "}\n";
3954
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003955 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3956 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes3c10b852015-05-25 11:13:13 +12003957
3958 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003959 pipe.AddColorAttachment();
Chris Forbes3c10b852015-05-25 11:13:13 +12003960 pipe.AddShader(&vs);
3961 pipe.AddShader(&fs);
3962
Chris Forbes3c10b852015-05-25 11:13:13 +12003963 VkDescriptorSetObj descriptorSet(m_device);
3964 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06003965 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes3c10b852015-05-25 11:13:13 +12003966
3967 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06003968 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes3c10b852015-05-25 11:13:13 +12003969
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003970 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes3c10b852015-05-25 11:13:13 +12003971
Cody Northrop1684adb2015-08-05 11:15:02 -06003972 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes3c10b852015-05-25 11:13:13 +12003973 if (!strstr(msgString.c_str(),"not written by vertex shader")) {
3974 FAIL() << "Incorrect error: " << msgString;
3975 }
3976}
3977
Chris Forbescc281692015-05-25 11:13:17 +12003978TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch)
3979{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003980 VkFlags msgFlags;
Chris Forbescc281692015-05-25 11:13:17 +12003981 std::string msgString;
3982 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06003983 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbescc281692015-05-25 11:13:17 +12003984
3985 char const *vsSource =
3986 "#version 140\n"
3987 "#extension GL_ARB_separate_shader_objects: require\n"
3988 "#extension GL_ARB_shading_language_420pack: require\n"
3989 "\n"
3990 "layout(location=0) out int x;\n"
3991 "void main(){\n"
3992 " x = 0;\n"
3993 " gl_Position = vec4(1);\n"
3994 "}\n";
3995 char const *fsSource =
3996 "#version 140\n"
3997 "#extension GL_ARB_separate_shader_objects: require\n"
3998 "#extension GL_ARB_shading_language_420pack: require\n"
3999 "\n"
4000 "layout(location=0) in float x;\n" /* VS writes int */
4001 "layout(location=0) out vec4 color;\n"
4002 "void main(){\n"
4003 " color = vec4(x);\n"
4004 "}\n";
4005
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004006 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4007 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbescc281692015-05-25 11:13:17 +12004008
4009 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004010 pipe.AddColorAttachment();
Chris Forbescc281692015-05-25 11:13:17 +12004011 pipe.AddShader(&vs);
4012 pipe.AddShader(&fs);
4013
Chris Forbescc281692015-05-25 11:13:17 +12004014 VkDescriptorSetObj descriptorSet(m_device);
4015 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004016 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbescc281692015-05-25 11:13:17 +12004017
4018 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004019 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbescc281692015-05-25 11:13:17 +12004020
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004021 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbescc281692015-05-25 11:13:17 +12004022
Cody Northrop1684adb2015-08-05 11:15:02 -06004023 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbescc281692015-05-25 11:13:17 +12004024 if (!strstr(msgString.c_str(),"Type mismatch on location 0")) {
4025 FAIL() << "Incorrect error: " << msgString;
4026 }
4027}
4028
Chris Forbes8291c052015-05-25 11:13:28 +12004029TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed)
4030{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004031 VkFlags msgFlags;
Chris Forbes8291c052015-05-25 11:13:28 +12004032 std::string msgString;
4033 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes8291c052015-05-25 11:13:28 +12004035
4036 VkVertexInputBindingDescription input_binding;
4037 memset(&input_binding, 0, sizeof(input_binding));
4038
4039 VkVertexInputAttributeDescription input_attrib;
4040 memset(&input_attrib, 0, sizeof(input_attrib));
4041 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4042
4043 char const *vsSource =
4044 "#version 140\n"
4045 "#extension GL_ARB_separate_shader_objects: require\n"
4046 "#extension GL_ARB_shading_language_420pack: require\n"
4047 "\n"
4048 "void main(){\n"
4049 " gl_Position = vec4(1);\n"
4050 "}\n";
4051 char const *fsSource =
4052 "#version 140\n"
4053 "#extension GL_ARB_separate_shader_objects: require\n"
4054 "#extension GL_ARB_shading_language_420pack: require\n"
4055 "\n"
4056 "layout(location=0) out vec4 color;\n"
4057 "void main(){\n"
4058 " color = vec4(1);\n"
4059 "}\n";
4060
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004061 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4062 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes8291c052015-05-25 11:13:28 +12004063
4064 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004065 pipe.AddColorAttachment();
Chris Forbes8291c052015-05-25 11:13:28 +12004066 pipe.AddShader(&vs);
4067 pipe.AddShader(&fs);
4068
4069 pipe.AddVertexInputBindings(&input_binding, 1);
4070 pipe.AddVertexInputAttribs(&input_attrib, 1);
4071
Chris Forbes8291c052015-05-25 11:13:28 +12004072 VkDescriptorSetObj descriptorSet(m_device);
4073 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004074 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes8291c052015-05-25 11:13:28 +12004075
4076 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004077 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes8291c052015-05-25 11:13:28 +12004078
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004079 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes8291c052015-05-25 11:13:28 +12004080
Cody Northrop1684adb2015-08-05 11:15:02 -06004081 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes8291c052015-05-25 11:13:28 +12004082 if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) {
4083 FAIL() << "Incorrect warning: " << msgString;
4084 }
4085}
4086
Chris Forbes37367e62015-05-25 11:13:29 +12004087TEST_F(VkLayerTest, CreatePipelineAttribNotProvided)
4088{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004089 VkFlags msgFlags;
Chris Forbes37367e62015-05-25 11:13:29 +12004090 std::string msgString;
4091 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004092 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes37367e62015-05-25 11:13:29 +12004093
4094 char const *vsSource =
4095 "#version 140\n"
4096 "#extension GL_ARB_separate_shader_objects: require\n"
4097 "#extension GL_ARB_shading_language_420pack: require\n"
4098 "\n"
4099 "layout(location=0) in vec4 x;\n" /* not provided */
4100 "void main(){\n"
4101 " gl_Position = x;\n"
4102 "}\n";
4103 char const *fsSource =
4104 "#version 140\n"
4105 "#extension GL_ARB_separate_shader_objects: require\n"
4106 "#extension GL_ARB_shading_language_420pack: require\n"
4107 "\n"
4108 "layout(location=0) out vec4 color;\n"
4109 "void main(){\n"
4110 " color = vec4(1);\n"
4111 "}\n";
4112
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004113 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4114 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes37367e62015-05-25 11:13:29 +12004115
4116 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004117 pipe.AddColorAttachment();
Chris Forbes37367e62015-05-25 11:13:29 +12004118 pipe.AddShader(&vs);
4119 pipe.AddShader(&fs);
4120
Chris Forbes37367e62015-05-25 11:13:29 +12004121 VkDescriptorSetObj descriptorSet(m_device);
4122 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004123 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes37367e62015-05-25 11:13:29 +12004124
4125 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004126 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes37367e62015-05-25 11:13:29 +12004127
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004128 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes37367e62015-05-25 11:13:29 +12004129
Cody Northrop1684adb2015-08-05 11:15:02 -06004130 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes37367e62015-05-25 11:13:29 +12004131 if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) {
4132 FAIL() << "Incorrect warning: " << msgString;
4133 }
4134}
4135
Chris Forbesa4b02322015-05-25 11:13:31 +12004136TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch)
4137{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004138 VkFlags msgFlags;
Chris Forbesa4b02322015-05-25 11:13:31 +12004139 std::string msgString;
4140 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004141 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa4b02322015-05-25 11:13:31 +12004142
4143 VkVertexInputBindingDescription input_binding;
4144 memset(&input_binding, 0, sizeof(input_binding));
4145
4146 VkVertexInputAttributeDescription input_attrib;
4147 memset(&input_attrib, 0, sizeof(input_attrib));
4148 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4149
4150 char const *vsSource =
4151 "#version 140\n"
4152 "#extension GL_ARB_separate_shader_objects: require\n"
4153 "#extension GL_ARB_shading_language_420pack: require\n"
4154 "\n"
4155 "layout(location=0) in int x;\n" /* attrib provided float */
4156 "void main(){\n"
4157 " gl_Position = vec4(x);\n"
4158 "}\n";
4159 char const *fsSource =
4160 "#version 140\n"
4161 "#extension GL_ARB_separate_shader_objects: require\n"
4162 "#extension GL_ARB_shading_language_420pack: require\n"
4163 "\n"
4164 "layout(location=0) out vec4 color;\n"
4165 "void main(){\n"
4166 " color = vec4(1);\n"
4167 "}\n";
4168
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004169 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4170 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa4b02322015-05-25 11:13:31 +12004171
4172 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004173 pipe.AddColorAttachment();
Chris Forbesa4b02322015-05-25 11:13:31 +12004174 pipe.AddShader(&vs);
4175 pipe.AddShader(&fs);
4176
4177 pipe.AddVertexInputBindings(&input_binding, 1);
4178 pipe.AddVertexInputAttribs(&input_attrib, 1);
4179
Chris Forbesa4b02322015-05-25 11:13:31 +12004180 VkDescriptorSetObj descriptorSet(m_device);
4181 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004182 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesa4b02322015-05-25 11:13:31 +12004183
4184 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004185 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa4b02322015-05-25 11:13:31 +12004186
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004187 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesa4b02322015-05-25 11:13:31 +12004188
Cody Northrop1684adb2015-08-05 11:15:02 -06004189 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesa4b02322015-05-25 11:13:31 +12004190 if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) {
4191 FAIL() << "Incorrect error: " << msgString;
4192 }
4193}
4194
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004195TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict)
4196{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004197 VkFlags msgFlags;
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004198 std::string msgString;
4199 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisf2f97402015-09-11 12:57:55 -06004200 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004201
4202 /* Two binding descriptions for binding 0 */
4203 VkVertexInputBindingDescription input_bindings[2];
4204 memset(input_bindings, 0, sizeof(input_bindings));
4205
4206 VkVertexInputAttributeDescription input_attrib;
4207 memset(&input_attrib, 0, sizeof(input_attrib));
4208 input_attrib.format = VK_FORMAT_R32_SFLOAT;
4209
4210 char const *vsSource =
4211 "#version 140\n"
4212 "#extension GL_ARB_separate_shader_objects: require\n"
4213 "#extension GL_ARB_shading_language_420pack: require\n"
4214 "\n"
4215 "layout(location=0) in float x;\n" /* attrib provided float */
4216 "void main(){\n"
4217 " gl_Position = vec4(x);\n"
4218 "}\n";
4219 char const *fsSource =
4220 "#version 140\n"
4221 "#extension GL_ARB_separate_shader_objects: require\n"
4222 "#extension GL_ARB_shading_language_420pack: require\n"
4223 "\n"
4224 "layout(location=0) out vec4 color;\n"
4225 "void main(){\n"
4226 " color = vec4(1);\n"
4227 "}\n";
4228
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004229 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4230 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004231
4232 VkPipelineObj pipe(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004233 pipe.AddColorAttachment();
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004234 pipe.AddShader(&vs);
4235 pipe.AddShader(&fs);
4236
4237 pipe.AddVertexInputBindings(input_bindings, 2);
4238 pipe.AddVertexInputAttribs(&input_attrib, 1);
4239
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004240 VkDescriptorSetObj descriptorSet(m_device);
4241 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004242 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004243
4244 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004245 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004246
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004247 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004248
Cody Northrop1684adb2015-08-05 11:15:02 -06004249 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes0bf8fe12015-06-12 11:16:41 +12004250 if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) {
4251 FAIL() << "Incorrect error: " << msgString;
4252 }
4253}
Chris Forbes4c948702015-05-25 11:13:32 +12004254
Chris Forbesc12ef122015-05-25 11:13:40 +12004255/* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler
4256 * rejects it. */
4257
4258TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten)
4259{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004260 VkFlags msgFlags;
Chris Forbesc12ef122015-05-25 11:13:40 +12004261 std::string msgString;
4262 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc12ef122015-05-25 11:13:40 +12004263
4264 char const *vsSource =
4265 "#version 140\n"
4266 "#extension GL_ARB_separate_shader_objects: require\n"
4267 "#extension GL_ARB_shading_language_420pack: require\n"
4268 "\n"
4269 "void main(){\n"
4270 " gl_Position = vec4(1);\n"
4271 "}\n";
4272 char const *fsSource =
4273 "#version 140\n"
4274 "#extension GL_ARB_separate_shader_objects: require\n"
4275 "#extension GL_ARB_shading_language_420pack: require\n"
4276 "\n"
4277 "void main(){\n"
4278 "}\n";
4279
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004280 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4281 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc12ef122015-05-25 11:13:40 +12004282
4283 VkPipelineObj pipe(m_device);
4284 pipe.AddShader(&vs);
4285 pipe.AddShader(&fs);
4286
Chia-I Wuc278df82015-07-07 11:50:03 +08004287 /* set up CB 0, not written */
4288 pipe.AddColorAttachment();
4289 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc12ef122015-05-25 11:13:40 +12004290
Chris Forbesc12ef122015-05-25 11:13:40 +12004291 VkDescriptorSetObj descriptorSet(m_device);
4292 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004293 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbesc12ef122015-05-25 11:13:40 +12004294
4295 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004296 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc12ef122015-05-25 11:13:40 +12004297
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004298 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbesc12ef122015-05-25 11:13:40 +12004299
Cody Northrop1684adb2015-08-05 11:15:02 -06004300 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbesc12ef122015-05-25 11:13:40 +12004301 if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) {
4302 FAIL() << "Incorrect error: " << msgString;
4303 }
4304}
4305
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004306TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed)
4307{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004308 VkFlags msgFlags;
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004309 std::string msgString;
4310 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004311
4312 char const *vsSource =
4313 "#version 140\n"
4314 "#extension GL_ARB_separate_shader_objects: require\n"
4315 "#extension GL_ARB_shading_language_420pack: require\n"
4316 "\n"
4317 "void main(){\n"
4318 " gl_Position = vec4(1);\n"
4319 "}\n";
4320 char const *fsSource =
4321 "#version 140\n"
4322 "#extension GL_ARB_separate_shader_objects: require\n"
4323 "#extension GL_ARB_shading_language_420pack: require\n"
4324 "\n"
4325 "layout(location=0) out vec4 x;\n"
4326 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
4327 "void main(){\n"
4328 " x = vec4(1);\n"
4329 " y = vec4(1);\n"
4330 "}\n";
4331
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004332 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4333 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004334
4335 VkPipelineObj pipe(m_device);
4336 pipe.AddShader(&vs);
4337 pipe.AddShader(&fs);
4338
Chia-I Wuc278df82015-07-07 11:50:03 +08004339 /* set up CB 0, not written */
4340 pipe.AddColorAttachment();
4341 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004342 /* FS writes CB 1, but we don't configure it */
4343
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004344 VkDescriptorSetObj descriptorSet(m_device);
4345 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004346 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004347
4348 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004349 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004350
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004351 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004352
Cody Northrop1684adb2015-08-05 11:15:02 -06004353 ASSERT_NE(0, msgFlags & VK_DBG_REPORT_WARN_BIT);
Chris Forbes5d15a4f2015-05-25 11:13:43 +12004354 if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) {
4355 FAIL() << "Incorrect warning: " << msgString;
4356 }
4357}
4358
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004359TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch)
4360{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004361 VkFlags msgFlags;
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004362 std::string msgString;
4363 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004364
4365 char const *vsSource =
4366 "#version 140\n"
4367 "#extension GL_ARB_separate_shader_objects: require\n"
4368 "#extension GL_ARB_shading_language_420pack: require\n"
4369 "\n"
4370 "void main(){\n"
4371 " gl_Position = vec4(1);\n"
4372 "}\n";
4373 char const *fsSource =
4374 "#version 140\n"
4375 "#extension GL_ARB_separate_shader_objects: require\n"
4376 "#extension GL_ARB_shading_language_420pack: require\n"
4377 "\n"
4378 "layout(location=0) out ivec4 x;\n" /* not UNORM */
4379 "void main(){\n"
4380 " x = ivec4(1);\n"
4381 "}\n";
4382
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004383 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4384 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004385
4386 VkPipelineObj pipe(m_device);
4387 pipe.AddShader(&vs);
4388 pipe.AddShader(&fs);
4389
Chia-I Wuc278df82015-07-07 11:50:03 +08004390 /* set up CB 0; type is UNORM by default */
4391 pipe.AddColorAttachment();
4392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004393
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004394 VkDescriptorSetObj descriptorSet(m_device);
4395 descriptorSet.AppendDummy();
Tony Barbour1490c912015-07-28 10:17:20 -06004396 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004397
4398 m_errorMonitor->ClearState();
Tony Barboured132432015-08-04 16:23:11 -06004399 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004400
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06004401 msgFlags = m_errorMonitor->GetState(&msgString);
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004402
Cody Northrop1684adb2015-08-05 11:15:02 -06004403 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT));
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004404 if (!strstr(msgString.c_str(),"does not match FS output type")) {
4405 FAIL() << "Incorrect error: " << msgString;
4406 }
4407}
Chris Forbesc2050732015-06-05 14:43:36 +12004408
Chris Forbes76ce7882015-08-14 12:04:59 +12004409TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided)
4410{
4411 VkFlags msgFlags;
4412 std::string msgString;
4413 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes76ce7882015-08-14 12:04:59 +12004414
4415 char const *vsSource =
4416 "#version 140\n"
4417 "#extension GL_ARB_separate_shader_objects: require\n"
4418 "#extension GL_ARB_shading_language_420pack: require\n"
4419 "\n"
4420 "void main(){\n"
4421 " gl_Position = vec4(1);\n"
4422 "}\n";
4423 char const *fsSource =
4424 "#version 140\n"
4425 "#extension GL_ARB_separate_shader_objects: require\n"
4426 "#extension GL_ARB_shading_language_420pack: require\n"
4427 "\n"
4428 "layout(location=0) out vec4 x;\n"
4429 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4430 "void main(){\n"
4431 " x = vec4(bar.y);\n"
4432 "}\n";
4433
4434 m_errorMonitor->ClearState();
4435
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004436 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4437 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes76ce7882015-08-14 12:04:59 +12004438
4439
4440 VkPipelineObj pipe(m_device);
4441 pipe.AddShader(&vs);
4442 pipe.AddShader(&fs);
4443
4444 /* set up CB 0; type is UNORM by default */
4445 pipe.AddColorAttachment();
4446 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4447
4448 VkDescriptorSetObj descriptorSet(m_device);
4449 descriptorSet.CreateVKDescriptorSet(m_cmdBuffer);
4450
4451 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
4452
4453 /* should have generated an error -- pipeline layout does not
4454 * provide a uniform buffer in 0.0
4455 */
4456 msgFlags = m_errorMonitor->GetState(&msgString);
Courtney Goeltzenleuchter0abdb662015-10-07 13:28:58 -06004457 ASSERT_TRUE((msgFlags & VK_DBG_REPORT_ERROR_BIT) == VK_DBG_REPORT_ERROR_BIT);
Chris Forbes76ce7882015-08-14 12:04:59 +12004458 if (!strstr(msgString.c_str(),"not declared in pipeline layout")) {
4459 FAIL() << "Incorrect error: " << msgString;
4460 }
4461}
4462
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004463#endif // SHADER_CHECKER_TESTS
4464
4465#if DEVICE_LIMITS_TESTS
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004466TEST_F(VkLayerTest, CreateImageLimitsViolationWidth)
4467{
4468 VkFlags msgFlags;
4469 std::string msgString;
4470
4471 ASSERT_NO_FATAL_FAILURE(InitState());
4472 m_errorMonitor->ClearState();
4473
4474 // Create an image
4475 VkImage image;
4476
4477 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4478 const int32_t tex_width = 32;
4479 const int32_t tex_height = 32;
4480
4481 VkImageCreateInfo image_create_info = {};
4482 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4483 image_create_info.pNext = NULL;
4484 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4485 image_create_info.format = tex_format;
4486 image_create_info.extent.width = tex_width;
4487 image_create_info.extent.height = tex_height;
4488 image_create_info.extent.depth = 1;
4489 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004490 image_create_info.arrayLayers = 1;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004491 image_create_info.samples = 1;
4492 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4493 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4494 image_create_info.flags = 0;
4495
4496 // Introduce error by sending down a bogus width extent
4497 image_create_info.extent.width = 65536;
4498 vkCreateImage(m_device->device(), &image_create_info, &image);
4499
4500 msgFlags = m_errorMonitor->GetState(&msgString);
4501 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4502 "with extents outside the queried limits";
4503 if (!strstr(msgString.c_str(),"CreateImage extents exceed allowable limits for format")) {
4504 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4505 }
4506}
4507
4508TEST_F(VkLayerTest, CreateImageResourceSizeViolation)
4509{
4510 VkFlags msgFlags;
4511 std::string msgString;
4512
4513 ASSERT_NO_FATAL_FAILURE(InitState());
4514 m_errorMonitor->ClearState();
4515
4516 // Create an image
4517 VkImage image;
4518
4519 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4520 const int32_t tex_width = 32;
4521 const int32_t tex_height = 32;
4522
4523 VkImageCreateInfo image_create_info = {};
4524 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4525 image_create_info.pNext = NULL;
4526 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4527 image_create_info.format = tex_format;
4528 image_create_info.extent.width = tex_width;
4529 image_create_info.extent.height = tex_height;
4530 image_create_info.extent.depth = 1;
4531 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004532 image_create_info.arrayLayers = 1;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004533 image_create_info.samples = 1;
4534 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4535 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4536 image_create_info.flags = 0;
4537
4538 // Introduce error by sending down individually allowable values that result in a surface size
4539 // exceeding the device maximum
4540 image_create_info.extent.width = 8192;
4541 image_create_info.extent.height = 8192;
4542 image_create_info.extent.depth = 16;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004543 image_create_info.arrayLayers = 4;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -06004544 image_create_info.samples = 2;
4545 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
4546 vkCreateImage(m_device->device(), &image_create_info, &image);
4547
4548 msgFlags = m_errorMonitor->GetState(&msgString);
4549 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an image" <<
4550 "with resource size exceeding queried limit";
4551 if (!strstr(msgString.c_str(),"CreateImage resource size exceeds allowable maximum")) {
4552 FAIL() << "Error received did not match expected error message from vkCreateImage in DeviceLimits layer";
4553 }
4554}
4555
Mike Stroyan43909d82015-09-25 13:39:21 -06004556TEST_F(VkLayerTest, UpdateBufferAlignment)
4557{
4558 VkFlags msgFlags;
4559 std::string msgString;
4560 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
4561
4562 ASSERT_NO_FATAL_FAILURE(InitState());
4563
4564 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4565 vk_testing::Buffer buffer;
4566 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4567
4568 BeginCommandBuffer();
4569 // Introduce failure by using offset that is not multiple of 4
4570 m_cmdBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
4571 msgFlags = m_errorMonitor->GetState(&msgString);
4572 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad offset";
4573 if (!strstr(msgString.c_str(),"destOffset, is not a multiple of 4")) {
4574 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4'";
4575 }
4576 // Introduce failure by using size that is not multiple of 4
4577 m_cmdBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
4578 msgFlags = m_errorMonitor->GetState(&msgString);
4579 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling UpdateBuffer with bad size";
4580 if (!strstr(msgString.c_str(),"dataSize, is not a multiple of 4")) {
4581 FAIL() << "Error received was not 'vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4'";
4582 }
4583 EndCommandBuffer();
4584}
4585
4586TEST_F(VkLayerTest, FillBufferAlignment)
4587{
4588 VkFlags msgFlags;
4589 std::string msgString;
4590
4591 ASSERT_NO_FATAL_FAILURE(InitState());
4592
4593 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
4594 vk_testing::Buffer buffer;
4595 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
4596
4597 BeginCommandBuffer();
4598 // Introduce failure by using offset that is not multiple of 4
4599 m_cmdBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
4600 msgFlags = m_errorMonitor->GetState(&msgString);
4601 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad offset";
4602 if (!strstr(msgString.c_str(),"destOffset, is not a multiple of 4")) {
4603 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4'";
4604 }
4605 // Introduce failure by using size that is not multiple of 4
4606 m_cmdBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
4607 msgFlags = m_errorMonitor->GetState(&msgString);
4608 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an err after calling FillBuffer with bad size";
4609 if (!strstr(msgString.c_str(),"fillSize, is not a multiple of 4")) {
4610 FAIL() << "Error received was not 'vkCmdFillBuffer parameter, VkDeviceSize fillSize, is not a multiple of 4'";
4611 }
4612 EndCommandBuffer();
4613}
4614
Mark Lobodzinskic11cd2c2015-09-17 09:44:05 -06004615#endif // DEVICE_LIMITS_TESTS
Chris Forbes7d64a4f2015-05-25 11:13:44 +12004616
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004617#if IMAGE_TESTS
4618TEST_F(VkLayerTest, InvalidImageView)
4619{
4620 VkFlags msgFlags;
4621 std::string msgString;
4622 VkResult err;
4623
4624 ASSERT_NO_FATAL_FAILURE(InitState());
4625 m_errorMonitor->ClearState();
4626
Mike Stroyan43909d82015-09-25 13:39:21 -06004627 // Create an image and try to create a view with bad baseMipLevel
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004628 VkImage image;
4629
4630 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4631 const int32_t tex_width = 32;
4632 const int32_t tex_height = 32;
4633
4634 VkImageCreateInfo image_create_info = {};
4635 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4636 image_create_info.pNext = NULL;
4637 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4638 image_create_info.format = tex_format;
4639 image_create_info.extent.width = tex_width;
4640 image_create_info.extent.height = tex_height;
4641 image_create_info.extent.depth = 1;
4642 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004643 image_create_info.arrayLayers = 1;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004644 image_create_info.samples = 1;
4645 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4646 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4647 image_create_info.flags = 0;
4648
4649 err = vkCreateImage(m_device->device(), &image_create_info, &image);
4650 ASSERT_VK_SUCCESS(err);
4651
4652 VkImageViewCreateInfo image_view_create_info = {};
4653 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4654 image_view_create_info.image = image;
4655 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4656 image_view_create_info.format = tex_format;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004657 image_view_create_info.subresourceRange.numLayers = 1;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004658 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004659 image_view_create_info.subresourceRange.numLevels = 1;
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004660 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004661
4662 VkImageView view;
4663 err = vkCreateImageView(m_device->device(), &image_view_create_info, &view);
4664
4665 msgFlags = m_errorMonitor->GetState(&msgString);
4666 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error while creating an invalid ImageView";
4667 if (!strstr(msgString.c_str(),"vkCreateImageView called with baseMipLevel 10 ")) {
Mike Stroyan43909d82015-09-25 13:39:21 -06004668 FAIL() << "Error received was not 'vkCreateImageView called with baseMipLevel 10...' but instead '" << msgString.c_str() << "'";
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06004669 }
4670}
Mike Stroyan43909d82015-09-25 13:39:21 -06004671
Mark Lobodzinskib4092de2015-10-23 14:20:31 -06004672TEST_F(VkLayerTest, InvalidImageViewAspect)
4673{
4674 VkFlags msgFlags;
4675 std::string msgString;
4676 VkResult err;
4677
4678 ASSERT_NO_FATAL_FAILURE(InitState());
4679 m_errorMonitor->ClearState();
4680
4681 // Create an image and try to create a view with an invalid aspectMask
4682 VkImage image;
4683
4684 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4685 const int32_t tex_width = 32;
4686 const int32_t tex_height = 32;
4687
4688 VkImageCreateInfo image_create_info = {};
4689 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4690 image_create_info.pNext = NULL;
4691 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4692 image_create_info.format = tex_format;
4693 image_create_info.extent.width = tex_width;
4694 image_create_info.extent.height = tex_height;
4695 image_create_info.extent.depth = 1;
4696 image_create_info.mipLevels = 1;
4697 image_create_info.samples = 1;
4698 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4699 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4700 image_create_info.flags = 0;
4701
4702 err = vkCreateImage(m_device->device(), &image_create_info, &image);
4703 ASSERT_VK_SUCCESS(err);
4704
4705 VkImageViewCreateInfo image_view_create_info = {};
4706 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4707 image_view_create_info.image = image;
4708 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4709 image_view_create_info.format = tex_format;
4710 image_view_create_info.subresourceRange.baseMipLevel = 0;
4711 image_view_create_info.subresourceRange.numLevels = 1;
4712 // Cause an error by setting an invalid image aspect
4713 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
4714
4715 VkImageView view;
4716 err = vkCreateImageView(m_device->device(), &image_view_create_info, &view);
4717
4718 msgFlags = m_errorMonitor->GetState(&msgString);
4719 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error when specifying an invalid ImageView aspect";
4720 if (!strstr(msgString.c_str(),"vkCreateImageView: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set")) {
4721 FAIL() << "Error received was not 'VkCreateImageView: Color image formats must have ...' but instead '" << msgString.c_str() << "'";
4722 }
4723}
4724
Mike Stroyan43909d82015-09-25 13:39:21 -06004725TEST_F(VkLayerTest, CopyImageTypeMismatch)
4726{
4727 VkFlags msgFlags;
4728 std::string msgString;
4729 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004730 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06004731
4732 ASSERT_NO_FATAL_FAILURE(InitState());
4733 m_errorMonitor->ClearState();
4734
4735 // Create two images of different types and try to copy between them
4736 VkImage srcImage;
4737 VkImage destImage;
4738 VkDeviceMemory srcMem;
4739 VkDeviceMemory destMem;
4740 VkMemoryRequirements memReqs;
4741
4742 VkImageCreateInfo image_create_info = {};
4743 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4744 image_create_info.pNext = NULL;
4745 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4746 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4747 image_create_info.extent.width = 32;
4748 image_create_info.extent.height = 32;
4749 image_create_info.extent.depth = 1;
4750 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004751 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06004752 image_create_info.samples = 1;
4753 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4754 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4755 image_create_info.flags = 0;
4756
4757 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4758 ASSERT_VK_SUCCESS(err);
4759
4760 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4761 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4762
4763 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4764 ASSERT_VK_SUCCESS(err);
4765
4766 // Allocate memory
4767 VkMemoryAllocInfo memAlloc = {};
4768 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4769 memAlloc.pNext = NULL;
4770 memAlloc.allocationSize = 0;
4771 memAlloc.memoryTypeIndex = 0;
4772
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004773 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004774 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004775 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4776 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004777 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4778 ASSERT_VK_SUCCESS(err);
4779
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004780 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004781 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004782 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan43909d82015-09-25 13:39:21 -06004783 ASSERT_VK_SUCCESS(err);
4784 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4785 ASSERT_VK_SUCCESS(err);
4786
4787 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4788 ASSERT_VK_SUCCESS(err);
4789 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4790 ASSERT_VK_SUCCESS(err);
4791
4792 BeginCommandBuffer();
4793 VkImageCopy copyRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004794 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004795 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004796 copyRegion.srcSubresource.baseArrayLayer = 0;
4797 copyRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004798 copyRegion.srcOffset.x = 0;
4799 copyRegion.srcOffset.y = 0;
4800 copyRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004801 copyRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004802 copyRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004803 copyRegion.destSubresource.baseArrayLayer = 0;
4804 copyRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004805 copyRegion.destOffset.x = 0;
4806 copyRegion.destOffset.y = 0;
4807 copyRegion.destOffset.z = 0;
4808 copyRegion.extent.width = 1;
4809 copyRegion.extent.height = 1;
4810 copyRegion.extent.depth = 1;
4811 m_cmdBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
4812 EndCommandBuffer();
4813
4814 msgFlags = m_errorMonitor->GetState(&msgString);
4815 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
4816 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
4817 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
4818 }
4819
4820 vkDestroyImage(m_device->device(), srcImage);
4821 vkDestroyImage(m_device->device(), destImage);
4822 vkFreeMemory(m_device->device(), srcMem);
4823 vkFreeMemory(m_device->device(), destMem);
4824}
4825
4826TEST_F(VkLayerTest, CopyImageFormatSizeMismatch)
4827{
4828 // TODO : Create two images with different format sizes and vkCmdCopyImage between them
4829}
4830
4831TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch)
4832{
4833 VkFlags msgFlags;
4834 std::string msgString;
4835 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004836 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06004837
4838 ASSERT_NO_FATAL_FAILURE(InitState());
4839 m_errorMonitor->ClearState();
4840
4841 // Create two images of different types and try to copy between them
4842 VkImage srcImage;
4843 VkImage destImage;
4844 VkDeviceMemory srcMem;
4845 VkDeviceMemory destMem;
4846 VkMemoryRequirements memReqs;
4847
4848 VkImageCreateInfo image_create_info = {};
4849 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4850 image_create_info.pNext = NULL;
4851 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4852 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4853 image_create_info.extent.width = 32;
4854 image_create_info.extent.height = 32;
4855 image_create_info.extent.depth = 1;
4856 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004857 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06004858 image_create_info.samples = 1;
4859 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4860 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4861 image_create_info.flags = 0;
4862
4863 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4864 ASSERT_VK_SUCCESS(err);
4865
4866 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4867 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4868
4869 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4870 ASSERT_VK_SUCCESS(err);
4871
4872 // Allocate memory
4873 VkMemoryAllocInfo memAlloc = {};
4874 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4875 memAlloc.pNext = NULL;
4876 memAlloc.allocationSize = 0;
4877 memAlloc.memoryTypeIndex = 0;
4878
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004879 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004880 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004881 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4882 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004883 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4884 ASSERT_VK_SUCCESS(err);
4885
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004886 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004887 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004888 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4889 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004890 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4891 ASSERT_VK_SUCCESS(err);
4892
4893 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4894 ASSERT_VK_SUCCESS(err);
4895 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4896 ASSERT_VK_SUCCESS(err);
4897
4898 BeginCommandBuffer();
4899 VkImageCopy copyRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004900 copyRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004901 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004902 copyRegion.srcSubresource.baseArrayLayer = 0;
4903 copyRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004904 copyRegion.srcOffset.x = 0;
4905 copyRegion.srcOffset.y = 0;
4906 copyRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06004907 copyRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06004908 copyRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06004909 copyRegion.destSubresource.baseArrayLayer = 0;
4910 copyRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06004911 copyRegion.destOffset.x = 0;
4912 copyRegion.destOffset.y = 0;
4913 copyRegion.destOffset.z = 0;
4914 copyRegion.extent.width = 1;
4915 copyRegion.extent.height = 1;
4916 copyRegion.extent.depth = 1;
4917 m_cmdBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
4918 EndCommandBuffer();
4919
4920 msgFlags = m_errorMonitor->GetState(&msgString);
4921 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdCopyImage type mismatch";
4922 if (!strstr(msgString.c_str(),"vkCmdCopyImage called with unmatched source and dest image types")) {
4923 FAIL() << "Error received was not 'vkCmdCopyImage called with unmatched source and dest image types' but instead '" << msgString.c_str() << "'";
4924 }
4925
4926 vkDestroyImage(m_device->device(), srcImage);
4927 vkDestroyImage(m_device->device(), destImage);
4928 vkFreeMemory(m_device->device(), srcMem);
4929 vkFreeMemory(m_device->device(), destMem);
4930}
4931
4932TEST_F(VkLayerTest, ResolveImageLowSampleCount)
4933{
4934 VkFlags msgFlags;
4935 std::string msgString;
4936 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004937 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06004938
4939 ASSERT_NO_FATAL_FAILURE(InitState());
4940 m_errorMonitor->ClearState();
4941
4942 // Create two images of sample count 1 and try to Resolve between them
4943 VkImage srcImage;
4944 VkImage destImage;
4945 VkDeviceMemory srcMem;
4946 VkDeviceMemory destMem;
4947 VkMemoryRequirements memReqs;
4948
4949 VkImageCreateInfo image_create_info = {};
4950 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4951 image_create_info.pNext = NULL;
4952 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4953 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
4954 image_create_info.extent.width = 32;
4955 image_create_info.extent.height = 1;
4956 image_create_info.extent.depth = 1;
4957 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004958 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06004959 image_create_info.samples = 1;
4960 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
4961 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
4962 image_create_info.flags = 0;
4963
4964 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
4965 ASSERT_VK_SUCCESS(err);
4966
4967 image_create_info.imageType = VK_IMAGE_TYPE_1D;
4968 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
4969
4970 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
4971 ASSERT_VK_SUCCESS(err);
4972
4973 // Allocate memory
4974 VkMemoryAllocInfo memAlloc = {};
4975 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
4976 memAlloc.pNext = NULL;
4977 memAlloc.allocationSize = 0;
4978 memAlloc.memoryTypeIndex = 0;
4979
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004980 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004981 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004982 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4983 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004984 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
4985 ASSERT_VK_SUCCESS(err);
4986
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06004987 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06004988 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06004989 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
4990 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06004991 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
4992 ASSERT_VK_SUCCESS(err);
4993
4994 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
4995 ASSERT_VK_SUCCESS(err);
4996 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
4997 ASSERT_VK_SUCCESS(err);
4998
4999 BeginCommandBuffer();
5000 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5001 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5002 //VK_IMAGE_LAYOUT_GENERAL = 1,
5003 VkImageResolve resolveRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06005004 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005005 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005006 resolveRegion.srcSubresource.baseArrayLayer = 0;
5007 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005008 resolveRegion.srcOffset.x = 0;
5009 resolveRegion.srcOffset.y = 0;
5010 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06005011 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005012 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005013 resolveRegion.destSubresource.baseArrayLayer = 0;
5014 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005015 resolveRegion.destOffset.x = 0;
5016 resolveRegion.destOffset.y = 0;
5017 resolveRegion.destOffset.z = 0;
5018 resolveRegion.extent.width = 1;
5019 resolveRegion.extent.height = 1;
5020 resolveRegion.extent.depth = 1;
5021 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
5022 EndCommandBuffer();
5023
5024 msgFlags = m_errorMonitor->GetState(&msgString);
5025 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
5026 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with source sample count less than 2.")) {
5027 FAIL() << "Error received was not 'vkCmdResolveImage called with source sample count less than 2.' but instead '" << msgString.c_str() << "'";
5028 }
5029
5030 vkDestroyImage(m_device->device(), srcImage);
5031 vkDestroyImage(m_device->device(), destImage);
5032 vkFreeMemory(m_device->device(), srcMem);
5033 vkFreeMemory(m_device->device(), destMem);
5034}
5035
5036TEST_F(VkLayerTest, ResolveImageHighSampleCount)
5037{
5038 VkFlags msgFlags;
5039 std::string msgString;
5040 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005041 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005042
5043 ASSERT_NO_FATAL_FAILURE(InitState());
5044 m_errorMonitor->ClearState();
5045
5046 // Create two images of sample count 2 and try to Resolve between them
5047 VkImage srcImage;
5048 VkImage destImage;
5049 VkDeviceMemory srcMem;
5050 VkDeviceMemory destMem;
5051 VkMemoryRequirements memReqs;
5052
5053 VkImageCreateInfo image_create_info = {};
5054 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5055 image_create_info.pNext = NULL;
5056 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5057 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5058 image_create_info.extent.width = 32;
5059 image_create_info.extent.height = 1;
5060 image_create_info.extent.depth = 1;
5061 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005062 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06005063 image_create_info.samples = 2;
5064 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5065 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
5066 image_create_info.flags = 0;
5067
5068 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
5069 ASSERT_VK_SUCCESS(err);
5070
5071 image_create_info.imageType = VK_IMAGE_TYPE_1D;
5072 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
5073
5074 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
5075 ASSERT_VK_SUCCESS(err);
5076
5077 // Allocate memory
5078 VkMemoryAllocInfo memAlloc = {};
5079 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5080 memAlloc.pNext = NULL;
5081 memAlloc.allocationSize = 0;
5082 memAlloc.memoryTypeIndex = 0;
5083
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005084 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005085 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005086 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5087 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06005088 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
5089 ASSERT_VK_SUCCESS(err);
5090
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005091 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005092 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005093 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5094 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06005095 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
5096 ASSERT_VK_SUCCESS(err);
5097
5098 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5099 ASSERT_VK_SUCCESS(err);
5100 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
5101 ASSERT_VK_SUCCESS(err);
5102
5103 BeginCommandBuffer();
5104 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5105 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5106 //VK_IMAGE_LAYOUT_GENERAL = 1,
5107 VkImageResolve resolveRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06005108 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005109 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005110 resolveRegion.srcSubresource.baseArrayLayer = 0;
5111 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005112 resolveRegion.srcOffset.x = 0;
5113 resolveRegion.srcOffset.y = 0;
5114 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06005115 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005116 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005117 resolveRegion.destSubresource.baseArrayLayer = 0;
5118 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005119 resolveRegion.destOffset.x = 0;
5120 resolveRegion.destOffset.y = 0;
5121 resolveRegion.destOffset.z = 0;
5122 resolveRegion.extent.width = 1;
5123 resolveRegion.extent.height = 1;
5124 resolveRegion.extent.depth = 1;
5125 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
5126 EndCommandBuffer();
5127
5128 msgFlags = m_errorMonitor->GetState(&msgString);
5129 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
5130 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with dest sample count greater than 1.")) {
5131 FAIL() << "Error received was not 'vkCmdResolveImage called with dest sample count greater than 1.' but instead '" << msgString.c_str() << "'";
5132 }
5133
5134 vkDestroyImage(m_device->device(), srcImage);
5135 vkDestroyImage(m_device->device(), destImage);
5136 vkFreeMemory(m_device->device(), srcMem);
5137 vkFreeMemory(m_device->device(), destMem);
5138}
5139
5140TEST_F(VkLayerTest, ResolveImageFormatMismatch)
5141{
5142 VkFlags msgFlags;
5143 std::string msgString;
5144 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005145 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005146
5147 ASSERT_NO_FATAL_FAILURE(InitState());
5148 m_errorMonitor->ClearState();
5149
5150 // Create two images of different types and try to copy between them
5151 VkImage srcImage;
5152 VkImage destImage;
5153 VkDeviceMemory srcMem;
5154 VkDeviceMemory destMem;
5155 VkMemoryRequirements memReqs;
5156
5157 VkImageCreateInfo image_create_info = {};
5158 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5159 image_create_info.pNext = NULL;
5160 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5161 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5162 image_create_info.extent.width = 32;
5163 image_create_info.extent.height = 1;
5164 image_create_info.extent.depth = 1;
5165 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005166 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06005167 image_create_info.samples = 2;
5168 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5169 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
5170 image_create_info.flags = 0;
5171
5172 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
5173 ASSERT_VK_SUCCESS(err);
5174
5175 image_create_info.format = VK_FORMAT_B8G8R8_SRGB;
5176 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
5177 image_create_info.samples = 1;
5178
5179 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
5180 ASSERT_VK_SUCCESS(err);
5181
5182 // Allocate memory
5183 VkMemoryAllocInfo memAlloc = {};
5184 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5185 memAlloc.pNext = NULL;
5186 memAlloc.allocationSize = 0;
5187 memAlloc.memoryTypeIndex = 0;
5188
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005189 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005190 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005191 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5192 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06005193 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
5194 ASSERT_VK_SUCCESS(err);
5195
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005196 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005197 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005198 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5199 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06005200 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
5201 ASSERT_VK_SUCCESS(err);
5202
5203 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5204 ASSERT_VK_SUCCESS(err);
5205 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
5206 ASSERT_VK_SUCCESS(err);
5207
5208 BeginCommandBuffer();
5209 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5210 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5211 //VK_IMAGE_LAYOUT_GENERAL = 1,
5212 VkImageResolve resolveRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06005213 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005214 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005215 resolveRegion.srcSubresource.baseArrayLayer = 0;
5216 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005217 resolveRegion.srcOffset.x = 0;
5218 resolveRegion.srcOffset.y = 0;
5219 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06005220 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005221 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005222 resolveRegion.destSubresource.baseArrayLayer = 0;
5223 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005224 resolveRegion.destOffset.x = 0;
5225 resolveRegion.destOffset.y = 0;
5226 resolveRegion.destOffset.z = 0;
5227 resolveRegion.extent.width = 1;
5228 resolveRegion.extent.height = 1;
5229 resolveRegion.extent.depth = 1;
5230 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
5231 EndCommandBuffer();
5232
5233 msgFlags = m_errorMonitor->GetState(&msgString);
5234 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage format mismatch";
5235 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest formats.")) {
5236 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest formats.' but instead '" << msgString.c_str() << "'";
5237 }
5238
5239 vkDestroyImage(m_device->device(), srcImage);
5240 vkDestroyImage(m_device->device(), destImage);
5241 vkFreeMemory(m_device->device(), srcMem);
5242 vkFreeMemory(m_device->device(), destMem);
5243}
5244
5245TEST_F(VkLayerTest, ResolveImageTypeMismatch)
5246{
5247 VkFlags msgFlags;
5248 std::string msgString;
5249 VkResult err;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005250 bool pass;
Mike Stroyan43909d82015-09-25 13:39:21 -06005251
5252 ASSERT_NO_FATAL_FAILURE(InitState());
5253 m_errorMonitor->ClearState();
5254
5255 // Create two images of different types and try to copy between them
5256 VkImage srcImage;
5257 VkImage destImage;
5258 VkDeviceMemory srcMem;
5259 VkDeviceMemory destMem;
5260 VkMemoryRequirements memReqs;
5261
5262 VkImageCreateInfo image_create_info = {};
5263 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5264 image_create_info.pNext = NULL;
5265 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5266 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
5267 image_create_info.extent.width = 32;
5268 image_create_info.extent.height = 1;
5269 image_create_info.extent.depth = 1;
5270 image_create_info.mipLevels = 1;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06005271 image_create_info.arrayLayers = 1;
Mike Stroyan43909d82015-09-25 13:39:21 -06005272 image_create_info.samples = 2;
5273 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5274 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT;
5275 image_create_info.flags = 0;
5276
5277 err = vkCreateImage(m_device->device(), &image_create_info, &srcImage);
5278 ASSERT_VK_SUCCESS(err);
5279
5280 image_create_info.imageType = VK_IMAGE_TYPE_1D;
5281 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
5282 image_create_info.samples = 1;
5283
5284 err = vkCreateImage(m_device->device(), &image_create_info, &destImage);
5285 ASSERT_VK_SUCCESS(err);
5286
5287 // Allocate memory
5288 VkMemoryAllocInfo memAlloc = {};
5289 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
5290 memAlloc.pNext = NULL;
5291 memAlloc.allocationSize = 0;
5292 memAlloc.memoryTypeIndex = 0;
5293
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005294 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005295 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005296 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5297 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06005298 err = vkAllocMemory(m_device->device(), &memAlloc, &srcMem);
5299 ASSERT_VK_SUCCESS(err);
5300
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06005301 vkGetImageMemoryRequirements(m_device->device(), destImage, &memReqs);
Mike Stroyan43909d82015-09-25 13:39:21 -06005302 memAlloc.allocationSize = memReqs.size;
Courtney Goeltzenleuchter37a43a62015-10-22 11:03:31 -06005303 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
5304 ASSERT_TRUE(pass);
Mike Stroyan43909d82015-09-25 13:39:21 -06005305 err = vkAllocMemory(m_device->device(), &memAlloc, &destMem);
5306 ASSERT_VK_SUCCESS(err);
5307
5308 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
5309 ASSERT_VK_SUCCESS(err);
5310 err = vkBindImageMemory(m_device->device(), destImage, destMem, 0);
5311 ASSERT_VK_SUCCESS(err);
5312
5313 BeginCommandBuffer();
5314 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
5315 //VK_IMAGE_LAYOUT_UNDEFINED = 0,
5316 //VK_IMAGE_LAYOUT_GENERAL = 1,
5317 VkImageResolve resolveRegion;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06005318 resolveRegion.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005319 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005320 resolveRegion.srcSubresource.baseArrayLayer = 0;
5321 resolveRegion.srcSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005322 resolveRegion.srcOffset.x = 0;
5323 resolveRegion.srcOffset.y = 0;
5324 resolveRegion.srcOffset.z = 0;
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06005325 resolveRegion.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyan43909d82015-09-25 13:39:21 -06005326 resolveRegion.destSubresource.mipLevel = 0;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06005327 resolveRegion.destSubresource.baseArrayLayer = 0;
5328 resolveRegion.destSubresource.numLayers = 0;
Mike Stroyan43909d82015-09-25 13:39:21 -06005329 resolveRegion.destOffset.x = 0;
5330 resolveRegion.destOffset.y = 0;
5331 resolveRegion.destOffset.z = 0;
5332 resolveRegion.extent.width = 1;
5333 resolveRegion.extent.height = 1;
5334 resolveRegion.extent.depth = 1;
5335 m_cmdBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, destImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
5336 EndCommandBuffer();
5337
5338 msgFlags = m_errorMonitor->GetState(&msgString);
5339 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive an error from vkCmdResolveImage type mismatch";
5340 if (!strstr(msgString.c_str(),"vkCmdResolveImage called with unmatched source and dest image types.")) {
5341 FAIL() << "Error received was not 'vkCmdResolveImage called with unmatched source and dest image types.' but instead '" << msgString.c_str() << "'";
5342 }
5343
5344 vkDestroyImage(m_device->device(), srcImage);
5345 vkDestroyImage(m_device->device(), destImage);
5346 vkFreeMemory(m_device->device(), srcMem);
5347 vkFreeMemory(m_device->device(), destMem);
5348}
Tobin Ehlisb46be812015-10-23 16:00:08 -06005349
5350TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError)
5351{
5352 // Create a single Image descriptor and cause it to first hit an error due
5353 // to using a DS format, then cause it to hit error due to COLOR_BIT not set in aspect
5354 // The image format check comes 2nd in validation so we trigger it first,
5355 // then when we cause aspect fail next, bad format check will be preempted
5356 VkFlags msgFlags;
5357 std::string msgString;
5358 VkResult err;
5359
5360 ASSERT_NO_FATAL_FAILURE(InitState());
5361 m_errorMonitor->ClearState();
5362 VkDescriptorTypeCount ds_type_count = {};
5363 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5364 ds_type_count.count = 1;
5365
5366 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5367 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5368 ds_pool_ci.pNext = NULL;
5369 ds_pool_ci.maxSets = 1;
5370 ds_pool_ci.count = 1;
5371 ds_pool_ci.pTypeCount = &ds_type_count;
5372
5373 VkDescriptorPool ds_pool;
5374 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, &ds_pool);
5375 ASSERT_VK_SUCCESS(err);
5376
5377 VkDescriptorSetLayoutBinding dsl_binding = {};
5378 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5379 dsl_binding.arraySize = 1;
5380 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5381 dsl_binding.pImmutableSamplers = NULL;
5382
5383 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5384 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5385 ds_layout_ci.pNext = NULL;
5386 ds_layout_ci.count = 1;
5387 ds_layout_ci.pBinding = &dsl_binding;
5388 VkDescriptorSetLayout ds_layout;
5389 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout);
5390 ASSERT_VK_SUCCESS(err);
5391
5392 VkDescriptorSet descriptorSet;
5393 VkDescriptorSetAllocInfo alloc_info = {};
5394 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOC_INFO;
5395 alloc_info.count = 1;
5396 alloc_info.descriptorPool = ds_pool;
5397 alloc_info.pSetLayouts = &ds_layout;
5398 err = vkAllocDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5399 ASSERT_VK_SUCCESS(err);
5400
5401 VkImage image_bad;
5402 VkImage image_good;
5403 // One bad format and one good format for Color attachment
5404 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
5405 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
5406 const int32_t tex_width = 32;
5407 const int32_t tex_height = 32;
5408
5409 VkImageCreateInfo image_create_info = {};
5410 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5411 image_create_info.pNext = NULL;
5412 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5413 image_create_info.format = tex_format_bad;
5414 image_create_info.extent.width = tex_width;
5415 image_create_info.extent.height = tex_height;
5416 image_create_info.extent.depth = 1;
5417 image_create_info.mipLevels = 1;
5418 image_create_info.arrayLayers = 1;
5419 image_create_info.samples = 1;
5420 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5421 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
5422 image_create_info.flags = 0;
5423
5424 err = vkCreateImage(m_device->device(), &image_create_info, &image_bad);
5425 ASSERT_VK_SUCCESS(err);
5426 image_create_info.format = tex_format_good;
5427 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
5428 err = vkCreateImage(m_device->device(), &image_create_info, &image_good);
5429 ASSERT_VK_SUCCESS(err);
5430
5431 VkImageViewCreateInfo image_view_create_info = {};
5432 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5433 image_view_create_info.image = image_bad;
5434 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5435 image_view_create_info.format = tex_format_bad;
5436 image_view_create_info.subresourceRange.baseArrayLayer = 0;
5437 image_view_create_info.subresourceRange.baseMipLevel = 0;
5438 image_view_create_info.subresourceRange.numLayers = 1;
5439 image_view_create_info.subresourceRange.numLevels = 1;
5440 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5441
5442 VkImageView view;
5443 err = vkCreateImageView(m_device->device(), &image_view_create_info, &view);
5444 msgFlags = m_errorMonitor->GetState(&msgString);
5445 ASSERT_TRUE(0 != (msgFlags & VK_DBG_REPORT_ERROR_BIT)) << "Did not receive error after creating ImageView for DS image w/ COLOR aspect bit set.";
5446 if (!strstr(msgString.c_str(),"Combination depth/stencil image formats can have only the ")) {
5447 FAIL() << "Error received was not 'Combination depth/stencil image formats can have only the....' but instead '" << msgString.c_str() << "'";
5448 }
5449
5450 vkDestroyImage(m_device->device(), image_bad);
5451 vkDestroyImage(m_device->device(), image_good);
5452 vkDestroyImageView(m_device->device(), view);
5453 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout);
5454 vkDestroyDescriptorPool(m_device->device(), ds_pool);
5455}
5456
Tobin Ehlis342b9bf2015-09-22 10:11:37 -06005457#endif // IMAGE_TESTS
5458
Tony Barbour30486ea2015-04-07 13:44:53 -06005459int main(int argc, char **argv) {
5460 int result;
5461
5462 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06005463 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -06005464
5465 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
5466
5467 result = RUN_ALL_TESTS();
5468
Tony Barbour01999182015-04-09 12:58:51 -06005469 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -06005470 return result;
5471}